gridviz 2.0.38 → 2.0.40

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 (58) hide show
  1. package/README.md +119 -119
  2. package/dist/gridviz.js +7945 -8887
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +77 -78
  5. package/src/App.js +698 -698
  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 +103 -103
  10. package/src/GeoCanvas.js +419 -419
  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 +168 -168
  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/ParquetGrid.js +122 -122
  22. package/src/dataset/TiledGrid.js +296 -296
  23. package/src/index.js +174 -177
  24. package/src/legend/ColorCategoryLegend.js +124 -124
  25. package/src/legend/ColorDiscreteLegend.js +105 -105
  26. package/src/legend/ColorLegend.js +125 -125
  27. package/src/legend/SegmentOrientationLegend.js +87 -87
  28. package/src/legend/SegmentWidthLegend.js +97 -97
  29. package/src/legend/SizeLegend.js +141 -141
  30. package/src/style/CompositionStyle.js +300 -300
  31. package/src/style/ContourStyle.js +54 -54
  32. package/src/style/DotDensityStyle.js +156 -156
  33. package/src/style/JoyPlotStyle.js +135 -135
  34. package/src/style/LegoStyle.js +112 -112
  35. package/src/style/MosaicStyle.js +107 -107
  36. package/src/style/NinjaStarStyle.js +124 -124
  37. package/src/style/PillarStyle.js +230 -230
  38. package/src/style/SegmentStyle.js +142 -142
  39. package/src/style/ShapeColorSizeStyle.js +126 -126
  40. package/src/style/SideCatStyle.js +172 -172
  41. package/src/style/SideStyle.js +218 -218
  42. package/src/style/SquareColorCatWGLStyle.js +120 -120
  43. package/src/style/SquareColorWGLStyle.js +146 -146
  44. package/src/style/StrokeStyle.js +131 -131
  45. package/src/style/TanakaStyle.js +160 -160
  46. package/src/style/TextStyle.js +132 -132
  47. package/src/utils/Utils.js +35 -35
  48. package/src/utils/WebGLRectangleColoring.js +106 -106
  49. package/src/utils/WebGLSquareColoring.js +118 -118
  50. package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
  51. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
  52. package/src/utils/WebGLSquareColoringKS.js +153 -153
  53. package/src/utils/stretching.js +131 -131
  54. package/src/utils/webGLUtils.js +71 -71
  55. package/src/utils/zoomUtils.js +142 -142
  56. package/src/style/KernelSmoothingOldStyle.js +0 -221
  57. package/src/style/KernelSmoothingStyle.js +0 -115
  58. package/src/style/KernelSmoothingWGLStyle.js +0 -130
@@ -1,142 +1,142 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- /**
5
- *
6
- * @param {import("../App").App} app
7
- * @param {number} zfTarget
8
- * @param {number} factor
9
- * @param {number} delayMs
10
- * @param {function|undefined} callback
11
- * @param {number} delayBeforeCallBackMs
12
- * @returns
13
- */
14
- export function zoomTo(
15
- app,
16
- zfTarget,
17
- factor = 1.01,
18
- delayMs = 0,
19
- callback = undefined,
20
- delayBeforeCallBackMs = 0
21
- ) {
22
- //ensure good factor value: >1
23
- factor = factor || 1.01
24
- if (factor < 1) {
25
- console.error('Unexpected value for factor: ' + factor + '. Set to default value 1.01')
26
- factor = 1.01
27
- }
28
-
29
- const zfIni = app.getZoomFactor()
30
- if (zfTarget == zfIni) return
31
- if (zfTarget < zfIni) factor = 1 / factor
32
- let zf = zfIni
33
- let timer = setInterval(() => {
34
- //compute new zoom level
35
- zf = app.getZoomFactor() * factor
36
- if (zfTarget > zfIni && zf > zfTarget) zf = zfTarget
37
- if (zfTarget < zfIni && zf < zfTarget) zf = zfTarget
38
-
39
- //set new zoom level
40
- app.setZoomFactor(zf)
41
- app.redraw()
42
-
43
- //target reached
44
- if (zf == zfTarget) {
45
- clearInterval(timer)
46
- //trigger callback, if any
47
- if (callback)
48
- setTimeout(() => {
49
- callback()
50
- }, delayBeforeCallBackMs)
51
- }
52
- }, delayMs)
53
- return timer
54
- }
55
-
56
- /**
57
- *
58
- * @param {import("../App").App} app
59
- * @param {number} xTarget
60
- * @param {number} yTarget
61
- * @param {number} zfTarget
62
- * @param {number} progressFactorPix
63
- * @param {number} delayMs
64
- * @param {function|undefined} callback
65
- * @param {number} delayBeforeCallBackMs
66
- * @returns
67
- */
68
- export function goToStraight(
69
- app,
70
- xTarget = NaN,
71
- yTarget = NaN,
72
- zfTarget = NaN,
73
- progressFactorPix = 5,
74
- delayMs = 0,
75
- callback = undefined,
76
- delayBeforeCallBackMs = 0
77
- ) {
78
- //store initial position/zoom
79
- const zfIni = app.getZoomFactor()
80
- const cIni = app.getGeoCenter()
81
-
82
- //default
83
- xTarget = isNaN(xTarget) ? cIni.x : xTarget
84
- yTarget = isNaN(yTarget) ? cIni.y : yTarget
85
- zfTarget = isNaN(zfTarget) ? zfIni : zfTarget
86
-
87
- //prepare for pan
88
- const dx = xTarget - cIni.x
89
- const dy = yTarget - cIni.y
90
- let d = Math.hypot(dx, dy)
91
- const ddx = (progressFactorPix * zfIni * dx) / d
92
- const ddy = (progressFactorPix * zfIni * dy) / d
93
-
94
- //prepare for zoom
95
- let r = zfTarget / zfIni
96
- const n = d / (progressFactorPix * zfIni)
97
- const zoomFactor = d > 0 ? Math.pow(r, 1 / n) : Math.pow(r, 1 / 10) //TODO not 10 ?
98
-
99
- //timer
100
- let timer = setInterval(() => {
101
- //compute and set new position
102
- if (d > 0) {
103
- const c = app.getGeoCenter()
104
- let nx = c.x + ddx
105
- let ny = c.y + ddy
106
- //if went too far, stop at target values
107
- if (nx < xTarget && xTarget < c.x) nx = xTarget
108
- if (c.x < xTarget && xTarget < nx) nx = xTarget
109
- if (ny < yTarget && yTarget < c.y) ny = yTarget
110
- if (c.y < yTarget && yTarget < ny) ny = yTarget
111
- app.setGeoCenter({ x: nx, y: ny })
112
- if (nx == xTarget && ny == yTarget) d = 0
113
- }
114
-
115
- //compute and set new zoom
116
- if (r != 1) {
117
- const zf = app.getZoomFactor()
118
- let nzf = zoomFactor * zf
119
- //if went too far, stop at target values
120
- if (nzf < zfTarget && zfTarget < zf) nzf = zfTarget
121
- if (zf < zfTarget && zfTarget < nzf) nzf = zfTarget
122
- app.setZoomFactor(nzf)
123
- if (nzf == zfTarget) r = 1
124
- }
125
-
126
- //redraw
127
- app.redraw()
128
-
129
- //if target reached, stop
130
- if (d == 0 && r == 1) {
131
- //console.log("OK !")
132
- clearInterval(timer)
133
- //trigger callback, if any
134
- if (callback)
135
- setTimeout(() => {
136
- callback()
137
- }, delayBeforeCallBackMs)
138
- }
139
- }, delayMs)
140
-
141
- return timer
142
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ /**
5
+ *
6
+ * @param {import("../App").App} app
7
+ * @param {number} zfTarget
8
+ * @param {number} factor
9
+ * @param {number} delayMs
10
+ * @param {function|undefined} callback
11
+ * @param {number} delayBeforeCallBackMs
12
+ * @returns
13
+ */
14
+ export function zoomTo(
15
+ app,
16
+ zfTarget,
17
+ factor = 1.01,
18
+ delayMs = 0,
19
+ callback = undefined,
20
+ delayBeforeCallBackMs = 0
21
+ ) {
22
+ //ensure good factor value: >1
23
+ factor = factor || 1.01
24
+ if (factor < 1) {
25
+ console.error('Unexpected value for factor: ' + factor + '. Set to default value 1.01')
26
+ factor = 1.01
27
+ }
28
+
29
+ const zfIni = app.getZoomFactor()
30
+ if (zfTarget == zfIni) return
31
+ if (zfTarget < zfIni) factor = 1 / factor
32
+ let zf = zfIni
33
+ let timer = setInterval(() => {
34
+ //compute new zoom level
35
+ zf = app.getZoomFactor() * factor
36
+ if (zfTarget > zfIni && zf > zfTarget) zf = zfTarget
37
+ if (zfTarget < zfIni && zf < zfTarget) zf = zfTarget
38
+
39
+ //set new zoom level
40
+ app.setZoomFactor(zf)
41
+ app.redraw()
42
+
43
+ //target reached
44
+ if (zf == zfTarget) {
45
+ clearInterval(timer)
46
+ //trigger callback, if any
47
+ if (callback)
48
+ setTimeout(() => {
49
+ callback()
50
+ }, delayBeforeCallBackMs)
51
+ }
52
+ }, delayMs)
53
+ return timer
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @param {import("../App").App} app
59
+ * @param {number} xTarget
60
+ * @param {number} yTarget
61
+ * @param {number} zfTarget
62
+ * @param {number} progressFactorPix
63
+ * @param {number} delayMs
64
+ * @param {function|undefined} callback
65
+ * @param {number} delayBeforeCallBackMs
66
+ * @returns
67
+ */
68
+ export function goToStraight(
69
+ app,
70
+ xTarget = NaN,
71
+ yTarget = NaN,
72
+ zfTarget = NaN,
73
+ progressFactorPix = 5,
74
+ delayMs = 0,
75
+ callback = undefined,
76
+ delayBeforeCallBackMs = 0
77
+ ) {
78
+ //store initial position/zoom
79
+ const zfIni = app.getZoomFactor()
80
+ const cIni = app.getGeoCenter()
81
+
82
+ //default
83
+ xTarget = isNaN(xTarget) ? cIni.x : xTarget
84
+ yTarget = isNaN(yTarget) ? cIni.y : yTarget
85
+ zfTarget = isNaN(zfTarget) ? zfIni : zfTarget
86
+
87
+ //prepare for pan
88
+ const dx = xTarget - cIni.x
89
+ const dy = yTarget - cIni.y
90
+ let d = Math.hypot(dx, dy)
91
+ const ddx = (progressFactorPix * zfIni * dx) / d
92
+ const ddy = (progressFactorPix * zfIni * dy) / d
93
+
94
+ //prepare for zoom
95
+ let r = zfTarget / zfIni
96
+ const n = d / (progressFactorPix * zfIni)
97
+ const zoomFactor = d > 0 ? Math.pow(r, 1 / n) : Math.pow(r, 1 / 10) //TODO not 10 ?
98
+
99
+ //timer
100
+ let timer = setInterval(() => {
101
+ //compute and set new position
102
+ if (d > 0) {
103
+ const c = app.getGeoCenter()
104
+ let nx = c.x + ddx
105
+ let ny = c.y + ddy
106
+ //if went too far, stop at target values
107
+ if (nx < xTarget && xTarget < c.x) nx = xTarget
108
+ if (c.x < xTarget && xTarget < nx) nx = xTarget
109
+ if (ny < yTarget && yTarget < c.y) ny = yTarget
110
+ if (c.y < yTarget && yTarget < ny) ny = yTarget
111
+ app.setGeoCenter({ x: nx, y: ny })
112
+ if (nx == xTarget && ny == yTarget) d = 0
113
+ }
114
+
115
+ //compute and set new zoom
116
+ if (r != 1) {
117
+ const zf = app.getZoomFactor()
118
+ let nzf = zoomFactor * zf
119
+ //if went too far, stop at target values
120
+ if (nzf < zfTarget && zfTarget < zf) nzf = zfTarget
121
+ if (zf < zfTarget && zfTarget < nzf) nzf = zfTarget
122
+ app.setZoomFactor(nzf)
123
+ if (nzf == zfTarget) r = 1
124
+ }
125
+
126
+ //redraw
127
+ app.redraw()
128
+
129
+ //if target reached, stop
130
+ if (d == 0 && r == 1) {
131
+ //console.log("OK !")
132
+ clearInterval(timer)
133
+ //trigger callback, if any
134
+ if (callback)
135
+ setTimeout(() => {
136
+ callback()
137
+ }, delayBeforeCallBackMs)
138
+ }
139
+ }, delayMs)
140
+
141
+ return timer
142
+ }
@@ -1,221 +0,0 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../Style.js'
5
-
6
- /**
7
- * A style representing the cell as a smoothed layer, to smoothing local variations and show main trends across space.
8
- *
9
- * @author Julien Gaffuri
10
- */
11
- export class KernelSmoothingStyle extends Style {
12
- //bandwidth
13
- // https://observablehq.com/@uwdata/fast-kde
14
- // https://observablehq.com/d/3127b6d89ada959f
15
- //TODO use https://github.com/uwdata/fast-kde ?
16
- //TODO https://observablehq.com/@sahilchinoy/areal-interpolation-iii ?
17
-
18
- /** @param {object} opts */
19
- constructor(opts) {
20
- super(opts)
21
- opts = opts || {}
22
-
23
- /** A function specifying the value to consider for each cell. This is the value to smooth.
24
- * @type {function(import("../Dataset").Cell):number} */
25
- this.value = opts.value
26
-
27
- /** The smoothing parameter, in geo unit. The larger, the more smoothed.
28
- * @type {function(number,number):number}
29
- */
30
- this.sigma = opts.sigma // (r, zf)=>...
31
-
32
- /** The styles to represent the smoothed cells.
33
- * @type {Array.<Style>}
34
- */
35
- this.styles = opts.styles
36
- }
37
-
38
- /**
39
- * Compute the kernel matrix, that is the matrix of the weights.
40
- * One quadrant is necessary only, since it is symetrical (along both x and y axes).
41
- * @param {number} s Sigma (in grid pixel !)
42
- * @returns {Array.<Array<number>>}
43
- * @private
44
- */
45
- getKernelMatrix(s) {
46
- //the size of the kernel: lets limit that to ~3 times the standard deviation, as an approximation.
47
- const kernelSize = Math.floor(3.25 * s)
48
-
49
- //pre-compute coefficient for gaussian computation, to avoid computing them every time.
50
- const c2 = 2 * s * s
51
-
52
- /**
53
- * The gaussian function. TODO expose that function as a parameter, to use other kernels ?
54
- * @param {number} x
55
- * @param {number} y
56
- * @returns {number}
57
- */
58
- const gaussian = (x, y) => (c2 != 0 ? Math.exp(-(x * x + y * y) / c2) : x == 0 && y == 0 ? 1 : 0) //dirac case
59
-
60
- /** @type {Array.<Array<number>>} */
61
- const kw = []
62
- for (let wi = 0; wi <= kernelSize; wi++) {
63
- /** @type {Array<number>} */
64
- const col = []
65
- for (let wj = 0; wj <= kernelSize; wj++) {
66
- //compute weight at wi,wj
67
- col.push(gaussian(wi, wj))
68
- }
69
- kw.push(col)
70
- }
71
-
72
- /*
73
- //debug: show values
74
- for (let wj = kernelSize-1; wj >=0; wj--) {
75
- let st = "";
76
- for (let wi = 0; wi <= kernelSize; wi++) {
77
- st += " " + Math.floor(kw[wi][wj].w *1000) /1000
78
- }
79
- console.log(st)
80
- }*/
81
-
82
- return kw
83
- }
84
-
85
- /**
86
- * Compute kernel smoothing of some cells.
87
- *
88
- * @private
89
- * @param {Array.<import("../Dataset").Cell>} cells The cells to be smoothed.
90
- * @param {import("../Dataset").Envelope} e Geo envelope to consider.
91
- * @param {number} r Resolution, in geo unit.
92
- * @param {number} s Sigma (in grid pixel !)
93
- * @returns {Array.<import("../Dataset").Cell>} The list of cells, including the initial ones and the ones with smoothed values, in "ksmval" property.
94
- */
95
- kernelSmoothing(cells, e, r, s) {
96
- //filter
97
- if (this.filter) cells = cells.filter(this.filter)
98
-
99
- const wThr = 0.01 //gaussian weights below this value will be ignored
100
-
101
- //compute extent, in grid position
102
- const xMin = Math.floor(e.xMin / r) * r
103
- const xMax = Math.floor(e.xMax / r) * r
104
- const yMin = Math.floor(e.yMin / r) * r
105
- const yMax = Math.floor(e.yMax / r) * r
106
-
107
- //compute matrix dimensions
108
- const nbX = (xMax - xMin) / r + 1
109
- const nbY = (yMax - yMin) / r + 1
110
-
111
- //initialise smoothed value to 0
112
- for (const c of cells) c['ksmval'] = 0
113
-
114
- //make matrix. add input cells by i/j (grid position)
115
- const index = {}
116
- for (const c of cells) {
117
- // i,j of the cell
118
- const i = Math.floor((c.x - xMin) / r)
119
- const j = Math.floor((c.y - yMin) / r)
120
- if (!index[i]) index[i] = {}
121
- index[i][j] = c
122
- }
123
-
124
- /** Check that the cell i,j is within the frame */
125
- const isWithinFrame = (i, j) => i >= 0 && i < nbX && j >= 0 && j < nbY
126
-
127
- //get kernel matrix
128
- /** @type {Array.<Array.<number>>} */
129
- const kernelMatrix = this.getKernelMatrix(s)
130
- const kernelSize = kernelMatrix.length
131
-
132
- //compute summ of the weights over entire kernel window
133
- /** @type {number} */
134
- let sumWeights = 0
135
- for (let ki = 1 - kernelSize; ki < kernelSize; ki++) {
136
- for (let kj = 1 - kernelSize; kj < kernelSize; kj++) {
137
- let w = kernelMatrix[Math.abs(ki)][Math.abs(kj)]
138
- if (w < wThr) continue
139
- sumWeights += w
140
- }
141
- }
142
-
143
- /** Add v as a contribution to the cell i,j */
144
- const addContributionTo = (i, j, v) => {
145
- //get cell at (i,j)
146
- const c_ = index[i] ? index[i][j] : undefined
147
-
148
- if (c_) {
149
- //cell exists: add contribution
150
- if (c_.ksmval) c_.ksmval += v
151
- else c_.ksmval = v
152
- } else {
153
- //cell does not exist: create a new one with the smoothed value
154
- if (!index[i]) index[i] = {}
155
- index[i][j] = { x: xMin + i * r, y: yMin + j * r, ksmval: v }
156
- }
157
- }
158
-
159
- //compute smoothing, input cell by input cell
160
- for (const c of cells) {
161
- /** get value of cell c
162
- * @type {number} */
163
- const val = this.value(c)
164
- if (!val) continue
165
-
166
- //cell matrix coordinates
167
- const i = Math.floor((c.x - xMin) / r)
168
- const j = Math.floor((c.y - yMin) / r)
169
-
170
- //add contributions to smoothed values
171
- for (let ki = 1 - kernelSize; ki < kernelSize; ki++) {
172
- for (let kj = 1 - kernelSize; kj < kernelSize; kj++) {
173
- //check cell is within the frame
174
- if (!isWithinFrame(i + ki, j + kj)) continue
175
-
176
- //get contribution (ki,kj)
177
- let w = kernelMatrix[Math.abs(ki)][Math.abs(kj)]
178
- if (!w || w < wThr) continue
179
- let v = w * val
180
- if (!v) continue
181
- v /= sumWeights
182
- if (!v) continue
183
-
184
- //add contribution
185
- addContributionTo(i + ki, j + kj, v)
186
- }
187
- }
188
- }
189
-
190
- //make output list
191
- const out = []
192
- for (let i of Object.keys(index)) for (const j of Object.keys(index[i])) out.push(index[i][j])
193
-
194
- return out
195
- }
196
-
197
- /**
198
- * Draw the smoothed cells depending on the list of styles specified.
199
- *
200
- * @param {Array.<import("../Dataset").Cell>} cells
201
- * @param {number} r
202
- * @param {import("../GeoCanvas").GeoCanvas} cg
203
- */
204
- draw(cells, r, cg) {
205
- if (!cells || cells.length == 0) return
206
-
207
- //get smoothing param in geo unit
208
- /** @type {number} */
209
- const sG = this.sigma(r, cg.zf)
210
-
211
- //apply kernel smoothing
212
- cells = this.kernelSmoothing(cells, cg.extGeo, r, sG / r)
213
-
214
- //draw smoothed cells from styles
215
- for (let s of this.styles) s.draw(cells, r, cg)
216
-
217
- //update legends
218
- //for (let s of this.styles)
219
- // s.updateLegends({ style: s, r: r, zf: cg.getZf() });
220
- }
221
- }
@@ -1,115 +0,0 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../Style.js'
5
- import { density2d } from 'fast-kde'
6
-
7
- /**
8
- * A style representing the cell as a smoothed layer, to smoothing local variations and show main trends across space.
9
- *
10
- * @author Julien Gaffuri
11
- */
12
- export class KernelSmoothingStyle extends Style {
13
- // https://observablehq.com/d/5dd1cb5e4d21c021
14
- // https://observablehq.com/@uwdata/fast-kde
15
- // https://observablehq.com/d/3127b6d89ada959f
16
- //TODO https://observablehq.com/@sahilchinoy/areal-interpolation-iii ?
17
-
18
- /** @param {object} opts */
19
- constructor(opts) {
20
- super(opts)
21
- opts = opts || {}
22
-
23
- /** A function returning the value to consider for each cell. This is the value to be smoothed.
24
- * @type {function(import("../Dataset").Cell):number} */
25
- this.value = opts.value
26
-
27
- /** The smoothing parameter, in geo unit. The larger, the more smoothed.
28
- * @type {function(number,number):number}
29
- */
30
- this.sigma = opts.sigma // (r, zf)=>...
31
-
32
- /** A factor to adjust the smoothed grid resolution.
33
- * When set to 1, the smoothed grid is exactly the screen resolution.
34
- * Set to 2 to degrade the resolution to a factor 2.
35
- * The higher, the more pixelised and the faster to compute.
36
- * @type { number }
37
- */
38
- this.factor = opts.factor || 2
39
-
40
- /** A filter function to filter the smoothed cells based on their smoothed value.
41
- * Return true to keep the cell, false otherwise.
42
- * @type { function(number):boolean }
43
- */
44
- this.filterSm = opts.filterSm
45
-
46
- /** The name of the attribute where the smoothed value is stored in the output smoothed grid.
47
- * @type { string }
48
- */
49
- this.sCol = opts.sCol || 'ksmval'
50
-
51
- /** The styles to represent the smoothed grid.
52
- * @type {Array.<Style>}
53
- */
54
- this.styles = opts.styles || []
55
- }
56
-
57
- /**
58
- * Draw the smoothed cells depending on the list of styles specified.
59
- *
60
- * @param {Array.<import("../Dataset").Cell>} cells
61
- * @param {number} r
62
- * @param {import("../GeoCanvas").GeoCanvas} cg
63
- */
64
- draw(cells, r, cg) {
65
- //filter
66
- if (this.filter) cells = cells.filter(this.filter)
67
-
68
- if (!cells || cells.length == 0) return
69
-
70
- //get smoothing param in geo unit
71
- /** @type {number} */
72
- const sG = this.sigma(r, cg.zf)
73
-
74
- //compute smoothed grid dimensions
75
- const nbX = Math.ceil(cg.w / this.factor)
76
- const nbY = Math.ceil(cg.h / this.factor)
77
- //compute smoothed grid geo extent
78
- const e_ = [
79
- [cg.pixToGeoX(0), cg.pixToGeoX(nbX * this.factor)],
80
- [cg.pixToGeoY(nbY * this.factor), cg.pixToGeoY(0)],
81
- ]
82
-
83
- //compute smoothed grid
84
- let g = density2d(cells, {
85
- x: (c) => c.x + r / 2,
86
- y: (c) => c.y + r / 2,
87
- weight: (c) => this.value(c),
88
- bins: [nbX, nbY],
89
- bandwidth: sG,
90
- extent: e_,
91
- }).grid()
92
-
93
- //compute the resolution of the smoothed grid
94
- const resSmoothed = (e_[0][1] - e_[0][0]) / nbX
95
-
96
- //make smoothed cells
97
- cells = []
98
- for (let ind = 0; ind < g.length; ind++) {
99
- const v = g[ind]
100
- if (this.filterSm && !this.filterSm(v)) continue
101
- const row = Math.floor(ind / nbX)
102
- const col = ind % nbX
103
- const c = { x: e_[0][0] + col * resSmoothed, y: e_[1][0] + row * resSmoothed }
104
- c[this.sCol] = v
105
- cells.push(c)
106
- }
107
-
108
- //draw smoothed cells from styles
109
- for (let s of this.styles) s.draw(cells, resSmoothed, cg)
110
-
111
- //update legends
112
- //for (let s of this.styles)
113
- // s.updateLegends({ style: s, r: r, zf: cg.getZf() });
114
- }
115
- }