@keneth80/k-chart 1.26.0 → 1.26.1
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 +21 -0
- package/README.md +7 -2
- package/examples/stackblitz-calendar-heatmap-basic/index.html +37 -0
- package/examples/stackblitz-calendar-heatmap-basic/package-lock.json +1548 -0
- package/examples/stackblitz-calendar-heatmap-basic/package.json +18 -0
- package/examples/stackblitz-calendar-heatmap-basic/src/main.ts +172 -0
- package/examples/stackblitz-calendar-heatmap-basic/src/style.css +33 -0
- package/examples/stackblitz-calendar-heatmap-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-dual-axis-combo-basic/index.html +27 -0
- package/examples/stackblitz-dual-axis-combo-basic/package-lock.json +1548 -0
- package/examples/stackblitz-dual-axis-combo-basic/package.json +18 -0
- package/examples/stackblitz-dual-axis-combo-basic/src/main.ts +88 -0
- package/examples/stackblitz-dual-axis-combo-basic/src/style.css +31 -0
- package/examples/stackblitz-dual-axis-combo-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-hybrid-operations-dashboard/index.html +53 -0
- package/examples/stackblitz-hybrid-operations-dashboard/package-lock.json +1548 -0
- package/examples/stackblitz-hybrid-operations-dashboard/package.json +18 -0
- package/examples/stackblitz-hybrid-operations-dashboard/src/main.ts +181 -0
- package/examples/stackblitz-hybrid-operations-dashboard/src/style.css +52 -0
- package/examples/stackblitz-pareto-basic/index.html +22 -0
- package/examples/stackblitz-pareto-basic/package-lock.json +1548 -0
- package/examples/stackblitz-pareto-basic/package.json +18 -0
- package/examples/stackblitz-pareto-basic/src/main.ts +101 -0
- package/examples/stackblitz-pareto-basic/src/style.css +31 -0
- package/examples/stackblitz-pareto-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-us-transport-route/index.html +29 -0
- package/examples/stackblitz-us-transport-route/package.json +17 -0
- package/examples/stackblitz-us-transport-route/src/main.ts +211 -0
- package/examples/stackblitz-us-transport-route/src/style.css +178 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kchart-stackblitz-calendar-heatmap-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 --noEmit && 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,172 @@
|
|
|
1
|
+
import {createCustomSeries, createKChart} from '@keneth80/k-chart';
|
|
2
|
+
import './style.css';
|
|
3
|
+
|
|
4
|
+
interface CalendarDay {
|
|
5
|
+
date: string;
|
|
6
|
+
dateLabel: string;
|
|
7
|
+
weekKey: string;
|
|
8
|
+
dayLabel: string;
|
|
9
|
+
cases: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const DAY_MS = 86_400_000;
|
|
13
|
+
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
|
14
|
+
const PALETTE = ['#ffffd9', '#c7e9b4', '#7fcdbb', '#41b6c4', '#225ea8'];
|
|
15
|
+
const START = Date.UTC(2026, 0, 1);
|
|
16
|
+
const END = Date.UTC(2026, 5, 30);
|
|
17
|
+
const START_DAY_OFFSET = (new Date(START).getUTCDay() + 6) % 7;
|
|
18
|
+
|
|
19
|
+
const colorForCases = (value: number): string => {
|
|
20
|
+
if (value < 24) return PALETTE[0];
|
|
21
|
+
if (value < 38) return PALETTE[1];
|
|
22
|
+
if (value < 52) return PALETTE[2];
|
|
23
|
+
if (value < 65) return PALETTE[3];
|
|
24
|
+
return PALETTE[4];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const dateFormatter = new Intl.DateTimeFormat('en', {
|
|
28
|
+
month: 'short',
|
|
29
|
+
day: 'numeric',
|
|
30
|
+
year: 'numeric',
|
|
31
|
+
timeZone: 'UTC'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const data: CalendarDay[] = [];
|
|
35
|
+
for (let timestamp = START, dayIndex = 0; timestamp <= END; timestamp += DAY_MS, dayIndex += 1) {
|
|
36
|
+
const date = new Date(timestamp);
|
|
37
|
+
const day = (date.getUTCDay() + 6) % 7;
|
|
38
|
+
const week = Math.floor((START_DAY_OFFSET + dayIndex) / 7);
|
|
39
|
+
const weekdayBase = day < 5 ? 48 : 17;
|
|
40
|
+
const seasonality = Math.sin(dayIndex / 13) * 11 + Math.cos(dayIndex / 31) * 7;
|
|
41
|
+
const launchLift = date.getUTCMonth() === 2 || date.getUTCMonth() === 4 ? 13 : 0;
|
|
42
|
+
const cases = Math.max(6, Math.round(weekdayBase + seasonality + launchLift + (dayIndex % 9)));
|
|
43
|
+
|
|
44
|
+
data.push({
|
|
45
|
+
date: date.toISOString().slice(0, 10),
|
|
46
|
+
dateLabel: dateFormatter.format(date),
|
|
47
|
+
weekKey: 'W' + String(week + 1).padStart(2, '0'),
|
|
48
|
+
dayLabel: DAYS[day],
|
|
49
|
+
cases
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const weekKeys = Array.from(new Set(data.map((point) => point.weekKey)));
|
|
54
|
+
const monthLabels = new Map<string, string>();
|
|
55
|
+
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'];
|
|
56
|
+
weekKeys.forEach((weekKey, index) => {
|
|
57
|
+
const representativeDay = new Date(START + Math.max(0, index * 7 - START_DAY_OFFSET) * DAY_MS);
|
|
58
|
+
monthLabels.set(weekKey, monthNames[Math.min(representativeDay.getUTCMonth(), 5)]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const calendarSeries = createCustomSeries<CalendarDay>({
|
|
62
|
+
selector: 'support-calendar',
|
|
63
|
+
displayName: 'Cases opened',
|
|
64
|
+
xField: 'weekKey',
|
|
65
|
+
yField: 'dayLabel',
|
|
66
|
+
color: PALETTE[3],
|
|
67
|
+
render({group, data: points, xScale, yScale, plotSize}) {
|
|
68
|
+
if (!xScale || !yScale) return;
|
|
69
|
+
|
|
70
|
+
const stepX = xScale.scale.step?.() ?? plotSize.width / weekKeys.length;
|
|
71
|
+
const stepY = yScale.scale.step?.() ?? plotSize.height / DAYS.length;
|
|
72
|
+
const cellWidth = Math.max(3, stepX - Math.min(3, stepX * 0.2));
|
|
73
|
+
const cellHeight = Math.max(8, stepY - Math.min(4, stepY * 0.18));
|
|
74
|
+
|
|
75
|
+
const cells = group.selectAll<SVGRectElement, CalendarDay>('rect.calendar-cell')
|
|
76
|
+
.data(points, (point: CalendarDay) => point.date)
|
|
77
|
+
.join('rect')
|
|
78
|
+
.attr('class', 'calendar-cell')
|
|
79
|
+
.attr('x', (point) => xScale.scale(point.weekKey) - cellWidth / 2)
|
|
80
|
+
.attr('y', (point) => yScale.scale(point.dayLabel) - cellHeight / 2)
|
|
81
|
+
.attr('width', cellWidth)
|
|
82
|
+
.attr('height', cellHeight)
|
|
83
|
+
.attr('rx', Math.min(3, cellWidth / 4))
|
|
84
|
+
.attr('aria-label', (point) => point.dateLabel + ': ' + point.cases + ' cases opened')
|
|
85
|
+
.style('fill', (point) => colorForCases(point.cases))
|
|
86
|
+
.style('stroke', '#ffffff')
|
|
87
|
+
.style('stroke-width', 1);
|
|
88
|
+
|
|
89
|
+
cells.selectAll('title')
|
|
90
|
+
.data((point) => [point])
|
|
91
|
+
.join('title')
|
|
92
|
+
.text((point) => point.dateLabel + ': ' + point.cases + ' cases opened');
|
|
93
|
+
},
|
|
94
|
+
tooltip({data: points, scales, plotSize, seriesGroup, mouseX, mouseY}) {
|
|
95
|
+
const xScale = scales.find((scale) => scale.field === 'weekKey');
|
|
96
|
+
const yScale = scales.find((scale) => scale.field === 'dayLabel');
|
|
97
|
+
if (!xScale || !yScale) return undefined;
|
|
98
|
+
|
|
99
|
+
const stepX = xScale.scale.step?.() ?? plotSize.width / weekKeys.length;
|
|
100
|
+
const stepY = yScale.scale.step?.() ?? plotSize.height / DAYS.length;
|
|
101
|
+
const cellWidth = Math.max(3, stepX - Math.min(3, stepX * 0.2));
|
|
102
|
+
const cellHeight = Math.max(8, stepY - Math.min(4, stepY * 0.18));
|
|
103
|
+
|
|
104
|
+
seriesGroup.selectAll<SVGRectElement, CalendarDay>('rect.calendar-cell')
|
|
105
|
+
.style('stroke', '#ffffff')
|
|
106
|
+
.style('stroke-width', 1);
|
|
107
|
+
|
|
108
|
+
for (const point of points) {
|
|
109
|
+
const centerX = xScale.scale(point.weekKey);
|
|
110
|
+
const centerY = yScale.scale(point.dayLabel);
|
|
111
|
+
const inside = Math.abs(mouseX - centerX) <= cellWidth / 2
|
|
112
|
+
&& Math.abs(mouseY - centerY) <= cellHeight / 2;
|
|
113
|
+
if (!inside) continue;
|
|
114
|
+
|
|
115
|
+
seriesGroup.selectAll<SVGRectElement, CalendarDay>('rect.calendar-cell')
|
|
116
|
+
.filter((item) => item === point)
|
|
117
|
+
.style('stroke', '#152b2a')
|
|
118
|
+
.style('stroke-width', 2);
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
data: point,
|
|
122
|
+
x: centerX,
|
|
123
|
+
y: centerY,
|
|
124
|
+
distance: 0,
|
|
125
|
+
color: colorForCases(point.cases),
|
|
126
|
+
html: '<strong>' + point.dateLabel + '</strong><br/>' + point.cases + ' cases opened'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return undefined;
|
|
131
|
+
},
|
|
132
|
+
clearTooltip({seriesGroup}) {
|
|
133
|
+
seriesGroup.selectAll<SVGRectElement, CalendarDay>('rect.calendar-cell')
|
|
134
|
+
.style('stroke', '#ffffff')
|
|
135
|
+
.style('stroke-width', 1);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const chart = createKChart<CalendarDay>({
|
|
140
|
+
selector: '#chart',
|
|
141
|
+
data,
|
|
142
|
+
height: 340,
|
|
143
|
+
margin: {top: 66, right: 24, bottom: 28, left: 58},
|
|
144
|
+
title: {text: 'H1 2026 case intake calendar', align: 'left', fontSize: 17},
|
|
145
|
+
grid: {visible: false},
|
|
146
|
+
legend: {visible: false},
|
|
147
|
+
tooltip: {visible: true},
|
|
148
|
+
axes: [
|
|
149
|
+
{
|
|
150
|
+
field: 'weekKey', type: 'point', placement: 'top', domain: weekKeys,
|
|
151
|
+
padding: 0.5, tickCount: 6,
|
|
152
|
+
tickFormat: (value) => monthLabels.get(String(value)) ?? ''
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
field: 'dayLabel', type: 'point', placement: 'left', domain: [...DAYS].reverse(),
|
|
156
|
+
padding: 0.5, tickCount: 7
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
series: [calendarSeries]
|
|
160
|
+
}).render();
|
|
161
|
+
|
|
162
|
+
const totalElement = document.querySelector<HTMLElement>('#case-total');
|
|
163
|
+
if (totalElement) {
|
|
164
|
+
totalElement.textContent = data.reduce((sum, point) => sum + point.cases, 0).toLocaleString();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const chartElement = document.querySelector<HTMLElement>('#chart');
|
|
168
|
+
if (chartElement) {
|
|
169
|
+
new ResizeObserver(() => chart.resize()).observe(chartElement);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
window.addEventListener('beforeunload', () => chart.destroy());
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
3
|
+
color: #172625;
|
|
4
|
+
background: #f2f5f3;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
* { box-sizing: border-box; }
|
|
8
|
+
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f2f5f3; }
|
|
9
|
+
.calendar-shell { width: min(1120px, calc(100vw - 32px)); margin: 0 auto; padding: 34px 0; }
|
|
10
|
+
.calendar-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
|
|
11
|
+
.eyebrow { margin: 0 0 7px; color: #14756d; font-size: 12px; font-weight: 800; text-transform: uppercase; }
|
|
12
|
+
h1 { margin: 0; font-size: 34px; line-height: 1.12; }
|
|
13
|
+
.calendar-header p:last-child { margin: 10px 0 0; color: #5b6966; }
|
|
14
|
+
.summary { min-width: 130px; padding-left: 16px; border-left: 3px solid #348a80; }
|
|
15
|
+
.summary span, .summary small { display: block; color: #62716e; font-size: 11px; }
|
|
16
|
+
.summary strong { display: block; margin: 2px 0; font-size: 22px; }
|
|
17
|
+
.chart-panel { min-height: 408px; padding: 20px; overflow: hidden; border: 1px solid #d2dad6; border-radius: 8px; background: #ffffff; box-shadow: 0 16px 40px rgba(32, 61, 56, 0.08); }
|
|
18
|
+
.heat-legend { display: flex; align-items: center; justify-content: flex-end; gap: 5px; min-height: 22px; color: #5b6966; font-size: 11px; font-weight: 700; }
|
|
19
|
+
.heat-legend i { width: 18px; height: 12px; border: 1px solid rgba(21, 43, 42, 0.14); border-radius: 2px; background: var(--swatch); }
|
|
20
|
+
#chart { width: 100%; height: 340px; }
|
|
21
|
+
#chart .kchart-svg text { font-family: inherit; }
|
|
22
|
+
#chart .domain, #chart .tick line { stroke: #a8b5b1; }
|
|
23
|
+
#chart .tick text, #chart .kchart-axis-title { fill: #53635f !important; }
|
|
24
|
+
#chart .kchart-title { fill: #172625 !important; }
|
|
25
|
+
|
|
26
|
+
@media (max-width: 640px) {
|
|
27
|
+
.calendar-shell { width: calc(100vw - 20px); padding: 22px 0; }
|
|
28
|
+
.calendar-header { align-items: flex-start; flex-direction: column; gap: 14px; }
|
|
29
|
+
h1 { font-size: 28px; }
|
|
30
|
+
.chart-panel { min-height: 392px; padding: 8px; }
|
|
31
|
+
.heat-legend { justify-content: flex-start; padding-left: 4px; }
|
|
32
|
+
#chart { height: 340px; }
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,27 @@
|
|
|
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 Dual-Axis Combo Basic</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main class="report-shell">
|
|
10
|
+
<header class="report-header">
|
|
11
|
+
<div>
|
|
12
|
+
<p class="eyebrow">Commercial operations</p>
|
|
13
|
+
<h1>Pipeline value and win rate</h1>
|
|
14
|
+
<p>Monthly qualified pipeline alongside the share converted to signed business.</p>
|
|
15
|
+
</div>
|
|
16
|
+
<aside class="period" aria-label="Reporting period">
|
|
17
|
+
<span>Reporting period</span>
|
|
18
|
+
<strong>FY 2026</strong>
|
|
19
|
+
</aside>
|
|
20
|
+
</header>
|
|
21
|
+
<section class="chart-panel" aria-label="Pipeline value and win rate chart">
|
|
22
|
+
<div id="chart"></div>
|
|
23
|
+
</section>
|
|
24
|
+
</main>
|
|
25
|
+
<script type="module" src="/src/main.ts"></script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|