@keneth80/k-chart 1.16.0 → 1.16.1

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.16.1 - 2026-07-10
4
+
5
+ ### Added
6
+
7
+ - Added a realtime time-series line demo with a 250ms sliding time window.
8
+ - Added a `stackblitz-realtime-line-basic` starter showing fixed-size stream data and interval cleanup.
9
+
10
+ ### Changed
11
+
12
+ - Updated the playground/demo realtime usage snippet to avoid unbounded data growth and duplicate axis/data renders.
13
+
14
+ ### Packages
15
+
16
+ - Published `@keneth80/k-chart@1.16.1`.
17
+
3
18
  ## 1.16.0 - 2026-07-10
4
19
 
5
20
  ### Added
package/README.md CHANGED
@@ -54,6 +54,8 @@
54
54
  ·
55
55
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-webgl-line-basic?title=KChart%20WebGL%20Line&file=src/main.ts"><strong>WebGL Line</strong></a>
56
56
  ·
57
+ <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-realtime-line-basic?title=KChart%20Realtime%20Line&file=src/main.ts"><strong>Realtime Line</strong></a>
58
+ ·
57
59
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-worker-json-line?title=KChart%20Worker%20JSON%20Line&file=src/main.ts"><strong>Worker JSON</strong></a>
58
60
  ·
59
61
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-korea-region-map-basic?title=KChart%20Korea%20Region%20Map&file=src/main.ts"><strong>Korea Map</strong></a>
@@ -0,0 +1,26 @@
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 Realtime Line</title>
7
+ </head>
8
+ <body>
9
+ <main class="page-shell">
10
+ <section class="intro">
11
+ <p class="eyebrow">StackBlitz starter</p>
12
+ <h1>KChart Realtime Time-Series</h1>
13
+ <p>Streams a fixed-size time window so the chart keeps moving without unbounded memory growth.</p>
14
+ </section>
15
+ <section class="chart-panel">
16
+ <div class="metric-strip">
17
+ <span>250ms interval</span>
18
+ <span>240 point window</span>
19
+ <span>single chart instance</span>
20
+ </div>
21
+ <div id="chart"></div>
22
+ </section>
23
+ </main>
24
+ <script type="module" src="/src/main.ts"></script>
25
+ </body>
26
+ </html>
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "kchart-stackblitz-realtime-line-basic",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite --host 0.0.0.0",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview --host 0.0.0.0"
10
+ },
11
+ "dependencies": {
12
+ "@keneth80/k-chart": "^1.16.1"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^6.0.3",
16
+ "vite": "^7.2.7"
17
+ }
18
+ }
@@ -0,0 +1,105 @@
1
+ import { createCanvasLineSeries, createKChart } from '@keneth80/k-chart';
2
+ import './style.css';
3
+
4
+ interface RealtimePoint {
5
+ label: string;
6
+ time: Date;
7
+ signalA: number;
8
+ signalB: number;
9
+ signalC: number;
10
+ }
11
+
12
+ const INTERVAL_MS = 250;
13
+ const MAX_POINTS = 240;
14
+ const INITIAL_POINTS = 120;
15
+
16
+ const formatTick = (value: Date): string =>
17
+ value.toLocaleTimeString([], { minute: '2-digit', second: '2-digit' });
18
+
19
+ const createPoint = (tick: number, startTime: number): RealtimePoint => {
20
+ const time = new Date(startTime + tick * INTERVAL_MS);
21
+ return {
22
+ label: formatTick(time),
23
+ time,
24
+ signalA: 52 + Math.sin(tick / 8) * 13 + Math.sin(tick / 2.9) * 2.8,
25
+ signalB: 45 + Math.cos(tick / 10) * 8 + Math.sin(tick / 3.4) * 2.6,
26
+ signalC: 58 + Math.sin(tick / 14) * 7 - Math.cos(tick / 6.2) * 3.2
27
+ };
28
+ };
29
+
30
+ const startTime = Date.now() - (INITIAL_POINTS - 1) * INTERVAL_MS;
31
+ let tick = INITIAL_POINTS;
32
+ let data: RealtimePoint[] = Array.from({ length: INITIAL_POINTS }, (_, index) =>
33
+ createPoint(index, startTime)
34
+ );
35
+
36
+ const chart = createKChart<RealtimePoint>({
37
+ selector: '#chart',
38
+ data,
39
+ width: 920,
40
+ height: 460,
41
+ margin: { top: 92, right: 36, bottom: 58, left: 64 },
42
+ colors: ['#5db8ff', '#56d08f', '#f3b45b'],
43
+ title: { text: 'Realtime time-series line', align: 'left', fontSize: 18 },
44
+ grid: {
45
+ visible: true,
46
+ x: false,
47
+ y: true,
48
+ color: 'rgba(148, 163, 184, 0.22)',
49
+ dasharray: '3 8'
50
+ },
51
+ legend: { visible: true, placement: 'top', selectable: true },
52
+ tooltip: {
53
+ visible: true,
54
+ formatter: ({ data: point, series, y }) => `
55
+ <strong>${series.displayName}</strong>
56
+ <div>${point.label}</div>
57
+ <div>${Number(y).toFixed(2)}</div>
58
+ `
59
+ },
60
+ axes: [
61
+ { field: 'time', type: 'time', placement: 'bottom', title: 'Clock', tickCount: 6, tickFormat: formatTick },
62
+ {
63
+ field: 'signalA',
64
+ type: 'number',
65
+ placement: 'left',
66
+ min: 28,
67
+ max: 76,
68
+ title: 'Signal',
69
+ domainFields: ['signalA', 'signalB', 'signalC']
70
+ }
71
+ ],
72
+ series: [
73
+ createCanvasLineSeries({ selector: 'signal-a', displayName: 'Signal A', xField: 'time', yField: 'signalA', color: '#5db8ff', lineWidth: 2.5 }),
74
+ createCanvasLineSeries({ selector: 'signal-b', displayName: 'Signal B', xField: 'time', yField: 'signalB', color: '#56d08f', lineWidth: 2.5 }),
75
+ createCanvasLineSeries({ selector: 'signal-c', displayName: 'Signal C', xField: 'time', yField: 'signalC', color: '#f3b45b', lineWidth: 2.5 })
76
+ ]
77
+ });
78
+
79
+ chart.render();
80
+
81
+ const appendPoint = (): void => {
82
+ data.push(createPoint(tick, startTime));
83
+ if (data.length > MAX_POINTS) {
84
+ data.splice(0, data.length - MAX_POINTS);
85
+ }
86
+
87
+ chart.updateData(data);
88
+ tick += 1;
89
+ };
90
+
91
+ const timer = window.setInterval(appendPoint, INTERVAL_MS);
92
+
93
+ window.addEventListener('resize', () => {
94
+ const panel = document.querySelector<HTMLElement>('.chart-panel');
95
+ if (!panel) {
96
+ return;
97
+ }
98
+
99
+ chart.resize({ width: Math.max(panel.clientWidth - 48, 320), height: 460 });
100
+ });
101
+
102
+ window.addEventListener('beforeunload', () => {
103
+ window.clearInterval(timer);
104
+ chart.destroy();
105
+ });
@@ -0,0 +1,121 @@
1
+ :root {
2
+ color-scheme: dark;
3
+ font-family:
4
+ Inter,
5
+ ui-sans-serif,
6
+ system-ui,
7
+ -apple-system,
8
+ BlinkMacSystemFont,
9
+ "Segoe UI",
10
+ sans-serif;
11
+ background: #0b1120;
12
+ color: #e5edf7;
13
+ }
14
+
15
+ * {
16
+ box-sizing: border-box;
17
+ }
18
+
19
+ body {
20
+ margin: 0;
21
+ min-width: 320px;
22
+ min-height: 100vh;
23
+ background:
24
+ radial-gradient(circle at 18% 8%, rgba(93, 184, 255, 0.2), transparent 32rem),
25
+ radial-gradient(circle at 80% 4%, rgba(86, 208, 143, 0.16), transparent 28rem),
26
+ #0b1120;
27
+ }
28
+
29
+ .page-shell {
30
+ width: min(1120px, calc(100vw - 32px));
31
+ margin: 0 auto;
32
+ padding: 40px 0;
33
+ }
34
+
35
+ .intro {
36
+ margin-bottom: 18px;
37
+ }
38
+
39
+ .eyebrow {
40
+ margin: 0 0 8px;
41
+ color: #7dd3fc;
42
+ font-size: 12px;
43
+ font-weight: 700;
44
+ letter-spacing: 0.08em;
45
+ text-transform: uppercase;
46
+ }
47
+
48
+ h1 {
49
+ margin: 0;
50
+ font-size: clamp(28px, 5vw, 52px);
51
+ line-height: 1.05;
52
+ }
53
+
54
+ .intro p:last-child {
55
+ margin: 12px 0 0;
56
+ color: #b8c5d6;
57
+ }
58
+
59
+ .chart-panel {
60
+ min-height: 548px;
61
+ padding: 24px;
62
+ border: 1px solid rgba(148, 163, 184, 0.24);
63
+ border-radius: 12px;
64
+ background: linear-gradient(145deg, rgba(15, 23, 42, 0.94), rgba(17, 24, 39, 0.84));
65
+ box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
66
+ }
67
+
68
+ .metric-strip {
69
+ display: flex;
70
+ flex-wrap: wrap;
71
+ gap: 8px;
72
+ margin: 0 0 12px;
73
+ }
74
+
75
+ .metric-strip span {
76
+ padding: 6px 10px;
77
+ border: 1px solid rgba(125, 211, 252, 0.22);
78
+ border-radius: 999px;
79
+ color: #cde9ff;
80
+ background: rgba(14, 165, 233, 0.1);
81
+ font-size: 12px;
82
+ font-weight: 700;
83
+ }
84
+
85
+ #chart {
86
+ width: 100%;
87
+ height: 460px;
88
+ }
89
+
90
+ #chart .kchart-svg text {
91
+ font-family: inherit;
92
+ }
93
+
94
+ #chart .domain,
95
+ #chart .tick line {
96
+ stroke: rgba(203, 213, 225, 0.54);
97
+ }
98
+
99
+ #chart .tick text,
100
+ #chart .kchart-axis-title {
101
+ fill: #cbd5e1;
102
+ }
103
+
104
+ #chart .kchart-title {
105
+ fill: #f8fafc;
106
+ }
107
+
108
+ #chart .kchart-legend text {
109
+ fill: #dbeafe;
110
+ }
111
+
112
+ @media (max-width: 720px) {
113
+ .page-shell {
114
+ width: min(100vw - 20px, 1120px);
115
+ padding: 24px 0;
116
+ }
117
+
118
+ .chart-panel {
119
+ padding: 12px;
120
+ }
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keneth80/k-chart",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Lightweight TypeScript D3 chart runtime with functional SVG, Canvas, and WebGL series renderers.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",