@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.
- package/CHANGELOG.md +41 -0
- package/README.md +242 -4
- package/docs/assets/kchart-hero.svg +110 -0
- package/docs/assets/kchart-icon.svg +40 -0
- package/docs/configuration-reference.md +395 -0
- package/docs/functional-api.md +103 -3
- package/examples/stackblitz-candlestick-basic/index.html +23 -0
- package/examples/stackblitz-candlestick-basic/package-lock.json +1435 -0
- package/examples/stackblitz-candlestick-basic/package.json +18 -0
- package/examples/stackblitz-candlestick-basic/src/main.ts +107 -0
- package/examples/stackblitz-candlestick-basic/src/style.css +16 -0
- package/examples/stackblitz-canvas-line-basic/index.html +23 -0
- package/examples/stackblitz-canvas-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-canvas-line-basic/package.json +18 -0
- package/examples/stackblitz-canvas-line-basic/src/main.ts +73 -0
- package/examples/stackblitz-canvas-line-basic/src/style.css +46 -0
- package/examples/stackblitz-column-basic/index.html +23 -0
- package/examples/stackblitz-column-basic/package-lock.json +1435 -0
- package/examples/stackblitz-column-basic/package.json +18 -0
- package/examples/stackblitz-column-basic/src/main.ts +128 -0
- package/examples/stackblitz-column-basic/src/style.css +41 -0
- package/examples/stackblitz-doughnut-basic/index.html +21 -0
- package/examples/stackblitz-doughnut-basic/package-lock.json +1435 -0
- package/examples/stackblitz-doughnut-basic/package.json +18 -0
- package/examples/stackblitz-doughnut-basic/src/main.ts +177 -0
- package/examples/stackblitz-doughnut-basic/src/style.css +43 -0
- package/examples/stackblitz-line-basic/index.html +23 -0
- package/examples/stackblitz-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-line-basic/package.json +18 -0
- package/examples/stackblitz-line-basic/src/main.ts +112 -0
- package/examples/stackblitz-line-basic/src/style.css +108 -0
- package/examples/stackblitz-multi-series-basic/index.html +1 -0
- package/examples/stackblitz-multi-series-basic/package-lock.json +1435 -0
- package/examples/stackblitz-multi-series-basic/package.json +9 -0
- package/examples/stackblitz-multi-series-basic/src/main.ts +29 -0
- package/examples/stackblitz-multi-series-basic/src/style.css +1 -0
- package/examples/stackblitz-options-basic/index.html +1 -0
- package/examples/stackblitz-options-basic/package-lock.json +1435 -0
- package/examples/stackblitz-options-basic/package.json +9 -0
- package/examples/stackblitz-options-basic/src/main.ts +32 -0
- package/examples/stackblitz-options-basic/src/style.css +1 -0
- package/examples/stackblitz-pie-basic/index.html +21 -0
- package/examples/stackblitz-pie-basic/package-lock.json +1435 -0
- package/examples/stackblitz-pie-basic/package.json +18 -0
- package/examples/stackblitz-pie-basic/src/main.ts +156 -0
- package/examples/stackblitz-pie-basic/src/style.css +43 -0
- package/examples/stackblitz-plot-basic/index.html +1 -0
- package/examples/stackblitz-plot-basic/package-lock.json +1435 -0
- package/examples/stackblitz-plot-basic/package.json +9 -0
- package/examples/stackblitz-plot-basic/src/main.ts +32 -0
- package/examples/stackblitz-plot-basic/src/style.css +1 -0
- package/examples/stackblitz-radial-basic/index.html +21 -0
- package/examples/stackblitz-radial-basic/package-lock.json +1435 -0
- package/examples/stackblitz-radial-basic/package.json +18 -0
- package/examples/stackblitz-radial-basic/src/main.ts +223 -0
- package/examples/stackblitz-radial-basic/src/style.css +87 -0
- package/examples/stackblitz-simple-api-basic/index.html +30 -0
- package/examples/stackblitz-simple-api-basic/package-lock.json +1435 -0
- package/examples/stackblitz-simple-api-basic/package.json +18 -0
- package/examples/stackblitz-simple-api-basic/src/main.ts +69 -0
- package/examples/stackblitz-simple-api-basic/src/style.css +127 -0
- package/examples/stackblitz-stacked-column-basic/index.html +23 -0
- package/examples/stackblitz-stacked-column-basic/package-lock.json +1435 -0
- package/examples/stackblitz-stacked-column-basic/package.json +18 -0
- package/examples/stackblitz-stacked-column-basic/src/main.ts +136 -0
- package/examples/stackblitz-stacked-column-basic/src/style.css +16 -0
- package/examples/stackblitz-three-wafer-basic/index.html +1 -0
- package/examples/stackblitz-three-wafer-basic/package-lock.json +1453 -0
- package/examples/stackblitz-three-wafer-basic/package.json +9 -0
- package/examples/stackblitz-three-wafer-basic/src/main.ts +29 -0
- package/examples/stackblitz-three-wafer-basic/src/style.css +1 -0
- package/examples/stackblitz-topology-basic/index.html +1 -0
- package/examples/stackblitz-topology-basic/package-lock.json +1435 -0
- package/examples/stackblitz-topology-basic/package.json +9 -0
- package/examples/stackblitz-topology-basic/src/main.ts +89 -0
- package/examples/stackblitz-topology-basic/src/style.css +1 -0
- package/examples/stackblitz-webgl-line-basic/index.html +23 -0
- package/examples/stackblitz-webgl-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-webgl-line-basic/package.json +18 -0
- package/examples/stackblitz-webgl-line-basic/src/main.ts +86 -0
- package/examples/stackblitz-webgl-line-basic/src/style.css +46 -0
- package/examples/stackblitz-worker-json-line/index.html +41 -0
- package/examples/stackblitz-worker-json-line/package-lock.json +1435 -0
- package/examples/stackblitz-worker-json-line/package.json +19 -0
- package/examples/stackblitz-worker-json-line/public/data/large-line.json +4322 -0
- package/examples/stackblitz-worker-json-line/src/kchart-render.worker.ts +4 -0
- package/examples/stackblitz-worker-json-line/src/main.ts +185 -0
- package/examples/stackblitz-worker-json-line/src/style.css +101 -0
- package/lib/core/contracts.d.ts +22 -0
- package/lib/core/contracts.d.ts.map +1 -1
- package/lib/core/create-kchart.d.ts.map +1 -1
- package/lib/core/create-kchart.js +93 -4
- package/lib/core/create-kchart.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/kchart.d.ts +1 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +1 -0
- package/lib/kchart.js.map +1 -1
- package/lib/presets/index.d.ts +97 -0
- package/lib/presets/index.d.ts.map +1 -0
- package/lib/presets/index.js +481 -0
- package/lib/presets/index.js.map +1 -0
- package/lib/series/canvas-line.d.ts.map +1 -1
- package/lib/series/canvas-line.js +16 -11
- package/lib/series/canvas-line.js.map +1 -1
- package/lib/series/svg-line.d.ts.map +1 -1
- package/lib/series/svg-line.js +19 -3
- package/lib/series/svg-line.js.map +1 -1
- package/lib/series/webgl-line.d.ts.map +1 -1
- package/lib/series/webgl-line.js +10 -3
- package/lib/series/webgl-line.js.map +1 -1
- 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>
|