gridviz 3.0.15 → 3.0.17
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/README.md +127 -128
- package/dist/gridviz.js +7958 -7861
- package/dist/gridviz.min.js +1 -1
- package/package.json +74 -74
- package/src/button/ZoomButtons.js +101 -96
- package/src/core/Dataset.js +154 -157
- package/src/core/Drawable.js +60 -61
- package/src/core/GeoCanvas.js +409 -370
- package/src/core/Layer.js +23 -25
- package/src/core/Legend.js +108 -110
- package/src/core/Map.js +494 -495
- package/src/core/MultiResolutionDataset.js +93 -97
- package/src/core/Style.js +98 -99
- package/src/dataset/CSVGrid.js +112 -112
- package/src/dataset/GeoTIFF.js +122 -123
- package/src/dataset/JSGrid.js +55 -54
- package/src/dataset/TiledGrid.js +289 -288
- package/src/dataset/worker.js +18 -0
- package/src/index.js +77 -71
- package/src/layer/BackgroundLayer.js +162 -158
- package/src/layer/BackgroundLayerImage.js +81 -84
- package/src/layer/BackgroundLayerWMS.js +104 -108
- package/src/layer/GeoJSONLayer.js +214 -220
- package/src/layer/GridLayer.js +148 -157
- package/src/layer/LabelLayer.js +194 -193
- package/src/legend/ColorCategoryLegend.js +109 -110
- package/src/legend/ColorDiscreteLegend.js +100 -102
- package/src/legend/ColorLegend.js +115 -118
- package/src/legend/OrientationLegend.js +89 -91
- package/src/legend/SizeLegend.js +224 -224
- package/src/legend/TernaryLegend.js +302 -210
- package/src/style/CompositionStyle.js +291 -288
- package/src/style/DotDensityStyle.js +133 -134
- package/src/style/ImageStyle.js +100 -102
- package/src/style/IsoFenceStyle.js +217 -203
- package/src/style/JoyPlotStyle.js +127 -128
- package/src/style/LegoStyle.js +110 -110
- package/src/style/MosaicStyle.js +99 -99
- package/src/style/NinjaStarStyle.js +102 -102
- package/src/style/PillarStyle.js +207 -208
- package/src/style/SegmentStyle.js +105 -105
- package/src/style/ShapeColorSizeStyle.js +147 -132
- package/src/style/SideCategoryStyle.js +112 -114
- package/src/style/SideStyle.js +212 -205
- package/src/style/SquareColorCategoryWebGLStyle.js +107 -108
- package/src/style/SquareColorWebGLStyle.js +126 -126
- package/src/style/StrokeStyle.js +135 -136
- package/src/style/TanakaStyle.js +69 -68
- package/src/style/TextStyle.js +110 -111
- package/src/style/TimeSeriesStyle.js +222 -229
- package/src/utils/scale.js +218 -228
- package/src/utils/stretching.js +120 -133
- package/src/utils/ternary.js +203 -204
- package/src/utils/utils.js +58 -63
- package/src/utils/webGLUtils.js +72 -70
package/src/layer/GridLayer.js
CHANGED
|
@@ -1,157 +1,148 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
import { Layer } from '../core/Layer.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A layer, which specifies a dataset to be shown with specified styles.
|
|
8
|
-
*
|
|
9
|
-
* @module layer
|
|
10
|
-
* @author Joseph Davies, Julien Gaffuri
|
|
11
|
-
*/
|
|
12
|
-
export class GridLayer extends Layer {
|
|
13
|
-
/**
|
|
14
|
-
* @param {import("../core/Dataset").Dataset|import("../core/MultiResolutionDataset").MultiResolutionDataset} dataset The dataset to show.
|
|
15
|
-
* @param {Array.<import("../core/Style").Style>} styles The styles, ordered in drawing order.
|
|
16
|
-
* @param {{visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,minPixelsPerCell?:number,cellInfoHTML?:function(import("../core/Dataset").Cell):string}} opts
|
|
17
|
-
*/
|
|
18
|
-
constructor(dataset, styles, opts = {}) {
|
|
19
|
-
super(opts)
|
|
20
|
-
opts = opts || {}
|
|
21
|
-
|
|
22
|
-
/** @type {import("../core/Dataset").Dataset|import("../core/MultiResolutionDataset").MultiResolutionDataset} */
|
|
23
|
-
this.dataset = dataset
|
|
24
|
-
|
|
25
|
-
/** @type {Array.<import("../core/Style").Style>} */
|
|
26
|
-
this.styles = styles
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* This parameter is used when the dataset is a MultiResolutionDataset.
|
|
30
|
-
* It defines the minimum number of pixels a grid cell should have to select the dataset to display based on its resolution.
|
|
31
|
-
* A low value, means that the map will be more detailled (smaller cells).
|
|
32
|
-
* A high value, means that the map will be less detailled (larger cells).
|
|
33
|
-
* This value should be higher than 1, otherwise it means a grid cell is smaller than the screen resolution.
|
|
34
|
-
* For more complex cell representations that require some more map space, this value should be higher.
|
|
35
|
-
* @type {number} */
|
|
36
|
-
this.minPixelsPerCell = opts.minPixelsPerCell || 3
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The function returning cell information as HTML.
|
|
40
|
-
* This is typically used for tooltip information.
|
|
41
|
-
* @type {function(import("../core/Dataset").Cell, number):string} */
|
|
42
|
-
this.cellInfoHTML = opts.cellInfoHTML || GridLayer.defaultCellInfoHTML
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** */
|
|
46
|
-
draw(geoCanvas, legend) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
//get layer dataset component
|
|
52
|
-
/** @type {import('../core/Dataset.js').Dataset|undefined} */
|
|
53
|
-
const dsc = this.getDataset(z)
|
|
54
|
-
if (!dsc) return
|
|
55
|
-
|
|
56
|
-
//launch data download, if necessary
|
|
57
|
-
dsc.getData(geoCanvas.extGeo)
|
|
58
|
-
|
|
59
|
-
//update dataset view cache
|
|
60
|
-
dsc.updateViewCache(geoCanvas.extGeo)
|
|
61
|
-
|
|
62
|
-
//draw cells, style by style
|
|
63
|
-
for (const s of this.styles) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const buf = []
|
|
150
|
-
for (const key of Object.keys(cell)) {
|
|
151
|
-
if (key === 'x') continue
|
|
152
|
-
if (key === 'y') continue
|
|
153
|
-
buf.push('<b>', key, '</b>', ' : ', cell[key], '<br>')
|
|
154
|
-
}
|
|
155
|
-
return buf.join('')
|
|
156
|
-
}
|
|
157
|
-
}
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { Layer } from '../core/Layer.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A layer, which specifies a dataset to be shown with specified styles.
|
|
8
|
+
*
|
|
9
|
+
* @module layer
|
|
10
|
+
* @author Joseph Davies, Julien Gaffuri
|
|
11
|
+
*/
|
|
12
|
+
export class GridLayer extends Layer {
|
|
13
|
+
/**
|
|
14
|
+
* @param {import("../core/Dataset").Dataset|import("../core/MultiResolutionDataset").MultiResolutionDataset} dataset The dataset to show.
|
|
15
|
+
* @param {Array.<import("../core/Style").Style>} styles The styles, ordered in drawing order.
|
|
16
|
+
* @param {{visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,minPixelsPerCell?:number,cellInfoHTML?:function(import("../core/Dataset").Cell):string}} opts
|
|
17
|
+
*/
|
|
18
|
+
constructor(dataset, styles, opts = {}) {
|
|
19
|
+
super(opts)
|
|
20
|
+
opts = opts || {}
|
|
21
|
+
|
|
22
|
+
/** @type {import("../core/Dataset").Dataset|import("../core/MultiResolutionDataset").MultiResolutionDataset} */
|
|
23
|
+
this.dataset = dataset
|
|
24
|
+
|
|
25
|
+
/** @type {Array.<import("../core/Style").Style>} */
|
|
26
|
+
this.styles = styles
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This parameter is used when the dataset is a MultiResolutionDataset.
|
|
30
|
+
* It defines the minimum number of pixels a grid cell should have to select the dataset to display based on its resolution.
|
|
31
|
+
* A low value, means that the map will be more detailled (smaller cells).
|
|
32
|
+
* A high value, means that the map will be less detailled (larger cells).
|
|
33
|
+
* This value should be higher than 1, otherwise it means a grid cell is smaller than the screen resolution.
|
|
34
|
+
* For more complex cell representations that require some more map space, this value should be higher.
|
|
35
|
+
* @type {number} */
|
|
36
|
+
this.minPixelsPerCell = opts.minPixelsPerCell || 3
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The function returning cell information as HTML.
|
|
40
|
+
* This is typically used for tooltip information.
|
|
41
|
+
* @type {function(import("../core/Dataset").Cell, number):string} */
|
|
42
|
+
this.cellInfoHTML = opts.cellInfoHTML || GridLayer.defaultCellInfoHTML
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** */
|
|
46
|
+
draw(geoCanvas, legend) {
|
|
47
|
+
//get zoom level
|
|
48
|
+
const z = geoCanvas.view.z
|
|
49
|
+
const ctx = geoCanvas.offscreenCtx
|
|
50
|
+
|
|
51
|
+
//get layer dataset component
|
|
52
|
+
/** @type {import('../core/Dataset.js').Dataset|undefined} */
|
|
53
|
+
const dsc = this.getDataset(z)
|
|
54
|
+
if (!dsc) return
|
|
55
|
+
|
|
56
|
+
//launch data download, if necessary
|
|
57
|
+
dsc.getData(geoCanvas.extGeo)
|
|
58
|
+
|
|
59
|
+
//update dataset view cache
|
|
60
|
+
dsc.updateViewCache(geoCanvas.extGeo)
|
|
61
|
+
|
|
62
|
+
//draw cells, style by style
|
|
63
|
+
for (const s of this.styles) {
|
|
64
|
+
//check if style is visible
|
|
65
|
+
if (s.visible && !s.visible(z)) continue
|
|
66
|
+
|
|
67
|
+
//set style alpha and blend mode
|
|
68
|
+
//TODO: multiply by layer alpha ?
|
|
69
|
+
ctx.globalAlpha = s.alpha ? s.alpha(z) : 1.0
|
|
70
|
+
if (s.blendOperation) ctx.globalCompositeOperation = s.blendOperation(z)
|
|
71
|
+
|
|
72
|
+
//set affin transform to draw with geographical coordinates
|
|
73
|
+
geoCanvas.setCanvasTransform()
|
|
74
|
+
|
|
75
|
+
//draw with style
|
|
76
|
+
s.draw(dsc.getViewCache(), geoCanvas, dsc.getResolution())
|
|
77
|
+
|
|
78
|
+
//draw style filter
|
|
79
|
+
if (s.filterColor) s.drawFilter(geoCanvas)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//add legend element
|
|
83
|
+
if (legend) {
|
|
84
|
+
for (const s of this.styles) {
|
|
85
|
+
//check if style is visible
|
|
86
|
+
if (s.visible && !s.visible(z)) continue
|
|
87
|
+
GridLayer.addLegends(legend, s.legends)
|
|
88
|
+
|
|
89
|
+
//case for styles of styles, like kernel smoothing
|
|
90
|
+
//TODO do better
|
|
91
|
+
if (s['styles']) {
|
|
92
|
+
for (const s2 of s['styles']) {
|
|
93
|
+
if (s2.visible && !s2.visible(z)) continue
|
|
94
|
+
GridLayer.addLegends(legend, s2.legends)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @private */
|
|
102
|
+
static addLegends(legendComp, lg) {
|
|
103
|
+
if (Array.isArray(lg)) for (const lg_ of lg) this.addLegends(legendComp, lg_)
|
|
104
|
+
else legendComp.node().append(lg.div.node())
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Return the relevant dataset component for a specified zoom.
|
|
109
|
+
*
|
|
110
|
+
* @param {number} z
|
|
111
|
+
* @returns {import("../core/Dataset").Dataset|undefined}
|
|
112
|
+
* */
|
|
113
|
+
getDataset(z) {
|
|
114
|
+
return this.dataset.getDataset(z, this.minPixelsPerCell)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Set/get style stack.
|
|
119
|
+
*
|
|
120
|
+
* @param {undefined|import("../core/Style").Style|Array.<import("../core/Style").Style>} styles
|
|
121
|
+
* @returns { this | Array.<import("../core/Style").Style> }
|
|
122
|
+
*/
|
|
123
|
+
styles_(styles) {
|
|
124
|
+
if (arguments.length === 0) return this.styles
|
|
125
|
+
if (arguments.length === 1)
|
|
126
|
+
if (Array.isArray(styles)) this.styles = styles
|
|
127
|
+
else this.styles = [styles]
|
|
128
|
+
else this.styles = arguments
|
|
129
|
+
return this
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The default function returning cell information as HTML.
|
|
134
|
+
* This is typically used for tooltip information.
|
|
135
|
+
*
|
|
136
|
+
* @param {import("../core/Dataset").Cell} cell
|
|
137
|
+
* @returns {string}
|
|
138
|
+
*/
|
|
139
|
+
static defaultCellInfoHTML(cell) {
|
|
140
|
+
const buf = []
|
|
141
|
+
for (const key of Object.keys(cell)) {
|
|
142
|
+
if (key === 'x') continue
|
|
143
|
+
if (key === 'y') continue
|
|
144
|
+
buf.push('<b>', key, '</b>', ' : ', cell[key], '<br>')
|
|
145
|
+
}
|
|
146
|
+
return buf.join('')
|
|
147
|
+
}
|
|
148
|
+
}
|