@keneth80/k-chart 1.9.0 → 1.11.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 +39 -0
- package/README.md +208 -1
- package/docs/assets/kchart-hero.svg +110 -0
- package/docs/assets/kchart-icon.svg +40 -0
- package/docs/configuration-reference.md +395 -0
- package/docs/functional-api.md +164 -3
- package/examples/stackblitz-candlestick-basic/index.html +23 -0
- package/examples/stackblitz-candlestick-basic/package-lock.json +1435 -0
- package/examples/stackblitz-candlestick-basic/package.json +18 -0
- package/examples/stackblitz-candlestick-basic/src/main.ts +107 -0
- package/examples/stackblitz-candlestick-basic/src/style.css +16 -0
- package/examples/stackblitz-canvas-line-basic/index.html +23 -0
- package/examples/stackblitz-canvas-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-canvas-line-basic/package.json +18 -0
- package/examples/stackblitz-canvas-line-basic/src/main.ts +73 -0
- package/examples/stackblitz-canvas-line-basic/src/style.css +46 -0
- package/examples/stackblitz-column-basic/index.html +23 -0
- package/examples/stackblitz-column-basic/package-lock.json +1435 -0
- package/examples/stackblitz-column-basic/package.json +18 -0
- package/examples/stackblitz-column-basic/src/main.ts +128 -0
- package/examples/stackblitz-column-basic/src/style.css +41 -0
- package/examples/stackblitz-doughnut-basic/index.html +21 -0
- package/examples/stackblitz-doughnut-basic/package-lock.json +1435 -0
- package/examples/stackblitz-doughnut-basic/package.json +18 -0
- package/examples/stackblitz-doughnut-basic/src/main.ts +177 -0
- package/examples/stackblitz-doughnut-basic/src/style.css +43 -0
- package/examples/stackblitz-korea-region-map-basic/index.html +20 -0
- package/examples/stackblitz-korea-region-map-basic/package-lock.json +1434 -0
- package/examples/stackblitz-korea-region-map-basic/package.json +17 -0
- package/examples/stackblitz-korea-region-map-basic/src/main.ts +90 -0
- package/examples/stackblitz-korea-region-map-basic/src/style.css +57 -0
- package/examples/stackblitz-line-basic/index.html +23 -0
- package/examples/stackblitz-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-line-basic/package.json +18 -0
- package/examples/stackblitz-line-basic/src/main.ts +112 -0
- package/examples/stackblitz-line-basic/src/style.css +108 -0
- package/examples/stackblitz-multi-series-basic/index.html +1 -0
- package/examples/stackblitz-multi-series-basic/package-lock.json +1435 -0
- package/examples/stackblitz-multi-series-basic/package.json +9 -0
- package/examples/stackblitz-multi-series-basic/src/main.ts +29 -0
- package/examples/stackblitz-multi-series-basic/src/style.css +1 -0
- package/examples/stackblitz-options-basic/index.html +1 -0
- package/examples/stackblitz-options-basic/package-lock.json +1435 -0
- package/examples/stackblitz-options-basic/package.json +9 -0
- package/examples/stackblitz-options-basic/src/main.ts +32 -0
- package/examples/stackblitz-options-basic/src/style.css +1 -0
- package/examples/stackblitz-pie-basic/index.html +21 -0
- package/examples/stackblitz-pie-basic/package-lock.json +1435 -0
- package/examples/stackblitz-pie-basic/package.json +18 -0
- package/examples/stackblitz-pie-basic/src/main.ts +156 -0
- package/examples/stackblitz-pie-basic/src/style.css +43 -0
- package/examples/stackblitz-plot-basic/index.html +1 -0
- package/examples/stackblitz-plot-basic/package-lock.json +1435 -0
- package/examples/stackblitz-plot-basic/package.json +9 -0
- package/examples/stackblitz-plot-basic/src/main.ts +32 -0
- package/examples/stackblitz-plot-basic/src/style.css +1 -0
- package/examples/stackblitz-radial-basic/index.html +21 -0
- package/examples/stackblitz-radial-basic/package-lock.json +1435 -0
- package/examples/stackblitz-radial-basic/package.json +18 -0
- package/examples/stackblitz-radial-basic/src/main.ts +223 -0
- package/examples/stackblitz-radial-basic/src/style.css +87 -0
- package/examples/stackblitz-simple-api-basic/index.html +30 -0
- package/examples/stackblitz-simple-api-basic/package-lock.json +1435 -0
- package/examples/stackblitz-simple-api-basic/package.json +18 -0
- package/examples/stackblitz-simple-api-basic/src/main.ts +69 -0
- package/examples/stackblitz-simple-api-basic/src/style.css +127 -0
- package/examples/stackblitz-stacked-column-basic/index.html +23 -0
- package/examples/stackblitz-stacked-column-basic/package-lock.json +1435 -0
- package/examples/stackblitz-stacked-column-basic/package.json +18 -0
- package/examples/stackblitz-stacked-column-basic/src/main.ts +136 -0
- package/examples/stackblitz-stacked-column-basic/src/style.css +16 -0
- package/examples/stackblitz-three-wafer-basic/index.html +1 -0
- package/examples/stackblitz-three-wafer-basic/package-lock.json +1453 -0
- package/examples/stackblitz-three-wafer-basic/package.json +9 -0
- package/examples/stackblitz-three-wafer-basic/src/main.ts +29 -0
- package/examples/stackblitz-three-wafer-basic/src/style.css +1 -0
- package/examples/stackblitz-topology-basic/index.html +1 -0
- package/examples/stackblitz-topology-basic/package-lock.json +1435 -0
- package/examples/stackblitz-topology-basic/package.json +9 -0
- package/examples/stackblitz-topology-basic/src/main.ts +89 -0
- package/examples/stackblitz-topology-basic/src/style.css +1 -0
- package/examples/stackblitz-webgl-line-basic/index.html +23 -0
- package/examples/stackblitz-webgl-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-webgl-line-basic/package.json +18 -0
- package/examples/stackblitz-webgl-line-basic/src/main.ts +86 -0
- package/examples/stackblitz-webgl-line-basic/src/style.css +46 -0
- package/examples/stackblitz-worker-json-line/index.html +41 -0
- package/examples/stackblitz-worker-json-line/package-lock.json +1435 -0
- package/examples/stackblitz-worker-json-line/package.json +19 -0
- package/examples/stackblitz-worker-json-line/public/data/large-line.json +4322 -0
- package/examples/stackblitz-worker-json-line/src/kchart-render.worker.ts +4 -0
- package/examples/stackblitz-worker-json-line/src/main.ts +185 -0
- package/examples/stackblitz-worker-json-line/src/style.css +101 -0
- package/examples/stackblitz-world-country-map-basic/index.html +20 -0
- package/examples/stackblitz-world-country-map-basic/package-lock.json +1434 -0
- package/examples/stackblitz-world-country-map-basic/package.json +17 -0
- package/examples/stackblitz-world-country-map-basic/src/main.ts +64 -0
- package/examples/stackblitz-world-country-map-basic/src/style.css +57 -0
- package/lib/core/contracts.d.ts +72 -0
- package/lib/core/contracts.d.ts.map +1 -1
- package/lib/core/create-kchart.d.ts.map +1 -1
- package/lib/core/create-kchart.js +93 -4
- package/lib/core/create-kchart.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/kchart.d.ts +1 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +1 -0
- package/lib/kchart.js.map +1 -1
- package/lib/presets/index.d.ts +97 -0
- package/lib/presets/index.d.ts.map +1 -0
- package/lib/presets/index.js +481 -0
- package/lib/presets/index.js.map +1 -0
- package/lib/series/canvas-line.d.ts.map +1 -1
- package/lib/series/canvas-line.js +16 -11
- package/lib/series/canvas-line.js.map +1 -1
- package/lib/series/index.d.ts +1 -0
- package/lib/series/index.d.ts.map +1 -1
- package/lib/series/index.js +1 -0
- package/lib/series/index.js.map +1 -1
- package/lib/series/svg-line.d.ts.map +1 -1
- package/lib/series/svg-line.js +19 -3
- package/lib/series/svg-line.js.map +1 -1
- package/lib/series/svg-region-map.d.ts +4 -0
- package/lib/series/svg-region-map.d.ts.map +1 -0
- package/lib/series/svg-region-map.js +324 -0
- package/lib/series/svg-region-map.js.map +1 -0
- package/lib/series/webgl-line.d.ts.map +1 -1
- package/lib/series/webgl-line.js +10 -3
- package/lib/series/webgl-line.js.map +1 -1
- package/package.json +13 -2
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createGuideLineOption,
|
|
3
|
+
createKChart,
|
|
4
|
+
createSpecAreaOption,
|
|
5
|
+
createWebglLineSeries
|
|
6
|
+
} from '@keneth80/k-chart';
|
|
7
|
+
import './style.css';
|
|
8
|
+
|
|
9
|
+
interface JsonTracePoint {
|
|
10
|
+
x: number;
|
|
11
|
+
signal: number;
|
|
12
|
+
baseline: number;
|
|
13
|
+
upper: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const dataStatus = document.querySelector<HTMLElement>('#data-status');
|
|
17
|
+
const offscreenStatus = document.querySelector<HTMLElement>('#offscreen-status');
|
|
18
|
+
const workerStatus = document.querySelector<HTMLElement>('#worker-status');
|
|
19
|
+
|
|
20
|
+
let workerCreateCount = 0;
|
|
21
|
+
|
|
22
|
+
const setText = (target: HTMLElement | null, text: string): void => {
|
|
23
|
+
if (target) {
|
|
24
|
+
target.textContent = text;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const supportsOffscreenCanvas = (): boolean => {
|
|
29
|
+
const canvas = document.createElement('canvas');
|
|
30
|
+
return typeof canvas.transferControlToOffscreen === 'function';
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const createKChartRenderWorker = (): Worker => {
|
|
34
|
+
workerCreateCount += 1;
|
|
35
|
+
setText(workerStatus, `called ${workerCreateCount} time${workerCreateCount === 1 ? '' : 's'}`);
|
|
36
|
+
console.info(`[KChart StackBlitz] render worker created #${workerCreateCount}`);
|
|
37
|
+
|
|
38
|
+
return new Worker(
|
|
39
|
+
new URL('./kchart-render.worker.ts', import.meta.url),
|
|
40
|
+
{ type: 'module' }
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const loadData = async (): Promise<JsonTracePoint[]> => {
|
|
45
|
+
const response = await fetch('/data/large-line.json');
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(`Failed to load JSON data: ${response.status}`);
|
|
48
|
+
}
|
|
49
|
+
return response.json() as Promise<JsonTracePoint[]>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const renderChart = (data: JsonTracePoint[]): void => {
|
|
53
|
+
const chart = createKChart<JsonTracePoint>({
|
|
54
|
+
selector: '#chart',
|
|
55
|
+
data,
|
|
56
|
+
width: 920,
|
|
57
|
+
height: 460,
|
|
58
|
+
margin: { top: 118, right: 36, bottom: 58, left: 64 },
|
|
59
|
+
colors: ['#5db8ff', '#56d08f', '#f3b45b'],
|
|
60
|
+
title: { text: 'WebGL line from fetched JSON', align: 'left', fontSize: 18 },
|
|
61
|
+
grid: {
|
|
62
|
+
visible: true,
|
|
63
|
+
x: false,
|
|
64
|
+
y: true,
|
|
65
|
+
color: 'rgba(148, 163, 184, 0.2)',
|
|
66
|
+
dasharray: '3 8'
|
|
67
|
+
},
|
|
68
|
+
legend: { visible: true, placement: 'top', selectable: true },
|
|
69
|
+
tooltip: { visible: false },
|
|
70
|
+
zoom: {
|
|
71
|
+
enabled: true,
|
|
72
|
+
mode: 'both',
|
|
73
|
+
direction: 'x',
|
|
74
|
+
scaleExtent: [1, 80],
|
|
75
|
+
wheelZoom: { enabled: true, devices: 'pc', sensitivity: 0.85 },
|
|
76
|
+
resetOnDoubleClick: true
|
|
77
|
+
},
|
|
78
|
+
options: [
|
|
79
|
+
createSpecAreaOption([
|
|
80
|
+
{ start: 120, end: 210, label: 'FETCHED JSON', color: 'rgba(216, 118, 255, 0.16)' },
|
|
81
|
+
{ start: 420, end: 520, label: 'WORKER DRAW', color: 'rgba(93, 184, 255, 0.13)' }
|
|
82
|
+
]),
|
|
83
|
+
createGuideLineOption({
|
|
84
|
+
x: [
|
|
85
|
+
{ value: 100, label: '100' },
|
|
86
|
+
{ value: 300, label: '300' },
|
|
87
|
+
{ value: 500, label: '500' }
|
|
88
|
+
],
|
|
89
|
+
y: [
|
|
90
|
+
{ value: 42, label: 'LOW', color: 'rgba(93, 184, 255, 0.55)' },
|
|
91
|
+
{ value: 68, label: 'HIGH', color: 'rgba(255, 107, 138, 0.55)' }
|
|
92
|
+
]
|
|
93
|
+
})
|
|
94
|
+
],
|
|
95
|
+
axes: [
|
|
96
|
+
{
|
|
97
|
+
field: 'x',
|
|
98
|
+
type: 'number',
|
|
99
|
+
placement: 'bottom',
|
|
100
|
+
min: 0,
|
|
101
|
+
max: data.length - 1,
|
|
102
|
+
title: 'Sample Index',
|
|
103
|
+
tickCount: 7
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
field: 'signal',
|
|
107
|
+
type: 'number',
|
|
108
|
+
placement: 'left',
|
|
109
|
+
min: 24,
|
|
110
|
+
max: 78,
|
|
111
|
+
title: 'Signal',
|
|
112
|
+
domainFields: ['signal', 'baseline', 'upper']
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
series: [
|
|
116
|
+
createWebglLineSeries({
|
|
117
|
+
selector: 'signal',
|
|
118
|
+
displayName: 'Signal',
|
|
119
|
+
xField: 'x',
|
|
120
|
+
yField: 'signal',
|
|
121
|
+
color: '#5db8ff',
|
|
122
|
+
lineWidth: 1,
|
|
123
|
+
asyncRender: {
|
|
124
|
+
enabled: true,
|
|
125
|
+
workerFactory: createKChartRenderWorker
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
createWebglLineSeries({
|
|
129
|
+
selector: 'baseline',
|
|
130
|
+
displayName: 'Baseline',
|
|
131
|
+
xField: 'x',
|
|
132
|
+
yField: 'baseline',
|
|
133
|
+
color: '#56d08f',
|
|
134
|
+
lineWidth: 1,
|
|
135
|
+
asyncRender: {
|
|
136
|
+
enabled: true,
|
|
137
|
+
workerFactory: createKChartRenderWorker
|
|
138
|
+
}
|
|
139
|
+
}),
|
|
140
|
+
createWebglLineSeries({
|
|
141
|
+
selector: 'upper',
|
|
142
|
+
displayName: 'Upper band',
|
|
143
|
+
xField: 'x',
|
|
144
|
+
yField: 'upper',
|
|
145
|
+
color: '#f3b45b',
|
|
146
|
+
lineWidth: 1,
|
|
147
|
+
asyncRender: {
|
|
148
|
+
enabled: true,
|
|
149
|
+
workerFactory: createKChartRenderWorker
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
chart.render();
|
|
156
|
+
|
|
157
|
+
window.addEventListener('resize', () => {
|
|
158
|
+
const panel = document.querySelector<HTMLElement>('.chart-panel');
|
|
159
|
+
if (!panel) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
chart.resize({
|
|
164
|
+
width: Math.max(panel.clientWidth - 48, 320),
|
|
165
|
+
height: 460
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const boot = async (): Promise<void> => {
|
|
171
|
+
const offscreenSupported = supportsOffscreenCanvas();
|
|
172
|
+
setText(offscreenStatus, offscreenSupported ? 'supported' : 'not supported; main-thread fallback');
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
const data = await loadData();
|
|
176
|
+
setText(dataStatus, `${data.length.toLocaleString()} rows from /data/large-line.json`);
|
|
177
|
+
renderChart(data);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error(error);
|
|
180
|
+
setText(dataStatus, 'failed to load JSON');
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
void boot();
|
|
185
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: dark;
|
|
3
|
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
4
|
+
background: #0b1120;
|
|
5
|
+
color: #e5edf7;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
* { box-sizing: border-box; }
|
|
9
|
+
|
|
10
|
+
body {
|
|
11
|
+
margin: 0;
|
|
12
|
+
min-width: 320px;
|
|
13
|
+
min-height: 100vh;
|
|
14
|
+
background:
|
|
15
|
+
radial-gradient(circle at 18% 8%, rgba(93, 184, 255, 0.22), transparent 32rem),
|
|
16
|
+
radial-gradient(circle at 82% 0%, rgba(86, 208, 143, 0.12), transparent 28rem),
|
|
17
|
+
#0b1120;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.page-shell {
|
|
21
|
+
width: min(1120px, calc(100vw - 32px));
|
|
22
|
+
margin: 0 auto;
|
|
23
|
+
padding: 40px 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.intro { margin-bottom: 18px; }
|
|
27
|
+
|
|
28
|
+
.eyebrow {
|
|
29
|
+
margin: 0 0 8px;
|
|
30
|
+
color: #7dd3fc;
|
|
31
|
+
font-size: 12px;
|
|
32
|
+
font-weight: 700;
|
|
33
|
+
letter-spacing: 0.08em;
|
|
34
|
+
text-transform: uppercase;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
h1 {
|
|
38
|
+
margin: 0;
|
|
39
|
+
font-size: clamp(28px, 5vw, 52px);
|
|
40
|
+
line-height: 1.05;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.intro p:last-child {
|
|
44
|
+
margin: 12px 0 0;
|
|
45
|
+
color: #b8c5d6;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
code { color: #fbbf24; }
|
|
49
|
+
|
|
50
|
+
.status-grid {
|
|
51
|
+
display: grid;
|
|
52
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
53
|
+
gap: 12px;
|
|
54
|
+
margin: 0 0 16px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.status-grid div {
|
|
58
|
+
min-height: 74px;
|
|
59
|
+
padding: 14px 16px;
|
|
60
|
+
border: 1px solid rgba(148, 163, 184, 0.24);
|
|
61
|
+
border-radius: 12px;
|
|
62
|
+
background: rgba(15, 23, 42, 0.72);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.status-grid span {
|
|
66
|
+
display: block;
|
|
67
|
+
margin-bottom: 7px;
|
|
68
|
+
color: #8ba2bd;
|
|
69
|
+
font-size: 12px;
|
|
70
|
+
font-weight: 700;
|
|
71
|
+
text-transform: uppercase;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.status-grid strong {
|
|
75
|
+
display: block;
|
|
76
|
+
color: #f8fafc;
|
|
77
|
+
font-size: 15px;
|
|
78
|
+
line-height: 1.3;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.chart-panel {
|
|
82
|
+
min-height: 520px;
|
|
83
|
+
padding: 24px;
|
|
84
|
+
border: 1px solid rgba(148, 163, 184, 0.24);
|
|
85
|
+
border-radius: 12px;
|
|
86
|
+
background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(17, 24, 39, 0.82));
|
|
87
|
+
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#chart { width: 100%; height: 460px; }
|
|
91
|
+
#chart .kchart-svg text { font-family: inherit; }
|
|
92
|
+
#chart .domain, #chart .tick line { stroke: rgba(203, 213, 225, 0.54); }
|
|
93
|
+
#chart .tick text, #chart .kchart-axis-title { fill: #cbd5e1; }
|
|
94
|
+
#chart .kchart-title { fill: #f8fafc; }
|
|
95
|
+
#chart .kchart-legend text { fill: #dbeafe; }
|
|
96
|
+
|
|
97
|
+
@media (max-width: 760px) {
|
|
98
|
+
.page-shell { width: min(100vw - 20px, 1120px); padding: 24px 0; }
|
|
99
|
+
.status-grid { grid-template-columns: 1fr; }
|
|
100
|
+
.chart-panel { padding: 12px; }
|
|
101
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>KChart World Country Map</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main>
|
|
10
|
+
<section>
|
|
11
|
+
<div>
|
|
12
|
+
<p>KChart SVG region map</p>
|
|
13
|
+
<h1>World country map</h1>
|
|
14
|
+
</div>
|
|
15
|
+
<div id="chart"></div>
|
|
16
|
+
</section>
|
|
17
|
+
</main>
|
|
18
|
+
<script type="module" src="/src/main.ts"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|