gridviz 2.0.28 → 2.0.29

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 (56) hide show
  1. package/dist/gridviz.js +34315 -0
  2. package/package.json +3 -2
  3. package/src/App.js +651 -0
  4. package/src/BackgroundLayer.js +182 -0
  5. package/src/BackgroundLayerWMS.js +131 -0
  6. package/src/Dataset.js +76 -0
  7. package/src/DatasetComponent.js +103 -0
  8. package/src/GeoCanvas.js +419 -0
  9. package/src/LabelLayer.js +190 -0
  10. package/src/Layer.js +92 -0
  11. package/src/Legend.js +86 -0
  12. package/src/LineLayer.js +150 -0
  13. package/src/Style.js +114 -0
  14. package/src/Tooltip.js +150 -0
  15. package/src/dataset/COGeo.js +24 -0
  16. package/src/dataset/CSVGrid.js +105 -0
  17. package/src/dataset/GeoTIFF.js +127 -0
  18. package/src/dataset/GridTile.js +41 -0
  19. package/src/dataset/ParquetGrid.js +123 -0
  20. package/src/dataset/TiledGrid.js +294 -0
  21. package/src/index.js +176 -0
  22. package/src/legend/ColorCategoryLegend.js +124 -0
  23. package/src/legend/ColorDiscreteLegend.js +105 -0
  24. package/src/legend/ColorLegend.js +125 -0
  25. package/src/legend/SegmentOrientationLegend.js +87 -0
  26. package/src/legend/SegmentWidthLegend.js +97 -0
  27. package/src/legend/SizeLegend.js +141 -0
  28. package/src/style/CompositionStyle.js +294 -0
  29. package/src/style/ContourStyle.js +54 -0
  30. package/src/style/DotDensityStyle.js +156 -0
  31. package/src/style/JoyPlotStyle.js +135 -0
  32. package/src/style/KernelSmoothingOldStyle.js +221 -0
  33. package/src/style/KernelSmoothingStyle.js +115 -0
  34. package/src/style/KernelSmoothingWGLStyle.js +130 -0
  35. package/src/style/LegoStyle.js +112 -0
  36. package/src/style/MosaicStyle.js +107 -0
  37. package/src/style/NinjaStarStyle.js +124 -0
  38. package/src/style/PillarStyle.js +230 -0
  39. package/src/style/SegmentStyle.js +142 -0
  40. package/src/style/ShapeColorSizeStyle.js +126 -0
  41. package/src/style/SideCatStyle.js +172 -0
  42. package/src/style/SideStyle.js +218 -0
  43. package/src/style/SquareColorCatWGLStyle.js +120 -0
  44. package/src/style/SquareColorWGLStyle.js +146 -0
  45. package/src/style/StrokeStyle.js +131 -0
  46. package/src/style/TanakaStyle.js +160 -0
  47. package/src/style/TextStyle.js +132 -0
  48. package/src/utils/Utils.js +35 -0
  49. package/src/utils/WebGLRectangleColoring.js +106 -0
  50. package/src/utils/WebGLSquareColoring.js +118 -0
  51. package/src/utils/WebGLSquareColoringAdvanced.js +230 -0
  52. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -0
  53. package/src/utils/WebGLSquareColoringKS.js +153 -0
  54. package/src/utils/stretching.js +131 -0
  55. package/src/utils/webGLUtils.js +71 -0
  56. package/src/utils/zoomUtils.js +142 -0
@@ -0,0 +1,97 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Legend } from '../Legend'
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'
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,294 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../Style'
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')
122
+ cumul = Math.PI / 2 + offAng
123
+
124
+ //compute the increment, which is the value to increment the cumul for each category
125
+ const incr =
126
+ type_ === 'agepyramid'
127
+ ? (this.agePyramidHeight ? this.agePyramidHeight(cell, r, zf) : r) / nbCat
128
+ : type_ === 'radar' || type_ === 'halftone'
129
+ ? (2 * Math.PI) / nbCat
130
+ : undefined
131
+ if (incr === undefined) throw new Error('Unexpected symbol type:' + type_)
132
+
133
+ for (let [column, color] of Object.entries(this.color)) {
134
+ if (type_ === 'agepyramid') {
135
+ //set category color
136
+ cg.ctx.fillStyle = color
137
+
138
+ //get category value
139
+ const val = cell[column]
140
+
141
+ //compute category length - in geo
142
+ /** @type {number} */
143
+ const wG = (sG * val) / maxVal
144
+
145
+ //draw bar
146
+ cg.ctx.fillRect(xc + (r - wG) / 2, yc + cumul, wG, incr)
147
+
148
+ //next height
149
+ cumul += incr
150
+ } else if (type_ === 'radar') {
151
+ //set category color
152
+ cg.ctx.fillStyle = color
153
+
154
+ //get categroy value
155
+ const val = cell[column]
156
+
157
+ //compute category radius - in geo
158
+ /** @type {number} */
159
+ //const rG = this.radius(val, r, stat, cellStat, zf)
160
+ const rG = (sG / 2) * Math.sqrt(val / maxVal)
161
+
162
+ //draw angular sector
163
+ cg.ctx.beginPath()
164
+ cg.ctx.moveTo(xc, yc)
165
+ cg.ctx.arc(xc, yc, rG, cumul - incr, cumul)
166
+ cg.ctx.lineTo(xc, yc)
167
+ cg.ctx.fill()
168
+
169
+ //next angular sector
170
+ cumul += incr
171
+ } else if (type_ === 'halftone') {
172
+ //set category color
173
+ cg.ctx.fillStyle = color
174
+
175
+ //get categroy value
176
+ const val = cell[column]
177
+
178
+ //compute category radius - in geo
179
+ /** @type {number} */
180
+ const rG = sG * 0.333 * Math.sqrt(val / maxVal)
181
+
182
+ //draw circle
183
+ cg.ctx.beginPath()
184
+ cg.ctx.arc(
185
+ xc + r * 0.25 * Math.cos(cumul),
186
+ yc + r * 0.25 * Math.sin(cumul),
187
+ rG,
188
+ 0,
189
+ 2 * Math.PI
190
+ )
191
+ cg.ctx.fill()
192
+
193
+ //next angular sector
194
+ cumul += incr
195
+ } else {
196
+ throw new Error('Unexpected symbol type:' + type_)
197
+ }
198
+ }
199
+ } else {
200
+ //compute total
201
+ let total = 0
202
+ for (let column of Object.keys(this.color)) {
203
+ const v = +cell[column]
204
+ if (!v) continue
205
+ total += v
206
+ }
207
+ if (!total || isNaN(total)) continue
208
+
209
+ //draw decomposition symbol
210
+ let cumul = 0
211
+ const d = r * (1 - sG / r) * 0.5
212
+ const ori = this.stripesOrientation(cell, r, zf)
213
+
214
+ for (let [column, color] of Object.entries(this.color)) {
215
+ //get share
216
+ const share = cell[column] / total
217
+ if (!share || isNaN(share)) continue
218
+
219
+ //set color
220
+ cg.ctx.fillStyle = color
221
+
222
+ //draw symbol part
223
+ if (type_ === 'flag') {
224
+ //draw flag stripe
225
+ if (ori == 0) {
226
+ //horizontal
227
+ cg.ctx.fillRect(
228
+ cell.x + d + offset.dx,
229
+ cell.y + d + cumul * sG + offset.dy,
230
+ sG,
231
+ share * sG
232
+ )
233
+ } else {
234
+ //vertical
235
+ cg.ctx.fillRect(
236
+ cell.x + d + cumul * sG + offset.dx,
237
+ cell.y + d + offset.dy,
238
+ share * sG,
239
+ sG
240
+ )
241
+ }
242
+ } else if (type_ === 'piechart') {
243
+ //draw pie chart angular sector
244
+
245
+ //compute angles
246
+ const a1 = cumul * 2 * Math.PI
247
+ const a2 = (cumul + share) * 2 * Math.PI
248
+
249
+ //draw
250
+ cg.ctx.beginPath()
251
+ cg.ctx.moveTo(xc, yc)
252
+ cg.ctx.arc(xc, yc, sG * 0.5, a1+offAng, a2+offAng)
253
+ if (this.pieChartInternalRadiusFactor)
254
+ cg.ctx.arc(xc, yc, sG * 0.5 * this.pieChartInternalRadiusFactor, a1+offAng, a2+offAng, true)
255
+ cg.ctx.closePath()
256
+ cg.ctx.fill()
257
+ } else if (type_ === 'ring') {
258
+ //draw ring
259
+ cg.ctx.beginPath()
260
+ cg.ctx.arc(xc, yc, Math.sqrt(1 - cumul) * sG * 0.5, 0, 2 * Math.PI)
261
+ cg.ctx.fill()
262
+ } else if (type_ === 'segment') {
263
+ //draw segment sections
264
+ const wG = (sG * sG) / r
265
+ if (ori == 0) {
266
+ //horizontal
267
+ cg.ctx.fillRect(
268
+ cell.x + offset.dx,
269
+ cell.y + (r - wG) / 2 + cumul * wG + offset.dy,
270
+ r,
271
+ share * wG
272
+ )
273
+ } else {
274
+ //vertical
275
+ cg.ctx.fillRect(
276
+ cell.x + cumul * r + offset.dx,
277
+ cell.y + (r - wG) / 2 + offset.dy,
278
+ share * r,
279
+ wG
280
+ )
281
+ }
282
+ } else {
283
+ throw new Error('Unexpected symbol type:' + type_)
284
+ }
285
+
286
+ cumul += share
287
+ }
288
+ }
289
+ }
290
+
291
+ //update legends
292
+ this.updateLegends({ style: this, r: r, zf: zf, sSize: stat })
293
+ }
294
+ }
@@ -0,0 +1,54 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { SideStyle } from './SideStyle'
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
+ }