@keneth80/k-chart 1.26.0 → 1.27.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 (65) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +129 -1095
  3. package/docs/code-graph-handoff.md +19 -37
  4. package/docs/configuration-reference.md +8 -1
  5. package/docs/functional-api.md +77 -0
  6. package/docs/react-nextjs.md +62 -8
  7. package/docs/refactor-plan.md +39 -23
  8. package/docs/release.md +9 -4
  9. package/examples/stackblitz-calendar-heatmap-basic/index.html +37 -0
  10. package/examples/stackblitz-calendar-heatmap-basic/package-lock.json +1548 -0
  11. package/examples/stackblitz-calendar-heatmap-basic/package.json +18 -0
  12. package/examples/stackblitz-calendar-heatmap-basic/src/main.ts +172 -0
  13. package/examples/stackblitz-calendar-heatmap-basic/src/style.css +33 -0
  14. package/examples/stackblitz-calendar-heatmap-basic/src/vite-env.d.ts +1 -0
  15. package/examples/stackblitz-dual-axis-combo-basic/index.html +27 -0
  16. package/examples/stackblitz-dual-axis-combo-basic/package-lock.json +1548 -0
  17. package/examples/stackblitz-dual-axis-combo-basic/package.json +18 -0
  18. package/examples/stackblitz-dual-axis-combo-basic/src/main.ts +88 -0
  19. package/examples/stackblitz-dual-axis-combo-basic/src/style.css +31 -0
  20. package/examples/stackblitz-dual-axis-combo-basic/src/vite-env.d.ts +1 -0
  21. package/examples/stackblitz-hybrid-operations-dashboard/index.html +53 -0
  22. package/examples/stackblitz-hybrid-operations-dashboard/package-lock.json +1548 -0
  23. package/examples/stackblitz-hybrid-operations-dashboard/package.json +18 -0
  24. package/examples/stackblitz-hybrid-operations-dashboard/src/main.ts +181 -0
  25. package/examples/stackblitz-hybrid-operations-dashboard/src/style.css +52 -0
  26. package/examples/stackblitz-pareto-basic/index.html +22 -0
  27. package/examples/stackblitz-pareto-basic/package-lock.json +1548 -0
  28. package/examples/stackblitz-pareto-basic/package.json +18 -0
  29. package/examples/stackblitz-pareto-basic/src/main.ts +101 -0
  30. package/examples/stackblitz-pareto-basic/src/style.css +31 -0
  31. package/examples/stackblitz-pareto-basic/src/vite-env.d.ts +1 -0
  32. package/examples/stackblitz-simple-api-basic/package-lock.json +96 -4
  33. package/examples/stackblitz-simple-api-basic/package.json +1 -1
  34. package/examples/stackblitz-subcell-heatmap-basic/README.md +48 -0
  35. package/examples/stackblitz-subcell-heatmap-basic/index.html +13 -0
  36. package/examples/stackblitz-subcell-heatmap-basic/package-lock.json +1788 -0
  37. package/examples/stackblitz-subcell-heatmap-basic/package.json +23 -0
  38. package/examples/stackblitz-subcell-heatmap-basic/src/app.ts +212 -0
  39. package/examples/stackblitz-subcell-heatmap-basic/src/component.css +169 -0
  40. package/examples/stackblitz-subcell-heatmap-basic/src/heatmap-demo-core.ts +505 -0
  41. package/examples/stackblitz-subcell-heatmap-basic/src/heatmap-demo.ts +23 -0
  42. package/examples/stackblitz-subcell-heatmap-basic/src/main.ts +15 -0
  43. package/examples/stackblitz-subcell-heatmap-basic/src/maplibre-compat.ts +6 -0
  44. package/examples/stackblitz-subcell-heatmap-basic/src/model.ts +242 -0
  45. package/examples/stackblitz-subcell-heatmap-basic/src/raster.ts +121 -0
  46. package/examples/stackblitz-subcell-heatmap-basic/src/style.css +15 -0
  47. package/examples/stackblitz-subcell-heatmap-basic/src/synthetic.ts +72 -0
  48. package/examples/stackblitz-subcell-heatmap-basic/src/vendor.d.ts +3 -0
  49. package/examples/stackblitz-subcell-heatmap-basic/src/vite-env.d.ts +1 -0
  50. package/examples/stackblitz-topology-basic/package-lock.json +96 -4
  51. package/examples/stackblitz-topology-basic/package.json +1 -1
  52. package/examples/stackblitz-us-transport-route/index.html +29 -0
  53. package/examples/stackblitz-us-transport-route/package.json +17 -0
  54. package/examples/stackblitz-us-transport-route/src/main.ts +211 -0
  55. package/examples/stackblitz-us-transport-route/src/style.css +178 -0
  56. package/examples/stackblitz-webgl-line-basic/package-lock.json +96 -4
  57. package/examples/stackblitz-webgl-line-basic/package.json +1 -1
  58. package/examples/stackblitz-world-activity-map/package.json +1 -1
  59. package/lib/core/contracts.d.ts +6 -2
  60. package/lib/core/contracts.d.ts.map +1 -1
  61. package/lib/series/svg-graph.d.ts +29 -0
  62. package/lib/series/svg-graph.d.ts.map +1 -1
  63. package/lib/series/svg-graph.js +509 -80
  64. package/lib/series/svg-graph.js.map +1 -1
  65. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "kchart-stackblitz-hybrid-operations-dashboard",
3
+ "private": true,
4
+ "version": "0.0.0",
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.26.0"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^6.0.3",
16
+ "vite": "^7.2.7"
17
+ }
18
+ }
@@ -0,0 +1,181 @@
1
+ import {
2
+ createCanvasLineSeries,
3
+ createCustomSeries,
4
+ createKChart,
5
+ createWebglLineSeries,
6
+ type KChartSeries
7
+ } from "@keneth80/k-chart";
8
+ import "./style.css";
9
+
10
+ type IncidentSeverity = "warning" | "critical";
11
+
12
+ type OperationPoint = {
13
+ x: number;
14
+ throughput: number;
15
+ baseline: number;
16
+ severity?: IncidentSeverity;
17
+ site?: string;
18
+ message?: string;
19
+ };
20
+
21
+ type IncidentSummary = {
22
+ severity: IncidentSeverity;
23
+ site: string;
24
+ message: string;
25
+ time: string;
26
+ };
27
+
28
+ const POINT_COUNT = 14_000;
29
+ const incidents = new Map<number, Omit<OperationPoint, "x" | "throughput" | "baseline">>([
30
+ [3_250, { severity: "warning", site: "Seoul edge", message: "Packet retry burst" }],
31
+ [7_820, { severity: "critical", site: "Frankfurt gateway", message: "Latency above SLA" }],
32
+ [11_680, { severity: "warning", site: "Virginia cluster", message: "Queue depth elevated" }]
33
+ ]);
34
+
35
+ const incidentSummaries: IncidentSummary[] = [
36
+ { severity: "critical", site: "Frankfurt gateway", message: "Latency above SLA", time: "12 sec ago" },
37
+ { severity: "warning", site: "Virginia cluster", message: "Queue depth elevated", time: "46 sec ago" },
38
+ { severity: "warning", site: "Seoul edge", message: "Packet retry burst", time: "2 min ago" }
39
+ ];
40
+
41
+ const data: OperationPoint[] = Array.from({ length: POINT_COUNT }, (_, x) => {
42
+ const baseline = 57 + Math.sin(x / 1_900) * 4.8 + Math.cos(x / 780) * 2.1;
43
+ const telemetry = baseline
44
+ + Math.sin(x / 18) * 5.4
45
+ + Math.sin(x / 71) * 3.2
46
+ + Math.cos(x / 9) * 1.4;
47
+ const incident = incidents.get(x);
48
+ const incidentLift = incident?.severity === "critical" ? 24 : incident ? 14 : 0;
49
+
50
+ return {
51
+ x,
52
+ throughput: Number(Math.min(96, telemetry + incidentLift).toFixed(2)),
53
+ baseline: Number(baseline.toFixed(2)),
54
+ ...incident
55
+ };
56
+ });
57
+
58
+ const createIncidentSeries = (): KChartSeries<OperationPoint> =>
59
+ createCustomSeries<OperationPoint>({
60
+ selector: "operations-incidents",
61
+ displayName: "SVG incidents",
62
+ xField: "x",
63
+ yField: "throughput",
64
+ color: "#fb7185",
65
+ render({ group, data: points, xScale, yScale, plotSize }) {
66
+ if (!xScale || !yScale) return;
67
+
68
+ const alerts = points.filter((point) => point.severity);
69
+ const groups = group
70
+ .selectAll("g.operation-alert")
71
+ .data(alerts, (point: OperationPoint) => String(point.x))
72
+ .join("g")
73
+ .attr("class", "operation-alert")
74
+ .attr("transform", (point: OperationPoint) =>
75
+ `translate(${xScale.scale(point.x)},${yScale.scale(point.throughput)})`
76
+ );
77
+
78
+ groups.selectAll("line.alert-stem")
79
+ .data((point: OperationPoint) => [point])
80
+ .join("line")
81
+ .attr("class", "alert-stem")
82
+ .attr("x1", 0).attr("x2", 0).attr("y1", 9).attr("y2", 34)
83
+ .attr("stroke", (point: OperationPoint) => point.severity === "critical" ? "#fb7185" : "#fbbf24");
84
+
85
+ groups.selectAll("circle.alert-pulse")
86
+ .data((point: OperationPoint) => [point])
87
+ .join("circle")
88
+ .attr("class", "alert-pulse")
89
+ .attr("r", 10).attr("fill", "none")
90
+ .attr("stroke", (point: OperationPoint) => point.severity === "critical" ? "#fb7185" : "#fbbf24");
91
+
92
+ groups.selectAll("circle.alert-core")
93
+ .data((point: OperationPoint) => [point])
94
+ .join("circle")
95
+ .attr("class", "alert-core")
96
+ .attr("r", 4.5)
97
+ .attr("fill", (point: OperationPoint) => point.severity === "critical" ? "#fb7185" : "#fbbf24")
98
+ .attr("stroke", "#f8fafc").attr("stroke-width", 1.5);
99
+
100
+ groups.selectAll("text.alert-label")
101
+ .data((point: OperationPoint) => [point])
102
+ .join("text")
103
+ .attr("class", "alert-label")
104
+ .attr("x", (point: OperationPoint) => xScale.scale(point.x) > plotSize.width - 150 ? -12 : 12)
105
+ .attr("y", 40)
106
+ .attr("text-anchor", (point: OperationPoint) => xScale.scale(point.x) > plotSize.width - 150 ? "end" : "start")
107
+ .text((point: OperationPoint) => point.site ?? "Incident");
108
+ }
109
+ });
110
+
111
+ const series = [
112
+ createWebglLineSeries<OperationPoint>({
113
+ selector: "operations-telemetry",
114
+ displayName: "WebGL telemetry",
115
+ xField: "x",
116
+ yField: "throughput",
117
+ color: "#38bdf8",
118
+ lineWidth: 1.2,
119
+ downsample: { enabled: true, strategy: "min-max", pointsPerPixel: 2 }
120
+ }),
121
+ createCanvasLineSeries<OperationPoint>({
122
+ selector: "operations-baseline",
123
+ displayName: "Canvas baseline",
124
+ xField: "x",
125
+ yField: "baseline",
126
+ color: "#fbbf24",
127
+ lineWidth: 2.2
128
+ }),
129
+ createIncidentSeries()
130
+ ];
131
+
132
+ const chart = createKChart<OperationPoint>({
133
+ selector: "#chart",
134
+ data,
135
+ height: 410,
136
+ margin: { top: 22, right: 28, bottom: 48, left: 56 },
137
+ grid: { visible: true, x: false, y: true, color: "rgba(148, 163, 184, 0.17)", dasharray: "2 7" },
138
+ legend: { visible: false },
139
+ tooltip: {
140
+ visible: true,
141
+ formatter: ({ data: point, series: activeSeries, color }) => {
142
+ const value = activeSeries.selector === "operations-baseline" ? point.baseline : point.throughput;
143
+ return `<div style="min-width:168px">
144
+ <div style="color:${color};font-weight:800;margin-bottom:6px">${activeSeries.displayName}</div>
145
+ <div>Sample: ${point.x.toLocaleString()}</div>
146
+ <div>Value: ${value.toFixed(2)}%</div>
147
+ ${point.site ? `<div style="margin-top:6px;color:#f8fafc">${point.site}: ${point.message}</div>` : ""}
148
+ </div>`;
149
+ }
150
+ },
151
+ axes: [
152
+ {
153
+ field: "x", type: "number", placement: "bottom", min: 0, max: POINT_COUNT - 1,
154
+ title: "Rolling 60-minute window", tickCount: 7,
155
+ tickFormat: (value) => `${Math.round((Number(value) / (POINT_COUNT - 1)) * 60 - 60)}m`
156
+ },
157
+ {
158
+ field: "throughput", domainFields: ["throughput", "baseline"], type: "number", placement: "left",
159
+ min: 20, max: 100, title: "Capacity", tickCount: 5,
160
+ tickFormat: (value) => `${Number(value).toFixed(0)}%`
161
+ }
162
+ ],
163
+ series
164
+ }).render();
165
+
166
+ const incidentList = document.querySelector<HTMLElement>("#incident-list");
167
+ if (incidentList) {
168
+ incidentList.innerHTML = incidentSummaries.map((incident) => `
169
+ <article class="${incident.severity}">
170
+ <div><i></i>${incident.severity}</div>
171
+ <strong>${incident.site}</strong>
172
+ <p>${incident.message}</p>
173
+ <time>${incident.time}</time>
174
+ </article>
175
+ `).join("");
176
+ }
177
+
178
+ const chartElement = document.querySelector<HTMLElement>("#chart");
179
+ if (chartElement) {
180
+ new ResizeObserver(() => chart.resize()).observe(chartElement);
181
+ }
@@ -0,0 +1,52 @@
1
+ @import url("https://fonts.googleapis.com/css2?family=Inter:wght@500;700;800&display=swap");
2
+
3
+ :root { font-family: Inter, ui-sans-serif, system-ui, sans-serif; color: #edf3f8; background: #070b11; }
4
+ * { box-sizing: border-box; }
5
+ html, body { width: 100%; min-width: 1080px; min-height: 100%; margin: 0; }
6
+ body { padding: 22px; }
7
+
8
+ .operations-dashboard { width: 100%; min-height: 680px; padding: 22px; background: #0a0f16; }
9
+ .operations-header, .section-heading, .renderer-key, .live-state { display: flex; align-items: center; }
10
+ .operations-header { justify-content: space-between; margin-bottom: 18px; }
11
+ .operations-header p, .section-heading span, .kpi-strip span { margin: 0; color: #7f94a7; font-size: 10px; font-weight: 800; }
12
+ .operations-header h1 { margin: 4px 0 0; font-size: 24px; line-height: 1.1; }
13
+ .live-state { gap: 8px; color: #9eddb9; font-size: 12px; font-weight: 700; }
14
+ .live-state i { width: 8px; height: 8px; border-radius: 50%; background: #45d48a; box-shadow: 0 0 0 4px rgba(69, 212, 138, .12); }
15
+
16
+ .kpi-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-block: 1px solid rgba(148, 163, 184, .16); margin-bottom: 18px; }
17
+ .kpi-strip article { padding: 14px 18px; border-right: 1px solid rgba(148, 163, 184, .16); }
18
+ .kpi-strip article:last-child { border-right: 0; }
19
+ .kpi-strip strong { display: block; margin-top: 5px; font-size: 22px; line-height: 1; }
20
+ .kpi-strip small { display: block; margin-top: 7px; color: #91a4b5; font-size: 10px; }
21
+ .kpi-strip .critical strong { color: #fb7185; }
22
+
23
+ .operations-main { display: grid; grid-template-columns: minmax(0, 1fr) 248px; min-height: 496px; border: 1px solid rgba(148, 163, 184, .17); background: #0d141d; }
24
+ .telemetry-panel { min-width: 0; padding: 17px 16px 8px; }
25
+ .section-heading { justify-content: space-between; gap: 12px; min-height: 40px; }
26
+ .section-heading strong { display: block; margin-top: 4px; font-size: 13px; }
27
+ .renderer-key { gap: 6px; }
28
+ .renderer-key > span { display: grid; grid-template-columns: auto auto; gap: 6px; padding: 6px 8px; border: 1px solid rgba(148, 163, 184, .18); background: #111b27; color: #8ea3b5; font-size: 9px; }
29
+ .renderer-key b { font-size: 9px; }
30
+ .renderer-key .webgl b { color: #38bdf8; }
31
+ .renderer-key .canvas b { color: #fbbf24; }
32
+ .renderer-key .svg b { color: #fb7185; }
33
+ #chart { width: 100%; height: 410px; }
34
+
35
+ .incident-panel { border-left: 1px solid rgba(148, 163, 184, .17); padding: 17px 15px; background: #0b1119; }
36
+ .incident-panel .section-heading > b { color: #fb7185; font-size: 20px; }
37
+ .incident-list { display: grid; gap: 8px; margin-top: 16px; }
38
+ .incident-list article { padding: 12px; border: 1px solid rgba(148, 163, 184, .15); border-left: 3px solid #fbbf24; background: #101923; }
39
+ .incident-list article.critical { border-left-color: #fb7185; }
40
+ .incident-list article > div { display: flex; align-items: center; gap: 7px; color: #fbbf24; font-size: 9px; font-weight: 800; text-transform: uppercase; }
41
+ .incident-list article.critical > div { color: #fb7185; }
42
+ .incident-list article i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
43
+ .incident-list article strong { display: block; margin-top: 9px; font-size: 12px; }
44
+ .incident-list p, .incident-list time { color: #8fa2b3; font-size: 10px; }
45
+ .incident-list p { margin: 4px 0 10px; }
46
+ .incident-panel footer { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(148, 163, 184, .16); color: #8295a6; font-size: 9px; }
47
+ .incident-panel footer strong { color: #b9c8d5; }
48
+
49
+ .alert-stem { stroke-width: 1; stroke-dasharray: 2 3; opacity: .78; }
50
+ .alert-pulse { stroke-width: 1.5; transform-box: fill-box; transform-origin: center; animation: alert-pulse 2s ease-out infinite; }
51
+ .alert-label { fill: #e2e8f0; paint-order: stroke; stroke: #0d141d; stroke-width: 4px; font-size: 9px; font-weight: 800; }
52
+ @keyframes alert-pulse { 0% { opacity: .9; transform: scale(.7); } 75%, 100% { opacity: 0; transform: scale(1.45); } }
@@ -0,0 +1,22 @@
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 Pareto Basic</title>
7
+ </head>
8
+ <body>
9
+ <main class="quality-shell">
10
+ <header class="quality-header">
11
+ <p class="eyebrow">Distribution quality</p>
12
+ <h1>Fulfillment incident priorities</h1>
13
+ <p>Incidents are ranked by frequency; the cumulative line shows where corrective work has the greatest reach.</p>
14
+ </header>
15
+ <section class="chart-panel" aria-label="Pareto chart of fulfillment incidents">
16
+ <div class="threshold-key"><i></i>80% focus threshold</div>
17
+ <div id="chart"></div>
18
+ </section>
19
+ </main>
20
+ <script type="module" src="/src/main.ts"></script>
21
+ </body>
22
+ </html>