gridviz 3.0.15 → 3.0.16
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 +7959 -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 +495 -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/utils/stretching.js
CHANGED
|
@@ -1,133 +1,120 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @module utils
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//TODO
|
|
10
|
-
//TODO
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
if (exp == 0) continue
|
|
122
|
-
const f = fun(exp)
|
|
123
|
-
test(f, fun, exp)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
for (let fun of [exponentialScale, logarithmicScale])
|
|
128
|
-
for (let base = -20; base <= 20; base += 1) {
|
|
129
|
-
//if (exp == 0) continue
|
|
130
|
-
const f = fun(base)
|
|
131
|
-
test(f, fun, base, 1e-10)
|
|
132
|
-
}
|
|
133
|
-
*/
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module utils
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
//TODO invert for circular
|
|
9
|
+
//TODO use Math.sqrt
|
|
10
|
+
//TODO validate
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Some function [0,1]->[0,1] to stretch range of values.
|
|
14
|
+
* @see https://github.com/eurostat/gridviz/blob/master/docs/reference.md#stretching
|
|
15
|
+
* @see https://observablehq.com/@jgaffuri/stretching
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
//identity function
|
|
19
|
+
const identity = (t) => t
|
|
20
|
+
identity.invert = identity
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {number} base
|
|
24
|
+
* @returns {function(number):number}
|
|
25
|
+
*/
|
|
26
|
+
export const exponentialScale = (base = 3) => {
|
|
27
|
+
if (base == 0) return identity
|
|
28
|
+
const a = Math.exp(base) - 1
|
|
29
|
+
const f = (t) => (Math.exp(t * base) - 1) / a
|
|
30
|
+
f.invert = (t) => Math.log(a * t + 1) / base
|
|
31
|
+
return f
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {number} base
|
|
36
|
+
* @returns {function(number):number}
|
|
37
|
+
*/
|
|
38
|
+
export const logarithmicScale = (base = 3) => {
|
|
39
|
+
if (base == 0) return identity
|
|
40
|
+
const a = Math.exp(base),
|
|
41
|
+
b = 1 - a
|
|
42
|
+
const f = (t) => 1 - Math.log(a + t * b) / base
|
|
43
|
+
f.invert = (t) => (Math.exp((1 - t) * base) - a) / b
|
|
44
|
+
return f
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} exponent
|
|
49
|
+
* @returns {function(number):number}
|
|
50
|
+
*/
|
|
51
|
+
export const powerScale = (exponent = 3) => {
|
|
52
|
+
if (exponent == 1) return identity
|
|
53
|
+
//TODO if (exponent == 0.5) return Math.sqrt
|
|
54
|
+
const f = (t) => Math.pow(t, exponent)
|
|
55
|
+
const a = 1 / exponent
|
|
56
|
+
f.invert = (t) => Math.pow(t, a)
|
|
57
|
+
return f
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {number} exponent
|
|
62
|
+
* @returns {function(number):number}
|
|
63
|
+
*/
|
|
64
|
+
export const powerInverseScale = (exponent = 3) => {
|
|
65
|
+
if (exponent == 1) return identity
|
|
66
|
+
//TODO if (exponent == 2) return t => 1 - Math.sqrt(1 - t)
|
|
67
|
+
const a = 1 / exponent
|
|
68
|
+
const f = (t) => 1 - Math.pow(1 - t, a)
|
|
69
|
+
f.invert = (t) => 1 - Math.pow(1 - t, exponent)
|
|
70
|
+
return f
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {number} circularity
|
|
75
|
+
* @returns {function(number):number}
|
|
76
|
+
*/
|
|
77
|
+
export const circularScale = (circularity = 0.8) => {
|
|
78
|
+
if (circularity == 0) return identity
|
|
79
|
+
if (circularity == 1) return (t) => Math.sqrt(t * (2 - t))
|
|
80
|
+
else {
|
|
81
|
+
const a = circularity / (1 - circularity)
|
|
82
|
+
return (t) => Math.sqrt(1 / (a * a) + t * (2 / a + 2 - t)) - 1 / a
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {number} circularity
|
|
88
|
+
* @returns {function(number):number}
|
|
89
|
+
*/
|
|
90
|
+
export const circularInverseScale = (circularity = 0.8) => {
|
|
91
|
+
if (circularity == 0) return identity
|
|
92
|
+
const f = circularScale(circularity)
|
|
93
|
+
return (t) => 1 - f(1 - t)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//test
|
|
97
|
+
/*
|
|
98
|
+
const test = (f, fun, a, err = 1e-12) => {
|
|
99
|
+
for (let t = 0; t <= 1; t += 1 / 50) {
|
|
100
|
+
const er = t - f.invert(f(t))
|
|
101
|
+
if (Math.abs(er) < err) continue
|
|
102
|
+
console.log(fun, a, er)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (let fun of [powerScale, powerInverseScale])
|
|
107
|
+
for (let exp = -30; exp <= 50; exp += 1) {
|
|
108
|
+
if (exp == 0) continue
|
|
109
|
+
const f = fun(exp)
|
|
110
|
+
test(f, fun, exp)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
for (let fun of [exponentialScale, logarithmicScale])
|
|
115
|
+
for (let base = -20; base <= 20; base += 1) {
|
|
116
|
+
//if (exp == 0) continue
|
|
117
|
+
const f = fun(base)
|
|
118
|
+
test(f, fun, base, 1e-10)
|
|
119
|
+
}
|
|
120
|
+
*/
|