@keneth80/k-chart 1.8.2 → 1.10.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 (115) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +242 -4
  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 +103 -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-line-basic/index.html +23 -0
  28. package/examples/stackblitz-line-basic/package-lock.json +1435 -0
  29. package/examples/stackblitz-line-basic/package.json +18 -0
  30. package/examples/stackblitz-line-basic/src/main.ts +112 -0
  31. package/examples/stackblitz-line-basic/src/style.css +108 -0
  32. package/examples/stackblitz-multi-series-basic/index.html +1 -0
  33. package/examples/stackblitz-multi-series-basic/package-lock.json +1435 -0
  34. package/examples/stackblitz-multi-series-basic/package.json +9 -0
  35. package/examples/stackblitz-multi-series-basic/src/main.ts +29 -0
  36. package/examples/stackblitz-multi-series-basic/src/style.css +1 -0
  37. package/examples/stackblitz-options-basic/index.html +1 -0
  38. package/examples/stackblitz-options-basic/package-lock.json +1435 -0
  39. package/examples/stackblitz-options-basic/package.json +9 -0
  40. package/examples/stackblitz-options-basic/src/main.ts +32 -0
  41. package/examples/stackblitz-options-basic/src/style.css +1 -0
  42. package/examples/stackblitz-pie-basic/index.html +21 -0
  43. package/examples/stackblitz-pie-basic/package-lock.json +1435 -0
  44. package/examples/stackblitz-pie-basic/package.json +18 -0
  45. package/examples/stackblitz-pie-basic/src/main.ts +156 -0
  46. package/examples/stackblitz-pie-basic/src/style.css +43 -0
  47. package/examples/stackblitz-plot-basic/index.html +1 -0
  48. package/examples/stackblitz-plot-basic/package-lock.json +1435 -0
  49. package/examples/stackblitz-plot-basic/package.json +9 -0
  50. package/examples/stackblitz-plot-basic/src/main.ts +32 -0
  51. package/examples/stackblitz-plot-basic/src/style.css +1 -0
  52. package/examples/stackblitz-radial-basic/index.html +21 -0
  53. package/examples/stackblitz-radial-basic/package-lock.json +1435 -0
  54. package/examples/stackblitz-radial-basic/package.json +18 -0
  55. package/examples/stackblitz-radial-basic/src/main.ts +223 -0
  56. package/examples/stackblitz-radial-basic/src/style.css +87 -0
  57. package/examples/stackblitz-simple-api-basic/index.html +30 -0
  58. package/examples/stackblitz-simple-api-basic/package-lock.json +1435 -0
  59. package/examples/stackblitz-simple-api-basic/package.json +18 -0
  60. package/examples/stackblitz-simple-api-basic/src/main.ts +69 -0
  61. package/examples/stackblitz-simple-api-basic/src/style.css +127 -0
  62. package/examples/stackblitz-stacked-column-basic/index.html +23 -0
  63. package/examples/stackblitz-stacked-column-basic/package-lock.json +1435 -0
  64. package/examples/stackblitz-stacked-column-basic/package.json +18 -0
  65. package/examples/stackblitz-stacked-column-basic/src/main.ts +136 -0
  66. package/examples/stackblitz-stacked-column-basic/src/style.css +16 -0
  67. package/examples/stackblitz-three-wafer-basic/index.html +1 -0
  68. package/examples/stackblitz-three-wafer-basic/package-lock.json +1453 -0
  69. package/examples/stackblitz-three-wafer-basic/package.json +9 -0
  70. package/examples/stackblitz-three-wafer-basic/src/main.ts +29 -0
  71. package/examples/stackblitz-three-wafer-basic/src/style.css +1 -0
  72. package/examples/stackblitz-topology-basic/index.html +1 -0
  73. package/examples/stackblitz-topology-basic/package-lock.json +1435 -0
  74. package/examples/stackblitz-topology-basic/package.json +9 -0
  75. package/examples/stackblitz-topology-basic/src/main.ts +89 -0
  76. package/examples/stackblitz-topology-basic/src/style.css +1 -0
  77. package/examples/stackblitz-webgl-line-basic/index.html +23 -0
  78. package/examples/stackblitz-webgl-line-basic/package-lock.json +1435 -0
  79. package/examples/stackblitz-webgl-line-basic/package.json +18 -0
  80. package/examples/stackblitz-webgl-line-basic/src/main.ts +86 -0
  81. package/examples/stackblitz-webgl-line-basic/src/style.css +46 -0
  82. package/examples/stackblitz-worker-json-line/index.html +41 -0
  83. package/examples/stackblitz-worker-json-line/package-lock.json +1435 -0
  84. package/examples/stackblitz-worker-json-line/package.json +19 -0
  85. package/examples/stackblitz-worker-json-line/public/data/large-line.json +4322 -0
  86. package/examples/stackblitz-worker-json-line/src/kchart-render.worker.ts +4 -0
  87. package/examples/stackblitz-worker-json-line/src/main.ts +185 -0
  88. package/examples/stackblitz-worker-json-line/src/style.css +101 -0
  89. package/lib/core/contracts.d.ts +22 -0
  90. package/lib/core/contracts.d.ts.map +1 -1
  91. package/lib/core/create-kchart.d.ts.map +1 -1
  92. package/lib/core/create-kchart.js +93 -4
  93. package/lib/core/create-kchart.js.map +1 -1
  94. package/lib/index.d.ts +1 -0
  95. package/lib/index.d.ts.map +1 -1
  96. package/lib/index.js +1 -0
  97. package/lib/index.js.map +1 -1
  98. package/lib/kchart.d.ts +1 -0
  99. package/lib/kchart.d.ts.map +1 -1
  100. package/lib/kchart.js +1 -0
  101. package/lib/kchart.js.map +1 -1
  102. package/lib/presets/index.d.ts +97 -0
  103. package/lib/presets/index.d.ts.map +1 -0
  104. package/lib/presets/index.js +481 -0
  105. package/lib/presets/index.js.map +1 -0
  106. package/lib/series/canvas-line.d.ts.map +1 -1
  107. package/lib/series/canvas-line.js +16 -11
  108. package/lib/series/canvas-line.js.map +1 -1
  109. package/lib/series/svg-line.d.ts.map +1 -1
  110. package/lib/series/svg-line.js +19 -3
  111. package/lib/series/svg-line.js.map +1 -1
  112. package/lib/series/webgl-line.d.ts.map +1 -1
  113. package/lib/series/webgl-line.js +10 -3
  114. package/lib/series/webgl-line.js.map +1 -1
  115. package/package.json +13 -2
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "kchart-stackblitz-column-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,128 @@
1
+ import { createCustomSeries, createKChart } from '@keneth80/k-chart';
2
+ import './style.css';
3
+
4
+ interface MonthPoint {
5
+ label: string;
6
+ x: number;
7
+ value: number;
8
+ }
9
+
10
+ const data: MonthPoint[] = [
11
+ { label: 'Jan', x: 1, value: 34 },
12
+ { label: 'Feb', x: 2, value: 42 },
13
+ { label: 'Mar', x: 3, value: 38 },
14
+ { label: 'Apr', x: 4, value: 56 },
15
+ { label: 'May', x: 5, value: 51 },
16
+ { label: 'Jun', x: 6, value: 64 }
17
+ ];
18
+
19
+ const isInsideRoundedRect = (
20
+ mouseX: number,
21
+ mouseY: number,
22
+ x: number,
23
+ y: number,
24
+ width: number,
25
+ height: number,
26
+ radius: number
27
+ ) => {
28
+ if (mouseX < x || mouseX > x + width || mouseY < y || mouseY > y + height) {
29
+ return false;
30
+ }
31
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
32
+ if (r === 0) return true;
33
+ const left = x + r;
34
+ const right = x + width - r;
35
+ const top = y + r;
36
+ const bottom = y + height - r;
37
+ if ((mouseX >= left && mouseX <= right) || (mouseY >= top && mouseY <= bottom)) {
38
+ return true;
39
+ }
40
+ const cornerX = mouseX < left ? left : right;
41
+ const cornerY = mouseY < top ? top : bottom;
42
+ return Math.hypot(mouseX - cornerX, mouseY - cornerY) <= r;
43
+ };
44
+
45
+ const columnSeries = createCustomSeries<MonthPoint>({
46
+ selector: 'custom-column',
47
+ displayName: 'Column',
48
+ xField: 'x',
49
+ yField: 'value',
50
+ color: '#5db8ff',
51
+ render({ group, data, xScale, yScale, plotSize }) {
52
+ if (!xScale || !yScale) return;
53
+
54
+ const barWidth = Math.max(24, plotSize.width / Math.max(data.length, 1) * 0.48);
55
+ group.selectAll<SVGRectElement, MonthPoint>('rect.demo-column')
56
+ .data(data)
57
+ .join('rect')
58
+ .attr('class', 'demo-column')
59
+ .attr('x', (point) => xScale.scale(point.x) - barWidth / 2)
60
+ .attr('y', (point) => yScale.scale(point.value))
61
+ .attr('width', barWidth)
62
+ .attr('height', (point) => plotSize.height - yScale.scale(point.value))
63
+ .attr('rx', 7)
64
+ .style('fill', '#5db8ff')
65
+ .style('fill-opacity', 0.86)
66
+ .style('stroke', 'transparent')
67
+ .style('stroke-width', 0);
68
+ },
69
+ tooltip({ data, scales, plotSize, seriesGroup, mouseX, mouseY }) {
70
+ const xScale = scales.find((scale) => scale.field === 'x');
71
+ const yScale = scales.find((scale) => scale.field === 'value');
72
+ if (!xScale || !yScale) return undefined;
73
+
74
+ seriesGroup.selectAll<SVGRectElement, MonthPoint>('rect.demo-column')
75
+ .style('fill-opacity', 0.86)
76
+ .style('stroke', 'transparent')
77
+ .style('stroke-width', 0);
78
+
79
+ const barWidth = Math.max(24, plotSize.width / Math.max(data.length, 1) * 0.48);
80
+ for (const point of data) {
81
+ const x = xScale.scale(point.x);
82
+ const y = yScale.scale(point.value);
83
+ const height = plotSize.height - y;
84
+ if (isInsideRoundedRect(mouseX, mouseY, x - barWidth / 2, y, barWidth, height, 7)) {
85
+ seriesGroup.selectAll<SVGRectElement, MonthPoint>('rect.demo-column')
86
+ .filter((item) => item === point)
87
+ .style('fill-opacity', 1)
88
+ .style('stroke', '#f8fbff')
89
+ .style('stroke-width', 2);
90
+
91
+ return {
92
+ data: point,
93
+ x,
94
+ y,
95
+ distance: 0,
96
+ color: '#5db8ff',
97
+ html: `<strong style="color:#5db8ff">${point.label}</strong><br/>value: ${point.value}`
98
+ };
99
+ }
100
+ }
101
+ return undefined;
102
+ },
103
+ clearTooltip({ seriesGroup }) {
104
+ seriesGroup.selectAll<SVGRectElement, MonthPoint>('rect.demo-column')
105
+ .style('fill-opacity', 0.86)
106
+ .style('stroke', 'transparent')
107
+ .style('stroke-width', 0);
108
+ }
109
+ });
110
+
111
+ const chart = createKChart<MonthPoint>({
112
+ selector: '#chart',
113
+ data,
114
+ width: 920,
115
+ height: 460,
116
+ margin: { top: 88, right: 36, bottom: 58, left: 64 },
117
+ title: { text: 'Custom SVG Column Renderer', align: 'left', fontSize: 18 },
118
+ grid: { visible: true, x: false, y: true, color: 'rgba(148, 163, 184, 0.22)', dasharray: '3 8' },
119
+ legend: { visible: true, placement: 'top', selectable: true },
120
+ tooltip: { visible: true },
121
+ axes: [
122
+ { field: 'x', type: 'number', placement: 'bottom', min: 0, max: 7, title: 'Month Index' },
123
+ { field: 'value', type: 'number', placement: 'left', min: 0, max: 72, title: 'Value' }
124
+ ],
125
+ series: [columnSeries]
126
+ });
127
+
128
+ chart.render();
@@ -0,0 +1,41 @@
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(251, 191, 36, 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
+ code { color: #fbbf24; }
26
+
27
+ .chart-panel {
28
+ min-height: 520px;
29
+ padding: 24px;
30
+ border: 1px solid rgba(148, 163, 184, 0.24);
31
+ border-radius: 12px;
32
+ background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(17, 24, 39, 0.82));
33
+ box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
34
+ }
35
+
36
+ #chart { width: 100%; height: 460px; }
37
+ #chart .kchart-svg text { font-family: inherit; }
38
+ #chart .domain, #chart .tick line { stroke: rgba(203, 213, 225, 0.54); }
39
+ #chart .tick text, #chart .kchart-axis-title { fill: #cbd5e1; }
40
+ #chart .kchart-title { fill: #f8fafc; }
41
+ #chart .kchart-legend text { fill: #dbeafe; }
@@ -0,0 +1,21 @@
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 Doughnut 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 Doughnut Chart</h1>
13
+ <p>Use the same custom arc renderer with an inner radius and center total label.</p>
14
+ </section>
15
+ <section class="chart-panel">
16
+ <div id="chart"></div>
17
+ </section>
18
+ </main>
19
+ <script type="module" src="/src/main.ts"></script>
20
+ </body>
21
+ </html>