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.
- package/README.md +129 -129
- package/dist/gridviz.js +17487 -17471
- package/dist/gridviz.min.js +2 -2
- package/package.json +73 -73
- package/src/button/Button.js +67 -67
- package/src/button/FullscreenButton.js +121 -121
- package/src/button/ZoomButtons.js +103 -103
- package/src/core/Dataset.js +154 -154
- package/src/core/Drawable.js +78 -78
- package/src/core/GeoCanvas.js +443 -443
- package/src/core/Layer.js +23 -23
- package/src/core/Legend.js +108 -108
- package/src/core/Map.js +568 -552
- package/src/core/MultiResolutionDataset.js +93 -93
- package/src/core/Style.js +98 -98
- package/src/core/Tooltip.js +182 -182
- package/src/dataset/COGeo.js +25 -25
- package/src/dataset/CSVGrid.js +112 -112
- package/src/dataset/GeoTIFF.js +122 -122
- package/src/dataset/JSGrid.js +55 -55
- package/src/dataset/TiledGrid.js +302 -302
- package/src/dataset/worker.js +18 -18
- package/src/index.js +79 -79
- package/src/layer/BackgroundLayer.js +173 -173
- package/src/layer/BackgroundLayerImage.js +81 -81
- package/src/layer/BackgroundLayerWMS.js +104 -104
- package/src/layer/GeoJSONLayer.js +276 -276
- package/src/layer/GridLayer.js +166 -166
- package/src/layer/LabelLayer.js +194 -194
- package/src/legend/ColorCategoryLegend.js +109 -109
- package/src/legend/ColorDiscreteLegend.js +100 -100
- package/src/legend/ColorLegend.js +115 -115
- package/src/legend/OrientationLegend.js +89 -89
- package/src/legend/SizeLegend.js +224 -224
- package/src/legend/TernaryLegend.js +302 -302
- package/src/style/CompositionStyle.js +291 -291
- package/src/style/DotDensityStyle.js +133 -133
- package/src/style/ImageStyle.js +100 -100
- package/src/style/Interpolator.js +258 -258
- package/src/style/IsoFenceStyle.js +217 -217
- package/src/style/JoyPlotStyle.js +180 -180
- package/src/style/LegoStyle.js +132 -132
- package/src/style/MosaicStyle.js +99 -99
- package/src/style/NinjaStarStyle.js +102 -102
- package/src/style/PillarStyle.js +207 -207
- package/src/style/SegmentStyle.js +105 -105
- package/src/style/ShadingRayStyle.js +280 -280
- package/src/style/ShadingStyle.js +72 -72
- package/src/style/ShapeColorSizeStyle.js +147 -147
- package/src/style/SideCategoryStyle.js +112 -112
- package/src/style/SideStyle.js +217 -217
- package/src/style/SideTanakaStyle.js +154 -154
- package/src/style/SquareColorCategoryWebGLStyle.js +307 -294
- package/src/style/SquareColorWebGLStyle.js +126 -126
- package/src/style/StrokeStyle.js +135 -135
- package/src/style/TextStyle.js +110 -110
- package/src/style/TimeSeriesStyle.js +222 -222
- package/src/utils/WebGLRectangleColoring.js +106 -106
- package/src/utils/WebGLSquareColoring.js +118 -118
- package/src/utils/WebGLSquareColoringAdvanced.js +227 -227
- package/src/utils/WebGLSquareColoringKS.js +153 -153
- package/src/utils/scale.js +255 -255
- package/src/utils/stretching.js +120 -120
- package/src/utils/ternary.js +208 -208
- package/src/utils/utils.js +125 -125
- package/src/utils/webGLUtils.js +73 -73
- 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
|
+
}
|