gridviz 2.0.45 → 2.0.46

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 (53) hide show
  1. package/README.md +119 -119
  2. package/dist/gridviz.js +6937 -6937
  3. package/package.json +76 -76
  4. package/src/App.js +668 -668
  5. package/src/BackgroundLayer.js +182 -182
  6. package/src/BackgroundLayerWMS.js +131 -131
  7. package/src/Dataset.js +76 -76
  8. package/src/DatasetComponent.js +101 -101
  9. package/src/GeoCanvas.js +420 -420
  10. package/src/LabelLayer.js +190 -190
  11. package/src/Layer.js +92 -92
  12. package/src/Legend.js +86 -86
  13. package/src/LineLayer.js +150 -150
  14. package/src/Style.js +114 -114
  15. package/src/Tooltip.js +172 -172
  16. package/src/dataset/COGeo.js +24 -24
  17. package/src/dataset/CSVGrid.js +104 -104
  18. package/src/dataset/GeoTIFF.js +127 -127
  19. package/src/dataset/GridTile.js +41 -41
  20. package/src/dataset/TiledGrid.js +264 -264
  21. package/src/index.js +177 -176
  22. package/src/legend/ColorCategoryLegend.js +124 -124
  23. package/src/legend/ColorDiscreteLegend.js +103 -103
  24. package/src/legend/ColorLegend.js +124 -124
  25. package/src/legend/SegmentOrientationLegend.js +87 -87
  26. package/src/legend/SegmentWidthLegend.js +97 -97
  27. package/src/legend/SizeLegend.js +141 -141
  28. package/src/style/CompositionStyle.js +300 -300
  29. package/src/style/ContourStyle.js +54 -54
  30. package/src/style/DotDensityStyle.js +156 -156
  31. package/src/style/JoyPlotStyle.js +135 -135
  32. package/src/style/LegoStyle.js +112 -112
  33. package/src/style/MosaicStyle.js +107 -107
  34. package/src/style/NinjaStarStyle.js +124 -124
  35. package/src/style/PillarStyle.js +230 -230
  36. package/src/style/SegmentStyle.js +142 -142
  37. package/src/style/ShapeColorSizeStyle.js +126 -126
  38. package/src/style/SideCatStyle.js +172 -172
  39. package/src/style/SideStyle.js +218 -218
  40. package/src/style/SquareColorCatWGLStyle.js +120 -120
  41. package/src/style/SquareColorWGLStyle.js +146 -146
  42. package/src/style/StrokeStyle.js +131 -131
  43. package/src/style/TanakaStyle.js +160 -160
  44. package/src/style/TextStyle.js +132 -132
  45. package/src/utils/Utils.js +35 -35
  46. package/src/utils/WebGLRectangleColoring.js +106 -106
  47. package/src/utils/WebGLSquareColoring.js +118 -118
  48. package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
  49. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
  50. package/src/utils/WebGLSquareColoringKS.js +153 -153
  51. package/src/utils/stretching.js +131 -131
  52. package/src/utils/webGLUtils.js +71 -71
  53. package/src/utils/zoomUtils.js +142 -142
@@ -1,120 +1,120 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../Style.js'
5
- import { makeWebGLCanvas } from '../utils/webGLUtils.js'
6
- import { WebGLSquareColoringCatAdvanced } from '../utils/WebGLSquareColoringCatAdvanced.js'
7
- import { monitor, monitorDuration } from '../utils/Utils.js'
8
-
9
- /**
10
- * Style based on webGL
11
- * To show cells as colored squares, from categories.
12
- * Alls squares with the same size
13
- *
14
- * @author Julien Gaffuri
15
- */
16
- export class SquareColorCatWGLStyle extends Style {
17
- /** @param {object} opts */
18
- constructor(opts) {
19
- super(opts)
20
- opts = opts || {}
21
-
22
- /**
23
- * The name of the column/attribute of the tabular data where to retrieve the category of the cell, for coloring.
24
- * @type {string} */
25
- this.colorCol = opts.colorCol
26
-
27
- /**
28
- * The dictionary (string -> color) which give the color of each category.
29
- * @type {object} */
30
- opts.color = opts.color || undefined
31
-
32
- /** @type { Array.<string> } @private */
33
- const keys = Object.keys(opts.color)
34
-
35
- /** @type { object } @private */
36
- this.catToI = {}
37
- for (let i = 0; i < keys.length; i++) this.catToI[keys[i]] = i + ''
38
-
39
- /** @type { Array.<string> } @private */
40
- this.colors = []
41
- for (let i = 0; i < keys.length; i++) {
42
- this.colors.push(opts.color['' + keys[i]])
43
- }
44
-
45
- /**
46
- * A function returning the size of the cells, in geographical unit. All cells have the same size.
47
- * @type {function(number,number):number} */
48
- this.size = opts.size // (resolution, zf) => ...
49
-
50
- /**
51
- * @private
52
- * @type { WebGLSquareColoringCatAdvanced } */
53
- this.wgp = new WebGLSquareColoringCatAdvanced(this.colors)
54
- }
55
-
56
- /**
57
- * @param {Array.<import("../Dataset").Cell>} cells
58
- * @param {number} r
59
- * @param {import("../GeoCanvas").GeoCanvas} cg
60
- */
61
- draw(cells, r, cg) {
62
- if (monitor) monitorDuration('*** SquareColorCatWGLStyle draw')
63
-
64
- //filter
65
- if (this.filter) cells = cells.filter(this.filter)
66
-
67
- //zoom factor
68
- const zf = cg.getZf()
69
-
70
- //add vertice and fragment data
71
- const r2 = r / 2
72
- let c,
73
- nb = cells.length
74
- const verticesBuffer = []
75
- const iBuffer = []
76
- for (let i = 0; i < nb; i++) {
77
- c = cells[i]
78
- const cat = c[this.colorCol]
79
- if (cat == undefined) {
80
- console.log('Unexpected category: ' + cat)
81
- continue
82
- }
83
- /** @type {number} */
84
- const i_ = this.catToI[cat]
85
- if (isNaN(+i_)) {
86
- console.log('Unexpected category index: ' + cat + ' ' + i_)
87
- continue
88
- }
89
- verticesBuffer.push(c.x + r2, c.y + r2)
90
- iBuffer.push(+i_)
91
- }
92
-
93
- if (monitor) monitorDuration(' webgl program inputs preparation')
94
-
95
- //create canvas and webgl renderer
96
- const cvWGL = makeWebGLCanvas(cg.w + '', cg.h + '')
97
- if (!cvWGL) {
98
- console.error('No webGL')
99
- return
100
- }
101
- if (monitor) monitorDuration(' web GL canvas creation')
102
-
103
- //draw
104
- const sizeGeo = this.size ? this.size(r, zf) : r + 0.2 * zf
105
- this.wgp.draw(cvWGL.gl, verticesBuffer, iBuffer, cg.getWebGLTransform(), sizeGeo / zf)
106
-
107
- if (monitor) monitorDuration(' webgl drawing')
108
-
109
- //draw in canvas geo
110
- cg.initCanvasTransform()
111
- cg.ctx.drawImage(cvWGL.canvas, 0, 0)
112
-
113
- if (monitor) monitorDuration(' canvas drawing')
114
-
115
- //update legends
116
- this.updateLegends({ style: this, r: r, zf: zf })
117
-
118
- if (monitor) monitorDuration('*** SquareColorCatWGLStyle end draw')
119
- }
120
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../Style.js'
5
+ import { makeWebGLCanvas } from '../utils/webGLUtils.js'
6
+ import { WebGLSquareColoringCatAdvanced } from '../utils/WebGLSquareColoringCatAdvanced.js'
7
+ import { monitor, monitorDuration } from '../utils/Utils.js'
8
+
9
+ /**
10
+ * Style based on webGL
11
+ * To show cells as colored squares, from categories.
12
+ * Alls squares with the same size
13
+ *
14
+ * @author Julien Gaffuri
15
+ */
16
+ export class SquareColorCatWGLStyle extends Style {
17
+ /** @param {object} opts */
18
+ constructor(opts) {
19
+ super(opts)
20
+ opts = opts || {}
21
+
22
+ /**
23
+ * The name of the column/attribute of the tabular data where to retrieve the category of the cell, for coloring.
24
+ * @type {string} */
25
+ this.colorCol = opts.colorCol
26
+
27
+ /**
28
+ * The dictionary (string -> color) which give the color of each category.
29
+ * @type {object} */
30
+ opts.color = opts.color || undefined
31
+
32
+ /** @type { Array.<string> } @private */
33
+ const keys = Object.keys(opts.color)
34
+
35
+ /** @type { object } @private */
36
+ this.catToI = {}
37
+ for (let i = 0; i < keys.length; i++) this.catToI[keys[i]] = i + ''
38
+
39
+ /** @type { Array.<string> } @private */
40
+ this.colors = []
41
+ for (let i = 0; i < keys.length; i++) {
42
+ this.colors.push(opts.color['' + keys[i]])
43
+ }
44
+
45
+ /**
46
+ * A function returning the size of the cells, in geographical unit. All cells have the same size.
47
+ * @type {function(number,number):number} */
48
+ this.size = opts.size // (resolution, zf) => ...
49
+
50
+ /**
51
+ * @private
52
+ * @type { WebGLSquareColoringCatAdvanced } */
53
+ this.wgp = new WebGLSquareColoringCatAdvanced(this.colors)
54
+ }
55
+
56
+ /**
57
+ * @param {Array.<import("../Dataset").Cell>} cells
58
+ * @param {number} r
59
+ * @param {import("../GeoCanvas").GeoCanvas} cg
60
+ */
61
+ draw(cells, r, cg) {
62
+ if (monitor) monitorDuration('*** SquareColorCatWGLStyle draw')
63
+
64
+ //filter
65
+ if (this.filter) cells = cells.filter(this.filter)
66
+
67
+ //zoom factor
68
+ const zf = cg.getZf()
69
+
70
+ //add vertice and fragment data
71
+ const r2 = r / 2
72
+ let c,
73
+ nb = cells.length
74
+ const verticesBuffer = []
75
+ const iBuffer = []
76
+ for (let i = 0; i < nb; i++) {
77
+ c = cells[i]
78
+ const cat = c[this.colorCol]
79
+ if (cat == undefined) {
80
+ console.log('Unexpected category: ' + cat)
81
+ continue
82
+ }
83
+ /** @type {number} */
84
+ const i_ = this.catToI[cat]
85
+ if (isNaN(+i_)) {
86
+ console.log('Unexpected category index: ' + cat + ' ' + i_)
87
+ continue
88
+ }
89
+ verticesBuffer.push(c.x + r2, c.y + r2)
90
+ iBuffer.push(+i_)
91
+ }
92
+
93
+ if (monitor) monitorDuration(' webgl program inputs preparation')
94
+
95
+ //create canvas and webgl renderer
96
+ const cvWGL = makeWebGLCanvas(cg.w + '', cg.h + '')
97
+ if (!cvWGL) {
98
+ console.error('No webGL')
99
+ return
100
+ }
101
+ if (monitor) monitorDuration(' web GL canvas creation')
102
+
103
+ //draw
104
+ const sizeGeo = this.size ? this.size(r, zf) : r + 0.2 * zf
105
+ this.wgp.draw(cvWGL.gl, verticesBuffer, iBuffer, cg.getWebGLTransform(), sizeGeo / zf)
106
+
107
+ if (monitor) monitorDuration(' webgl drawing')
108
+
109
+ //draw in canvas geo
110
+ cg.initCanvasTransform()
111
+ cg.ctx.drawImage(cvWGL.canvas, 0, 0)
112
+
113
+ if (monitor) monitorDuration(' canvas drawing')
114
+
115
+ //update legends
116
+ this.updateLegends({ style: this, r: r, zf: zf })
117
+
118
+ if (monitor) monitorDuration('*** SquareColorCatWGLStyle end draw')
119
+ }
120
+ }
@@ -1,146 +1,146 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../Style.js'
5
- import { makeWebGLCanvas } from '../utils/webGLUtils.js'
6
- import { WebGLSquareColoringAdvanced } from '../utils/WebGLSquareColoringAdvanced.js'
7
- import { monitor, monitorDuration } from '../utils/Utils.js'
8
-
9
- /**
10
- * Style based on webGL
11
- * To show cells as colored squares, with computation of the colors on GPU side (faster than JavaScript side).
12
- * Alls squares with the same size
13
- *
14
- * @author Julien Gaffuri
15
- */
16
- export class SquareColorWGLStyle extends Style {
17
- /** @param {object} opts */
18
- constructor(opts) {
19
- super(opts)
20
- opts = opts || {}
21
-
22
- /**
23
- * The name of the column/attribute of the tabular data where to retrieve the variable for color.
24
- * @type {string} */
25
- this.colorCol = opts.colorCol
26
-
27
- /**
28
- * A function returning the t value (within [0,1]) of the cell.
29
- * @type {function(number,number,import("../Style").Stat):number} */
30
- this.tFun = opts.tFun || ((v, r, s) => v / s.max)
31
-
32
- /**
33
- * Distribution stretching method.
34
- * The stretching is performed on GPU side (fragment shader).
35
- * @type {{ fun:string, alpha:number }} */
36
- this.stretching = opts.stretching
37
-
38
- /**
39
- * The sample of the color ramp.
40
- * The color is computed on GPU side (fragment shader) based on those values (linear interpolation).
41
- * @type {Array.<string>} */
42
- this.colors =
43
- opts.colors ||
44
- [
45
- 'rgb(158, 1, 66)',
46
- 'rgb(248, 142, 83)',
47
- 'rgb(251, 248, 176)',
48
- 'rgb(137, 207, 165)',
49
- 'rgb(94, 79, 162)',
50
- ].reverse()
51
- if (opts.color)
52
- this.colors = [
53
- opts.color(0),
54
- opts.color(0.2),
55
- opts.color(0.4),
56
- opts.color(0.6),
57
- opts.color(0.8),
58
- opts.color(1),
59
- ]
60
-
61
- /**
62
- * Define the opacity of the style, within [0,1].
63
- * If this opacity is defined, the individual color opacity will be ignored.
64
- * @type {function(number,number):number} */
65
- this.opacity = opts.opacity // (r,zf) => ...
66
-
67
- /**
68
- * A function returning the size of the cells, in geographical unit. All cells have the same size.
69
- * @type {function(number,number):number} */
70
- this.size = opts.size // (resolution, zf) => ...
71
- }
72
-
73
- /**
74
- * @param {Array.<import("../Dataset").Cell>} cells
75
- * @param {number} r
76
- * @param {import("../GeoCanvas").GeoCanvas} cg
77
- */
78
- draw(cells, r, cg) {
79
- if (monitor) monitorDuration('*** SquareColorWGLStyle draw')
80
-
81
- //filter
82
- if (this.filter) cells = cells.filter(this.filter)
83
-
84
- //zoom factor
85
- const zf = cg.getZf()
86
-
87
- //compute color variable statistics
88
- const statColor = Style.getStatistics(cells, (c) => c[this.colorCol], true)
89
- if (monitor) monitorDuration(' color stats computation')
90
-
91
- if (!statColor) return
92
-
93
- //create canvas and webgl renderer
94
- //for opacity control, see: https://webglfundamentals.org/webgl/lessons/webgl-and-alpha.html
95
- const cvWGL = makeWebGLCanvas(
96
- cg.w + '',
97
- cg.h + '',
98
- this.opacity != undefined ? { premultipliedAlpha: false } : undefined
99
- )
100
- if (!cvWGL) {
101
- console.error('No webGL')
102
- return
103
- }
104
- if (monitor) monitorDuration(' web GL canvas creation')
105
-
106
- //add vertice and fragment data
107
- const r2 = r / 2
108
- const verticesBuffer = []
109
- const tBuffer = []
110
- for (let c of cells) {
111
- const t = this.tFun(c[this.colorCol], r, statColor)
112
- if (t == null || t == undefined) continue
113
- verticesBuffer.push(c.x + r2, c.y + r2)
114
- tBuffer.push(t > 1 ? 1 : t < 0 ? 0 : t)
115
- }
116
-
117
- if (monitor) monitorDuration(' webgl drawing data preparation')
118
-
119
- //compute pixel size
120
- const sizeGeo = this.size ? this.size(r, zf) : r + 0.2 * zf
121
-
122
- //compute opacity
123
- const op = this.opacity ? this.opacity(r, zf) : undefined
124
-
125
- //
126
- const wgp = new WebGLSquareColoringAdvanced(cvWGL.gl, this.colors, this.stretching, sizeGeo / zf, op)
127
-
128
- if (monitor) monitorDuration(' webgl program preparation')
129
-
130
- //draw
131
- wgp.draw(verticesBuffer, tBuffer, cg.getWebGLTransform())
132
-
133
- if (monitor) monitorDuration(' webgl drawing')
134
-
135
- //draw in canvas geo
136
- cg.initCanvasTransform()
137
- cg.ctx.drawImage(cvWGL.canvas, 0, 0)
138
-
139
- if (monitor) monitorDuration(' canvas drawing')
140
-
141
- //update legends
142
- this.updateLegends({ style: this, r: r, zf: zf, sColor: statColor })
143
-
144
- if (monitor) monitorDuration('*** SquareColorWGLStyle end draw')
145
- }
146
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../Style.js'
5
+ import { makeWebGLCanvas } from '../utils/webGLUtils.js'
6
+ import { WebGLSquareColoringAdvanced } from '../utils/WebGLSquareColoringAdvanced.js'
7
+ import { monitor, monitorDuration } from '../utils/Utils.js'
8
+
9
+ /**
10
+ * Style based on webGL
11
+ * To show cells as colored squares, with computation of the colors on GPU side (faster than JavaScript side).
12
+ * Alls squares with the same size
13
+ *
14
+ * @author Julien Gaffuri
15
+ */
16
+ export class SquareColorWGLStyle extends Style {
17
+ /** @param {object} opts */
18
+ constructor(opts) {
19
+ super(opts)
20
+ opts = opts || {}
21
+
22
+ /**
23
+ * The name of the column/attribute of the tabular data where to retrieve the variable for color.
24
+ * @type {string} */
25
+ this.colorCol = opts.colorCol
26
+
27
+ /**
28
+ * A function returning the t value (within [0,1]) of the cell.
29
+ * @type {function(number,number,import("../Style").Stat):number} */
30
+ this.tFun = opts.tFun || ((v, r, s) => v / s.max)
31
+
32
+ /**
33
+ * Distribution stretching method.
34
+ * The stretching is performed on GPU side (fragment shader).
35
+ * @type {{ fun:string, alpha:number }} */
36
+ this.stretching = opts.stretching
37
+
38
+ /**
39
+ * The sample of the color ramp.
40
+ * The color is computed on GPU side (fragment shader) based on those values (linear interpolation).
41
+ * @type {Array.<string>} */
42
+ this.colors =
43
+ opts.colors ||
44
+ [
45
+ 'rgb(158, 1, 66)',
46
+ 'rgb(248, 142, 83)',
47
+ 'rgb(251, 248, 176)',
48
+ 'rgb(137, 207, 165)',
49
+ 'rgb(94, 79, 162)',
50
+ ].reverse()
51
+ if (opts.color)
52
+ this.colors = [
53
+ opts.color(0),
54
+ opts.color(0.2),
55
+ opts.color(0.4),
56
+ opts.color(0.6),
57
+ opts.color(0.8),
58
+ opts.color(1),
59
+ ]
60
+
61
+ /**
62
+ * Define the opacity of the style, within [0,1].
63
+ * If this opacity is defined, the individual color opacity will be ignored.
64
+ * @type {function(number,number):number} */
65
+ this.opacity = opts.opacity // (r,zf) => ...
66
+
67
+ /**
68
+ * A function returning the size of the cells, in geographical unit. All cells have the same size.
69
+ * @type {function(number,number):number} */
70
+ this.size = opts.size // (resolution, zf) => ...
71
+ }
72
+
73
+ /**
74
+ * @param {Array.<import("../Dataset").Cell>} cells
75
+ * @param {number} r
76
+ * @param {import("../GeoCanvas").GeoCanvas} cg
77
+ */
78
+ draw(cells, r, cg) {
79
+ if (monitor) monitorDuration('*** SquareColorWGLStyle draw')
80
+
81
+ //filter
82
+ if (this.filter) cells = cells.filter(this.filter)
83
+
84
+ //zoom factor
85
+ const zf = cg.getZf()
86
+
87
+ //compute color variable statistics
88
+ const statColor = Style.getStatistics(cells, (c) => c[this.colorCol], true)
89
+ if (monitor) monitorDuration(' color stats computation')
90
+
91
+ if (!statColor) return
92
+
93
+ //create canvas and webgl renderer
94
+ //for opacity control, see: https://webglfundamentals.org/webgl/lessons/webgl-and-alpha.html
95
+ const cvWGL = makeWebGLCanvas(
96
+ cg.w + '',
97
+ cg.h + '',
98
+ this.opacity != undefined ? { premultipliedAlpha: false } : undefined
99
+ )
100
+ if (!cvWGL) {
101
+ console.error('No webGL')
102
+ return
103
+ }
104
+ if (monitor) monitorDuration(' web GL canvas creation')
105
+
106
+ //add vertice and fragment data
107
+ const r2 = r / 2
108
+ const verticesBuffer = []
109
+ const tBuffer = []
110
+ for (let c of cells) {
111
+ const t = this.tFun(c[this.colorCol], r, statColor)
112
+ if (t == null || t == undefined) continue
113
+ verticesBuffer.push(c.x + r2, c.y + r2)
114
+ tBuffer.push(t > 1 ? 1 : t < 0 ? 0 : t)
115
+ }
116
+
117
+ if (monitor) monitorDuration(' webgl drawing data preparation')
118
+
119
+ //compute pixel size
120
+ const sizeGeo = this.size ? this.size(r, zf) : r + 0.2 * zf
121
+
122
+ //compute opacity
123
+ const op = this.opacity ? this.opacity(r, zf) : undefined
124
+
125
+ //
126
+ const wgp = new WebGLSquareColoringAdvanced(cvWGL.gl, this.colors, this.stretching, sizeGeo / zf, op)
127
+
128
+ if (monitor) monitorDuration(' webgl program preparation')
129
+
130
+ //draw
131
+ wgp.draw(verticesBuffer, tBuffer, cg.getWebGLTransform())
132
+
133
+ if (monitor) monitorDuration(' webgl drawing')
134
+
135
+ //draw in canvas geo
136
+ cg.initCanvasTransform()
137
+ cg.ctx.drawImage(cvWGL.canvas, 0, 0)
138
+
139
+ if (monitor) monitorDuration(' canvas drawing')
140
+
141
+ //update legends
142
+ this.updateLegends({ style: this, r: r, zf: zf, sColor: statColor })
143
+
144
+ if (monitor) monitorDuration('*** SquareColorWGLStyle end draw')
145
+ }
146
+ }