gridviz 3.0.22 → 3.0.24

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 +8618 -8579
  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 -101
  8. package/src/core/Dataset.js +154 -154
  9. package/src/core/Drawable.js +78 -78
  10. package/src/core/GeoCanvas.js +437 -430
  11. package/src/core/Layer.js +23 -23
  12. package/src/core/Legend.js +108 -108
  13. package/src/core/Map.js +542 -516
  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 +214 -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,194 +1,194 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Layer } from '../core/Layer.js'
5
- import { csv } from 'd3-fetch'
6
-
7
- /** A label. The name is the text to show. (x,y) are the coordinates in the same CRS as the grid.
8
- * @typedef {{name: string, x:number, y:number }} Label */
9
-
10
- /**
11
- * A (generic) layer for placename labels, to be shown on top of the grid layers.
12
- * The input is a CSV file with the position (x, y) of the labels and name + some other info on the label importance.
13
- * If the label data is not in the expected format or in the same CRS as the grid, it can be corrected with the "preprocess" function.
14
- * The selection of the label, their style (font, weight, etc.) and color can be specified depending on their importance and the zoom level.
15
- *
16
- * @module layer
17
- * @author Joseph Davies, Julien Gaffuri
18
- */
19
- export class LabelLayer extends Layer {
20
- /**
21
- * @param {object} opts
22
- */
23
- constructor(opts) {
24
- super(opts)
25
- opts = opts || {}
26
-
27
- /**
28
- * The URL of the label data, as CSV file.
29
- * The file should contain the information for each label such as the text, the position and other information for the display of the label according to the zoom level.
30
- * If necessary, this data can be reformated with the 'preprocess' parameter.
31
- * @private
32
- * @type {string} */
33
- this.url = opts.url
34
-
35
- /** Specify if and how a label should be drawn, depending on its importance and the zoom level.
36
- * @private
37
- * @type {function(Label,number):string} */
38
- this.style = opts.style || (() => '1.2em Arial')
39
-
40
- /** Specify the label color, depending on its importance and the zoom level.
41
- * @private
42
- * @type {function(Label,number):string} */
43
- this.color = opts.color || (opts.dark ? () => 'white' : () => 'black')
44
-
45
- /** Specify the label halo color, depending on its importance and the zoom level.
46
- * @private
47
- * @type {function(Label,number):string} */
48
- this.haloColor = opts.haloColor || (opts.dark ? () => 'black' : () => 'white')
49
-
50
- /** Specify the label halo width, depending on its importance and the zoom level.
51
- * @private
52
- * @type {function(Label,number):number} */
53
- this.haloWidth = opts.haloWidth || (() => 2.5)
54
-
55
- /** The anchor where to draw the text, from label position. See HTML-canvas textAlign property.
56
- * "left" || "right" || "center" || "start" || "end"
57
- * @private
58
- * @type {CanvasTextAlign} */
59
- this.textAlign = opts.textAlign || 'start'
60
-
61
- /**
62
- * @private
63
- * @type {Array.<number>} */
64
- this.offsetPix = opts.offsetPix || [5, 5]
65
-
66
- /**
67
- * A preprocess to run on each label after loading.
68
- * It can be used to apply some specific treatment before, format the label data, project coordinates, etc.
69
- * Return false if the label should not be kept.
70
- * @private
71
- * @type {function(Label):boolean} */
72
- this.preprocess = opts.preprocess
73
-
74
- /**
75
- * @private
76
- * @type {Array.<Label> | undefined} */
77
- this.labels = undefined
78
-
79
- /**
80
- * @private
81
- * @type {string} */
82
- this.loadingStatus = 'notLoaded'
83
- }
84
-
85
- /**
86
- * Draw the label layer.
87
- *
88
- * @param {import("../core/GeoCanvas").GeoCanvas} geoCanvas The canvas where to draw the layer.
89
- * @returns {void}
90
- */
91
- draw(geoCanvas) {
92
- //load labels, if not done yet.
93
- if (!this.labels) {
94
- this.load(geoCanvas.redraw)
95
- return
96
- }
97
-
98
- //
99
- const z = geoCanvas.view.z
100
- const ctx = geoCanvas.offscreenCtx
101
-
102
- //text align
103
- ctx.textAlign = this.textAlign || 'start'
104
-
105
- //line join and cap
106
- ctx.lineJoin = 'bevel' //|| "round" || "miter";
107
- ctx.lineCap = 'butt' //|| "round" || "square";
108
-
109
- //draw in pix coordinates
110
- geoCanvas.initCanvasTransform()
111
-
112
- //draw labels, one by one
113
- for (const lb of this.labels) {
114
- //get label style
115
- const st = this.style(lb, z)
116
- if (!st) continue
117
- ctx.font = st
118
-
119
- //check label within the view, to be drawn
120
- if (!geoCanvas.toDraw(lb)) continue
121
-
122
- //position
123
- const xP = geoCanvas.geoToPixX(lb.x) + this.offsetPix[0]
124
- const yP = geoCanvas.geoToPixY(lb.y) - this.offsetPix[1]
125
-
126
- //label stroke, for the halo
127
- if (this.haloColor && this.haloWidth) {
128
- const hc = this.haloColor(lb, z)
129
- const hw = this.haloWidth(lb, z)
130
- if (hc && hw && hw > 0) {
131
- ctx.strokeStyle = hc
132
- ctx.lineWidth = hw
133
- ctx.strokeText(lb.name, xP, yP)
134
- }
135
- }
136
-
137
- //label fill
138
- if (this.color) {
139
- const col = this.color(lb, z)
140
- if (col) {
141
- ctx.fillStyle = col
142
- ctx.fillText(lb.name, xP, yP)
143
- }
144
- }
145
- }
146
- }
147
-
148
- /**
149
- * Load data for labels, from URL this.url
150
- * @param {function():void} callback
151
- * @private
152
- */
153
- async load(callback) {
154
- if (!this.url) {
155
- console.log('Failed loading labels: No URL specified. ' + this.url)
156
- this.loadingStatus = 'failed'
157
- this.labels = []
158
- return
159
- }
160
-
161
- //check if data already loaded
162
- if (this.loadingStatus != 'notLoaded') return
163
-
164
- //load data
165
- this.loadingStatus = 'loading'
166
-
167
- try {
168
- /** @type { Array.<Label> } */
169
- const data = await csv(this.url)
170
-
171
- //preprocess/filter
172
- if (this.preprocess) {
173
- this.labels = []
174
- for (const c of data) {
175
- const b = this.preprocess(c)
176
- if (b == false) continue
177
- this.labels.push(c)
178
- }
179
- } else {
180
- //store labels
181
- this.labels = data
182
- }
183
-
184
- this.loadingStatus = 'loaded'
185
-
186
- //redraw
187
- if (callback) callback()
188
- } catch (error) {
189
- console.log('Failed loading labels from ' + this.url)
190
- this.labels = []
191
- this.loadingStatus = 'failed'
192
- }
193
- }
194
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Layer } from '../core/Layer.js'
5
+ import { csv } from 'd3-fetch'
6
+
7
+ /** A label. The name is the text to show. (x,y) are the coordinates in the same CRS as the grid.
8
+ * @typedef {{name: string, x:number, y:number }} Label */
9
+
10
+ /**
11
+ * A (generic) layer for placename labels, to be shown on top of the grid layers.
12
+ * The input is a CSV file with the position (x, y) of the labels and name + some other info on the label importance.
13
+ * If the label data is not in the expected format or in the same CRS as the grid, it can be corrected with the "preprocess" function.
14
+ * The selection of the label, their style (font, weight, etc.) and color can be specified depending on their importance and the zoom level.
15
+ *
16
+ * @module layer
17
+ * @author Joseph Davies, Julien Gaffuri
18
+ */
19
+ export class LabelLayer extends Layer {
20
+ /**
21
+ * @param {object} opts
22
+ */
23
+ constructor(opts) {
24
+ super(opts)
25
+ opts = opts || {}
26
+
27
+ /**
28
+ * The URL of the label data, as CSV file.
29
+ * The file should contain the information for each label such as the text, the position and other information for the display of the label according to the zoom level.
30
+ * If necessary, this data can be reformated with the 'preprocess' parameter.
31
+ * @private
32
+ * @type {string} */
33
+ this.url = opts.url
34
+
35
+ /** Specify if and how a label should be drawn, depending on its importance and the zoom level.
36
+ * @private
37
+ * @type {function(Label,number):string} */
38
+ this.style = opts.style || (() => '1.2em Arial')
39
+
40
+ /** Specify the label color, depending on its importance and the zoom level.
41
+ * @private
42
+ * @type {function(Label,number):string} */
43
+ this.color = opts.color || (opts.dark ? () => 'white' : () => 'black')
44
+
45
+ /** Specify the label halo color, depending on its importance and the zoom level.
46
+ * @private
47
+ * @type {function(Label,number):string} */
48
+ this.haloColor = opts.haloColor || (opts.dark ? () => 'black' : () => 'white')
49
+
50
+ /** Specify the label halo width, depending on its importance and the zoom level.
51
+ * @private
52
+ * @type {function(Label,number):number} */
53
+ this.haloWidth = opts.haloWidth || (() => 2.5)
54
+
55
+ /** The anchor where to draw the text, from label position. See HTML-canvas textAlign property.
56
+ * "left" || "right" || "center" || "start" || "end"
57
+ * @private
58
+ * @type {CanvasTextAlign} */
59
+ this.textAlign = opts.textAlign || 'start'
60
+
61
+ /**
62
+ * @private
63
+ * @type {Array.<number>} */
64
+ this.offsetPix = opts.offsetPix || [5, 5]
65
+
66
+ /**
67
+ * A preprocess to run on each label after loading.
68
+ * It can be used to apply some specific treatment before, format the label data, project coordinates, etc.
69
+ * Return false if the label should not be kept.
70
+ * @private
71
+ * @type {function(Label):boolean} */
72
+ this.preprocess = opts.preprocess
73
+
74
+ /**
75
+ * @private
76
+ * @type {Array.<Label> | undefined} */
77
+ this.labels = undefined
78
+
79
+ /**
80
+ * @private
81
+ * @type {string} */
82
+ this.loadingStatus = 'notLoaded'
83
+ }
84
+
85
+ /**
86
+ * Draw the label layer.
87
+ *
88
+ * @param {import("../core/GeoCanvas").GeoCanvas} geoCanvas The canvas where to draw the layer.
89
+ * @returns {void}
90
+ */
91
+ draw(geoCanvas) {
92
+ //load labels, if not done yet.
93
+ if (!this.labels) {
94
+ this.load(geoCanvas.redraw)
95
+ return
96
+ }
97
+
98
+ //
99
+ const z = geoCanvas.view.z
100
+ const ctx = geoCanvas.offscreenCtx
101
+
102
+ //text align
103
+ ctx.textAlign = this.textAlign || 'start'
104
+
105
+ //line join and cap
106
+ ctx.lineJoin = 'bevel' //|| "round" || "miter";
107
+ ctx.lineCap = 'butt' //|| "round" || "square";
108
+
109
+ //draw in pix coordinates
110
+ geoCanvas.initCanvasTransform()
111
+
112
+ //draw labels, one by one
113
+ for (const lb of this.labels) {
114
+ //get label style
115
+ const st = this.style(lb, z)
116
+ if (!st) continue
117
+ ctx.font = st
118
+
119
+ //check label within the view, to be drawn
120
+ if (!geoCanvas.toDraw(lb)) continue
121
+
122
+ //position
123
+ const xP = geoCanvas.geoToPixX(lb.x) + this.offsetPix[0]
124
+ const yP = geoCanvas.geoToPixY(lb.y) - this.offsetPix[1]
125
+
126
+ //label stroke, for the halo
127
+ if (this.haloColor && this.haloWidth) {
128
+ const hc = this.haloColor(lb, z)
129
+ const hw = this.haloWidth(lb, z)
130
+ if (hc && hw && hw > 0) {
131
+ ctx.strokeStyle = hc
132
+ ctx.lineWidth = hw
133
+ ctx.strokeText(lb.name, xP, yP)
134
+ }
135
+ }
136
+
137
+ //label fill
138
+ if (this.color) {
139
+ const col = this.color(lb, z)
140
+ if (col) {
141
+ ctx.fillStyle = col
142
+ ctx.fillText(lb.name, xP, yP)
143
+ }
144
+ }
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Load data for labels, from URL this.url
150
+ * @param {function():void} callback
151
+ * @private
152
+ */
153
+ async load(callback) {
154
+ if (!this.url) {
155
+ console.log('Failed loading labels: No URL specified. ' + this.url)
156
+ this.loadingStatus = 'failed'
157
+ this.labels = []
158
+ return
159
+ }
160
+
161
+ //check if data already loaded
162
+ if (this.loadingStatus != 'notLoaded') return
163
+
164
+ //load data
165
+ this.loadingStatus = 'loading'
166
+
167
+ try {
168
+ /** @type { Array.<Label> } */
169
+ const data = await csv(this.url)
170
+
171
+ //preprocess/filter
172
+ if (this.preprocess) {
173
+ this.labels = []
174
+ for (const c of data) {
175
+ const b = this.preprocess(c)
176
+ if (b == false) continue
177
+ this.labels.push(c)
178
+ }
179
+ } else {
180
+ //store labels
181
+ this.labels = data
182
+ }
183
+
184
+ this.loadingStatus = 'loaded'
185
+
186
+ //redraw
187
+ if (callback) callback()
188
+ } catch (error) {
189
+ console.log('Failed loading labels from ' + this.url)
190
+ this.labels = []
191
+ this.loadingStatus = 'failed'
192
+ }
193
+ }
194
+ }
@@ -1,109 +1,109 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Legend } from '../core/Legend.js'
5
-
6
- /**
7
- * A legend element for color categrories.
8
- *
9
- * @module legend
10
- * @author Joseph Davies, Julien Gaffuri
11
- */
12
- export class ColorCategoryLegend extends Legend {
13
- /** @param {Object} opts */
14
- constructor(opts) {
15
- super(opts)
16
- opts = opts || {}
17
-
18
- //col/categories array, in display order
19
- /**
20
- * @private
21
- * @type {Array.<[string,string]>} */
22
- this.colorLabel = opts.colorLabel || [['gray', '-']]
23
-
24
- /**
25
- * @private
26
- * @type {import("../core/Style.js").Shape} */
27
- this.shape = opts.shape || 'circle'
28
- this.dimension = opts.dimension || { r: 8 }
29
- this.strokeColor = opts.strokeColor || 'gray'
30
- this.strokeWidth = opts.strokeWidth || 1
31
- }
32
-
33
- /**
34
- */
35
- update() {
36
- //clear
37
- this.div.selectAll('*').remove()
38
-
39
- //title
40
- this.makeTitle()
41
-
42
- //categories
43
- const nb = this.colorLabel.length
44
- if (nb == 0) return
45
-
46
- for (let i = 0; i < nb; i++) {
47
- const cat = this.colorLabel[i]
48
-
49
- //make div for category
50
- const d = this.div.append('div')
51
- //to enable vertical centering
52
- //.style("position", "relative")
53
-
54
- const sw = this.strokeWidth
55
-
56
- //draw graphic element: box / circle
57
- if (this.shape === 'square') {
58
- const h = this.dimension.h || 15
59
- const w = this.dimension.w || 20
60
- d.append('div')
61
- .style('display', 'inline')
62
-
63
- .append('svg')
64
- .attr('width', w + 2 * sw)
65
- .attr('height', h + 2 * sw)
66
-
67
- .append('rect')
68
- .attr('x', sw)
69
- .attr('y', sw)
70
- .attr('width', w)
71
- .attr('height', h)
72
- .style('fill', cat[0])
73
- .style('stroke', this.strokeColor)
74
- .style('stroke-width', this.strokeWidth)
75
- } else if (this.shape === 'circle') {
76
- const r = this.dimension.r || 8
77
- const h = 2 * r + 2 * sw
78
- d.append('div')
79
- .style('display', 'inline')
80
-
81
- .append('svg')
82
- .attr('width', h)
83
- .attr('height', h)
84
-
85
- .append('circle')
86
- .attr('cx', r + sw)
87
- .attr('cy', r + sw)
88
- .attr('r', r)
89
- .style('fill', cat[0])
90
- .style('stroke', this.strokeColor)
91
- .style('stroke-width', this.strokeWidth)
92
- } else {
93
- throw new Error('Unexpected shape:' + this.shape)
94
- }
95
-
96
- //write label text
97
- d.append('div')
98
- //show on right of graphic
99
- .style('display', 'inline')
100
-
101
- //center vertically
102
- //.style("position", "absolute").style("top", "0").style("bottom", "0")
103
-
104
- .style('padding-left', '5px')
105
- .style('font-size', this.labelFontSize)
106
- .text(cat[1])
107
- }
108
- }
109
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Legend } from '../core/Legend.js'
5
+
6
+ /**
7
+ * A legend element for color categrories.
8
+ *
9
+ * @module legend
10
+ * @author Joseph Davies, Julien Gaffuri
11
+ */
12
+ export class ColorCategoryLegend extends Legend {
13
+ /** @param {Object} opts */
14
+ constructor(opts) {
15
+ super(opts)
16
+ opts = opts || {}
17
+
18
+ //col/categories array, in display order
19
+ /**
20
+ * @private
21
+ * @type {Array.<[string,string]>} */
22
+ this.colorLabel = opts.colorLabel || [['gray', '-']]
23
+
24
+ /**
25
+ * @private
26
+ * @type {import("../core/Style.js").Shape} */
27
+ this.shape = opts.shape || 'circle'
28
+ this.dimension = opts.dimension || { r: 8 }
29
+ this.strokeColor = opts.strokeColor || 'gray'
30
+ this.strokeWidth = opts.strokeWidth || 1
31
+ }
32
+
33
+ /**
34
+ */
35
+ update() {
36
+ //clear
37
+ this.div.selectAll('*').remove()
38
+
39
+ //title
40
+ this.makeTitle()
41
+
42
+ //categories
43
+ const nb = this.colorLabel.length
44
+ if (nb == 0) return
45
+
46
+ for (let i = 0; i < nb; i++) {
47
+ const cat = this.colorLabel[i]
48
+
49
+ //make div for category
50
+ const d = this.div.append('div')
51
+ //to enable vertical centering
52
+ //.style("position", "relative")
53
+
54
+ const sw = this.strokeWidth
55
+
56
+ //draw graphic element: box / circle
57
+ if (this.shape === 'square') {
58
+ const h = this.dimension.h || 15
59
+ const w = this.dimension.w || 20
60
+ d.append('div')
61
+ .style('display', 'inline')
62
+
63
+ .append('svg')
64
+ .attr('width', w + 2 * sw)
65
+ .attr('height', h + 2 * sw)
66
+
67
+ .append('rect')
68
+ .attr('x', sw)
69
+ .attr('y', sw)
70
+ .attr('width', w)
71
+ .attr('height', h)
72
+ .style('fill', cat[0])
73
+ .style('stroke', this.strokeColor)
74
+ .style('stroke-width', this.strokeWidth)
75
+ } else if (this.shape === 'circle') {
76
+ const r = this.dimension.r || 8
77
+ const h = 2 * r + 2 * sw
78
+ d.append('div')
79
+ .style('display', 'inline')
80
+
81
+ .append('svg')
82
+ .attr('width', h)
83
+ .attr('height', h)
84
+
85
+ .append('circle')
86
+ .attr('cx', r + sw)
87
+ .attr('cy', r + sw)
88
+ .attr('r', r)
89
+ .style('fill', cat[0])
90
+ .style('stroke', this.strokeColor)
91
+ .style('stroke-width', this.strokeWidth)
92
+ } else {
93
+ throw new Error('Unexpected shape:' + this.shape)
94
+ }
95
+
96
+ //write label text
97
+ d.append('div')
98
+ //show on right of graphic
99
+ .style('display', 'inline')
100
+
101
+ //center vertically
102
+ //.style("position", "absolute").style("top", "0").style("bottom", "0")
103
+
104
+ .style('padding-left', '5px')
105
+ .style('font-size', this.labelFontSize)
106
+ .text(cat[1])
107
+ }
108
+ }
109
+ }