@keneth80/k-chart 1.24.1 → 1.25.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.25.0 - 2026-08-27
4
+
5
+ ### Added
6
+
7
+ - Added configurable pie and doughnut `sliceLabel` formatters with access to
8
+ the original datum, value, total, percentage, index, and segment color.
9
+ - Added outside slice labels with leader lines, minimum-percentage and
10
+ maximum-count filtering, multi-line output, collision spacing, and plot-bound
11
+ clamping.
12
+ - Added continuous value coloring and a fixed color legend for SVG region maps,
13
+ including configurable domains, palettes, labels, placement, and styling.
14
+ - Added StackBlitz-ready world activity map and scrollable doughnut legend
15
+ examples.
16
+
17
+ ### Changed
18
+
19
+ - Documented how to combine formatted outside doughnut labels with a separately
20
+ scrollable detail legend for dense category sets.
21
+
22
+ ### Tests
23
+
24
+ - Added regression coverage for region-map color domains and legends, pie label
25
+ formatter contexts, filtering, collision layout, leader lines, and legacy
26
+ label visibility.
27
+
3
28
  ## 1.24.1 - 2026-08-26
4
29
 
5
30
  ### Changed
package/README.md CHANGED
@@ -66,6 +66,8 @@
66
66
  ·
67
67
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-world-country-map-basic?title=KChart%20World%20Country%20Map&file=src/main.ts"><strong>World Map</strong></a>
68
68
  ·
69
+ <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-world-activity-map?title=KChart%20World%20Activity%20Map&file=src/main.ts"><strong>World Activity Map</strong></a>
70
+ ·
69
71
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-column-basic?title=KChart%20Column&file=src/main.ts"><strong>Column</strong></a>
70
72
  ·
71
73
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-stacked-column-basic?title=KChart%20Stacked%20Column&file=src/main.ts"><strong>Stacked Column</strong></a>
@@ -80,6 +82,8 @@
80
82
  ·
81
83
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-doughnut-basic?title=KChart%20Doughnut&file=src/main.ts"><strong>Doughnut</strong></a>
82
84
  ·
85
+ <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-doughnut-scroll-legend?title=KChart%20Scrollable%20Doughnut%20Legend&file=src/main.ts"><strong>Scrollable Doughnut Legend</strong></a>
86
+ ·
83
87
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-multi-series-basic?title=KChart%20Multi%20Series&file=src/main.ts"><strong>Multi Series</strong></a>
84
88
  ·
85
89
  <a href="https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-options-basic?title=KChart%20Options&file=src/main.ts"><strong>Options</strong></a>
@@ -904,6 +904,24 @@ createWorldCountryMapSeries<Country>({
904
904
  });
905
905
  ```
906
906
 
907
+ `colorLegend`를 사용하면 `valueField`의 숫자 값을 연속 색상으로 변환하고, 지도 확대와 무관하게 고정되는 범례를 함께 표시할 수 있습니다. `colorField` 또는 `fill`을 명시하면 기존 사용자 지정 색상이 우선합니다. `domain`을 생략하면 현재 데이터의 최솟값과 최댓값을 사용합니다.
908
+
909
+ ```ts
910
+ createWorldCountryMapSeries<Country>({
911
+ selector: 'world-activity',
912
+ dataKey: 'name',
913
+ valueField: 'activity',
914
+ colorLegend: {
915
+ visible: true,
916
+ title: '국가별 활동 지수',
917
+ position: 'bottom-left',
918
+ domain: [0, 100],
919
+ colors: ['#274c77', '#2a9d8f', '#e9c46a', '#e76f51'],
920
+ labels: ['낮음', '보통', '높음', '매우 높음']
921
+ }
922
+ });
923
+ ```
924
+
907
925
  지도 위에 좌표 기반 강조 요소가 필요하면 `bubbles`와 `markers`를 함께 사용할 수 있습니다. 둘 다 일반적인 위도/경도 값을 사용하며 내부에서 `projection([lon, lat])`로 화면 좌표를 계산합니다. `bubbles`는 지도 위 원형 분포/규모 표현에 적합하고, `markers`는 사진 썸네일, 라벨, 핀 형태의 지점 표시를 제공합니다. `imageUrl`에는 일반 이미지 URL이나 `data:image/...` URI를 넣을 수 있습니다. 마커별 `onClick`을 지정하면 원본 marker, 화면 좌표, mouse event를 받아 팝업이나 상세 이동을 연결할 수 있습니다.
908
926
 
909
927
  ```ts
@@ -944,6 +962,7 @@ createWorldCountryMapSeries<Country>({
944
962
 
945
963
  - [Korea Region Map StackBlitz](https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-korea-region-map-basic?title=KChart%20Korea%20Region%20Map&file=src/main.ts)
946
964
  - [World Country Map StackBlitz](https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-world-country-map-basic?title=KChart%20World%20Country%20Map&file=src/main.ts)
965
+ - [World Activity Map StackBlitz](https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-world-activity-map?title=KChart%20World%20Activity%20Map&file=src/main.ts)
947
966
  - [World Photo Marker Map StackBlitz](https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-world-photo-marker-map?title=KChart%20World%20Photo%20Marker%20Map&file=src/main.ts)
948
967
 
949
968
  ## Display Options
@@ -970,6 +989,33 @@ createKChart({
970
989
 
971
990
  The default tooltip shows the active series name and nearest x/y values. Provide `tooltip.formatter` for custom HTML/text.
972
991
 
992
+ Pie and doughnut presets accept `sliceLabel` when labels need domain-specific text or an outside layout. The formatter receives the original datum together with the computed label, value, total, percentage, index, and segment color. Returning an array renders a multi-line SVG label.
993
+
994
+ ```ts
995
+ createDoughnutChart({
996
+ selector: '#chart',
997
+ data: services,
998
+ label: 'label',
999
+ value: 'value',
1000
+ innerRadiusRatio: 0.58,
1001
+ sliceLabel: {
1002
+ position: 'outside',
1003
+ formatter: ({data, percentage}) =>
1004
+ `${data.category} · ${percentage.toFixed(1)}%`,
1005
+ leaderLine: {visible: true, length: 16},
1006
+ minPercentage: 2.2,
1007
+ maxVisible: 12,
1008
+ collision: {minGap: 22, padding: 8}
1009
+ }
1010
+ });
1011
+ ```
1012
+
1013
+ `minPercentage` and `maxVisible` keep dense outside labels readable; filtered slices remain in the chart and tooltip. Keep every category in the scrollable detail legend described below.
1014
+
1015
+ When one custom series has many internal categories, such as doughnut segments, keep its detailed legend separate from KChart's series legend. Set `legend.visible: false`, reserve chart margin for an HTML legend, and apply `overflow-y: auto` to a fixed-height list. The list can then scroll without moving or resizing the SVG plot; on narrow screens, place the same list below the chart.
1016
+
1017
+ Full example: [Scrollable Doughnut Legend StackBlitz](https://stackblitz.com/fork/github/keneth80/k-chart/tree/main/examples/stackblitz-doughnut-scroll-legend?title=KChart%20Scrollable%20Doughnut%20Legend&file=src/main.ts)
1018
+
973
1019
  ### Pinned Tooltip Notes
974
1020
 
975
1021
  Tooltip notes are opt-in. `createTooltipNoteOption()` adds a pin action to the normal hover tooltip and renders each pinned snapshot as an editable annotation card over the chart. Drag a card header to move it without changing the original data coordinates. Pinned cards do not replace or block later hover tooltips.
@@ -0,0 +1,46 @@
1
+ <!doctype html>
2
+ <html lang="ko">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <meta
7
+ name="description"
8
+ content="KChart custom SVG doughnut chart with formatted outside labels and a scrollable HTML legend."
9
+ />
10
+ <title>KChart Scrollable Doughnut Legend</title>
11
+ </head>
12
+ <body>
13
+ <main class="page-shell">
14
+ <header class="page-header">
15
+ <p class="eyebrow">KChart · Custom SVG</p>
16
+ <h1>서비스 운영 현황</h1>
17
+ <p>함수로 조합한 외곽 라벨과 독립적인 스크롤 범례로 많은 카테고리를 탐색합니다.</p>
18
+ </header>
19
+
20
+ <section class="dashboard-card" aria-label="서비스 워크로드 구성 차트">
21
+ <div class="chart-region">
22
+ <div id="chart"></div>
23
+ </div>
24
+
25
+ <aside class="legend-panel" aria-labelledby="legend-title">
26
+ <header class="legend-header">
27
+ <div>
28
+ <p class="legend-kicker">최근 24시간</p>
29
+ <h2 id="legend-title">서비스별 활성 세션</h2>
30
+ </div>
31
+ <span class="legend-count" id="legend-count"></span>
32
+ </header>
33
+ <div class="legend-scroll" tabindex="0" aria-label="서비스 범례 스크롤 영역">
34
+ <ul id="legend-list" class="legend-list"></ul>
35
+ </div>
36
+ <footer class="legend-footer">
37
+ <span>단위</span>
38
+ <strong>세션</strong>
39
+ </footer>
40
+ </aside>
41
+ </section>
42
+ </main>
43
+
44
+ <script type="module" src="/src/main.ts"></script>
45
+ </body>
46
+ </html>
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "kchart-doughnut-scroll-legend",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite --host 0.0.0.0",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview --host 0.0.0.0"
10
+ },
11
+ "dependencies": {
12
+ "@keneth80/k-chart": "^1.25.0"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^6.0.3",
16
+ "vite": "^7.2.7"
17
+ }
18
+ }
@@ -0,0 +1,96 @@
1
+ import {createDoughnutChart} from '@keneth80/k-chart/presets';
2
+ import './style.css';
3
+
4
+ interface ServicePoint {
5
+ id: string;
6
+ label: string;
7
+ value: number;
8
+ color: string;
9
+ }
10
+
11
+ const services: ServicePoint[] = [
12
+ {id: 'monitoring', label: '실시간 모니터링', value: 68420, color: '#22d3ee'},
13
+ {id: 'pipeline', label: '데이터 파이프라인', value: 57180, color: '#38bdf8'},
14
+ {id: 'gateway', label: 'API 게이트웨이', value: 49360, color: '#60a5fa'},
15
+ {id: 'analytics', label: '사용자 분석', value: 42640, color: '#818cf8'},
16
+ {id: 'automation', label: '알림 자동화', value: 37120, color: '#a78bfa'},
17
+ {id: 'search', label: '검색 인덱스', value: 32980, color: '#c084fc'},
18
+ {id: 'storage', label: '파일 스토리지', value: 28410, color: '#e879f9'},
19
+ {id: 'workspace', label: '협업 워크스페이스', value: 24680, color: '#f472b6'},
20
+ {id: 'payments', label: '결제 처리', value: 21340, color: '#fb7185'},
21
+ {id: 'reports', label: '보고서 빌더', value: 18720, color: '#fb923c'},
22
+ {id: 'access', label: '접근 제어', value: 16290, color: '#fbbf24'},
23
+ {id: 'archive', label: '백업 아카이브', value: 13980, color: '#a3e635'},
24
+ {id: 'inference', label: '머신러닝 추론', value: 11860, color: '#4ade80'},
25
+ {id: 'events', label: '이벤트 스트림', value: 9720, color: '#2dd4bf'},
26
+ {id: 'audit', label: '감사 로그', value: 7640, color: '#14b8a6'},
27
+ {id: 'utilities', label: '기타 운영 도구', value: 5260, color: '#94a3b8'}
28
+ ];
29
+
30
+ const numberFormatter = new Intl.NumberFormat('ko-KR');
31
+ const total = services.reduce((sum, service) => sum + service.value, 0);
32
+ const legendList = document.querySelector<HTMLUListElement>('#legend-list');
33
+ const legendCount = document.querySelector<HTMLElement>('#legend-count');
34
+ const chartHost = document.querySelector<HTMLElement>('#chart');
35
+
36
+ if (!legendList || !legendCount || !chartHost) {
37
+ throw new Error('The chart example container is missing.');
38
+ }
39
+
40
+ legendCount.textContent = `${services.length}개`;
41
+ legendList.replaceChildren(...services.map((service) => {
42
+ const share = service.value / total * 100;
43
+ const item = document.createElement('li');
44
+ item.className = 'legend-item';
45
+ item.innerHTML = `
46
+ <span class="legend-swatch" style="--series-color:${service.color}"></span>
47
+ <span class="legend-name">${service.label}</span>
48
+ <span class="legend-metric">
49
+ <strong>${numberFormatter.format(service.value)}</strong>
50
+ <small>${share.toFixed(1)}%</small>
51
+ </span>
52
+ `;
53
+ return item;
54
+ }));
55
+
56
+ const resolveChartHeight = (): number => window.innerWidth <= 720 ? 390 : 520;
57
+ const resolveChartWidth = (): number => Math.max(chartHost.clientWidth, 320);
58
+
59
+ // The preset owns the doughnut geometry, hit testing, tooltip, leader lines,
60
+ // and collision layout. The adjacent HTML legend only handles dense browsing.
61
+ const chart = createDoughnutChart<ServicePoint>({
62
+ selector: '#chart',
63
+ data: services,
64
+ width: resolveChartWidth(),
65
+ height: resolveChartHeight(),
66
+ margin: {top: 86, right: 18, bottom: 18, left: 18},
67
+ title: {text: '서비스 워크로드 구성', align: 'center', fontSize: 19},
68
+ grid: false,
69
+ legend: false,
70
+ tooltip: true,
71
+ label: 'label',
72
+ value: 'value',
73
+ displayName: '활성 세션',
74
+ innerRadiusRatio: 0.62,
75
+ palette: services.map((service) => service.color),
76
+ sliceLabel: {
77
+ position: 'outside',
78
+ formatter: ({data, percentage}) => `${data.label} · ${percentage.toFixed(1)}%`,
79
+ leaderLine: {visible: true, length: 18, width: 1.2},
80
+ minPercentage: 2.2,
81
+ maxVisible: 12,
82
+ collision: {minGap: 10, padding: 8}
83
+ }
84
+ });
85
+
86
+ let resizeFrame = 0;
87
+ const resizeChart = () => {
88
+ cancelAnimationFrame(resizeFrame);
89
+ resizeFrame = requestAnimationFrame(() => {
90
+ chart.resize({width: resolveChartWidth(), height: resolveChartHeight()});
91
+ });
92
+ };
93
+
94
+ const resizeObserver = new ResizeObserver(resizeChart);
95
+ resizeObserver.observe(chartHost);
96
+ window.addEventListener('resize', resizeChart);
@@ -0,0 +1,267 @@
1
+ :root {
2
+ color-scheme: dark;
3
+ font-family: Inter, Pretendard, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
4
+ background: #080d18;
5
+ color: #e5edf7;
6
+ }
7
+
8
+ * {
9
+ box-sizing: border-box;
10
+ }
11
+
12
+ body {
13
+ margin: 0;
14
+ min-width: 320px;
15
+ min-height: 100vh;
16
+ background:
17
+ radial-gradient(circle at 12% 4%, rgba(34, 211, 238, 0.13), transparent 29rem),
18
+ radial-gradient(circle at 88% 0%, rgba(129, 140, 248, 0.14), transparent 30rem),
19
+ #080d18;
20
+ }
21
+
22
+ .page-shell {
23
+ width: min(1180px, calc(100vw - 32px));
24
+ margin: 0 auto;
25
+ padding: 42px 0;
26
+ }
27
+
28
+ .page-header {
29
+ margin-bottom: 20px;
30
+ }
31
+
32
+ .eyebrow,
33
+ .legend-kicker {
34
+ margin: 0 0 8px;
35
+ color: #67e8f9;
36
+ font-size: 12px;
37
+ font-weight: 800;
38
+ letter-spacing: 0.08em;
39
+ text-transform: uppercase;
40
+ }
41
+
42
+ h1 {
43
+ margin: 0;
44
+ color: #f8fafc;
45
+ font-size: clamp(28px, 5vw, 46px);
46
+ line-height: 1.1;
47
+ letter-spacing: 0;
48
+ }
49
+
50
+ .page-header > p:last-child {
51
+ margin: 12px 0 0;
52
+ color: #94a3b8;
53
+ line-height: 1.6;
54
+ }
55
+
56
+ .dashboard-card {
57
+ display: grid;
58
+ grid-template-columns: minmax(0, 1fr) 330px;
59
+ min-height: 580px;
60
+ overflow: hidden;
61
+ border: 1px solid rgba(148, 163, 184, 0.2);
62
+ border-radius: 8px;
63
+ background: rgba(12, 19, 33, 0.94);
64
+ box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
65
+ }
66
+
67
+ .chart-region {
68
+ min-width: 0;
69
+ padding: 24px 18px;
70
+ background:
71
+ linear-gradient(rgba(148, 163, 184, 0.035) 1px, transparent 1px),
72
+ linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px);
73
+ background-size: 28px 28px;
74
+ }
75
+
76
+ #chart {
77
+ width: 100%;
78
+ height: 520px;
79
+ }
80
+
81
+ #chart .kchart-svg text {
82
+ font-family: inherit;
83
+ }
84
+
85
+ #chart .kchart-title {
86
+ fill: #f8fafc;
87
+ }
88
+
89
+ #chart .value-pie {
90
+ transition: fill-opacity 140ms ease, stroke 140ms ease;
91
+ }
92
+
93
+ .legend-panel {
94
+ display: flex;
95
+ min-width: 0;
96
+ flex-direction: column;
97
+ align-self: center;
98
+ margin: 24px 24px 24px 0;
99
+ overflow: hidden;
100
+ border: 1px solid rgba(148, 163, 184, 0.18);
101
+ border-radius: 8px;
102
+ background: rgba(15, 23, 42, 0.86);
103
+ }
104
+
105
+ .legend-header,
106
+ .legend-footer {
107
+ display: flex;
108
+ align-items: center;
109
+ justify-content: space-between;
110
+ gap: 16px;
111
+ padding: 18px;
112
+ }
113
+
114
+ .legend-header {
115
+ border-bottom: 1px solid rgba(148, 163, 184, 0.13);
116
+ }
117
+
118
+ .legend-kicker {
119
+ margin-bottom: 5px;
120
+ color: #94a3b8;
121
+ letter-spacing: 0.04em;
122
+ }
123
+
124
+ .legend-header h2 {
125
+ margin: 0;
126
+ color: #f8fafc;
127
+ font-size: 16px;
128
+ letter-spacing: 0;
129
+ }
130
+
131
+ .legend-count {
132
+ flex: 0 0 auto;
133
+ color: #67e8f9;
134
+ font-size: 13px;
135
+ font-weight: 800;
136
+ }
137
+
138
+ .legend-scroll {
139
+ height: 360px;
140
+ overflow-x: hidden;
141
+ overflow-y: auto;
142
+ scrollbar-color: #475569 transparent;
143
+ scrollbar-width: thin;
144
+ }
145
+
146
+ .legend-scroll:focus-visible {
147
+ outline: 2px solid #22d3ee;
148
+ outline-offset: -2px;
149
+ }
150
+
151
+ .legend-scroll::-webkit-scrollbar {
152
+ width: 8px;
153
+ }
154
+
155
+ .legend-scroll::-webkit-scrollbar-track {
156
+ background: transparent;
157
+ }
158
+
159
+ .legend-scroll::-webkit-scrollbar-thumb {
160
+ border: 2px solid transparent;
161
+ border-radius: 8px;
162
+ background: #475569;
163
+ background-clip: padding-box;
164
+ }
165
+
166
+ .legend-list {
167
+ margin: 0;
168
+ padding: 6px 10px;
169
+ list-style: none;
170
+ }
171
+
172
+ .legend-item {
173
+ display: grid;
174
+ grid-template-columns: 10px minmax(0, 1fr) auto;
175
+ align-items: center;
176
+ gap: 11px;
177
+ min-height: 54px;
178
+ padding: 8px;
179
+ border-bottom: 1px solid rgba(148, 163, 184, 0.09);
180
+ }
181
+
182
+ .legend-item:last-child {
183
+ border-bottom: 0;
184
+ }
185
+
186
+ .legend-swatch {
187
+ width: 9px;
188
+ height: 9px;
189
+ border-radius: 50%;
190
+ background: var(--series-color);
191
+ box-shadow: 0 0 10px color-mix(in srgb, var(--series-color) 72%, transparent);
192
+ }
193
+
194
+ .legend-name {
195
+ min-width: 0;
196
+ overflow: hidden;
197
+ color: #cbd5e1;
198
+ font-size: 13px;
199
+ font-weight: 650;
200
+ text-overflow: ellipsis;
201
+ white-space: nowrap;
202
+ }
203
+
204
+ .legend-metric {
205
+ display: grid;
206
+ justify-items: end;
207
+ gap: 2px;
208
+ font-variant-numeric: tabular-nums;
209
+ }
210
+
211
+ .legend-metric strong {
212
+ color: #f8fafc;
213
+ font-size: 13px;
214
+ }
215
+
216
+ .legend-metric small {
217
+ color: #64748b;
218
+ font-size: 11px;
219
+ }
220
+
221
+ .legend-footer {
222
+ border-top: 1px solid rgba(148, 163, 184, 0.13);
223
+ color: #64748b;
224
+ font-size: 12px;
225
+ }
226
+
227
+ .legend-footer strong {
228
+ color: #cbd5e1;
229
+ }
230
+
231
+ @media (max-width: 860px) {
232
+ .dashboard-card {
233
+ grid-template-columns: 1fr;
234
+ }
235
+
236
+ .legend-panel {
237
+ margin: 0 18px 18px;
238
+ }
239
+
240
+ .legend-scroll {
241
+ height: 260px;
242
+ }
243
+ }
244
+
245
+ @media (max-width: 720px) {
246
+ .page-shell {
247
+ width: min(100vw - 20px, 1180px);
248
+ padding: 24px 0;
249
+ }
250
+
251
+ .chart-region {
252
+ padding: 14px 6px;
253
+ }
254
+
255
+ #chart {
256
+ height: 390px;
257
+ }
258
+
259
+ .legend-panel {
260
+ margin: 0 10px 10px;
261
+ }
262
+
263
+ .legend-header,
264
+ .legend-footer {
265
+ padding: 15px;
266
+ }
267
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,23 @@
1
+ <!doctype html>
2
+ <html lang="ko">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>KChart World Activity Map</title>
7
+ </head>
8
+ <body>
9
+ <main>
10
+ <section>
11
+ <div id="chart"></div>
12
+ <aside class="activity-legend" aria-label="국가별 활동 지수 범례">
13
+ <strong>국가별 활동 지수</strong>
14
+ <span class="activity-legend__bar"></span>
15
+ <span class="activity-legend__labels">
16
+ <span>낮음</span><span>보통</span><span>높음</span><span>매우 높음</span>
17
+ </span>
18
+ </aside>
19
+ </section>
20
+ </main>
21
+ <script type="module" src="/src/main.ts"></script>
22
+ </body>
23
+ </html>
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "kchart-world-activity-map",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite --host 0.0.0.0",
8
+ "build": "vite build",
9
+ "preview": "vite preview --host 0.0.0.0"
10
+ },
11
+ "dependencies": {
12
+ "@keneth80/k-chart": "^1.25.0",
13
+ "typescript": "^6.0.3",
14
+ "vite": "^7.1.12"
15
+ }
16
+ }
@@ -0,0 +1,77 @@
1
+ import {createKChart, createWorldCountryMapSeries} from '@keneth80/k-chart';
2
+ import './style.css';
3
+
4
+ type CountryActivity = {
5
+ name: string;
6
+ activity: number;
7
+ region: string;
8
+ };
9
+
10
+ const countryActivity: CountryActivity[] = [
11
+ {name: 'South Korea', activity: 92, region: 'Asia'},
12
+ {name: 'Japan', activity: 84, region: 'Asia'},
13
+ {name: 'China', activity: 78, region: 'Asia'},
14
+ {name: 'India', activity: 71, region: 'Asia'},
15
+ {name: 'Australia', activity: 63, region: 'Oceania'},
16
+ {name: 'United States of America', activity: 88, region: 'North America'},
17
+ {name: 'Canada', activity: 66, region: 'North America'},
18
+ {name: 'Brazil', activity: 58, region: 'South America'},
19
+ {name: 'France', activity: 73, region: 'Europe'},
20
+ {name: 'Germany', activity: 76, region: 'Europe'},
21
+ {name: 'United Kingdom', activity: 69, region: 'Europe'},
22
+ {name: 'South Africa', activity: 46, region: 'Africa'}
23
+ ];
24
+
25
+ createKChart<CountryActivity>({
26
+ selector: '#chart',
27
+ data: countryActivity,
28
+ width: 1180,
29
+ height: 650,
30
+ margin: {top: 76, right: 24, bottom: 24, left: 24},
31
+ title: {
32
+ text: '글로벌 시장 활동 현황',
33
+ align: 'center',
34
+ fontSize: 18,
35
+ fontWeight: 800
36
+ },
37
+ grid: {visible: false},
38
+ legend: {visible: false},
39
+ tooltip: {visible: true},
40
+ axes: [],
41
+ series: [
42
+ createWorldCountryMapSeries<CountryActivity>({
43
+ selector: 'world-activity-map',
44
+ displayName: 'Market activity',
45
+ dataKey: 'name',
46
+ valueField: 'activity',
47
+ colorLegend: {
48
+ visible: true,
49
+ title: '국가별 활동 지수',
50
+ position: 'bottom-left',
51
+ domain: [40, 100],
52
+ colors: ['#315a7d', '#2f9c95', '#f2c14e', '#e05d5d'],
53
+ labels: ['관찰', '안정', '활발', '최상'],
54
+ width: 280
55
+ },
56
+ fitPadding: 34,
57
+ backgroundFill: 'rgba(9, 15, 24, 0.72)',
58
+ missingFill: 'rgba(112, 132, 151, 0.22)',
59
+ stroke: 'rgba(225, 236, 246, 0.5)',
60
+ strokeWidth: 0.55,
61
+ hoverStroke: '#ffffff',
62
+ hoverStrokeWidth: 1.5,
63
+ zoom: {
64
+ enabled: true,
65
+ wheel: true,
66
+ pan: true,
67
+ scaleExtent: [1, 8],
68
+ controls: {visible: true, x: 10, y: 12, step: 0.3}
69
+ },
70
+ tooltip: {
71
+ formatter: ({label, data}) => data
72
+ ? `<strong>${label}</strong><br/>활동 지수: ${data.activity}<br/>권역: ${data.region}`
73
+ : `<strong>${label}</strong><br/>집계 데이터 없음`
74
+ }
75
+ })
76
+ ]
77
+ }).render();