gridviz 3.0.34 → 3.0.36

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 +17487 -17471
  3. package/dist/gridviz.min.js +2 -2
  4. package/package.json +73 -73
  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 +154 -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 +568 -552
  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 +302 -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 +307 -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 +118 -118
  60. package/src/utils/WebGLSquareColoringAdvanced.js +227 -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 +73 -73
  67. package/src/utils/zoomUtils.js +142 -142
@@ -1,154 +1,154 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../core/Style.js'
5
- import { SideStyle } from './SideStyle.js'
6
-
7
- /** @typedef {{ x:number, y:number, or:"v"|"h", c1:(import('../core/Dataset.js').Cell)|undefined, c2:(import('../core/Dataset.js').Cell)|undefined }} Side */
8
-
9
- /**
10
- * @typedef {function(Array.<Side>,number, number):*} SideViewScale */
11
-
12
- /**
13
- * @see https://manifold.net/doc/mfd9/example__tanaka_contours.htm
14
- *
15
- * @module style
16
- * @author Julien Gaffuri
17
- */
18
- export class SideTanakaStyle extends Style {
19
- /** @param {object} opts */
20
- constructor(opts = {}) {
21
- super(opts)
22
-
23
- /** A function returning the cells classifier.
24
- * The cell classifier is a function that for each cell returns its class number (int).
25
- */
26
- this.classifier = opts.classifier || ((cells, resolution, z) => c => 1)
27
-
28
- /** A function returning the width of a cell side, in geo unit
29
- * @type {function(Side, number, number, number, object):number} */
30
- this.width = opts.width || ((side, sideValue, resolution, z, sidesScale) => Math.abs(sideValue) * z) //Math.min(2 * z, resolution / 3))
31
-
32
- /** A function returning the length of a cell side, in geo unit
33
- * @type {function(Side, number, number, object):number} */
34
- this.length = opts.length || ((side, resolution, z, sidesScale) => resolution)
35
-
36
- // the dark color: for side facing away from light (coming from NW)
37
- this.colorDark = opts.colorDark || '#111'
38
- // the bright color: for side facing the light (coming from NW)
39
- this.colorBright = opts.colorBright || '#ddd'
40
- //
41
- this.revert = opts.revert == undefined? false : opts.revert
42
-
43
- /** Set to A or true so that the side is drawn as a diamond */
44
- this.diamond = opts.diamond
45
-
46
- /* Determines what to do for limit sides, between a cell with value and one with no value
47
- * steep: the cell value absence is equivalent to 0. It shows potentially a steep limit then.
48
- * skip: no side is drawn
49
- * step: a side with a 1 step */
50
- this.limit = opts.limit || "steep"
51
- }
52
-
53
- /**
54
- * @param {Array.<import("../core/Dataset.js").Cell>} cells
55
- * @param {number} resolution
56
- * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas
57
- */
58
- draw(cells, geoCanvas, resolution) {
59
- //filter
60
- if (this.filter) cells = cells.filter(this.filter)
61
-
62
- //
63
- const z = geoCanvas.view.z
64
- const ctx = geoCanvas.offscreenCtx
65
-
66
- //get cell classifier
67
- const classifier = this.classifier(cells, resolution, z)
68
-
69
- //get side value: class change difference
70
- const getSideValue = (/** @type {{ c1: Side; c2: Side; }} */ side) => {
71
- const cl1 = side.c1 ? classifier(side.c1) : undefined
72
- const cl2 = side.c2 ? classifier(side.c2) : undefined
73
- if (cl1 === undefined && cl2 === undefined) return undefined
74
- if (cl1 === undefined) return this.limit=="none"? undefined : this.limit=="steep"? cl2 : Math.sign(cl2)
75
- if (cl2 === undefined) return this.limit=="none"? undefined : this.limit=="steep"? -cl1 : Math.sign(-cl1)
76
- return cl2 - cl1
77
- }
78
-
79
- //build sides
80
- //TODO build only those with different codes ?
81
- /** @type {Array.<Side>} */
82
- const sides = SideStyle.buildSides(cells, resolution)
83
- if (sides.length == 0) return
84
-
85
- //get side view scale
86
- const viewScale = this.viewScale ? this.viewScale(sides, resolution, z) : undefined
87
-
88
- //draw sides
89
- ctx.lineCap = 'butt'
90
- const r2 = resolution * 0.5
91
- const cd = this.revert? this.colorBright : this.colorDark
92
- const cb = this.revert? this.colorDark : this.colorBright
93
- for (let side of sides) {
94
-
95
- //get side value
96
- const v = getSideValue(side)
97
- if (v === undefined || v === 0) continue
98
-
99
- //color
100
- /** @type {string|undefined} */
101
- const col = ((v < 0 && side.or === 'h') || (v > 0 && side.or === 'v')) ? cb : cd
102
- if (!col || col == 'none') continue
103
-
104
- if (this.diamond) {
105
- //set color
106
- ctx.fillStyle = col
107
-
108
- //draw diamond
109
- const x = side.x,
110
- y = side.y
111
- ctx.beginPath()
112
- ctx.moveTo(x - r2, y)
113
- ctx.lineTo(x, y + r2)
114
- ctx.lineTo(x + r2, y)
115
- ctx.lineTo(x, y - r2)
116
- ctx.closePath()
117
- ctx.fill()
118
- } else {
119
- //width
120
- /** @type {number|undefined} */
121
- const wG = this.width ? this.width(side, v, resolution, z, viewScale) : undefined
122
- if (!wG || wG <= 0) continue
123
-
124
- //length
125
- /** @type {number|undefined} */
126
- const lG = this.length ? this.length(side, resolution, z, viewScale) : undefined
127
- if (!lG || lG <= 0) continue
128
- const lG2 = lG * 0.5
129
-
130
- //set width
131
- ctx.lineWidth = wG
132
- //set color
133
- ctx.strokeStyle = col
134
-
135
- //draw segment with correct orientation
136
- const x = side.x,
137
- y = side.y
138
- ctx.beginPath()
139
- if (side.or === 'v') {
140
- ctx.moveTo(x, y - lG2)
141
- ctx.lineTo(x, y + lG2)
142
- } else {
143
- ctx.moveTo(x - lG2, y)
144
- ctx.lineTo(x + lG2, y)
145
- }
146
- ctx.stroke()
147
- }
148
- }
149
-
150
- //update legends
151
- this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
152
- }
153
-
154
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../core/Style.js'
5
+ import { SideStyle } from './SideStyle.js'
6
+
7
+ /** @typedef {{ x:number, y:number, or:"v"|"h", c1:(import('../core/Dataset.js').Cell)|undefined, c2:(import('../core/Dataset.js').Cell)|undefined }} Side */
8
+
9
+ /**
10
+ * @typedef {function(Array.<Side>,number, number):*} SideViewScale */
11
+
12
+ /**
13
+ * @see https://manifold.net/doc/mfd9/example__tanaka_contours.htm
14
+ *
15
+ * @module style
16
+ * @author Julien Gaffuri
17
+ */
18
+ export class SideTanakaStyle extends Style {
19
+ /** @param {object} opts */
20
+ constructor(opts = {}) {
21
+ super(opts)
22
+
23
+ /** A function returning the cells classifier.
24
+ * The cell classifier is a function that for each cell returns its class number (int).
25
+ */
26
+ this.classifier = opts.classifier || ((cells, resolution, z) => c => 1)
27
+
28
+ /** A function returning the width of a cell side, in geo unit
29
+ * @type {function(Side, number, number, number, object):number} */
30
+ this.width = opts.width || ((side, sideValue, resolution, z, sidesScale) => Math.abs(sideValue) * z) //Math.min(2 * z, resolution / 3))
31
+
32
+ /** A function returning the length of a cell side, in geo unit
33
+ * @type {function(Side, number, number, object):number} */
34
+ this.length = opts.length || ((side, resolution, z, sidesScale) => resolution)
35
+
36
+ // the dark color: for side facing away from light (coming from NW)
37
+ this.colorDark = opts.colorDark || '#111'
38
+ // the bright color: for side facing the light (coming from NW)
39
+ this.colorBright = opts.colorBright || '#ddd'
40
+ //
41
+ this.revert = opts.revert == undefined? false : opts.revert
42
+
43
+ /** Set to A or true so that the side is drawn as a diamond */
44
+ this.diamond = opts.diamond
45
+
46
+ /* Determines what to do for limit sides, between a cell with value and one with no value
47
+ * steep: the cell value absence is equivalent to 0. It shows potentially a steep limit then.
48
+ * skip: no side is drawn
49
+ * step: a side with a 1 step */
50
+ this.limit = opts.limit || "steep"
51
+ }
52
+
53
+ /**
54
+ * @param {Array.<import("../core/Dataset.js").Cell>} cells
55
+ * @param {number} resolution
56
+ * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas
57
+ */
58
+ draw(cells, geoCanvas, resolution) {
59
+ //filter
60
+ if (this.filter) cells = cells.filter(this.filter)
61
+
62
+ //
63
+ const z = geoCanvas.view.z
64
+ const ctx = geoCanvas.offscreenCtx
65
+
66
+ //get cell classifier
67
+ const classifier = this.classifier(cells, resolution, z)
68
+
69
+ //get side value: class change difference
70
+ const getSideValue = (/** @type {{ c1: Side; c2: Side; }} */ side) => {
71
+ const cl1 = side.c1 ? classifier(side.c1) : undefined
72
+ const cl2 = side.c2 ? classifier(side.c2) : undefined
73
+ if (cl1 === undefined && cl2 === undefined) return undefined
74
+ if (cl1 === undefined) return this.limit=="none"? undefined : this.limit=="steep"? cl2 : Math.sign(cl2)
75
+ if (cl2 === undefined) return this.limit=="none"? undefined : this.limit=="steep"? -cl1 : Math.sign(-cl1)
76
+ return cl2 - cl1
77
+ }
78
+
79
+ //build sides
80
+ //TODO build only those with different codes ?
81
+ /** @type {Array.<Side>} */
82
+ const sides = SideStyle.buildSides(cells, resolution)
83
+ if (sides.length == 0) return
84
+
85
+ //get side view scale
86
+ const viewScale = this.viewScale ? this.viewScale(sides, resolution, z) : undefined
87
+
88
+ //draw sides
89
+ ctx.lineCap = 'butt'
90
+ const r2 = resolution * 0.5
91
+ const cd = this.revert? this.colorBright : this.colorDark
92
+ const cb = this.revert? this.colorDark : this.colorBright
93
+ for (let side of sides) {
94
+
95
+ //get side value
96
+ const v = getSideValue(side)
97
+ if (v === undefined || v === 0) continue
98
+
99
+ //color
100
+ /** @type {string|undefined} */
101
+ const col = ((v < 0 && side.or === 'h') || (v > 0 && side.or === 'v')) ? cb : cd
102
+ if (!col || col == 'none') continue
103
+
104
+ if (this.diamond) {
105
+ //set color
106
+ ctx.fillStyle = col
107
+
108
+ //draw diamond
109
+ const x = side.x,
110
+ y = side.y
111
+ ctx.beginPath()
112
+ ctx.moveTo(x - r2, y)
113
+ ctx.lineTo(x, y + r2)
114
+ ctx.lineTo(x + r2, y)
115
+ ctx.lineTo(x, y - r2)
116
+ ctx.closePath()
117
+ ctx.fill()
118
+ } else {
119
+ //width
120
+ /** @type {number|undefined} */
121
+ const wG = this.width ? this.width(side, v, resolution, z, viewScale) : undefined
122
+ if (!wG || wG <= 0) continue
123
+
124
+ //length
125
+ /** @type {number|undefined} */
126
+ const lG = this.length ? this.length(side, resolution, z, viewScale) : undefined
127
+ if (!lG || lG <= 0) continue
128
+ const lG2 = lG * 0.5
129
+
130
+ //set width
131
+ ctx.lineWidth = wG
132
+ //set color
133
+ ctx.strokeStyle = col
134
+
135
+ //draw segment with correct orientation
136
+ const x = side.x,
137
+ y = side.y
138
+ ctx.beginPath()
139
+ if (side.or === 'v') {
140
+ ctx.moveTo(x, y - lG2)
141
+ ctx.lineTo(x, y + lG2)
142
+ } else {
143
+ ctx.moveTo(x - lG2, y)
144
+ ctx.lineTo(x + lG2, y)
145
+ }
146
+ ctx.stroke()
147
+ }
148
+ }
149
+
150
+ //update legends
151
+ this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
152
+ }
153
+
154
+ }