gridviz 2.0.45 → 2.0.47

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 (54) hide show
  1. package/README.md +119 -119
  2. package/dist/gridviz.js +7559 -7549
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +78 -76
  5. package/src/App.js +668 -668
  6. package/src/BackgroundLayer.js +182 -182
  7. package/src/BackgroundLayerWMS.js +131 -131
  8. package/src/Dataset.js +76 -76
  9. package/src/DatasetComponent.js +101 -101
  10. package/src/GeoCanvas.js +420 -420
  11. package/src/LabelLayer.js +190 -190
  12. package/src/Layer.js +92 -92
  13. package/src/Legend.js +86 -86
  14. package/src/LineLayer.js +150 -150
  15. package/src/Style.js +114 -114
  16. package/src/Tooltip.js +172 -172
  17. package/src/dataset/COGeo.js +24 -24
  18. package/src/dataset/CSVGrid.js +104 -104
  19. package/src/dataset/GeoTIFF.js +127 -127
  20. package/src/dataset/GridTile.js +41 -41
  21. package/src/dataset/TiledGrid.js +264 -264
  22. package/src/index.js +177 -176
  23. package/src/legend/ColorCategoryLegend.js +124 -124
  24. package/src/legend/ColorDiscreteLegend.js +103 -103
  25. package/src/legend/ColorLegend.js +124 -124
  26. package/src/legend/SegmentOrientationLegend.js +87 -87
  27. package/src/legend/SegmentWidthLegend.js +97 -97
  28. package/src/legend/SizeLegend.js +141 -141
  29. package/src/style/CompositionStyle.js +300 -300
  30. package/src/style/ContourStyle.js +54 -54
  31. package/src/style/DotDensityStyle.js +156 -156
  32. package/src/style/JoyPlotStyle.js +135 -135
  33. package/src/style/LegoStyle.js +112 -112
  34. package/src/style/MosaicStyle.js +107 -107
  35. package/src/style/NinjaStarStyle.js +124 -124
  36. package/src/style/PillarStyle.js +230 -230
  37. package/src/style/SegmentStyle.js +142 -142
  38. package/src/style/ShapeColorSizeStyle.js +126 -126
  39. package/src/style/SideCatStyle.js +172 -172
  40. package/src/style/SideStyle.js +218 -218
  41. package/src/style/SquareColorCatWGLStyle.js +120 -120
  42. package/src/style/SquareColorWGLStyle.js +146 -146
  43. package/src/style/StrokeStyle.js +131 -131
  44. package/src/style/TanakaStyle.js +160 -160
  45. package/src/style/TextStyle.js +132 -132
  46. package/src/utils/Utils.js +35 -35
  47. package/src/utils/WebGLRectangleColoring.js +106 -106
  48. package/src/utils/WebGLSquareColoring.js +118 -118
  49. package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
  50. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
  51. package/src/utils/WebGLSquareColoringKS.js +153 -153
  52. package/src/utils/stretching.js +131 -131
  53. package/src/utils/webGLUtils.js +71 -71
  54. package/src/utils/zoomUtils.js +142 -142
@@ -1,230 +1,230 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { initShaderProgram, createShader } from './webGLUtils.js'
5
- import { color } from 'd3-color'
6
-
7
- /**
8
- * Everything to easily draw colored squares with webGL.
9
- * All the same size, but different fill color.
10
- * The color interpolation is computed in the fragment shader program, by the GPU, thus it is less flexible but faster.
11
- */
12
- export class WebGLSquareColoringAdvanced {
13
- //see:
14
- //https://webglfundamentals.org/webgl/lessons/fr/webgl-shaders-and-glsl.html#les-uniforms-dans-les-shaders-de-vertex
15
- //https://thebookofshaders.com/glossary/?search=mix
16
- //https://thebookofshaders.com/06/
17
- //https://thebookofshaders.com/glossary/
18
-
19
- /**
20
- *
21
- * @param {*} gl
22
- * @param {Array.<String>} colors
23
- * @param {{fun:string,alpha:number}} stretching
24
- * @param {number} sizePix
25
- * @param {number|undefined} globalOpacity
26
- */
27
- constructor(gl, colors, stretching, sizePix = 10, globalOpacity = undefined) {
28
- /** @type {WebGLRenderingContext} */
29
- this.gl = gl
30
- //gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
31
- //gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
32
- //gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
33
-
34
- /** @type {WebGLShader} */
35
- const vShader = createShader(
36
- gl,
37
- gl.VERTEX_SHADER,
38
- `
39
- attribute vec2 pos;
40
- uniform float sizePix;
41
- uniform mat3 mat;
42
-
43
- attribute float t;
44
- varying float vt;
45
-
46
- void main() {
47
- gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
48
- gl_PointSize = sizePix;
49
- vt = t;
50
- }
51
- `
52
- )
53
-
54
- //prepare fragment shader code
55
- //declare the uniform and other variables
56
- let fshString =
57
- '' +
58
- 'precision mediump float;\n' +
59
- 'varying float vt;\n' +
60
- 'uniform float alpha;\n' +
61
- (() => {
62
- const out = []
63
- for (let i = 0; i < colors.length; i++) out.push('uniform vec4 c' + i + ';\n')
64
- return out.join('')
65
- })() +
66
- //start the main function, apply the stretching of t
67
- 'void main(void) {\n'
68
-
69
- if (stretching) {
70
- if (stretching.fun == 'pow')
71
- //sPow = (t, alpha = 3) => Math.pow(t, alpha);
72
- fshString += ' float t = pow(vt, alpha);\n'
73
- else if (stretching.fun == 'powRev')
74
- //sPowRev = (t, alpha = 3) => 1 - Math.pow(1 - t, 1 / alpha);
75
- fshString += ' float t = 1.0-pow(1.0-vt, 1.0/alpha);\n'
76
- else if (stretching.fun == 'exp')
77
- //sExp = (t, alpha = 3) => alpha == 0 ? t : (Math.exp(t * alpha) - 1) / (Math.exp(alpha) - 1);
78
- fshString +=
79
- stretching.alpha == 0
80
- ? `float t = vt;`
81
- : ' float t = (exp(vt * alpha) - 1.0) / (exp(alpha) - 1.0);\n'
82
- else if (stretching.fun == 'expRev')
83
- //sExpRev = (t, alpha = 3) => alpha == 0 ? t : 1 - (1 / alpha) * Math.log(Math.exp(alpha) * (1 - t) + t);
84
- fshString +=
85
- stretching.alpha == 0
86
- ? `float t = vt;`
87
- : ' float t = 1.0 - (1.0 / alpha) * log(exp(alpha) * (1.0 - vt) + vt);\n'
88
- else if (stretching.fun == 'circleLow') {
89
- if (stretching.alpha == 0)
90
- //if (alpha == 0) return t;
91
- fshString += ' float t = vt;\n'
92
- else if (stretching.alpha == 1)
93
- // if (alpha == 1) return Math.sqrt(2 * t - t * t);
94
- fshString += ' float t = sqrt(vt * (2.0 - vt));\n'
95
- else {
96
- //const a = alpha / (1 - alpha);
97
- //return Math.sqrt(1 / (a * a) + t * (2 / a + 2 - t)) - 1 / a;
98
- fshString +=
99
- ' float a = alpha / (1.0 - alpha);\n' +
100
- ' float t = sqrt(1.0 / (a * a) + vt * ( 2.0/a + 2.0 - vt )) - 1.0 / a;\n'
101
- }
102
- } else if (stretching.fun == 'circleHigh') {
103
- // 1 - sCircleLow(1 - t, alpha)
104
- if (stretching.alpha == 0)
105
- //if (alpha == 0) return t;
106
- fshString += ' float t = vt;\n'
107
- else if (stretching.alpha == 1)
108
- // if (alpha == 1) return Math.sqrt(2 * t - t * t);
109
- fshString += ' float t = 1.0 - sqrt((1.0 - vt) * (1.0 + vt));\n'
110
- else {
111
- //const a = alpha / (1 - alpha);
112
- //return Math.sqrt(1 / (a * a) + (2 * t) / a + 2 * t - t * t) - 1 / a;
113
- fshString +=
114
- ' float a = alpha / (1.0 - alpha);\n' +
115
- ' float t = 1.0 - sqrt(1.0 / (a * a) + (1.0-vt) * ( 2.0/a + 1.0 + vt )) + 1.0 / a;\n'
116
- }
117
- } else {
118
- console.error('Unexpected stretching function code: ' + stretching.fun)
119
- fshString += ' float t = vt;\n'
120
- }
121
- } else {
122
- fshString += ' float t = vt;\n'
123
- }
124
-
125
- //choose initial and final colors, and adjust t value
126
- if (colors.length == 1) fshString += ' vec4 cI=c0;\n vec4 cF=c0;\n'
127
- else if (colors.length == 2) fshString += ' vec4 cI=c0;\n vec4 cF=c1;\n'
128
- else {
129
- const nb = colors.length - 1
130
- const nbs = nb + '.0'
131
- fshString += ' vec4 cI;\n'
132
- fshString += ' vec4 cF;\n'
133
- fshString += ' if(t<1.0/' + nbs + ') { cI=c0; cF=c1; t=t*' + nbs + '; }\n'
134
- for (let i = 2; i < nb; i++)
135
- fshString +=
136
- ' else if(t<' +
137
- i +
138
- '.0/' +
139
- nbs +
140
- ') { cI=c' +
141
- (i - 1) +
142
- '; cF=c' +
143
- i +
144
- '; t=' +
145
- nbs +
146
- '*t-' +
147
- (i - 1) +
148
- '.0; }\n'
149
- fshString +=
150
- ' else { cI=c' + (nb - 1) + '; cF=c' + nb + '; t=' + nbs + '*t-' + (nb - 1) + '.0; }\n'
151
- }
152
-
153
- //one single color
154
- if (colors.length == 1) fshString += ' gl_FragColor = vec4(c0[0], c0[1], c0[2], c0[3]);}\n'
155
- //set interpolated color, between initial and final one
156
- else fshString += ' gl_FragColor = mix(cI, cF, t);}\n'
157
-
158
- //console.log(fshString)
159
-
160
- /** @type {WebGLShader} */
161
- const fShader = createShader(gl, gl.FRAGMENT_SHADER, fshString)
162
-
163
- /** @type {WebGLProgram} */
164
- this.program = initShaderProgram(gl, vShader, fShader)
165
- gl.useProgram(this.program)
166
-
167
- //set uniforms
168
-
169
- //sizePix
170
- //TODO: bug here. Seems to be limited to some threshold value (around 250).
171
- gl.uniform1f(gl.getUniformLocation(this.program, 'sizePix'), 1.0 * sizePix)
172
-
173
- //stretching alpha factor
174
- gl.uniform1f(gl.getUniformLocation(this.program, 'alpha'), stretching ? 1.0 * stretching.alpha : 0.0)
175
-
176
- //colors
177
- for (let i = 0; i < colors.length; i++) {
178
- const c = color(colors[i])
179
-
180
- let opacity = c.opacity
181
- if (c.opacity == 1 && globalOpacity != undefined) opacity = globalOpacity
182
-
183
- gl.uniform4fv(gl.getUniformLocation(this.program, 'c' + i), [
184
- +c.r / 255.0,
185
- +c.g / 255.0,
186
- +c.b / 255.0,
187
- +opacity,
188
- ])
189
- }
190
- }
191
-
192
- /** */
193
- draw(verticesBuffer, tBuffer, transfoMat) {
194
- const gl = this.gl
195
- const program = this.program
196
-
197
- //vertice data
198
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
199
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesBuffer), gl.STATIC_DRAW)
200
- const position = gl.getAttribLocation(program, 'pos')
201
- gl.vertexAttribPointer(
202
- position,
203
- 2, //numComponents
204
- gl.FLOAT, //type
205
- false, //normalise
206
- 0, //stride
207
- 0 //offset
208
- )
209
- gl.enableVertexAttribArray(position)
210
-
211
- //t data
212
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
213
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(tBuffer), gl.STATIC_DRAW)
214
- const t = gl.getAttribLocation(program, 't')
215
- gl.vertexAttribPointer(t, 1, gl.FLOAT, false, 0, 0)
216
- gl.enableVertexAttribArray(t)
217
-
218
- //transformation
219
- gl.uniformMatrix3fv(gl.getUniformLocation(program, 'mat'), false, new Float32Array(transfoMat))
220
-
221
- // Enable the depth test
222
- //gl.enable(gl.DEPTH_TEST);
223
- // Clear the color buffer bit
224
- gl.clear(gl.COLOR_BUFFER_BIT)
225
- // Set the view port
226
- //gl.viewport(0, 0, cg.w, cg.h);
227
-
228
- gl.drawArrays(gl.POINTS, 0, verticesBuffer.length / 2)
229
- }
230
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { initShaderProgram, createShader } from './webGLUtils.js'
5
+ import { color } from 'd3-color'
6
+
7
+ /**
8
+ * Everything to easily draw colored squares with webGL.
9
+ * All the same size, but different fill color.
10
+ * The color interpolation is computed in the fragment shader program, by the GPU, thus it is less flexible but faster.
11
+ */
12
+ export class WebGLSquareColoringAdvanced {
13
+ //see:
14
+ //https://webglfundamentals.org/webgl/lessons/fr/webgl-shaders-and-glsl.html#les-uniforms-dans-les-shaders-de-vertex
15
+ //https://thebookofshaders.com/glossary/?search=mix
16
+ //https://thebookofshaders.com/06/
17
+ //https://thebookofshaders.com/glossary/
18
+
19
+ /**
20
+ *
21
+ * @param {*} gl
22
+ * @param {Array.<String>} colors
23
+ * @param {{fun:string,alpha:number}} stretching
24
+ * @param {number} sizePix
25
+ * @param {number|undefined} globalOpacity
26
+ */
27
+ constructor(gl, colors, stretching, sizePix = 10, globalOpacity = undefined) {
28
+ /** @type {WebGLRenderingContext} */
29
+ this.gl = gl
30
+ //gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
31
+ //gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
32
+ //gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
33
+
34
+ /** @type {WebGLShader} */
35
+ const vShader = createShader(
36
+ gl,
37
+ gl.VERTEX_SHADER,
38
+ `
39
+ attribute vec2 pos;
40
+ uniform float sizePix;
41
+ uniform mat3 mat;
42
+
43
+ attribute float t;
44
+ varying float vt;
45
+
46
+ void main() {
47
+ gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
48
+ gl_PointSize = sizePix;
49
+ vt = t;
50
+ }
51
+ `
52
+ )
53
+
54
+ //prepare fragment shader code
55
+ //declare the uniform and other variables
56
+ let fshString =
57
+ '' +
58
+ 'precision mediump float;\n' +
59
+ 'varying float vt;\n' +
60
+ 'uniform float alpha;\n' +
61
+ (() => {
62
+ const out = []
63
+ for (let i = 0; i < colors.length; i++) out.push('uniform vec4 c' + i + ';\n')
64
+ return out.join('')
65
+ })() +
66
+ //start the main function, apply the stretching of t
67
+ 'void main(void) {\n'
68
+
69
+ if (stretching) {
70
+ if (stretching.fun == 'pow')
71
+ //sPow = (t, alpha = 3) => Math.pow(t, alpha);
72
+ fshString += ' float t = pow(vt, alpha);\n'
73
+ else if (stretching.fun == 'powRev')
74
+ //sPowRev = (t, alpha = 3) => 1 - Math.pow(1 - t, 1 / alpha);
75
+ fshString += ' float t = 1.0-pow(1.0-vt, 1.0/alpha);\n'
76
+ else if (stretching.fun == 'exp')
77
+ //sExp = (t, alpha = 3) => alpha == 0 ? t : (Math.exp(t * alpha) - 1) / (Math.exp(alpha) - 1);
78
+ fshString +=
79
+ stretching.alpha == 0
80
+ ? `float t = vt;`
81
+ : ' float t = (exp(vt * alpha) - 1.0) / (exp(alpha) - 1.0);\n'
82
+ else if (stretching.fun == 'expRev')
83
+ //sExpRev = (t, alpha = 3) => alpha == 0 ? t : 1 - (1 / alpha) * Math.log(Math.exp(alpha) * (1 - t) + t);
84
+ fshString +=
85
+ stretching.alpha == 0
86
+ ? `float t = vt;`
87
+ : ' float t = 1.0 - (1.0 / alpha) * log(exp(alpha) * (1.0 - vt) + vt);\n'
88
+ else if (stretching.fun == 'circleLow') {
89
+ if (stretching.alpha == 0)
90
+ //if (alpha == 0) return t;
91
+ fshString += ' float t = vt;\n'
92
+ else if (stretching.alpha == 1)
93
+ // if (alpha == 1) return Math.sqrt(2 * t - t * t);
94
+ fshString += ' float t = sqrt(vt * (2.0 - vt));\n'
95
+ else {
96
+ //const a = alpha / (1 - alpha);
97
+ //return Math.sqrt(1 / (a * a) + t * (2 / a + 2 - t)) - 1 / a;
98
+ fshString +=
99
+ ' float a = alpha / (1.0 - alpha);\n' +
100
+ ' float t = sqrt(1.0 / (a * a) + vt * ( 2.0/a + 2.0 - vt )) - 1.0 / a;\n'
101
+ }
102
+ } else if (stretching.fun == 'circleHigh') {
103
+ // 1 - sCircleLow(1 - t, alpha)
104
+ if (stretching.alpha == 0)
105
+ //if (alpha == 0) return t;
106
+ fshString += ' float t = vt;\n'
107
+ else if (stretching.alpha == 1)
108
+ // if (alpha == 1) return Math.sqrt(2 * t - t * t);
109
+ fshString += ' float t = 1.0 - sqrt((1.0 - vt) * (1.0 + vt));\n'
110
+ else {
111
+ //const a = alpha / (1 - alpha);
112
+ //return Math.sqrt(1 / (a * a) + (2 * t) / a + 2 * t - t * t) - 1 / a;
113
+ fshString +=
114
+ ' float a = alpha / (1.0 - alpha);\n' +
115
+ ' float t = 1.0 - sqrt(1.0 / (a * a) + (1.0-vt) * ( 2.0/a + 1.0 + vt )) + 1.0 / a;\n'
116
+ }
117
+ } else {
118
+ console.error('Unexpected stretching function code: ' + stretching.fun)
119
+ fshString += ' float t = vt;\n'
120
+ }
121
+ } else {
122
+ fshString += ' float t = vt;\n'
123
+ }
124
+
125
+ //choose initial and final colors, and adjust t value
126
+ if (colors.length == 1) fshString += ' vec4 cI=c0;\n vec4 cF=c0;\n'
127
+ else if (colors.length == 2) fshString += ' vec4 cI=c0;\n vec4 cF=c1;\n'
128
+ else {
129
+ const nb = colors.length - 1
130
+ const nbs = nb + '.0'
131
+ fshString += ' vec4 cI;\n'
132
+ fshString += ' vec4 cF;\n'
133
+ fshString += ' if(t<1.0/' + nbs + ') { cI=c0; cF=c1; t=t*' + nbs + '; }\n'
134
+ for (let i = 2; i < nb; i++)
135
+ fshString +=
136
+ ' else if(t<' +
137
+ i +
138
+ '.0/' +
139
+ nbs +
140
+ ') { cI=c' +
141
+ (i - 1) +
142
+ '; cF=c' +
143
+ i +
144
+ '; t=' +
145
+ nbs +
146
+ '*t-' +
147
+ (i - 1) +
148
+ '.0; }\n'
149
+ fshString +=
150
+ ' else { cI=c' + (nb - 1) + '; cF=c' + nb + '; t=' + nbs + '*t-' + (nb - 1) + '.0; }\n'
151
+ }
152
+
153
+ //one single color
154
+ if (colors.length == 1) fshString += ' gl_FragColor = vec4(c0[0], c0[1], c0[2], c0[3]);}\n'
155
+ //set interpolated color, between initial and final one
156
+ else fshString += ' gl_FragColor = mix(cI, cF, t);}\n'
157
+
158
+ //console.log(fshString)
159
+
160
+ /** @type {WebGLShader} */
161
+ const fShader = createShader(gl, gl.FRAGMENT_SHADER, fshString)
162
+
163
+ /** @type {WebGLProgram} */
164
+ this.program = initShaderProgram(gl, vShader, fShader)
165
+ gl.useProgram(this.program)
166
+
167
+ //set uniforms
168
+
169
+ //sizePix
170
+ //TODO: bug here. Seems to be limited to some threshold value (around 250).
171
+ gl.uniform1f(gl.getUniformLocation(this.program, 'sizePix'), 1.0 * sizePix)
172
+
173
+ //stretching alpha factor
174
+ gl.uniform1f(gl.getUniformLocation(this.program, 'alpha'), stretching ? 1.0 * stretching.alpha : 0.0)
175
+
176
+ //colors
177
+ for (let i = 0; i < colors.length; i++) {
178
+ const c = color(colors[i])
179
+
180
+ let opacity = c.opacity
181
+ if (c.opacity == 1 && globalOpacity != undefined) opacity = globalOpacity
182
+
183
+ gl.uniform4fv(gl.getUniformLocation(this.program, 'c' + i), [
184
+ +c.r / 255.0,
185
+ +c.g / 255.0,
186
+ +c.b / 255.0,
187
+ +opacity,
188
+ ])
189
+ }
190
+ }
191
+
192
+ /** */
193
+ draw(verticesBuffer, tBuffer, transfoMat) {
194
+ const gl = this.gl
195
+ const program = this.program
196
+
197
+ //vertice data
198
+ gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
199
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verticesBuffer), gl.STATIC_DRAW)
200
+ const position = gl.getAttribLocation(program, 'pos')
201
+ gl.vertexAttribPointer(
202
+ position,
203
+ 2, //numComponents
204
+ gl.FLOAT, //type
205
+ false, //normalise
206
+ 0, //stride
207
+ 0 //offset
208
+ )
209
+ gl.enableVertexAttribArray(position)
210
+
211
+ //t data
212
+ gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
213
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(tBuffer), gl.STATIC_DRAW)
214
+ const t = gl.getAttribLocation(program, 't')
215
+ gl.vertexAttribPointer(t, 1, gl.FLOAT, false, 0, 0)
216
+ gl.enableVertexAttribArray(t)
217
+
218
+ //transformation
219
+ gl.uniformMatrix3fv(gl.getUniformLocation(program, 'mat'), false, new Float32Array(transfoMat))
220
+
221
+ // Enable the depth test
222
+ //gl.enable(gl.DEPTH_TEST);
223
+ // Clear the color buffer bit
224
+ gl.clear(gl.COLOR_BUFFER_BIT)
225
+ // Set the view port
226
+ //gl.viewport(0, 0, cg.w, cg.h);
227
+
228
+ gl.drawArrays(gl.POINTS, 0, verticesBuffer.length / 2)
229
+ }
230
+ }