@@ -14,14 +14,45 @@ import {
14
14
import { MetricsUtil } from '../metrics/MetricsUtil'
15
15
import { IVSCodeMetricsConfiguration } from '../metrics/common/VSCodeMetricsConfiguration'
16
16
import { getColor } from './get-color'
17
- import { interpolate , toDecimal } from 'rambdax'
17
+ import { interpolate , switcher , toDecimal } from 'rambdax'
18
18
import { IMetricsModel } from '../tsmetrics-core/MetricsModel'
19
19
20
20
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
+
22
23
let decorationTemplateComplex =
23
24
"<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>"
24
25
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
+
25
56
export class EditorDecoration implements Disposable {
26
57
private decoratorInstances : TextEditorDecorationType [ ] = [ ]
27
58
private decorationModeEnabled : boolean = false
@@ -186,16 +217,21 @@ export class EditorDecoration implements Disposable {
186
217
return window . createTextEditorDecorationType ( options )
187
218
}
188
219
getContentIconPath ( color : string , size : number , complexity : number ) : Uri {
189
- const template =
190
- complexity >= 6 ? decorationTemplateComplex : decorationTemplateSimple
191
220
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 = {
193
224
color,
194
225
size,
195
226
complexity,
196
227
textSize,
197
- } )
198
-
228
+ }
229
+
230
+ let interpolateInput = isComplex ? complexInput : {
231
+ ...complexInput ,
232
+ ...getInterpolateInput ( size , complexity )
233
+ }
234
+ const decoration = interpolate ( template , interpolateInput )
199
235
return Uri . parse ( `data:image/svg+xml,` + encodeURIComponent ( decoration ) )
200
236
}
201
237
disposeDecorators ( ) {
0 commit comments