Skip to content

Commit 7c22291

Browse files
author
Deyan Totev
committed
chore@small
1 parent 2d2ea98 commit 7c22291

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/editordecoration/EditorDecoration.ts

+43-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,45 @@ import {
1414
import {MetricsUtil} from '../metrics/MetricsUtil'
1515
import {IVSCodeMetricsConfiguration} from '../metrics/common/VSCodeMetricsConfiguration'
1616
import {getColor} from './get-color'
17-
import {interpolate, toDecimal} from 'rambdax'
17+
import {interpolate, switcher, toDecimal} from 'rambdax'
1818
import {IMetricsModel} from '../tsmetrics-core/MetricsModel'
1919

2020
let decorationTemplateSimple =
21-
"<svg xmlns='http://www.w3.org/2000/svg' width='{{size}}px' height='{{size}}px' viewbox='0 0 {{size}} {{size}}'><rect width='{{size}}px' height='{{size}}px' style='fill:{{color}};stroke-width:1px;stroke:{{color}}'/></svg>"
21+
"<svg xmlns='http://www.w3.org/2000/svg' width='{{size}}px' height='{{size}}px' viewbox='0 0 {{size}} {{size}}'><rect width='{{size}}px' height='{{size}}px' style='fill:{{color}};stroke-width:1px;stroke:{{color}}'/><rect x='{{innerX}}' y='{{innerY}}' width='{{innerSize}}px' height='{{innerSize}}px' style='fill:{{innerColor}};stroke-width:1px;stroke:{{innerColor}}'/></svg>"
22+
2223
let decorationTemplateComplex =
2324
"<svg xmlns='http://www.w3.org/2000/svg' width='{{size}}px' height='{{size}}px' viewbox='0 0 {{size}} {{size}}'><rect width='{{size}}px' height='{{size}}px' style='fill:{{color}};stroke-width:1px;stroke:{{color}}'/><text dy='1px' x='50%' y='50%' dominant-baseline='middle' text-anchor='middle' style='fill:#fff;font-size:{{textSize}}px;'>{{complexity}}</text></svg>"
2425

26+
let LIMIT_COMPLEXITY = 12
27+
28+
function calculateSize (complexity){
29+
return switcher(complexity)
30+
.is(1, 0)
31+
.is(2, 0.1)
32+
.is(3, 0.15)
33+
.is(4, 0.25)
34+
.is(5, 0.3)
35+
.is(6, 0.35)
36+
.is(7, 0.4)
37+
.is(8, 0.45)
38+
.is(9, 0.52)
39+
.is(10, 0.55)
40+
.default(0.6)
41+
}
42+
43+
let innerSquareColor = '#5151ff'
44+
45+
function getInterpolateInput(size, complexity){
46+
let innerSquareSize = calculateSize(complexity) * size
47+
48+
return {
49+
innerX: toDecimal((size - innerSquareSize)/2),
50+
innerY: toDecimal((size - innerSquareSize)/2),
51+
innerSize: innerSquareSize,
52+
innerColor: innerSquareColor
53+
}
54+
}
55+
2556
export class EditorDecoration implements Disposable {
2657
private decoratorInstances: TextEditorDecorationType[] = []
2758
private decorationModeEnabled: boolean = false
@@ -186,16 +217,21 @@ export class EditorDecoration implements Disposable {
186217
return window.createTextEditorDecorationType(options)
187218
}
188219
getContentIconPath(color: string, size: number, complexity: number): Uri {
189-
const template =
190-
complexity >= 6 ? decorationTemplateComplex : decorationTemplateSimple
191220
const textSize = toDecimal(size * 0.85)
192-
const decoration = interpolate(template, {
221+
let isComplex = complexity >= LIMIT_COMPLEXITY
222+
const template = isComplex ? decorationTemplateComplex : decorationTemplateSimple
223+
let complexInput = {
193224
color,
194225
size,
195226
complexity,
196227
textSize,
197-
})
198-
228+
}
229+
230+
let interpolateInput = isComplex ? complexInput : {
231+
...complexInput,
232+
...getInterpolateInput(size, complexity)
233+
}
234+
const decoration = interpolate(template, interpolateInput)
199235
return Uri.parse(`data:image/svg+xml,` + encodeURIComponent(decoration))
200236
}
201237
disposeDecorators() {

0 commit comments

Comments
 (0)