@keneth80/k-chart 1.9.0 → 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 +22 -0
- package/README.md +204 -1
- 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-stacked-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,136 @@
|
|
|
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
|
+
volume: number;
|
|
9
|
+
extra: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type StackSegment = { field: 'extra' | 'volume' | 'value'; label: string; color: string };
|
|
13
|
+
type StackDatum = { point: MonthPoint; segment: StackSegment; y0: number; y1: number };
|
|
14
|
+
|
|
15
|
+
const stackSegments: StackSegment[] = [
|
|
16
|
+
{ field: 'extra', label: 'Extra', color: '#f3b45b' },
|
|
17
|
+
{ field: 'volume', label: 'Volume', color: '#56d08f' },
|
|
18
|
+
{ field: 'value', label: 'Value', color: '#5db8ff' }
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const data: MonthPoint[] = [
|
|
22
|
+
{ label: 'Jan', x: 1, value: 34, volume: 18, extra: 12 },
|
|
23
|
+
{ label: 'Feb', x: 2, value: 42, volume: 28, extra: 18 },
|
|
24
|
+
{ label: 'Mar', x: 3, value: 38, volume: 22, extra: 20 },
|
|
25
|
+
{ label: 'Apr', x: 4, value: 56, volume: 34, extra: 26 },
|
|
26
|
+
{ label: 'May', x: 5, value: 51, volume: 30, extra: 24 },
|
|
27
|
+
{ label: 'Jun', x: 6, value: 64, volume: 42, extra: 31 }
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const isInsideRect = (mouseX: number, mouseY: number, x: number, y: number, width: number, height: number) =>
|
|
31
|
+
mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
|
|
32
|
+
|
|
33
|
+
const formatTooltip = (point: MonthPoint) => {
|
|
34
|
+
const rows = stackSegments.map((segment) => `
|
|
35
|
+
<div style="display:flex;justify-content:space-between;gap:18px;color:${segment.color}">
|
|
36
|
+
<span>${segment.label}</span><strong>${point[segment.field]}</strong>
|
|
37
|
+
</div>`).join('');
|
|
38
|
+
const total = stackSegments.reduce((sum, segment) => sum + point[segment.field], 0);
|
|
39
|
+
return `<div style="min-width:150px"><strong>${point.label}</strong>${rows}<hr/>Total ${total}</div>`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const stackedColumnSeries = createCustomSeries<MonthPoint>({
|
|
43
|
+
selector: 'stacked-column',
|
|
44
|
+
displayName: 'Stacked Column',
|
|
45
|
+
xField: 'x',
|
|
46
|
+
yField: 'value',
|
|
47
|
+
render({ group, data, xScale, yScale, plotSize }) {
|
|
48
|
+
if (!xScale || !yScale) return;
|
|
49
|
+
|
|
50
|
+
const barWidth = Math.max(24, plotSize.width / Math.max(data.length, 1) * 0.48);
|
|
51
|
+
const stacks = group.selectAll<SVGGElement, MonthPoint>('g.demo-stack')
|
|
52
|
+
.data(data)
|
|
53
|
+
.join('g')
|
|
54
|
+
.attr('class', 'demo-stack');
|
|
55
|
+
|
|
56
|
+
stacks.selectAll<SVGRectElement, StackDatum>('rect')
|
|
57
|
+
.data((point) => {
|
|
58
|
+
let offset = 0;
|
|
59
|
+
return stackSegments.map((segment) => {
|
|
60
|
+
const value = point[segment.field] * 0.42;
|
|
61
|
+
const item = { point, segment, y0: offset, y1: offset + value };
|
|
62
|
+
offset += value;
|
|
63
|
+
return item;
|
|
64
|
+
});
|
|
65
|
+
})
|
|
66
|
+
.join('rect')
|
|
67
|
+
.attr('x', (item) => xScale.scale(item.point.x) - barWidth / 2)
|
|
68
|
+
.attr('y', (item) => yScale.scale(item.y1))
|
|
69
|
+
.attr('width', barWidth)
|
|
70
|
+
.attr('height', (item) => yScale.scale(item.y0) - yScale.scale(item.y1))
|
|
71
|
+
.attr('rx', 5)
|
|
72
|
+
.style('fill', (item) => item.segment.color)
|
|
73
|
+
.style('fill-opacity', 0.88)
|
|
74
|
+
.style('stroke', 'transparent')
|
|
75
|
+
.style('stroke-width', 0);
|
|
76
|
+
},
|
|
77
|
+
tooltip({ data, scales, plotSize, seriesGroup, mouseX, mouseY }) {
|
|
78
|
+
const xScale = scales.find((scale) => scale.field === 'x');
|
|
79
|
+
const yScale = scales.find((scale) => scale.field === 'value');
|
|
80
|
+
if (!xScale || !yScale) return undefined;
|
|
81
|
+
|
|
82
|
+
seriesGroup.selectAll<SVGRectElement, StackDatum>('g.demo-stack rect')
|
|
83
|
+
.style('fill-opacity', 0.88)
|
|
84
|
+
.style('stroke', 'transparent')
|
|
85
|
+
.style('stroke-width', 0);
|
|
86
|
+
|
|
87
|
+
const barWidth = Math.max(24, plotSize.width / Math.max(data.length, 1) * 0.48);
|
|
88
|
+
for (const point of data) {
|
|
89
|
+
const x = xScale.scale(point.x);
|
|
90
|
+
let offset = 0;
|
|
91
|
+
const totalScaled = stackSegments.reduce((sum, segment) => sum + point[segment.field] * 0.42, 0);
|
|
92
|
+
for (const segment of stackSegments) {
|
|
93
|
+
const value = point[segment.field] * 0.42;
|
|
94
|
+
const y0 = yScale.scale(offset);
|
|
95
|
+
const y1 = yScale.scale(offset + value);
|
|
96
|
+
const top = Math.min(y0, y1);
|
|
97
|
+
const bottom = Math.max(y0, y1);
|
|
98
|
+
if (isInsideRect(mouseX, mouseY, x - barWidth / 2, top, barWidth, bottom - top)) {
|
|
99
|
+
seriesGroup.selectAll<SVGRectElement, StackDatum>('g.demo-stack rect')
|
|
100
|
+
.filter((item) => item.point === point)
|
|
101
|
+
.style('fill-opacity', 1)
|
|
102
|
+
.style('stroke', '#f8fbff')
|
|
103
|
+
.style('stroke-width', 1.5);
|
|
104
|
+
return { data: point, x, y: yScale.scale(totalScaled), distance: 0, html: formatTooltip(point) };
|
|
105
|
+
}
|
|
106
|
+
offset += value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
},
|
|
111
|
+
clearTooltip({ seriesGroup }) {
|
|
112
|
+
seriesGroup.selectAll<SVGRectElement, StackDatum>('g.demo-stack rect')
|
|
113
|
+
.style('fill-opacity', 0.88)
|
|
114
|
+
.style('stroke', 'transparent')
|
|
115
|
+
.style('stroke-width', 0);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const chart = createKChart<MonthPoint>({
|
|
120
|
+
selector: '#chart',
|
|
121
|
+
data,
|
|
122
|
+
width: 920,
|
|
123
|
+
height: 460,
|
|
124
|
+
margin: { top: 88, right: 36, bottom: 58, left: 64 },
|
|
125
|
+
title: { text: 'Custom SVG Stacked Column', align: 'left', fontSize: 18 },
|
|
126
|
+
grid: { visible: true, x: false, y: true, color: 'rgba(148, 163, 184, 0.22)', dasharray: '3 8' },
|
|
127
|
+
legend: { visible: true, placement: 'top', selectable: false },
|
|
128
|
+
tooltip: { visible: true },
|
|
129
|
+
axes: [
|
|
130
|
+
{ field: 'x', type: 'number', placement: 'bottom', min: 0, max: 7, title: 'Month Index' },
|
|
131
|
+
{ field: 'value', type: 'number', placement: 'left', min: 0, max: 72, title: 'Stacked Value' }
|
|
132
|
+
],
|
|
133
|
+
series: [stackedColumnSeries]
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
chart.render();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
:root { color-scheme: dark; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0b1120; color: #e5edf7; }
|
|
2
|
+
* { box-sizing: border-box; }
|
|
3
|
+
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 20% 10%, rgba(93, 184, 255, 0.18), transparent 32rem), radial-gradient(circle at 80% 0%, rgba(86, 208, 143, 0.12), transparent 28rem), #0b1120; }
|
|
4
|
+
.page-shell { width: min(1120px, calc(100vw - 32px)); margin: 0 auto; padding: 40px 0; }
|
|
5
|
+
.intro { margin-bottom: 18px; }
|
|
6
|
+
.eyebrow { margin: 0 0 8px; color: #7dd3fc; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
|
|
7
|
+
h1 { margin: 0; font-size: clamp(28px, 5vw, 52px); line-height: 1.05; }
|
|
8
|
+
.intro p:last-child { margin: 12px 0 0; color: #b8c5d6; }
|
|
9
|
+
code { color: #fbbf24; }
|
|
10
|
+
.chart-panel { min-height: 520px; padding: 24px; border: 1px solid rgba(148, 163, 184, 0.24); border-radius: 12px; background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(17, 24, 39, 0.82)); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28); }
|
|
11
|
+
#chart { width: 100%; height: 460px; }
|
|
12
|
+
#chart .kchart-svg text { font-family: inherit; }
|
|
13
|
+
#chart .domain, #chart .tick line { stroke: rgba(203, 213, 225, 0.54); }
|
|
14
|
+
#chart .tick text, #chart .kchart-axis-title { fill: #cbd5e1; }
|
|
15
|
+
#chart .kchart-title { fill: #f8fafc; }
|
|
16
|
+
#chart .kchart-legend text { fill: #dbeafe; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>KChart Three.js Wafer</title></head><body><main class="page-shell"><section class="intro"><p class="eyebrow">StackBlitz starter</p><h1>KChart Three.js Wafer</h1><p>Orbit, drag, and zoom a Three.js monitoring object hosted by KChart.</p></section><section class="chart-panel"><div id="chart"></div></section></main><script type="module" src="/src/main.ts"></script></body></html>
|