@joplo-app/plugin-viz 0.0.0-stage → 0.9.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/LICENSE +97 -0
- package/dist/catalog.d.ts +8 -0
- package/dist/catalog.js +178 -0
- package/dist/components.d.ts +234 -0
- package/dist/components.js +55 -0
- package/dist/effects.d.ts +27 -0
- package/dist/effects.js +32 -0
- package/dist/guide.d.ts +3 -0
- package/dist/guide.js +79 -0
- package/dist/labels.json +12 -0
- package/dist/plugin.d.ts +6 -0
- package/dist/plugin.js +312 -0
- package/dist/runtime/bar-chart.d.ts +4 -0
- package/dist/runtime/bar-chart.js +193 -0
- package/dist/runtime/delta-bar.d.ts +4 -0
- package/dist/runtime/delta-bar.js +165 -0
- package/dist/runtime/heatmap.d.ts +4 -0
- package/dist/runtime/heatmap.js +138 -0
- package/dist/runtime/hooks.d.ts +36 -0
- package/dist/runtime/hooks.js +54 -0
- package/dist/runtime/line-chart.d.ts +4 -0
- package/dist/runtime/line-chart.js +197 -0
- package/dist/runtime/radar.d.ts +4 -0
- package/dist/runtime/radar.js +101 -0
- package/dist/runtime/ratio-bar.d.ts +4 -0
- package/dist/runtime/ratio-bar.js +77 -0
- package/dist/runtime/sankey.d.ts +4 -0
- package/dist/runtime/sankey.js +171 -0
- package/dist/runtime/scatter-plot.d.ts +4 -0
- package/dist/runtime/scatter-plot.js +202 -0
- package/dist/runtime/time-lanes.d.ts +4 -0
- package/dist/runtime/time-lanes.js +179 -0
- package/dist/runtime/tokens.d.ts +11 -0
- package/dist/runtime/tokens.js +51 -0
- package/dist/runtime/waterfall.d.ts +4 -0
- package/dist/runtime/waterfall.js +119 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +26 -0
- package/dist/schema.d.ts +202 -0
- package/dist/schema.js +255 -0
- package/dist/version.json +3 -0
- package/package.json +67 -3
- package/README.md +0 -3
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { scaleLinear } from 'd3-scale';
|
|
3
|
+
import { motion, useRoot } from '@joplo-app/kit/renderer';
|
|
4
|
+
import { formatDeltaPercent } from "../schema.js";
|
|
5
|
+
import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
|
|
6
|
+
import { DANGER, DIMMED, EASE_OUT_EXPO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SUBTLE, SURFACE, VIZ_FONT_SANS, arr, dim, formatNumber, num, str, tint, vizColor, } from "./tokens.js";
|
|
7
|
+
function DeltaRow({ item, index, baseline, scale, ticks, unit, variant, lowerIsBetter, baselineLabel, afterLabel, animate, dimmed, anchors, }) {
|
|
8
|
+
const anchorProps = useAnchorAttrs(anchors, item.id, item.label);
|
|
9
|
+
const current = item.value;
|
|
10
|
+
const changed = Math.abs(current - baseline) > 1e-6;
|
|
11
|
+
const improved = lowerIsBetter ? current < baseline : current > baseline;
|
|
12
|
+
const deltaTone = !changed ? DIMMED : improved ? OK : DANGER;
|
|
13
|
+
const deltaText = formatDeltaPercent(baseline, current, item.deltaLabel);
|
|
14
|
+
const basePct = Math.max(0, Math.min(100, scale(baseline)));
|
|
15
|
+
const curPct = Math.max(0, Math.min(100, scale(current)));
|
|
16
|
+
const barColor = item.color ? vizColor(item.color) : changed ? vizColor('indigo') : '#475569';
|
|
17
|
+
const delaySec = animate ? index * 0.12 : 0;
|
|
18
|
+
const barTrans = animate
|
|
19
|
+
? { duration: 0.78, delay: delaySec, ease: EASE_OUT_EXPO }
|
|
20
|
+
: { duration: 0 };
|
|
21
|
+
const revealTrans = animate
|
|
22
|
+
? { duration: 0.34, delay: delaySec + 0.34, ease: EASE_OUT_EXPO }
|
|
23
|
+
: { duration: 0 };
|
|
24
|
+
if (variant === 'paired') {
|
|
25
|
+
return (_jsxs("div", { ...anchorProps, style: {
|
|
26
|
+
display: 'grid',
|
|
27
|
+
gridTemplateColumns: 'minmax(112px, 154px) 1fr minmax(108px, 146px)',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
columnGap: 20,
|
|
30
|
+
opacity: dimmed ? 0.26 : 1,
|
|
31
|
+
transition: animate ? 'opacity 280ms ease' : undefined,
|
|
32
|
+
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 }, children: [_jsx("span", { style: { fontSize: 14.5, fontWeight: 800, color: INK }, children: item.label }), item.sub && _jsx("span", { style: { fontSize: 12, color: DIMMED }, children: item.sub })] }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 6 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 10 }, children: [_jsx("div", { style: { flex: 1, height: 14, borderRadius: 4, background: SUBTLE, overflow: 'hidden' }, children: _jsx("div", { style: { width: `${basePct}%`, height: '100%', borderRadius: 4, background: '#94a3b8' } }) }), _jsxs("span", { style: { fontFamily: MONO, fontSize: 11.5, color: DIMMED, minWidth: 60 }, children: [baselineLabel, " ", formatNumber(baseline, unit)] })] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 10 }, children: [_jsx("div", { style: { flex: 1, height: 18, borderRadius: 5, background: SUBTLE, overflow: 'hidden' }, children: _jsx(motion.div, { initial: false, animate: { width: `${curPct}%`, backgroundColor: barColor }, transition: barTrans, style: { height: '100%', borderRadius: 5 } }) }), _jsxs("span", { style: { fontFamily: MONO, fontSize: 12, fontWeight: 800, color: barColor, minWidth: 60 }, children: [afterLabel, " ", formatNumber(current, unit)] })] })] }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column', alignItems: 'flex-end', fontVariantNumeric: 'tabular-nums' }, children: [_jsx("span", { style: { fontFamily: MONO, fontSize: changed ? 18 : 13.5, fontWeight: changed ? 900 : 700, color: deltaTone }, children: changed ? deltaText : `${formatNumber(baseline, unit)} ${baselineLabel}` }), changed && item.note && _jsx("span", { style: { fontSize: 11.5, color: DIMMED }, children: item.note })] })] }));
|
|
33
|
+
}
|
|
34
|
+
// Default variant="ghost": curtain-uncover retract with dashed ghost baseline + staggered delta pill
|
|
35
|
+
const bandLeft = Math.min(curPct, basePct);
|
|
36
|
+
const bandWidth = Math.abs(basePct - curPct);
|
|
37
|
+
return (_jsxs("div", { ...anchorProps, style: {
|
|
38
|
+
display: 'grid',
|
|
39
|
+
gridTemplateColumns: 'minmax(112px, 154px) 1fr minmax(112px, 148px)',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
columnGap: 20,
|
|
42
|
+
padding: '4px 0',
|
|
43
|
+
opacity: dimmed ? 0.26 : 1,
|
|
44
|
+
transition: animate ? 'opacity 280ms ease' : undefined,
|
|
45
|
+
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 }, children: [_jsx("span", { style: { fontSize: 14.5, fontWeight: 800, color: INK }, children: item.label }), item.sub && _jsx("span", { style: { fontSize: 12, color: DIMMED }, children: item.sub })] }), _jsxs("div", { style: { position: 'relative', height: 46, borderRadius: 8, background: SUBTLE, overflow: 'hidden' }, children: [ticks.slice(1, -1).map((tk) => (_jsx("div", { style: {
|
|
46
|
+
position: 'absolute',
|
|
47
|
+
left: `${scale(tk)}%`,
|
|
48
|
+
top: 0,
|
|
49
|
+
bottom: 0,
|
|
50
|
+
borderLeft: `1px solid ${LINE}`,
|
|
51
|
+
pointerEvents: 'none',
|
|
52
|
+
} }, tk))), changed && (_jsx(motion.div, { initial: animate ? { opacity: 0 } : false, animate: { opacity: 1 }, transition: animate ? { duration: 0.24, delay: delaySec } : { duration: 0 }, style: {
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
left: 0,
|
|
55
|
+
top: 4,
|
|
56
|
+
width: `${Math.max(basePct, curPct)}%`,
|
|
57
|
+
height: 38,
|
|
58
|
+
borderRadius: 7,
|
|
59
|
+
background: tint(deltaTone, 14),
|
|
60
|
+
border: `1.5px dashed ${tint(deltaTone, 42)}`,
|
|
61
|
+
boxSizing: 'border-box',
|
|
62
|
+
zIndex: 1,
|
|
63
|
+
} })), _jsx(motion.div, { initial: false, animate: { width: `${curPct}%`, backgroundColor: barColor }, transition: barTrans, style: {
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
left: 0,
|
|
66
|
+
top: 4,
|
|
67
|
+
height: 38,
|
|
68
|
+
borderRadius: 7,
|
|
69
|
+
display: 'flex',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
justifyContent: 'flex-end',
|
|
72
|
+
paddingRight: curPct > 12 ? 12 : 6,
|
|
73
|
+
boxSizing: 'border-box',
|
|
74
|
+
zIndex: 2,
|
|
75
|
+
boxShadow: '0 2px 8px rgba(23, 24, 26, 0.08)',
|
|
76
|
+
overflow: 'hidden',
|
|
77
|
+
}, children: _jsx("span", { style: {
|
|
78
|
+
fontFamily: MONO,
|
|
79
|
+
fontSize: 12.5,
|
|
80
|
+
fontWeight: 800,
|
|
81
|
+
color: '#ffffff',
|
|
82
|
+
whiteSpace: 'nowrap',
|
|
83
|
+
}, children: changed ? formatNumber(current, unit) : `${baselineLabel} ${formatNumber(baseline, unit)}` }) }), changed && bandWidth >= 14 && (_jsx(motion.div, { initial: animate ? { opacity: 0, y: 6 } : false, animate: { opacity: 1, y: 0 }, transition: revealTrans, style: {
|
|
84
|
+
position: 'absolute',
|
|
85
|
+
left: `${bandLeft}%`,
|
|
86
|
+
width: `${bandWidth}%`,
|
|
87
|
+
top: 4,
|
|
88
|
+
height: 38,
|
|
89
|
+
display: 'flex',
|
|
90
|
+
alignItems: 'center',
|
|
91
|
+
justifyContent: 'center',
|
|
92
|
+
zIndex: 3,
|
|
93
|
+
pointerEvents: 'none',
|
|
94
|
+
}, children: _jsxs("span", { style: {
|
|
95
|
+
padding: '2px 9px',
|
|
96
|
+
borderRadius: 999,
|
|
97
|
+
background: SURFACE,
|
|
98
|
+
border: `1px solid ${tint(deltaTone, 36)}`,
|
|
99
|
+
fontFamily: MONO,
|
|
100
|
+
fontSize: 12,
|
|
101
|
+
fontWeight: 850,
|
|
102
|
+
color: deltaTone,
|
|
103
|
+
whiteSpace: 'nowrap',
|
|
104
|
+
}, children: [current < baseline ? '← ' : '→ ', deltaText] }) }))] }), _jsx("div", { style: {
|
|
105
|
+
display: 'flex',
|
|
106
|
+
flexDirection: 'column',
|
|
107
|
+
alignItems: 'flex-end',
|
|
108
|
+
gap: 2,
|
|
109
|
+
fontVariantNumeric: 'tabular-nums',
|
|
110
|
+
}, children: !changed ? (_jsxs("span", { style: { fontFamily: MONO, fontSize: 13.5, fontWeight: 700, color: DIMMED }, children: [formatNumber(baseline, unit), " ", baselineLabel] })) : (_jsxs(motion.div, { initial: animate ? { opacity: 0, y: 6 } : false, animate: { opacity: 1, y: 0 }, transition: revealTrans, style: { display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 1 }, children: [_jsx("span", { style: { fontFamily: MONO, fontSize: 19, fontWeight: 900, color: deltaTone }, children: deltaText }), _jsx("span", { style: { fontSize: 11.5, color: DIMMED, whiteSpace: 'nowrap' }, children: item.note ?? `${formatNumber(baseline, unit)} → ${formatNumber(current, unit)}` })] })) })] }));
|
|
111
|
+
}
|
|
112
|
+
export function DeltaBarView({ ctx }) {
|
|
113
|
+
const { node, p, animate, snap, anchors, isDimmed } = useVizChart(ctx);
|
|
114
|
+
const { items: rawItems, itemIds: _ids, title, subtitle, variant, domain: rawDomain, unit: rawUnit, lowerIsBetter, ticks: rawTicks, baselineLabel, afterLabel, showAxis, w, h, ...rest } = p;
|
|
115
|
+
const root = useRoot(node, rest, {
|
|
116
|
+
style: {
|
|
117
|
+
width: dim(w) ?? '100%',
|
|
118
|
+
height: dim(h),
|
|
119
|
+
minWidth: 0,
|
|
120
|
+
fontFamily: VIZ_FONT_SANS,
|
|
121
|
+
color: INK,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const items = arr(rawItems).filter((x) => !!x && typeof x === 'object' && typeof x.value === 'number');
|
|
125
|
+
if (!items.length)
|
|
126
|
+
return _jsx("div", { ...root, role: "status", children: "DeltaBar \u00B7 no items" });
|
|
127
|
+
const unit = str(rawUnit, '%');
|
|
128
|
+
const mode = variant === 'paired' ? 'paired' : 'ghost';
|
|
129
|
+
const baselines = items.map((item, i) => {
|
|
130
|
+
const key = item.id ?? String(i);
|
|
131
|
+
if (typeof item.baseline === 'number' && Number.isFinite(item.baseline))
|
|
132
|
+
return item.baseline;
|
|
133
|
+
if (snap.baselines && typeof snap.baselines[key] === 'number')
|
|
134
|
+
return snap.baselines[key];
|
|
135
|
+
return item.value;
|
|
136
|
+
});
|
|
137
|
+
const maxData = Math.max(1, ...items.map((x) => x.value), ...baselines);
|
|
138
|
+
const domain = Array.isArray(rawDomain) && typeof rawDomain[0] === 'number' && typeof rawDomain[1] === 'number'
|
|
139
|
+
? [rawDomain[0], rawDomain[1]]
|
|
140
|
+
: [0, maxData];
|
|
141
|
+
const scale = scaleLinear().domain(domain).range([0, 100]).clamp(true);
|
|
142
|
+
const ticks = Array.isArray(rawTicks) && rawTicks.every((t) => typeof t === 'number')
|
|
143
|
+
? rawTicks
|
|
144
|
+
: scale.ticks(4);
|
|
145
|
+
const anyChanged = items.some((item, i) => Math.abs(item.value - baselines[i]) > 1e-6);
|
|
146
|
+
return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'DeltaBar', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined }), showAxis !== false && mode === 'ghost' && (_jsxs("div", { style: {
|
|
147
|
+
display: 'grid',
|
|
148
|
+
gridTemplateColumns: 'minmax(112px, 154px) 1fr minmax(112px, 148px)',
|
|
149
|
+
alignItems: 'center',
|
|
150
|
+
columnGap: 20,
|
|
151
|
+
marginBottom: 10,
|
|
152
|
+
}, children: [_jsx("span", { style: { fontSize: 11.5, fontWeight: 700, color: DIMMED }, children: "\u6307\u6807" }), _jsx("div", { style: { position: 'relative', height: 18, fontFamily: MONO, fontSize: 11, color: DIMMED }, children: ticks.map((tk, i) => {
|
|
153
|
+
const pct = scale(tk);
|
|
154
|
+
const isFirst = i === 0;
|
|
155
|
+
const isLast = i === ticks.length - 1;
|
|
156
|
+
return (_jsx("span", { style: {
|
|
157
|
+
position: 'absolute',
|
|
158
|
+
left: `${pct}%`,
|
|
159
|
+
transform: isFirst ? 'none' : isLast ? 'translateX(-100%)' : 'translateX(-50%)',
|
|
160
|
+
fontWeight: isLast ? 750 : 500,
|
|
161
|
+
color: isLast ? INK2 : DIMMED,
|
|
162
|
+
whiteSpace: 'nowrap',
|
|
163
|
+
}, children: formatNumber(tk, unit) }, tk));
|
|
164
|
+
}) }), _jsx("span", { style: { fontSize: 11.5, fontWeight: 700, color: DIMMED, textAlign: 'right' }, children: anyChanged ? '实测变化' : '基准态' })] })), _jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: 16 }, children: items.map((item, index) => (_jsx(DeltaRow, { item: item, index: index, baseline: baselines[index], scale: scale, ticks: ticks, unit: unit, variant: mode, lowerIsBetter: item.lowerIsBetter ?? lowerIsBetter === true, baselineLabel: str(baselineLabel, '基准'), afterLabel: str(afterLabel, '新值'), animate: animate, dimmed: isDimmed(item.id, item.label), anchors: anchors }, item.id ?? `${item.label}_${index}`))) })] }));
|
|
165
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { motion, useRoot } from '@joplo-app/kit/renderer';
|
|
3
|
+
import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
|
|
4
|
+
import { ACCENT, DIMMED, EASE_OUT_EXPO, INK, INK2, MONO, VIZ_FONT_SANS, arr, dim, str, } from "./tokens.js";
|
|
5
|
+
const SEQ_RAMPS = {
|
|
6
|
+
indigo: [[241, 245, 255], [34, 49, 221]],
|
|
7
|
+
emerald: [[236, 253, 245], [15, 138, 95]],
|
|
8
|
+
amber: [[255, 251, 235], [217, 119, 6]],
|
|
9
|
+
crimson: [[254, 242, 242], [220, 38, 38]],
|
|
10
|
+
};
|
|
11
|
+
function lerpRgb(a, b, t) {
|
|
12
|
+
const c = Math.max(0, Math.min(1, t));
|
|
13
|
+
const r = Math.round(a[0] + (b[0] - a[0]) * c);
|
|
14
|
+
const g = Math.round(a[1] + (b[1] - a[1]) * c);
|
|
15
|
+
const bl = Math.round(a[2] + (b[2] - a[2]) * c);
|
|
16
|
+
return `rgb(${r}, ${g}, ${bl})`;
|
|
17
|
+
}
|
|
18
|
+
function cellColors(val, domain, scaleName) {
|
|
19
|
+
const [min, max] = domain;
|
|
20
|
+
const span = Math.max(1e-9, max - min);
|
|
21
|
+
if (scaleName === 'diverging') {
|
|
22
|
+
const mid = min < 0 && max > 0 ? 0 : (min + max) / 2;
|
|
23
|
+
const negSpan = Math.max(1e-9, mid - min);
|
|
24
|
+
const posSpan = Math.max(1e-9, max - mid);
|
|
25
|
+
if (val >= mid) {
|
|
26
|
+
const t = Math.min(1, (val - mid) / posSpan);
|
|
27
|
+
return {
|
|
28
|
+
bg: lerpRgb([248, 250, 252], [34, 49, 221], t),
|
|
29
|
+
fg: t >= 0.54 ? '#ffffff' : INK,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const t = Math.min(1, (mid - val) / negSpan);
|
|
33
|
+
return {
|
|
34
|
+
bg: lerpRgb([248, 250, 252], [220, 38, 38], t),
|
|
35
|
+
fg: t >= 0.54 ? '#ffffff' : INK,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const t = Math.max(0, Math.min(1, (val - min) / span));
|
|
39
|
+
const [lo, hi] = SEQ_RAMPS[scaleName];
|
|
40
|
+
return {
|
|
41
|
+
bg: lerpRgb(lo, hi, t),
|
|
42
|
+
fg: t >= 0.52 ? '#ffffff' : INK,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function formatCellValue(v, fmt) {
|
|
46
|
+
if (!Number.isFinite(v))
|
|
47
|
+
return '—';
|
|
48
|
+
if (fmt === 'percent')
|
|
49
|
+
return `${Math.round(v * 100)}%`;
|
|
50
|
+
if (fmt === 'int')
|
|
51
|
+
return String(Math.round(v));
|
|
52
|
+
return v.toFixed(2);
|
|
53
|
+
}
|
|
54
|
+
function HeatmapCell({ ri, ci, rowLabel, colLabel, value, text, bg, fg, cellId, dimmed, emphasized, animate, anchors, }) {
|
|
55
|
+
const anchorProps = useAnchorAttrs(anchors, cellId, `${rowLabel} × ${colLabel}: ${text}`);
|
|
56
|
+
return (_jsx(motion.div, { ...anchorProps, "data-jcell": `${ri}:${ci}`, title: `${rowLabel} × ${colLabel}: ${value}`, initial: false, animate: { opacity: dimmed ? 0.2 : 1, scale: emphasized ? 1.03 : 1 }, transition: animate ? { duration: 0.28, ease: EASE_OUT_EXPO } : { duration: 0 }, style: {
|
|
57
|
+
height: 44,
|
|
58
|
+
borderRadius: 8,
|
|
59
|
+
background: bg,
|
|
60
|
+
color: fg,
|
|
61
|
+
display: 'flex',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
justifyContent: 'center',
|
|
64
|
+
fontFamily: MONO,
|
|
65
|
+
fontSize: 12.5,
|
|
66
|
+
fontWeight: emphasized ? 900 : 750,
|
|
67
|
+
boxShadow: emphasized ? `0 0 0 2px ${ACCENT}` : undefined,
|
|
68
|
+
fontVariantNumeric: 'tabular-nums',
|
|
69
|
+
}, children: text }));
|
|
70
|
+
}
|
|
71
|
+
export function HeatmapView({ ctx }) {
|
|
72
|
+
const { node, p, animate, anchors, focusSet, isDimmed } = useVizChart(ctx);
|
|
73
|
+
const { title, subtitle, rows: rawRows, cols: rawCols, values: rawValues, domain: rawDomain, colorScale, format: rawFormat, cornerLabel, showScale, cellAnchors: rawCellAnchors, cellIds: _cids, w, h, ...rest } = p;
|
|
74
|
+
const root = useRoot(node, rest, {
|
|
75
|
+
style: {
|
|
76
|
+
width: dim(w) ?? '100%',
|
|
77
|
+
height: dim(h),
|
|
78
|
+
minWidth: 0,
|
|
79
|
+
fontFamily: VIZ_FONT_SANS,
|
|
80
|
+
color: INK,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
const rows = arr(rawRows).map((r) => str(r));
|
|
84
|
+
const cols = arr(rawCols).map((c) => str(c));
|
|
85
|
+
const values = arr(rawValues).map((row) => arr(row).map((v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0)));
|
|
86
|
+
if (!rows.length || !cols.length || !values.length) {
|
|
87
|
+
return _jsx("div", { ...root, role: "status", children: "Heatmap \u00B7 no data" });
|
|
88
|
+
}
|
|
89
|
+
const flat = values.flat();
|
|
90
|
+
const minVal = Math.min(...flat);
|
|
91
|
+
const maxVal = Math.max(...flat);
|
|
92
|
+
const domain = Array.isArray(rawDomain) && typeof rawDomain[0] === 'number' && typeof rawDomain[1] === 'number'
|
|
93
|
+
? [rawDomain[0], rawDomain[1]]
|
|
94
|
+
: [minVal, maxVal === minVal ? minVal + 1 : maxVal];
|
|
95
|
+
const scaleName = colorScale === 'emerald' || colorScale === 'amber' || colorScale === 'crimson' || colorScale === 'diverging'
|
|
96
|
+
? colorScale
|
|
97
|
+
: 'indigo';
|
|
98
|
+
const fmt = typeof rawFormat === 'string' ? rawFormat : 'fixed2';
|
|
99
|
+
const cellAnchors = rawCellAnchors && typeof rawCellAnchors === 'object'
|
|
100
|
+
? rawCellAnchors
|
|
101
|
+
: {};
|
|
102
|
+
const gradientCss = scaleName === 'diverging'
|
|
103
|
+
? `linear-gradient(90deg, ${lerpRgb([220, 38, 38], [220, 38, 38], 1)}, rgb(248,250,252), ${lerpRgb([34, 49, 221], [34, 49, 221], 1)})`
|
|
104
|
+
: `linear-gradient(90deg, ${lerpRgb(SEQ_RAMPS[scaleName][0], SEQ_RAMPS[scaleName][1], 0)}, ${lerpRgb(SEQ_RAMPS[scaleName][0], SEQ_RAMPS[scaleName][1], 1)})`;
|
|
105
|
+
return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'Heatmap', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined }), _jsxs("div", { style: {
|
|
106
|
+
display: 'grid',
|
|
107
|
+
gridTemplateColumns: `minmax(58px, auto) repeat(${cols.length}, minmax(44px, 1fr))`,
|
|
108
|
+
gap: 7,
|
|
109
|
+
alignItems: 'center',
|
|
110
|
+
}, children: [_jsx("div", { style: { fontSize: 11.5, fontFamily: MONO, color: DIMMED, paddingRight: 4 }, children: str(cornerLabel) }), cols.map((col) => {
|
|
111
|
+
const colFocused = focusSet ? focusSet.has(`col:${col}`) || focusSet.has(col) : false;
|
|
112
|
+
return (_jsx("div", { style: {
|
|
113
|
+
textAlign: 'center',
|
|
114
|
+
fontSize: 12.5,
|
|
115
|
+
fontWeight: colFocused ? 850 : 700,
|
|
116
|
+
color: colFocused ? ACCENT : INK2,
|
|
117
|
+
paddingBottom: 2,
|
|
118
|
+
whiteSpace: 'nowrap',
|
|
119
|
+
}, children: col }, col));
|
|
120
|
+
}), rows.map((rowLabel, ri) => {
|
|
121
|
+
const rowFocused = focusSet ? focusSet.has(`row:${rowLabel}`) || focusSet.has(rowLabel) : false;
|
|
122
|
+
return (_jsxs("div", { style: { display: 'contents' }, children: [_jsx("div", { style: {
|
|
123
|
+
fontSize: 12.5,
|
|
124
|
+
fontWeight: rowFocused ? 850 : 700,
|
|
125
|
+
color: rowFocused ? ACCENT : INK2,
|
|
126
|
+
paddingRight: 8,
|
|
127
|
+
whiteSpace: 'nowrap',
|
|
128
|
+
}, children: rowLabel }), cols.map((colLabel, ci) => {
|
|
129
|
+
const v = values[ri]?.[ci] ?? 0;
|
|
130
|
+
const { bg, fg } = cellColors(v, domain, scaleName);
|
|
131
|
+
const cellId = cellAnchors[`${ri}:${ci}`];
|
|
132
|
+
const cellKey = `cell:${ri}:${ci}`;
|
|
133
|
+
const dimmed = isDimmed(cellId, cellKey, `row:${rowLabel}`, `col:${colLabel}`, rowLabel, colLabel);
|
|
134
|
+
const emphasized = !!focusSet && !dimmed && (focusSet.has(cellKey) || (!!cellId && focusSet.has(cellId)));
|
|
135
|
+
return (_jsx(HeatmapCell, { ri: ri, ci: ci, rowLabel: rowLabel, colLabel: colLabel, value: v, text: formatCellValue(v, fmt), bg: bg, fg: fg, cellId: cellId, dimmed: dimmed, emphasized: emphasized, animate: animate, anchors: anchors }, `${ri}_${ci}`));
|
|
136
|
+
})] }, `${rowLabel}_${ri}`));
|
|
137
|
+
})] }), showScale !== false && (_jsxs("div", { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10, marginTop: 14 }, children: [_jsx("span", { style: { fontFamily: MONO, fontSize: 11.5, color: DIMMED }, children: formatCellValue(domain[0], fmt) }), _jsx("div", { style: { flex: 1, maxWidth: 160, height: 8, borderRadius: 999, background: gradientCss } }), _jsx("span", { style: { fontFamily: MONO, fontSize: 11.5, fontWeight: 700, color: INK2 }, children: formatCellValue(domain[1], fmt) })] }))] }));
|
|
138
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ComponentCtx, PluginIRNode } from '@joplo-app/kit/plugin';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export declare function useVizChart(ctx: ComponentCtx): {
|
|
4
|
+
node: PluginIRNode;
|
|
5
|
+
p: Record<string, unknown>;
|
|
6
|
+
animate: boolean;
|
|
7
|
+
snap: {
|
|
8
|
+
focus?: string[] | null | undefined;
|
|
9
|
+
reveal?: string | number | null | undefined;
|
|
10
|
+
cursor?: {
|
|
11
|
+
value: string | number;
|
|
12
|
+
label?: string | undefined;
|
|
13
|
+
} | null | undefined;
|
|
14
|
+
baselines?: Record<string, number> | undefined;
|
|
15
|
+
};
|
|
16
|
+
anchors: Map<string, PluginIRNode>;
|
|
17
|
+
focusSet: Set<string> | null;
|
|
18
|
+
isDimmed: (...keys: (string | undefined)[]) => boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function useAnchorAttrs(anchors: Map<string, PluginIRNode>, id: string | undefined, label?: string): {};
|
|
21
|
+
export declare function ChartHeader({ title, subtitle, right }: {
|
|
22
|
+
title?: string;
|
|
23
|
+
subtitle?: string;
|
|
24
|
+
right?: ReactNode;
|
|
25
|
+
}): import("react").JSX.Element | null;
|
|
26
|
+
export declare const chartCardStyle: {
|
|
27
|
+
width: string;
|
|
28
|
+
minWidth: number;
|
|
29
|
+
fontFamily: string;
|
|
30
|
+
color: string;
|
|
31
|
+
background: string;
|
|
32
|
+
border: string;
|
|
33
|
+
borderRadius: number;
|
|
34
|
+
padding: string;
|
|
35
|
+
boxSizing: "border-box";
|
|
36
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRootAttrs } from '@joplo-app/kit/renderer';
|
|
3
|
+
import { DIMMED, INK, LINE, SURFACE, VIZ_FONT_SANS } from "./tokens.js";
|
|
4
|
+
export function useVizChart(ctx) {
|
|
5
|
+
const node = ctx.model;
|
|
6
|
+
const p = ctx.node.props;
|
|
7
|
+
const animate = ctx.frame.animate;
|
|
8
|
+
const frame = ctx.ext.viz;
|
|
9
|
+
const snap = frame?.charts?.[node.id] ?? {};
|
|
10
|
+
const anchors = new Map();
|
|
11
|
+
for (const child of node.children ?? [])
|
|
12
|
+
anchors.set(child.id, child);
|
|
13
|
+
const focusSet = snap.focus && snap.focus.length > 0 ? new Set(snap.focus) : null;
|
|
14
|
+
const isDimmed = (...keys) => {
|
|
15
|
+
if (!focusSet)
|
|
16
|
+
return false;
|
|
17
|
+
return !keys.some((k) => k !== undefined && focusSet.has(k));
|
|
18
|
+
};
|
|
19
|
+
return { node, p, animate, snap, anchors, focusSet, isDimmed };
|
|
20
|
+
}
|
|
21
|
+
export function useAnchorAttrs(anchors, id, label) {
|
|
22
|
+
const anchor = id ? anchors.get(id) : undefined;
|
|
23
|
+
const attrs = useRootAttrs(anchor ?? { id: id ?? '', type: 'Custom' });
|
|
24
|
+
if (!id)
|
|
25
|
+
return {};
|
|
26
|
+
return {
|
|
27
|
+
...attrs,
|
|
28
|
+
'data-jframe': 'content',
|
|
29
|
+
...(label ? { 'data-jlabel': label } : {}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function ChartHeader({ title, subtitle, right }) {
|
|
33
|
+
if (!title && !subtitle && !right)
|
|
34
|
+
return null;
|
|
35
|
+
return (_jsxs("div", { style: {
|
|
36
|
+
display: 'flex',
|
|
37
|
+
alignItems: 'baseline',
|
|
38
|
+
justifyContent: 'space-between',
|
|
39
|
+
gap: 16,
|
|
40
|
+
marginBottom: 14,
|
|
41
|
+
fontFamily: VIZ_FONT_SANS,
|
|
42
|
+
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0 }, children: [title && _jsx("span", { style: { fontSize: 16, fontWeight: 850, color: INK, letterSpacing: -0.2 }, children: title }), subtitle && _jsx("span", { style: { fontSize: 12.5, color: DIMMED }, children: subtitle })] }), right] }));
|
|
43
|
+
}
|
|
44
|
+
export const chartCardStyle = {
|
|
45
|
+
width: '100%',
|
|
46
|
+
minWidth: 0,
|
|
47
|
+
fontFamily: VIZ_FONT_SANS,
|
|
48
|
+
color: INK,
|
|
49
|
+
background: SURFACE,
|
|
50
|
+
border: `1px solid ${LINE}`,
|
|
51
|
+
borderRadius: 14,
|
|
52
|
+
padding: '18px 22px',
|
|
53
|
+
boxSizing: 'border-box',
|
|
54
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { scaleLinear, scalePoint } from 'd3-scale';
|
|
3
|
+
import { area as d3Area, curveLinear, curveMonotoneX, line as d3Line } from 'd3-shape';
|
|
4
|
+
import { motion, useRoot } from '@joplo-app/kit/renderer';
|
|
5
|
+
import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
|
|
6
|
+
import { DIMMED, EASE_OUT_CUBIC, INK, LINE, LINE_STRONG, MONO, SURFACE, VIZ_FONT_SANS, arr, dim, formatNumber, num, str, tint, vizColor, } from "./tokens.js";
|
|
7
|
+
function LinePointDot({ seriesName, idx, ptId, label, valueText, pxPct, py, color, isFocused, showVal, animate, anchors, }) {
|
|
8
|
+
const anchorProps = useAnchorAttrs(anchors, ptId, `${label} ${valueText}`);
|
|
9
|
+
const labelBelow = py < 26;
|
|
10
|
+
return (_jsx(motion.div, { ...anchorProps, "data-jpoint": `${seriesName}:${idx}`, initial: animate ? { scale: 0.4, opacity: 0 } : false, animate: { scale: 1, opacity: isFocused ? 1 : 0.25 }, transition: animate ? { duration: 0.26, delay: idx * 0.06 } : { duration: 0 }, style: {
|
|
11
|
+
position: 'absolute',
|
|
12
|
+
left: `${pxPct}%`,
|
|
13
|
+
top: py,
|
|
14
|
+
width: 11,
|
|
15
|
+
height: 11,
|
|
16
|
+
marginLeft: -5.5,
|
|
17
|
+
marginTop: -5.5,
|
|
18
|
+
borderRadius: '50%',
|
|
19
|
+
background: SURFACE,
|
|
20
|
+
border: `2.5px solid ${color}`,
|
|
21
|
+
boxSizing: 'border-box',
|
|
22
|
+
zIndex: 3,
|
|
23
|
+
}, children: showVal && (_jsx("span", { style: {
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
left: '50%',
|
|
26
|
+
top: labelBelow ? 13 : -22,
|
|
27
|
+
transform: 'translateX(-50%)',
|
|
28
|
+
fontFamily: MONO,
|
|
29
|
+
fontSize: 11.5,
|
|
30
|
+
fontWeight: 850,
|
|
31
|
+
color: INK,
|
|
32
|
+
whiteSpace: 'nowrap',
|
|
33
|
+
pointerEvents: 'none',
|
|
34
|
+
}, children: valueText })) }));
|
|
35
|
+
}
|
|
36
|
+
export function LineChartView({ ctx }) {
|
|
37
|
+
const { node, p, animate, snap, anchors, isDimmed } = useVizChart(ctx);
|
|
38
|
+
const { title, subtitle, data: rawData, dataKey, series: rawSeries, unit: rawUnit, yDomain: rawYDomain, curve, referenceLine, referenceBand, revealTo: propReveal, directLabels, withLegend, pointIds: _pids, w, h, ...rest } = p;
|
|
39
|
+
const H = num(h, 240);
|
|
40
|
+
const root = useRoot(node, rest, {
|
|
41
|
+
style: {
|
|
42
|
+
width: dim(w) ?? '100%',
|
|
43
|
+
minWidth: 0,
|
|
44
|
+
fontFamily: VIZ_FONT_SANS,
|
|
45
|
+
color: INK,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const rows = arr(rawData).filter((r) => !!r && typeof r === 'object');
|
|
49
|
+
const key = str(dataKey);
|
|
50
|
+
const series = arr(rawSeries)
|
|
51
|
+
.filter((s) => !!s && typeof s === 'object' && typeof s.name === 'string')
|
|
52
|
+
.map((s, i) => ({
|
|
53
|
+
name: s.name,
|
|
54
|
+
label: s.label ?? s.name,
|
|
55
|
+
color: vizColor(s.color, i),
|
|
56
|
+
area: s.area === true,
|
|
57
|
+
dashed: s.dashed === true,
|
|
58
|
+
}));
|
|
59
|
+
if (!rows.length || !series.length)
|
|
60
|
+
return _jsx("div", { ...root, role: "status", children: "LineChart \u00B7 no data" });
|
|
61
|
+
const unit = str(rawUnit);
|
|
62
|
+
const labels = rows.map((r) => str(r[key]));
|
|
63
|
+
const refLine = referenceLine && typeof referenceLine === 'object' && typeof referenceLine.value === 'number'
|
|
64
|
+
? referenceLine
|
|
65
|
+
: null;
|
|
66
|
+
const refBand = referenceBand &&
|
|
67
|
+
typeof referenceBand === 'object' &&
|
|
68
|
+
typeof referenceBand.from === 'number' &&
|
|
69
|
+
typeof referenceBand.to === 'number'
|
|
70
|
+
? referenceBand
|
|
71
|
+
: null;
|
|
72
|
+
const allVals = [
|
|
73
|
+
...series.flatMap((s) => rows.map((r) => (typeof r[s.name] === 'number' && Number.isFinite(r[s.name]) ? r[s.name] : 0))),
|
|
74
|
+
...(refLine ? [refLine.value] : []),
|
|
75
|
+
...(refBand ? [refBand.from, refBand.to] : []),
|
|
76
|
+
];
|
|
77
|
+
const minVal = Math.min(0, ...allVals);
|
|
78
|
+
const maxVal = Math.max(1, ...allVals);
|
|
79
|
+
const yDomain = Array.isArray(rawYDomain) && typeof rawYDomain[0] === 'number' && typeof rawYDomain[1] === 'number'
|
|
80
|
+
? [rawYDomain[0], rawYDomain[1]]
|
|
81
|
+
: [minVal, maxVal * 1.08];
|
|
82
|
+
const showLegend = withLegend === true || (withLegend !== false && series.length > 1);
|
|
83
|
+
const plotH = Math.max(120, H - (showLegend ? 54 : 32));
|
|
84
|
+
const vbW = 1000;
|
|
85
|
+
const vbH = plotH;
|
|
86
|
+
const padX = 28;
|
|
87
|
+
const padTop = 14;
|
|
88
|
+
const padBot = 10;
|
|
89
|
+
const xScale = scalePoint()
|
|
90
|
+
.domain(rows.map((_, i) => i))
|
|
91
|
+
.range([padX, vbW - padX]);
|
|
92
|
+
const yScale = scaleLinear().domain(yDomain).range([vbH - padBot, padTop]);
|
|
93
|
+
const yTicks = yScale.ticks(4);
|
|
94
|
+
// Reveal cutoff (effect snapshot wins over prop)
|
|
95
|
+
const cutoff = snap.reveal !== undefined ? snap.reveal : propReveal;
|
|
96
|
+
let visibleCount = rows.length;
|
|
97
|
+
if (typeof cutoff === 'number' && Number.isFinite(cutoff)) {
|
|
98
|
+
visibleCount = Math.max(1, Math.min(rows.length, Math.round(cutoff)));
|
|
99
|
+
}
|
|
100
|
+
else if (typeof cutoff === 'string') {
|
|
101
|
+
const idx = rows.findIndex((r, i) => labels[i] === cutoff || r.id === cutoff);
|
|
102
|
+
if (idx >= 0)
|
|
103
|
+
visibleCount = idx + 1;
|
|
104
|
+
}
|
|
105
|
+
const clipPct = visibleCount >= rows.length ? 100 : ((xScale(visibleCount - 1) ?? vbW) + 18) / vbW * 100;
|
|
106
|
+
const curveFactory = curve === 'monotone' ? curveMonotoneX : curveLinear;
|
|
107
|
+
const lineGen = d3Line()
|
|
108
|
+
.x((d) => d[0])
|
|
109
|
+
.y((d) => d[1])
|
|
110
|
+
.curve(curveFactory);
|
|
111
|
+
const areaGen = d3Area()
|
|
112
|
+
.x((d) => d[0])
|
|
113
|
+
.y0(yScale(Math.max(yDomain[0], 0)))
|
|
114
|
+
.y1((d) => d[1])
|
|
115
|
+
.curve(curveFactory);
|
|
116
|
+
const revealTrans = animate ? { duration: 0.85, ease: EASE_OUT_CUBIC } : { duration: 0 };
|
|
117
|
+
return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'LineChart', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: '52px 1fr', columnGap: 12, alignItems: 'start' }, children: [_jsx("div", { style: { position: 'relative', height: plotH, fontFamily: MONO, fontSize: 11, color: DIMMED, textAlign: 'right' }, children: yTicks.map((tk) => (_jsx("span", { style: {
|
|
118
|
+
position: 'absolute',
|
|
119
|
+
right: 0,
|
|
120
|
+
top: yScale(tk),
|
|
121
|
+
transform: 'translateY(-50%)',
|
|
122
|
+
whiteSpace: 'nowrap',
|
|
123
|
+
}, children: formatNumber(tk, unit) }, tk))) }), _jsxs("div", { style: { position: 'relative', width: '100%', height: plotH + 28 }, children: [yTicks.map((tk) => (_jsx("div", { style: {
|
|
124
|
+
position: 'absolute',
|
|
125
|
+
left: 0,
|
|
126
|
+
right: 0,
|
|
127
|
+
top: yScale(tk),
|
|
128
|
+
borderTop: tk === yDomain[0] ? `1.5px solid ${LINE_STRONG}` : `1px solid ${LINE}`,
|
|
129
|
+
pointerEvents: 'none',
|
|
130
|
+
} }, tk))), refBand && (_jsx("div", { style: {
|
|
131
|
+
position: 'absolute',
|
|
132
|
+
left: 0,
|
|
133
|
+
right: 0,
|
|
134
|
+
top: Math.min(yScale(refBand.from), yScale(refBand.to)),
|
|
135
|
+
height: Math.abs(yScale(refBand.from) - yScale(refBand.to)),
|
|
136
|
+
background: tint(refBand.color ? vizColor(refBand.color) : vizColor('ok'), 12),
|
|
137
|
+
pointerEvents: 'none',
|
|
138
|
+
} })), refLine && (_jsx("div", { style: {
|
|
139
|
+
position: 'absolute',
|
|
140
|
+
left: 0,
|
|
141
|
+
right: 0,
|
|
142
|
+
top: yScale(refLine.value),
|
|
143
|
+
borderTop: `1.5px dashed ${refLine.color ? vizColor(refLine.color) : vizColor('ok')}`,
|
|
144
|
+
pointerEvents: 'none',
|
|
145
|
+
zIndex: 1,
|
|
146
|
+
}, children: refLine.label && (_jsx("span", { style: {
|
|
147
|
+
position: 'absolute',
|
|
148
|
+
right: 54,
|
|
149
|
+
top: -20,
|
|
150
|
+
fontSize: 11,
|
|
151
|
+
fontWeight: 800,
|
|
152
|
+
fontFamily: MONO,
|
|
153
|
+
color: refLine.color ? vizColor(refLine.color) : vizColor('ok'),
|
|
154
|
+
background: SURFACE,
|
|
155
|
+
padding: '1px 6px',
|
|
156
|
+
borderRadius: 4,
|
|
157
|
+
whiteSpace: 'nowrap',
|
|
158
|
+
}, children: refLine.label })) })), _jsx(motion.div, { initial: false, animate: { width: `${clipPct}%` }, transition: revealTrans, style: {
|
|
159
|
+
position: 'absolute',
|
|
160
|
+
left: 0,
|
|
161
|
+
top: 0,
|
|
162
|
+
height: plotH,
|
|
163
|
+
overflow: 'hidden',
|
|
164
|
+
zIndex: 2,
|
|
165
|
+
}, children: _jsx("svg", { viewBox: `0 0 ${vbW} ${vbH}`, preserveAspectRatio: "none", style: { width: `${(100 / Math.max(clipPct, 0.1)) * 100}%`, height: plotH, display: 'block', overflow: 'visible' }, children: series.map((s) => {
|
|
166
|
+
const pts = rows.map((r, i) => [
|
|
167
|
+
xScale(i) ?? 0,
|
|
168
|
+
yScale(typeof r[s.name] === 'number' && Number.isFinite(r[s.name]) ? r[s.name] : 0),
|
|
169
|
+
]);
|
|
170
|
+
const dLine = lineGen(pts) ?? '';
|
|
171
|
+
const dArea = s.area ? (areaGen(pts) ?? '') : '';
|
|
172
|
+
const dimmed = isDimmed(s.name, s.label);
|
|
173
|
+
return (_jsxs("g", { style: { opacity: dimmed ? 0.22 : 1 }, children: [dArea && _jsx("path", { d: dArea, fill: s.color, fillOpacity: 0.11 }), _jsx("path", { d: dLine, fill: "none", stroke: s.color, strokeWidth: 2.6, strokeDasharray: s.dashed ? '6 5' : undefined, strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke" })] }, s.name));
|
|
174
|
+
}) }) }), series.map((s, si) => {
|
|
175
|
+
const dimmedSeries = isDimmed(s.name, s.label);
|
|
176
|
+
return rows.map((r, idx) => {
|
|
177
|
+
if (idx >= visibleCount)
|
|
178
|
+
return null;
|
|
179
|
+
const rawV = typeof r[s.name] === 'number' && Number.isFinite(r[s.name]) ? r[s.name] : 0;
|
|
180
|
+
const pxPct = ((xScale(idx) ?? 0) / vbW) * 100;
|
|
181
|
+
const py = yScale(rawV);
|
|
182
|
+
const ptId = si === 0 && typeof r.id === 'string' ? r.id : undefined;
|
|
183
|
+
const isFocusedPt = ptId ? !isDimmed(ptId) : !dimmedSeries;
|
|
184
|
+
const showVal = directLabels !== false && series.length === 1;
|
|
185
|
+
return (_jsx(LinePointDot, { seriesName: s.name, idx: idx, ptId: ptId, label: labels[idx] ?? '', valueText: formatNumber(rawV, unit), pxPct: pxPct, py: py, color: s.color, isFocused: isFocusedPt, showVal: showVal, animate: animate, anchors: anchors }, `${s.name}_${idx}`));
|
|
186
|
+
});
|
|
187
|
+
}), labels.map((lbl, idx) => (_jsx("span", { style: {
|
|
188
|
+
position: 'absolute',
|
|
189
|
+
left: `${((xScale(idx) ?? 0) / vbW) * 100}%`,
|
|
190
|
+
top: plotH + 8,
|
|
191
|
+
transform: 'translateX(-50%)',
|
|
192
|
+
fontSize: 12,
|
|
193
|
+
fontWeight: 650,
|
|
194
|
+
color: DIMMED,
|
|
195
|
+
whiteSpace: 'nowrap',
|
|
196
|
+
}, children: lbl }, `${lbl}_${idx}`)))] })] }), showLegend && (_jsx("div", { style: { display: 'flex', flexWrap: 'wrap', gap: 14, justifyContent: 'center', marginTop: 10, fontSize: 12, color: DIMMED }, children: series.map((s) => (_jsxs("span", { style: { display: 'inline-flex', alignItems: 'center', gap: 6 }, children: [_jsx("span", { "aria-hidden": true, style: { width: 12, height: 3, borderRadius: 2, background: s.color } }), s.label] }, s.name))) }))] }));
|
|
197
|
+
}
|