gridviz 3.0.35 → 3.0.36

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 (67) hide show
  1. package/README.md +129 -129
  2. package/dist/gridviz.js +17486 -17486
  3. package/dist/gridviz.min.js +2 -2
  4. package/package.json +73 -73
  5. package/src/button/Button.js +67 -67
  6. package/src/button/FullscreenButton.js +121 -121
  7. package/src/button/ZoomButtons.js +103 -103
  8. package/src/core/Dataset.js +154 -154
  9. package/src/core/Drawable.js +78 -78
  10. package/src/core/GeoCanvas.js +443 -443
  11. package/src/core/Layer.js +23 -23
  12. package/src/core/Legend.js +108 -108
  13. package/src/core/Map.js +568 -568
  14. package/src/core/MultiResolutionDataset.js +93 -93
  15. package/src/core/Style.js +98 -98
  16. package/src/core/Tooltip.js +182 -182
  17. package/src/dataset/COGeo.js +25 -25
  18. package/src/dataset/CSVGrid.js +112 -112
  19. package/src/dataset/GeoTIFF.js +122 -122
  20. package/src/dataset/JSGrid.js +55 -55
  21. package/src/dataset/TiledGrid.js +302 -302
  22. package/src/dataset/worker.js +18 -18
  23. package/src/index.js +79 -79
  24. package/src/layer/BackgroundLayer.js +173 -173
  25. package/src/layer/BackgroundLayerImage.js +81 -81
  26. package/src/layer/BackgroundLayerWMS.js +104 -104
  27. package/src/layer/GeoJSONLayer.js +276 -276
  28. package/src/layer/GridLayer.js +166 -166
  29. package/src/layer/LabelLayer.js +194 -194
  30. package/src/legend/ColorCategoryLegend.js +109 -109
  31. package/src/legend/ColorDiscreteLegend.js +100 -100
  32. package/src/legend/ColorLegend.js +115 -115
  33. package/src/legend/OrientationLegend.js +89 -89
  34. package/src/legend/SizeLegend.js +224 -224
  35. package/src/legend/TernaryLegend.js +302 -302
  36. package/src/style/CompositionStyle.js +291 -291
  37. package/src/style/DotDensityStyle.js +133 -133
  38. package/src/style/ImageStyle.js +100 -100
  39. package/src/style/Interpolator.js +258 -258
  40. package/src/style/IsoFenceStyle.js +217 -217
  41. package/src/style/JoyPlotStyle.js +180 -180
  42. package/src/style/LegoStyle.js +132 -132
  43. package/src/style/MosaicStyle.js +99 -99
  44. package/src/style/NinjaStarStyle.js +102 -102
  45. package/src/style/PillarStyle.js +207 -207
  46. package/src/style/SegmentStyle.js +105 -105
  47. package/src/style/ShadingRayStyle.js +280 -280
  48. package/src/style/ShadingStyle.js +72 -72
  49. package/src/style/ShapeColorSizeStyle.js +147 -147
  50. package/src/style/SideCategoryStyle.js +112 -112
  51. package/src/style/SideStyle.js +217 -217
  52. package/src/style/SideTanakaStyle.js +154 -154
  53. package/src/style/SquareColorCategoryWebGLStyle.js +307 -294
  54. package/src/style/SquareColorWebGLStyle.js +126 -126
  55. package/src/style/StrokeStyle.js +135 -135
  56. package/src/style/TextStyle.js +110 -110
  57. package/src/style/TimeSeriesStyle.js +222 -222
  58. package/src/utils/WebGLRectangleColoring.js +106 -106
  59. package/src/utils/WebGLSquareColoring.js +118 -118
  60. package/src/utils/WebGLSquareColoringAdvanced.js +227 -227
  61. package/src/utils/WebGLSquareColoringKS.js +153 -153
  62. package/src/utils/scale.js +255 -255
  63. package/src/utils/stretching.js +120 -120
  64. package/src/utils/ternary.js +208 -208
  65. package/src/utils/utils.js +125 -125
  66. package/src/utils/webGLUtils.js +73 -73
  67. package/src/utils/zoomUtils.js +142 -142
@@ -1,217 +1,217 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../core/Style.js'
5
-
6
- /** @typedef {{ x:number, y:number, or:"v"|"h", c1:(import('../core/Dataset').Cell)|undefined, c2:(import('../core/Dataset').Cell)|undefined }} Side */
7
-
8
- /**
9
- * @typedef {function(Array.<Side>,number, number):*} SideViewScale */
10
-
11
- /**
12
- * @module style
13
- * @author Julien Gaffuri
14
- */
15
- export class SideStyle extends Style {
16
- /** @param {object} opts */
17
- constructor(opts = {}) {
18
- super(opts)
19
-
20
- /** A function returning the color of a cell side.
21
- * @type {function(Side, number, number, object):string} */
22
- this.color = opts.color || ((side, resolution, z, sideViewScale) => '#EA6BAC')
23
-
24
- /** A function returning the width of a cell side, in geo unit
25
- * @type {function(Side, number, number, object):number} */
26
- this.width = opts.width || ((side, resolution, z, sideViewScale) => resolution / 5)
27
-
28
- /** A function returning the length of a cell side, in geo unit
29
- * @type {function(Side, number, number, object):number} */
30
- this.length = opts.length || ((side, resolution, z, sideViewScale) => resolution)
31
-
32
- /** Set to A or true so that the side is drawn as a diamond */
33
- this.diamond = opts.diamond
34
- }
35
-
36
- /**
37
- * @param {Array.<import("../core/Dataset").Cell>} cells
38
- * @param {number} resolution
39
- * @param {import("../core/GeoCanvas").GeoCanvas} geoCanvas
40
- */
41
- draw(cells, geoCanvas, resolution) {
42
- //filter
43
- if (this.filter) cells = cells.filter(this.filter)
44
-
45
- //
46
- const z = geoCanvas.view.z
47
- const ctx = geoCanvas.offscreenCtx
48
-
49
- //build sides
50
-
51
- /** @type {Array.<Side>} */
52
- const sides = SideStyle.buildSides(cells, resolution)
53
- if (sides.length == 0) return
54
-
55
- //get side view scale
56
- const viewScale = this.viewScale ? this.viewScale(sides, resolution, z) : undefined
57
-
58
- //draw sides
59
-
60
- ctx.lineCap = 'butt'
61
- const r2 = resolution * 0.5
62
- for (let side of sides) {
63
- //color
64
- /** @type {string|undefined} */
65
- const col = this.color ? this.color(side, resolution, z, viewScale) : undefined
66
- if (!col || col == 'none') continue
67
-
68
- if (this.diamond) {
69
- //set color
70
- ctx.fillStyle = col
71
-
72
- //draw diamond
73
- const x = side.x,
74
- y = side.y
75
- ctx.beginPath()
76
- ctx.moveTo(x - r2, y)
77
- ctx.lineTo(x, y + r2)
78
- ctx.lineTo(x + r2, y)
79
- ctx.lineTo(x, y - r2)
80
- ctx.closePath()
81
- ctx.fill()
82
- } else {
83
- //width
84
- /** @type {number|undefined} */
85
- const wG = this.width ? this.width(side, resolution, z, viewScale) : undefined
86
- if (!wG || wG <= 0) continue
87
-
88
- //length
89
- /** @type {number|undefined} */
90
- const lG = this.length ? this.length(side, resolution, z, viewScale) : undefined
91
- if (!lG || lG <= 0) continue
92
- const lG2 = lG * 0.5
93
-
94
- //set width
95
- ctx.lineWidth = wG
96
- //set color
97
- ctx.strokeStyle = col
98
-
99
- //draw segment with correct orientation
100
- const x = side.x,
101
- y = side.y
102
- ctx.beginPath()
103
- if (side.or === 'v') {
104
- ctx.moveTo(x, y - lG2)
105
- ctx.lineTo(x, y + lG2)
106
- } else {
107
- ctx.moveTo(x - lG2, y)
108
- ctx.lineTo(x + lG2, y)
109
- }
110
- ctx.stroke()
111
- }
112
- }
113
-
114
- //update legends
115
- this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
116
- }
117
-
118
- /**
119
- *
120
- * @param {Array.<import('../core/Dataset').Cell>} cells The cells to use to build the sides.
121
- * @param {number} resolution The cells resolution
122
- * @param {boolean} withHorizontal Set to true to build horizontal sides, false otherwise.
123
- * @param {boolean} withVertical Set to true to build vertical sides, false otherwise.
124
- * @param {boolean} center Set to true so that the side coordinate are those of its center point rather than its left/bottom point (the side x,y coordinates are those of the left point for horizontal sides, and of the bottom point for vertical sides)
125
- * @returns { Array.<Side> }
126
- */
127
- static buildSides(cells, resolution, withHorizontal = true, withVertical = true, center = true, eps = 0.01) {
128
- /** @type { Array.<Side> } */
129
- const sides = []
130
-
131
- // half resolution
132
- const r2 = center ? resolution / 2 : 0
133
-
134
- // epsilon
135
- eps = resolution * eps
136
- const abs = Math.abs
137
-
138
- //make horizontal sides
139
- //sort cells by x and y
140
- cells.sort((c1, c2) => (c2.x == c1.x ? c1.y - c2.y : c1.x - c2.x))
141
- let c1 = cells[0]
142
- for (let i = 1; i < cells.length; i++) {
143
- let c2 = cells[i]
144
-
145
- if (abs(c1.y + resolution - c2.y) < eps && abs(c1.x - c2.x) < eps)
146
- //cells in same column and touch along horizontal side
147
- //make shared side
148
- sides.push({
149
- or: 'h',
150
- x: c1.x + r2,
151
- y: c2.y,
152
- c1: c1,
153
- c2: c2,
154
- })
155
- else {
156
- //cells do not touch along horizontal side
157
- //make two sides: top one for c1, bottom for c2
158
- sides.push({
159
- or: 'h',
160
- x: c1.x + r2,
161
- y: c1.y + resolution,
162
- c1: c1,
163
- c2: undefined,
164
- })
165
- sides.push({
166
- or: 'h',
167
- x: c2.x + r2,
168
- y: c2.y,
169
- c1: undefined,
170
- c2: c2,
171
- })
172
- }
173
-
174
- c1 = c2
175
- }
176
-
177
- //make vertical sides
178
- //sort cells by y and x
179
- cells.sort((c1, c2) => (c2.y == c1.y ? c1.x - c2.x : c1.y - c2.y))
180
- c1 = cells[0]
181
- for (let i = 1; i < cells.length; i++) {
182
- let c2 = cells[i]
183
-
184
- if (abs(c1.x + resolution - c2.x) < eps && abs(c1.y - c2.y) < eps)
185
- //cells in same row and touch along vertical side
186
- //make shared side
187
- sides.push({
188
- or: 'v',
189
- x: c1.x + resolution,
190
- y: c1.y + r2,
191
- c1: c1,
192
- c2: c2,
193
- })
194
- else {
195
- //cells do not touch along vertical side
196
- //make two sides: right one for c1, left for c2
197
- sides.push({
198
- or: 'v',
199
- x: c1.x + resolution,
200
- y: c1.y + r2,
201
- c1: c1,
202
- c2: undefined,
203
- })
204
- sides.push({
205
- or: 'v',
206
- x: c2.x,
207
- y: c2.y + r2,
208
- c1: undefined,
209
- c2: c2,
210
- })
211
- }
212
-
213
- c1 = c2
214
- }
215
- return sides
216
- }
217
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../core/Style.js'
5
+
6
+ /** @typedef {{ x:number, y:number, or:"v"|"h", c1:(import('../core/Dataset').Cell)|undefined, c2:(import('../core/Dataset').Cell)|undefined }} Side */
7
+
8
+ /**
9
+ * @typedef {function(Array.<Side>,number, number):*} SideViewScale */
10
+
11
+ /**
12
+ * @module style
13
+ * @author Julien Gaffuri
14
+ */
15
+ export class SideStyle extends Style {
16
+ /** @param {object} opts */
17
+ constructor(opts = {}) {
18
+ super(opts)
19
+
20
+ /** A function returning the color of a cell side.
21
+ * @type {function(Side, number, number, object):string} */
22
+ this.color = opts.color || ((side, resolution, z, sideViewScale) => '#EA6BAC')
23
+
24
+ /** A function returning the width of a cell side, in geo unit
25
+ * @type {function(Side, number, number, object):number} */
26
+ this.width = opts.width || ((side, resolution, z, sideViewScale) => resolution / 5)
27
+
28
+ /** A function returning the length of a cell side, in geo unit
29
+ * @type {function(Side, number, number, object):number} */
30
+ this.length = opts.length || ((side, resolution, z, sideViewScale) => resolution)
31
+
32
+ /** Set to A or true so that the side is drawn as a diamond */
33
+ this.diamond = opts.diamond
34
+ }
35
+
36
+ /**
37
+ * @param {Array.<import("../core/Dataset").Cell>} cells
38
+ * @param {number} resolution
39
+ * @param {import("../core/GeoCanvas").GeoCanvas} geoCanvas
40
+ */
41
+ draw(cells, geoCanvas, resolution) {
42
+ //filter
43
+ if (this.filter) cells = cells.filter(this.filter)
44
+
45
+ //
46
+ const z = geoCanvas.view.z
47
+ const ctx = geoCanvas.offscreenCtx
48
+
49
+ //build sides
50
+
51
+ /** @type {Array.<Side>} */
52
+ const sides = SideStyle.buildSides(cells, resolution)
53
+ if (sides.length == 0) return
54
+
55
+ //get side view scale
56
+ const viewScale = this.viewScale ? this.viewScale(sides, resolution, z) : undefined
57
+
58
+ //draw sides
59
+
60
+ ctx.lineCap = 'butt'
61
+ const r2 = resolution * 0.5
62
+ for (let side of sides) {
63
+ //color
64
+ /** @type {string|undefined} */
65
+ const col = this.color ? this.color(side, resolution, z, viewScale) : undefined
66
+ if (!col || col == 'none') continue
67
+
68
+ if (this.diamond) {
69
+ //set color
70
+ ctx.fillStyle = col
71
+
72
+ //draw diamond
73
+ const x = side.x,
74
+ y = side.y
75
+ ctx.beginPath()
76
+ ctx.moveTo(x - r2, y)
77
+ ctx.lineTo(x, y + r2)
78
+ ctx.lineTo(x + r2, y)
79
+ ctx.lineTo(x, y - r2)
80
+ ctx.closePath()
81
+ ctx.fill()
82
+ } else {
83
+ //width
84
+ /** @type {number|undefined} */
85
+ const wG = this.width ? this.width(side, resolution, z, viewScale) : undefined
86
+ if (!wG || wG <= 0) continue
87
+
88
+ //length
89
+ /** @type {number|undefined} */
90
+ const lG = this.length ? this.length(side, resolution, z, viewScale) : undefined
91
+ if (!lG || lG <= 0) continue
92
+ const lG2 = lG * 0.5
93
+
94
+ //set width
95
+ ctx.lineWidth = wG
96
+ //set color
97
+ ctx.strokeStyle = col
98
+
99
+ //draw segment with correct orientation
100
+ const x = side.x,
101
+ y = side.y
102
+ ctx.beginPath()
103
+ if (side.or === 'v') {
104
+ ctx.moveTo(x, y - lG2)
105
+ ctx.lineTo(x, y + lG2)
106
+ } else {
107
+ ctx.moveTo(x - lG2, y)
108
+ ctx.lineTo(x + lG2, y)
109
+ }
110
+ ctx.stroke()
111
+ }
112
+ }
113
+
114
+ //update legends
115
+ this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
116
+ }
117
+
118
+ /**
119
+ *
120
+ * @param {Array.<import('../core/Dataset').Cell>} cells The cells to use to build the sides.
121
+ * @param {number} resolution The cells resolution
122
+ * @param {boolean} withHorizontal Set to true to build horizontal sides, false otherwise.
123
+ * @param {boolean} withVertical Set to true to build vertical sides, false otherwise.
124
+ * @param {boolean} center Set to true so that the side coordinate are those of its center point rather than its left/bottom point (the side x,y coordinates are those of the left point for horizontal sides, and of the bottom point for vertical sides)
125
+ * @returns { Array.<Side> }
126
+ */
127
+ static buildSides(cells, resolution, withHorizontal = true, withVertical = true, center = true, eps = 0.01) {
128
+ /** @type { Array.<Side> } */
129
+ const sides = []
130
+
131
+ // half resolution
132
+ const r2 = center ? resolution / 2 : 0
133
+
134
+ // epsilon
135
+ eps = resolution * eps
136
+ const abs = Math.abs
137
+
138
+ //make horizontal sides
139
+ //sort cells by x and y
140
+ cells.sort((c1, c2) => (c2.x == c1.x ? c1.y - c2.y : c1.x - c2.x))
141
+ let c1 = cells[0]
142
+ for (let i = 1; i < cells.length; i++) {
143
+ let c2 = cells[i]
144
+
145
+ if (abs(c1.y + resolution - c2.y) < eps && abs(c1.x - c2.x) < eps)
146
+ //cells in same column and touch along horizontal side
147
+ //make shared side
148
+ sides.push({
149
+ or: 'h',
150
+ x: c1.x + r2,
151
+ y: c2.y,
152
+ c1: c1,
153
+ c2: c2,
154
+ })
155
+ else {
156
+ //cells do not touch along horizontal side
157
+ //make two sides: top one for c1, bottom for c2
158
+ sides.push({
159
+ or: 'h',
160
+ x: c1.x + r2,
161
+ y: c1.y + resolution,
162
+ c1: c1,
163
+ c2: undefined,
164
+ })
165
+ sides.push({
166
+ or: 'h',
167
+ x: c2.x + r2,
168
+ y: c2.y,
169
+ c1: undefined,
170
+ c2: c2,
171
+ })
172
+ }
173
+
174
+ c1 = c2
175
+ }
176
+
177
+ //make vertical sides
178
+ //sort cells by y and x
179
+ cells.sort((c1, c2) => (c2.y == c1.y ? c1.x - c2.x : c1.y - c2.y))
180
+ c1 = cells[0]
181
+ for (let i = 1; i < cells.length; i++) {
182
+ let c2 = cells[i]
183
+
184
+ if (abs(c1.x + resolution - c2.x) < eps && abs(c1.y - c2.y) < eps)
185
+ //cells in same row and touch along vertical side
186
+ //make shared side
187
+ sides.push({
188
+ or: 'v',
189
+ x: c1.x + resolution,
190
+ y: c1.y + r2,
191
+ c1: c1,
192
+ c2: c2,
193
+ })
194
+ else {
195
+ //cells do not touch along vertical side
196
+ //make two sides: right one for c1, left for c2
197
+ sides.push({
198
+ or: 'v',
199
+ x: c1.x + resolution,
200
+ y: c1.y + r2,
201
+ c1: c1,
202
+ c2: undefined,
203
+ })
204
+ sides.push({
205
+ or: 'v',
206
+ x: c2.x,
207
+ y: c2.y + r2,
208
+ c1: undefined,
209
+ c2: c2,
210
+ })
211
+ }
212
+
213
+ c1 = c2
214
+ }
215
+ return sides
216
+ }
217
+ }