gridviz 3.0.15 → 3.0.17

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 (55) hide show
  1. package/README.md +127 -128
  2. package/dist/gridviz.js +7958 -7861
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +74 -74
  5. package/src/button/ZoomButtons.js +101 -96
  6. package/src/core/Dataset.js +154 -157
  7. package/src/core/Drawable.js +60 -61
  8. package/src/core/GeoCanvas.js +409 -370
  9. package/src/core/Layer.js +23 -25
  10. package/src/core/Legend.js +108 -110
  11. package/src/core/Map.js +494 -495
  12. package/src/core/MultiResolutionDataset.js +93 -97
  13. package/src/core/Style.js +98 -99
  14. package/src/dataset/CSVGrid.js +112 -112
  15. package/src/dataset/GeoTIFF.js +122 -123
  16. package/src/dataset/JSGrid.js +55 -54
  17. package/src/dataset/TiledGrid.js +289 -288
  18. package/src/dataset/worker.js +18 -0
  19. package/src/index.js +77 -71
  20. package/src/layer/BackgroundLayer.js +162 -158
  21. package/src/layer/BackgroundLayerImage.js +81 -84
  22. package/src/layer/BackgroundLayerWMS.js +104 -108
  23. package/src/layer/GeoJSONLayer.js +214 -220
  24. package/src/layer/GridLayer.js +148 -157
  25. package/src/layer/LabelLayer.js +194 -193
  26. package/src/legend/ColorCategoryLegend.js +109 -110
  27. package/src/legend/ColorDiscreteLegend.js +100 -102
  28. package/src/legend/ColorLegend.js +115 -118
  29. package/src/legend/OrientationLegend.js +89 -91
  30. package/src/legend/SizeLegend.js +224 -224
  31. package/src/legend/TernaryLegend.js +302 -210
  32. package/src/style/CompositionStyle.js +291 -288
  33. package/src/style/DotDensityStyle.js +133 -134
  34. package/src/style/ImageStyle.js +100 -102
  35. package/src/style/IsoFenceStyle.js +217 -203
  36. package/src/style/JoyPlotStyle.js +127 -128
  37. package/src/style/LegoStyle.js +110 -110
  38. package/src/style/MosaicStyle.js +99 -99
  39. package/src/style/NinjaStarStyle.js +102 -102
  40. package/src/style/PillarStyle.js +207 -208
  41. package/src/style/SegmentStyle.js +105 -105
  42. package/src/style/ShapeColorSizeStyle.js +147 -132
  43. package/src/style/SideCategoryStyle.js +112 -114
  44. package/src/style/SideStyle.js +212 -205
  45. package/src/style/SquareColorCategoryWebGLStyle.js +107 -108
  46. package/src/style/SquareColorWebGLStyle.js +126 -126
  47. package/src/style/StrokeStyle.js +135 -136
  48. package/src/style/TanakaStyle.js +69 -68
  49. package/src/style/TextStyle.js +110 -111
  50. package/src/style/TimeSeriesStyle.js +222 -229
  51. package/src/utils/scale.js +218 -228
  52. package/src/utils/stretching.js +120 -133
  53. package/src/utils/ternary.js +203 -204
  54. package/src/utils/utils.js +58 -63
  55. package/src/utils/webGLUtils.js +72 -70
@@ -1,157 +1,154 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- /**
5
- * A grid cell.
6
- * @typedef {{x: number, y: number}} Cell */
7
-
8
- /**
9
- * A dataset component, of grid cells.
10
- * @abstract
11
- *
12
- * @module core
13
- * @author Joseph Davies, Julien Gaffuri
14
- */
15
- export class Dataset {
16
- /**
17
- * @param {import("./Map.js").Map} map The map.
18
- * @param {string} url The URL of the dataset.
19
- * @param {number} resolution The dataset resolution, in the CRS geographical unit.
20
- * @param {{preprocess?:function(Cell):boolean, mixedResolution?:function(Cell):number}} opts
21
- * @abstract
22
- */
23
- constructor(map, url, resolution, opts = {}) {
24
-
25
- /**
26
- * The map.
27
- * @protected
28
- * @type {import("./Map.js").Map} */
29
- this.map = map
30
-
31
- /**
32
- * The url of the dataset.
33
- * @protected
34
- * @type {string} */
35
- this.url = url
36
-
37
- /**
38
- * The dataset resolution in geographical unit.
39
- * @protected
40
- * @type {number} */
41
- this.resolution = resolution
42
-
43
- /**
44
- * In case the dataset is a dataset with cells having different resolution,
45
- * this is the function returning the resolution of each cell.
46
- * @protected
47
- * @type {(function(Cell):number )| undefined } */
48
- this.mixedResolution = opts.mixedResolution
49
-
50
- /**
51
- * A preprocess to run on each cell after loading. It can be used to apply some specific treatment before or compute a new column. And also to determine which cells to keep after loading.
52
- * @type {(function(Cell):boolean )| undefined } */
53
- this.preprocess = opts.preprocess || undefined
54
-
55
- /** The cells within the view
56
- * @protected
57
- * @type {Array.<Cell>} */
58
- this.cellsViewCache = []
59
- }
60
-
61
- /**
62
- * Request data within a geographic envelope.
63
- *
64
- * @abstract
65
- * @param {import("./GeoCanvas").Envelope|undefined} extGeo
66
- * @returns {this}
67
- */
68
- getData(extGeo = undefined) {
69
- throw new Error('Method getData not implemented.')
70
- }
71
-
72
- /**
73
- * Fill the view cache with all cells which are within a geographical envelope.
74
- * @abstract
75
- * @param {import("./GeoCanvas").Envelope} extGeo The view geographical envelope.
76
- * @returns {void}
77
- */
78
- updateViewCache(extGeo) {
79
- throw new Error('Method updateViewCache not implemented.')
80
- }
81
-
82
- /**
83
- * Get a cell under a given position, if any.
84
- *
85
- * @param {{x:number,y:number}} posGeo
86
- * @param {Array.<Cell>} cells Some cells from the dataset (a subset if necessary, usually the view cache).
87
- * @returns {Cell|undefined}
88
- */
89
- getCellFromPosition(posGeo, cells) {
90
- //compute candidate cell position
91
- /** @type {number} */
92
- //const r = this.getResolution()
93
- /** @type {number} */
94
- //const cellX = r * Math.floor(posGeo.x / r)
95
- /** @type {number} */
96
- //const cellY = r * Math.floor(posGeo.y / r)
97
-
98
- /*/get cell
99
- for (const cell of cells) {
100
- if (cell.x != cellX) continue
101
- if (cell.y != cellY) continue
102
- return cell
103
- }
104
- return undefined*/
105
-
106
- //rare case of mixed resolution dataset
107
- if (this.mixedResolution) {
108
- for (const c of cells) {
109
- /** @type {number} */
110
- const r = +this.mixedResolution(c)
111
- if (posGeo.x < c.x) continue
112
- else if (c.x + r < posGeo.x) continue
113
- else if (posGeo.y < c.y) continue
114
- else if (c.y + r < posGeo.y) continue
115
- else return c
116
- }
117
- return undefined
118
- }
119
-
120
- //common case
121
-
122
- /** @type {number} */
123
- const r = this.getResolution()
124
- for (const cell of cells) {
125
- if (posGeo.x < cell.x) continue
126
- else if (cell.x + r < posGeo.x) continue
127
- else if (posGeo.y < cell.y) continue
128
- else if (cell.y + r < posGeo.y) continue
129
- else return cell
130
- }
131
- return undefined
132
-
133
- }
134
-
135
- //getters and setters
136
-
137
- /** @returns {number} */
138
- getResolution() {
139
- return this.resolution
140
- }
141
-
142
- /** @returns {Array.<Cell>} */
143
- getViewCache() {
144
- return this.cellsViewCache
145
- }
146
-
147
- /**
148
- * Return the relevant dataset for a specified zoom.
149
- * @param {number} z
150
- * @param {number} minPixelsPerCell
151
- * @returns {Dataset|undefined}
152
- * */
153
- getDataset(z, minPixelsPerCell) {
154
- return this
155
- }
156
-
157
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ /**
5
+ * A grid cell.
6
+ * @typedef {{x: number, y: number}} Cell */
7
+
8
+ /**
9
+ * A dataset component, of grid cells.
10
+ * @abstract
11
+ *
12
+ * @module core
13
+ * @author Joseph Davies, Julien Gaffuri
14
+ */
15
+ export class Dataset {
16
+ /**
17
+ * @param {import("./Map.js").Map} map The map.
18
+ * @param {string} url The URL of the dataset.
19
+ * @param {number} resolution The dataset resolution, in the CRS geographical unit.
20
+ * @param {{preprocess?:function(Cell):boolean, mixedResolution?:function(Cell):number}} opts
21
+ * @abstract
22
+ */
23
+ constructor(map, url, resolution, opts = {}) {
24
+ /**
25
+ * The map.
26
+ * @protected
27
+ * @type {import("./Map.js").Map} */
28
+ this.map = map
29
+
30
+ /**
31
+ * The url of the dataset.
32
+ * @protected
33
+ * @type {string} */
34
+ this.url = url
35
+
36
+ /**
37
+ * The dataset resolution in geographical unit.
38
+ * @protected
39
+ * @type {number} */
40
+ this.resolution = resolution
41
+
42
+ /**
43
+ * In case the dataset is a dataset with cells having different resolution,
44
+ * this is the function returning the resolution of each cell.
45
+ * @protected
46
+ * @type {(function(Cell):number )| undefined } */
47
+ this.mixedResolution = opts.mixedResolution
48
+
49
+ /**
50
+ * A preprocess to run on each cell after loading. It can be used to apply some specific treatment before or compute a new column. And also to determine which cells to keep after loading.
51
+ * @type {(function(Cell):boolean )| undefined } */
52
+ this.preprocess = opts.preprocess || undefined
53
+
54
+ /** The cells within the view
55
+ * @protected
56
+ * @type {Array.<Cell>} */
57
+ this.cellsViewCache = []
58
+ }
59
+
60
+ /**
61
+ * Request data within a geographic envelope.
62
+ *
63
+ * @abstract
64
+ * @param {import("./GeoCanvas").Envelope|undefined} extGeo
65
+ * @returns {this}
66
+ */
67
+ getData(extGeo = undefined) {
68
+ throw new Error('Method getData not implemented.')
69
+ }
70
+
71
+ /**
72
+ * Fill the view cache with all cells which are within a geographical envelope.
73
+ * @abstract
74
+ * @param {import("./GeoCanvas").Envelope} extGeo The view geographical envelope.
75
+ * @returns {void}
76
+ */
77
+ updateViewCache(extGeo) {
78
+ throw new Error('Method updateViewCache not implemented.')
79
+ }
80
+
81
+ /**
82
+ * Get a cell under a given position, if any.
83
+ *
84
+ * @param {{x:number,y:number}} posGeo
85
+ * @param {Array.<Cell>} cells Some cells from the dataset (a subset if necessary, usually the view cache).
86
+ * @returns {Cell|undefined}
87
+ */
88
+ getCellFromPosition(posGeo, cells) {
89
+ //compute candidate cell position
90
+ /** @type {number} */
91
+ //const r = this.getResolution()
92
+ /** @type {number} */
93
+ //const cellX = r * Math.floor(posGeo.x / r)
94
+ /** @type {number} */
95
+ //const cellY = r * Math.floor(posGeo.y / r)
96
+
97
+ /*/get cell
98
+ for (const cell of cells) {
99
+ if (cell.x != cellX) continue
100
+ if (cell.y != cellY) continue
101
+ return cell
102
+ }
103
+ return undefined*/
104
+
105
+ //rare case of mixed resolution dataset
106
+ if (this.mixedResolution) {
107
+ for (const c of cells) {
108
+ /** @type {number} */
109
+ const r = +this.mixedResolution(c)
110
+ if (posGeo.x < c.x) continue
111
+ else if (c.x + r < posGeo.x) continue
112
+ else if (posGeo.y < c.y) continue
113
+ else if (c.y + r < posGeo.y) continue
114
+ else return c
115
+ }
116
+ return undefined
117
+ }
118
+
119
+ //common case
120
+
121
+ /** @type {number} */
122
+ const r = this.getResolution()
123
+ for (const cell of cells) {
124
+ if (posGeo.x < cell.x) continue
125
+ else if (cell.x + r < posGeo.x) continue
126
+ else if (posGeo.y < cell.y) continue
127
+ else if (cell.y + r < posGeo.y) continue
128
+ else return cell
129
+ }
130
+ return undefined
131
+ }
132
+
133
+ //getters and setters
134
+
135
+ /** @returns {number} */
136
+ getResolution() {
137
+ return this.resolution
138
+ }
139
+
140
+ /** @returns {Array.<Cell>} */
141
+ getViewCache() {
142
+ return this.cellsViewCache
143
+ }
144
+
145
+ /**
146
+ * Return the relevant dataset for a specified zoom.
147
+ * @param {number} z
148
+ * @param {number} minPixelsPerCell
149
+ * @returns {Dataset|undefined}
150
+ * */
151
+ getDataset(z, minPixelsPerCell) {
152
+ return this
153
+ }
154
+ }
@@ -1,61 +1,60 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- /**
5
- * This is an abstract class used to group elements shared between Layer and Style classes.
6
- *
7
- * @abstract
8
- * @module core
9
- * @author Joseph Davies, Julien Gaffuri
10
- */
11
- export class Drawable {
12
- /**
13
- * @param {object} opts
14
- */
15
- constructor(opts) {
16
- opts = opts || {}
17
-
18
- /** A function specifying if the element should be visible or not.
19
- * The function parameter is the zoom level.
20
- * @type {function(number):boolean} */
21
- this.visible = opts.visible
22
-
23
- /** A function returning the alpha (transparency/opacity), between 0.0 (fully transparent) and 1.0 (fully opaque).
24
- * The function parameter is the zoom level.
25
- * (see CanvasRenderingContext2D: globalAlpha property)
26
- * @type {(function(number):number)|undefined} */
27
- this.alpha = opts.alpha
28
-
29
- /** A function returning the blend operation.
30
- * The function parameter is the zoom level.
31
- * (see CanvasRenderingContext2D: globalCompositeOperation property)
32
- * @type {function(number):GlobalCompositeOperation} */
33
- this.blendOperation = opts.blendOperation || (z => "source-over")
34
-
35
- /** @type {(function(number):string)|undefined} */
36
- this.filterColor = opts.filterColor // (z) => "#eee7"
37
- }
38
-
39
- /**
40
- * Draw layer filter.
41
- *
42
- * @param {import("./GeoCanvas.js").GeoCanvas} geoCanvas The canvas where to draw the layer.
43
- * @returns {void}
44
- * @abstract
45
- */
46
- drawFilter(geoCanvas) {
47
- //no filter: return
48
- if (!this.filterColor) return
49
-
50
- //get filter
51
- const fc = this.filterColor(geoCanvas.view.z)
52
-
53
- //no filter: return
54
- if (!fc || fc == 'none') return
55
-
56
- //draw filter
57
- geoCanvas.ctx.fillStyle = fc
58
- geoCanvas.ctx.fillRect(0, 0, geoCanvas.w, geoCanvas.h)
59
- }
60
-
61
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ /**
5
+ * This is an abstract class used to group elements shared between Layer and Style classes.
6
+ *
7
+ * @abstract
8
+ * @module core
9
+ * @author Joseph Davies, Julien Gaffuri
10
+ */
11
+ export class Drawable {
12
+ /**
13
+ * @param {object} opts
14
+ */
15
+ constructor(opts) {
16
+ opts = opts || {}
17
+
18
+ /** A function specifying if the element should be visible or not.
19
+ * The function parameter is the zoom level.
20
+ * @type {function(number):boolean} */
21
+ this.visible = opts.visible
22
+
23
+ /** A function returning the alpha (transparency/opacity), between 0.0 (fully transparent) and 1.0 (fully opaque).
24
+ * The function parameter is the zoom level.
25
+ * (see CanvasRenderingContext2D: globalAlpha property)
26
+ * @type {(function(number):number)|undefined} */
27
+ this.alpha = opts.alpha
28
+
29
+ /** A function returning the blend operation.
30
+ * The function parameter is the zoom level.
31
+ * (see CanvasRenderingContext2D: globalCompositeOperation property)
32
+ * @type {function(number):GlobalCompositeOperation} */
33
+ this.blendOperation = opts.blendOperation || ((z) => 'source-over')
34
+
35
+ /** @type {(function(number):string)|undefined} */
36
+ this.filterColor = opts.filterColor // (z) => "#eee7"
37
+ }
38
+
39
+ /**
40
+ * Draw layer filter.
41
+ *
42
+ * @param {import("./GeoCanvas.js").GeoCanvas} geoCanvas The canvas where to draw the layer.
43
+ * @returns {void}
44
+ * @abstract
45
+ */
46
+ drawFilter(geoCanvas) {
47
+ //no filter: return
48
+ if (!this.filterColor) return
49
+
50
+ //get filter
51
+ const fc = this.filterColor(geoCanvas.view.z)
52
+
53
+ //no filter: return
54
+ if (!fc || fc == 'none') return
55
+
56
+ //draw filter
57
+ geoCanvas.offscreenCtx.fillStyle = fc
58
+ geoCanvas.offscreenCtx.fillRect(0, 0, geoCanvas.w, geoCanvas.h)
59
+ }
60
+ }