gridviz 2.1.13 → 2.1.15

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 (62) hide show
  1. package/README.md +124 -125
  2. package/dist/gridviz.js +8900 -8368
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +77 -77
  5. package/src/App.js +760 -758
  6. package/src/BackgroundLayer.js +182 -182
  7. package/src/BackgroundLayerWMS.js +131 -131
  8. package/src/Dataset.js +76 -76
  9. package/src/DatasetComponent.js +113 -113
  10. package/src/GeoCanvas.js +420 -420
  11. package/src/LabelLayer.js +190 -190
  12. package/src/Layer.js +103 -103
  13. package/src/Legend.js +86 -86
  14. package/src/LineLayer.js +150 -150
  15. package/src/Style.js +131 -129
  16. package/src/Tooltip.js +182 -180
  17. package/src/button/Button.js +66 -54
  18. package/src/button/FullscreenButton.js +120 -98
  19. package/src/button/ZoomButtons.js +95 -72
  20. package/src/dataset/COGeo.js +24 -24
  21. package/src/dataset/CSVGrid.js +104 -104
  22. package/src/dataset/GeoTIFF.js +127 -127
  23. package/src/dataset/GridTile.js +41 -41
  24. package/src/dataset/LGrid.js +54 -54
  25. package/src/dataset/TiledGrid.js +264 -264
  26. package/src/index.js +73 -71
  27. package/src/legend/ColorCategoryLegend.js +124 -124
  28. package/src/legend/ColorDiscreteLegend.js +103 -103
  29. package/src/legend/ColorLegend.js +128 -128
  30. package/src/legend/SegmentOrientationLegend.js +87 -87
  31. package/src/legend/SegmentWidthLegend.js +101 -101
  32. package/src/legend/SizeLegend.js +141 -141
  33. package/src/style/CompositionStyle.js +300 -300
  34. package/src/style/CompositionStyle_.js +293 -0
  35. package/src/style/ContourStyle.js +54 -54
  36. package/src/style/DotDensityStyle.js +156 -156
  37. package/src/style/IsoFenceStyle.js +262 -262
  38. package/src/style/JoyPlotStyle.js +135 -135
  39. package/src/style/LegoStyle.js +112 -112
  40. package/src/style/MosaicStyle.js +107 -107
  41. package/src/style/NinjaStarStyle.js +125 -125
  42. package/src/style/PillarStyle.js +230 -230
  43. package/src/style/SegmentStyle.js +142 -142
  44. package/src/style/ShapeColorSizeStyle.js +152 -152
  45. package/src/style/ShapeColorSizeStyle_.js +108 -0
  46. package/src/style/SideCatStyle.js +172 -172
  47. package/src/style/SideStyle.js +216 -216
  48. package/src/style/SquareColorCatWGLStyle.js +120 -120
  49. package/src/style/SquareColorWGLStyle.js +146 -146
  50. package/src/style/StrokeStyle.js +131 -131
  51. package/src/style/TanakaStyle.js +160 -160
  52. package/src/style/TextStyle.js +132 -132
  53. package/src/style/TimeSeriesStyle.js +259 -259
  54. package/src/utils/Utils.js +35 -35
  55. package/src/utils/WebGLRectangleColoring.js +106 -106
  56. package/src/utils/WebGLSquareColoring.js +118 -118
  57. package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
  58. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
  59. package/src/utils/WebGLSquareColoringKS.js +153 -153
  60. package/src/utils/stretching.js +154 -131
  61. package/src/utils/webGLUtils.js +71 -71
  62. package/src/utils/zoomUtils.js +142 -142
@@ -0,0 +1,293 @@
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
+ /** A function returning the view scale.
23
+ * @type {function(Array.<import('../Dataset.js').Cell>,number, number):object} */
24
+ this.viewScale = opts.viewScale
25
+
26
+ /**
27
+ * The dictionary (string -> color) which give the color of each category.
28
+ * @type {object} */
29
+ this.color = opts.color
30
+
31
+ /**
32
+ * A function returning the type of decomposition symbol of a cell, @see CompositionType
33
+ * @type {function(import("../Dataset.js").Cell,number, number,object):CompositionType} */
34
+ this.type = opts.type
35
+
36
+ /** A function returning the size of a cell in geographical unit.
37
+ * @type {function(import('../Dataset.js').Cell,number, number,object):number} */
38
+ this.size = opts.size
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.js").Cell,number,number,object):number} */
42
+ this.stripesOrientation = opts.stripesOrientation || (() => 0) //(c,r,zf,vc) => ...
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.js").Cell,number,number,object):number} */
47
+ this.offsetAngle = opts.offsetAngle || (() => 0) //(cell,r,zf,vc) => ...
48
+
49
+ /** The function specifying the height of the age pyramid, in geo unit.
50
+ * @type {function(import("../Dataset.js").Cell,number,number,object):number} */
51
+ this.agePyramidHeight = opts.agePyramidHeight || ((c, r, zf) => r) //(cell,r,zf,vc) => ...
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.js").Cell>} cells
63
+ * @param {number} r
64
+ * @param {import("../GeoCanvas.js").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
+ //get view scale
74
+ const vc = this.viewScale ? this.viewScale(cells, r, zf) : undefined
75
+
76
+ //nb categories - used for radar and agepyramid
77
+ const nbCat = Object.entries(this.color).length
78
+
79
+ //draw in geo coordinates
80
+ cg.setCanvasTransform()
81
+
82
+ //draw calls
83
+ for (let cell of cells) {
84
+
85
+ //size
86
+ const sG = this.size ? this.size(cell, r, zf, vc) : r
87
+ if (!sG) continue
88
+
89
+ //get offset
90
+ const offset = this.offset(cell, r, zf)
91
+
92
+ //get symbol type
93
+ const type_ = this.type ? this.type(cell, r, zf, vc) : 'flag'
94
+
95
+ //compute center position
96
+ const xc = cell.x + offset.dx + (type_ === 'agepyramid' ? 0 : r * 0.5)
97
+ const yc = cell.y + offset.dy + (type_ === 'agepyramid' ? 0 : r * 0.5)
98
+
99
+ //compute offset angle, when relevant
100
+ const offAng = this.offsetAngle ? (this.offsetAngle(cell, r, zf, vc) * Math.PI) / 180 : 0
101
+
102
+ if (type_ === 'agepyramid' || type_ === 'radar' || type_ === 'halftone') {
103
+ //get cell category max value
104
+ let maxVal = -Infinity
105
+ for (let key of Object.keys(this.color)) {
106
+ const v = +cell[key]
107
+ if (v > maxVal) maxVal = v
108
+ }
109
+
110
+ //cumul
111
+ let cumul = 0
112
+ if (type_ === 'agepyramid' && this.agePyramidHeight)
113
+ cumul = (r - this.agePyramidHeight(cell, r, zf, vc)) / 2
114
+ if (type_ === 'radar' || type_ === 'halftone') cumul = Math.PI / 2 + offAng
115
+
116
+ //compute the increment, which is the value to increment the cumul for each category
117
+ const incr =
118
+ type_ === 'agepyramid'
119
+ ? (this.agePyramidHeight ? this.agePyramidHeight(cell, r, zf, vc) : r) / nbCat
120
+ : type_ === 'radar' || type_ === 'halftone'
121
+ ? (2 * Math.PI) / nbCat
122
+ : undefined
123
+ if (incr === undefined) throw new Error('Unexpected symbol type:' + type_)
124
+
125
+ for (let [column, color] of Object.entries(this.color)) {
126
+ if (type_ === 'agepyramid') {
127
+ //set category color
128
+ cg.ctx.fillStyle = color
129
+
130
+ //get category value
131
+ const val = cell[column]
132
+
133
+ //compute category length - in geo
134
+ /** @type {number} */
135
+ const wG = (sG * val) / maxVal
136
+
137
+ //draw bar
138
+ cg.ctx.fillRect(xc + (r - wG) / 2, yc + cumul, wG, incr)
139
+
140
+ //next height
141
+ cumul += incr
142
+ } else if (type_ === 'radar') {
143
+ //set category color
144
+ cg.ctx.fillStyle = color
145
+
146
+ //get categroy value
147
+ const val = cell[column]
148
+
149
+ //compute category radius - in geo
150
+ /** @type {number} */
151
+ //const rG = this.radius(val, r, stat, cellStat, zf)
152
+ const rG = (sG / 2) * Math.sqrt(val / maxVal)
153
+
154
+ //draw angular sector
155
+ cg.ctx.beginPath()
156
+ cg.ctx.moveTo(xc, yc)
157
+ cg.ctx.arc(xc, yc, rG, cumul - incr, cumul)
158
+ cg.ctx.lineTo(xc, yc)
159
+ cg.ctx.fill()
160
+
161
+ //next angular sector
162
+ cumul += incr
163
+ } else if (type_ === 'halftone') {
164
+ //set category color
165
+ cg.ctx.fillStyle = color
166
+
167
+ //get categroy value
168
+ const val = cell[column]
169
+
170
+ //compute category radius - in geo
171
+ /** @type {number} */
172
+ const rG = sG * 0.333 * Math.sqrt(val / maxVal)
173
+
174
+ //draw circle
175
+ cg.ctx.beginPath()
176
+ cg.ctx.arc(
177
+ xc + r * 0.25 * Math.cos(cumul),
178
+ yc + r * 0.25 * Math.sin(cumul),
179
+ rG,
180
+ 0,
181
+ 2 * Math.PI
182
+ )
183
+ cg.ctx.fill()
184
+
185
+ //next angular sector
186
+ cumul += incr
187
+ } else {
188
+ throw new Error('Unexpected symbol type:' + type_)
189
+ }
190
+ }
191
+ } else {
192
+ //compute total
193
+ let total = 0
194
+ for (let column of Object.keys(this.color)) {
195
+ const v = +cell[column]
196
+ if (!v) continue
197
+ total += v
198
+ }
199
+ if (!total || isNaN(total)) continue
200
+
201
+ //draw decomposition symbol
202
+ let cumul = 0
203
+ const d = r * (1 - sG / r) * 0.5
204
+ const ori = this.stripesOrientation(cell, r, zf, vc)
205
+
206
+ for (let [column, color] of Object.entries(this.color)) {
207
+ //get share
208
+ const share = cell[column] / total
209
+ if (!share || isNaN(share)) continue
210
+
211
+ //set color
212
+ cg.ctx.fillStyle = color
213
+
214
+ //draw symbol part
215
+ if (type_ === 'flag') {
216
+ //draw flag stripe
217
+ if (ori == 0) {
218
+ //horizontal
219
+ cg.ctx.fillRect(
220
+ cell.x + d + offset.dx,
221
+ cell.y + d + cumul * sG + offset.dy,
222
+ sG,
223
+ share * sG
224
+ )
225
+ } else {
226
+ //vertical
227
+ cg.ctx.fillRect(
228
+ cell.x + d + cumul * sG + offset.dx,
229
+ cell.y + d + offset.dy,
230
+ share * sG,
231
+ sG
232
+ )
233
+ }
234
+ } else if (type_ === 'piechart') {
235
+ //draw pie chart angular sector
236
+
237
+ //compute angles
238
+ const a1 = cumul * 2 * Math.PI
239
+ const a2 = (cumul + share) * 2 * Math.PI
240
+
241
+ //draw
242
+ cg.ctx.beginPath()
243
+ cg.ctx.moveTo(xc, yc)
244
+ cg.ctx.arc(xc, yc, sG * 0.5, a1 + offAng, a2 + offAng)
245
+ if (this.pieChartInternalRadiusFactor)
246
+ cg.ctx.arc(
247
+ xc,
248
+ yc,
249
+ sG * 0.5 * this.pieChartInternalRadiusFactor,
250
+ a1 + offAng,
251
+ a2 + offAng,
252
+ true
253
+ )
254
+ cg.ctx.closePath()
255
+ cg.ctx.fill()
256
+ } else if (type_ === 'ring') {
257
+ //draw ring
258
+ cg.ctx.beginPath()
259
+ cg.ctx.arc(xc, yc, Math.sqrt(1 - cumul) * sG * 0.5, 0, 2 * Math.PI)
260
+ cg.ctx.fill()
261
+ } else if (type_ === 'segment') {
262
+ //draw segment sections
263
+ const wG = (sG * sG) / r
264
+ if (ori == 0) {
265
+ //horizontal
266
+ cg.ctx.fillRect(
267
+ cell.x + offset.dx,
268
+ cell.y + (r - wG) / 2 + cumul * wG + offset.dy,
269
+ r,
270
+ share * wG
271
+ )
272
+ } else {
273
+ //vertical
274
+ cg.ctx.fillRect(
275
+ cell.x + cumul * r + offset.dx,
276
+ cell.y + (r - wG) / 2 + offset.dy,
277
+ share * r,
278
+ wG
279
+ )
280
+ }
281
+ } else {
282
+ throw new Error('Unexpected symbol type:' + type_)
283
+ }
284
+
285
+ cumul += share
286
+ }
287
+ }
288
+ }
289
+
290
+ //update legends
291
+ this.updateLegends({ style: this, r: r, zf: zf, viewScale: vc })
292
+ }
293
+ }
@@ -1,54 +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
- }
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
+ }