@keneth80/k-chart 1.17.1 → 1.18.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +6 -0
  3. package/docs/configuration-reference.md +64 -2
  4. package/docs/functional-api.md +103 -0
  5. package/examples/stackblitz-tree-basic/index.html +26 -0
  6. package/examples/stackblitz-tree-basic/package.json +18 -0
  7. package/examples/stackblitz-tree-basic/src/main.ts +72 -0
  8. package/examples/stackblitz-tree-basic/src/style.css +56 -0
  9. package/examples/stackblitz-tree-basic/src/vite-env.d.ts +1 -0
  10. package/examples/stackblitz-treemap-basic/index.html +26 -0
  11. package/examples/stackblitz-treemap-basic/package.json +18 -0
  12. package/examples/stackblitz-treemap-basic/src/main.ts +66 -0
  13. package/examples/stackblitz-treemap-basic/src/style.css +56 -0
  14. package/examples/stackblitz-treemap-basic/src/vite-env.d.ts +1 -0
  15. package/lib/core/contracts.d.ts +67 -0
  16. package/lib/core/contracts.d.ts.map +1 -1
  17. package/lib/core/create-kchart.d.ts.map +1 -1
  18. package/lib/core/create-kchart.js +2 -3
  19. package/lib/core/create-kchart.js.map +1 -1
  20. package/lib/core/ticks.d.ts +14 -0
  21. package/lib/core/ticks.d.ts.map +1 -0
  22. package/lib/core/ticks.js +43 -0
  23. package/lib/core/ticks.js.map +1 -0
  24. package/lib/series/index.d.ts +1 -0
  25. package/lib/series/index.d.ts.map +1 -1
  26. package/lib/series/index.js +1 -0
  27. package/lib/series/index.js.map +1 -1
  28. package/lib/series/svg-dashboard.d.ts.map +1 -1
  29. package/lib/series/svg-dashboard.js +6 -0
  30. package/lib/series/svg-dashboard.js.map +1 -1
  31. package/lib/series/svg-tree.d.ts +11 -0
  32. package/lib/series/svg-tree.d.ts.map +1 -0
  33. package/lib/series/svg-tree.js +654 -0
  34. package/lib/series/svg-tree.js.map +1 -0
  35. package/package.json +4 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.18.1 - 2026-07-14
4
+
5
+ ### Changed
6
+
7
+ - Improved categorical (`point`/`string`) axis `tickCount` to evenly sample displayed ticks while preserving the first and last domain values without changing the scale domain or data positions. Omitting `tickCount` or setting it to at least the domain length displays every tick; `number`/`time` axes retain the existing D3 tick hint behavior.
8
+
9
+ ## 1.18.0 - 2026-07-12
10
+
11
+ ### Added
12
+
13
+ - 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.
14
+ - Added the Tree Chart library demo, StackBlitz starter, API reference, and hierarchy validation regression tests.
15
+ - Added a Preset-inspired Treemap library demo, StackBlitz starter, Usage snippet, and API guidance for Dimension + Metric part-to-whole analysis.
16
+
17
+ ### Packages
18
+
19
+ - Published `@keneth80/k-chart@1.18.0`.
20
+
3
21
  ## 1.17.1 - 2026-07-11
4
22
 
5
23
  ### Changed
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
@@ -58,9 +58,11 @@ createKChart({
58
58
  | `visible` | `boolean` | no | `false`이면 axis를 숨깁니다. scale 자체는 여전히 series 계산에 사용할 수 있습니다. |
59
59
  | `padding` | `number` | no | number/time domain 양끝에 비율 padding을 추가합니다. `min`, `max`가 없을 때만 적용됩니다. |
60
60
  | `title` | `string` | no | axis title입니다. |
61
- | `tickCount` | `number` | no | tick 개수 힌트입니다. |
61
+ | `tickCount` | `number` | no | `number`/`time` 축에서는 기존 D3 tick 개수 힌트입니다. `point`/`string` 축에서는 표시할 tick을 domain 전체에서 균등하게 샘플링하며 첫 값과 마지막 값을 보존합니다. |
62
62
  | `tickFormat` | `(value: any) => string` | no | tick label formatter입니다. |
63
63
 
64
+ `point`/`string` 축의 `tickCount`는 표시 tick만 줄입니다. scale domain과 데이터 위치는 전체 domain을 기준으로 그대로 유지됩니다. `tickCount`를 지정하지 않거나 domain 길이 이상으로 지정하면 모든 tick을 표시합니다. 여러 category가 있을 때 `tickCount`가 `1`이면 범위의 양 끝을 전달하기 위해 첫 값과 마지막 값, 총 2개를 표시합니다. `number`/`time` 축에서는 계속 D3에 tick 개수 힌트로 전달되므로 실제 tick 개수는 달라질 수 있습니다.
65
+
64
66
  ## Title, Grid, Legend, Tooltip
65
67
 
66
68
  ### `title`
@@ -282,6 +284,51 @@ createGraphSeries<Relation>({
282
284
 
283
285
  Graph가 직접 node hover/click 및 roaming을 처리해야 하는 화면에서는 chart-level `tooltip`과 `zoom`을 끄는 구성을 권장합니다. 코어 tooltip overlay가 필요한 경우 Graph의 `tooltip()` hit-test도 동작하지만, overlay가 SVG node의 직접 pointer event보다 위에 놓일 수 있습니다.
284
286
 
287
+ ### SVG Tree: `createTreeSeries`
288
+
289
+ 각 행의 `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)을 사용합니다.
290
+
291
+ | Field | Type | Default | Description |
292
+ | --- | --- | --- | --- |
293
+ | `selector` | `string` | required | series id/class입니다. |
294
+ | `idField` / `parentField` | `keyof T & string` | required | node id와 부모 id field입니다. 루트의 부모 값은 `null`, `undefined`, 빈 문자열 중 하나로 둡니다. |
295
+ | `labelField` | `keyof T & string` | id | 표시할 node 이름 field입니다. |
296
+ | `valueField` | `keyof T & string` | `0` | tooltip과 node 크기 함수에서 사용할 수치 field입니다. |
297
+ | `categoryField` | `keyof T & string` | - | 기본 palette 색상을 나눌 category field입니다. |
298
+ | `layout` | `orthogonal \| radial` | `orthogonal` | 직교 트리 또는 방사형 트리 배치입니다. |
299
+ | `orientation` | `left-right \| right-left \| top-bottom \| bottom-top` | `left-right` | 직교 트리의 진행 방향입니다. |
300
+ | `emphasis` | `ancestor \| descendant \| both \| none` | `both` | hover node와 함께 강조할 연결 범위입니다. |
301
+ | `symbol` | `circle \| square \| diamond` | `circle` | node 모양입니다. |
302
+ | `symbolSize` | `number \| (node) => number` | `13` | node 크기 또는 값 기반 크기 함수입니다. |
303
+ | `labelPosition` | `auto \| left \| right \| top \| bottom` | `auto` | node label 위치입니다. |
304
+ | `roam` | `move \| scale \| both \| disabled` | `both` | drag 이동과 wheel/touch 확대 사용 범위입니다. |
305
+ | `scaleExtent` | `[number, number]` | `[0.45, 5]` | tree 자체 zoom 배율 범위입니다. |
306
+ | `fitPadding` | `number` | `28` | layout과 plot 경계 사이 여백입니다. |
307
+ | `palette` / `nodeColor` | colors / color resolver | built-in palette | category 또는 node별 색상을 설정합니다. |
308
+ | `nodeOpacity`, `nodeStroke`, `nodeStrokeWidth` | number/string | metallic theme values | node fill/stroke 스타일입니다. |
309
+ | `edgeColor`, `edgeOpacity`, `edgeStrokeWidth` | value or resolver | metallic theme values | parent-child link 스타일입니다. |
310
+ | `dimOpacity` | `number` | `0.12` | hover 연결 범위 밖 node/link의 투명도입니다. |
311
+ | `labels` | `boolean \| object` | visible | formatter, 색상, 크기, 굵기, offset을 설정합니다. |
312
+ | `onNodeClick` | `(context) => void` | - | 클릭 node와 원본 event를 받습니다. |
313
+
314
+ ```ts
315
+ createTreeSeries<OrganizationRow>({
316
+ selector: 'organization-tree',
317
+ idField: 'id',
318
+ parentField: 'parentId',
319
+ labelField: 'name',
320
+ valueField: 'headcount',
321
+ categoryField: 'team',
322
+ layout: 'orthogonal',
323
+ orientation: 'left-right',
324
+ emphasis: 'descendant',
325
+ symbolSize: (node) => 10 + Math.sqrt(node.value),
326
+ roam: 'both'
327
+ });
328
+ ```
329
+
330
+ Tree가 pointer hover와 roaming을 직접 처리하므로 chart-level `zoom`은 끄는 구성을 권장합니다. chart-level tooltip은 node와 link를 hit-test하며, `onNodeClick`은 업무 화면의 상세 패널 연결에 사용할 수 있습니다.
331
+
285
332
  ### SVG Sankey: `createSankeySeries`
286
333
 
287
334
  Sankey 역시 source-target-metric 행을 직접 받지만, 관계 탐색보다 왼쪽에서 오른쪽으로 진행되는 단계별 흐름과 상대적인 flow 폭을 강조합니다. 동일 source-target 행은 합산합니다. Sankey는 방향성 비순환 그래프(DAG)를 전제로 하며 순환이 발견되면 명확한 오류를 발생시킵니다.
@@ -348,6 +395,8 @@ createSankeySeries<FlowRow>({
348
395
 
349
396
  ### SVG Treemap: `createTreemapSeries`
350
397
 
398
+ 각 data row를 하나의 Dimension 항목으로 보고, `valueField` Metric의 비중을 tile 면적으로 표현합니다. 이 입력 방식은 [Preset Tree Map](https://docs.preset.io/docs/tree-map)의 기본 Dimension + Metric 모델과 같습니다.
399
+
351
400
  | Field | Type | Default | Description |
352
401
  | --- | --- | --- | --- |
353
402
  | `selector` | `string` | required | series id/class입니다. |
@@ -360,7 +409,20 @@ createSankeySeries<FlowRow>({
360
409
  | `minLabelArea` | `number` | `1800` | label을 표시할 최소 tile 면적입니다. |
361
410
  | `sort` | `boolean` | `true` | value 내림차순으로 layout할지 정합니다. |
362
411
 
363
- 현재 treemap은 추가 dependency 없이 recursive slice layout을 사용합니다. 많은 계층 구조나 squarified layout이 필요하면 custom series로 확장하거나 향후 전용 hierarchy 옵션을 추가할 수 있습니다.
412
+ 현재 Treemap은 추가 dependency 없이 recursive slice layout을 사용하며 단일 Dimension을 평면 분할합니다. Preset의 여러 Dimension처럼 부모-자식 구조 자체를 탐색해야 할 때는 `createTreeSeries()`를 사용하고, 계층형 면적 분할이 필요하면 custom series로 확장할 수 있습니다.
413
+
414
+ ```ts
415
+ createTreemapSeries<ProductShare>({
416
+ selector: 'product-share',
417
+ labelField: 'product',
418
+ valueField: 'revenue',
419
+ colorField: 'color',
420
+ gap: 5,
421
+ radius: 4,
422
+ minLabelArea: 1600,
423
+ sort: true
424
+ });
425
+ ```
364
426
 
365
427
  ### SVG Gauge / KPI Meter: `createGaugeSeries`
366
428
 
@@ -129,6 +129,19 @@ const chart = chartConfig(data)
129
129
 
130
130
  Builder는 `series(...)`와 `option(...)`도 제공하므로, 초보자용 흐름에서 시작해 기존 `createLineSeries(...)`, `createSpecAreaOption(...)` 같은 고급 함수와 섞어 사용할 수 있습니다.
131
131
 
132
+ ## Axis Tick Density
133
+
134
+ `point`와 `string` 축에서 `tickCount`를 지정하면 전체 domain 중 표시할 tick을 균등하게 샘플링하고 첫 값과 마지막 값을 보존합니다. 이 설정은 axis에 표시되는 tick만 제한하며 scale domain이나 series의 데이터 위치를 변경하지 않습니다.
135
+
136
+ ```ts
137
+ axes: [
138
+ {field: 'month', type: 'point', placement: 'bottom', tickCount: 4},
139
+ {field: 'revenue', type: 'number', placement: 'left', tickCount: 5}
140
+ ]
141
+ ```
142
+
143
+ `tickCount`를 생략하거나 domain 길이 이상으로 지정한 `point`/`string` 축은 모든 tick을 표시합니다. 여러 category가 있는 축에서 `tickCount: 1`은 첫 값과 마지막 값을 보존하기 위해 2개 라벨로 처리됩니다. `number`와 `time` 축의 `tickCount`는 기존처럼 D3 tick 생성에 전달되는 개수 힌트이며 실제 표시 개수와 정확히 일치하지 않을 수 있습니다.
144
+
132
145
  ## Built-In BI / Distribution Series
133
146
 
134
147
  대시보드에서 자주 필요한 분포, 구성, KPI, 누적 흐름 차트도 class-free factory로 사용할 수 있습니다.
@@ -339,6 +352,96 @@ chart.render();
339
352
 
340
353
  `layout: 'circular'`로 바꾸면 같은 데이터를 원형 배치로 비교할 수 있습니다. 중복 source-target 행은 하나의 edge로 합산되고, node metric은 연결된 edge metric의 합입니다.
341
354
 
355
+ ## Built-In Tree Series
356
+
357
+ 조직도나 분류 체계처럼 부모가 하나인 계층 데이터는 별도 nested object 변환 없이 id-parent 행 배열을 전달할 수 있습니다.
358
+
359
+ ```ts
360
+ type OrganizationRow = {
361
+ id: string;
362
+ parentId: string | null;
363
+ name: string;
364
+ team: string;
365
+ headcount: number;
366
+ };
367
+
368
+ const organization: OrganizationRow[] = [
369
+ {id: 'company', parentId: null, name: 'KChart', team: 'Company', headcount: 42},
370
+ {id: 'product', parentId: 'company', name: 'Product', team: 'Product', headcount: 14},
371
+ {id: 'engineering', parentId: 'company', name: 'Engineering', team: 'Engineering', headcount: 24},
372
+ {id: 'platform', parentId: 'engineering', name: 'Platform', team: 'Engineering', headcount: 8}
373
+ ];
374
+
375
+ createKChart<OrganizationRow>({
376
+ selector: '#chart',
377
+ data: organization,
378
+ axes: [],
379
+ grid: {visible: false},
380
+ legend: {visible: false},
381
+ tooltip: {visible: true},
382
+ zoom: {visible: false},
383
+ series: [
384
+ createTreeSeries({
385
+ selector: 'organization-tree',
386
+ idField: 'id',
387
+ parentField: 'parentId',
388
+ labelField: 'name',
389
+ valueField: 'headcount',
390
+ categoryField: 'team',
391
+ layout: 'orthogonal',
392
+ orientation: 'left-right',
393
+ emphasis: 'descendant',
394
+ roam: 'both'
395
+ })
396
+ ]
397
+ }).render();
398
+ ```
399
+
400
+ `layout: 'radial'`은 같은 데이터를 중심에서 바깥으로 펼칩니다. 루트는 하나만 허용하며 모든 non-root node는 존재하는 부모를 가리켜야 합니다. 입력 오류는 렌더 전에 명확한 예외로 반환됩니다.
401
+
402
+ ## Built-In Treemap Series
403
+
404
+ Treemap은 동일 metric을 여러 Dimension 항목으로 나누고, 전체에서 차지하는 비중을 tile 면적으로 비교할 때 사용합니다.
405
+
406
+ ```ts
407
+ type ProductShare = {
408
+ product: string;
409
+ revenue: number;
410
+ color: string;
411
+ };
412
+
413
+ const products: ProductShare[] = [
414
+ {product: 'Analytics Cloud', revenue: 420, color: '#5db8ff'},
415
+ {product: 'Commerce API', revenue: 310, color: '#56d08f'},
416
+ {product: 'Data Platform', revenue: 245, color: '#f3b45b'},
417
+ {product: 'Automation', revenue: 165, color: '#d876ff'}
418
+ ];
419
+
420
+ createKChart<ProductShare>({
421
+ selector: '#chart',
422
+ data: products,
423
+ axes: [],
424
+ grid: {visible: false},
425
+ legend: {visible: false},
426
+ tooltip: {visible: true},
427
+ animation: {enabled: true, duration: 720, mode: 'enter'},
428
+ series: [
429
+ createTreemapSeries({
430
+ selector: 'product-share',
431
+ labelField: 'product',
432
+ valueField: 'revenue',
433
+ colorField: 'color',
434
+ gap: 5,
435
+ radius: 4,
436
+ minLabelArea: 1600,
437
+ sort: true
438
+ })
439
+ ]
440
+ }).render();
441
+ ```
442
+
443
+ `valueField`는 0보다 큰 숫자를 사용해야 하며 면적은 전체 양수 metric 합에 대한 상대 비율입니다. 현재 API는 단일 Dimension 항목 비교에 집중합니다.
444
+
342
445
  ## Built-In Sankey Series
343
446
 
344
447
  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" />