@keneth80/k-chart 1.17.0 → 1.18.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 +27 -0
- package/README.md +6 -0
- package/docs/configuration-reference.md +61 -1
- package/docs/functional-api.md +90 -0
- package/examples/stackblitz-tree-basic/index.html +26 -0
- package/examples/stackblitz-tree-basic/package.json +18 -0
- package/examples/stackblitz-tree-basic/src/main.ts +72 -0
- package/examples/stackblitz-tree-basic/src/style.css +56 -0
- package/examples/stackblitz-tree-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-treemap-basic/index.html +26 -0
- package/examples/stackblitz-treemap-basic/package.json +18 -0
- package/examples/stackblitz-treemap-basic/src/main.ts +66 -0
- package/examples/stackblitz-treemap-basic/src/style.css +56 -0
- package/examples/stackblitz-treemap-basic/src/vite-env.d.ts +1 -0
- package/lib/core/contracts.d.ts +67 -0
- package/lib/core/contracts.d.ts.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/support/canvas.d.ts +1 -0
- package/lib/series/support/canvas.d.ts.map +1 -1
- package/lib/series/support/canvas.js +35 -6
- package/lib/series/support/canvas.js.map +1 -1
- package/lib/series/svg-dashboard.d.ts.map +1 -1
- package/lib/series/svg-dashboard.js +6 -0
- package/lib/series/svg-dashboard.js.map +1 -1
- package/lib/series/svg-tree.d.ts +11 -0
- package/lib/series/svg-tree.d.ts.map +1 -0
- package/lib/series/svg-tree.js +654 -0
- package/lib/series/svg-tree.js.map +1 -0
- package/lib/worker/render-worker.d.ts.map +1 -1
- package/lib/worker/render-worker.js +44 -14
- package/lib/worker/render-worker.js.map +1 -1
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.18.0 - 2026-07-12
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added `createTreeSeries()` for id-parent hierarchy data with orthogonal and radial layouts, four orientations, ancestor/descendant hover emphasis, node labels, click callbacks, tooltips, and pan/zoom roaming.
|
|
8
|
+
- Added the Tree Chart library demo, StackBlitz starter, API reference, and hierarchy validation regression tests.
|
|
9
|
+
- Added a Preset-inspired Treemap library demo, StackBlitz starter, Usage snippet, and API guidance for Dimension + Metric part-to-whole analysis.
|
|
10
|
+
|
|
11
|
+
### Packages
|
|
12
|
+
|
|
13
|
+
- Published `@keneth80/k-chart@1.18.0`.
|
|
14
|
+
|
|
15
|
+
## 1.17.1 - 2026-07-11
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Removed the Worker WebGL line renderer's per-frame pixel-to-clip coordinate copy by moving the equivalent conversion into the vertex shader.
|
|
20
|
+
- Reused one GPU position buffer per OffscreenCanvas and released cached WebGL resources through an acknowledged worker teardown with a termination fallback.
|
|
21
|
+
|
|
22
|
+
### Tests
|
|
23
|
+
|
|
24
|
+
- Added Worker WebGL regression coverage for coordinate equivalence, zero-copy uploads, buffer reuse, resizing, render completion messages, acknowledged teardown, pending render rejection, per-canvas isolation, and resource cleanup.
|
|
25
|
+
|
|
26
|
+
### Packages
|
|
27
|
+
|
|
28
|
+
- Published `@keneth80/k-chart@1.17.1`.
|
|
29
|
+
|
|
3
30
|
## 1.17.0 - 2026-07-10
|
|
4
31
|
|
|
5
32
|
### Added
|
package/README.md
CHANGED
|
@@ -84,6 +84,10 @@
|
|
|
84
84
|
·
|
|
85
85
|
<a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-graph-basic?title=KChart%20Graph%20Chart&file=src/main.ts"><strong>Graph Chart</strong></a>
|
|
86
86
|
·
|
|
87
|
+
<a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-tree-basic?title=KChart%20Tree%20Chart&file=src/main.ts"><strong>Tree Chart</strong></a>
|
|
88
|
+
·
|
|
89
|
+
<a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-treemap-basic?title=KChart%20Treemap&file=src/main.ts"><strong>Treemap</strong></a>
|
|
90
|
+
·
|
|
87
91
|
<a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-sankey-basic?title=KChart%20Sankey%20Flow&file=src/main.ts"><strong>Sankey</strong></a>
|
|
88
92
|
·
|
|
89
93
|
<a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-three-wafer-basic?title=KChart%20Three.js%20Wafer&file=src/main.ts"><strong>Three.js Wafer</strong></a>
|
|
@@ -107,6 +111,8 @@ KChart는 완성형 대시보드 차트만 제공하는 라이브러리라기보
|
|
|
107
111
|
| Optional adapters | Three.js, CesiumJS, MapLibre는 별도 package로 분리해 기본 chart bundle에 3D/map 비용을 섞지 않습니다. |
|
|
108
112
|
| Business UI fit | tooltip note, fixed guide line, spec area, topology, candlestick처럼 운영 화면에서 바로 쓰는 옵션을 포함합니다. |
|
|
109
113
|
| Relationship analysis | `createGraphSeries(...)`로 source-target-metric 데이터를 Force/Circular 관계망으로 표현합니다. |
|
|
114
|
+
| Hierarchy analysis | `createTreeSeries(...)`로 id-parent 행을 조직도, 분류 체계, 의존 구조 형태로 표현합니다. |
|
|
115
|
+
| Part-to-whole analysis | `createTreemapSeries(...)`로 동일 metric의 구성 비중을 사각형 면적으로 비교합니다. |
|
|
110
116
|
| Flow analysis | `createSankeySeries(...)`로 단계별 흐름의 상대적인 크기와 이탈 지점을 표현합니다. |
|
|
111
117
|
|
|
112
118
|
### Size And Capability Snapshot
|
|
@@ -282,6 +282,51 @@ createGraphSeries<Relation>({
|
|
|
282
282
|
|
|
283
283
|
Graph가 직접 node hover/click 및 roaming을 처리해야 하는 화면에서는 chart-level `tooltip`과 `zoom`을 끄는 구성을 권장합니다. 코어 tooltip overlay가 필요한 경우 Graph의 `tooltip()` hit-test도 동작하지만, overlay가 SVG node의 직접 pointer event보다 위에 놓일 수 있습니다.
|
|
284
284
|
|
|
285
|
+
### SVG Tree: `createTreeSeries`
|
|
286
|
+
|
|
287
|
+
각 행의 `idField`와 `parentField`로 계층을 구성합니다. 부모가 없는 행은 정확히 하나여야 하며, 중복 id, 존재하지 않는 부모, 순환 관계는 오류로 처리합니다. 입력 형태는 [Preset Tree Chart](https://docs.preset.io/docs/tree-chart)의 name/id/parent 모델을 참고했고, 배치는 공식 [D3 tree layout](https://d3js.org/d3-hierarchy/tree)을 사용합니다.
|
|
288
|
+
|
|
289
|
+
| Field | Type | Default | Description |
|
|
290
|
+
| --- | --- | --- | --- |
|
|
291
|
+
| `selector` | `string` | required | series id/class입니다. |
|
|
292
|
+
| `idField` / `parentField` | `keyof T & string` | required | node id와 부모 id field입니다. 루트의 부모 값은 `null`, `undefined`, 빈 문자열 중 하나로 둡니다. |
|
|
293
|
+
| `labelField` | `keyof T & string` | id | 표시할 node 이름 field입니다. |
|
|
294
|
+
| `valueField` | `keyof T & string` | `0` | tooltip과 node 크기 함수에서 사용할 수치 field입니다. |
|
|
295
|
+
| `categoryField` | `keyof T & string` | - | 기본 palette 색상을 나눌 category field입니다. |
|
|
296
|
+
| `layout` | `orthogonal \| radial` | `orthogonal` | 직교 트리 또는 방사형 트리 배치입니다. |
|
|
297
|
+
| `orientation` | `left-right \| right-left \| top-bottom \| bottom-top` | `left-right` | 직교 트리의 진행 방향입니다. |
|
|
298
|
+
| `emphasis` | `ancestor \| descendant \| both \| none` | `both` | hover node와 함께 강조할 연결 범위입니다. |
|
|
299
|
+
| `symbol` | `circle \| square \| diamond` | `circle` | node 모양입니다. |
|
|
300
|
+
| `symbolSize` | `number \| (node) => number` | `13` | node 크기 또는 값 기반 크기 함수입니다. |
|
|
301
|
+
| `labelPosition` | `auto \| left \| right \| top \| bottom` | `auto` | node label 위치입니다. |
|
|
302
|
+
| `roam` | `move \| scale \| both \| disabled` | `both` | drag 이동과 wheel/touch 확대 사용 범위입니다. |
|
|
303
|
+
| `scaleExtent` | `[number, number]` | `[0.45, 5]` | tree 자체 zoom 배율 범위입니다. |
|
|
304
|
+
| `fitPadding` | `number` | `28` | layout과 plot 경계 사이 여백입니다. |
|
|
305
|
+
| `palette` / `nodeColor` | colors / color resolver | built-in palette | category 또는 node별 색상을 설정합니다. |
|
|
306
|
+
| `nodeOpacity`, `nodeStroke`, `nodeStrokeWidth` | number/string | metallic theme values | node fill/stroke 스타일입니다. |
|
|
307
|
+
| `edgeColor`, `edgeOpacity`, `edgeStrokeWidth` | value or resolver | metallic theme values | parent-child link 스타일입니다. |
|
|
308
|
+
| `dimOpacity` | `number` | `0.12` | hover 연결 범위 밖 node/link의 투명도입니다. |
|
|
309
|
+
| `labels` | `boolean \| object` | visible | formatter, 색상, 크기, 굵기, offset을 설정합니다. |
|
|
310
|
+
| `onNodeClick` | `(context) => void` | - | 클릭 node와 원본 event를 받습니다. |
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
createTreeSeries<OrganizationRow>({
|
|
314
|
+
selector: 'organization-tree',
|
|
315
|
+
idField: 'id',
|
|
316
|
+
parentField: 'parentId',
|
|
317
|
+
labelField: 'name',
|
|
318
|
+
valueField: 'headcount',
|
|
319
|
+
categoryField: 'team',
|
|
320
|
+
layout: 'orthogonal',
|
|
321
|
+
orientation: 'left-right',
|
|
322
|
+
emphasis: 'descendant',
|
|
323
|
+
symbolSize: (node) => 10 + Math.sqrt(node.value),
|
|
324
|
+
roam: 'both'
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
Tree가 pointer hover와 roaming을 직접 처리하므로 chart-level `zoom`은 끄는 구성을 권장합니다. chart-level tooltip은 node와 link를 hit-test하며, `onNodeClick`은 업무 화면의 상세 패널 연결에 사용할 수 있습니다.
|
|
329
|
+
|
|
285
330
|
### SVG Sankey: `createSankeySeries`
|
|
286
331
|
|
|
287
332
|
Sankey 역시 source-target-metric 행을 직접 받지만, 관계 탐색보다 왼쪽에서 오른쪽으로 진행되는 단계별 흐름과 상대적인 flow 폭을 강조합니다. 동일 source-target 행은 합산합니다. Sankey는 방향성 비순환 그래프(DAG)를 전제로 하며 순환이 발견되면 명확한 오류를 발생시킵니다.
|
|
@@ -348,6 +393,8 @@ createSankeySeries<FlowRow>({
|
|
|
348
393
|
|
|
349
394
|
### SVG Treemap: `createTreemapSeries`
|
|
350
395
|
|
|
396
|
+
각 data row를 하나의 Dimension 항목으로 보고, `valueField` Metric의 비중을 tile 면적으로 표현합니다. 이 입력 방식은 [Preset Tree Map](https://docs.preset.io/docs/tree-map)의 기본 Dimension + Metric 모델과 같습니다.
|
|
397
|
+
|
|
351
398
|
| Field | Type | Default | Description |
|
|
352
399
|
| --- | --- | --- | --- |
|
|
353
400
|
| `selector` | `string` | required | series id/class입니다. |
|
|
@@ -360,7 +407,20 @@ createSankeySeries<FlowRow>({
|
|
|
360
407
|
| `minLabelArea` | `number` | `1800` | label을 표시할 최소 tile 면적입니다. |
|
|
361
408
|
| `sort` | `boolean` | `true` | value 내림차순으로 layout할지 정합니다. |
|
|
362
409
|
|
|
363
|
-
현재
|
|
410
|
+
현재 Treemap은 추가 dependency 없이 recursive slice layout을 사용하며 단일 Dimension을 평면 분할합니다. Preset의 여러 Dimension처럼 부모-자식 구조 자체를 탐색해야 할 때는 `createTreeSeries()`를 사용하고, 계층형 면적 분할이 필요하면 custom series로 확장할 수 있습니다.
|
|
411
|
+
|
|
412
|
+
```ts
|
|
413
|
+
createTreemapSeries<ProductShare>({
|
|
414
|
+
selector: 'product-share',
|
|
415
|
+
labelField: 'product',
|
|
416
|
+
valueField: 'revenue',
|
|
417
|
+
colorField: 'color',
|
|
418
|
+
gap: 5,
|
|
419
|
+
radius: 4,
|
|
420
|
+
minLabelArea: 1600,
|
|
421
|
+
sort: true
|
|
422
|
+
});
|
|
423
|
+
```
|
|
364
424
|
|
|
365
425
|
### SVG Gauge / KPI Meter: `createGaugeSeries`
|
|
366
426
|
|
package/docs/functional-api.md
CHANGED
|
@@ -339,6 +339,96 @@ chart.render();
|
|
|
339
339
|
|
|
340
340
|
`layout: 'circular'`로 바꾸면 같은 데이터를 원형 배치로 비교할 수 있습니다. 중복 source-target 행은 하나의 edge로 합산되고, node metric은 연결된 edge metric의 합입니다.
|
|
341
341
|
|
|
342
|
+
## Built-In Tree Series
|
|
343
|
+
|
|
344
|
+
조직도나 분류 체계처럼 부모가 하나인 계층 데이터는 별도 nested object 변환 없이 id-parent 행 배열을 전달할 수 있습니다.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
type OrganizationRow = {
|
|
348
|
+
id: string;
|
|
349
|
+
parentId: string | null;
|
|
350
|
+
name: string;
|
|
351
|
+
team: string;
|
|
352
|
+
headcount: number;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const organization: OrganizationRow[] = [
|
|
356
|
+
{id: 'company', parentId: null, name: 'KChart', team: 'Company', headcount: 42},
|
|
357
|
+
{id: 'product', parentId: 'company', name: 'Product', team: 'Product', headcount: 14},
|
|
358
|
+
{id: 'engineering', parentId: 'company', name: 'Engineering', team: 'Engineering', headcount: 24},
|
|
359
|
+
{id: 'platform', parentId: 'engineering', name: 'Platform', team: 'Engineering', headcount: 8}
|
|
360
|
+
];
|
|
361
|
+
|
|
362
|
+
createKChart<OrganizationRow>({
|
|
363
|
+
selector: '#chart',
|
|
364
|
+
data: organization,
|
|
365
|
+
axes: [],
|
|
366
|
+
grid: {visible: false},
|
|
367
|
+
legend: {visible: false},
|
|
368
|
+
tooltip: {visible: true},
|
|
369
|
+
zoom: {visible: false},
|
|
370
|
+
series: [
|
|
371
|
+
createTreeSeries({
|
|
372
|
+
selector: 'organization-tree',
|
|
373
|
+
idField: 'id',
|
|
374
|
+
parentField: 'parentId',
|
|
375
|
+
labelField: 'name',
|
|
376
|
+
valueField: 'headcount',
|
|
377
|
+
categoryField: 'team',
|
|
378
|
+
layout: 'orthogonal',
|
|
379
|
+
orientation: 'left-right',
|
|
380
|
+
emphasis: 'descendant',
|
|
381
|
+
roam: 'both'
|
|
382
|
+
})
|
|
383
|
+
]
|
|
384
|
+
}).render();
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
`layout: 'radial'`은 같은 데이터를 중심에서 바깥으로 펼칩니다. 루트는 하나만 허용하며 모든 non-root node는 존재하는 부모를 가리켜야 합니다. 입력 오류는 렌더 전에 명확한 예외로 반환됩니다.
|
|
388
|
+
|
|
389
|
+
## Built-In Treemap Series
|
|
390
|
+
|
|
391
|
+
Treemap은 동일 metric을 여러 Dimension 항목으로 나누고, 전체에서 차지하는 비중을 tile 면적으로 비교할 때 사용합니다.
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
type ProductShare = {
|
|
395
|
+
product: string;
|
|
396
|
+
revenue: number;
|
|
397
|
+
color: string;
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
const products: ProductShare[] = [
|
|
401
|
+
{product: 'Analytics Cloud', revenue: 420, color: '#5db8ff'},
|
|
402
|
+
{product: 'Commerce API', revenue: 310, color: '#56d08f'},
|
|
403
|
+
{product: 'Data Platform', revenue: 245, color: '#f3b45b'},
|
|
404
|
+
{product: 'Automation', revenue: 165, color: '#d876ff'}
|
|
405
|
+
];
|
|
406
|
+
|
|
407
|
+
createKChart<ProductShare>({
|
|
408
|
+
selector: '#chart',
|
|
409
|
+
data: products,
|
|
410
|
+
axes: [],
|
|
411
|
+
grid: {visible: false},
|
|
412
|
+
legend: {visible: false},
|
|
413
|
+
tooltip: {visible: true},
|
|
414
|
+
animation: {enabled: true, duration: 720, mode: 'enter'},
|
|
415
|
+
series: [
|
|
416
|
+
createTreemapSeries({
|
|
417
|
+
selector: 'product-share',
|
|
418
|
+
labelField: 'product',
|
|
419
|
+
valueField: 'revenue',
|
|
420
|
+
colorField: 'color',
|
|
421
|
+
gap: 5,
|
|
422
|
+
radius: 4,
|
|
423
|
+
minLabelArea: 1600,
|
|
424
|
+
sort: true
|
|
425
|
+
})
|
|
426
|
+
]
|
|
427
|
+
}).render();
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
`valueField`는 0보다 큰 숫자를 사용해야 하며 면적은 전체 양수 metric 합에 대한 상대 비율입니다. 현재 API는 단일 Dimension 항목 비교에 집중합니다.
|
|
431
|
+
|
|
342
432
|
## Built-In Sankey Series
|
|
343
433
|
|
|
344
434
|
Sankey는 방향성 비순환 flow에서 단계별 전환량과 이탈량을 비교할 때 사용합니다.
|
|
@@ -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 Tree Chart</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main class="page-shell">
|
|
10
|
+
<section class="intro">
|
|
11
|
+
<p class="eyebrow">StackBlitz starter</p>
|
|
12
|
+
<h1>KChart Tree Chart</h1>
|
|
13
|
+
<p>Visualize strict parent-child hierarchy, inspect descendants, and roam through large organizations.</p>
|
|
14
|
+
</section>
|
|
15
|
+
<section class="chart-panel">
|
|
16
|
+
<div class="metric-strip">
|
|
17
|
+
<span>id / parent / name</span>
|
|
18
|
+
<span>orthogonal layout</span>
|
|
19
|
+
<span>descendant emphasis</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-tree-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 --noEmit --skipLibCheck --target ES2022 --module ESNext --moduleResolution Bundler --lib ES2022,DOM src/main.ts src/vite-env.d.ts && vite build",
|
|
9
|
+
"preview": "vite preview --host 0.0.0.0"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@keneth80/k-chart": "^1.18.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^6.0.3",
|
|
16
|
+
"vite": "^7.2.7"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {createKChart, createTreeSeries} from '@keneth80/k-chart';
|
|
2
|
+
import './style.css';
|
|
3
|
+
|
|
4
|
+
interface OrganizationRow {
|
|
5
|
+
id: string;
|
|
6
|
+
parent: string | null;
|
|
7
|
+
name: string;
|
|
8
|
+
team: string;
|
|
9
|
+
headcount: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const data: OrganizationRow[] = [
|
|
13
|
+
{id: 'ceo', parent: null, name: 'Chief Executive Officer', team: 'Executive', headcount: 1},
|
|
14
|
+
{id: 'product', parent: 'ceo', name: 'VP Product', team: 'Product', headcount: 28},
|
|
15
|
+
{id: 'engineering', parent: 'ceo', name: 'VP Engineering', team: 'Engineering', headcount: 54},
|
|
16
|
+
{id: 'revenue', parent: 'ceo', name: 'VP Revenue', team: 'Revenue', headcount: 35},
|
|
17
|
+
{id: 'design', parent: 'product', name: 'Design', team: 'Product', headcount: 9},
|
|
18
|
+
{id: 'research', parent: 'product', name: 'Research', team: 'Product', headcount: 7},
|
|
19
|
+
{id: 'platform', parent: 'engineering', name: 'Platform', team: 'Engineering', headcount: 18},
|
|
20
|
+
{id: 'frontend', parent: 'engineering', name: 'Frontend', team: 'Engineering', headcount: 16},
|
|
21
|
+
{id: 'data', parent: 'engineering', name: 'Data & AI', team: 'Engineering', headcount: 20},
|
|
22
|
+
{id: 'sales', parent: 'revenue', name: 'Sales', team: 'Revenue', headcount: 22},
|
|
23
|
+
{id: 'success', parent: 'revenue', name: 'Customer Success', team: 'Revenue', headcount: 13}
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const treeSeries = createTreeSeries<OrganizationRow>({
|
|
27
|
+
selector: 'organization-tree',
|
|
28
|
+
displayName: 'Organization',
|
|
29
|
+
idField: 'id',
|
|
30
|
+
parentField: 'parent',
|
|
31
|
+
labelField: 'name',
|
|
32
|
+
valueField: 'headcount',
|
|
33
|
+
categoryField: 'team',
|
|
34
|
+
layout: 'orthogonal',
|
|
35
|
+
orientation: 'left-right',
|
|
36
|
+
emphasis: 'descendant',
|
|
37
|
+
symbol: 'circle',
|
|
38
|
+
symbolSize: (node) => 10 + Math.sqrt(node.value) * 1.5,
|
|
39
|
+
labelPosition: 'right',
|
|
40
|
+
roam: 'both',
|
|
41
|
+
scaleExtent: [0.6, 4],
|
|
42
|
+
fitPadding: 112,
|
|
43
|
+
labels: {
|
|
44
|
+
visible: true,
|
|
45
|
+
formatter: (node) => `${node.label} · ${node.value}`
|
|
46
|
+
},
|
|
47
|
+
onNodeClick: ({node}) => console.info('Selected tree node', node.id, node.row)
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const chart = createKChart<OrganizationRow>({
|
|
51
|
+
selector: '#chart',
|
|
52
|
+
data,
|
|
53
|
+
width: 980,
|
|
54
|
+
height: 600,
|
|
55
|
+
margin: {top: 72, right: 32, bottom: 24, left: 32},
|
|
56
|
+
title: {text: 'Organization hierarchy', align: 'left', fontSize: 18},
|
|
57
|
+
grid: {visible: false},
|
|
58
|
+
legend: {visible: false},
|
|
59
|
+
tooltip: {visible: true},
|
|
60
|
+
axes: [],
|
|
61
|
+
series: [treeSeries]
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
chart.render();
|
|
65
|
+
|
|
66
|
+
window.addEventListener('resize', () => {
|
|
67
|
+
const panel = document.querySelector<HTMLElement>('.chart-panel');
|
|
68
|
+
if (!panel) return;
|
|
69
|
+
chart.resize({width: Math.max(panel.clientWidth - 48, 320), height: 600});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
window.addEventListener('beforeunload', () => chart.destroy());
|
|
@@ -0,0 +1,56 @@
|
|
|
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: #0b1120;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.page-shell {
|
|
18
|
+
width: min(1160px, calc(100vw - 32px));
|
|
19
|
+
margin: 0 auto;
|
|
20
|
+
padding: 40px 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.intro { margin-bottom: 18px; }
|
|
24
|
+
.eyebrow { margin: 0 0 8px; color: #7dd3fc; font-size: 12px; font-weight: 700; text-transform: uppercase; }
|
|
25
|
+
h1 { margin: 0; font-size: 42px; }
|
|
26
|
+
.intro p:last-child { margin: 12px 0 0; color: #b8c5d6; }
|
|
27
|
+
|
|
28
|
+
.chart-panel {
|
|
29
|
+
min-height: 680px;
|
|
30
|
+
padding: 24px;
|
|
31
|
+
border: 1px solid rgba(148, 163, 184, 0.24);
|
|
32
|
+
border-radius: 8px;
|
|
33
|
+
background: #111827;
|
|
34
|
+
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.metric-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
|
|
38
|
+
.metric-strip span {
|
|
39
|
+
padding: 6px 10px;
|
|
40
|
+
border: 1px solid rgba(125, 211, 252, 0.22);
|
|
41
|
+
border-radius: 999px;
|
|
42
|
+
color: #cde9ff;
|
|
43
|
+
background: rgba(14, 165, 233, 0.1);
|
|
44
|
+
font-size: 12px;
|
|
45
|
+
font-weight: 700;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#chart { width: 100%; height: 600px; }
|
|
49
|
+
#chart .kchart-svg text { font-family: inherit; }
|
|
50
|
+
#chart .kchart-title { fill: #f8fafc; }
|
|
51
|
+
|
|
52
|
+
@media (max-width: 720px) {
|
|
53
|
+
.page-shell { width: calc(100vw - 20px); padding: 24px 0; }
|
|
54
|
+
.chart-panel { padding: 12px; }
|
|
55
|
+
h1 { font-size: 32px; }
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -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 Treemap</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main class="page-shell">
|
|
10
|
+
<section class="intro">
|
|
11
|
+
<p class="eyebrow">StackBlitz starter</p>
|
|
12
|
+
<h1>KChart Treemap</h1>
|
|
13
|
+
<p>Compare product revenue at a glance while keeping each product category visually distinct.</p>
|
|
14
|
+
</section>
|
|
15
|
+
<section class="chart-panel">
|
|
16
|
+
<div class="metric-strip">
|
|
17
|
+
<span>area = revenue</span>
|
|
18
|
+
<span>label = product</span>
|
|
19
|
+
<span>color = category</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-treemap-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 --noEmit --ignoreConfig --skipLibCheck --target ES2022 --module ESNext --moduleResolution Bundler --lib ES2022,DOM src/main.ts src/vite-env.d.ts && vite build",
|
|
9
|
+
"preview": "vite preview --host 0.0.0.0"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@keneth80/k-chart": "^1.18.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^6.0.3",
|
|
16
|
+
"vite": "^7.2.7"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {createKChart, createTreemapSeries} from '@keneth80/k-chart';
|
|
2
|
+
import './style.css';
|
|
3
|
+
|
|
4
|
+
interface ProductMetric {
|
|
5
|
+
product: string;
|
|
6
|
+
category: 'Platform' | 'Analytics' | 'Commerce' | 'Services';
|
|
7
|
+
revenue: number;
|
|
8
|
+
color: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const categoryColors: Record<ProductMetric['category'], string> = {
|
|
12
|
+
Platform: '#38bdf8',
|
|
13
|
+
Analytics: '#a78bfa',
|
|
14
|
+
Commerce: '#34d399',
|
|
15
|
+
Services: '#fb7185'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const data: ProductMetric[] = [
|
|
19
|
+
{product: 'Core Platform', category: 'Platform', revenue: 42, color: categoryColors.Platform},
|
|
20
|
+
{product: 'Developer API', category: 'Platform', revenue: 24, color: categoryColors.Platform},
|
|
21
|
+
{product: 'Insights Pro', category: 'Analytics', revenue: 31, color: categoryColors.Analytics},
|
|
22
|
+
{product: 'Forecasting', category: 'Analytics', revenue: 18, color: categoryColors.Analytics},
|
|
23
|
+
{product: 'Checkout', category: 'Commerce', revenue: 27, color: categoryColors.Commerce},
|
|
24
|
+
{product: 'Subscriptions', category: 'Commerce', revenue: 21, color: categoryColors.Commerce},
|
|
25
|
+
{product: 'Implementation', category: 'Services', revenue: 16, color: categoryColors.Services},
|
|
26
|
+
{product: 'Support Plus', category: 'Services', revenue: 11, color: categoryColors.Services}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const treemapSeries = createTreemapSeries<ProductMetric>({
|
|
30
|
+
selector: 'product-revenue',
|
|
31
|
+
displayName: 'Product revenue',
|
|
32
|
+
// Rectangle area maps to this metric, so larger revenue occupies more space.
|
|
33
|
+
valueField: 'revenue',
|
|
34
|
+
// Treemap input stays flat: this dimension supplies the visible product label.
|
|
35
|
+
labelField: 'product',
|
|
36
|
+
colorField: 'color',
|
|
37
|
+
gap: 6,
|
|
38
|
+
radius: 6,
|
|
39
|
+
minLabelArea: 1500,
|
|
40
|
+
opacity: 0.9,
|
|
41
|
+
sort: true
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const chart = createKChart<ProductMetric>({
|
|
45
|
+
selector: '#chart',
|
|
46
|
+
data,
|
|
47
|
+
width: 980,
|
|
48
|
+
height: 560,
|
|
49
|
+
margin: {top: 72, right: 24, bottom: 24, left: 24},
|
|
50
|
+
title: {text: 'Product revenue by category', align: 'left', fontSize: 18},
|
|
51
|
+
grid: {visible: false},
|
|
52
|
+
legend: {visible: false},
|
|
53
|
+
tooltip: {visible: true},
|
|
54
|
+
axes: [],
|
|
55
|
+
series: [treemapSeries]
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
chart.render();
|
|
59
|
+
|
|
60
|
+
window.addEventListener('resize', () => {
|
|
61
|
+
const panel = document.querySelector<HTMLElement>('.chart-panel');
|
|
62
|
+
if (!panel) return;
|
|
63
|
+
chart.resize({width: Math.max(panel.clientWidth - 48, 320), height: 560});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
window.addEventListener('beforeunload', () => chart.destroy());
|
|
@@ -0,0 +1,56 @@
|
|
|
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: #0b1120;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.page-shell {
|
|
18
|
+
width: min(1160px, calc(100vw - 32px));
|
|
19
|
+
margin: 0 auto;
|
|
20
|
+
padding: 40px 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.intro { margin-bottom: 18px; }
|
|
24
|
+
.eyebrow { margin: 0 0 8px; color: #7dd3fc; font-size: 12px; font-weight: 700; text-transform: uppercase; }
|
|
25
|
+
h1 { margin: 0; font-size: 42px; }
|
|
26
|
+
.intro p:last-child { margin: 12px 0 0; color: #b8c5d6; }
|
|
27
|
+
|
|
28
|
+
.chart-panel {
|
|
29
|
+
min-height: 640px;
|
|
30
|
+
padding: 24px;
|
|
31
|
+
border: 1px solid rgba(148, 163, 184, 0.24);
|
|
32
|
+
border-radius: 8px;
|
|
33
|
+
background: #111827;
|
|
34
|
+
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.metric-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
|
|
38
|
+
.metric-strip span {
|
|
39
|
+
padding: 6px 10px;
|
|
40
|
+
border: 1px solid rgba(125, 211, 252, 0.22);
|
|
41
|
+
border-radius: 999px;
|
|
42
|
+
color: #cde9ff;
|
|
43
|
+
background: rgba(14, 165, 233, 0.1);
|
|
44
|
+
font-size: 12px;
|
|
45
|
+
font-weight: 700;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#chart { width: 100%; height: 560px; }
|
|
49
|
+
#chart .kchart-svg text { font-family: inherit; }
|
|
50
|
+
#chart .kchart-title { fill: #f8fafc; }
|
|
51
|
+
|
|
52
|
+
@media (max-width: 720px) {
|
|
53
|
+
.page-shell { width: calc(100vw - 20px); padding: 24px 0; }
|
|
54
|
+
.chart-panel { padding: 12px; }
|
|
55
|
+
h1 { font-size: 32px; }
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/lib/core/contracts.d.ts
CHANGED
|
@@ -371,6 +371,73 @@ export interface KChartGraphSeriesConfiguration<T = any> {
|
|
|
371
371
|
dimOpacity?: number;
|
|
372
372
|
onNodeClick?: (context: KChartGraphNodeInteractionContext<T>) => void;
|
|
373
373
|
}
|
|
374
|
+
export type KChartTreeLayout = 'orthogonal' | 'radial';
|
|
375
|
+
export type KChartTreeOrientation = 'left-right' | 'right-left' | 'top-bottom' | 'bottom-top';
|
|
376
|
+
export type KChartTreeEmphasis = 'ancestor' | 'descendant' | 'both' | 'none';
|
|
377
|
+
export type KChartTreeSymbol = 'circle' | 'square' | 'diamond';
|
|
378
|
+
export type KChartTreeLabelPosition = 'auto' | 'left' | 'right' | 'top' | 'bottom';
|
|
379
|
+
export interface KChartTreeNode<T = any> {
|
|
380
|
+
id: string;
|
|
381
|
+
parentId?: string;
|
|
382
|
+
label: string;
|
|
383
|
+
value: number;
|
|
384
|
+
category?: string;
|
|
385
|
+
row: T;
|
|
386
|
+
parent?: KChartTreeNode<T>;
|
|
387
|
+
children: Array<KChartTreeNode<T>>;
|
|
388
|
+
depth: number;
|
|
389
|
+
height: number;
|
|
390
|
+
x: number;
|
|
391
|
+
y: number;
|
|
392
|
+
}
|
|
393
|
+
export interface KChartTreeLink<T = any> {
|
|
394
|
+
id: string;
|
|
395
|
+
source: KChartTreeNode<T>;
|
|
396
|
+
target: KChartTreeNode<T>;
|
|
397
|
+
value: number;
|
|
398
|
+
row: T;
|
|
399
|
+
}
|
|
400
|
+
export interface KChartTreeNodeClickContext<T = any> {
|
|
401
|
+
node: KChartTreeNode<T>;
|
|
402
|
+
event: MouseEvent;
|
|
403
|
+
}
|
|
404
|
+
export interface KChartTreeSeriesConfiguration<T = any> {
|
|
405
|
+
selector: string;
|
|
406
|
+
displayName?: string;
|
|
407
|
+
idField: keyof T & string;
|
|
408
|
+
parentField: keyof T & string;
|
|
409
|
+
labelField?: keyof T & string;
|
|
410
|
+
valueField?: keyof T & string;
|
|
411
|
+
categoryField?: keyof T & string;
|
|
412
|
+
layout?: KChartTreeLayout;
|
|
413
|
+
orientation?: KChartTreeOrientation;
|
|
414
|
+
emphasis?: KChartTreeEmphasis;
|
|
415
|
+
symbol?: KChartTreeSymbol;
|
|
416
|
+
symbolSize?: number | ((node: KChartTreeNode<T>) => number);
|
|
417
|
+
labelPosition?: KChartTreeLabelPosition;
|
|
418
|
+
roam?: KChartGraphRoamMode;
|
|
419
|
+
scaleExtent?: [number, number];
|
|
420
|
+
fitPadding?: number;
|
|
421
|
+
color?: string;
|
|
422
|
+
palette?: string[];
|
|
423
|
+
nodeColor?: string | ((node: KChartTreeNode<T>, index: number) => string);
|
|
424
|
+
nodeOpacity?: number;
|
|
425
|
+
nodeStroke?: string;
|
|
426
|
+
nodeStrokeWidth?: number;
|
|
427
|
+
edgeColor?: string | ((link: KChartTreeLink<T>, index: number) => string);
|
|
428
|
+
edgeOpacity?: number;
|
|
429
|
+
edgeStrokeWidth?: number | ((link: KChartTreeLink<T>, index: number) => number);
|
|
430
|
+
dimOpacity?: number;
|
|
431
|
+
labels?: boolean | {
|
|
432
|
+
visible?: boolean;
|
|
433
|
+
formatter?: (node: KChartTreeNode<T>) => string;
|
|
434
|
+
color?: string;
|
|
435
|
+
fontSize?: number;
|
|
436
|
+
fontWeight?: number | string;
|
|
437
|
+
offset?: number;
|
|
438
|
+
};
|
|
439
|
+
onNodeClick?: (context: KChartTreeNodeClickContext<T>) => void;
|
|
440
|
+
}
|
|
374
441
|
export type KChartSankeyNodeAlign = 'left' | 'right' | 'center' | 'justify';
|
|
375
442
|
export interface KChartSankeyNode<T = any> {
|
|
376
443
|
id: string;
|