gridviz 2.0.28 → 2.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/gridviz.js +34368 -0
  2. package/dist/gridviz.min.js +1 -1
  3. package/package.json +10 -6
  4. package/src/App.js +654 -0
  5. package/src/BackgroundLayer.js +182 -0
  6. package/src/BackgroundLayerWMS.js +131 -0
  7. package/src/Dataset.js +76 -0
  8. package/src/DatasetComponent.js +103 -0
  9. package/src/GeoCanvas.js +419 -0
  10. package/src/LabelLayer.js +190 -0
  11. package/src/Layer.js +92 -0
  12. package/src/Legend.js +86 -0
  13. package/src/LineLayer.js +150 -0
  14. package/src/Style.js +114 -0
  15. package/src/Tooltip.js +150 -0
  16. package/src/dataset/COGeo.js +24 -0
  17. package/src/dataset/CSVGrid.js +104 -0
  18. package/src/dataset/GeoTIFF.js +127 -0
  19. package/src/dataset/GridTile.js +41 -0
  20. package/src/dataset/ParquetGrid.js +122 -0
  21. package/src/dataset/TiledGrid.js +296 -0
  22. package/src/index.js +177 -0
  23. package/src/legend/ColorCategoryLegend.js +124 -0
  24. package/src/legend/ColorDiscreteLegend.js +105 -0
  25. package/src/legend/ColorLegend.js +125 -0
  26. package/src/legend/SegmentOrientationLegend.js +87 -0
  27. package/src/legend/SegmentWidthLegend.js +97 -0
  28. package/src/legend/SizeLegend.js +141 -0
  29. package/src/style/CompositionStyle.js +300 -0
  30. package/src/style/ContourStyle.js +54 -0
  31. package/src/style/DotDensityStyle.js +156 -0
  32. package/src/style/JoyPlotStyle.js +135 -0
  33. package/src/style/KernelSmoothingOldStyle.js +221 -0
  34. package/src/style/KernelSmoothingStyle.js +115 -0
  35. package/src/style/KernelSmoothingWGLStyle.js +130 -0
  36. package/src/style/LegoStyle.js +112 -0
  37. package/src/style/MosaicStyle.js +107 -0
  38. package/src/style/NinjaStarStyle.js +124 -0
  39. package/src/style/PillarStyle.js +230 -0
  40. package/src/style/SegmentStyle.js +142 -0
  41. package/src/style/ShapeColorSizeStyle.js +126 -0
  42. package/src/style/SideCatStyle.js +172 -0
  43. package/src/style/SideStyle.js +218 -0
  44. package/src/style/SquareColorCatWGLStyle.js +120 -0
  45. package/src/style/SquareColorWGLStyle.js +146 -0
  46. package/src/style/StrokeStyle.js +131 -0
  47. package/src/style/TanakaStyle.js +160 -0
  48. package/src/style/TextStyle.js +132 -0
  49. package/src/utils/Utils.js +35 -0
  50. package/src/utils/WebGLRectangleColoring.js +106 -0
  51. package/src/utils/WebGLSquareColoring.js +118 -0
  52. package/src/utils/WebGLSquareColoringAdvanced.js +230 -0
  53. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -0
  54. package/src/utils/WebGLSquareColoringKS.js +153 -0
  55. package/src/utils/stretching.js +131 -0
  56. package/src/utils/webGLUtils.js +71 -0
  57. package/src/utils/zoomUtils.js +142 -0
@@ -0,0 +1,97 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Legend } from '../Legend.js'
5
+ import { format } from 'd3-format'
6
+
7
+ /**
8
+ * A legend element for segment width.
9
+ *
10
+ * @author Joseph Davies, Julien Gaffuri
11
+ */
12
+ export class SegmentWidthLegend extends Legend {
13
+ /** @param {Object} opts */
14
+ constructor(opts) {
15
+ super(opts)
16
+ opts = opts || {}
17
+
18
+ //title
19
+ this.title = opts.title
20
+ this.titleFontSize = opts.titleFontSize || '0.8em'
21
+ this.titleFontWeight = opts.titleFontWeight || 'bold'
22
+
23
+ //exageration
24
+ this.exaggerationFactor = opts.exaggerationFactor || 0.5
25
+
26
+ //color
27
+ this.color = opts.color || 'gray'
28
+ //orientation
29
+ this.orientation = opts.orientation || 0
30
+
31
+ //label
32
+ this.labelFontSize = opts.labelFontSize || '0.8em'
33
+ this.labelUnitText = opts.labelUnitText || ''
34
+ }
35
+
36
+ /**
37
+ * @param {{ style: import("../style/SegmentStyle").SegmentStyle, r: number, zf: number, sColor: import("../Style").Stat, sLength: import("../Style").Stat, sWidth: import("../Style").Stat }} opts
38
+ */
39
+ update(opts) {
40
+ //could happen when data is still loading
41
+ if (!opts.sWidth) return
42
+
43
+ //clear
44
+ this.div.selectAll('*').remove()
45
+
46
+ const d = this.div.append('div')
47
+
48
+ //title
49
+ if (this.title) {
50
+ d.append('div')
51
+ .attr('class', 'title')
52
+ .style('font-size', this.titleFontSize)
53
+ .style('font-weight', this.titleFontWeight)
54
+ .text(this.title)
55
+ }
56
+
57
+ //get max value
58
+ const value_ = opts.sWidth.max * this.exaggerationFactor
59
+
60
+ //take 'nice' value (power of ten, or multiple)
61
+ let pow10 = Math.log10(value_)
62
+ pow10 = Math.floor(pow10)
63
+ let value = Math.pow(10, pow10)
64
+ if (value * 8 <= value_) value *= 8
65
+ else if (value * 6 <= value_) value *= 6
66
+ else if (value * 5 <= value_) value *= 5
67
+ else if (value * 4 <= value_) value *= 4
68
+ else if (value * 2.5 <= value_) value *= 2.5
69
+ else if (value * 2 <= value_) value *= 2
70
+
71
+ //compute segment width and length, in pix
72
+ const sWidth = opts.style.width(value, opts.r, opts.sWidth, opts.zf) / opts.zf
73
+ const sLength = (1 * opts.r) / opts.zf
74
+
75
+ //TODO use orientation
76
+
77
+ const svg = d.append('svg').attr('width', sLength).attr('height', sWidth).style('', 'inline-block')
78
+
79
+ //<line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" />
80
+ svg.append('line')
81
+ .attr('x1', 0)
82
+ .attr('y1', sWidth / 2)
83
+ .attr('x2', sLength)
84
+ .attr('y2', sWidth / 2)
85
+ .style('stroke', this.color)
86
+ .style('stroke-width', sWidth)
87
+
88
+ const valueT = format(',.2r')(value)
89
+ d.append('div')
90
+ //show on right of graphic
91
+ .style('display', 'inline')
92
+ .style('padding-left', '5px')
93
+ .style('font-size', this.labelFontSize)
94
+ //.style("font-weight", "bold")
95
+ .text(valueT + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
96
+ }
97
+ }
@@ -0,0 +1,141 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Legend } from '../Legend.js'
5
+ import { format } from 'd3-format'
6
+
7
+ /**
8
+ * A legend element for proportional symbols.
9
+ *
10
+ * @author Joseph Davies, Julien Gaffuri
11
+ */
12
+ export class SizeLegend extends Legend {
13
+ /** @param {Object} opts */
14
+ constructor(opts) {
15
+ super(opts)
16
+ opts = opts || {}
17
+
18
+ //exageration
19
+ this.exaggerationFactor = opts.exaggerationFactor || 0.8
20
+
21
+ //if value is to be forced
22
+ this.value = opts.value || undefined
23
+
24
+ //title
25
+ this.title = opts.title
26
+ this.titleFontSize = opts.titleFontSize || '0.8em'
27
+ this.titleFontWeight = opts.titleFontWeight || 'bold'
28
+
29
+ //symbol
30
+ /**
31
+ * @private
32
+ * @type {import("../Style").Shape} */
33
+ this.shape = opts.shape || 'circle'
34
+ this.fillColor = opts.fillColor || 'none'
35
+ this.strokeColor = opts.strokeColor || 'gray'
36
+ this.strokeWidth = opts.strokeWidth || 1
37
+
38
+ //label
39
+ this.labelFontSize = opts.labelFontSize || '0.8em'
40
+ this.labelUnitText = opts.labelUnitText || ''
41
+ this.labelFormat = opts.labelFormat || ',.2r'
42
+
43
+ //
44
+ //this.div.style("text-align", "center")
45
+ }
46
+
47
+ /**
48
+ * @param {{ style: import("../style/ShapeColorSizeStyle").ShapeColorSizeStyle, r: number, zf: number, sSize: import("../Style").Stat, sColor: import("../Style").Stat }} opts
49
+ */
50
+ update(opts) {
51
+ //could happen when data is still loading
52
+ if (!opts.sSize) return
53
+
54
+ //clear
55
+ this.div.selectAll('*').remove()
56
+
57
+ //get value
58
+ let value = this.value
59
+ if (value == undefined) {
60
+ //compute 'nice value
61
+
62
+ //get max value
63
+ const value_ = opts.sSize.max * this.exaggerationFactor
64
+
65
+ //take 'nice' value (power of ten, or multiple)
66
+ let pow10 = Math.log10(value_)
67
+ pow10 = Math.floor(pow10)
68
+ value = Math.pow(10, pow10)
69
+ if (value * 8 <= value_) value *= 8
70
+ else if (value * 6 <= value_) value *= 6
71
+ else if (value * 5 <= value_) value *= 5
72
+ else if (value * 4 <= value_) value *= 4
73
+ else if (value * 2.5 <= value_) value *= 2.5
74
+ else if (value * 2 <= value_) value *= 2
75
+ }
76
+
77
+ if (!value) return
78
+
79
+ const d = this.div.append('div')
80
+ //to enable vertical centering
81
+ //.style("position", "relative")
82
+
83
+ //title
84
+ if (this.title) {
85
+ d.append('div')
86
+ .attr('class', 'title')
87
+ .style('font-size', this.titleFontSize)
88
+ .style('font-weight', this.titleFontWeight)
89
+ .text(this.title)
90
+ }
91
+
92
+ //compute size of symbol, in pix
93
+ const size = opts.style.size(value, opts.r, opts.sSize, opts.zf) / opts.zf
94
+
95
+ const svg = d
96
+ .append('svg')
97
+ .attr('width', size + this.strokeWidth + 2)
98
+ .attr('height', size + this.strokeWidth + 2)
99
+ .style('', 'inline-block')
100
+
101
+ if (this.shape === 'square') {
102
+ svg.append('rect')
103
+ .attr('x', 0)
104
+ .attr('y', 0)
105
+ .attr('width', size)
106
+ .attr('height', size)
107
+ .style('fill', this.fillColor)
108
+ .style('stroke', this.strokeColor)
109
+ .style('stroke-width', this.strokeWidth)
110
+ //TODO test
111
+ } else if (this.shape === 'circle') {
112
+ // <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
113
+ const r = (size + this.strokeWidth) * 0.5
114
+ svg.append('circle')
115
+ .attr('cx', r + 1)
116
+ .attr('cy', r + 1)
117
+ .attr('r', r)
118
+ .style('fill', this.fillColor)
119
+ .style('stroke', this.strokeColor)
120
+ .style('stroke-width', this.strokeWidth)
121
+ } else if (this.shape === 'donut') {
122
+ //TODO
123
+ } else if (this.shape === 'diamond') {
124
+ //TODO
125
+ } else {
126
+ throw new Error('Unexpected shape:' + this.shape)
127
+ }
128
+
129
+ const valueT = format(this.labelFormat)(value)
130
+ d.append('div')
131
+ //show on right of graphic
132
+ .style('display', 'inline')
133
+
134
+ //center vertically
135
+ //.style("position", "absolute").style("top", "0").style("bottom", "0")
136
+
137
+ .style('padding-left', '5px')
138
+ .style('font-size', this.labelFontSize)
139
+ .text(valueT + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
140
+ }
141
+ }
@@ -0,0 +1,300 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../Style.js'
5
+
6
+ /** @typedef {"flag"|"piechart"|"ring"|"segment"|"radar"|"agepyramid"|"halftone"} CompositionType */
7
+
8
+ /**
9
+ * A style showing the composition of a total in different categories, with different color hues.
10
+ * It consists of a symbol with different parts, whose size reflect the proportion of the corresponding category.
11
+ * For a list of supported symbols, @see CompositionType
12
+ * The symbol can be scaled depending on the cell importance.
13
+ *
14
+ * @author Julien Gaffuri
15
+ */
16
+ export class CompositionStyle extends Style {
17
+ /** @param {object} opts */
18
+ constructor(opts) {
19
+ super(opts)
20
+ opts = opts || {}
21
+
22
+ /**
23
+ * The dictionary (string -> color) which give the color of each category.
24
+ * @type {object} */
25
+ this.color = opts.color
26
+
27
+ /**
28
+ * A function returning the type of decomposition symbol of a cell, @see CompositionType
29
+ * @type {function(import("../Dataset").Cell):CompositionType} */
30
+ this.type = opts.type
31
+
32
+ /** The column where to get the size values.
33
+ * @type {string} */
34
+ this.sizeCol = opts.sizeCol
35
+
36
+ /** A function returning the size of a cell.
37
+ * @type {function(number,number,import("../Style").Stat|undefined,number):number} */
38
+ this.size = opts.size || ((v, r, s, zf) => r)
39
+
40
+ /** For style types with stripes (flag, segment), the orientation of the stripes (0 for horizontal, other for vertical).
41
+ * @type {function(import("../Dataset").Cell,number,number):number} */
42
+ this.stripesOrientation = opts.stripesOrientation || (() => 0) //(c,r,zf) => ...
43
+
44
+ /** The function specifying an offset angle for a radar, halftone or pie chart style.
45
+ * The angle is specified in degree. The rotation is anti-clockwise.
46
+ * @type {function(import("../Dataset").Cell,number,number):number} */
47
+ this.offsetAngle = opts.offsetAngle || (() => 0) //(cell,r,zf) => ...
48
+
49
+ /** The function specifying the height of the age pyramid, in geo unit.
50
+ * @type {function(import("../Dataset").Cell,number,number):number} */
51
+ this.agePyramidHeight = opts.agePyramidHeight || ((c, r, zf) => r) //(cell,r,zf) => ...
52
+
53
+ /** For pie chart, this is parameter for internal radius, so that the pie chart looks like a donut.
54
+ * 0 for normal pie charts, 0.5 to empty half of the radius.
55
+ * @type {number} */
56
+ this.pieChartInternalRadiusFactor = opts.pieChartInternalRadiusFactor || 0
57
+ }
58
+
59
+ /**
60
+ * Draw cells as squares depending on their value.
61
+ *
62
+ * @param {Array.<import("../Dataset").Cell>} cells
63
+ * @param {number} r
64
+ * @param {import("../GeoCanvas").GeoCanvas} cg
65
+ */
66
+ draw(cells, r, cg) {
67
+ //filter
68
+ if (this.filter) cells = cells.filter(this.filter)
69
+
70
+ //zoom factor
71
+ const zf = cg.getZf()
72
+
73
+ let stat
74
+ if (this.sizeCol) {
75
+ //if size is used, sort cells by size so that the biggest are drawn first
76
+ cells.sort((c1, c2) => c2[this.sizeCol] - c1[this.sizeCol])
77
+ //and compute statistics
78
+ stat = Style.getStatistics(cells, (c) => c[this.sizeCol], true)
79
+ }
80
+
81
+ //nb categories - used for radar and agepyramid
82
+ const nbCat = Object.entries(this.color).length
83
+
84
+ //draw in geo coordinates
85
+ cg.setCanvasTransform()
86
+
87
+ //draw calls
88
+ for (let cell of cells) {
89
+ //size
90
+ /** @type {function(number,number,import("../Style").Stat|undefined,number):number} */
91
+ let s_ = this.size || (() => r)
92
+ //size - in geo
93
+ /** @type {number} */
94
+ const sG = s_(cell[this.sizeCol], r, stat, zf)
95
+
96
+ //get offset
97
+ const offset = this.offset(cell, r, zf)
98
+
99
+ //get symbol type
100
+ const type_ = this.type ? this.type(cell) : 'flag'
101
+
102
+ //compute center position
103
+ const xc = cell.x + offset.dx + (type_ === 'agepyramid' ? 0 : r * 0.5)
104
+ const yc = cell.y + offset.dy + (type_ === 'agepyramid' ? 0 : r * 0.5)
105
+
106
+ //compute offset angle, when relevant
107
+ const offAng = this.offsetAngle ? (this.offsetAngle(cell, r, zf) * Math.PI) / 180 : 0
108
+
109
+ if (type_ === 'agepyramid' || type_ === 'radar' || type_ === 'halftone') {
110
+ //get cell category max value
111
+ let maxVal = -Infinity
112
+ for (let key of Object.keys(this.color)) {
113
+ const v = +cell[key]
114
+ if (v > maxVal) maxVal = v
115
+ }
116
+
117
+ //cumul
118
+ let cumul = 0
119
+ if (type_ === 'agepyramid' && this.agePyramidHeight)
120
+ cumul = (r - this.agePyramidHeight(cell, r, zf)) / 2
121
+ if (type_ === 'radar' || type_ === 'halftone') cumul = Math.PI / 2 + offAng
122
+
123
+ //compute the increment, which is the value to increment the cumul for each category
124
+ const incr =
125
+ type_ === 'agepyramid'
126
+ ? (this.agePyramidHeight ? this.agePyramidHeight(cell, r, zf) : r) / nbCat
127
+ : type_ === 'radar' || type_ === 'halftone'
128
+ ? (2 * Math.PI) / nbCat
129
+ : undefined
130
+ if (incr === undefined) throw new Error('Unexpected symbol type:' + type_)
131
+
132
+ for (let [column, color] of Object.entries(this.color)) {
133
+ if (type_ === 'agepyramid') {
134
+ //set category color
135
+ cg.ctx.fillStyle = color
136
+
137
+ //get category value
138
+ const val = cell[column]
139
+
140
+ //compute category length - in geo
141
+ /** @type {number} */
142
+ const wG = (sG * val) / maxVal
143
+
144
+ //draw bar
145
+ cg.ctx.fillRect(xc + (r - wG) / 2, yc + cumul, wG, incr)
146
+
147
+ //next height
148
+ cumul += incr
149
+ } else if (type_ === 'radar') {
150
+ //set category color
151
+ cg.ctx.fillStyle = color
152
+
153
+ //get categroy value
154
+ const val = cell[column]
155
+
156
+ //compute category radius - in geo
157
+ /** @type {number} */
158
+ //const rG = this.radius(val, r, stat, cellStat, zf)
159
+ const rG = (sG / 2) * Math.sqrt(val / maxVal)
160
+
161
+ //draw angular sector
162
+ cg.ctx.beginPath()
163
+ cg.ctx.moveTo(xc, yc)
164
+ cg.ctx.arc(xc, yc, rG, cumul - incr, cumul)
165
+ cg.ctx.lineTo(xc, yc)
166
+ cg.ctx.fill()
167
+
168
+ //next angular sector
169
+ cumul += incr
170
+ } else if (type_ === 'halftone') {
171
+ //set category color
172
+ cg.ctx.fillStyle = color
173
+
174
+ //get categroy value
175
+ const val = cell[column]
176
+
177
+ //compute category radius - in geo
178
+ /** @type {number} */
179
+ const rG = sG * 0.333 * Math.sqrt(val / maxVal)
180
+
181
+ //draw circle
182
+ cg.ctx.beginPath()
183
+ cg.ctx.arc(
184
+ xc + r * 0.25 * Math.cos(cumul),
185
+ yc + r * 0.25 * Math.sin(cumul),
186
+ rG,
187
+ 0,
188
+ 2 * Math.PI
189
+ )
190
+ cg.ctx.fill()
191
+
192
+ //next angular sector
193
+ cumul += incr
194
+ } else {
195
+ throw new Error('Unexpected symbol type:' + type_)
196
+ }
197
+ }
198
+ } else {
199
+ //compute total
200
+ let total = 0
201
+ for (let column of Object.keys(this.color)) {
202
+ const v = +cell[column]
203
+ if (!v) continue
204
+ total += v
205
+ }
206
+ if (!total || isNaN(total)) continue
207
+
208
+ //draw decomposition symbol
209
+ let cumul = 0
210
+ const d = r * (1 - sG / r) * 0.5
211
+ const ori = this.stripesOrientation(cell, r, zf)
212
+
213
+ for (let [column, color] of Object.entries(this.color)) {
214
+ //get share
215
+ const share = cell[column] / total
216
+ if (!share || isNaN(share)) continue
217
+
218
+ //set color
219
+ cg.ctx.fillStyle = color
220
+
221
+ //draw symbol part
222
+ if (type_ === 'flag') {
223
+ //draw flag stripe
224
+ if (ori == 0) {
225
+ //horizontal
226
+ cg.ctx.fillRect(
227
+ cell.x + d + offset.dx,
228
+ cell.y + d + cumul * sG + offset.dy,
229
+ sG,
230
+ share * sG
231
+ )
232
+ } else {
233
+ //vertical
234
+ cg.ctx.fillRect(
235
+ cell.x + d + cumul * sG + offset.dx,
236
+ cell.y + d + offset.dy,
237
+ share * sG,
238
+ sG
239
+ )
240
+ }
241
+ } else if (type_ === 'piechart') {
242
+ //draw pie chart angular sector
243
+
244
+ //compute angles
245
+ const a1 = cumul * 2 * Math.PI
246
+ const a2 = (cumul + share) * 2 * Math.PI
247
+
248
+ //draw
249
+ cg.ctx.beginPath()
250
+ cg.ctx.moveTo(xc, yc)
251
+ cg.ctx.arc(xc, yc, sG * 0.5, a1 + offAng, a2 + offAng)
252
+ if (this.pieChartInternalRadiusFactor)
253
+ cg.ctx.arc(
254
+ xc,
255
+ yc,
256
+ sG * 0.5 * this.pieChartInternalRadiusFactor,
257
+ a1 + offAng,
258
+ a2 + offAng,
259
+ true
260
+ )
261
+ cg.ctx.closePath()
262
+ cg.ctx.fill()
263
+ } else if (type_ === 'ring') {
264
+ //draw ring
265
+ cg.ctx.beginPath()
266
+ cg.ctx.arc(xc, yc, Math.sqrt(1 - cumul) * sG * 0.5, 0, 2 * Math.PI)
267
+ cg.ctx.fill()
268
+ } else if (type_ === 'segment') {
269
+ //draw segment sections
270
+ const wG = (sG * sG) / r
271
+ if (ori == 0) {
272
+ //horizontal
273
+ cg.ctx.fillRect(
274
+ cell.x + offset.dx,
275
+ cell.y + (r - wG) / 2 + cumul * wG + offset.dy,
276
+ r,
277
+ share * wG
278
+ )
279
+ } else {
280
+ //vertical
281
+ cg.ctx.fillRect(
282
+ cell.x + cumul * r + offset.dx,
283
+ cell.y + (r - wG) / 2 + offset.dy,
284
+ share * r,
285
+ wG
286
+ )
287
+ }
288
+ } else {
289
+ throw new Error('Unexpected symbol type:' + type_)
290
+ }
291
+
292
+ cumul += share
293
+ }
294
+ }
295
+ }
296
+
297
+ //update legends
298
+ this.updateLegends({ style: this, r: r, zf: zf, sSize: stat })
299
+ }
300
+ }
@@ -0,0 +1,54 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { SideStyle } from './SideStyle.js'
5
+
6
+ /** @typedef {{x:number,y:number,or:"v"|"h",value:number}} Side */
7
+
8
+ /**
9
+ *
10
+ * @author Julien Gaffuri
11
+ */
12
+ export class ContourStyle extends SideStyle {
13
+ /** @param {object} opts */
14
+ constructor(opts) {
15
+ super(opts)
16
+ opts = opts || {}
17
+
18
+ /** @type {number} */
19
+ //opts.interval = opts.interval || 100
20
+
21
+ /** @type {Array.<number>} */
22
+ opts.breaks = opts.breaks || [100, 1000, 10000, 100000, 1000000]
23
+
24
+ /** @type {function(Side,number,number):string} */
25
+ opts.width = opts.width || (() => 1) //(s, r, zf) => ...
26
+
27
+ /** @type {function(Side,number,number):string} */
28
+ opts.color = opts.color || (() => '#E7A935') //(s, r, zf) => ...
29
+
30
+ //override method for contour drawing
31
+
32
+ const getClass = function (v) {
33
+ if (v == undefined) return 0
34
+ for (let i = 0; i < opts.breaks.length; i++) if (v < opts.breaks[i]) return i
35
+ return opts.breaks.length
36
+ }
37
+
38
+ this.value = (v1, v2, r, s, zf) => {
39
+ //if (!v1 || !v2) return 0
40
+ return Math.abs(getClass(v2) - getClass(v1))
41
+
42
+ //check if v1 - v2 cross a contour line
43
+ //const r1 = Math.floor(v1 / opts.interval);
44
+ //const r2 = Math.floor(v2 / opts.interval);
45
+ //return Math.abs(r2 - r1);
46
+ }
47
+
48
+ //same color for all
49
+ this.color = (side, r, s, zf) => (side.value ? opts.color(side, r, zf) : undefined)
50
+
51
+ //width: multiple of
52
+ this.width = (side, r, s, zf) => side.value * zf * opts.width(side, r, zf)
53
+ }
54
+ }