gridviz 3.0.14 → 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 -7860
  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 -203
  54. package/src/utils/utils.js +58 -63
  55. package/src/utils/webGLUtils.js +72 -70
@@ -1,128 +1,127 @@
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 JoyPlotStyle extends Style {
11
- /** @param {object} opts */
12
- constructor(opts) {
13
- super(opts)
14
- opts = opts || {}
15
-
16
- /** A function returning the height of a cell in geographical unit.
17
- * @type {function(import('../core/Dataset.js').Cell, number, number, object):number} */
18
- this.height = opts.height || ((c, r) => r * Math.random()) //(c,r,z,vs) => {}
19
-
20
- /**
21
- * @type {function(number,{min:number, max:number},number,number):string} */
22
- this.lineColor = opts.lineColor || ((y, ys, r, z) => '#BBB')
23
- /**
24
- * @type {function(number,{min:number, max:number},number,number):number} */
25
- this.lineWidth = opts.lineWidth || ((y, ys, r, z) => z)
26
- /**
27
- * @type {function(number,{min:number, max:number},number,number):string} */
28
- this.fillColor = opts.fillColor || ((y, ys, r, z) => '#c08c5968')
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
- draw(cells, geoCanvas, resolution) {
39
-
40
- //filter
41
- if (this.filter) cells = cells.filter(this.filter)
42
-
43
- //
44
- const z = geoCanvas.view.z
45
-
46
- //get view scale
47
- const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
48
-
49
- //index cells by y and x
50
- /** @type {object} */
51
- const ind = {}
52
- for (const cell of cells) {
53
- let row = ind[cell.y]
54
- if (!row) {
55
- row = {}
56
- ind[cell.y] = row
57
- }
58
- row[cell.x] = this.height(cell, resolution, z, viewScale)
59
- }
60
-
61
- //compute extent
62
- const e = geoCanvas.extGeo
63
- if (!e) return
64
- const xMin = Math.floor(e.xMin / resolution) * resolution
65
- const xMax = Math.floor(e.xMax / resolution) * resolution
66
- const yMin = Math.floor(e.yMin / resolution) * resolution
67
- const yMax = Math.floor(e.yMax / resolution) * resolution
68
-
69
- /** @type {{min:number, max:number}} */
70
- const ys = { min: yMin, max: yMax }
71
-
72
- //draw lines, row by row, stating from the top
73
- geoCanvas.ctx.lineJoin = 'round'
74
- for (let y = yMax; y >= yMin; y -= resolution) {
75
- //get row
76
- const row = ind[y]
77
-
78
- //no row
79
- if (!row) continue
80
-
81
- //place first point
82
- geoCanvas.ctx.beginPath()
83
- geoCanvas.ctx.moveTo(xMin - resolution / 2, y)
84
-
85
- //store the previous height
86
- /** @type {number|undefined} */
87
- let hG_
88
-
89
- //go through the line cells
90
- for (let x = xMin; x <= xMax; x += resolution) {
91
- //get column value
92
- /** @type {number} */
93
- let hG = row[x]
94
- if (!hG) hG = 0
95
-
96
- if (hG || hG_) {
97
- //draw line only when at least one of both values is non-null
98
- //TODO test bezierCurveTo
99
- geoCanvas.ctx.lineTo(x + resolution / 2, y + hG)
100
- } else {
101
- //else move the point
102
- geoCanvas.ctx.moveTo(x + resolution / 2, y)
103
- }
104
- //store the previous value
105
- hG_ = hG
106
- }
107
-
108
- //last point
109
- if (hG_) geoCanvas.ctx.lineTo(xMax + resolution / 2, y)
110
-
111
- //draw fill
112
- const fc = this.fillColor(y, ys, resolution, z)
113
- if (fc && fc != 'none') {
114
- geoCanvas.ctx.fillStyle = fc
115
- geoCanvas.ctx.fill()
116
- }
117
-
118
- //draw line
119
- const lc = this.lineColor(y, ys, resolution, z)
120
- const lw = this.lineWidth(y, ys, resolution, z)
121
- if (lc && lc != 'none' && lw > 0) {
122
- geoCanvas.ctx.strokeStyle = lc
123
- geoCanvas.ctx.lineWidth = lw
124
- geoCanvas.ctx.stroke()
125
- }
126
- }
127
- }
128
- }
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 JoyPlotStyle extends Style {
11
+ /** @param {object} opts */
12
+ constructor(opts) {
13
+ super(opts)
14
+ opts = opts || {}
15
+
16
+ /** A function returning the height of a cell in geographical unit.
17
+ * @type {function(import('../core/Dataset.js').Cell, number, number, object):number} */
18
+ this.height = opts.height || ((c, r) => r * Math.random()) //(c,r,z,vs) => {}
19
+
20
+ /**
21
+ * @type {function(number,{min:number, max:number},number,number):string} */
22
+ this.lineColor = opts.lineColor || ((y, ys, r, z) => '#BBB')
23
+ /**
24
+ * @type {function(number,{min:number, max:number},number,number):number} */
25
+ this.lineWidth = opts.lineWidth || ((y, ys, r, z) => z)
26
+ /**
27
+ * @type {function(number,{min:number, max:number},number,number):string} */
28
+ this.fillColor = opts.fillColor || ((y, ys, r, z) => '#c08c5968')
29
+ }
30
+
31
+ /**
32
+ * @param {Array.<import("../core/Dataset.js").Cell>} cells
33
+ * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas
34
+ * @param {number} resolution
35
+ * @override
36
+ */
37
+ draw(cells, geoCanvas, resolution) {
38
+ //filter
39
+ if (this.filter) cells = cells.filter(this.filter)
40
+
41
+ //
42
+ const z = geoCanvas.view.z
43
+ const ctx = geoCanvas.offscreenCtx
44
+
45
+ //get view scale
46
+ const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
47
+
48
+ //index cells by y and x
49
+ /** @type {object} */
50
+ const ind = {}
51
+ for (const cell of cells) {
52
+ let row = ind[cell.y]
53
+ if (!row) {
54
+ row = {}
55
+ ind[cell.y] = row
56
+ }
57
+ row[cell.x] = this.height(cell, resolution, z, viewScale)
58
+ }
59
+
60
+ //compute extent
61
+ const e = geoCanvas.extGeo
62
+ if (!e) return
63
+ const xMin = Math.floor(e.xMin / resolution) * resolution
64
+ const xMax = Math.floor(e.xMax / resolution) * resolution
65
+ const yMin = Math.floor(e.yMin / resolution) * resolution
66
+ const yMax = Math.floor(e.yMax / resolution) * resolution
67
+
68
+ /** @type {{min:number, max:number}} */
69
+ const ys = { min: yMin, max: yMax }
70
+
71
+ //draw lines, row by row, stating from the top
72
+ ctx.lineJoin = 'round'
73
+ for (let y = yMax; y >= yMin; y -= resolution) {
74
+ //get row
75
+ const row = ind[y]
76
+
77
+ //no row
78
+ if (!row) continue
79
+
80
+ //place first point
81
+ ctx.beginPath()
82
+ ctx.moveTo(xMin - resolution / 2, y)
83
+
84
+ //store the previous height
85
+ /** @type {number|undefined} */
86
+ let hG_
87
+
88
+ //go through the line cells
89
+ for (let x = xMin; x <= xMax; x += resolution) {
90
+ //get column value
91
+ /** @type {number} */
92
+ let hG = row[x]
93
+ if (!hG) hG = 0
94
+
95
+ if (hG || hG_) {
96
+ //draw line only when at least one of both values is non-null
97
+ //TODO test bezierCurveTo
98
+ ctx.lineTo(x + resolution / 2, y + hG)
99
+ } else {
100
+ //else move the point
101
+ ctx.moveTo(x + resolution / 2, y)
102
+ }
103
+ //store the previous value
104
+ hG_ = hG
105
+ }
106
+
107
+ //last point
108
+ if (hG_) ctx.lineTo(xMax + resolution / 2, y)
109
+
110
+ //draw fill
111
+ const fc = this.fillColor(y, ys, resolution, z)
112
+ if (fc && fc != 'none') {
113
+ ctx.fillStyle = fc
114
+ ctx.fill()
115
+ }
116
+
117
+ //draw line
118
+ const lc = this.lineColor(y, ys, resolution, z)
119
+ const lw = this.lineWidth(y, ys, resolution, z)
120
+ if (lc && lc != 'none' && lw > 0) {
121
+ ctx.strokeStyle = lc
122
+ ctx.lineWidth = lw
123
+ ctx.stroke()
124
+ }
125
+ }
126
+ }
127
+ }
@@ -1,110 +1,110 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { TanakaStyle } from './TanakaStyle.js'
5
- import { StrokeStyle } from './StrokeStyle.js'
6
- import { SquareColorCategoryWebGLStyle } from './SquareColorCategoryWebGLStyle.js'
7
- import { Style } from '../core/Style.js'
8
-
9
- /**
10
- * @module style
11
- * @author Julien Gaffuri
12
- */
13
- export class LegoStyle {
14
-
15
- static get(value, breaks, colors, opts = {}) {
16
- opts = opts || {}
17
-
18
- //the colors
19
- //http://www.jennyscrayoncollection.com/2021/06/all-current-lego-colors.html
20
- //https://leonawicz.github.io/legocolors/reference/figures/README-plot-1.png
21
- /*opts.colors = opts.colors || [
22
- '#00852b', //darker green
23
- '#afd246', //light green
24
- '#fac80a', //dark yellow
25
- '#bb805a', //brown
26
- '#d67923', //mostard
27
- '#cb4e29', //redish
28
- '#b40000', //red
29
- '#720012', //dark red
30
- //"purple",
31
- //"#eee" //whithe
32
- ]*/
33
-
34
- opts.colDark = opts.colDark || '#333'
35
- opts.colBright = opts.colBright || '#aaa'
36
- opts.widthFactor = opts.widthFactor || 0.12
37
-
38
- //reuse tanaka as basis
39
- const ts = TanakaStyle.get(value, breaks, colors, opts)
40
- //style to show limits between pieces
41
- const sst = new StrokeStyle({
42
- strokeColor: () => '#666',
43
- strokeWidth: (c, r, z) => 0.2 * z,
44
- filter: opts.filter,
45
- })
46
-
47
- return [
48
- ts[0],
49
- sst,
50
- ts[1],
51
- new LegoTopStyle({ colDark: opts.colDark, colBright: opts.colBright, filter: opts.filter }),
52
- ]
53
- }
54
-
55
- /**
56
- * @param {function(import('../core/Dataset.js').Cell):string} code
57
- * @param {object} color
58
- * @param {object} opts
59
- * @returns {Array.<Style>}
60
- */
61
- static getCategory(code, color, opts) {
62
- opts = opts || {}
63
-
64
- opts.colDark = opts.colDark || '#333'
65
- opts.colBright = opts.colBright || '#aaa'
66
-
67
- //
68
- const s = new SquareColorCategoryWebGLStyle({ code: code, color: color })
69
- //style to show limits between pieces
70
- const sst = new StrokeStyle({ strokeColor: () => '#666', strokeWidth: (c, r, z) => 0.2 * z })
71
-
72
- return [s, sst, new LegoTopStyle({ colDark: opts.colDark, colBright: opts.colBright })]
73
- }
74
- }
75
-
76
- /**
77
- * A style to draw top circle of lego bricks.
78
- */
79
- class LegoTopStyle extends Style {
80
- /** @param {object|undefined} opts */
81
- constructor(opts) {
82
- super(opts)
83
- opts = opts || {}
84
- this.colDark = opts.colDark || '#333'
85
- this.colBright = opts.colBright || '#aaa'
86
- }
87
-
88
- draw(cells, geoCanvas, r) {
89
- //filter
90
- if (this.filter) cells = cells.filter(this.filter)
91
-
92
- geoCanvas.ctx.lineWidth = 0.6 * geoCanvas.view.z
93
-
94
- //dark part
95
- geoCanvas.ctx.strokeStyle = this.colDark
96
- for (let c of cells) {
97
- geoCanvas.ctx.beginPath()
98
- geoCanvas.ctx.arc(c.x + r * 0.5, c.y + r * 0.5, r * 0.55 * 0.5, Math.PI / 4, -Math.PI * (3 / 4), true)
99
- geoCanvas.ctx.stroke()
100
- }
101
-
102
- //bright part
103
- geoCanvas.ctx.strokeStyle = this.colBright
104
- for (let c of cells) {
105
- geoCanvas.ctx.beginPath()
106
- geoCanvas.ctx.arc(c.x + r * 0.5, c.y + r * 0.5, r * 0.55 * 0.5, Math.PI / 4, -Math.PI * (3 / 4), false)
107
- geoCanvas.ctx.stroke()
108
- }
109
- }
110
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { TanakaStyle } from './TanakaStyle.js'
5
+ import { StrokeStyle } from './StrokeStyle.js'
6
+ import { SquareColorCategoryWebGLStyle } from './SquareColorCategoryWebGLStyle.js'
7
+ import { Style } from '../core/Style.js'
8
+
9
+ /**
10
+ * @module style
11
+ * @author Julien Gaffuri
12
+ */
13
+ export class LegoStyle {
14
+ static get(value, breaks, colors, opts = {}) {
15
+ opts = opts || {}
16
+
17
+ //the colors
18
+ //http://www.jennyscrayoncollection.com/2021/06/all-current-lego-colors.html
19
+ //https://leonawicz.github.io/legocolors/reference/figures/README-plot-1.png
20
+ /*opts.colors = opts.colors || [
21
+ '#00852b', //darker green
22
+ '#afd246', //light green
23
+ '#fac80a', //dark yellow
24
+ '#bb805a', //brown
25
+ '#d67923', //mostard
26
+ '#cb4e29', //redish
27
+ '#b40000', //red
28
+ '#720012', //dark red
29
+ //"purple",
30
+ //"#eee" //whithe
31
+ ]*/
32
+
33
+ opts.colDark = opts.colDark || '#333'
34
+ opts.colBright = opts.colBright || '#aaa'
35
+ opts.widthFactor = opts.widthFactor || 0.12
36
+
37
+ //reuse tanaka as basis
38
+ const ts = TanakaStyle.get(value, breaks, colors, opts)
39
+ //style to show limits between pieces
40
+ const sst = new StrokeStyle({
41
+ strokeColor: () => '#666',
42
+ strokeWidth: (c, r, z) => 0.2 * z,
43
+ filter: opts.filter,
44
+ })
45
+
46
+ return [
47
+ ts[0],
48
+ sst,
49
+ ts[1],
50
+ new LegoTopStyle({ colDark: opts.colDark, colBright: opts.colBright, filter: opts.filter }),
51
+ ]
52
+ }
53
+
54
+ /**
55
+ * @param {function(import('../core/Dataset.js').Cell):string} code
56
+ * @param {object} color
57
+ * @param {object} opts
58
+ * @returns {Array.<Style>}
59
+ */
60
+ static getCategory(code, color, opts) {
61
+ opts = opts || {}
62
+
63
+ opts.colDark = opts.colDark || '#333'
64
+ opts.colBright = opts.colBright || '#aaa'
65
+
66
+ //
67
+ const s = new SquareColorCategoryWebGLStyle({ code: code, color: color })
68
+ //style to show limits between pieces
69
+ const sst = new StrokeStyle({ strokeColor: () => '#666', strokeWidth: (c, r, z) => 0.2 * z })
70
+
71
+ return [s, sst, new LegoTopStyle({ colDark: opts.colDark, colBright: opts.colBright })]
72
+ }
73
+ }
74
+
75
+ /**
76
+ * A style to draw top circle of lego bricks.
77
+ */
78
+ class LegoTopStyle extends Style {
79
+ /** @param {object|undefined} opts */
80
+ constructor(opts) {
81
+ super(opts)
82
+ opts = opts || {}
83
+ this.colDark = opts.colDark || '#333'
84
+ this.colBright = opts.colBright || '#aaa'
85
+ }
86
+
87
+ draw(cells, geoCanvas, r) {
88
+ //filter
89
+ if (this.filter) cells = cells.filter(this.filter)
90
+ const ctx = geoCanvas.offscreenCtx
91
+
92
+ ctx.lineWidth = 0.6 * geoCanvas.view.z
93
+
94
+ //dark part
95
+ ctx.strokeStyle = this.colDark
96
+ for (let c of cells) {
97
+ ctx.beginPath()
98
+ ctx.arc(c.x + r * 0.5, c.y + r * 0.5, r * 0.55 * 0.5, Math.PI / 4, -Math.PI * (3 / 4), true)
99
+ ctx.stroke()
100
+ }
101
+
102
+ //bright part
103
+ ctx.strokeStyle = this.colBright
104
+ for (let c of cells) {
105
+ ctx.beginPath()
106
+ ctx.arc(c.x + r * 0.5, c.y + r * 0.5, r * 0.55 * 0.5, Math.PI / 4, -Math.PI * (3 / 4), false)
107
+ ctx.stroke()
108
+ }
109
+ }
110
+ }