@keneth80/k-chart 1.3.0 → 1.5.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 +19 -0
- package/README.md +139 -0
- package/docs/code-graph-handoff.md +244 -0
- package/docs/functional-api.md +104 -1
- package/docs/release.md +74 -0
- package/examples/canvas-candlestick-series.ts +106 -0
- package/examples/svg-globe-map-series.ts +51 -0
- package/lib/kchart.d.ts +96 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +727 -16
- package/lib/kchart.js.map +1 -1
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.0 - 2026-06-14
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added `createSvgGlobeSeries` for draggable SVG orthographic globe maps with latitude/longitude markers and marker click callbacks.
|
|
8
|
+
- Added a default World Atlas 110m land layer for globe maps, with `landVisible` and `landGeoJson` controls.
|
|
9
|
+
- Added feature-level `landFill`, `landStroke`, and `landOpacity` styling callbacks for globe map land/country layers.
|
|
10
|
+
- Added optional globe wheel, pinch, and in-chart button zoom controls through `createSvgGlobeSeries({ zoom })`.
|
|
11
|
+
- Changed the default globe land rendering to a smooth World Atlas land layer with country borders as a mesh; country fills remain available through `landMode: 'countries'`.
|
|
12
|
+
|
|
13
|
+
## 1.4.0 - 2026-06-13
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Added `createCanvasCandlestickSeries` for Canvas OHLC candlestick charts.
|
|
18
|
+
- Added axis `domainFields` support so one axis can derive its domain from multiple fields such as `low` and `high`.
|
|
19
|
+
- Added `zoom.wheelZoom` and `zoom.gestureZoom` options to separate PC wheel/trackpad zoom from mobile touch gesture zoom.
|
|
20
|
+
- Added candlestick `colorMode: 'previous-close'` and `previousCloseField` support for previous-close based stock coloring.
|
|
21
|
+
|
|
3
22
|
## 1.3.0
|
|
4
23
|
|
|
5
24
|
### 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
|
|
@@ -52,9 +60,12 @@ Then open `http://127.0.0.1:9003/`.
|
|
|
52
60
|
## Guides
|
|
53
61
|
|
|
54
62
|
- [Functional API Guide](docs/functional-api.md)
|
|
63
|
+
- [Code Graph Handoff](docs/code-graph-handoff.md)
|
|
55
64
|
- [React And Next.js Guide](docs/react-nextjs.md)
|
|
56
65
|
- [Release Guide](docs/release.md)
|
|
57
66
|
- [React Wrapper Example](examples/react-wrapper.tsx)
|
|
67
|
+
- [Canvas Candlestick Example](examples/canvas-candlestick-series.ts)
|
|
68
|
+
- [SVG Globe Map Example](examples/svg-globe-map-series.ts)
|
|
58
69
|
|
|
59
70
|
## Quick Start
|
|
60
71
|
|
|
@@ -205,6 +216,130 @@ const webglLine = createWebglLineSeries<Point>({
|
|
|
205
216
|
});
|
|
206
217
|
```
|
|
207
218
|
|
|
219
|
+
## Candlestick Chart
|
|
220
|
+
|
|
221
|
+
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.
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import {
|
|
225
|
+
createCanvasCandlestickSeries,
|
|
226
|
+
createKChart
|
|
227
|
+
} from '@keneth80/k-chart';
|
|
228
|
+
|
|
229
|
+
interface StockPoint {
|
|
230
|
+
date: string;
|
|
231
|
+
open: number;
|
|
232
|
+
high: number;
|
|
233
|
+
low: number;
|
|
234
|
+
close: number;
|
|
235
|
+
previousClose: number;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const data: StockPoint[] = [
|
|
239
|
+
{ date: '2026-06-01', open: 101, high: 108, low: 98, close: 106, previousClose: 100 },
|
|
240
|
+
{ date: '2026-06-02', open: 106, high: 110, low: 102, close: 103, previousClose: 106 },
|
|
241
|
+
{ date: '2026-06-03', open: 103, high: 112, low: 101, close: 111, previousClose: 103 }
|
|
242
|
+
];
|
|
243
|
+
|
|
244
|
+
createKChart<StockPoint>({
|
|
245
|
+
selector: '#chart',
|
|
246
|
+
data,
|
|
247
|
+
axes: [
|
|
248
|
+
{ field: 'date', type: 'time', placement: 'bottom', tickCount: 5, domain: ['2026-05-31', '2026-06-04'] },
|
|
249
|
+
{
|
|
250
|
+
field: 'close',
|
|
251
|
+
type: 'number',
|
|
252
|
+
placement: 'left',
|
|
253
|
+
title: 'Price',
|
|
254
|
+
domainFields: ['low', 'high']
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
tooltip: { visible: true },
|
|
258
|
+
series: [
|
|
259
|
+
createCanvasCandlestickSeries({
|
|
260
|
+
selector: 'price',
|
|
261
|
+
displayName: 'Price',
|
|
262
|
+
xField: 'date',
|
|
263
|
+
openField: 'open',
|
|
264
|
+
highField: 'high',
|
|
265
|
+
lowField: 'low',
|
|
266
|
+
closeField: 'close',
|
|
267
|
+
colorMode: 'previous-close',
|
|
268
|
+
previousCloseField: 'previousClose',
|
|
269
|
+
upColor: '#22c55e',
|
|
270
|
+
downColor: '#ef4444'
|
|
271
|
+
})
|
|
272
|
+
]
|
|
273
|
+
}).render();
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
`colorMode` 기본값은 `'open-close'`이며 `close`와 `open`을 비교합니다. 한국 주식 화면처럼 전일 종가 대비 상승/하락 색상을 쓰려면 `colorMode: 'previous-close'`를 지정합니다. `previousCloseField`를 넘기면 해당 필드를 기준으로 비교하고, 생략하면 현재 데이터 배열에서 바로 앞 캔들의 `closeField` 값을 사용합니다.
|
|
277
|
+
|
|
278
|
+
## Globe Map
|
|
279
|
+
|
|
280
|
+
SVG globe series renders latitude/longitude markers on a draggable orthographic globe. Marker coordinates use ordinary geographic values: `lat` for latitude and `lon` for longitude. Click handlers receive the original data item, projected screen position, and the original browser event. A World Atlas 110m land layer is rendered by default with country borders as a separate mesh; set `landVisible: false` to hide it, or pass `landGeoJson` to use your own GeoJSON land/country data. `landMode: 'countries'` switches the fill layer to country features so `landFill`, `landStroke`, and `landOpacity` callbacks can style countries per feature. Set `zoom: { enabled: true }` to enable wheel zoom on desktop and pinch zoom on touch devices. Add `controls: true` to show in-chart zoom controls when page scrolling makes wheel zoom awkward.
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
import {
|
|
284
|
+
createKChart,
|
|
285
|
+
createSvgGlobeSeries
|
|
286
|
+
} from '@keneth80/k-chart';
|
|
287
|
+
|
|
288
|
+
interface CityPoint {
|
|
289
|
+
name: string;
|
|
290
|
+
lat: number;
|
|
291
|
+
lon: number;
|
|
292
|
+
url: string;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const cities: CityPoint[] = [
|
|
296
|
+
{ name: 'Seoul', lat: 37.5665, lon: 126.9780, url: 'https://en.wikipedia.org/wiki/Seoul' },
|
|
297
|
+
{ name: 'New York', lat: 40.7128, lon: -74.0060, url: 'https://en.wikipedia.org/wiki/New_York_City' }
|
|
298
|
+
];
|
|
299
|
+
|
|
300
|
+
createKChart<CityPoint>({
|
|
301
|
+
selector: '#chart',
|
|
302
|
+
data: cities,
|
|
303
|
+
grid: { visible: false },
|
|
304
|
+
legend: { visible: false },
|
|
305
|
+
tooltip: { visible: false },
|
|
306
|
+
axes: [],
|
|
307
|
+
series: [
|
|
308
|
+
createSvgGlobeSeries({
|
|
309
|
+
selector: 'cities',
|
|
310
|
+
latField: 'lat',
|
|
311
|
+
lonField: 'lon',
|
|
312
|
+
labelField: 'name',
|
|
313
|
+
initialRotate: [-120, -18, 0],
|
|
314
|
+
zoom: { enabled: true, min: 0.65, max: 3, controls: { visible: true, x: 6, y: 6 } },
|
|
315
|
+
landFill: '#22c55e',
|
|
316
|
+
landStroke: 'rgba(236, 253, 245, 0.72)',
|
|
317
|
+
landOpacity: 0.58,
|
|
318
|
+
countryBordersStroke: 'rgba(236, 253, 245, 0.28)',
|
|
319
|
+
onMarkerClick: ({ data }) => {
|
|
320
|
+
window.open(data.url, '_blank', 'noopener,noreferrer');
|
|
321
|
+
}
|
|
322
|
+
})
|
|
323
|
+
]
|
|
324
|
+
}).render();
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Country-level styling is available when the land layer uses country features:
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
createSvgGlobeSeries({
|
|
331
|
+
selector: 'country-colors',
|
|
332
|
+
latField: 'lat',
|
|
333
|
+
lonField: 'lon',
|
|
334
|
+
landMode: 'countries',
|
|
335
|
+
landFill: (feature, index) => {
|
|
336
|
+
const name = feature.properties?.name;
|
|
337
|
+
if (name === 'South Korea') return '#60a5fa';
|
|
338
|
+
return ['#22c55e', '#14b8a6', '#f59e0b'][index % 3];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
208
343
|
대용량 line 예제에서는 축 tick 수를 줄여 라벨 겹침을 피할 수 있습니다.
|
|
209
344
|
|
|
210
345
|
```ts
|
|
@@ -250,6 +385,8 @@ createKChart({
|
|
|
250
385
|
mode: 'both',
|
|
251
386
|
direction: 'x',
|
|
252
387
|
scaleExtent: [1, 80],
|
|
388
|
+
wheelZoom: { enabled: true, devices: 'pc', sensitivity: 0.85 },
|
|
389
|
+
gestureZoom: { enabled: true, devices: 'mobile', minTouches: 1 },
|
|
253
390
|
resetOnDoubleClick: true,
|
|
254
391
|
onZoom: ({ xDomain }) => {
|
|
255
392
|
console.log('visible x domain', xDomain);
|
|
@@ -261,6 +398,8 @@ createKChart({
|
|
|
261
398
|
- `direction`: `'x'`, `'y'`, `'xy'` 중 하나입니다. 대용량 line 차트는 보통 `'x'`가 가장 자연스럽습니다.
|
|
262
399
|
- `mode`: `'wheel'`은 wheel/trackpad zoom과 drag pan, `'select'`는 드래그 영역 선택 zoom, `'both'`는 wheel/trackpad zoom과 드래그 영역 선택 zoom을 함께 사용합니다.
|
|
263
400
|
- `scaleExtent`: 최소/최대 확대 배율입니다.
|
|
401
|
+
- `wheelZoom`: PC wheel/trackpad 입력을 제어합니다. `devices`는 기본값이 `'pc'`이며, 필요하면 `'all'`로 바꿀 수 있습니다. `sensitivity`로 확대 민감도를 조절합니다.
|
|
402
|
+
- `gestureZoom`: 모바일 touch gesture 입력을 제어합니다. `devices`는 기본값이 `'mobile'`이며, `minTouches: 1`이면 한 손가락 pan과 두 손가락 pinch를 함께 허용합니다.
|
|
264
403
|
- `resetOnDoubleClick`: `false`로 지정하면 더블클릭 reset을 끌 수 있습니다.
|
|
265
404
|
|
|
266
405
|
## LTTB Downsampling
|
|
@@ -0,0 +1,244 @@
|
|
|
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
|
+
- `createSvgGlobeSeries<T>(...)`: SVG orthographic globe renderer with draggable rotation, latitude/longitude markers, and marker click callbacks.
|
|
108
|
+
- `createWebglLineSeries<T>(...)`: WebGL line renderer for large data.
|
|
109
|
+
- `createWebglPointSeries<T>(...)`: WebGL point renderer using interleaved point buffer.
|
|
110
|
+
- `createCustomSeries<T>(...)`: user-defined renderer with access to chart layers and scales.
|
|
111
|
+
|
|
112
|
+
### Option Factories
|
|
113
|
+
|
|
114
|
+
- `createSpecAreaOption(...)`
|
|
115
|
+
- `createGuideLineOption(...)`
|
|
116
|
+
- `createCursorLineOption(...)`
|
|
117
|
+
|
|
118
|
+
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.
|
|
119
|
+
|
|
120
|
+
### Performance APIs
|
|
121
|
+
|
|
122
|
+
- `downsampleLTTB<T>(data, threshold, xAccessor, yAccessor)`
|
|
123
|
+
- `startKChartRenderWorker(scope?)`
|
|
124
|
+
- Series-level `downsample`
|
|
125
|
+
- Series-level `asyncRender`
|
|
126
|
+
|
|
127
|
+
## Responsibility Map
|
|
128
|
+
|
|
129
|
+
| Area | Main Location | Responsibility |
|
|
130
|
+
| --- | --- | --- |
|
|
131
|
+
| Public exports | `src/index.ts` | Re-export public KChart API. |
|
|
132
|
+
| Types and config contracts | `src/kchart.ts` top section | Define axes, series, tooltip, zoom, option, and controller contracts. |
|
|
133
|
+
| Container and layers | `createLayers`, `ensureCanvas` | Create/reuse SVG root, plot groups, overlay, Canvas, and WebGL canvas layers. |
|
|
134
|
+
| Layout | `resolveSize`, `resolveEffectiveMargin` | Calculate size and dynamic top margin for title, legend, and option labels. |
|
|
135
|
+
| Scales and axes | `resolveAxisDomain`, `resolveScales`, `renderAxes` | Build D3 scales and render axes/titles. |
|
|
136
|
+
| Options | `renderSpecAreas`, `renderGuideLines`, `getCursorGuide` | Render fixed background regions, fixed guide lines, and cursor line config. |
|
|
137
|
+
| Legend | `renderLegend` | Render selectable series legend and update visibility. |
|
|
138
|
+
| Tooltip and cursor guide | `renderTooltip` | Hit-test series, show tooltip, draw cursor line and value labels. |
|
|
139
|
+
| Zoom | `renderZoom`, `resolveZoomedAxes`, `resolveSelectionZoomAxes` | Wheel zoom, mobile gesture zoom, drag pan, selection zoom, double-click reset. |
|
|
140
|
+
| Downsampling | `downsampleLTTB`, `resolveSeriesRenderData` | Reduce line data before rendering while preserving shape. |
|
|
141
|
+
| SVG series | `createLineSeries` | Render SVG line/dot visuals. |
|
|
142
|
+
| Canvas series | `createCanvasLineSeries`, `createCanvasPointSeries` | Render Canvas 2D line/point visuals. |
|
|
143
|
+
| WebGL series | `createWebglLineSeries`, `createWebglPointSeries` | Render WebGL line/point visuals. |
|
|
144
|
+
| Worker rendering | `startKChartRenderWorker`, `src/kchart-render.worker.ts` | OffscreenCanvas worker bootstrap and async line drawing. |
|
|
145
|
+
|
|
146
|
+
## Data And Interaction Flow
|
|
147
|
+
|
|
148
|
+
```txt
|
|
149
|
+
KChartConfiguration<T>
|
|
150
|
+
-> createKChart()
|
|
151
|
+
-> KChartState<T>
|
|
152
|
+
-> render()
|
|
153
|
+
-> resolve scales from data + active axes
|
|
154
|
+
-> render chart chrome
|
|
155
|
+
-> filter visible series by legend state
|
|
156
|
+
-> apply downsample when configured
|
|
157
|
+
-> pass KChartRenderContext<T> to each series
|
|
158
|
+
-> attach tooltip, cursor guide, and zoom overlay
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Important state fields:
|
|
162
|
+
|
|
163
|
+
- `data`: current chart data.
|
|
164
|
+
- `axes`: active axes. Zoom updates this.
|
|
165
|
+
- `baseAxes`: original axes. Zoom reset returns to this.
|
|
166
|
+
- `series`: current series list.
|
|
167
|
+
- `visibleSeries`: legend-controlled visibility map.
|
|
168
|
+
- `zoomTransform`: current D3 zoom transform.
|
|
169
|
+
- `zoomSelection`: drag-selection state.
|
|
170
|
+
|
|
171
|
+
## Current Feature Status
|
|
172
|
+
|
|
173
|
+
### Done
|
|
174
|
+
|
|
175
|
+
- Class-free functional chart runtime.
|
|
176
|
+
- SVG, Canvas, WebGL series factories.
|
|
177
|
+
- Custom renderer API.
|
|
178
|
+
- Dark/light styling support through config and CSS.
|
|
179
|
+
- Legend selection and multi-series visibility.
|
|
180
|
+
- Tooltip support, including custom series tooltip hooks.
|
|
181
|
+
- Unified option array for spec areas, fixed guide lines, and cursor line.
|
|
182
|
+
- Dynamic title/legend/option-label top margin handling.
|
|
183
|
+
- LTTB downsampling for line series.
|
|
184
|
+
- OffscreenCanvas worker support for Canvas/WebGL line series.
|
|
185
|
+
- WebGL point interleaved buffer optimization.
|
|
186
|
+
- Wheel zoom, mobile gesture zoom, drag pan, drag-selection zoom, and double-click reset.
|
|
187
|
+
- `zoom.wheelZoom` and `zoom.gestureZoom` split desktop wheel/trackpad input from mobile touch gesture input without removing the older `mode` contract.
|
|
188
|
+
- Candlestick color modes support both `open-close` and `previous-close`; `previousCloseField` can point to an explicit previous close value.
|
|
189
|
+
- Globe map series uses `d3-geo` and expects ordinary `lat`/`lon` fields. It renders a built-in World Atlas 110m land layer plus country border mesh by default, accepts external GeoJSON through `landGeoJson`, supports country feature styling through `landMode: 'countries'`, `landFill`, `landStroke`, and `landOpacity`, and can enable wheel/pinch scaling plus in-chart zoom buttons through the `zoom` option.
|
|
190
|
+
|
|
191
|
+
### External Packages Around This Library
|
|
192
|
+
|
|
193
|
+
- `@keneth80/k-chart-react`: separate React wrapper package.
|
|
194
|
+
- 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.
|
|
195
|
+
|
|
196
|
+
## Known Design Decisions
|
|
197
|
+
|
|
198
|
+
- Axis, scale, layout, and interaction state belong to the core runtime.
|
|
199
|
+
- Visual drawing belongs to series renderers.
|
|
200
|
+
- Series receive already resolved scale information and can draw using SVG, Canvas, or WebGL.
|
|
201
|
+
- Custom visualizations should use `createCustomSeries` instead of class inheritance.
|
|
202
|
+
- 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`.
|
|
203
|
+
- The library does not execute user-edited JavaScript. Playground-generated configs should be validated before applying.
|
|
204
|
+
- Web Worker rendering is opt-in with `asyncRender` because bundler worker setup differs by application.
|
|
205
|
+
|
|
206
|
+
## Verification Commands
|
|
207
|
+
|
|
208
|
+
Use these before release or handoff:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
npm run typecheck
|
|
212
|
+
npm run build:lib
|
|
213
|
+
npm pack --dry-run
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
For local demo verification:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npm run dev
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Then open `http://127.0.0.1:9003/`.
|
|
223
|
+
|
|
224
|
+
## Next Good Work Items
|
|
225
|
+
|
|
226
|
+
- Split `src/kchart.ts` into smaller modules once API behavior is stable:
|
|
227
|
+
- `core/types.ts`
|
|
228
|
+
- `core/layout.ts`
|
|
229
|
+
- `core/scales.ts`
|
|
230
|
+
- `core/interactions.ts`
|
|
231
|
+
- `series/svg.ts`
|
|
232
|
+
- `series/canvas.ts`
|
|
233
|
+
- `series/webgl.ts`
|
|
234
|
+
- `options/*.ts`
|
|
235
|
+
- Add unit tests for:
|
|
236
|
+
- `downsampleLTTB`
|
|
237
|
+
- `resolveEffectiveMargin`
|
|
238
|
+
- zoom domain calculation
|
|
239
|
+
- option array normalization
|
|
240
|
+
- Add browser-level regression checks for:
|
|
241
|
+
- legend hit visibility
|
|
242
|
+
- stacked/column tooltip behavior
|
|
243
|
+
- topology hover behavior in the playground/wrapper layer
|
|
244
|
+
- Keep release notes in `CHANGELOG.md` aligned with npm versions.
|
package/docs/functional-api.md
CHANGED
|
@@ -14,8 +14,10 @@ import {
|
|
|
14
14
|
createCursorLineOption,
|
|
15
15
|
createGuideLineOption,
|
|
16
16
|
createLineSeries,
|
|
17
|
+
createCanvasCandlestickSeries,
|
|
17
18
|
createCanvasLineSeries,
|
|
18
19
|
createCanvasPointSeries,
|
|
20
|
+
createSvgGlobeSeries,
|
|
19
21
|
createSpecAreaOption,
|
|
20
22
|
createWebglPointSeries,
|
|
21
23
|
createCustomSeries,
|
|
@@ -116,6 +118,105 @@ const chart = createKChart<Point>({
|
|
|
116
118
|
});
|
|
117
119
|
```
|
|
118
120
|
|
|
121
|
+
## Built-In Canvas Candlestick Series
|
|
122
|
+
|
|
123
|
+
OHLC 주식 데이터는 `createCanvasCandlestickSeries`로 렌더링합니다. Y축은 보통 `close`를 기본 field로 두고, `domainFields`에 `low`와 `high`를 넣어 전체 캔들 범위가 축 domain에 포함되게 합니다.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
interface StockPoint {
|
|
127
|
+
date: string;
|
|
128
|
+
open: number;
|
|
129
|
+
high: number;
|
|
130
|
+
low: number;
|
|
131
|
+
close: number;
|
|
132
|
+
previousClose: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const chart = createKChart<StockPoint>({
|
|
136
|
+
selector: '#chart',
|
|
137
|
+
data: [
|
|
138
|
+
{ date: '2026-06-01', open: 101, high: 108, low: 98, close: 106, previousClose: 100 },
|
|
139
|
+
{ date: '2026-06-02', open: 106, high: 110, low: 102, close: 103, previousClose: 106 },
|
|
140
|
+
{ date: '2026-06-03', open: 103, high: 112, low: 101, close: 111, previousClose: 103 }
|
|
141
|
+
],
|
|
142
|
+
axes: [
|
|
143
|
+
{ field: 'date', type: 'time', placement: 'bottom', tickCount: 5, domain: ['2026-05-31', '2026-06-04'] },
|
|
144
|
+
{
|
|
145
|
+
field: 'close',
|
|
146
|
+
type: 'number',
|
|
147
|
+
placement: 'left',
|
|
148
|
+
domainFields: ['low', 'high'],
|
|
149
|
+
title: 'Price'
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
tooltip: { visible: true },
|
|
153
|
+
series: [
|
|
154
|
+
createCanvasCandlestickSeries({
|
|
155
|
+
selector: 'price',
|
|
156
|
+
displayName: 'Price',
|
|
157
|
+
xField: 'date',
|
|
158
|
+
openField: 'open',
|
|
159
|
+
highField: 'high',
|
|
160
|
+
lowField: 'low',
|
|
161
|
+
closeField: 'close',
|
|
162
|
+
colorMode: 'previous-close',
|
|
163
|
+
previousCloseField: 'previousClose',
|
|
164
|
+
upColor: '#22c55e',
|
|
165
|
+
downColor: '#ef4444'
|
|
166
|
+
})
|
|
167
|
+
]
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
캔들 색상은 기본적으로 `colorMode: 'open-close'`로 동작하며 `close`와 `open`을 비교합니다. `colorMode: 'previous-close'`를 사용하면 현재 `close`와 전일 종가를 비교합니다. `previousCloseField`가 있으면 그 필드를 우선 사용하고, 없으면 렌더링 데이터에서 바로 앞 항목의 `closeField` 값을 전일 종가로 사용합니다.
|
|
172
|
+
|
|
173
|
+
## Built-In SVG Globe Series
|
|
174
|
+
|
|
175
|
+
지도/지구본 데이터는 `createSvgGlobeSeries`로 렌더링합니다. 좌표는 일반 위도/경도 값을 그대로 사용하며, 내부에서는 `projection([lon, lat])`로 변환합니다. 마커 클릭 시 원본 데이터, 위도/경도, 화면 좌표, 브라우저 이벤트를 callback으로 받을 수 있습니다. 기본값으로 World Atlas 110m land layer와 국가 경계 mesh가 표시되며, `landVisible: false`로 끄거나 `landGeoJson`으로 더 정교한 GeoJSON을 교체할 수 있습니다. 나라별 색상 지정이 필요하면 `landMode: 'countries'`를 사용하고 `landFill`, `landStroke`, `landOpacity` callback을 feature 기준으로 지정합니다. `zoom: { enabled: true }`를 지정하면 데스크톱에서는 wheel zoom, 터치 장치에서는 pinch zoom을 사용할 수 있습니다. 페이지 스크롤 때문에 wheel zoom을 쓰기 어려우면 `controls: true`로 차트 오른쪽 상단의 zoom control을 표시할 수 있습니다.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
interface CityPoint {
|
|
179
|
+
name: string;
|
|
180
|
+
lat: number;
|
|
181
|
+
lon: number;
|
|
182
|
+
url: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const chart = createKChart<CityPoint>({
|
|
186
|
+
selector: '#chart',
|
|
187
|
+
data: [
|
|
188
|
+
{ name: 'Seoul', lat: 37.5665, lon: 126.9780, url: 'https://en.wikipedia.org/wiki/Seoul' },
|
|
189
|
+
{ name: 'New York', lat: 40.7128, lon: -74.0060, url: 'https://en.wikipedia.org/wiki/New_York_City' },
|
|
190
|
+
{ name: 'London', lat: 51.5072, lon: -0.1276, url: 'https://en.wikipedia.org/wiki/London' }
|
|
191
|
+
],
|
|
192
|
+
grid: { visible: false },
|
|
193
|
+
legend: { visible: false },
|
|
194
|
+
tooltip: { visible: false },
|
|
195
|
+
axes: [],
|
|
196
|
+
series: [
|
|
197
|
+
createSvgGlobeSeries({
|
|
198
|
+
selector: 'cities',
|
|
199
|
+
displayName: 'Cities',
|
|
200
|
+
latField: 'lat',
|
|
201
|
+
lonField: 'lon',
|
|
202
|
+
labelField: 'name',
|
|
203
|
+
initialRotate: [-120, -18, 0],
|
|
204
|
+
zoom: { enabled: true, min: 0.65, max: 3, controls: { visible: true, x: 6, y: 6 } },
|
|
205
|
+
landFill: '#22c55e',
|
|
206
|
+
landStroke: 'rgba(236, 253, 245, 0.72)',
|
|
207
|
+
landOpacity: 0.58,
|
|
208
|
+
countryBordersStroke: 'rgba(236, 253, 245, 0.28)',
|
|
209
|
+
markerColor: '#5db8ff',
|
|
210
|
+
onMarkerClick: ({ data }) => {
|
|
211
|
+
window.open(data.url, '_blank', 'noopener,noreferrer');
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
]
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`draggable` 기본값은 `true`입니다. `zoom` 기본값은 비활성화이며, `zoom: true` 또는 `zoom: { enabled: true }`로 켤 수 있습니다. `min`과 `max`는 기본 globe scale에 곱해지는 배율입니다. `controls: true`를 지정하면 `+`, 현재 배율, `-` 버튼이 표시되고 현재 배율 버튼은 1x로 리셋합니다. `controls: { visible: true, x, y }`의 `x`, `y`는 차트 전체 SVG의 오른쪽/위쪽 edge 기준 offset입니다. `landGeoJson`에 GeoJSON feature, feature collection, 또는 feature 배열을 넘기면 기본 land layer 대신 해당 path를 구면 위에 그립니다. `landMode: 'countries'`를 지정하면 기본 fill layer도 국가 feature 단위로 분리되어 나라별 색상 callback을 적용할 수 있습니다.
|
|
219
|
+
|
|
119
220
|
## Built-In WebGL Series
|
|
120
221
|
|
|
121
222
|
```ts
|
|
@@ -198,12 +299,14 @@ createKChart<Point>({
|
|
|
198
299
|
mode: 'both',
|
|
199
300
|
direction: 'x',
|
|
200
301
|
scaleExtent: [1, 80],
|
|
302
|
+
wheelZoom: { enabled: true, devices: 'pc', sensitivity: 0.85 },
|
|
303
|
+
gestureZoom: { enabled: true, devices: 'mobile', minTouches: 1 },
|
|
201
304
|
resetOnDoubleClick: true
|
|
202
305
|
}
|
|
203
306
|
});
|
|
204
307
|
```
|
|
205
308
|
|
|
206
|
-
`mode`는 `'wheel'`, `'select'`, `'both'`를 지원합니다. `'wheel'`은 wheel/trackpad zoom과 drag pan, `'select'`는 드래그 영역 선택 zoom, `'both'`는 wheel/trackpad zoom과 드래그 영역 선택 zoom을 함께 사용합니다. `direction`은 `'x'`, `'y'`, `'xy'`를 지원합니다. string/point 축은 순서형 축이라 현재 zoom 대상에서 제외됩니다.
|
|
309
|
+
`mode`는 `'wheel'`, `'select'`, `'both'`를 지원합니다. `'wheel'`은 wheel/trackpad zoom과 drag pan, `'select'`는 드래그 영역 선택 zoom, `'both'`는 wheel/trackpad zoom과 드래그 영역 선택 zoom을 함께 사용합니다. `wheelZoom`은 PC wheel/trackpad 입력을, `gestureZoom`은 모바일 touch gesture 입력을 분리해서 제어합니다. `direction`은 `'x'`, `'y'`, `'xy'`를 지원합니다. string/point 축은 순서형 축이라 현재 zoom 대상에서 제외됩니다.
|
|
207
310
|
|
|
208
311
|
### OffscreenCanvas Worker Rendering
|
|
209
312
|
|
package/docs/release.md
CHANGED
|
@@ -29,6 +29,80 @@ npm run pack:dry
|
|
|
29
29
|
|
|
30
30
|
It should not include `node_modules`, `src`, `dist`, demo files, webpack config, or local archives.
|
|
31
31
|
|
|
32
|
+
## GitFlow
|
|
33
|
+
|
|
34
|
+
KChart uses a lightweight GitFlow model:
|
|
35
|
+
|
|
36
|
+
- `main`: production and npm release branch. Every commit on `main` should represent a releasable state.
|
|
37
|
+
- `develop`: integration branch for the next release.
|
|
38
|
+
- `feature/<name>`: feature work branched from `develop`, merged back into `develop`.
|
|
39
|
+
- `release/<version>`: release stabilization branched from `develop`, merged into `main` and then back into `develop`.
|
|
40
|
+
- `hotfix/<version>`: urgent production fix branched from `main`, merged into both `main` and `develop`.
|
|
41
|
+
|
|
42
|
+
### Feature Flow
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
git switch develop
|
|
46
|
+
git pull origin develop
|
|
47
|
+
git switch -c feature/my-feature
|
|
48
|
+
|
|
49
|
+
# work, commit, verify
|
|
50
|
+
npm run typecheck
|
|
51
|
+
npm run build:lib
|
|
52
|
+
|
|
53
|
+
git push origin feature/my-feature
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Merge the feature into `develop` after review.
|
|
57
|
+
|
|
58
|
+
### Release Flow
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git switch develop
|
|
62
|
+
git pull origin develop
|
|
63
|
+
git switch -c release/1.4.0
|
|
64
|
+
|
|
65
|
+
npm version minor --no-git-tag-version
|
|
66
|
+
# update CHANGELOG.md and docs
|
|
67
|
+
npm run typecheck
|
|
68
|
+
npm run build:lib
|
|
69
|
+
npm run pack:dry
|
|
70
|
+
|
|
71
|
+
git commit -am "Prepare 1.4.0 release"
|
|
72
|
+
git switch main
|
|
73
|
+
git merge --no-ff release/1.4.0
|
|
74
|
+
git tag v1.4.0
|
|
75
|
+
git push origin main v1.4.0
|
|
76
|
+
|
|
77
|
+
git switch develop
|
|
78
|
+
git merge --no-ff release/1.4.0
|
|
79
|
+
git push origin develop
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Publish to npm from `main` after the release tag is pushed.
|
|
83
|
+
|
|
84
|
+
### Hotfix Flow
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
git switch main
|
|
88
|
+
git pull origin main
|
|
89
|
+
git switch -c hotfix/1.3.1
|
|
90
|
+
|
|
91
|
+
# fix, verify, update patch version and CHANGELOG.md
|
|
92
|
+
npm run typecheck
|
|
93
|
+
npm run build:lib
|
|
94
|
+
npm run pack:dry
|
|
95
|
+
|
|
96
|
+
git switch main
|
|
97
|
+
git merge --no-ff hotfix/1.3.1
|
|
98
|
+
git tag v1.3.1
|
|
99
|
+
git push origin main v1.3.1
|
|
100
|
+
|
|
101
|
+
git switch develop
|
|
102
|
+
git merge --no-ff hotfix/1.3.1
|
|
103
|
+
git push origin develop
|
|
104
|
+
```
|
|
105
|
+
|
|
32
106
|
## Publish
|
|
33
107
|
|
|
34
108
|
For the first public release:
|