gridviz 3.0.25 → 3.0.27

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 (66) hide show
  1. package/README.md +128 -128
  2. package/dist/gridviz.js +8630 -8615
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +74 -74
  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 -438
  11. package/src/core/Layer.js +23 -23
  12. package/src/core/Legend.js +108 -108
  13. package/src/core/Map.js +544 -544
  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 +77 -77
  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 +224 -214
  28. package/src/layer/GridLayer.js +148 -148
  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/ContourStyle.js +21 -21
  38. package/src/style/DotDensityStyle.js +133 -133
  39. package/src/style/ImageStyle.js +100 -100
  40. package/src/style/IsoFenceStyle.js +217 -217
  41. package/src/style/JoyPlotStyle.js +127 -127
  42. package/src/style/LegoStyle.js +110 -110
  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/ShapeColorSizeStyle.js +147 -147
  48. package/src/style/SideCategoryStyle.js +112 -112
  49. package/src/style/SideStyle.js +212 -212
  50. package/src/style/SquareColorCategoryWebGLStyle.js +107 -107
  51. package/src/style/SquareColorWebGLStyle.js +126 -126
  52. package/src/style/StrokeStyle.js +135 -135
  53. package/src/style/TanakaStyle.js +69 -69
  54. package/src/style/TextStyle.js +110 -110
  55. package/src/style/TimeSeriesStyle.js +222 -222
  56. package/src/utils/WebGLRectangleColoring.js +106 -106
  57. package/src/utils/WebGLSquareColoring.js +118 -118
  58. package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
  59. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
  60. package/src/utils/WebGLSquareColoringKS.js +153 -153
  61. package/src/utils/scale.js +218 -218
  62. package/src/utils/stretching.js +120 -120
  63. package/src/utils/ternary.js +208 -208
  64. package/src/utils/utils.js +58 -58
  65. package/src/utils/webGLUtils.js +72 -72
  66. package/src/utils/zoomUtils.js +142 -142
@@ -1,93 +1,93 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- /**
5
- * A multi resolution dataset of grid cells.
6
- * It consists of different {@link Dataset}s for each resolution.
7
- *
8
- * @abstract
9
- *
10
- * @module core
11
- * @author Joseph Davies, Julien Gaffuri
12
- */
13
- export class MultiResolutionDataset {
14
- /**
15
- * @param {Array.<number>} resolutions The resolutions of the datasets, in CRS geographical unit.
16
- * @param {Array.<import("./Dataset").Dataset>|function(number):import("./Dataset").Dataset} datasets The datasets list, one per resolution. Or a function that returns a dataset from a resolution value.
17
- * @param { {preprocess?:function(import("./Dataset").Cell):boolean} } opts Options. preprocess: A function to apply on each dataset cell to prepare its values. Can be used also to select cells to keep.
18
- */
19
- constructor(resolutions, datasets, opts = {}) {
20
- opts = opts || {}
21
-
22
- /** The resolutions of the datasets, in CRS geographical unit.
23
- * @type {Array.<number>} */
24
- this.resolutions = resolutions
25
-
26
- /** The datasets. If the list is not explictely defined, build it from the resolution list with the function
27
- * @type {Array.<import("./Dataset").Dataset>} */
28
- this.datasets = typeof datasets === 'function' ? this.resolutions.map(datasets) : datasets
29
-
30
- //there must be as many datasets as resolutions
31
- if (this.datasets.length > 1 && this.datasets.length != this.resolutions.length)
32
- throw new Error(
33
- 'Uncompatible number of datasets and resolutions: ' +
34
- this.datasets.length +
35
- ' ' +
36
- this.resolutions.length
37
- )
38
-
39
- //set dataset preprocesses if specified
40
- if (opts.preprocess) this.setPrepocesses(opts.preprocess)
41
- }
42
-
43
- /**
44
- * Return the relevant dataset for a specified zoom.
45
- * @param {number} z
46
- * @param {number} minPixelsPerCell
47
- * @returns {import("./Dataset").Dataset|undefined}
48
- * */
49
- getDataset(z, minPixelsPerCell) {
50
- //special case whith single dataset
51
- if (this.datasets.length == 1) return this.datasets[0]
52
-
53
- const rs = this.resolutions
54
- let i = 0
55
- let z_ = rs[i] / minPixelsPerCell
56
- while (z_ < z && i < rs.length) {
57
- i++
58
- z_ = rs[i] / minPixelsPerCell
59
- }
60
- //if (i == 0) return this.dataset.datasets[0];
61
- //return this.dataset.datasets[i - 1];
62
- if (i == rs.length) return this.datasets[rs.length - 1]
63
- return this.datasets[i]
64
- }
65
-
66
- /**
67
- * Set a preprocess function for all datasets.
68
- * This is a function applied on each cell after it has been loaded.
69
- *
70
- * @param {function(import("./Dataset").Cell):boolean} preprocess
71
- * @returns {this}
72
- */
73
- setPrepocesses(preprocess) {
74
- for (let ds of this.datasets) ds.preprocess = preprocess
75
- return this
76
- }
77
-
78
- /**
79
- * A function to ease the creation of multi resolution datasets.
80
- *
81
- * @param {Array.<number>} resolutions The resolutions of the datasets, in CRS geographical unit
82
- * @param {function(number):import("./Dataset").Dataset} resToDataset Function returning a dataset from a resolution
83
- * @param { {preprocess?:function(import("./Dataset").Cell):boolean} } opts Options. preprocess: A function to apply on each dataset cell to prepare its values
84
- * @returns {MultiResolutionDataset}
85
- */
86
- /*static make(resolutions, resToDataset, opts) {
87
- //make datasets
88
- const dsc = []
89
- for (const res of resolutions) dsc.push(resToDataset(res))
90
- //make multi resolution dataset
91
- return new MultiResolutionDataset(dsc, resolutions, opts)
92
- }*/
93
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ /**
5
+ * A multi resolution dataset of grid cells.
6
+ * It consists of different {@link Dataset}s for each resolution.
7
+ *
8
+ * @abstract
9
+ *
10
+ * @module core
11
+ * @author Joseph Davies, Julien Gaffuri
12
+ */
13
+ export class MultiResolutionDataset {
14
+ /**
15
+ * @param {Array.<number>} resolutions The resolutions of the datasets, in CRS geographical unit.
16
+ * @param {Array.<import("./Dataset").Dataset>|function(number):import("./Dataset").Dataset} datasets The datasets list, one per resolution. Or a function that returns a dataset from a resolution value.
17
+ * @param { {preprocess?:function(import("./Dataset").Cell):boolean} } opts Options. preprocess: A function to apply on each dataset cell to prepare its values. Can be used also to select cells to keep.
18
+ */
19
+ constructor(resolutions, datasets, opts = {}) {
20
+ opts = opts || {}
21
+
22
+ /** The resolutions of the datasets, in CRS geographical unit.
23
+ * @type {Array.<number>} */
24
+ this.resolutions = resolutions
25
+
26
+ /** The datasets. If the list is not explictely defined, build it from the resolution list with the function
27
+ * @type {Array.<import("./Dataset").Dataset>} */
28
+ this.datasets = typeof datasets === 'function' ? this.resolutions.map(datasets) : datasets
29
+
30
+ //there must be as many datasets as resolutions
31
+ if (this.datasets.length > 1 && this.datasets.length != this.resolutions.length)
32
+ throw new Error(
33
+ 'Uncompatible number of datasets and resolutions: ' +
34
+ this.datasets.length +
35
+ ' ' +
36
+ this.resolutions.length
37
+ )
38
+
39
+ //set dataset preprocesses if specified
40
+ if (opts.preprocess) this.setPrepocesses(opts.preprocess)
41
+ }
42
+
43
+ /**
44
+ * Return the relevant dataset for a specified zoom.
45
+ * @param {number} z
46
+ * @param {number} minPixelsPerCell
47
+ * @returns {import("./Dataset").Dataset|undefined}
48
+ * */
49
+ getDataset(z, minPixelsPerCell) {
50
+ //special case whith single dataset
51
+ if (this.datasets.length == 1) return this.datasets[0]
52
+
53
+ const rs = this.resolutions
54
+ let i = 0
55
+ let z_ = rs[i] / minPixelsPerCell
56
+ while (z_ < z && i < rs.length) {
57
+ i++
58
+ z_ = rs[i] / minPixelsPerCell
59
+ }
60
+ //if (i == 0) return this.dataset.datasets[0];
61
+ //return this.dataset.datasets[i - 1];
62
+ if (i == rs.length) return this.datasets[rs.length - 1]
63
+ return this.datasets[i]
64
+ }
65
+
66
+ /**
67
+ * Set a preprocess function for all datasets.
68
+ * This is a function applied on each cell after it has been loaded.
69
+ *
70
+ * @param {function(import("./Dataset").Cell):boolean} preprocess
71
+ * @returns {this}
72
+ */
73
+ setPrepocesses(preprocess) {
74
+ for (let ds of this.datasets) ds.preprocess = preprocess
75
+ return this
76
+ }
77
+
78
+ /**
79
+ * A function to ease the creation of multi resolution datasets.
80
+ *
81
+ * @param {Array.<number>} resolutions The resolutions of the datasets, in CRS geographical unit
82
+ * @param {function(number):import("./Dataset").Dataset} resToDataset Function returning a dataset from a resolution
83
+ * @param { {preprocess?:function(import("./Dataset").Cell):boolean} } opts Options. preprocess: A function to apply on each dataset cell to prepare its values
84
+ * @returns {MultiResolutionDataset}
85
+ */
86
+ /*static make(resolutions, resToDataset, opts) {
87
+ //make datasets
88
+ const dsc = []
89
+ for (const res of resolutions) dsc.push(resToDataset(res))
90
+ //make multi resolution dataset
91
+ return new MultiResolutionDataset(dsc, resolutions, opts)
92
+ }*/
93
+ }
package/src/core/Style.js CHANGED
@@ -1,98 +1,98 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Drawable } from './Drawable.js'
5
-
6
- /** @typedef {"square"|"circle"|"diamond"|"donut"|"triangle_up"|"triangle_down"|"triangle_left"|"triangle_right"|"none"} Shape */
7
-
8
- /**
9
- * viewScale type
10
- * Returns an object from a list of cells,
11
- * @typedef {function(Array.<import('./Dataset.js').Cell>,number, number):*} ViewScale */
12
-
13
- /**
14
- * A style, to show a grid dataset.
15
- *
16
- * @module core
17
- * @author Joseph Davies, Julien Gaffuri
18
- */
19
- export class Style extends Drawable {
20
- /**
21
- * @abstract
22
- * @param {{filter?:function(import('./Dataset').Cell):boolean, offset?:function(import('./Dataset').Cell, number, number):{dx:number,dy:number}, visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,drawFun?:function,viewScale?:ViewScale}} opts
23
- */
24
- constructor(opts) {
25
- super(opts)
26
- opts = opts || {}
27
-
28
- /**
29
- * @type {ViewScale|undefined} */
30
- this.viewScale = opts.viewScale
31
-
32
- /** A filter function to apply to the cell list, to filter out some cells not to be drawn (such as for example the cells with value=0).
33
- * @protected
34
- * @type {(function(import('./Dataset').Cell):boolean) | undefined} */
35
- this.filter = opts.filter || undefined
36
-
37
- /** An offset. This is to alter the position of all symbols in a given direction. In geographical unit.
38
- * @protected
39
- * @type {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} */
40
- this.offset = opts.offset || ((c, r, z) => ({ dx: 0, dy: 0 }))
41
-
42
- /** A draw function for the style.
43
- * @type {function|undefined} */
44
- this.drawFun = opts.drawFun
45
-
46
- /**
47
- * @public
48
- * @type {Array.<import("./Legend").Legend>} */
49
- this.legends = []
50
- }
51
-
52
- /**
53
- * Draw cells.
54
- *
55
- * @param {Array.<import('./Dataset').Cell>} cells The cells to draw.
56
- * @param {import("./GeoCanvas").GeoCanvas} geoCanvas The canvas where to draw them.
57
- * @param {number} resolution Their resolution (in geographic unit)
58
- * @abstract
59
- */
60
- draw(cells, geoCanvas, resolution) {
61
- if (this.drawFun) this.drawFun(cells, geoCanvas, resolution)
62
- else throw new Error('Method draw not implemented.')
63
- }
64
-
65
- //getters and setters
66
-
67
- /** @returns {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} */
68
- getOffset() {
69
- return this.offset
70
- }
71
- /** @param {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} val @returns {this} */
72
- setOffset(val) {
73
- this.offset = val
74
- return this
75
- }
76
-
77
- /** Update legends of the style, if any
78
- * @param {object} opts
79
- * @returns {this} */
80
- updateLegends(opts) {
81
- Style.updateLegendsRecursive(this.legends, opts)
82
- return this
83
- }
84
-
85
- /** @private */
86
- static updateLegendsRecursive(lg, opts) {
87
- if (Array.isArray(lg)) for (const lg_ of lg) this.updateLegendsRecursive(lg_, opts)
88
- else lg.update(opts)
89
- }
90
-
91
- /**
92
- * @param {Array.<import("./Legend").Legend>} legends
93
- * @returns {this} */
94
- addLegends(legends) {
95
- for (let legend of legends) this.legends.push(legend)
96
- return this
97
- }
98
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Drawable } from './Drawable.js'
5
+
6
+ /** @typedef {"square"|"circle"|"diamond"|"donut"|"triangle_up"|"triangle_down"|"triangle_left"|"triangle_right"|"none"} Shape */
7
+
8
+ /**
9
+ * viewScale type
10
+ * Returns an object from a list of cells,
11
+ * @typedef {function(Array.<import('./Dataset.js').Cell>,number, number):*} ViewScale */
12
+
13
+ /**
14
+ * A style, to show a grid dataset.
15
+ *
16
+ * @module core
17
+ * @author Joseph Davies, Julien Gaffuri
18
+ */
19
+ export class Style extends Drawable {
20
+ /**
21
+ * @abstract
22
+ * @param {{filter?:function(import('./Dataset').Cell):boolean, offset?:function(import('./Dataset').Cell, number, number):{dx:number,dy:number}, visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,drawFun?:function,viewScale?:ViewScale}} opts
23
+ */
24
+ constructor(opts) {
25
+ super(opts)
26
+ opts = opts || {}
27
+
28
+ /**
29
+ * @type {ViewScale|undefined} */
30
+ this.viewScale = opts.viewScale
31
+
32
+ /** A filter function to apply to the cell list, to filter out some cells not to be drawn (such as for example the cells with value=0).
33
+ * @protected
34
+ * @type {(function(import('./Dataset').Cell):boolean) | undefined} */
35
+ this.filter = opts.filter || undefined
36
+
37
+ /** An offset. This is to alter the position of all symbols in a given direction. In geographical unit.
38
+ * @protected
39
+ * @type {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} */
40
+ this.offset = opts.offset || ((c, r, z) => ({ dx: 0, dy: 0 }))
41
+
42
+ /** A draw function for the style.
43
+ * @type {function|undefined} */
44
+ this.drawFun = opts.drawFun
45
+
46
+ /**
47
+ * @public
48
+ * @type {Array.<import("./Legend").Legend>} */
49
+ this.legends = []
50
+ }
51
+
52
+ /**
53
+ * Draw cells.
54
+ *
55
+ * @param {Array.<import('./Dataset').Cell>} cells The cells to draw.
56
+ * @param {import("./GeoCanvas").GeoCanvas} geoCanvas The canvas where to draw them.
57
+ * @param {number} resolution Their resolution (in geographic unit)
58
+ * @abstract
59
+ */
60
+ draw(cells, geoCanvas, resolution) {
61
+ if (this.drawFun) this.drawFun(cells, geoCanvas, resolution)
62
+ else throw new Error('Method draw not implemented.')
63
+ }
64
+
65
+ //getters and setters
66
+
67
+ /** @returns {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} */
68
+ getOffset() {
69
+ return this.offset
70
+ }
71
+ /** @param {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} val @returns {this} */
72
+ setOffset(val) {
73
+ this.offset = val
74
+ return this
75
+ }
76
+
77
+ /** Update legends of the style, if any
78
+ * @param {object} opts
79
+ * @returns {this} */
80
+ updateLegends(opts) {
81
+ Style.updateLegendsRecursive(this.legends, opts)
82
+ return this
83
+ }
84
+
85
+ /** @private */
86
+ static updateLegendsRecursive(lg, opts) {
87
+ if (Array.isArray(lg)) for (const lg_ of lg) this.updateLegendsRecursive(lg_, opts)
88
+ else lg.update(opts)
89
+ }
90
+
91
+ /**
92
+ * @param {Array.<import("./Legend").Legend>} legends
93
+ * @returns {this} */
94
+ addLegends(legends) {
95
+ for (let legend of legends) this.legends.push(legend)
96
+ return this
97
+ }
98
+ }