@keneth80/k-chart 1.26.1 → 1.27.0
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/CHANGELOG.md +51 -0
- package/README.md +129 -1100
- package/docs/code-graph-handoff.md +19 -37
- package/docs/configuration-reference.md +8 -1
- package/docs/functional-api.md +77 -0
- package/docs/react-nextjs.md +62 -8
- package/docs/refactor-plan.md +39 -23
- package/docs/release.md +9 -4
- package/examples/stackblitz-simple-api-basic/package-lock.json +96 -4
- package/examples/stackblitz-simple-api-basic/package.json +1 -1
- package/examples/stackblitz-subcell-heatmap-basic/README.md +48 -0
- package/examples/stackblitz-subcell-heatmap-basic/index.html +13 -0
- package/examples/stackblitz-subcell-heatmap-basic/package-lock.json +1788 -0
- package/examples/stackblitz-subcell-heatmap-basic/package.json +23 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/app.ts +212 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/component.css +169 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/heatmap-demo-core.ts +505 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/heatmap-demo.ts +23 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/main.ts +15 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/maplibre-compat.ts +6 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/model.ts +242 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/raster.ts +121 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/style.css +15 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/synthetic.ts +72 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/vendor.d.ts +3 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-topology-basic/package-lock.json +96 -4
- package/examples/stackblitz-topology-basic/package.json +1 -1
- package/examples/stackblitz-webgl-line-basic/package-lock.json +96 -4
- package/examples/stackblitz-webgl-line-basic/package.json +1 -1
- package/examples/stackblitz-world-activity-map/package.json +1 -1
- package/lib/core/contracts.d.ts +6 -2
- package/lib/core/contracts.d.ts.map +1 -1
- package/lib/series/svg-graph.d.ts +29 -0
- package/lib/series/svg-graph.d.ts.map +1 -1
- package/lib/series/svg-graph.js +509 -80
- package/lib/series/svg-graph.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/** Geographic scalar samples, not a point-density heatmap. Coordinates use [lon, lat]. */
|
|
2
|
+
export interface Bounds {
|
|
3
|
+
west: number;
|
|
4
|
+
south: number;
|
|
5
|
+
east: number;
|
|
6
|
+
north: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SubcellField {
|
|
9
|
+
id: string;
|
|
10
|
+
bounds: Bounds;
|
|
11
|
+
/** Node samples; row 0 is north, column 0 is west. Both boundaries are included. */
|
|
12
|
+
columns: number;
|
|
13
|
+
rows: number;
|
|
14
|
+
/** Row-major. null is unobserved; numeric zero is a valid sample. */
|
|
15
|
+
values: readonly (number | null)[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface FieldFrame {
|
|
19
|
+
time: string;
|
|
20
|
+
metric: {
|
|
21
|
+
name: string;
|
|
22
|
+
unit: 'index-0-100';
|
|
23
|
+
range: readonly [0, 100];
|
|
24
|
+
};
|
|
25
|
+
provenance: 'synthetic' | 'observed' | 'modelled';
|
|
26
|
+
cells: readonly SubcellField[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Probe {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
longitude: number;
|
|
33
|
+
latitude: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const CELL_STEP = 0.5;
|
|
37
|
+
export const MERCATOR_LAT_LIMIT = 85;
|
|
38
|
+
const EPSILON = 1e-9;
|
|
39
|
+
|
|
40
|
+
export function validateBounds(bounds: Bounds): void {
|
|
41
|
+
if (
|
|
42
|
+
![bounds.west, bounds.east, bounds.south, bounds.north].every(Number.isFinite)
|
|
43
|
+
|| bounds.west < -180
|
|
44
|
+
|| bounds.east > 180
|
|
45
|
+
|| bounds.west >= bounds.east
|
|
46
|
+
|| bounds.south < -MERCATOR_LAT_LIMIT
|
|
47
|
+
|| bounds.north > MERCATOR_LAT_LIMIT
|
|
48
|
+
|| bounds.south >= bounds.north
|
|
49
|
+
) {
|
|
50
|
+
throw new RangeError(
|
|
51
|
+
'Invalid non-wrapping bounds. Split antimeridian data and keep latitude within [-85, 85].'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function validateCell(cell: SubcellField): void {
|
|
57
|
+
validateBounds(cell.bounds);
|
|
58
|
+
const {bounds} = cell;
|
|
59
|
+
if (
|
|
60
|
+
!cell.id
|
|
61
|
+
|| Math.abs(bounds.east - bounds.west - CELL_STEP) > EPSILON
|
|
62
|
+
|| Math.abs(bounds.north - bounds.south - CELL_STEP) > EPSILON
|
|
63
|
+
|| Math.abs(bounds.west / CELL_STEP - Math.round(bounds.west / CELL_STEP)) > EPSILON
|
|
64
|
+
|| Math.abs(bounds.south / CELL_STEP - Math.round(bounds.south / CELL_STEP)) > EPSILON
|
|
65
|
+
) {
|
|
66
|
+
throw new RangeError('Each cell needs an id and aligned 0.5-degree bounds.');
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
!Number.isInteger(cell.rows)
|
|
70
|
+
|| !Number.isInteger(cell.columns)
|
|
71
|
+
|| cell.rows < 2
|
|
72
|
+
|| cell.columns < 2
|
|
73
|
+
|| cell.rows > 1024
|
|
74
|
+
|| cell.columns > 1024
|
|
75
|
+
|| cell.values.length !== cell.rows * cell.columns
|
|
76
|
+
) {
|
|
77
|
+
throw new RangeError('Invalid sample matrix.');
|
|
78
|
+
}
|
|
79
|
+
for (const value of cell.values) {
|
|
80
|
+
if (!(value === null || (Number.isFinite(value) && value >= 0 && value <= 100))) {
|
|
81
|
+
throw new RangeError('Values must be finite numbers in [0, 100] or null.');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function validateFrame(frame: FieldFrame): void {
|
|
87
|
+
if (
|
|
88
|
+
!Number.isFinite(Date.parse(frame.time))
|
|
89
|
+
|| frame.metric.unit !== 'index-0-100'
|
|
90
|
+
|| frame.metric.range[0] !== 0
|
|
91
|
+
|| frame.metric.range[1] !== 100
|
|
92
|
+
|| !['synthetic', 'observed', 'modelled'].includes(frame.provenance)
|
|
93
|
+
) {
|
|
94
|
+
throw new TypeError('Invalid frame metadata.');
|
|
95
|
+
}
|
|
96
|
+
if (frame.cells.length < 1 || frame.cells.length > 100) {
|
|
97
|
+
throw new RangeError('This example supports 1 to 100 loaded cells.');
|
|
98
|
+
}
|
|
99
|
+
const ids = new Set<string>();
|
|
100
|
+
const positions = new Set<string>();
|
|
101
|
+
for (const cell of frame.cells) {
|
|
102
|
+
validateCell(cell);
|
|
103
|
+
const position = `${cell.bounds.west},${cell.bounds.south}`;
|
|
104
|
+
if (ids.has(cell.id) || positions.has(position)) {
|
|
105
|
+
throw new Error('Duplicate cell id or bounds.');
|
|
106
|
+
}
|
|
107
|
+
ids.add(cell.id);
|
|
108
|
+
positions.add(position);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function unionBounds(cells: readonly SubcellField[]): Bounds {
|
|
113
|
+
if (!cells.length) {
|
|
114
|
+
throw new RangeError('Cells are required.');
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
west: Math.min(...cells.map((cell) => cell.bounds.west)),
|
|
118
|
+
south: Math.min(...cells.map((cell) => cell.bounds.south)),
|
|
119
|
+
east: Math.max(...cells.map((cell) => cell.bounds.east)),
|
|
120
|
+
north: Math.max(...cells.map((cell) => cell.bounds.north))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function contains(bounds: Bounds, longitude: number, latitude: number): boolean {
|
|
125
|
+
return Number.isFinite(longitude)
|
|
126
|
+
&& Number.isFinite(latitude)
|
|
127
|
+
&& longitude >= bounds.west
|
|
128
|
+
&& longitude <= bounds.east
|
|
129
|
+
&& latitude >= bounds.south
|
|
130
|
+
&& latitude <= bounds.north;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Bilinear interpolation of node values. Missing neighbors remain missing. */
|
|
134
|
+
export function sampleCell(
|
|
135
|
+
cell: SubcellField,
|
|
136
|
+
longitude: number,
|
|
137
|
+
latitude: number
|
|
138
|
+
): number | null {
|
|
139
|
+
if (!contains(cell.bounds, longitude, latitude)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const {bounds} = cell;
|
|
143
|
+
const x = (longitude - bounds.west) / (bounds.east - bounds.west) * (cell.columns - 1);
|
|
144
|
+
const y = (bounds.north - latitude) / (bounds.north - bounds.south) * (cell.rows - 1);
|
|
145
|
+
const x0 = Math.min(cell.columns - 2, Math.floor(x));
|
|
146
|
+
const y0 = Math.min(cell.rows - 2, Math.floor(y));
|
|
147
|
+
const tx = x - x0;
|
|
148
|
+
const ty = y - y0;
|
|
149
|
+
const weights = [(1 - tx) * (1 - ty), tx * (1 - ty), (1 - tx) * ty, tx * ty];
|
|
150
|
+
const values = [
|
|
151
|
+
cell.values[y0 * cell.columns + x0],
|
|
152
|
+
cell.values[y0 * cell.columns + x0 + 1],
|
|
153
|
+
cell.values[(y0 + 1) * cell.columns + x0],
|
|
154
|
+
cell.values[(y0 + 1) * cell.columns + x0 + 1]
|
|
155
|
+
];
|
|
156
|
+
let result = 0;
|
|
157
|
+
for (let index = 0; index < weights.length; index += 1) {
|
|
158
|
+
if (weights[index] < 1e-10) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const value = values[index];
|
|
162
|
+
if (value === null) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
result += value * weights[index];
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function sampleFrame(
|
|
171
|
+
frame: FieldFrame,
|
|
172
|
+
longitude: number,
|
|
173
|
+
latitude: number
|
|
174
|
+
): number | null {
|
|
175
|
+
const cell = frame.cells.find((candidate) => contains(candidate.bounds, longitude, latitude));
|
|
176
|
+
return cell ? sampleCell(cell, longitude, latitude) : null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function frameStats(cell: SubcellField): {
|
|
180
|
+
min: number | null;
|
|
181
|
+
max: number | null;
|
|
182
|
+
sampleMean: number | null;
|
|
183
|
+
count: number;
|
|
184
|
+
} {
|
|
185
|
+
let min = Infinity;
|
|
186
|
+
let max = -Infinity;
|
|
187
|
+
let sum = 0;
|
|
188
|
+
let count = 0;
|
|
189
|
+
for (const value of cell.values) {
|
|
190
|
+
if (value !== null) {
|
|
191
|
+
min = Math.min(min, value);
|
|
192
|
+
max = Math.max(max, value);
|
|
193
|
+
sum += value;
|
|
194
|
+
count += 1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
min: count ? min : null,
|
|
199
|
+
max: count ? max : null,
|
|
200
|
+
sampleMean: count ? sum / count : null,
|
|
201
|
+
count
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function mixFrames(a: FieldFrame, b: FieldFrame, progress: number): FieldFrame {
|
|
206
|
+
if (!Number.isFinite(progress) || progress < 0 || progress > 1 || a.cells.length !== b.cells.length) {
|
|
207
|
+
throw new RangeError('Invalid frame blend.');
|
|
208
|
+
}
|
|
209
|
+
const cells = a.cells.map((cell, index) => {
|
|
210
|
+
const next = b.cells[index];
|
|
211
|
+
if (
|
|
212
|
+
cell.id !== next.id
|
|
213
|
+
|| cell.rows !== next.rows
|
|
214
|
+
|| cell.columns !== next.columns
|
|
215
|
+
|| JSON.stringify(cell.bounds) !== JSON.stringify(next.bounds)
|
|
216
|
+
) {
|
|
217
|
+
throw new Error('Frame blending requires matching geometry and cell order.');
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
...cell,
|
|
221
|
+
values: cell.values.map((value, valueIndex) => {
|
|
222
|
+
const nextValue = next.values[valueIndex];
|
|
223
|
+
if (progress === 0) return value;
|
|
224
|
+
if (progress === 1) return nextValue;
|
|
225
|
+
return value === null || nextValue === null
|
|
226
|
+
? null
|
|
227
|
+
: value + (nextValue - value) * progress;
|
|
228
|
+
})
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
return {...b, cells};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Spherical approximation for the explanatory UI, not geodesic analysis. */
|
|
235
|
+
export function approximateCellKm(bounds: Bounds): {widthKm: number; heightKm: number} {
|
|
236
|
+
const kilometersPerDegree = Math.PI * 6371 / 180;
|
|
237
|
+
return {
|
|
238
|
+
widthKm: (bounds.east - bounds.west) * kilometersPerDegree
|
|
239
|
+
* Math.cos((bounds.south + bounds.north) / 2 * Math.PI / 180),
|
|
240
|
+
heightKm: (bounds.north - bounds.south) * kilometersPerDegree
|
|
241
|
+
};
|
|
242
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {type Bounds, type FieldFrame, sampleFrame, validateBounds} from './model.js';
|
|
2
|
+
|
|
3
|
+
/** One fixed color scale for every cell, frame, and zoom level. */
|
|
4
|
+
export const COLOR_STOPS: readonly [number, readonly [number, number, number]][] = [
|
|
5
|
+
[0, [14, 49, 68]],
|
|
6
|
+
[20, [24, 121, 131]],
|
|
7
|
+
[40, [95, 181, 157]],
|
|
8
|
+
[60, [242, 209, 119]],
|
|
9
|
+
[80, [239, 119, 60]],
|
|
10
|
+
[100, [184, 35, 60]]
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export function colorFor(
|
|
14
|
+
value: number | null,
|
|
15
|
+
showLowValueBackground = true
|
|
16
|
+
): [number, number, number, number] {
|
|
17
|
+
if (value === null) {
|
|
18
|
+
return [0, 0, 0, 0];
|
|
19
|
+
}
|
|
20
|
+
if (!Number.isFinite(value) || value < 0 || value > 100) {
|
|
21
|
+
throw new RangeError('Invalid scalar value.');
|
|
22
|
+
}
|
|
23
|
+
let stopIndex = 0;
|
|
24
|
+
while (stopIndex < COLOR_STOPS.length - 2 && value > COLOR_STOPS[stopIndex + 1][0]) {
|
|
25
|
+
stopIndex += 1;
|
|
26
|
+
}
|
|
27
|
+
const [startValue, startColor] = COLOR_STOPS[stopIndex];
|
|
28
|
+
const [endValue, endColor] = COLOR_STOPS[stopIndex + 1];
|
|
29
|
+
const progress = (value - startValue) / (endValue - startValue);
|
|
30
|
+
return [
|
|
31
|
+
Math.round(startColor[0] + (endColor[0] - startColor[0]) * progress),
|
|
32
|
+
Math.round(startColor[1] + (endColor[1] - startColor[1]) * progress),
|
|
33
|
+
Math.round(startColor[2] + (endColor[2] - startColor[2]) * progress),
|
|
34
|
+
showLowValueBackground ? 224 : Math.round(224 * value / 100)
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function mercatorY(latitude: number): number {
|
|
39
|
+
return Math.log(Math.tan(Math.PI / 4 + latitude * Math.PI / 360));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function inverseMercatorY(value: number): number {
|
|
43
|
+
return (2 * Math.atan(Math.exp(value)) - Math.PI / 2) * 180 / Math.PI;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function geoToUV(
|
|
47
|
+
bounds: Bounds,
|
|
48
|
+
longitude: number,
|
|
49
|
+
latitude: number
|
|
50
|
+
): [number, number] {
|
|
51
|
+
return [
|
|
52
|
+
(longitude - bounds.west) / (bounds.east - bounds.west),
|
|
53
|
+
(mercatorY(bounds.north) - mercatorY(latitude))
|
|
54
|
+
/ (mercatorY(bounds.north) - mercatorY(bounds.south))
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function uvToGeo(bounds: Bounds, u: number, v: number): [number, number] {
|
|
59
|
+
return [
|
|
60
|
+
bounds.west + (bounds.east - bounds.west) * u,
|
|
61
|
+
inverseMercatorY(
|
|
62
|
+
mercatorY(bounds.north) - v * (mercatorY(bounds.north) - mercatorY(bounds.south))
|
|
63
|
+
)
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Pixel-center sampling in Web Mercator, not linear latitude screen placement. */
|
|
68
|
+
export function rasterPixels(
|
|
69
|
+
frame: FieldFrame,
|
|
70
|
+
bounds: Bounds,
|
|
71
|
+
width: number,
|
|
72
|
+
height: number,
|
|
73
|
+
showLowValueBackground = true
|
|
74
|
+
): Uint8ClampedArray {
|
|
75
|
+
validateBounds(bounds);
|
|
76
|
+
if (
|
|
77
|
+
!Number.isInteger(width)
|
|
78
|
+
|| !Number.isInteger(height)
|
|
79
|
+
|| width < 2
|
|
80
|
+
|| height < 2
|
|
81
|
+
|| width > 1024
|
|
82
|
+
|| height > 1024
|
|
83
|
+
) {
|
|
84
|
+
throw new RangeError('Raster size must be between 2 and 1024 pixels per side.');
|
|
85
|
+
}
|
|
86
|
+
const bytes = new Uint8ClampedArray(width * height * 4);
|
|
87
|
+
const northY = mercatorY(bounds.north);
|
|
88
|
+
const spanY = northY - mercatorY(bounds.south);
|
|
89
|
+
for (let y = 0; y < height; y += 1) {
|
|
90
|
+
const latitude = inverseMercatorY(northY - (y + 0.5) / height * spanY);
|
|
91
|
+
for (let x = 0; x < width; x += 1) {
|
|
92
|
+
const longitude = bounds.west + (x + 0.5) / width * (bounds.east - bounds.west);
|
|
93
|
+
bytes.set(
|
|
94
|
+
colorFor(sampleFrame(frame, longitude, latitude), showLowValueBackground),
|
|
95
|
+
(y * width + x) * 4
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return bytes;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function paintRaster(
|
|
103
|
+
canvas: HTMLCanvasElement,
|
|
104
|
+
frame: FieldFrame,
|
|
105
|
+
bounds: Bounds,
|
|
106
|
+
showLowValueBackground = true
|
|
107
|
+
): void {
|
|
108
|
+
const context = canvas.getContext('2d');
|
|
109
|
+
if (!context) {
|
|
110
|
+
throw new Error('Canvas 2D is unavailable.');
|
|
111
|
+
}
|
|
112
|
+
const image = context.createImageData(canvas.width, canvas.height);
|
|
113
|
+
image.data.set(rasterPixels(
|
|
114
|
+
frame,
|
|
115
|
+
bounds,
|
|
116
|
+
canvas.width,
|
|
117
|
+
canvas.height,
|
|
118
|
+
showLowValueBackground
|
|
119
|
+
));
|
|
120
|
+
context.putImageData(image, 0, 0);
|
|
121
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@import './component.css';
|
|
2
|
+
|
|
3
|
+
:root {
|
|
4
|
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans KR", sans-serif;
|
|
5
|
+
color: #e4eef1;
|
|
6
|
+
background: #07131c;
|
|
7
|
+
color-scheme: dark;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
body { margin: 0; }
|
|
11
|
+
#app { min-height: 100vh; padding: 28px; }
|
|
12
|
+
|
|
13
|
+
@media (max-width: 860px) {
|
|
14
|
+
#app { padding: 14px; }
|
|
15
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {type FieldFrame, type Probe, type SubcellField, validateFrame} from './model.js';
|
|
2
|
+
|
|
3
|
+
export const SELECTED_CELL_ID = 'cell:126.5:37.5';
|
|
4
|
+
|
|
5
|
+
export const PROBES: Probe[] = [
|
|
6
|
+
{id: 'SIM-A', name: 'Synthetic probe A', longitude: 126.66, latitude: 37.69},
|
|
7
|
+
{id: 'SIM-B', name: 'Synthetic probe B', longitude: 126.85, latitude: 37.83},
|
|
8
|
+
{id: 'SIM-C', name: 'Synthetic probe C', longitude: 126.9, latitude: 37.6}
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
/** Neighboring cells sample the same continuous synthetic field. */
|
|
12
|
+
function syntheticField(longitude: number, latitude: number, frame: number): number {
|
|
13
|
+
const peakA = [82, 42, 70][frame];
|
|
14
|
+
const peakB = [46, 87, 58][frame];
|
|
15
|
+
const a = Math.exp(-0.5 * (
|
|
16
|
+
((longitude - 126.66) / 0.064) ** 2 + ((latitude - 37.69) / 0.057) ** 2
|
|
17
|
+
));
|
|
18
|
+
const b = Math.exp(-0.5 * (
|
|
19
|
+
((longitude - 126.85) / 0.046) ** 2 + ((latitude - 37.83) / 0.073) ** 2
|
|
20
|
+
));
|
|
21
|
+
const c = Math.exp(-0.5 * (
|
|
22
|
+
((longitude - 127.13) / 0.13) ** 2 + ((latitude - 37.3) / 0.095) ** 2
|
|
23
|
+
));
|
|
24
|
+
const ridge = 15
|
|
25
|
+
* Math.exp(-0.5 * ((latitude - 37.52 - (longitude - 126.5) * 0.45) / 0.04) ** 2)
|
|
26
|
+
* Math.exp(-0.5 * ((longitude - 126.72) / 0.23) ** 2);
|
|
27
|
+
return Math.min(100, Math.max(0, 5 + peakA * a + peakB * b + 60 * c + ridge));
|
|
28
|
+
}
|
|
29
|
+
export function makeFrame(frame = 0): FieldFrame {
|
|
30
|
+
if (!Number.isInteger(frame) || frame < 0 || frame > 2) {
|
|
31
|
+
throw new RangeError('Frame must be 0, 1, or 2.');
|
|
32
|
+
}
|
|
33
|
+
const cells: SubcellField[] = [];
|
|
34
|
+
for (let row = 0; row < 3; row += 1) {
|
|
35
|
+
for (let column = 0; column < 3; column += 1) {
|
|
36
|
+
const west = 126 + column * 0.5;
|
|
37
|
+
const south = 37 + row * 0.5;
|
|
38
|
+
const bounds = {west, south, east: west + 0.5, north: south + 0.5};
|
|
39
|
+
const columns = 51;
|
|
40
|
+
const rows = 51;
|
|
41
|
+
const values: (number | null)[] = [];
|
|
42
|
+
for (let y = 0; y < rows; y += 1) {
|
|
43
|
+
for (let x = 0; x < columns; x += 1) {
|
|
44
|
+
const longitude = west + x / (columns - 1) * 0.5;
|
|
45
|
+
const latitude = south + 0.5 - y / (rows - 1) * 0.5;
|
|
46
|
+
const missing = longitude > 126.08
|
|
47
|
+
&& longitude < 126.22
|
|
48
|
+
&& latitude > 38.24
|
|
49
|
+
&& latitude < 38.37;
|
|
50
|
+
values.push(
|
|
51
|
+
missing ? null : Math.round(syntheticField(longitude, latitude, frame) * 100) / 100
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
cells.push({
|
|
56
|
+
id: `cell:${west}:${south}`,
|
|
57
|
+
bounds,
|
|
58
|
+
columns,
|
|
59
|
+
rows,
|
|
60
|
+
values
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const result: FieldFrame = {
|
|
65
|
+
time: `2026-01-01T00:${String(frame * 10).padStart(2, '0')}:00Z`,
|
|
66
|
+
metric: {name: 'Synthetic hazard intensity', unit: 'index-0-100', range: [0, 100]},
|
|
67
|
+
provenance: 'synthetic',
|
|
68
|
+
cells
|
|
69
|
+
};
|
|
70
|
+
validateFrame(result);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"name": "kchart-stackblitz-topology-basic",
|
|
9
9
|
"version": "0.0.0",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@keneth80/k-chart": "^1.
|
|
11
|
+
"@keneth80/k-chart": "^1.26.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"typescript": "^6.0.3",
|
|
@@ -458,14 +458,18 @@
|
|
|
458
458
|
}
|
|
459
459
|
},
|
|
460
460
|
"node_modules/@keneth80/k-chart": {
|
|
461
|
-
"version": "1.
|
|
462
|
-
"resolved": "https://registry.npmjs.org/@keneth80/k-chart/-/k-chart-1.
|
|
463
|
-
"integrity": "sha512-
|
|
461
|
+
"version": "1.26.1",
|
|
462
|
+
"resolved": "https://registry.npmjs.org/@keneth80/k-chart/-/k-chart-1.26.1.tgz",
|
|
463
|
+
"integrity": "sha512-UbAabIe1bsN0oXCecT7HWbJaHc2Mgu7F+aO6iT0v+ukEwKB91xCX5sLcOEsCiLcmXGcWe6UDwym6zhpojowuMg==",
|
|
464
464
|
"license": "MIT",
|
|
465
465
|
"dependencies": {
|
|
466
466
|
"d3-array": "^3.2.4",
|
|
467
467
|
"d3-axis": "^3.0.0",
|
|
468
|
+
"d3-brush": "^3.0.0",
|
|
469
|
+
"d3-force": "^3.0.0",
|
|
468
470
|
"d3-geo": "^3.1.1",
|
|
471
|
+
"d3-hierarchy": "^3.1.2",
|
|
472
|
+
"d3-sankey": "^0.12.3",
|
|
469
473
|
"d3-scale": "^4.0.2",
|
|
470
474
|
"d3-scale-chromatic": "^3.1.0",
|
|
471
475
|
"d3-selection": "^3.0.0",
|
|
@@ -898,6 +902,22 @@
|
|
|
898
902
|
"node": ">=12"
|
|
899
903
|
}
|
|
900
904
|
},
|
|
905
|
+
"node_modules/d3-brush": {
|
|
906
|
+
"version": "3.0.0",
|
|
907
|
+
"resolved": "https://registry.npmjs.org/d3-brush/-/d3-brush-3.0.0.tgz",
|
|
908
|
+
"integrity": "sha512-ALnjWlVYkXsVIGlOsuWH1+3udkYFI48Ljihfnh8FZPF2QS9o+PzGLBslO0PjzVoHLZ2KCVgAM8NVkXPJB2aNnQ==",
|
|
909
|
+
"license": "ISC",
|
|
910
|
+
"dependencies": {
|
|
911
|
+
"d3-dispatch": "1 - 3",
|
|
912
|
+
"d3-drag": "2 - 3",
|
|
913
|
+
"d3-interpolate": "1 - 3",
|
|
914
|
+
"d3-selection": "3",
|
|
915
|
+
"d3-transition": "3"
|
|
916
|
+
},
|
|
917
|
+
"engines": {
|
|
918
|
+
"node": ">=12"
|
|
919
|
+
}
|
|
920
|
+
},
|
|
901
921
|
"node_modules/d3-color": {
|
|
902
922
|
"version": "3.1.0",
|
|
903
923
|
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz",
|
|
@@ -938,6 +958,20 @@
|
|
|
938
958
|
"node": ">=12"
|
|
939
959
|
}
|
|
940
960
|
},
|
|
961
|
+
"node_modules/d3-force": {
|
|
962
|
+
"version": "3.0.0",
|
|
963
|
+
"resolved": "https://registry.npmjs.org/d3-force/-/d3-force-3.0.0.tgz",
|
|
964
|
+
"integrity": "sha512-zxV/SsA+U4yte8051P4ECydjD/S+qeYtnaIyAs9tgHCqfguma/aAQDjo85A9Z6EKhBirHRJHXIgJUlffT4wdLg==",
|
|
965
|
+
"license": "ISC",
|
|
966
|
+
"dependencies": {
|
|
967
|
+
"d3-dispatch": "1 - 3",
|
|
968
|
+
"d3-quadtree": "1 - 3",
|
|
969
|
+
"d3-timer": "1 - 3"
|
|
970
|
+
},
|
|
971
|
+
"engines": {
|
|
972
|
+
"node": ">=12"
|
|
973
|
+
}
|
|
974
|
+
},
|
|
941
975
|
"node_modules/d3-format": {
|
|
942
976
|
"version": "3.1.2",
|
|
943
977
|
"resolved": "https://registry.npmjs.org/d3-format/-/d3-format-3.1.2.tgz",
|
|
@@ -959,6 +993,15 @@
|
|
|
959
993
|
"node": ">=12"
|
|
960
994
|
}
|
|
961
995
|
},
|
|
996
|
+
"node_modules/d3-hierarchy": {
|
|
997
|
+
"version": "3.1.2",
|
|
998
|
+
"resolved": "https://registry.npmjs.org/d3-hierarchy/-/d3-hierarchy-3.1.2.tgz",
|
|
999
|
+
"integrity": "sha512-FX/9frcub54beBdugHjDCdikxThEqjnR93Qt7PvQTOHxyiNCAlvMrHhclk3cD5VeAaq9fxmfRp+CnWw9rEMBuA==",
|
|
1000
|
+
"license": "ISC",
|
|
1001
|
+
"engines": {
|
|
1002
|
+
"node": ">=12"
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
962
1005
|
"node_modules/d3-interpolate": {
|
|
963
1006
|
"version": "3.0.1",
|
|
964
1007
|
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
|
|
@@ -980,6 +1023,55 @@
|
|
|
980
1023
|
"node": ">=12"
|
|
981
1024
|
}
|
|
982
1025
|
},
|
|
1026
|
+
"node_modules/d3-quadtree": {
|
|
1027
|
+
"version": "3.0.1",
|
|
1028
|
+
"resolved": "https://registry.npmjs.org/d3-quadtree/-/d3-quadtree-3.0.1.tgz",
|
|
1029
|
+
"integrity": "sha512-04xDrxQTDTCFwP5H6hRhsRcb9xxv2RzkcsygFzmkSIOJy3PeRJP7sNk3VRIbKXcog561P9oU0/rVH6vDROAgUw==",
|
|
1030
|
+
"license": "ISC",
|
|
1031
|
+
"engines": {
|
|
1032
|
+
"node": ">=12"
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
"node_modules/d3-sankey": {
|
|
1036
|
+
"version": "0.12.3",
|
|
1037
|
+
"resolved": "https://registry.npmjs.org/d3-sankey/-/d3-sankey-0.12.3.tgz",
|
|
1038
|
+
"integrity": "sha512-nQhsBRmM19Ax5xEIPLMY9ZmJ/cDvd1BG3UVvt5h3WRxKg5zGRbvnteTyWAbzeSvlh3tW7ZEmq4VwR5mB3tutmQ==",
|
|
1039
|
+
"license": "BSD-3-Clause",
|
|
1040
|
+
"dependencies": {
|
|
1041
|
+
"d3-array": "1 - 2",
|
|
1042
|
+
"d3-shape": "^1.2.0"
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
"node_modules/d3-sankey/node_modules/d3-array": {
|
|
1046
|
+
"version": "2.12.1",
|
|
1047
|
+
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-2.12.1.tgz",
|
|
1048
|
+
"integrity": "sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ==",
|
|
1049
|
+
"license": "BSD-3-Clause",
|
|
1050
|
+
"dependencies": {
|
|
1051
|
+
"internmap": "^1.0.0"
|
|
1052
|
+
}
|
|
1053
|
+
},
|
|
1054
|
+
"node_modules/d3-sankey/node_modules/d3-path": {
|
|
1055
|
+
"version": "1.0.9",
|
|
1056
|
+
"resolved": "https://registry.npmjs.org/d3-path/-/d3-path-1.0.9.tgz",
|
|
1057
|
+
"integrity": "sha512-VLaYcn81dtHVTjEHd8B+pbe9yHWpXKZUC87PzoFmsFrJqgFwDe/qxfp5MlfsfM1V5E/iVt0MmEbWQ7FVIXh/bg==",
|
|
1058
|
+
"license": "BSD-3-Clause"
|
|
1059
|
+
},
|
|
1060
|
+
"node_modules/d3-sankey/node_modules/d3-shape": {
|
|
1061
|
+
"version": "1.3.7",
|
|
1062
|
+
"resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-1.3.7.tgz",
|
|
1063
|
+
"integrity": "sha512-EUkvKjqPFUAZyOlhY5gzCxCeI0Aep04LwIRpsZ/mLFelJiUfnK56jo5JMDSE7yyP2kLSb6LtF+S5chMk7uqPqw==",
|
|
1064
|
+
"license": "BSD-3-Clause",
|
|
1065
|
+
"dependencies": {
|
|
1066
|
+
"d3-path": "1"
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
"node_modules/d3-sankey/node_modules/internmap": {
|
|
1070
|
+
"version": "1.0.1",
|
|
1071
|
+
"resolved": "https://registry.npmjs.org/internmap/-/internmap-1.0.1.tgz",
|
|
1072
|
+
"integrity": "sha512-lDB5YccMydFBtasVtxnZ3MRBHuaoE8GKsppq+EchKL2U4nK/DmEpPHNH8MZe5HkMtpSiTSOZwfN0tzYjO/lJEw==",
|
|
1073
|
+
"license": "ISC"
|
|
1074
|
+
},
|
|
983
1075
|
"node_modules/d3-scale": {
|
|
984
1076
|
"version": "4.0.2",
|
|
985
1077
|
"resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-4.0.2.tgz",
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
"version": "0.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": { "dev": "vite --host 0.0.0.0", "build": "tsc && vite build", "preview": "vite preview --host 0.0.0.0" },
|
|
7
|
-
"dependencies": { "@keneth80/k-chart": "^1.
|
|
7
|
+
"dependencies": { "@keneth80/k-chart": "^1.26.1" },
|
|
8
8
|
"devDependencies": { "typescript": "^6.0.3", "vite": "^7.2.7" }
|
|
9
9
|
}
|