gridviz 2.0.40 → 2.0.41

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gridviz",
3
- "version": "2.0.40",
3
+ "version": "2.0.41",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -47,7 +47,6 @@
47
47
  "src/**/*.js"
48
48
  ],
49
49
  "dependencies": {
50
- "apache-arrow": "^10.0.1",
51
50
  "d3-color": "^3.1.0",
52
51
  "d3-fetch": "^3.0.1",
53
52
  "d3-format": "^3.1.0",
package/src/App.js CHANGED
@@ -7,7 +7,6 @@ import { Layer } from './Layer.js'
7
7
  import { Dataset } from './Dataset.js'
8
8
  import { Tooltip } from './Tooltip.js'
9
9
  import { CSVGrid } from './dataset/CSVGrid.js'
10
- //import { ParquetGrid } from './dataset/ParquetGrid';
11
10
  import { TiledGrid } from './dataset/TiledGrid.js'
12
11
  import { BackgroundLayer } from './BackgroundLayer.js'
13
12
  import { BackgroundLayerWMS } from './BackgroundLayerWMS.js'
@@ -450,18 +449,6 @@ export class App {
450
449
  )
451
450
  }
452
451
 
453
- /**
454
- * Make a parquet grid dataset.
455
- *
456
- * @param {string} url The URL of the dataset.
457
- * @param {number} resolution The dataset resolution in geographical unit.
458
- * @param {object=} opts The parameters of the dataset.
459
- * @returns {Dataset}
460
- */
461
- /*makeParquetGridDataset(url, resolution, opts) {
462
- return new Dataset([new ParquetGrid(url, resolution, opts).getData(undefined, () => { this.cg.redraw(); })], [], opts)
463
- }*/
464
-
465
452
  /**
466
453
  * Make a tiled grid dataset.
467
454
  *
@@ -483,22 +470,6 @@ export class App {
483
470
 
484
471
  //multi scale dataset creation
485
472
 
486
- /**
487
- * Make a multi scale parquet grid dataset.
488
- *
489
- * @param {Array.<number>} resolutions
490
- * @param {function(number):string} resToURL
491
- * @param {{preprocess?:function(import('./Dataset').Cell):boolean}} opts
492
- * @returns {Dataset}
493
- */
494
- /*makeMultiScaleParquetGridDataset(resolutions, resToURL, opts) {
495
- return Dataset.make(
496
- resolutions,
497
- (res) => new ParquetGrid(resToURL(res), res, opts).getData(undefined, () => { this.cg.redraw(); }),
498
- opts
499
- )
500
- }*/
501
-
502
473
  /**
503
474
  * Make a multi scale CSV grid dataset.
504
475
  *
@@ -555,19 +526,6 @@ export class App {
555
526
  return this.addLayerFromDataset(ds, styles, opts)
556
527
  }
557
528
 
558
- /**
559
- * Add a layer from a parquet grid dataset.
560
- *
561
- * @param {string} url The URL of the dataset.
562
- * @param {number} resolution The dataset resolution in geographical unit.
563
- * @param {Array.<import('./Style').Style>} styles The styles, ordered in drawing order.
564
- * @param {object=} opts The parameters of the dataset and layer.
565
- * @returns {this}
566
- */
567
- /*addParquetGridLayer(url, resolution, styles, opts) {
568
- const ds = this.makeParquetGridDataset(url, resolution, opts)
569
- return this.addLayerFromDataset(ds, styles, opts);
570
- }*/
571
529
 
572
530
  /**
573
531
  *
@@ -595,20 +553,6 @@ export class App {
595
553
  return this.addLayerFromDataset(ds, styles, opts)
596
554
  }
597
555
 
598
- /**
599
- * Add a layer from a parquet grid dataset.
600
- *
601
- * @param {Array.<number>} resolutions
602
- * @param {function(number):string} resToURL
603
- * @param {Array.<import('./Style').Style>} styles The styles, ordered in drawing order.
604
- * @param {object=} opts The parameters of the dataset and layer.
605
- * @returns {this}
606
- */
607
- /*addMultiScaleParquetGridLayer(resolutions, resToURL, styles, opts) {
608
- const ds = this.makeMultiScaleParquetGridDataset(resolutions, resToURL, opts)
609
- return this.addLayerFromDataset(ds, styles, opts);
610
- }*/
611
-
612
556
  /**
613
557
  * @param {Array.<number>} resolutions
614
558
  * @param {function(number):string} resToURL
@@ -1,8 +1,6 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
- /** @typedef {"CSV"|"PARQUET"} Format */
5
-
6
4
  /**
7
5
  * A dataset component, of grid cells.
8
6
  * @abstract
@@ -11,10 +11,9 @@ import { monitor, monitorDuration } from '../utils/Utils.js'
11
11
 
12
12
  // external
13
13
  import { json, csv } from 'd3-fetch'
14
- import { tableFromIPC } from 'apache-arrow'
15
14
 
16
15
  /**
17
- * A tiled dataset, composed of CSV (or parquet) tiles.
16
+ * A tiled dataset, composed of CSV tiles.
18
17
  *
19
18
  * @author Joseph Davies, Julien Gaffuri
20
19
  */
@@ -22,7 +21,7 @@ export class TiledGrid extends DatasetComponent {
22
21
  /**
23
22
  * @param {string} url The URL of the dataset.
24
23
  * @param {App} app The application.
25
- * @param {{preprocess?:(function(import("../Dataset").Cell):boolean), readParquetFun?:Function }} opts
24
+ * @param {{preprocess?:(function(import("../Dataset").Cell):boolean) }} opts
26
25
  */
27
26
  constructor(url, app, opts = {}) {
28
27
  super(url, 0, opts)
@@ -53,10 +52,6 @@ export class TiledGrid extends DatasetComponent {
53
52
  * */
54
53
  this.cache = {}
55
54
 
56
- /**
57
- * @type {Function|undefined}
58
- * @private */
59
- this.readParquetFun = opts.readParquetFun
60
55
  }
61
56
 
62
57
  /**
@@ -67,7 +62,7 @@ export class TiledGrid extends DatasetComponent {
67
62
  */
68
63
  loadInfo(callback) {
69
64
  if (!this.info && this.infoLoadingStatus === 'notLoaded') {
70
- ;(async () => {
65
+ ; (async () => {
71
66
  try {
72
67
  const data = await json(this.url + 'info.json')
73
68
  this.info = data
@@ -93,7 +88,7 @@ export class TiledGrid extends DatasetComponent {
93
88
  */
94
89
  getTilingEnvelope(e) {
95
90
  if (!this.info) {
96
- this.loadInfo(() => {})
91
+ this.loadInfo(() => { })
97
92
  return
98
93
  }
99
94
 
@@ -131,8 +126,6 @@ export class TiledGrid extends DatasetComponent {
131
126
  /** @type {import("../Dataset").Envelope} */
132
127
  const gb = this.info.tilingBounds
133
128
 
134
- const format = this.info.format
135
-
136
129
  for (let xT = Math.max(tb.xMin, gb.xMin); xT <= Math.min(tb.xMax, gb.xMax); xT++) {
137
130
  for (let yT = Math.max(tb.yMin, gb.yMin); yT <= Math.min(tb.yMax, gb.yMax); yT++) {
138
131
  //prepare cache
@@ -145,13 +138,12 @@ export class TiledGrid extends DatasetComponent {
145
138
 
146
139
  //mark tile as loading
147
140
  this.cache[xT][yT] = 'loading'
148
- ;(async () => {
149
- //request tile
150
- /** @type {Array.<import("../Dataset").Cell>} */
151
- let cells
141
+ ; (async () => {
142
+ //request tile
143
+ /** @type {Array.<import("../Dataset").Cell>} */
144
+ let cells
152
145
 
153
- try {
154
- if (!format || format === 'CSV') {
146
+ try {
155
147
  /** @type {Array.<import("../Dataset").Cell>} */
156
148
  // @ts-ignore
157
149
  const data = await csv(this.url + xT + '/' + yT + '.csv')
@@ -171,80 +163,56 @@ export class TiledGrid extends DatasetComponent {
171
163
  }
172
164
 
173
165
  if (monitor) monitorDuration('preprocess / filter')
174
- } else if (format === 'PARQUET') {
175
- if (!this.readParquetFun)
176
- throw new Error('readParquet function needed for parquet dataset')
177
-
178
- const resp = await fetch(this.url + xT + '/' + yT + '.parquet')
179
- const parquetUint8Array = new Uint8Array(await resp.arrayBuffer())
180
- const arrowUint8Array = this.readParquetFun(parquetUint8Array)
181
- const t = tableFromIPC(arrowUint8Array)
182
-
183
- cells = []
184
- for (const e of t) {
185
- //get cell
186
- const c = e.toJSON()
187
-
188
- //preprocess/filter
189
- if (this.preprocess) {
190
- const b = this.preprocess(c)
191
- if (b == false) continue
192
- cells.push(c)
193
- } else {
194
- cells.push(c)
195
- }
196
- }
197
- } else throw new Error('Tiled format not supported: ' + format)
198
- } catch (error) {
199
- //mark as failed
200
- this.cache[xT][yT] = 'failed'
201
- return
202
- }
203
-
204
- //store tile in cache
205
- if (!this.info) {
206
- console.error('Tile info inknown')
207
- return
208
- }
209
- const tile_ = new GridTile(cells, xT, yT, this.info)
210
- this.cache[xT][yT] = tile_
211
-
212
- if (monitor) monitorDuration('storage')
213
-
214
- //if no redraw is specified, then leave
215
- if (!redrawFun) return
216
-
217
- //check if redraw is really needed, that is if:
218
-
219
- // 1. the dataset belongs to a layer which is visible at the current zoom level
220
- let redraw = false
221
- //go through the layers
222
- const zf = this.app.getZoomFactor()
223
- for (const lay of this.app.layers) {
224
- if (!lay.visible) continue
225
- if (lay.getDatasetComponent(zf) != this) continue
226
- //found one layer. No need to seek more.
227
- redraw = true
228
- break
229
- }
230
- if (monitor) monitorDuration('check redraw 1')
231
-
232
- if (!redraw) return
233
-
234
- // 2. the tile is within the view, that is its geo envelope intersects the viewer geo envelope.
235
- const env = this.app.updateExtentGeo()
236
- const envT = tile_.extGeo
237
- if (env.xMax <= envT.xMin) return
238
- if (env.xMin >= envT.xMax) return
239
- if (env.yMax <= envT.yMin) return
240
- if (env.yMin >= envT.yMax) return
241
-
242
- if (monitor) monitorDuration('check redraw 2')
243
- if (monitor) monitorDuration('*** TiledGrid parse end')
244
-
245
- //redraw
246
- redrawFun()
247
- })()
166
+ } catch (error) {
167
+ //mark as failed
168
+ this.cache[xT][yT] = 'failed'
169
+ return
170
+ }
171
+
172
+ //store tile in cache
173
+ if (!this.info) {
174
+ console.error('Tile info inknown')
175
+ return
176
+ }
177
+ const tile_ = new GridTile(cells, xT, yT, this.info)
178
+ this.cache[xT][yT] = tile_
179
+
180
+ if (monitor) monitorDuration('storage')
181
+
182
+ //if no redraw is specified, then leave
183
+ if (!redrawFun) return
184
+
185
+ //check if redraw is really needed, that is if:
186
+
187
+ // 1. the dataset belongs to a layer which is visible at the current zoom level
188
+ let redraw = false
189
+ //go through the layers
190
+ const zf = this.app.getZoomFactor()
191
+ for (const lay of this.app.layers) {
192
+ if (!lay.visible) continue
193
+ if (lay.getDatasetComponent(zf) != this) continue
194
+ //found one layer. No need to seek more.
195
+ redraw = true
196
+ break
197
+ }
198
+ if (monitor) monitorDuration('check redraw 1')
199
+
200
+ if (!redraw) return
201
+
202
+ // 2. the tile is within the view, that is its geo envelope intersects the viewer geo envelope.
203
+ const env = this.app.updateExtentGeo()
204
+ const envT = tile_.extGeo
205
+ if (env.xMax <= envT.xMin) return
206
+ if (env.xMin >= envT.xMax) return
207
+ if (env.yMax <= envT.yMin) return
208
+ if (env.yMin >= envT.yMax) return
209
+
210
+ if (monitor) monitorDuration('check redraw 2')
211
+ if (monitor) monitorDuration('*** TiledGrid parse end')
212
+
213
+ //redraw
214
+ redrawFun()
215
+ })()
248
216
  }
249
217
  }
250
218
  return this
package/src/index.js CHANGED
@@ -12,7 +12,6 @@ export { DatasetComponent } from './DatasetComponent.js'
12
12
  // export dataset types
13
13
  export { TiledGrid } from './dataset/TiledGrid.js'
14
14
  export { CSVGrid } from './dataset/CSVGrid.js'
15
- //export { ParquetGrid } from "./dataset/ParquetGrid"
16
15
  //export { GeoTIFF } from "./dataset/GeoTIFF"
17
16
 
18
17
  // export styles
@@ -53,6 +52,9 @@ export * from './utils/stretching.js'
53
52
 
54
53
  export { getClass } from './utils/Utils.js'
55
54
 
55
+
56
+
57
+
56
58
  import { GeoCanvas } from './GeoCanvas.js'
57
59
  import { geoAzimuthalEqualArea } from 'd3-geo'
58
60
 
@@ -1,122 +0,0 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { DatasetComponent } from '../DatasetComponent.js'
5
- import { tableFromIPC } from 'apache-arrow'
6
- //import { readParquet } from "parquet-wasm"
7
-
8
- /**
9
- * A dataset composed of a single parquet file (not tiled).
10
- *
11
- * @author Julien Gaffuri
12
- */
13
- export class ParquetGrid extends DatasetComponent {
14
- /**
15
- * @param {string} url The URL of the dataset.
16
- * @param {number} resolution The dataset resolution in geographical unit.
17
- * @param {{preprocess?:(function(import("../Dataset").Cell):boolean), readParquetFun?:Function}} opts
18
- */
19
- constructor(url, resolution, opts = {}) {
20
- super(url, resolution, opts)
21
-
22
- /**
23
- * @private
24
- * @type {Array.<import("../Dataset").Cell>} */
25
- this.cells = []
26
-
27
- /**
28
- * @type {string}
29
- * @private */
30
- this.infoLoadingStatus = 'notLoaded'
31
-
32
- if (!opts.readParquetFun) throw new Error('readParquet function needed for parquet dataset')
33
-
34
- /**
35
- * @type {Function}
36
- * @private */
37
- this.readParquetFun = opts.readParquetFun
38
- }
39
-
40
- /**
41
- * Request data within a geographic envelope.
42
- *
43
- * @param {import("../Dataset").Envelope|undefined} e
44
- * @param {function():void} redraw
45
- */
46
- getData(e, redraw) {
47
- //check if data already loaded
48
- if (this.infoLoadingStatus != 'notLoaded') return this
49
-
50
- //load data
51
- this.infoLoadingStatus = 'loading'
52
- ;(async () => {
53
- try {
54
- const resp = await fetch(this.url)
55
- const parquetUint8Array = new Uint8Array(await resp.arrayBuffer())
56
- const arrowUint8Array = this.readParquetFun(parquetUint8Array)
57
-
58
- const t = tableFromIPC(arrowUint8Array)
59
- //see https://arrow.apache.org/docs/js/
60
- //https://loaders.gl/arrowjs/docs/developer-guide/tables#record-tojson-and-toarray
61
-
62
- this.cells = []
63
- for (const e of t) {
64
- //get cell
65
- const c = e.toJSON()
66
-
67
- //preprocess/filter
68
- if (this.preprocess) {
69
- const b = this.preprocess(c)
70
- if (b == false) continue
71
- this.cells.push(c)
72
- } else {
73
- this.cells.push(c)
74
- }
75
- }
76
-
77
- //TODO check if redraw is necessary
78
- //that is if the dataset belongs to a layer which is visible at the current zoom level
79
-
80
- //execute the callback, usually a draw function
81
- if (redraw) redraw()
82
-
83
- this.infoLoadingStatus = 'loaded'
84
- } catch (error) {
85
- //mark as failed
86
- this.infoLoadingStatus = 'failed'
87
- this.cells = []
88
- }
89
- })()
90
-
91
- return this
92
- }
93
-
94
- /**
95
- * Fill the view cache with all cells which are within a geographical envelope.
96
- *
97
- * @param {import("../Dataset").Envelope} extGeo
98
- * @returns {void}
99
- */
100
- updateViewCache(extGeo) {
101
- //data not loaded yet
102
- if (!this.cells) return
103
-
104
- this.cellsViewCache = []
105
- for (const cell of this.cells) {
106
- if (+cell.x + this.resolution < extGeo.xMin) continue
107
- if (+cell.x - this.resolution > extGeo.xMax) continue
108
- if (+cell.y + this.resolution < extGeo.yMin) continue
109
- if (+cell.y - this.resolution > extGeo.yMax) continue
110
- this.cellsViewCache.push(cell)
111
- }
112
- }
113
- }
114
-
115
- /**
116
- * Retrieve parquet wasm decoder
117
- */
118
- const getReadParquet = async () => {
119
- //const parquetModule = await import("https://unpkg.com/parquet-wasm@0.4.0-beta.5/esm/arrow2.js");
120
- //await parquetModule.default();
121
- //return parquetModule.readParquet;
122
- }