@keneth80/k-chart 1.2.0 → 1.4.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 +25 -0
- package/README.md +113 -46
- package/docs/code-graph-handoff.md +242 -0
- package/docs/functional-api.md +487 -0
- package/docs/react-nextjs.md +262 -0
- package/docs/refactor-plan.md +61 -0
- package/docs/release.md +155 -0
- package/examples/canvas-candlestick-series.ts +106 -0
- package/examples/custom-circle-series.ts +55 -0
- package/examples/functional-ui-usage.ts +44 -0
- package/examples/react-wrapper.tsx +84 -0
- package/lib/kchart.d.ts +69 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +568 -13
- package/lib/kchart.js.map +1 -1
- package/package.json +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.4.0 - 2026-06-13
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added `createCanvasCandlestickSeries` for Canvas OHLC candlestick charts.
|
|
8
|
+
- Added axis `domainFields` support so one axis can derive its domain from multiple fields such as `low` and `high`.
|
|
9
|
+
- Added `zoom.wheelZoom` and `zoom.gestureZoom` options to separate PC wheel/trackpad zoom from mobile touch gesture zoom.
|
|
10
|
+
- Added candlestick `colorMode: 'previous-close'` and `previousCloseField` support for previous-close based stock coloring.
|
|
11
|
+
|
|
12
|
+
## 1.3.0
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- Added chart-level `zoom` configuration for number and time axes.
|
|
17
|
+
- Added `zoom.mode` support for `wheel`, `select`, and `both`.
|
|
18
|
+
- Added wheel/trackpad zoom, drag pan, double-click reset, and drag-selection zoom interactions.
|
|
19
|
+
- Added zoom callback context with visible x/y domains and active transform state.
|
|
20
|
+
- Enabled zoom examples for Canvas BigData and WebGL BigData demos.
|
|
21
|
+
- Added `d3-zoom` as a runtime dependency and direct `@types/d3-zoom` typing support.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Updated the functional API guide and README with zoom usage examples.
|
|
26
|
+
- Preserved initial axes separately from active zoom axes so reset returns to the original domain.
|
|
27
|
+
|
|
3
28
|
## 1.2.0
|
|
4
29
|
|
|
5
30
|
### Added
|
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ createKChart(config)
|
|
|
14
14
|
├─ createLineSeries(...)
|
|
15
15
|
├─ createCanvasLineSeries(...)
|
|
16
16
|
├─ createCanvasPointSeries(...)
|
|
17
|
+
├─ createCanvasCandlestickSeries(...)
|
|
17
18
|
├─ createWebglLineSeries(...)
|
|
18
19
|
├─ createWebglPointSeries(...)
|
|
19
20
|
└─ createCustomSeries({ render(context) })
|
|
@@ -22,6 +23,7 @@ createKChart(config)
|
|
|
22
23
|
- `createKChart(...)`는 class 없이 plain runtime state와 controller를 만듭니다.
|
|
23
24
|
- `createLineSeries(...)`는 SVG line renderer를 함수형 series로 생성합니다.
|
|
24
25
|
- `createCanvasLineSeries(...)`, `createCanvasPointSeries(...)`는 Canvas 2D renderer를 함수형 series로 생성합니다.
|
|
26
|
+
- `createCanvasCandlestickSeries(...)`는 OHLC 데이터를 Canvas 2D 캔들차트로 렌더링합니다.
|
|
25
27
|
- `createWebglLineSeries(...)`는 대용량 line renderer를 WebGL `LINE_STRIP` 기반 함수형 series로 생성합니다.
|
|
26
28
|
- `createWebglPointSeries(...)`는 WebGL point renderer를 함수형 series로 생성합니다.
|
|
27
29
|
- `createCustomSeries(...)`는 renderer 함수를 그대로 series로 사용합니다.
|
|
@@ -34,6 +36,12 @@ createKChart(config)
|
|
|
34
36
|
npm install @keneth80/k-chart
|
|
35
37
|
```
|
|
36
38
|
|
|
39
|
+
## Playground
|
|
40
|
+
|
|
41
|
+
- Local playground URL: `http://127.0.0.1:9011`
|
|
42
|
+
|
|
43
|
+
The playground demonstrates the React wrapper, chart examples, configuration editor, and AI Builder flow.
|
|
44
|
+
|
|
37
45
|
## Local Development
|
|
38
46
|
|
|
39
47
|
```bash
|
|
@@ -49,6 +57,15 @@ npm run dev
|
|
|
49
57
|
|
|
50
58
|
Then open `http://127.0.0.1:9003/`.
|
|
51
59
|
|
|
60
|
+
## Guides
|
|
61
|
+
|
|
62
|
+
- [Functional API Guide](docs/functional-api.md)
|
|
63
|
+
- [Code Graph Handoff](docs/code-graph-handoff.md)
|
|
64
|
+
- [React And Next.js Guide](docs/react-nextjs.md)
|
|
65
|
+
- [Release Guide](docs/release.md)
|
|
66
|
+
- [React Wrapper Example](examples/react-wrapper.tsx)
|
|
67
|
+
- [Canvas Candlestick Example](examples/canvas-candlestick-series.ts)
|
|
68
|
+
|
|
52
69
|
## Quick Start
|
|
53
70
|
|
|
54
71
|
```ts
|
|
@@ -198,6 +215,65 @@ const webglLine = createWebglLineSeries<Point>({
|
|
|
198
215
|
});
|
|
199
216
|
```
|
|
200
217
|
|
|
218
|
+
## Candlestick Chart
|
|
219
|
+
|
|
220
|
+
Canvas candlestick series renders OHLC stock data. Set the y-axis `field` to the value you want tooltips and cursor guides to use, usually `close`, and set `domainFields` to `['low', 'high']` so the axis covers the full candle range.
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
import {
|
|
224
|
+
createCanvasCandlestickSeries,
|
|
225
|
+
createKChart
|
|
226
|
+
} from '@keneth80/k-chart';
|
|
227
|
+
|
|
228
|
+
interface StockPoint {
|
|
229
|
+
date: string;
|
|
230
|
+
open: number;
|
|
231
|
+
high: number;
|
|
232
|
+
low: number;
|
|
233
|
+
close: number;
|
|
234
|
+
previousClose: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const data: StockPoint[] = [
|
|
238
|
+
{ date: '2026-06-01', open: 101, high: 108, low: 98, close: 106, previousClose: 100 },
|
|
239
|
+
{ date: '2026-06-02', open: 106, high: 110, low: 102, close: 103, previousClose: 106 },
|
|
240
|
+
{ date: '2026-06-03', open: 103, high: 112, low: 101, close: 111, previousClose: 103 }
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
createKChart<StockPoint>({
|
|
244
|
+
selector: '#chart',
|
|
245
|
+
data,
|
|
246
|
+
axes: [
|
|
247
|
+
{ field: 'date', type: 'time', placement: 'bottom', tickCount: 5, domain: ['2026-05-31', '2026-06-04'] },
|
|
248
|
+
{
|
|
249
|
+
field: 'close',
|
|
250
|
+
type: 'number',
|
|
251
|
+
placement: 'left',
|
|
252
|
+
title: 'Price',
|
|
253
|
+
domainFields: ['low', 'high']
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
tooltip: { visible: true },
|
|
257
|
+
series: [
|
|
258
|
+
createCanvasCandlestickSeries({
|
|
259
|
+
selector: 'price',
|
|
260
|
+
displayName: 'Price',
|
|
261
|
+
xField: 'date',
|
|
262
|
+
openField: 'open',
|
|
263
|
+
highField: 'high',
|
|
264
|
+
lowField: 'low',
|
|
265
|
+
closeField: 'close',
|
|
266
|
+
colorMode: 'previous-close',
|
|
267
|
+
previousCloseField: 'previousClose',
|
|
268
|
+
upColor: '#22c55e',
|
|
269
|
+
downColor: '#ef4444'
|
|
270
|
+
})
|
|
271
|
+
]
|
|
272
|
+
}).render();
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
`colorMode` 기본값은 `'open-close'`이며 `close`와 `open`을 비교합니다. 한국 주식 화면처럼 전일 종가 대비 상승/하락 색상을 쓰려면 `colorMode: 'previous-close'`를 지정합니다. `previousCloseField`를 넘기면 해당 필드를 기준으로 비교하고, 생략하면 현재 데이터 배열에서 바로 앞 캔들의 `closeField` 값을 사용합니다.
|
|
276
|
+
|
|
201
277
|
대용량 line 예제에서는 축 tick 수를 줄여 라벨 겹침을 피할 수 있습니다.
|
|
202
278
|
|
|
203
279
|
```ts
|
|
@@ -225,6 +301,41 @@ createKChart({
|
|
|
225
301
|
}).render();
|
|
226
302
|
```
|
|
227
303
|
|
|
304
|
+
## Zoom
|
|
305
|
+
|
|
306
|
+
`zoom` 옵션을 켜면 number/time 축의 domain을 런타임에 갱신하면서 SVG, Canvas, WebGL series를 다시 렌더링합니다. 기본적으로 wheel/trackpad 확대, 드래그 pan, 더블클릭 reset을 지원합니다.
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
createKChart({
|
|
310
|
+
selector: '#chart',
|
|
311
|
+
data: largeData,
|
|
312
|
+
axes: [
|
|
313
|
+
{ field: 'x', type: 'number', placement: 'bottom', min: 0, max: 119999 },
|
|
314
|
+
{ field: 'y', type: 'number', placement: 'left', min: 0, max: 100 }
|
|
315
|
+
],
|
|
316
|
+
series: [webglLine],
|
|
317
|
+
zoom: {
|
|
318
|
+
enabled: true,
|
|
319
|
+
mode: 'both',
|
|
320
|
+
direction: 'x',
|
|
321
|
+
scaleExtent: [1, 80],
|
|
322
|
+
wheelZoom: { enabled: true, devices: 'pc', sensitivity: 0.85 },
|
|
323
|
+
gestureZoom: { enabled: true, devices: 'mobile', minTouches: 1 },
|
|
324
|
+
resetOnDoubleClick: true,
|
|
325
|
+
onZoom: ({ xDomain }) => {
|
|
326
|
+
console.log('visible x domain', xDomain);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}).render();
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
- `direction`: `'x'`, `'y'`, `'xy'` 중 하나입니다. 대용량 line 차트는 보통 `'x'`가 가장 자연스럽습니다.
|
|
333
|
+
- `mode`: `'wheel'`은 wheel/trackpad zoom과 drag pan, `'select'`는 드래그 영역 선택 zoom, `'both'`는 wheel/trackpad zoom과 드래그 영역 선택 zoom을 함께 사용합니다.
|
|
334
|
+
- `scaleExtent`: 최소/최대 확대 배율입니다.
|
|
335
|
+
- `wheelZoom`: PC wheel/trackpad 입력을 제어합니다. `devices`는 기본값이 `'pc'`이며, 필요하면 `'all'`로 바꿀 수 있습니다. `sensitivity`로 확대 민감도를 조절합니다.
|
|
336
|
+
- `gestureZoom`: 모바일 touch gesture 입력을 제어합니다. `devices`는 기본값이 `'mobile'`이며, `minTouches: 1`이면 한 손가락 pan과 두 손가락 pinch를 함께 허용합니다.
|
|
337
|
+
- `resetOnDoubleClick`: `false`로 지정하면 더블클릭 reset을 끌 수 있습니다.
|
|
338
|
+
|
|
228
339
|
## LTTB Downsampling
|
|
229
340
|
|
|
230
341
|
Line 계열 series는 `downsample` 옵션으로 LTTB(Largest Triangle Three Buckets) 다운샘플링을 사용할 수 있습니다. 원본 `data`와 축 domain은 그대로 유지하고, SVG/Canvas/WebGL renderer에 넘기는 series 데이터만 그리기 직전에 줄입니다.
|
|
@@ -488,53 +599,9 @@ const stackedSeries = createCustomSeries<Point>({
|
|
|
488
599
|
|
|
489
600
|
KChart touches the DOM, so create it in a Client Component after mount.
|
|
490
601
|
|
|
491
|
-
|
|
492
|
-
'use client';
|
|
493
|
-
|
|
494
|
-
import { useEffect, useRef } from 'react';
|
|
495
|
-
import { createKChart, createLineSeries, KChartController } from '@keneth80/k-chart';
|
|
602
|
+
See the full guide: [React And Next.js Guide](docs/react-nextjs.md).
|
|
496
603
|
|
|
497
|
-
|
|
498
|
-
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
499
|
-
const chartRef = useRef<KChartController | null>(null);
|
|
500
|
-
|
|
501
|
-
useEffect(() => {
|
|
502
|
-
if (!rootRef.current) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const chart = createKChart({
|
|
507
|
-
selector: rootRef.current,
|
|
508
|
-
data,
|
|
509
|
-
axes: [
|
|
510
|
-
{ field: 'time', type: 'string', placement: 'bottom' },
|
|
511
|
-
{ field: 'value', type: 'number', placement: 'left' }
|
|
512
|
-
],
|
|
513
|
-
series: [
|
|
514
|
-
createLineSeries({
|
|
515
|
-
selector: 'traffic',
|
|
516
|
-
xField: 'time',
|
|
517
|
-
yField: 'value'
|
|
518
|
-
})
|
|
519
|
-
]
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
chart.render();
|
|
523
|
-
chartRef.current = chart;
|
|
524
|
-
|
|
525
|
-
return () => {
|
|
526
|
-
chart.destroy();
|
|
527
|
-
chartRef.current = null;
|
|
528
|
-
};
|
|
529
|
-
}, []);
|
|
530
|
-
|
|
531
|
-
useEffect(() => {
|
|
532
|
-
chartRef.current?.updateData(data);
|
|
533
|
-
}, [data]);
|
|
534
|
-
|
|
535
|
-
return <div ref={rootRef} style={{ width: '100%', height: 420 }} />;
|
|
536
|
-
}
|
|
537
|
-
```
|
|
604
|
+
Note: the current `@keneth80/k-chart` package does not include an official React plugin package yet. The Next playground has a local wrapper example under `packages/react/src`.
|
|
538
605
|
|
|
539
606
|
## Migration Status
|
|
540
607
|
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# KChart Code Graph Handoff
|
|
2
|
+
|
|
3
|
+
이 문서는 다음 작업 세션에서 KChart의 현재 구조와 진행 상태를 빠르게 복원하기 위한 handoff 문서입니다.
|
|
4
|
+
|
|
5
|
+
## Current Snapshot
|
|
6
|
+
|
|
7
|
+
- Package: `@keneth80/k-chart`
|
|
8
|
+
- Current public API style: class-free functional runtime
|
|
9
|
+
- Current release baseline: `1.3.0`
|
|
10
|
+
- Main source entry: `src/index.ts` -> `src/kchart.ts`
|
|
11
|
+
- Worker entry: `src/kchart-render.worker.ts`
|
|
12
|
+
- Public playground source link: intentionally removed because the playground repository may become private.
|
|
13
|
+
- Local playground target: `http://127.0.0.1:9011`
|
|
14
|
+
- Library demo target: `http://127.0.0.1:9003`
|
|
15
|
+
|
|
16
|
+
## High-Level Code Graph
|
|
17
|
+
|
|
18
|
+
```mermaid
|
|
19
|
+
flowchart TD
|
|
20
|
+
App["Consumer App / React Wrapper / Playground"]
|
|
21
|
+
API["src/index.ts"]
|
|
22
|
+
Core["src/kchart.ts"]
|
|
23
|
+
Config["KChartConfiguration<T>"]
|
|
24
|
+
Controller["KChartController<T>"]
|
|
25
|
+
State["KChartState<T>"]
|
|
26
|
+
Layout["Layout / Margin / Size"]
|
|
27
|
+
Scales["Axes / Domain / D3 Scales"]
|
|
28
|
+
Layers["SVG / Canvas / WebGL Layers"]
|
|
29
|
+
Options["SpecArea / GuideLine / CursorLine"]
|
|
30
|
+
Legend["Legend Selection"]
|
|
31
|
+
Tooltip["Tooltip / Cursor Guide"]
|
|
32
|
+
Zoom["Wheel / Drag Pan / Selection Zoom"]
|
|
33
|
+
Downsample["LTTB Downsample"]
|
|
34
|
+
Series["KChartSeries<T>[]"]
|
|
35
|
+
SvgSeries["SVG Series"]
|
|
36
|
+
CanvasSeries["Canvas Series"]
|
|
37
|
+
WebglSeries["WebGL Series"]
|
|
38
|
+
Worker["OffscreenCanvas Worker"]
|
|
39
|
+
|
|
40
|
+
App --> API
|
|
41
|
+
API --> Core
|
|
42
|
+
Core --> Config
|
|
43
|
+
Config --> Controller
|
|
44
|
+
Controller --> State
|
|
45
|
+
State --> Layout
|
|
46
|
+
State --> Scales
|
|
47
|
+
State --> Layers
|
|
48
|
+
State --> Series
|
|
49
|
+
State --> Options
|
|
50
|
+
State --> Legend
|
|
51
|
+
State --> Tooltip
|
|
52
|
+
State --> Zoom
|
|
53
|
+
Series --> Downsample
|
|
54
|
+
Series --> SvgSeries
|
|
55
|
+
Series --> CanvasSeries
|
|
56
|
+
Series --> WebglSeries
|
|
57
|
+
CanvasSeries --> Worker
|
|
58
|
+
WebglSeries --> Worker
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Runtime Render Pipeline
|
|
62
|
+
|
|
63
|
+
```mermaid
|
|
64
|
+
sequenceDiagram
|
|
65
|
+
participant UI as UI / Consumer
|
|
66
|
+
participant Chart as createKChart
|
|
67
|
+
participant State as KChartState
|
|
68
|
+
participant Render as render(state)
|
|
69
|
+
participant Series as series.render(context)
|
|
70
|
+
participant Worker as OffscreenCanvas Worker
|
|
71
|
+
|
|
72
|
+
UI->>Chart: createKChart(config)
|
|
73
|
+
Chart->>State: resolve container, size, margin, layers
|
|
74
|
+
UI->>Chart: controller.render()
|
|
75
|
+
Chart->>Render: render(state)
|
|
76
|
+
Render->>State: resolve size, scales, plotSize
|
|
77
|
+
Render->>Render: title, grid, spec areas, guide lines, axes, legend
|
|
78
|
+
Render->>Series: render visible series with shared scales
|
|
79
|
+
alt asyncRender enabled and supported
|
|
80
|
+
Series->>Worker: post line render payload
|
|
81
|
+
Worker-->>Series: draw on OffscreenCanvas
|
|
82
|
+
else main thread render
|
|
83
|
+
Series-->>Series: draw SVG / Canvas / WebGL
|
|
84
|
+
end
|
|
85
|
+
Render->>Render: tooltip, cursor guide, zoom overlay
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Public API Surface
|
|
89
|
+
|
|
90
|
+
Primary exports come from `src/kchart.ts` through `src/index.ts`.
|
|
91
|
+
|
|
92
|
+
### Chart Runtime
|
|
93
|
+
|
|
94
|
+
- `createKChart<T>(config)`
|
|
95
|
+
- `KChartConfiguration<T>`
|
|
96
|
+
- `KChartController<T>`
|
|
97
|
+
- `KChartState<T>`
|
|
98
|
+
- `KChartAxis<T>`
|
|
99
|
+
- `KChartSeries<T>`
|
|
100
|
+
|
|
101
|
+
### Series Factories
|
|
102
|
+
|
|
103
|
+
- `createLineSeries<T>(...)`: SVG line and optional dots.
|
|
104
|
+
- `createCanvasLineSeries<T>(...)`: Canvas 2D line renderer.
|
|
105
|
+
- `createCanvasPointSeries<T>(...)`: Canvas 2D point renderer.
|
|
106
|
+
- `createCanvasCandlestickSeries<T>(...)`: Canvas 2D OHLC candlestick renderer with open/close or previous-close color modes.
|
|
107
|
+
- `createWebglLineSeries<T>(...)`: WebGL line renderer for large data.
|
|
108
|
+
- `createWebglPointSeries<T>(...)`: WebGL point renderer using interleaved point buffer.
|
|
109
|
+
- `createCustomSeries<T>(...)`: user-defined renderer with access to chart layers and scales.
|
|
110
|
+
|
|
111
|
+
### Option Factories
|
|
112
|
+
|
|
113
|
+
- `createSpecAreaOption(...)`
|
|
114
|
+
- `createGuideLineOption(...)`
|
|
115
|
+
- `createCursorLineOption(...)`
|
|
116
|
+
|
|
117
|
+
Options can be passed through the unified `config.options` array. Legacy direct fields such as `specAreas`, `guideLines`, and `cursorGuide` are still read by the renderer.
|
|
118
|
+
|
|
119
|
+
### Performance APIs
|
|
120
|
+
|
|
121
|
+
- `downsampleLTTB<T>(data, threshold, xAccessor, yAccessor)`
|
|
122
|
+
- `startKChartRenderWorker(scope?)`
|
|
123
|
+
- Series-level `downsample`
|
|
124
|
+
- Series-level `asyncRender`
|
|
125
|
+
|
|
126
|
+
## Responsibility Map
|
|
127
|
+
|
|
128
|
+
| Area | Main Location | Responsibility |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| Public exports | `src/index.ts` | Re-export public KChart API. |
|
|
131
|
+
| Types and config contracts | `src/kchart.ts` top section | Define axes, series, tooltip, zoom, option, and controller contracts. |
|
|
132
|
+
| Container and layers | `createLayers`, `ensureCanvas` | Create/reuse SVG root, plot groups, overlay, Canvas, and WebGL canvas layers. |
|
|
133
|
+
| Layout | `resolveSize`, `resolveEffectiveMargin` | Calculate size and dynamic top margin for title, legend, and option labels. |
|
|
134
|
+
| Scales and axes | `resolveAxisDomain`, `resolveScales`, `renderAxes` | Build D3 scales and render axes/titles. |
|
|
135
|
+
| Options | `renderSpecAreas`, `renderGuideLines`, `getCursorGuide` | Render fixed background regions, fixed guide lines, and cursor line config. |
|
|
136
|
+
| Legend | `renderLegend` | Render selectable series legend and update visibility. |
|
|
137
|
+
| Tooltip and cursor guide | `renderTooltip` | Hit-test series, show tooltip, draw cursor line and value labels. |
|
|
138
|
+
| Zoom | `renderZoom`, `resolveZoomedAxes`, `resolveSelectionZoomAxes` | Wheel zoom, mobile gesture zoom, drag pan, selection zoom, double-click reset. |
|
|
139
|
+
| Downsampling | `downsampleLTTB`, `resolveSeriesRenderData` | Reduce line data before rendering while preserving shape. |
|
|
140
|
+
| SVG series | `createLineSeries` | Render SVG line/dot visuals. |
|
|
141
|
+
| Canvas series | `createCanvasLineSeries`, `createCanvasPointSeries` | Render Canvas 2D line/point visuals. |
|
|
142
|
+
| WebGL series | `createWebglLineSeries`, `createWebglPointSeries` | Render WebGL line/point visuals. |
|
|
143
|
+
| Worker rendering | `startKChartRenderWorker`, `src/kchart-render.worker.ts` | OffscreenCanvas worker bootstrap and async line drawing. |
|
|
144
|
+
|
|
145
|
+
## Data And Interaction Flow
|
|
146
|
+
|
|
147
|
+
```txt
|
|
148
|
+
KChartConfiguration<T>
|
|
149
|
+
-> createKChart()
|
|
150
|
+
-> KChartState<T>
|
|
151
|
+
-> render()
|
|
152
|
+
-> resolve scales from data + active axes
|
|
153
|
+
-> render chart chrome
|
|
154
|
+
-> filter visible series by legend state
|
|
155
|
+
-> apply downsample when configured
|
|
156
|
+
-> pass KChartRenderContext<T> to each series
|
|
157
|
+
-> attach tooltip, cursor guide, and zoom overlay
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Important state fields:
|
|
161
|
+
|
|
162
|
+
- `data`: current chart data.
|
|
163
|
+
- `axes`: active axes. Zoom updates this.
|
|
164
|
+
- `baseAxes`: original axes. Zoom reset returns to this.
|
|
165
|
+
- `series`: current series list.
|
|
166
|
+
- `visibleSeries`: legend-controlled visibility map.
|
|
167
|
+
- `zoomTransform`: current D3 zoom transform.
|
|
168
|
+
- `zoomSelection`: drag-selection state.
|
|
169
|
+
|
|
170
|
+
## Current Feature Status
|
|
171
|
+
|
|
172
|
+
### Done
|
|
173
|
+
|
|
174
|
+
- Class-free functional chart runtime.
|
|
175
|
+
- SVG, Canvas, WebGL series factories.
|
|
176
|
+
- Custom renderer API.
|
|
177
|
+
- Dark/light styling support through config and CSS.
|
|
178
|
+
- Legend selection and multi-series visibility.
|
|
179
|
+
- Tooltip support, including custom series tooltip hooks.
|
|
180
|
+
- Unified option array for spec areas, fixed guide lines, and cursor line.
|
|
181
|
+
- Dynamic title/legend/option-label top margin handling.
|
|
182
|
+
- LTTB downsampling for line series.
|
|
183
|
+
- OffscreenCanvas worker support for Canvas/WebGL line series.
|
|
184
|
+
- WebGL point interleaved buffer optimization.
|
|
185
|
+
- Wheel zoom, mobile gesture zoom, drag pan, drag-selection zoom, and double-click reset.
|
|
186
|
+
- `zoom.wheelZoom` and `zoom.gestureZoom` split desktop wheel/trackpad input from mobile touch gesture input without removing the older `mode` contract.
|
|
187
|
+
- Candlestick color modes support both `open-close` and `previous-close`; `previousCloseField` can point to an explicit previous close value.
|
|
188
|
+
|
|
189
|
+
### External Packages Around This Library
|
|
190
|
+
|
|
191
|
+
- `@keneth80/k-chart-react`: separate React wrapper package.
|
|
192
|
+
- KChart Next playground: separate app used for examples, editable configuration, and AI Builder. Its GitHub source link should not be exposed from public library docs while it is private or planned private.
|
|
193
|
+
|
|
194
|
+
## Known Design Decisions
|
|
195
|
+
|
|
196
|
+
- Axis, scale, layout, and interaction state belong to the core runtime.
|
|
197
|
+
- Visual drawing belongs to series renderers.
|
|
198
|
+
- Series receive already resolved scale information and can draw using SVG, Canvas, or WebGL.
|
|
199
|
+
- Custom visualizations should use `createCustomSeries` instead of class inheritance.
|
|
200
|
+
- OHLC-style charts should use axis `domainFields` so a single y-axis can derive its domain from multiple value fields such as `low` and `high`.
|
|
201
|
+
- The library does not execute user-edited JavaScript. Playground-generated configs should be validated before applying.
|
|
202
|
+
- Web Worker rendering is opt-in with `asyncRender` because bundler worker setup differs by application.
|
|
203
|
+
|
|
204
|
+
## Verification Commands
|
|
205
|
+
|
|
206
|
+
Use these before release or handoff:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
npm run typecheck
|
|
210
|
+
npm run build:lib
|
|
211
|
+
npm pack --dry-run
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
For local demo verification:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npm run dev
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Then open `http://127.0.0.1:9003/`.
|
|
221
|
+
|
|
222
|
+
## Next Good Work Items
|
|
223
|
+
|
|
224
|
+
- Split `src/kchart.ts` into smaller modules once API behavior is stable:
|
|
225
|
+
- `core/types.ts`
|
|
226
|
+
- `core/layout.ts`
|
|
227
|
+
- `core/scales.ts`
|
|
228
|
+
- `core/interactions.ts`
|
|
229
|
+
- `series/svg.ts`
|
|
230
|
+
- `series/canvas.ts`
|
|
231
|
+
- `series/webgl.ts`
|
|
232
|
+
- `options/*.ts`
|
|
233
|
+
- Add unit tests for:
|
|
234
|
+
- `downsampleLTTB`
|
|
235
|
+
- `resolveEffectiveMargin`
|
|
236
|
+
- zoom domain calculation
|
|
237
|
+
- option array normalization
|
|
238
|
+
- Add browser-level regression checks for:
|
|
239
|
+
- legend hit visibility
|
|
240
|
+
- stacked/column tooltip behavior
|
|
241
|
+
- topology hover behavior in the playground/wrapper layer
|
|
242
|
+
- Keep release notes in `CHANGELOG.md` aligned with npm versions.
|