@keneth80/k-chart 1.9.0 → 1.11.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +208 -1
  3. package/docs/assets/kchart-hero.svg +110 -0
  4. package/docs/assets/kchart-icon.svg +40 -0
  5. package/docs/configuration-reference.md +395 -0
  6. package/docs/functional-api.md +164 -3
  7. package/examples/stackblitz-candlestick-basic/index.html +23 -0
  8. package/examples/stackblitz-candlestick-basic/package-lock.json +1435 -0
  9. package/examples/stackblitz-candlestick-basic/package.json +18 -0
  10. package/examples/stackblitz-candlestick-basic/src/main.ts +107 -0
  11. package/examples/stackblitz-candlestick-basic/src/style.css +16 -0
  12. package/examples/stackblitz-canvas-line-basic/index.html +23 -0
  13. package/examples/stackblitz-canvas-line-basic/package-lock.json +1435 -0
  14. package/examples/stackblitz-canvas-line-basic/package.json +18 -0
  15. package/examples/stackblitz-canvas-line-basic/src/main.ts +73 -0
  16. package/examples/stackblitz-canvas-line-basic/src/style.css +46 -0
  17. package/examples/stackblitz-column-basic/index.html +23 -0
  18. package/examples/stackblitz-column-basic/package-lock.json +1435 -0
  19. package/examples/stackblitz-column-basic/package.json +18 -0
  20. package/examples/stackblitz-column-basic/src/main.ts +128 -0
  21. package/examples/stackblitz-column-basic/src/style.css +41 -0
  22. package/examples/stackblitz-doughnut-basic/index.html +21 -0
  23. package/examples/stackblitz-doughnut-basic/package-lock.json +1435 -0
  24. package/examples/stackblitz-doughnut-basic/package.json +18 -0
  25. package/examples/stackblitz-doughnut-basic/src/main.ts +177 -0
  26. package/examples/stackblitz-doughnut-basic/src/style.css +43 -0
  27. package/examples/stackblitz-korea-region-map-basic/index.html +20 -0
  28. package/examples/stackblitz-korea-region-map-basic/package-lock.json +1434 -0
  29. package/examples/stackblitz-korea-region-map-basic/package.json +17 -0
  30. package/examples/stackblitz-korea-region-map-basic/src/main.ts +90 -0
  31. package/examples/stackblitz-korea-region-map-basic/src/style.css +57 -0
  32. package/examples/stackblitz-line-basic/index.html +23 -0
  33. package/examples/stackblitz-line-basic/package-lock.json +1435 -0
  34. package/examples/stackblitz-line-basic/package.json +18 -0
  35. package/examples/stackblitz-line-basic/src/main.ts +112 -0
  36. package/examples/stackblitz-line-basic/src/style.css +108 -0
  37. package/examples/stackblitz-multi-series-basic/index.html +1 -0
  38. package/examples/stackblitz-multi-series-basic/package-lock.json +1435 -0
  39. package/examples/stackblitz-multi-series-basic/package.json +9 -0
  40. package/examples/stackblitz-multi-series-basic/src/main.ts +29 -0
  41. package/examples/stackblitz-multi-series-basic/src/style.css +1 -0
  42. package/examples/stackblitz-options-basic/index.html +1 -0
  43. package/examples/stackblitz-options-basic/package-lock.json +1435 -0
  44. package/examples/stackblitz-options-basic/package.json +9 -0
  45. package/examples/stackblitz-options-basic/src/main.ts +32 -0
  46. package/examples/stackblitz-options-basic/src/style.css +1 -0
  47. package/examples/stackblitz-pie-basic/index.html +21 -0
  48. package/examples/stackblitz-pie-basic/package-lock.json +1435 -0
  49. package/examples/stackblitz-pie-basic/package.json +18 -0
  50. package/examples/stackblitz-pie-basic/src/main.ts +156 -0
  51. package/examples/stackblitz-pie-basic/src/style.css +43 -0
  52. package/examples/stackblitz-plot-basic/index.html +1 -0
  53. package/examples/stackblitz-plot-basic/package-lock.json +1435 -0
  54. package/examples/stackblitz-plot-basic/package.json +9 -0
  55. package/examples/stackblitz-plot-basic/src/main.ts +32 -0
  56. package/examples/stackblitz-plot-basic/src/style.css +1 -0
  57. package/examples/stackblitz-radial-basic/index.html +21 -0
  58. package/examples/stackblitz-radial-basic/package-lock.json +1435 -0
  59. package/examples/stackblitz-radial-basic/package.json +18 -0
  60. package/examples/stackblitz-radial-basic/src/main.ts +223 -0
  61. package/examples/stackblitz-radial-basic/src/style.css +87 -0
  62. package/examples/stackblitz-simple-api-basic/index.html +30 -0
  63. package/examples/stackblitz-simple-api-basic/package-lock.json +1435 -0
  64. package/examples/stackblitz-simple-api-basic/package.json +18 -0
  65. package/examples/stackblitz-simple-api-basic/src/main.ts +69 -0
  66. package/examples/stackblitz-simple-api-basic/src/style.css +127 -0
  67. package/examples/stackblitz-stacked-column-basic/index.html +23 -0
  68. package/examples/stackblitz-stacked-column-basic/package-lock.json +1435 -0
  69. package/examples/stackblitz-stacked-column-basic/package.json +18 -0
  70. package/examples/stackblitz-stacked-column-basic/src/main.ts +136 -0
  71. package/examples/stackblitz-stacked-column-basic/src/style.css +16 -0
  72. package/examples/stackblitz-three-wafer-basic/index.html +1 -0
  73. package/examples/stackblitz-three-wafer-basic/package-lock.json +1453 -0
  74. package/examples/stackblitz-three-wafer-basic/package.json +9 -0
  75. package/examples/stackblitz-three-wafer-basic/src/main.ts +29 -0
  76. package/examples/stackblitz-three-wafer-basic/src/style.css +1 -0
  77. package/examples/stackblitz-topology-basic/index.html +1 -0
  78. package/examples/stackblitz-topology-basic/package-lock.json +1435 -0
  79. package/examples/stackblitz-topology-basic/package.json +9 -0
  80. package/examples/stackblitz-topology-basic/src/main.ts +89 -0
  81. package/examples/stackblitz-topology-basic/src/style.css +1 -0
  82. package/examples/stackblitz-webgl-line-basic/index.html +23 -0
  83. package/examples/stackblitz-webgl-line-basic/package-lock.json +1435 -0
  84. package/examples/stackblitz-webgl-line-basic/package.json +18 -0
  85. package/examples/stackblitz-webgl-line-basic/src/main.ts +86 -0
  86. package/examples/stackblitz-webgl-line-basic/src/style.css +46 -0
  87. package/examples/stackblitz-worker-json-line/index.html +41 -0
  88. package/examples/stackblitz-worker-json-line/package-lock.json +1435 -0
  89. package/examples/stackblitz-worker-json-line/package.json +19 -0
  90. package/examples/stackblitz-worker-json-line/public/data/large-line.json +4322 -0
  91. package/examples/stackblitz-worker-json-line/src/kchart-render.worker.ts +4 -0
  92. package/examples/stackblitz-worker-json-line/src/main.ts +185 -0
  93. package/examples/stackblitz-worker-json-line/src/style.css +101 -0
  94. package/examples/stackblitz-world-country-map-basic/index.html +20 -0
  95. package/examples/stackblitz-world-country-map-basic/package-lock.json +1434 -0
  96. package/examples/stackblitz-world-country-map-basic/package.json +17 -0
  97. package/examples/stackblitz-world-country-map-basic/src/main.ts +64 -0
  98. package/examples/stackblitz-world-country-map-basic/src/style.css +57 -0
  99. package/lib/core/contracts.d.ts +72 -0
  100. package/lib/core/contracts.d.ts.map +1 -1
  101. package/lib/core/create-kchart.d.ts.map +1 -1
  102. package/lib/core/create-kchart.js +93 -4
  103. package/lib/core/create-kchart.js.map +1 -1
  104. package/lib/index.d.ts +1 -0
  105. package/lib/index.d.ts.map +1 -1
  106. package/lib/index.js +1 -0
  107. package/lib/index.js.map +1 -1
  108. package/lib/kchart.d.ts +1 -0
  109. package/lib/kchart.d.ts.map +1 -1
  110. package/lib/kchart.js +1 -0
  111. package/lib/kchart.js.map +1 -1
  112. package/lib/presets/index.d.ts +97 -0
  113. package/lib/presets/index.d.ts.map +1 -0
  114. package/lib/presets/index.js +481 -0
  115. package/lib/presets/index.js.map +1 -0
  116. package/lib/series/canvas-line.d.ts.map +1 -1
  117. package/lib/series/canvas-line.js +16 -11
  118. package/lib/series/canvas-line.js.map +1 -1
  119. package/lib/series/index.d.ts +1 -0
  120. package/lib/series/index.d.ts.map +1 -1
  121. package/lib/series/index.js +1 -0
  122. package/lib/series/index.js.map +1 -1
  123. package/lib/series/svg-line.d.ts.map +1 -1
  124. package/lib/series/svg-line.js +19 -3
  125. package/lib/series/svg-line.js.map +1 -1
  126. package/lib/series/svg-region-map.d.ts +4 -0
  127. package/lib/series/svg-region-map.d.ts.map +1 -0
  128. package/lib/series/svg-region-map.js +324 -0
  129. package/lib/series/svg-region-map.js.map +1 -0
  130. package/lib/series/webgl-line.d.ts.map +1 -1
  131. package/lib/series/webgl-line.js +10 -3
  132. package/lib/series/webgl-line.js.map +1 -1
  133. package/package.json +13 -2
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "kchart-stackblitz-doughnut-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 && vite build",
9
+ "preview": "vite preview --host 0.0.0.0"
10
+ },
11
+ "dependencies": {
12
+ "@keneth80/k-chart": "^1.9.0"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^6.0.3",
16
+ "vite": "^7.2.7"
17
+ }
18
+ }
@@ -0,0 +1,177 @@
1
+ import { createCustomSeries, createKChart, type KChartSeries } from '@keneth80/k-chart';
2
+ import './style.css';
3
+
4
+ interface SegmentPoint {
5
+ label: string;
6
+ value: number;
7
+ }
8
+
9
+ const data: SegmentPoint[] = [
10
+ { label: 'Product A', value: 34 },
11
+ { label: 'Product B', value: 42 },
12
+ { label: 'Product C', value: 26 },
13
+ { label: 'Product D', value: 18 },
14
+ { label: 'Product E', value: 31 }
15
+ ];
16
+
17
+ const palette = ['#5db8ff', '#56d08f', '#f3b45b', '#d876ff', '#ff6b8a'];
18
+
19
+ const createDoughnutSeries = (): KChartSeries<SegmentPoint> => {
20
+ type PieSegment = {
21
+ point: SegmentPoint;
22
+ value: number;
23
+ startAngle: number;
24
+ endAngle: number;
25
+ color: string;
26
+ };
27
+
28
+ const innerRadiusRatio = 0.56;
29
+ const pointOnCircle = (centerX: number, centerY: number, radius: number, angle: number): [number, number] => [
30
+ centerX + Math.cos(angle) * radius,
31
+ centerY + Math.sin(angle) * radius
32
+ ];
33
+
34
+ const createSegments = (points: SegmentPoint[]): PieSegment[] => {
35
+ const total = points.reduce((sum, point) => sum + Math.max(0, point.value), 0) || 1;
36
+ let cursor = -Math.PI / 2;
37
+ return points.map((point, index) => {
38
+ const value = Math.max(0, point.value);
39
+ const angle = (value / total) * Math.PI * 2;
40
+ const segment = { point, value, startAngle: cursor, endAngle: cursor + angle, color: palette[index % palette.length] };
41
+ cursor += angle;
42
+ return segment;
43
+ });
44
+ };
45
+
46
+ const describeSegment = (segment: PieSegment, centerX: number, centerY: number, outerRadius: number, innerRadius: number): string => {
47
+ const [outerStartX, outerStartY] = pointOnCircle(centerX, centerY, outerRadius, segment.startAngle);
48
+ const [outerEndX, outerEndY] = pointOnCircle(centerX, centerY, outerRadius, segment.endAngle);
49
+ const [innerEndX, innerEndY] = pointOnCircle(centerX, centerY, innerRadius, segment.endAngle);
50
+ const [innerStartX, innerStartY] = pointOnCircle(centerX, centerY, innerRadius, segment.startAngle);
51
+ const largeArcFlag = segment.endAngle - segment.startAngle > Math.PI ? 1 : 0;
52
+ return `M${outerStartX},${outerStartY} A${outerRadius},${outerRadius} 0 ${largeArcFlag} 1 ${outerEndX},${outerEndY} L${innerEndX},${innerEndY} A${innerRadius},${innerRadius} 0 ${largeArcFlag} 0 ${innerStartX},${innerStartY} Z`;
53
+ };
54
+
55
+ const normalizeAngle = (angle: number): number => {
56
+ let normalized = angle;
57
+ while (normalized < -Math.PI / 2) normalized += Math.PI * 2;
58
+ while (normalized >= Math.PI * 1.5) normalized -= Math.PI * 2;
59
+ return normalized;
60
+ };
61
+
62
+ return createCustomSeries<SegmentPoint>({
63
+ selector: 'doughnut-segments',
64
+ displayName: 'Share',
65
+ xField: 'label',
66
+ yField: 'value',
67
+ render({ group, data: points, plotSize }) {
68
+ const centerX = plotSize.width / 2;
69
+ const centerY = plotSize.height / 2 + 8;
70
+ const outerRadius = Math.max(92, Math.min(plotSize.width, plotSize.height) * 0.34);
71
+ const innerRadius = outerRadius * innerRadiusRatio;
72
+ const segments = createSegments(points);
73
+ const total = segments.reduce((sum, segment) => sum + segment.value, 0) || 1;
74
+
75
+ group.selectAll<SVGPathElement, PieSegment>('path.doughnut-segment')
76
+ .data(segments)
77
+ .join('path')
78
+ .attr('class', 'doughnut-segment')
79
+ .attr('d', (segment) => describeSegment(segment, centerX, centerY, outerRadius, innerRadius))
80
+ .style('fill', (segment) => segment.color)
81
+ .style('fill-opacity', 0.84)
82
+ .style('stroke', '#101720')
83
+ .style('stroke-width', 2);
84
+
85
+ group.selectAll<SVGTextElement, PieSegment>('text.doughnut-label')
86
+ .data(segments)
87
+ .join('text')
88
+ .attr('class', 'doughnut-label')
89
+ .attr('x', (segment) => pointOnCircle(centerX, centerY, outerRadius + 28, (segment.startAngle + segment.endAngle) / 2)[0])
90
+ .attr('y', (segment) => pointOnCircle(centerX, centerY, outerRadius + 28, (segment.startAngle + segment.endAngle) / 2)[1])
91
+ .attr('text-anchor', 'middle')
92
+ .attr('dominant-baseline', 'middle')
93
+ .style('fill', 'rgba(226, 232, 240, 0.86)')
94
+ .style('font-size', '12px')
95
+ .style('font-weight', 700)
96
+ .text((segment) => `${segment.point.label} ${Math.round((segment.value / total) * 100)}%`);
97
+
98
+ group.selectAll<SVGTextElement, string>('text.doughnut-center-title')
99
+ .data(['Total'])
100
+ .join('text')
101
+ .attr('class', 'doughnut-center-title')
102
+ .attr('x', centerX)
103
+ .attr('y', centerY - 6)
104
+ .attr('text-anchor', 'middle')
105
+ .style('fill', '#f8fafc')
106
+ .style('font-size', '13px')
107
+ .style('font-weight', 800)
108
+ .text('Total');
109
+
110
+ group.selectAll<SVGTextElement, number>('text.doughnut-center-value')
111
+ .data([total])
112
+ .join('text')
113
+ .attr('class', 'doughnut-center-value')
114
+ .attr('x', centerX)
115
+ .attr('y', centerY + 14)
116
+ .attr('text-anchor', 'middle')
117
+ .style('fill', 'rgba(226, 232, 240, 0.72)')
118
+ .style('font-size', '12px')
119
+ .text((value) => value.toFixed(0));
120
+ },
121
+ tooltip({ data: points, plotSize, seriesGroup, mouseX, mouseY }) {
122
+ const centerX = plotSize.width / 2;
123
+ const centerY = plotSize.height / 2 + 8;
124
+ const outerRadius = Math.max(92, Math.min(plotSize.width, plotSize.height) * 0.34);
125
+ const innerRadius = outerRadius * innerRadiusRatio;
126
+ const distance = Math.hypot(mouseX - centerX, mouseY - centerY);
127
+ const angle = normalizeAngle(Math.atan2(mouseY - centerY, mouseX - centerX));
128
+ const total = points.reduce((sum, point) => sum + Math.max(0, point.value), 0) || 1;
129
+
130
+ seriesGroup.selectAll<SVGPathElement, PieSegment>('path.doughnut-segment')
131
+ .style('fill-opacity', 0.84)
132
+ .style('stroke', '#101720');
133
+
134
+ if (distance > outerRadius || distance < innerRadius) return undefined;
135
+ const segment = createSegments(points).find((item) => angle >= item.startAngle && angle <= item.endAngle);
136
+ if (!segment) return undefined;
137
+
138
+ seriesGroup.selectAll<SVGPathElement, PieSegment>('path.doughnut-segment')
139
+ .filter((item) => item.point === segment.point)
140
+ .style('fill-opacity', 1)
141
+ .style('stroke', '#f8fafc');
142
+
143
+ const midAngle = (segment.startAngle + segment.endAngle) / 2;
144
+ const [x, y] = pointOnCircle(centerX, centerY, (innerRadius + outerRadius) / 2, midAngle);
145
+ return {
146
+ data: segment.point,
147
+ x,
148
+ y,
149
+ distance: 0,
150
+ color: segment.color,
151
+ html: `<strong style="color:${segment.color}">${segment.point.label}</strong><br/>value: ${segment.value}<br/>share: ${Math.round((segment.value / total) * 100)}%`
152
+ };
153
+ }
154
+ });
155
+ };
156
+
157
+ const chart = createKChart<SegmentPoint>({
158
+ selector: '#chart',
159
+ data,
160
+ width: 920,
161
+ height: 500,
162
+ margin: { top: 88, right: 36, bottom: 42, left: 36 },
163
+ title: { text: 'Market Share Doughnut Chart', align: 'left', fontSize: 18 },
164
+ grid: { visible: false },
165
+ legend: { visible: false },
166
+ tooltip: { visible: true },
167
+ axes: [],
168
+ series: [createDoughnutSeries()]
169
+ });
170
+
171
+ chart.render();
172
+
173
+ window.addEventListener('resize', () => {
174
+ const panel = document.querySelector<HTMLElement>('.chart-panel');
175
+ if (!panel) return;
176
+ chart.resize({ width: Math.max(panel.clientWidth - 48, 320), height: 500 });
177
+ });
@@ -0,0 +1,43 @@
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:
15
+ radial-gradient(circle at 20% 10%, rgba(93, 184, 255, 0.18), transparent 32rem),
16
+ radial-gradient(circle at 80% 0%, rgba(86, 208, 143, 0.12), transparent 28rem),
17
+ #0b1120;
18
+ }
19
+
20
+ .page-shell { width: min(1120px, calc(100vw - 32px)); margin: 0 auto; padding: 40px 0; }
21
+ .intro { margin-bottom: 18px; }
22
+ .eyebrow { margin: 0 0 8px; color: #7dd3fc; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
23
+ h1 { margin: 0; font-size: clamp(28px, 5vw, 52px); line-height: 1.05; }
24
+ .intro p:last-child { margin: 12px 0 0; color: #b8c5d6; }
25
+
26
+ .chart-panel {
27
+ min-height: 560px;
28
+ padding: 24px;
29
+ border: 1px solid rgba(148, 163, 184, 0.24);
30
+ border-radius: 12px;
31
+ background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(17, 24, 39, 0.82));
32
+ box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
33
+ }
34
+
35
+ #chart { width: 100%; height: 500px; }
36
+ #chart .kchart-svg text { font-family: inherit; }
37
+ #chart .kchart-title { fill: #f8fafc; }
38
+ #chart .kchart-legend text { fill: #dbeafe; }
39
+
40
+ @media (max-width: 720px) {
41
+ .page-shell { width: min(100vw - 20px, 1120px); padding: 24px 0; }
42
+ .chart-panel { padding: 12px; }
43
+ }
@@ -0,0 +1,20 @@
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 Korea Region Map</title>
7
+ </head>
8
+ <body>
9
+ <main>
10
+ <section>
11
+ <div>
12
+ <p>KChart SVG region map</p>
13
+ <h1>Korea region map</h1>
14
+ </div>
15
+ <div id="chart"></div>
16
+ </section>
17
+ </main>
18
+ <script type="module" src="/src/main.ts"></script>
19
+ </body>
20
+ </html>