gridviz 3.0.15 → 3.0.16

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 +7959 -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 +495 -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,134 +1,133 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../core/Style.js'
5
- import { randomNormal } from 'd3-random'
6
- import { checkWebGLSupport, makeWebGLCanvas } from '../utils/webGLUtils.js'
7
- import { WebGLSquareColoring } from '../utils/WebGLSquareColoring.js'
8
- import { color } from 'd3-color'
9
-
10
- /**
11
- *
12
- * @module style
13
- * @author Julien Gaffuri
14
- */
15
- export class DotDensityStyle extends Style {
16
- /** @param {object} opts */
17
- constructor(opts) {
18
- super(opts)
19
- opts = opts || {}
20
-
21
- /** A function returning the number of dots for a cell value.
22
- * @type {function(import('../core/Dataset.js').Cell, number, number, object):number} */
23
- this.dotNumber = opts.dotNumber || ((cell, resolution) => resolution / 100)//(c,r,z,vs) => {}
24
-
25
- /** The color of the dots. Same color for all dots within a cell.
26
- * @type {function(import('../core/Dataset.js').Cell, number, number, object):string} */
27
- this.color = opts.color || (() => '#FF5733') //(c,r,z,vs) => {}
28
-
29
- /** A function returning the size of the dots, in geo unit. Same size for all cells.
30
- * @type {function(number, number,object):number} */
31
- this.dotSize = opts.dotSize || ((resolution, z) => 1.5 * z) //(c,r,z,vs) => {}
32
-
33
- /** A function returning the sigma of the dots distribution. Same value for all cells.
34
- * @type {function(number, number,object):number} */
35
- this.sigma = opts.sigma || ((resolution, z) => resolution / 2)//(c,r,z,vs) => {}
36
- }
37
-
38
- /**
39
- * Draw cells as text.
40
- *
41
- * @param {Array.<import("../core/Dataset").Cell>} cells
42
- * @param {import("../core/GeoCanvas").GeoCanvas} geoCanvas
43
- * @param {number} resolution
44
- */
45
- draw(cells, geoCanvas, resolution) {
46
-
47
- //filter
48
- if (this.filter) cells = cells.filter(this.filter)
49
-
50
- //
51
- const z = geoCanvas.view.z
52
-
53
- //get view scale
54
- const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
55
-
56
- //get size
57
- const sGeo = this.dotSize ? this.dotSize(resolution, z, viewScale) : z
58
-
59
- //make random function
60
- const sig = this.sigma ? this.sigma(resolution, z, viewScale) : resolution * 0.4
61
- const rand = randomNormal(0, sig)
62
-
63
- if (checkWebGLSupport()) {
64
- //create canvas and webgl renderer
65
- const cvWGL = makeWebGLCanvas(geoCanvas.w + '', geoCanvas.h + '')
66
- if (!cvWGL) {
67
- console.error('No webGL')
68
- return
69
- }
70
-
71
- //create webGL program
72
- const prog = new WebGLSquareColoring(cvWGL.gl, sGeo / z)
73
-
74
- const r2 = resolution / 2
75
-
76
- for (let cell of cells) {
77
- //get color
78
- const col = this.color(cell, resolution, z, viewScale)
79
- if (!col || col === 'none') continue
80
-
81
- //number of dots
82
- const dotNumber = this.dotNumber(cell, resolution, z, viewScale)
83
-
84
- //get offset
85
- const offset = this.offset(cell, resolution, z)
86
-
87
- //cell center
88
- const cx = cell.x + offset.dx + r2
89
- const cy = cell.y + offset.dy + r2
90
-
91
- //convert color
92
- const cc = color(col)
93
- if (!cc) return
94
-
95
- //random points
96
- for (let i = 0; i <= dotNumber; i++)
97
- prog.addPointData2(cx + rand(), cy + rand(), cc.r, cc.g, cc.b, cc.opacity)
98
- }
99
-
100
- //draw
101
- prog.draw(geoCanvas.getWebGLTransform())
102
-
103
- //draw in canvas geo
104
- geoCanvas.initCanvasTransform()
105
- geoCanvas.ctx.drawImage(cvWGL.canvas, 0, 0)
106
-
107
- } else {
108
- for (let cell of cells) {
109
-
110
- //get color
111
- const col = this.color(cell, resolution, z, viewScale)
112
- if (!col || col === 'none') continue
113
- //set color
114
- geoCanvas.ctx.fillStyle = col
115
-
116
- //number of dots
117
- const dotNumber = this.dotNumber(cell, resolution, z, viewScale)
118
-
119
- //get offset
120
- const offset = this.offset(cell, resolution, z)
121
-
122
- //draw random dots
123
- const cx = cell.x + offset.dx + resolution / 2,
124
- cy = cell.y + offset.dy + resolution / 2
125
- for (let i = 0; i <= dotNumber; i++) {
126
- geoCanvas.ctx.fillRect(cx + rand(), cy + rand(), sGeo, sGeo)
127
- }
128
- }
129
- }
130
-
131
- //update legends
132
- this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
133
- }
134
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../core/Style.js'
5
+ import { randomNormal } from 'd3-random'
6
+ import { checkWebGLSupport, makeWebGLCanvas } from '../utils/webGLUtils.js'
7
+ import { WebGLSquareColoring } from '../utils/WebGLSquareColoring.js'
8
+ import { color } from 'd3-color'
9
+
10
+ /**
11
+ *
12
+ * @module style
13
+ * @author Julien Gaffuri
14
+ */
15
+ export class DotDensityStyle extends Style {
16
+ /** @param {object} opts */
17
+ constructor(opts) {
18
+ super(opts)
19
+ opts = opts || {}
20
+
21
+ /** A function returning the number of dots for a cell value.
22
+ * @type {function(import('../core/Dataset.js').Cell, number, number, object):number} */
23
+ this.dotNumber = opts.dotNumber || ((cell, resolution) => resolution / 100) //(c,r,z,vs) => {}
24
+
25
+ /** The color of the dots. Same color for all dots within a cell.
26
+ * @type {function(import('../core/Dataset.js').Cell, number, number, object):string} */
27
+ this.color = opts.color || (() => '#FF5733') //(c,r,z,vs) => {}
28
+
29
+ /** A function returning the size of the dots, in geo unit. Same size for all cells.
30
+ * @type {function(number, number,object):number} */
31
+ this.dotSize = opts.dotSize || ((resolution, z) => 1.5 * z) //(c,r,z,vs) => {}
32
+
33
+ /** A function returning the sigma of the dots distribution. Same value for all cells.
34
+ * @type {function(number, number,object):number} */
35
+ this.sigma = opts.sigma || ((resolution, z) => resolution / 2) //(c,r,z,vs) => {}
36
+ }
37
+
38
+ /**
39
+ * Draw cells as text.
40
+ *
41
+ * @param {Array.<import("../core/Dataset").Cell>} cells
42
+ * @param {import("../core/GeoCanvas").GeoCanvas} geoCanvas
43
+ * @param {number} resolution
44
+ */
45
+ draw(cells, geoCanvas, resolution) {
46
+ //filter
47
+ if (this.filter) cells = cells.filter(this.filter)
48
+
49
+ //
50
+ const z = geoCanvas.view.z
51
+
52
+ //get view scale
53
+ const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
54
+
55
+ //get size
56
+ const sGeo = this.dotSize ? this.dotSize(resolution, z, viewScale) : z
57
+
58
+ //make random function
59
+ const sig = this.sigma ? this.sigma(resolution, z, viewScale) : resolution * 0.4
60
+ const rand = randomNormal(0, sig)
61
+
62
+ const ctx = geoCanvas.offscreenCtx
63
+
64
+ if (checkWebGLSupport()) {
65
+ //create canvas and webgl renderer
66
+ const cvWGL = makeWebGLCanvas(geoCanvas.w + '', geoCanvas.h + '')
67
+ if (!cvWGL) {
68
+ console.error('No webGL')
69
+ return
70
+ }
71
+
72
+ //create webGL program
73
+ const prog = new WebGLSquareColoring(cvWGL.gl, sGeo / z)
74
+
75
+ const r2 = resolution / 2
76
+
77
+ for (let cell of cells) {
78
+ //get color
79
+ const col = this.color(cell, resolution, z, viewScale)
80
+ if (!col || col === 'none') continue
81
+
82
+ //number of dots
83
+ const dotNumber = this.dotNumber(cell, resolution, z, viewScale)
84
+
85
+ //get offset
86
+ const offset = this.offset(cell, resolution, z)
87
+
88
+ //cell center
89
+ const cx = cell.x + offset.dx + r2
90
+ const cy = cell.y + offset.dy + r2
91
+
92
+ //convert color
93
+ const cc = color(col)
94
+ if (!cc) return
95
+
96
+ //random points
97
+ for (let i = 0; i <= dotNumber; i++)
98
+ prog.addPointData2(cx + rand(), cy + rand(), cc.r, cc.g, cc.b, cc.opacity)
99
+ }
100
+
101
+ //draw
102
+ prog.draw(geoCanvas.getWebGLTransform())
103
+
104
+ //draw in canvas geo
105
+ geoCanvas.initCanvasTransform()
106
+ ctx.drawImage(cvWGL.canvas, 0, 0)
107
+ } else {
108
+ for (let cell of cells) {
109
+ //get color
110
+ const col = this.color(cell, resolution, z, viewScale)
111
+ if (!col || col === 'none') continue
112
+ //set color
113
+ ctx.fillStyle = col
114
+
115
+ //number of dots
116
+ const dotNumber = this.dotNumber(cell, resolution, z, viewScale)
117
+
118
+ //get offset
119
+ const offset = this.offset(cell, resolution, z)
120
+
121
+ //draw random dots
122
+ const cx = cell.x + offset.dx + resolution / 2,
123
+ cy = cell.y + offset.dy + resolution / 2
124
+ for (let i = 0; i <= dotNumber; i++) {
125
+ ctx.fillRect(cx + rand(), cy + rand(), sGeo, sGeo)
126
+ }
127
+ }
128
+ }
129
+
130
+ //update legends
131
+ this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
132
+ }
133
+ }
@@ -1,102 +1,100 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../core/Style.js'
5
-
6
- /**
7
- * @module style
8
- * @author Julien Gaffuri
9
- */
10
- export class ImageStyle extends Style {
11
-
12
- /** @param {object} opts */
13
- constructor(opts) {
14
- super(opts)
15
- opts = opts || {}
16
-
17
- /** A function returning the image URL of a cell.
18
- * @type {function(import('../core/Dataset.js').Cell, number, number, object):string} */
19
- this.image = opts.image || (() => '') //(c,r,z,vs) => {}
20
-
21
- /** The image size in ground meters
22
- * @type {function(import('../core/Dataset.js').Cell, number, number, object):number} */
23
- this.size = opts.size || ((cell, resolution) => resolution)
24
-
25
- /** Dictionnary of preloaded images. url -> image
26
- * @private
27
- * @type {object} */
28
- this.cache = {}
29
-
30
- }
31
-
32
- /**
33
- * @param {Array.<import("../core/Dataset.js").Cell>} cells
34
- * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas
35
- * @param {number} resolution
36
- * @override
37
- */
38
- async draw(cells, geoCanvas, resolution) {
39
-
40
- //
41
- const z = geoCanvas.view.z,
42
- resolutionPix = resolution / z
43
-
44
- //get view scale
45
- const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
46
-
47
- //draw in screen coordinates
48
- geoCanvas.initCanvasTransform()
49
-
50
- //
51
- for (let cell of cells) {
52
-
53
- //get cell image url
54
- const url = this.image(cell, resolution, z, viewScale)
55
- if (!url) continue
56
-
57
- //size and position values
58
- let sizePix = this.size(cell, resolution, z, viewScale) / z
59
- if (!sizePix) continue
60
-
61
- //get image from cache
62
- const image = this.cache[url]
63
-
64
- //loading, keep waiting
65
- if (image == "loading") return;
66
-
67
- //no image: load it
68
- else if (!image) {
69
- //tag as loading
70
- this.cache[url] = "loading"
71
-
72
- //define image
73
- const img = new Image()
74
- img.onload = () => {
75
- //store image data in cache and redraw
76
- this.cache[url] = img
77
- geoCanvas.redraw()
78
- }
79
- img.onerror = () => {
80
- //case when no image
81
- console.warn("Could not retrieve image from", url)
82
- }
83
- //set URL to launch the download
84
- img.src = url
85
-
86
- } else {
87
- //draw image
88
- const d = (resolutionPix - sizePix) / 2
89
- try {
90
- geoCanvas.ctx.drawImage(image, geoCanvas.geoToPixX(cell.x) + d, geoCanvas.geoToPixY(cell.y) + d - resolutionPix, sizePix, sizePix)
91
- } catch (error) {
92
- console.error(error)
93
- }
94
- }
95
-
96
- }
97
-
98
-
99
- //update legends
100
- this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
101
- }
102
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../core/Style.js'
5
+
6
+ /**
7
+ * @module style
8
+ * @author Julien Gaffuri
9
+ */
10
+ export class ImageStyle extends Style {
11
+ /** @param {object} opts */
12
+ constructor(opts) {
13
+ super(opts)
14
+ opts = opts || {}
15
+
16
+ /** A function returning the image URL of a cell.
17
+ * @type {function(import('../core/Dataset.js').Cell, number, number, object):string} */
18
+ this.image = opts.image || (() => '') //(c,r,z,vs) => {}
19
+
20
+ /** The image size in ground meters
21
+ * @type {function(import('../core/Dataset.js').Cell, number, number, object):number} */
22
+ this.size = opts.size || ((cell, resolution) => resolution)
23
+
24
+ /** Dictionnary of preloaded images. url -> image
25
+ * @private
26
+ * @type {object} */
27
+ this.cache = {}
28
+ }
29
+
30
+ /**
31
+ * @param {Array.<import("../core/Dataset.js").Cell>} cells
32
+ * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas
33
+ * @param {number} resolution
34
+ * @override
35
+ */
36
+ async draw(cells, geoCanvas, resolution) {
37
+ //
38
+ const z = geoCanvas.view.z,
39
+ resolutionPix = resolution / z
40
+
41
+ //get view scale
42
+ const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
43
+
44
+ //draw in screen coordinates
45
+ geoCanvas.initCanvasTransform()
46
+
47
+ //
48
+ for (let cell of cells) {
49
+ //get cell image url
50
+ const url = this.image(cell, resolution, z, viewScale)
51
+ if (!url) continue
52
+
53
+ //size and position values
54
+ let sizePix = this.size(cell, resolution, z, viewScale) / z
55
+ if (!sizePix) continue
56
+
57
+ //get image from cache
58
+ const image = this.cache[url]
59
+
60
+ //loading, keep waiting
61
+ if (image == 'loading') return
62
+ //no image: load it
63
+ else if (!image) {
64
+ //tag as loading
65
+ this.cache[url] = 'loading'
66
+
67
+ //define image
68
+ const img = new Image()
69
+ img.onload = () => {
70
+ //store image data in cache and redraw
71
+ this.cache[url] = img
72
+ geoCanvas.redraw()
73
+ }
74
+ img.onerror = () => {
75
+ //case when no image
76
+ console.warn('Could not retrieve image from', url)
77
+ }
78
+ //set URL to launch the download
79
+ img.src = url
80
+ } else {
81
+ //draw image
82
+ const d = (resolutionPix - sizePix) / 2
83
+ try {
84
+ geoCanvas.offscreenCtx.drawImage(
85
+ image,
86
+ geoCanvas.geoToPixX(cell.x) + d,
87
+ geoCanvas.geoToPixY(cell.y) + d - resolutionPix,
88
+ sizePix,
89
+ sizePix
90
+ )
91
+ } catch (error) {
92
+ console.error(error)
93
+ }
94
+ }
95
+ }
96
+
97
+ //update legends
98
+ this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
99
+ }
100
+ }