gridviz 3.0.35 → 3.0.37

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 (67) hide show
  1. package/README.md +129 -129
  2. package/dist/gridviz.js +21056 -17487
  3. package/dist/gridviz.min.js +2 -2
  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 -103
  8. package/src/core/Dataset.js +232 -154
  9. package/src/core/Drawable.js +78 -78
  10. package/src/core/GeoCanvas.js +443 -443
  11. package/src/core/Layer.js +23 -23
  12. package/src/core/Legend.js +108 -108
  13. package/src/core/Map.js +650 -568
  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 +311 -302
  22. package/src/dataset/worker.js +18 -18
  23. package/src/index.js +79 -79
  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 +276 -276
  28. package/src/layer/GridLayer.js +166 -166
  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/DotDensityStyle.js +133 -133
  38. package/src/style/ImageStyle.js +100 -100
  39. package/src/style/Interpolator.js +258 -258
  40. package/src/style/IsoFenceStyle.js +217 -217
  41. package/src/style/JoyPlotStyle.js +180 -180
  42. package/src/style/LegoStyle.js +132 -132
  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/ShadingRayStyle.js +280 -280
  48. package/src/style/ShadingStyle.js +72 -72
  49. package/src/style/ShapeColorSizeStyle.js +147 -147
  50. package/src/style/SideCategoryStyle.js +112 -112
  51. package/src/style/SideStyle.js +217 -217
  52. package/src/style/SideTanakaStyle.js +154 -154
  53. package/src/style/SquareColorCategoryWebGLStyle.js +311 -294
  54. package/src/style/SquareColorWebGLStyle.js +126 -126
  55. package/src/style/StrokeStyle.js +135 -135
  56. package/src/style/TextStyle.js +110 -110
  57. package/src/style/TimeSeriesStyle.js +222 -222
  58. package/src/utils/WebGLRectangleColoring.js +106 -106
  59. package/src/utils/WebGLSquareColoring.js +114 -118
  60. package/src/utils/WebGLSquareColoringAdvanced.js +223 -227
  61. package/src/utils/WebGLSquareColoringKS.js +153 -153
  62. package/src/utils/scale.js +255 -255
  63. package/src/utils/stretching.js +120 -120
  64. package/src/utils/ternary.js +208 -208
  65. package/src/utils/utils.js +125 -125
  66. package/src/utils/webGLUtils.js +178 -73
  67. package/src/utils/zoomUtils.js +142 -142
@@ -1,106 +1,106 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { initShaderProgram, createShader } from './webGLUtils.js'
5
-
6
- /**
7
- * Everything to easily draw colored rectangles with webGL.
8
- */
9
- export class WebGLRectangleColoring {
10
- //TODO: add color alpha/opacity
11
-
12
- /**
13
- *
14
- * @param {WebGLRenderingContext} gl
15
- */
16
- constructor(gl) {
17
- this.gl = gl
18
-
19
- this.program = initShaderProgram(
20
- gl,
21
- createShader(
22
- gl,
23
- gl.VERTEX_SHADER,
24
- `
25
- attribute vec2 pos;
26
- uniform mat3 mat;
27
- attribute vec3 color;
28
- varying vec3 vColor;
29
- void main() {
30
- gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
31
- vColor = color;
32
- }
33
- `
34
- ),
35
- createShader(
36
- gl,
37
- gl.FRAGMENT_SHADER,
38
- `
39
- precision mediump float;
40
- varying vec3 vColor;
41
- void main(void) {
42
- gl_FragColor = vec4(vColor, 1.0);
43
- }`
44
- )
45
- )
46
- gl.useProgram(this.program)
47
-
48
- //buffer data
49
- this.verticesBuffer = []
50
- this.colorsBuffer = []
51
- }
52
-
53
- /** Add data to vertices/color buffers for color rectangle drawing */
54
- addRectangleData(x1, x2, y1, y2, cR = 0, cG = 0, cB = 1, cA = 0) {
55
- //TODO cA
56
- //add vertices
57
- this.verticesBuffer.push(x1, y1, x2, y1, x1, y2, x2, y2)
58
-
59
- //colors, 3 parts (RGB), one per vertice
60
- this.colorsBuffer.push(cR, cG, cB, cR, cG, cB, cR, cG, cB, cR, cG, cB)
61
- }
62
-
63
- /** */
64
- draw(transfoMat) {
65
- const gl = this.gl
66
-
67
- //vertice data
68
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
69
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.verticesBuffer), gl.STATIC_DRAW)
70
- const position = gl.getAttribLocation(this.program, 'pos')
71
- gl.vertexAttribPointer(
72
- position,
73
- 2, //numComponents
74
- gl.FLOAT, //type
75
- false, //normalise
76
- 0, //stride
77
- 0 //offset
78
- )
79
- gl.enableVertexAttribArray(position)
80
-
81
- //color data
82
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
83
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.colorsBuffer), gl.STATIC_DRAW)
84
- var color = gl.getAttribLocation(this.program, 'color')
85
- gl.vertexAttribPointer(color, 3, gl.FLOAT, false, 0, 0)
86
- gl.enableVertexAttribArray(color)
87
-
88
- //transformation
89
- gl.uniformMatrix3fv(gl.getUniformLocation(this.program, 'mat'), false, new Float32Array(transfoMat))
90
-
91
- // Enable the depth test
92
- //gl.enable(gl.DEPTH_TEST);
93
- // Clear the color buffer bit
94
- gl.clear(gl.COLOR_BUFFER_BIT)
95
- // Set the view port
96
- //gl.viewport(0, 0, cg.w, cg.h);
97
-
98
- for (let i = 0; i < this.verticesBuffer.length / 8; i++) {
99
- gl.drawArrays(
100
- gl.TRIANGLE_STRIP, // mode,see https://miro.medium.com/max/700/0*HQHB5lCGqlOUiysy.jpg
101
- i * 4, // vertex list start
102
- 4 // vertex count
103
- )
104
- }
105
- }
106
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { initShaderProgram, createShader } from './webGLUtils.js'
5
+
6
+ /**
7
+ * Everything to easily draw colored rectangles with webGL.
8
+ */
9
+ export class WebGLRectangleColoring {
10
+ //TODO: add color alpha/opacity
11
+
12
+ /**
13
+ *
14
+ * @param {WebGLRenderingContext} gl
15
+ */
16
+ constructor(gl) {
17
+ this.gl = gl
18
+
19
+ this.program = initShaderProgram(
20
+ gl,
21
+ createShader(
22
+ gl,
23
+ gl.VERTEX_SHADER,
24
+ `
25
+ attribute vec2 pos;
26
+ uniform mat3 mat;
27
+ attribute vec3 color;
28
+ varying vec3 vColor;
29
+ void main() {
30
+ gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
31
+ vColor = color;
32
+ }
33
+ `
34
+ ),
35
+ createShader(
36
+ gl,
37
+ gl.FRAGMENT_SHADER,
38
+ `
39
+ precision mediump float;
40
+ varying vec3 vColor;
41
+ void main(void) {
42
+ gl_FragColor = vec4(vColor, 1.0);
43
+ }`
44
+ )
45
+ )
46
+ gl.useProgram(this.program)
47
+
48
+ //buffer data
49
+ this.verticesBuffer = []
50
+ this.colorsBuffer = []
51
+ }
52
+
53
+ /** Add data to vertices/color buffers for color rectangle drawing */
54
+ addRectangleData(x1, x2, y1, y2, cR = 0, cG = 0, cB = 1, cA = 0) {
55
+ //TODO cA
56
+ //add vertices
57
+ this.verticesBuffer.push(x1, y1, x2, y1, x1, y2, x2, y2)
58
+
59
+ //colors, 3 parts (RGB), one per vertice
60
+ this.colorsBuffer.push(cR, cG, cB, cR, cG, cB, cR, cG, cB, cR, cG, cB)
61
+ }
62
+
63
+ /** */
64
+ draw(transfoMat) {
65
+ const gl = this.gl
66
+
67
+ //vertice data
68
+ gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
69
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.verticesBuffer), gl.STATIC_DRAW)
70
+ const position = gl.getAttribLocation(this.program, 'pos')
71
+ gl.vertexAttribPointer(
72
+ position,
73
+ 2, //numComponents
74
+ gl.FLOAT, //type
75
+ false, //normalise
76
+ 0, //stride
77
+ 0 //offset
78
+ )
79
+ gl.enableVertexAttribArray(position)
80
+
81
+ //color data
82
+ gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
83
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.colorsBuffer), gl.STATIC_DRAW)
84
+ var color = gl.getAttribLocation(this.program, 'color')
85
+ gl.vertexAttribPointer(color, 3, gl.FLOAT, false, 0, 0)
86
+ gl.enableVertexAttribArray(color)
87
+
88
+ //transformation
89
+ gl.uniformMatrix3fv(gl.getUniformLocation(this.program, 'mat'), false, new Float32Array(transfoMat))
90
+
91
+ // Enable the depth test
92
+ //gl.enable(gl.DEPTH_TEST);
93
+ // Clear the color buffer bit
94
+ gl.clear(gl.COLOR_BUFFER_BIT)
95
+ // Set the view port
96
+ //gl.viewport(0, 0, cg.w, cg.h);
97
+
98
+ for (let i = 0; i < this.verticesBuffer.length / 8; i++) {
99
+ gl.drawArrays(
100
+ gl.TRIANGLE_STRIP, // mode,see https://miro.medium.com/max/700/0*HQHB5lCGqlOUiysy.jpg
101
+ i * 4, // vertex list start
102
+ 4 // vertex count
103
+ )
104
+ }
105
+ }
106
+ }
@@ -1,118 +1,114 @@
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
- */
11
- export class WebGLSquareColoring {
12
- /**
13
- *
14
- * @param {WebGLRenderingContext} gl
15
- */
16
- constructor(gl, sizePix) {
17
- this.gl = gl
18
- this.sizePix = sizePix || 10.0
19
-
20
- this.program = initShaderProgram(
21
- gl,
22
- createShader(
23
- gl,
24
- gl.VERTEX_SHADER,
25
- `
26
- attribute vec2 pos;
27
- uniform float sizePix;
28
- uniform mat3 mat;
29
- attribute vec4 color;
30
- varying vec4 vColor;
31
- void main() {
32
- gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
33
- gl_PointSize = sizePix;
34
- vColor = color;
35
- }
36
- `
37
- ),
38
- createShader(
39
- gl,
40
- gl.FRAGMENT_SHADER,
41
- `
42
- precision mediump float;
43
- varying vec4 vColor;
44
- void main(void) {
45
- vec4 vColor_ = vColor / 255.0;
46
- vColor_[3] = 255.0 * vColor_[3];
47
- gl_FragColor = vColor_;
48
- }`
49
- )
50
- )
51
- gl.useProgram(this.program)
52
-
53
- //buffer data
54
- this.verticesBuffer = []
55
- this.colorsBuffer = []
56
- }
57
-
58
- /** Add data to vertices/size/color buffers for color squares drawing */
59
- addPointData(xC, yC, col) {
60
- //convert color
61
- const cc = color(col)
62
- //const cc = {r:45,g:87,b:98,opacity:0.9}
63
- if (!cc) return
64
-
65
- //vertices
66
- this.verticesBuffer.push(xC, yC)
67
- //color
68
- this.colorsBuffer.push(cc.r, cc.g, cc.b, cc.opacity)
69
- }
70
-
71
- addPointData2(xC, yC, r, g, b, opacity) {
72
- //vertices
73
- this.verticesBuffer.push(xC, yC)
74
- //color
75
- this.colorsBuffer.push(r, g, b, opacity)
76
- }
77
-
78
- /** */
79
- draw(transfoMat) {
80
- const gl = this.gl
81
-
82
- //vertice data
83
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
84
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.verticesBuffer), gl.STATIC_DRAW)
85
- const position = gl.getAttribLocation(this.program, 'pos')
86
- gl.vertexAttribPointer(
87
- position,
88
- 2, //numComponents
89
- gl.FLOAT, //type
90
- false, //normalise
91
- 0, //stride
92
- 0 //offset
93
- )
94
- gl.enableVertexAttribArray(position)
95
-
96
- //color data
97
- gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
98
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.colorsBuffer), gl.STATIC_DRAW)
99
- var color = gl.getAttribLocation(this.program, 'color')
100
- gl.vertexAttribPointer(color, 4, gl.FLOAT, false, 0, 0)
101
- gl.enableVertexAttribArray(color)
102
-
103
- //sizePix
104
- gl.uniform1f(gl.getUniformLocation(this.program, 'sizePix'), 1.0 * this.sizePix)
105
-
106
- //transformation
107
- gl.uniformMatrix3fv(gl.getUniformLocation(this.program, 'mat'), false, new Float32Array(transfoMat))
108
-
109
- // Enable the depth test
110
- //gl.enable(gl.DEPTH_TEST);
111
- // Clear the color buffer bit
112
- gl.clear(gl.COLOR_BUFFER_BIT)
113
- // Set the view port
114
- //gl.viewport(0, 0, cg.w, cg.h);
115
-
116
- gl.drawArrays(gl.POINTS, 0, this.verticesBuffer.length / 2)
117
- }
118
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { getProgram, getBuffer } from './webGLUtils.js'
5
+ import { color } from 'd3-color'
6
+
7
+ const VERTEX_SHADER = `
8
+ attribute vec2 pos;
9
+ uniform float sizePix;
10
+ uniform mat3 mat;
11
+ attribute vec4 color;
12
+ varying vec4 vColor;
13
+ void main() {
14
+ gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
15
+ gl_PointSize = sizePix;
16
+ vColor = color;
17
+ }
18
+ `
19
+
20
+ const FRAGMENT_SHADER = `
21
+ precision mediump float;
22
+ varying vec4 vColor;
23
+ void main(void) {
24
+ vec4 vColor_ = vColor / 255.0;
25
+ vColor_[3] = 255.0 * vColor_[3];
26
+ gl_FragColor = vColor_;
27
+ }`
28
+
29
+ /**
30
+ * Everything to easily draw colored squares with webGL.
31
+ * All the same size, but different fill color.
32
+ */
33
+ export class WebGLSquareColoring {
34
+ /**
35
+ *
36
+ * @param {WebGLRenderingContext} gl
37
+ */
38
+ constructor(gl, sizePix) {
39
+ this.gl = gl
40
+ this.sizePix = sizePix || 10.0
41
+
42
+ // compiled once per context, then reused
43
+ this.program = getProgram(gl, VERTEX_SHADER, FRAGMENT_SHADER)
44
+ gl.useProgram(this.program)
45
+
46
+ //buffer data
47
+ this.verticesBuffer = []
48
+ this.colorsBuffer = []
49
+ }
50
+
51
+ /** Add data to vertices/size/color buffers for color squares drawing */
52
+ addPointData(xC, yC, col) {
53
+ //convert color
54
+ const cc = color(col)
55
+ //const cc = {r:45,g:87,b:98,opacity:0.9}
56
+ if (!cc) return
57
+
58
+ //vertices
59
+ this.verticesBuffer.push(xC, yC)
60
+ //color
61
+ this.colorsBuffer.push(cc.r, cc.g, cc.b, cc.opacity)
62
+ }
63
+
64
+ addPointData2(xC, yC, r, g, b, opacity) {
65
+ //vertices
66
+ this.verticesBuffer.push(xC, yC)
67
+ //color
68
+ this.colorsBuffer.push(r, g, b, opacity)
69
+ }
70
+
71
+ /** */
72
+ draw(transfoMat) {
73
+ const gl = this.gl
74
+
75
+ gl.useProgram(this.program)
76
+
77
+ //vertice data, in a buffer reused from draw to draw
78
+ gl.bindBuffer(gl.ARRAY_BUFFER, getBuffer(gl, 'WebGLSquareColoring.pos'))
79
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.verticesBuffer), gl.DYNAMIC_DRAW)
80
+ const position = gl.getAttribLocation(this.program, 'pos')
81
+ gl.vertexAttribPointer(
82
+ position,
83
+ 2, //numComponents
84
+ gl.FLOAT, //type
85
+ false, //normalise
86
+ 0, //stride
87
+ 0 //offset
88
+ )
89
+ gl.enableVertexAttribArray(position)
90
+
91
+ //color data
92
+ gl.bindBuffer(gl.ARRAY_BUFFER, getBuffer(gl, 'WebGLSquareColoring.color'))
93
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.colorsBuffer), gl.DYNAMIC_DRAW)
94
+ var color = gl.getAttribLocation(this.program, 'color')
95
+ gl.vertexAttribPointer(color, 4, gl.FLOAT, false, 0, 0)
96
+ gl.enableVertexAttribArray(color)
97
+
98
+ //sizePix
99
+ gl.uniform1f(gl.getUniformLocation(this.program, 'sizePix'), 1.0 * this.sizePix)
100
+
101
+ //transformation
102
+ gl.uniformMatrix3fv(gl.getUniformLocation(this.program, 'mat'), false, new Float32Array(transfoMat))
103
+
104
+ // Enable the depth test
105
+ //gl.enable(gl.DEPTH_TEST);
106
+ // Clear the color buffer bit
107
+ gl.clearColor(0, 0, 0, 0)
108
+ gl.clear(gl.COLOR_BUFFER_BIT)
109
+ // Set the view port
110
+ //gl.viewport(0, 0, cg.w, cg.h);
111
+
112
+ gl.drawArrays(gl.POINTS, 0, this.verticesBuffer.length / 2)
113
+ }
114
+ }