@joplo-app/plugin-viz 0.0.0-stage → 0.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/LICENSE +97 -0
- package/dist/catalog.d.ts +8 -0
- package/dist/catalog.js +178 -0
- package/dist/components.d.ts +236 -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 +204 -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,101 @@
|
|
|
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 { DIMMED, EASE_OUT_EXPO, INK, LINE, LINE_STRONG, MONO, SURFACE, VIZ_FONT_SANS, arr, dim, num, str, vizColor, } from "./tokens.js";
|
|
5
|
+
function polarPoint(cx, cy, r, index, count) {
|
|
6
|
+
const angle = -Math.PI / 2 + (index * 2 * Math.PI) / count;
|
|
7
|
+
return [cx + r * Math.cos(angle), cy + r * Math.sin(angle)];
|
|
8
|
+
}
|
|
9
|
+
function polygonPoints(pts) {
|
|
10
|
+
return pts.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(' ');
|
|
11
|
+
}
|
|
12
|
+
function RadarSeriesLayer({ seriesItem, axes, defaultMax, cx, cy, radius, color, dimmed, animate, anchors, }) {
|
|
13
|
+
const anchorProps = useAnchorAttrs(anchors, seriesItem.id, seriesItem.name);
|
|
14
|
+
const count = axes.length;
|
|
15
|
+
const pts = axes.map((ax, i) => {
|
|
16
|
+
const raw = Array.isArray(seriesItem.values)
|
|
17
|
+
? seriesItem.values[i]
|
|
18
|
+
: seriesItem.values[ax.key];
|
|
19
|
+
const val = typeof raw === 'number' && Number.isFinite(raw) ? raw : 0;
|
|
20
|
+
const maxV = typeof ax.max === 'number' && ax.max > 0 ? ax.max : defaultMax;
|
|
21
|
+
const frac = Math.max(0, Math.min(1, val / maxV));
|
|
22
|
+
return polarPoint(cx, cy, radius * frac, i, count);
|
|
23
|
+
});
|
|
24
|
+
return (_jsxs(motion.g, { ...anchorProps, "data-jseries": seriesItem.id ?? seriesItem.name, initial: false, animate: { opacity: dimmed ? 0.16 : 1 }, transition: animate ? { duration: 0.3, ease: EASE_OUT_EXPO } : { duration: 0 }, children: [_jsx("polygon", { points: polygonPoints(pts), fill: color, fillOpacity: seriesItem.dashed ? 0.08 : 0.16, stroke: color, strokeWidth: seriesItem.dashed ? 2 : 2.6, strokeDasharray: seriesItem.dashed ? '5 4' : undefined, strokeLinejoin: "round" }), pts.map(([x, y], i) => (_jsx("circle", { cx: x, cy: y, r: seriesItem.dashed ? 3.2 : 4.2, fill: SURFACE, stroke: color, strokeWidth: 2.2 }, i)))] }));
|
|
25
|
+
}
|
|
26
|
+
export function RadarView({ ctx }) {
|
|
27
|
+
const { node, p, animate, anchors, isDimmed } = useVizChart(ctx);
|
|
28
|
+
const { title, subtitle, axes: rawAxes, series: rawSeries, levels: rawLevels, max: rawMax, showTicks, seriesIds: _sids, w, h, ...rest } = p;
|
|
29
|
+
const H = num(h, 280);
|
|
30
|
+
const root = useRoot(node, rest, {
|
|
31
|
+
style: {
|
|
32
|
+
width: dim(w) ?? '100%',
|
|
33
|
+
minWidth: 0,
|
|
34
|
+
fontFamily: VIZ_FONT_SANS,
|
|
35
|
+
color: INK,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const axes = arr(rawAxes).filter((a) => !!a && typeof a === 'object' && typeof a.key === 'string');
|
|
39
|
+
const series = arr(rawSeries).filter((s) => !!s && typeof s === 'object' && typeof s.name === 'string');
|
|
40
|
+
if (axes.length < 3 || !series.length) {
|
|
41
|
+
return _jsx("div", { ...root, role: "status", children: "Radar \u00B7 requires at least 3 axes and 1 series" });
|
|
42
|
+
}
|
|
43
|
+
const levels = Math.max(2, Math.min(6, Math.round(num(rawLevels, 3))));
|
|
44
|
+
const maxVal = Math.max(1, num(rawMax, 100));
|
|
45
|
+
const size = Math.max(210, H - 36);
|
|
46
|
+
const vb = 340;
|
|
47
|
+
const cx = vb / 2;
|
|
48
|
+
const cy = vb / 2;
|
|
49
|
+
const radius = 104;
|
|
50
|
+
const seriesPalette = series.map((s, i) => ({
|
|
51
|
+
...s,
|
|
52
|
+
resolvedColor: vizColor(s.color, i),
|
|
53
|
+
}));
|
|
54
|
+
return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'Radar', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined, right: _jsx("div", { style: { display: 'flex', flexWrap: 'wrap', gap: 12, fontSize: 12, color: DIMMED }, children: seriesPalette.map((s) => (_jsxs("span", { style: { display: 'inline-flex', alignItems: 'center', gap: 6, fontWeight: 700, color: INK }, children: [_jsx("span", { "aria-hidden": true, style: {
|
|
55
|
+
width: 12,
|
|
56
|
+
height: 3,
|
|
57
|
+
borderRadius: 2,
|
|
58
|
+
background: s.resolvedColor,
|
|
59
|
+
borderBottom: s.dashed ? `1px dashed ${s.resolvedColor}` : undefined,
|
|
60
|
+
} }), s.name] }, s.id ?? s.name))) }) }), _jsxs("div", { style: { position: 'relative', width: size, height: size, margin: '0 auto' }, children: [_jsxs("svg", { viewBox: `0 0 ${vb} ${vb}`, style: { width: '100%', height: '100%', display: 'block', overflow: 'visible' }, children: [Array.from({ length: levels }, (_, idx) => {
|
|
61
|
+
const frac = (idx + 1) / levels;
|
|
62
|
+
const ringPts = axes.map((_, ai) => polarPoint(cx, cy, radius * frac, ai, axes.length));
|
|
63
|
+
return (_jsx("polygon", { points: polygonPoints(ringPts), fill: idx === levels - 1 ? 'rgba(241, 245, 249, 0.45)' : 'none', stroke: idx === levels - 1 ? LINE_STRONG : LINE, strokeWidth: idx === levels - 1 ? 1.3 : 1, "data-jring": idx + 1 }, idx));
|
|
64
|
+
}), axes.map((ax, i) => {
|
|
65
|
+
const [x, y] = polarPoint(cx, cy, radius, i, axes.length);
|
|
66
|
+
return _jsx("line", { x1: cx, y1: cy, x2: x, y2: y, stroke: LINE, strokeWidth: 1 }, ax.key);
|
|
67
|
+
}), showTicks !== false &&
|
|
68
|
+
Array.from({ length: levels }, (_, idx) => {
|
|
69
|
+
const frac = (idx + 1) / levels;
|
|
70
|
+
const tickVal = Math.round(maxVal * frac);
|
|
71
|
+
const ty = cy - radius * frac;
|
|
72
|
+
return (_jsx("text", { x: cx + 5, y: ty + 3, fontSize: 9.5, fontFamily: MONO, fontWeight: 700, fill: DIMMED, children: tickVal }, idx));
|
|
73
|
+
}), seriesPalette.map((s) => (_jsx(RadarSeriesLayer, { seriesItem: s, axes: axes, defaultMax: maxVal, cx: cx, cy: cy, radius: radius, color: s.resolvedColor, dimmed: isDimmed(s.id, s.name), animate: animate, anchors: anchors }, s.id ?? s.name)))] }), axes.map((ax, i) => {
|
|
74
|
+
const [vx, vy] = polarPoint(cx, cy, radius + 30, i, axes.length);
|
|
75
|
+
const leftPct = (vx / vb) * 100;
|
|
76
|
+
const topPct = (vy / vb) * 100;
|
|
77
|
+
const align = vx < cx - 18 ? 'right' : vx > cx + 18 ? 'left' : 'center';
|
|
78
|
+
const transform = align === 'right'
|
|
79
|
+
? 'translate(-100%, -50%)'
|
|
80
|
+
: align === 'left'
|
|
81
|
+
? 'translate(0%, -50%)'
|
|
82
|
+
: 'translate(-50%, -50%)';
|
|
83
|
+
return (_jsxs("div", { style: {
|
|
84
|
+
position: 'absolute',
|
|
85
|
+
left: `${leftPct}%`,
|
|
86
|
+
top: `${topPct}%`,
|
|
87
|
+
transform,
|
|
88
|
+
display: 'flex',
|
|
89
|
+
flexDirection: 'column',
|
|
90
|
+
alignItems: align === 'right' ? 'flex-end' : align === 'left' ? 'flex-start' : 'center',
|
|
91
|
+
gap: 2,
|
|
92
|
+
whiteSpace: 'nowrap',
|
|
93
|
+
pointerEvents: 'none',
|
|
94
|
+
}, children: [_jsx("span", { style: { fontSize: 12.5, fontWeight: 800, color: INK }, children: str(ax.label) }), ax.deltaLabel && (_jsx("span", { style: {
|
|
95
|
+
fontFamily: MONO,
|
|
96
|
+
fontSize: 11,
|
|
97
|
+
fontWeight: 800,
|
|
98
|
+
color: seriesPalette[seriesPalette.length - 1]?.resolvedColor ?? INK,
|
|
99
|
+
}, children: ax.deltaLabel }))] }, ax.key));
|
|
100
|
+
})] })] }));
|
|
101
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { motion, useI18n, useRoot } from '@joplo-app/kit/renderer';
|
|
3
|
+
import { ratioParts } from "../schema.js";
|
|
4
|
+
import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
|
|
5
|
+
import { ACCENT, DIMMED, EASE_OUT_EXPO, INK, LINE_STRONG, MONO, SUBTLE, SURFACE, VIZ_FONT_SANS, dim, formatNumber, str, vizColor, } from "./tokens.js";
|
|
6
|
+
function RatioSegmentBar({ seg, pct, color, borderRadius, transition, anchors, }) {
|
|
7
|
+
const anchorProps = useAnchorAttrs(anchors, seg.id, seg.label);
|
|
8
|
+
return (_jsx(motion.div, { ...anchorProps, initial: false, animate: { width: `${pct}%` }, transition: transition, style: { background: color, borderRadius } }));
|
|
9
|
+
}
|
|
10
|
+
export function RatioBarView({ ctx }) {
|
|
11
|
+
const { node, p, animate, anchors } = useVizChart(ctx);
|
|
12
|
+
const { t } = useI18n();
|
|
13
|
+
const { title, total: _t, left: _l, right: _r, segments: _s, threshold: _th, labels: rawLabels, remainderLabel, thresholdLabel, colors: rawColors, unit: rawUnit, height, showDenominator, segmentIds: _sids, ...rest } = p;
|
|
14
|
+
const root = useRoot(node, rest, {
|
|
15
|
+
style: { minWidth: 0, width: '100%', margin: 0, fontFamily: VIZ_FONT_SANS, color: INK },
|
|
16
|
+
});
|
|
17
|
+
const parts = ratioParts(p);
|
|
18
|
+
if (!parts || ['right', 'threshold'].some((key) => node.props?.[key] !== undefined && p[key] === undefined)) {
|
|
19
|
+
return _jsx("figure", { ...root, children: t.stage.noData });
|
|
20
|
+
}
|
|
21
|
+
const unit = str(rawUnit);
|
|
22
|
+
const trackH = dim(height) ?? 20;
|
|
23
|
+
const transition = animate ? { duration: 0.45, ease: EASE_OUT_EXPO } : { duration: 0 };
|
|
24
|
+
const fmt = (n) => showDenominator === true ? `${formatNumber(n, unit)} / ${formatNumber(parts.total, unit)}` : formatNumber(n, unit);
|
|
25
|
+
if (parts.mode === 'segments') {
|
|
26
|
+
const segColors = parts.segments.map((seg, i) => vizColor(seg.color ?? (Array.isArray(rawColors) ? rawColors[i] : undefined), i));
|
|
27
|
+
const remColor = Array.isArray(rawColors) && rawColors[parts.segments.length]
|
|
28
|
+
? vizColor(rawColors[parts.segments.length])
|
|
29
|
+
: SUBTLE;
|
|
30
|
+
return (_jsxs("figure", { ...root, "aria-label": typeof p['aria-label'] === 'string' ? p['aria-label'] : typeof title === 'string' ? title : undefined, children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined }), _jsxs("div", { style: { position: 'relative', display: 'flex', height: trackH, borderRadius: 6, background: SUBTLE, overflow: 'visible' }, children: [parts.segments.map((seg, i) => (_jsx(RatioSegmentBar, { seg: seg, pct: parts.percentages[i], color: segColors[i], borderRadius: i === 0 ? '6px 0 0 6px' : i === parts.segments.length - 1 && parts.remainder <= 0 ? '0 6px 6px 0' : 0, transition: transition, anchors: anchors }, seg.id ?? i))), parts.remainder > 0 && (_jsx(motion.div, { initial: false, animate: { width: `${parts.remainderPct}%` }, transition: transition, style: { background: remColor, borderRadius: '0 6px 6px 0' } })), parts.threshold !== undefined && (_jsx(motion.span, { initial: false, animate: { left: `${parts.threshold}%` }, transition: transition, style: {
|
|
31
|
+
position: 'absolute',
|
|
32
|
+
top: -4,
|
|
33
|
+
bottom: -4,
|
|
34
|
+
borderLeft: `2px solid ${INK}`,
|
|
35
|
+
transform: 'translateX(-50%)',
|
|
36
|
+
boxShadow: `1px 0 ${SURFACE}`,
|
|
37
|
+
} }))] }), _jsxs("figcaption", { style: { display: 'flex', flexWrap: 'wrap', gap: '6px 18px', marginTop: 9, fontSize: 13.5, fontVariantNumeric: 'tabular-nums' }, children: [parts.segments.map((seg, i) => (_jsxs("span", { style: { display: 'inline-flex', alignItems: 'center', gap: 6 }, children: [_jsx("span", { "aria-hidden": true, style: { width: 10, height: 10, borderRadius: 2, background: segColors[i] } }), _jsx("span", { style: { fontWeight: 700, color: INK }, children: seg.label ?? `Segment ${i + 1}` }), _jsx("span", { style: { fontFamily: MONO, fontWeight: 800, color: segColors[i] }, children: fmt(seg.value) })] }, seg.id ?? i))), parts.remainder > 0 && (_jsxs("span", { style: { display: 'inline-flex', alignItems: 'center', gap: 6, color: DIMMED }, children: [_jsx("span", { "aria-hidden": true, style: { width: 10, height: 10, borderRadius: 2, background: remColor } }), str(remainderLabel, 'Remainder'), " ", fmt(parts.remainder)] })), parts.threshold !== undefined && (_jsxs("span", { style: { fontFamily: MONO, fontSize: 12.5, color: INK }, children: [_jsx("b", { "aria-hidden": true, children: "\u2502 " }), str(thresholdLabel, 'Threshold'), " ", formatNumber(p.threshold, unit)] }))] })] }));
|
|
38
|
+
}
|
|
39
|
+
// Pair / single-value mode
|
|
40
|
+
const labels = Array.isArray(rawLabels) ? rawLabels : [];
|
|
41
|
+
const isSingle = p.right === undefined;
|
|
42
|
+
const userColors = Array.isArray(rawColors) ? rawColors : [];
|
|
43
|
+
// Smart 2-color mapping when right is omitted: colors={[left, remainder]} works naturally without falling back to gray!
|
|
44
|
+
const leftColor = userColors[0] ? vizColor(userColors[0], 0) : ACCENT;
|
|
45
|
+
const rightColor = !isSingle && userColors[1] ? vizColor(userColors[1], 1) : DIMMED;
|
|
46
|
+
const remColor = isSingle
|
|
47
|
+
? userColors[2]
|
|
48
|
+
? vizColor(userColors[2], 2)
|
|
49
|
+
: userColors[1]
|
|
50
|
+
? vizColor(userColors[1], 2)
|
|
51
|
+
: LINE_STRONG
|
|
52
|
+
: userColors[2]
|
|
53
|
+
? vizColor(userColors[2], 2)
|
|
54
|
+
: LINE_STRONG;
|
|
55
|
+
const colors = [leftColor, rightColor, remColor];
|
|
56
|
+
const names = [labels[0] ?? 'A', labels[1] ?? 'B', str(remainderLabel, 'Remainder')];
|
|
57
|
+
const indices = isSingle ? [0, 2] : [0, 1, 2];
|
|
58
|
+
// Clean editorial single-value layout: label + direct bold value on top, crisp bar below, threshold note cleanly aligned
|
|
59
|
+
if (isSingle && showDenominator !== true) {
|
|
60
|
+
return (_jsxs("figure", { ...root, "aria-label": typeof p['aria-label'] === 'string' ? p['aria-label'] : str(labels[0], 'RatioBar'), children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined }), _jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', gap: 12, marginBottom: 7 }, children: [_jsx("span", { style: { fontSize: 14, fontWeight: 750, color: INK }, children: str(names[0]) }), _jsxs("div", { style: { display: 'inline-flex', alignItems: 'baseline', gap: 12, fontVariantNumeric: 'tabular-nums' }, children: [_jsx("span", { style: { fontFamily: MONO, fontSize: 16.5, fontWeight: 900, color: leftColor }, children: formatNumber(parts.counts[0], unit) }), parts.counts[2] > 0 && (_jsxs("span", { style: { fontSize: 12.5, fontWeight: 650, color: remColor === LINE_STRONG ? DIMMED : remColor }, children: [formatNumber(parts.counts[2], unit), " ", str(names[2])] }))] })] }), _jsxs("div", { "aria-hidden": true, style: { position: 'relative', display: 'flex', height: trackH, borderRadius: 6, background: SUBTLE }, children: [_jsx(motion.div, { initial: false, animate: { width: `${parts.percentages[0]}%` }, transition: transition, style: { background: leftColor, borderRadius: parts.percentages[2] > 0 ? '6px 0 0 6px' : 6 } }), _jsx(motion.div, { initial: false, animate: { width: `${parts.percentages[2]}%` }, transition: transition, style: { background: remColor === LINE_STRONG ? SUBTLE : `color-mix(in srgb, ${remColor} 18%, ${SURFACE})`, borderRadius: '0 6px 6px 0' } }), parts.threshold !== undefined && (_jsx(motion.span, { initial: false, animate: { left: `${parts.threshold}%` }, transition: transition, style: {
|
|
61
|
+
position: 'absolute',
|
|
62
|
+
top: -4,
|
|
63
|
+
bottom: -4,
|
|
64
|
+
borderLeft: `2px solid ${INK}`,
|
|
65
|
+
transform: 'translateX(-50%)',
|
|
66
|
+
boxShadow: `1px 0 ${SURFACE}`,
|
|
67
|
+
} }))] }), parts.threshold !== undefined && (_jsxs("figcaption", { style: { display: 'flex', justifyContent: 'flex-end', marginTop: 6, fontSize: 11.5, fontFamily: MONO, color: DIMMED }, children: ["\u2502 ", str(thresholdLabel, 'Threshold'), " ", formatNumber(p.threshold, unit)] }))] }));
|
|
68
|
+
}
|
|
69
|
+
return (_jsxs("figure", { ...root, "aria-label": typeof p['aria-label'] === 'string' ? p['aria-label'] : undefined, children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined }), _jsxs("div", { "aria-hidden": true, style: { position: 'relative', display: 'flex', height: trackH, borderRadius: 6, background: SUBTLE }, children: [indices.map((i) => (_jsx(motion.div, { initial: false, animate: { width: `${parts.percentages[i]}%` }, transition: transition, style: { background: colors[i], borderRadius: i === 0 ? '6px 0 0 6px' : i === 2 ? '0 6px 6px 0' : 0 } }, i))), parts.threshold !== undefined && (_jsx(motion.span, { initial: false, animate: { left: `${parts.threshold}%` }, transition: transition, style: {
|
|
70
|
+
position: 'absolute',
|
|
71
|
+
top: -4,
|
|
72
|
+
bottom: -4,
|
|
73
|
+
borderLeft: `2px solid ${INK}`,
|
|
74
|
+
transform: 'translateX(-50%)',
|
|
75
|
+
boxShadow: `1px 0 ${SURFACE}`,
|
|
76
|
+
} }))] }), _jsxs("figcaption", { style: { display: 'flex', flexWrap: 'wrap', gap: '4px 16px', marginTop: 8, fontSize: 13.5, fontVariantNumeric: 'tabular-nums' }, children: [indices.map((i) => (_jsxs("span", { style: { display: 'inline-flex', alignItems: 'center', gap: 5 }, children: [_jsx("span", { "aria-hidden": true, style: { width: 10, height: 10, borderRadius: 2, background: colors[i] } }), str(names[i]), " ", fmt(parts.counts[i])] }, i))), parts.threshold !== undefined && (_jsxs("span", { children: [_jsx("b", { "aria-hidden": true, children: "\u2502 " }), str(thresholdLabel, 'Threshold'), " ", formatNumber(p.threshold, unit)] }))] })] }));
|
|
77
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { sankey as d3Sankey } from 'd3-sankey';
|
|
3
|
+
import { motion, useRoot } from '@joplo-app/kit/renderer';
|
|
4
|
+
import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
|
|
5
|
+
import { DIMMED, EASE_OUT_EXPO, INK, LINE, MONO, SURFACE, VIZ_FONT_SANS, arr, dim, formatNumber, num, str, tint, vizColor, } from "./tokens.js";
|
|
6
|
+
/** Closed cubic-Bezier ribbon band so width scales cleanly with zero stroke-cap distortion. */
|
|
7
|
+
function ribbonPath(link) {
|
|
8
|
+
const src = link.source;
|
|
9
|
+
const dst = link.target;
|
|
10
|
+
const x0 = src.x1 ?? 0;
|
|
11
|
+
const x1 = dst.x0 ?? 0;
|
|
12
|
+
const y0 = link.y0 ?? 0;
|
|
13
|
+
const y1 = link.y1 ?? 0;
|
|
14
|
+
const hw = Math.max(1.5, (link.width ?? 2) / 2);
|
|
15
|
+
const mx = (x0 + x1) / 2;
|
|
16
|
+
return [
|
|
17
|
+
`M ${x0},${y0 - hw}`,
|
|
18
|
+
`C ${mx},${y0 - hw} ${mx},${y1 - hw} ${x1},${y1 - hw}`,
|
|
19
|
+
`L ${x1},${y1 + hw}`,
|
|
20
|
+
`C ${mx},${y1 + hw} ${mx},${y0 + hw} ${x0},${y0 + hw}`,
|
|
21
|
+
'Z',
|
|
22
|
+
].join(' ');
|
|
23
|
+
}
|
|
24
|
+
function SankeyNodeBox({ nodeItem, color, vbW, vbH, unit, dimmed, animate, anchors, }) {
|
|
25
|
+
const anchorProps = useAnchorAttrs(anchors, nodeItem.id, nodeItem.label);
|
|
26
|
+
const x0 = nodeItem.x0 ?? 0;
|
|
27
|
+
const x1 = nodeItem.x1 ?? 0;
|
|
28
|
+
const y0 = nodeItem.y0 ?? 0;
|
|
29
|
+
const y1 = nodeItem.y1 ?? 0;
|
|
30
|
+
const hPx = Math.max(22, y1 - y0);
|
|
31
|
+
const leftPct = (x0 / vbW) * 100;
|
|
32
|
+
const widthPct = ((x1 - x0) / vbW) * 100;
|
|
33
|
+
const isRightSide = x0 > vbW * 0.6;
|
|
34
|
+
const valText = nodeItem.valueLabel ?? (typeof nodeItem.value === 'number' ? formatNumber(nodeItem.value, unit) : '');
|
|
35
|
+
return (_jsx(motion.div, { ...anchorProps, "data-jsankey-node": nodeItem.id, initial: false, animate: { opacity: dimmed ? 0.22 : 1 }, transition: animate ? { duration: 0.3, ease: EASE_OUT_EXPO } : { duration: 0 }, style: {
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
left: `${leftPct}%`,
|
|
38
|
+
top: y0,
|
|
39
|
+
width: `${widthPct}%`,
|
|
40
|
+
height: hPx,
|
|
41
|
+
borderRadius: 6,
|
|
42
|
+
background: color,
|
|
43
|
+
boxShadow: `0 2px 6px ${tint(color, 26)}`,
|
|
44
|
+
zIndex: 3,
|
|
45
|
+
}, children: _jsxs("div", { style: {
|
|
46
|
+
position: 'absolute',
|
|
47
|
+
top: '50%',
|
|
48
|
+
transform: 'translateY(-50%)',
|
|
49
|
+
...(isRightSide ? { right: 'calc(100% + 10px)', textAlign: 'right' } : { left: 'calc(100% + 10px)', textAlign: 'left' }),
|
|
50
|
+
display: 'flex',
|
|
51
|
+
flexDirection: 'column',
|
|
52
|
+
gap: 1,
|
|
53
|
+
whiteSpace: 'nowrap',
|
|
54
|
+
pointerEvents: 'none',
|
|
55
|
+
background: 'rgba(255,255,255,0.88)',
|
|
56
|
+
padding: '2px 6px',
|
|
57
|
+
borderRadius: 6,
|
|
58
|
+
}, children: [_jsx("span", { style: { fontSize: 12.5, fontWeight: 800, color: INK }, children: nodeItem.label }), (valText || nodeItem.sub) && (_jsxs("span", { style: { fontFamily: MONO, fontSize: 11, fontWeight: 700, color: dimmed ? DIMMED : color }, children: [valText, nodeItem.sub ? ` · ${nodeItem.sub}` : ''] }))] }) }));
|
|
59
|
+
}
|
|
60
|
+
function SankeyLinkAnchor({ link, vbW, label, color, dimmed, animate, anchors, }) {
|
|
61
|
+
const anchorProps = useAnchorAttrs(anchors, link.id, label);
|
|
62
|
+
const src = link.source;
|
|
63
|
+
const dst = link.target;
|
|
64
|
+
const mxPct = ((((src.x1 ?? 0) + (dst.x0 ?? 0)) / 2) / vbW) * 100;
|
|
65
|
+
const my = ((link.y0 ?? 0) + (link.y1 ?? 0)) / 2;
|
|
66
|
+
return (_jsx(motion.div, { ...anchorProps, "data-jsankey-link": link.id ?? `${src.id}->${dst.id}`, initial: false, animate: { opacity: dimmed ? 0.14 : 1 }, transition: animate ? { duration: 0.3, ease: EASE_OUT_EXPO } : { duration: 0 }, style: {
|
|
67
|
+
position: 'absolute',
|
|
68
|
+
left: `${mxPct}%`,
|
|
69
|
+
top: my,
|
|
70
|
+
transform: 'translate(-50%, -50%)',
|
|
71
|
+
padding: '2px 7px',
|
|
72
|
+
borderRadius: 999,
|
|
73
|
+
background: SURFACE,
|
|
74
|
+
border: `1px solid ${dimmed ? LINE : tint(color, 36)}`,
|
|
75
|
+
fontFamily: MONO,
|
|
76
|
+
fontSize: 11,
|
|
77
|
+
fontWeight: 800,
|
|
78
|
+
color: dimmed ? DIMMED : color,
|
|
79
|
+
whiteSpace: 'nowrap',
|
|
80
|
+
zIndex: 4,
|
|
81
|
+
pointerEvents: 'none',
|
|
82
|
+
}, children: label }));
|
|
83
|
+
}
|
|
84
|
+
export function SankeyView({ ctx }) {
|
|
85
|
+
const { node, p, animate, anchors, focusSet } = useVizChart(ctx);
|
|
86
|
+
const { title, subtitle, nodes: rawNodes, links: rawLinks, unit: rawUnit, nodeWidth, nodePadding, nodeIds: _nids, w, h, ...rest } = p;
|
|
87
|
+
const H = num(h, 240);
|
|
88
|
+
const root = useRoot(node, rest, {
|
|
89
|
+
style: {
|
|
90
|
+
width: dim(w) ?? '100%',
|
|
91
|
+
minWidth: 0,
|
|
92
|
+
fontFamily: VIZ_FONT_SANS,
|
|
93
|
+
color: INK,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const inNodes = arr(rawNodes).filter((n) => !!n && typeof n === 'object' && typeof n.id === 'string');
|
|
97
|
+
const nodeIds = new Set(inNodes.map((n) => n.id));
|
|
98
|
+
const inLinks = arr(rawLinks).filter((l) => !!l &&
|
|
99
|
+
typeof l === 'object' &&
|
|
100
|
+
typeof l.source === 'string' &&
|
|
101
|
+
typeof l.target === 'string' &&
|
|
102
|
+
nodeIds.has(l.source) &&
|
|
103
|
+
nodeIds.has(l.target) &&
|
|
104
|
+
typeof l.value === 'number' &&
|
|
105
|
+
l.value > 0);
|
|
106
|
+
if (!inNodes.length || !inLinks.length)
|
|
107
|
+
return _jsx("div", { ...root, role: "status", children: "Sankey \u00B7 no flows" });
|
|
108
|
+
const unit = str(rawUnit);
|
|
109
|
+
const vbW = 900;
|
|
110
|
+
const vbH = Math.max(150, H);
|
|
111
|
+
const nw = num(nodeWidth, 16);
|
|
112
|
+
const np = num(nodePadding, 18);
|
|
113
|
+
// Deep-clone inputs so d3-sankey's in-place mutation never leaks into props or subsequent renders
|
|
114
|
+
const graph = d3Sankey()
|
|
115
|
+
.nodeId((d) => d.id)
|
|
116
|
+
.nodeWidth(nw)
|
|
117
|
+
.nodePadding(np)
|
|
118
|
+
.extent([
|
|
119
|
+
[6, 10],
|
|
120
|
+
[vbW - 6, vbH - 10],
|
|
121
|
+
])({
|
|
122
|
+
nodes: inNodes.map((n) => ({ ...n })),
|
|
123
|
+
links: inLinks.map((l) => ({ ...l })),
|
|
124
|
+
});
|
|
125
|
+
const nodes = graph.nodes;
|
|
126
|
+
const links = graph.links;
|
|
127
|
+
const nodeColorMap = new Map();
|
|
128
|
+
nodes.forEach((n, idx) => {
|
|
129
|
+
nodeColorMap.set(n.id, vizColor(n.color ?? n.tone, idx));
|
|
130
|
+
});
|
|
131
|
+
// Focusing a node or link illuminates its directly connected flow chain
|
|
132
|
+
const isLinkFocused = (link) => {
|
|
133
|
+
if (!focusSet)
|
|
134
|
+
return true;
|
|
135
|
+
const src = link.source;
|
|
136
|
+
const dst = link.target;
|
|
137
|
+
return ((!!link.id && focusSet.has(link.id)) ||
|
|
138
|
+
focusSet.has(`${src.id}->${dst.id}`) ||
|
|
139
|
+
focusSet.has(src.id) ||
|
|
140
|
+
focusSet.has(dst.id));
|
|
141
|
+
};
|
|
142
|
+
const activeNodeIds = new Set();
|
|
143
|
+
if (focusSet) {
|
|
144
|
+
for (const id of focusSet)
|
|
145
|
+
activeNodeIds.add(id);
|
|
146
|
+
for (const link of links) {
|
|
147
|
+
if (isLinkFocused(link)) {
|
|
148
|
+
activeNodeIds.add(link.source.id);
|
|
149
|
+
activeNodeIds.add(link.target.id);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const gradPrefix = `jp-sankey-${node.id.replace(/[^a-zA-Z0-9_-]/g, '_')}`;
|
|
154
|
+
return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'Sankey', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined }), _jsxs("div", { style: { position: 'relative', width: '100%', height: vbH }, children: [_jsxs("svg", { viewBox: `0 0 ${vbW} ${vbH}`, preserveAspectRatio: "none", style: { position: 'absolute', inset: 0, width: '100%', height: vbH, display: 'block', overflow: 'visible' }, children: [_jsx("defs", { children: links.map((link, idx) => {
|
|
155
|
+
const src = link.source;
|
|
156
|
+
const dst = link.target;
|
|
157
|
+
const c1 = link.color ? vizColor(link.color) : (nodeColorMap.get(src.id) ?? vizColor('accent'));
|
|
158
|
+
const c2 = link.color ? vizColor(link.color) : (nodeColorMap.get(dst.id) ?? c1);
|
|
159
|
+
return (_jsxs("linearGradient", { id: `${gradPrefix}-${idx}`, x1: "0%", y1: "0%", x2: "100%", y2: "0%", children: [_jsx("stop", { offset: "0%", stopColor: c1 }), _jsx("stop", { offset: "100%", stopColor: c2 })] }, idx));
|
|
160
|
+
}) }), links.map((link, idx) => {
|
|
161
|
+
const focused = isLinkFocused(link);
|
|
162
|
+
return (_jsx("path", { d: ribbonPath(link), fill: `url(#${gradPrefix}-${idx})`, fillOpacity: focused ? (focusSet ? 0.56 : 0.34) : 0.08, "data-jsankey-ribbon": link.id ?? idx, style: { transition: animate ? 'fill-opacity 280ms ease' : undefined } }, link.id ?? idx));
|
|
163
|
+
})] }), nodes.map((n) => (_jsx(SankeyNodeBox, { nodeItem: n, color: nodeColorMap.get(n.id) ?? vizColor('accent'), vbW: vbW, vbH: vbH, unit: unit, dimmed: !!focusSet && !activeNodeIds.has(n.id), animate: animate, anchors: anchors }, n.id))), links.map((link, idx) => {
|
|
164
|
+
const text = link.label ?? (link.id ? formatNumber(link.value, unit) : '');
|
|
165
|
+
if (!text)
|
|
166
|
+
return null;
|
|
167
|
+
const dst = link.target;
|
|
168
|
+
const color = link.color ? vizColor(link.color) : (nodeColorMap.get(dst.id) ?? vizColor('accent'));
|
|
169
|
+
return (_jsx(SankeyLinkAnchor, { link: link, vbW: vbW, label: text, color: color, dimmed: !isLinkFocused(link), animate: animate, anchors: anchors }, link.id ?? `lbl_${idx}`));
|
|
170
|
+
})] })] }));
|
|
171
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { scaleLinear } from 'd3-scale';
|
|
3
|
+
import { line as d3Line } from 'd3-shape';
|
|
4
|
+
import { motion, useRoot } from '@joplo-app/kit/renderer';
|
|
5
|
+
import { computeParetoFrontier } from "../schema.js";
|
|
6
|
+
import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
|
|
7
|
+
import { ACCENT, DIMMED, EASE_OUT_EXPO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SURFACE, VIZ_FONT_SANS, arr, dim, formatNumber, num, str, tint, vizColor, } from "./tokens.js";
|
|
8
|
+
function ScatterDot({ pt, pxPct, pyPx, pyPct, fill, radius, isHighlight, isDominated, dimmed, animate, index, xUnit, yUnit, anchors, }) {
|
|
9
|
+
const anchorProps = useAnchorAttrs(anchors, pt.id, pt.label);
|
|
10
|
+
const size = radius * 2;
|
|
11
|
+
// Smart default label placement so labels stay inside plot bounds and don't cross top frontier line
|
|
12
|
+
const pos = pt.labelPos ??
|
|
13
|
+
(pxPct > 74 ? 'bottom' : pyPct < 24 ? 'right' : pxPct < 18 ? 'right' : 'right');
|
|
14
|
+
const labelStyle = pos === 'top'
|
|
15
|
+
? { left: '50%', bottom: size / 2 + 8, transform: 'translateX(-50%)' }
|
|
16
|
+
: pos === 'bottom'
|
|
17
|
+
? { left: pxPct > 80 ? undefined : '50%', right: pxPct > 80 ? -2 : undefined, top: size / 2 + 8, transform: pxPct > 80 ? undefined : 'translateX(-50%)' }
|
|
18
|
+
: pos === 'left'
|
|
19
|
+
? { right: size / 2 + 10, top: '50%', transform: 'translateY(-50%)' }
|
|
20
|
+
: { left: size / 2 + 10, top: '50%', transform: 'translateY(-50%)' };
|
|
21
|
+
const meta = pt.valueLabel ?? (xUnit || yUnit ? `${formatNumber(pt.x, xUnit)} · ${formatNumber(pt.y, yUnit)}` : '');
|
|
22
|
+
return (_jsx(motion.div, { ...anchorProps, "data-jpoint": pt.id ?? pt.label, initial: animate ? { scale: 0.4, opacity: 0 } : false, animate: { scale: 1, opacity: dimmed ? 0.2 : 1 }, transition: animate ? { duration: 0.36, delay: index * 0.05, ease: EASE_OUT_EXPO } : { duration: 0 }, style: {
|
|
23
|
+
position: 'absolute',
|
|
24
|
+
left: `${pxPct}%`,
|
|
25
|
+
top: pyPx,
|
|
26
|
+
width: size,
|
|
27
|
+
height: size,
|
|
28
|
+
marginLeft: -radius,
|
|
29
|
+
marginTop: -radius,
|
|
30
|
+
borderRadius: '50%',
|
|
31
|
+
background: fill,
|
|
32
|
+
border: isHighlight ? `3px solid ${SURFACE}` : `2px solid ${SURFACE}`,
|
|
33
|
+
boxShadow: isHighlight
|
|
34
|
+
? `0 0 0 3px ${tint(fill, 28)}, 0 4px 12px rgba(23,24,26,0.14)`
|
|
35
|
+
: isDominated
|
|
36
|
+
? 'none'
|
|
37
|
+
: `0 2px 6px ${tint(fill, 28)}`,
|
|
38
|
+
boxSizing: 'border-box',
|
|
39
|
+
zIndex: isHighlight ? 5 : isDominated ? 2 : 3,
|
|
40
|
+
}, children: _jsxs("div", { style: {
|
|
41
|
+
position: 'absolute',
|
|
42
|
+
...labelStyle,
|
|
43
|
+
display: 'inline-flex',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
gap: 6,
|
|
46
|
+
whiteSpace: 'nowrap',
|
|
47
|
+
pointerEvents: 'none',
|
|
48
|
+
background: isHighlight ? tint(fill, 10) : 'rgba(255,255,255,0.88)',
|
|
49
|
+
border: isHighlight ? `1px solid ${tint(fill, 34)}` : 'none',
|
|
50
|
+
borderRadius: 6,
|
|
51
|
+
padding: isHighlight ? '2px 7px' : '1px 4px',
|
|
52
|
+
}, children: [_jsx("span", { style: {
|
|
53
|
+
fontSize: isHighlight ? 12.5 : 11.5,
|
|
54
|
+
fontWeight: isHighlight ? 850 : isDominated ? 600 : 750,
|
|
55
|
+
color: isHighlight ? fill : isDominated ? DIMMED : INK,
|
|
56
|
+
}, children: pt.label }), meta && (_jsx("span", { style: {
|
|
57
|
+
fontFamily: MONO,
|
|
58
|
+
fontSize: 11,
|
|
59
|
+
fontWeight: isHighlight ? 800 : 600,
|
|
60
|
+
color: isHighlight ? fill : DIMMED,
|
|
61
|
+
}, children: meta }))] }) }));
|
|
62
|
+
}
|
|
63
|
+
export function ScatterPlotView({ ctx }) {
|
|
64
|
+
const { node, p, animate, anchors, isDimmed } = useVizChart(ctx);
|
|
65
|
+
const { title, subtitle, points: rawPoints, xLabel, yLabel, xUnit: rawXUnit, yUnit: rawYUnit, xDomain: rawXDomain, yDomain: rawYDomain, pareto, quadrant, pointIds: _pids, w, h, ...rest } = p;
|
|
66
|
+
const H = num(h, 290);
|
|
67
|
+
const root = useRoot(node, rest, {
|
|
68
|
+
style: {
|
|
69
|
+
width: dim(w) ?? '100%',
|
|
70
|
+
minWidth: 0,
|
|
71
|
+
fontFamily: VIZ_FONT_SANS,
|
|
72
|
+
color: INK,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const points = arr(rawPoints).filter((pt) => !!pt &&
|
|
76
|
+
typeof pt === 'object' &&
|
|
77
|
+
typeof pt.x === 'number' &&
|
|
78
|
+
Number.isFinite(pt.x) &&
|
|
79
|
+
typeof pt.y === 'number' &&
|
|
80
|
+
Number.isFinite(pt.y));
|
|
81
|
+
if (!points.length)
|
|
82
|
+
return _jsx("div", { ...root, role: "status", children: "ScatterPlot \u00B7 no points" });
|
|
83
|
+
const xUnit = str(rawXUnit);
|
|
84
|
+
const yUnit = str(rawYUnit);
|
|
85
|
+
const xs = points.map((pt) => pt.x);
|
|
86
|
+
const ys = points.map((pt) => pt.y);
|
|
87
|
+
const xMin = Math.min(...xs);
|
|
88
|
+
const xMax = Math.max(...xs);
|
|
89
|
+
const yMin = Math.min(...ys);
|
|
90
|
+
const yMax = Math.max(...ys);
|
|
91
|
+
const xPad = Math.max((xMax - xMin) * 0.14, 1);
|
|
92
|
+
const yPad = Math.max((yMax - yMin) * 0.16, 1);
|
|
93
|
+
const xDomain = Array.isArray(rawXDomain) && typeof rawXDomain[0] === 'number' && typeof rawXDomain[1] === 'number'
|
|
94
|
+
? [rawXDomain[0], rawXDomain[1]]
|
|
95
|
+
: [Math.max(0, xMin - xPad), xMax + xPad];
|
|
96
|
+
const yDomain = Array.isArray(rawYDomain) && typeof rawYDomain[0] === 'number' && typeof rawYDomain[1] === 'number'
|
|
97
|
+
? [rawYDomain[0], rawYDomain[1]]
|
|
98
|
+
: [yMin - yPad, yMax + yPad];
|
|
99
|
+
const plotH = Math.max(160, H - 48);
|
|
100
|
+
const vbW = 1000;
|
|
101
|
+
const vbH = plotH;
|
|
102
|
+
const xScale = scaleLinear().domain(xDomain).range([0, vbW]).clamp(true);
|
|
103
|
+
const yScale = scaleLinear().domain(yDomain).range([vbH, 0]).clamp(true);
|
|
104
|
+
const xTicks = xScale.ticks(4);
|
|
105
|
+
const yTicks = yScale.ticks(4);
|
|
106
|
+
const paretoCorner = pareto === false
|
|
107
|
+
? false
|
|
108
|
+
: pareto === 'top-right' || pareto === 'bottom-left' || pareto === 'bottom-right'
|
|
109
|
+
? pareto
|
|
110
|
+
: 'top-left';
|
|
111
|
+
const frontier = paretoCorner ? computeParetoFrontier(points, paretoCorner) : [];
|
|
112
|
+
const frontierSet = new Set(frontier);
|
|
113
|
+
const frontierPath = frontier.length >= 2
|
|
114
|
+
? (d3Line()
|
|
115
|
+
.x((d) => xScale(d.x))
|
|
116
|
+
.y((d) => yScale(d.y))(frontier) ?? '')
|
|
117
|
+
: '';
|
|
118
|
+
const quadObj = quadrant &&
|
|
119
|
+
typeof quadrant === 'object' &&
|
|
120
|
+
typeof quadrant.x === 'number' &&
|
|
121
|
+
typeof quadrant.y === 'number'
|
|
122
|
+
? quadrant
|
|
123
|
+
: null;
|
|
124
|
+
const quadCorner = quadObj?.corner ?? (paretoCorner || 'top-left');
|
|
125
|
+
const quadRect = quadObj
|
|
126
|
+
? (() => {
|
|
127
|
+
const qx = xScale(quadObj.x);
|
|
128
|
+
const qy = yScale(quadObj.y);
|
|
129
|
+
const left = quadCorner.endsWith('left') ? 0 : qx;
|
|
130
|
+
const width = quadCorner.endsWith('left') ? qx : vbW - qx;
|
|
131
|
+
const top = quadCorner.startsWith('top') ? 0 : qy;
|
|
132
|
+
const height = quadCorner.startsWith('top') ? qy : vbH - qy;
|
|
133
|
+
return { left, top, width: Math.max(0, width), height: Math.max(0, height) };
|
|
134
|
+
})()
|
|
135
|
+
: null;
|
|
136
|
+
const cornerBadge = paretoCorner === 'top-left'
|
|
137
|
+
? '↖ 越往左上越优'
|
|
138
|
+
: paretoCorner === 'top-right'
|
|
139
|
+
? '↗ 越往右上越优'
|
|
140
|
+
: paretoCorner === 'bottom-left'
|
|
141
|
+
? '↙ 越往左下越优'
|
|
142
|
+
: paretoCorner === 'bottom-right'
|
|
143
|
+
? '↘ 越往右下越优'
|
|
144
|
+
: undefined;
|
|
145
|
+
return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'ScatterPlot', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined, right: cornerBadge ? (_jsx("span", { style: {
|
|
146
|
+
padding: '3px 9px',
|
|
147
|
+
borderRadius: 999,
|
|
148
|
+
background: tint(OK, 12),
|
|
149
|
+
color: OK,
|
|
150
|
+
fontSize: 11.5,
|
|
151
|
+
fontWeight: 800,
|
|
152
|
+
whiteSpace: 'nowrap',
|
|
153
|
+
}, children: cornerBadge })) : undefined }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: '52px 1fr', columnGap: 12, alignItems: 'start' }, children: [_jsxs("div", { style: { position: 'relative', height: plotH, fontFamily: MONO, fontSize: 11, color: DIMMED, textAlign: 'right' }, children: [yTicks.map((tk) => (_jsx("span", { style: {
|
|
154
|
+
position: 'absolute',
|
|
155
|
+
right: 0,
|
|
156
|
+
top: yScale(tk),
|
|
157
|
+
transform: 'translateY(-50%)',
|
|
158
|
+
whiteSpace: 'nowrap',
|
|
159
|
+
}, children: formatNumber(tk, yUnit) }, tk))), typeof yLabel === 'string' && yLabel && (_jsx("span", { style: { position: 'absolute', right: 0, top: -18, fontSize: 11, fontWeight: 700, color: INK2, whiteSpace: 'nowrap' }, children: yLabel }))] }), _jsxs("div", { style: { position: 'relative', width: '100%', height: plotH + 28 }, children: [_jsxs("svg", { viewBox: `0 0 ${vbW} ${vbH}`, preserveAspectRatio: "none", style: { position: 'absolute', left: 0, top: 0, width: '100%', height: plotH, display: 'block', overflow: 'visible' }, children: [quadRect && (_jsx("rect", { x: quadRect.left, y: quadRect.top, width: quadRect.width, height: quadRect.height, fill: OK, fillOpacity: 0.07, stroke: OK, strokeOpacity: 0.28, strokeDasharray: "5 5", strokeWidth: 1.2, vectorEffect: "non-scaling-stroke" })), yTicks.map((tk) => (_jsx("line", { x1: 0, x2: vbW, y1: yScale(tk), y2: yScale(tk), stroke: LINE, strokeWidth: 1, vectorEffect: "non-scaling-stroke" }, `y_${tk}`))), xTicks.map((tk) => (_jsx("line", { x1: xScale(tk), x2: xScale(tk), y1: 0, y2: vbH, stroke: LINE, strokeWidth: 1, strokeDasharray: "3 4", vectorEffect: "non-scaling-stroke" }, `x_${tk}`))), _jsx("line", { x1: 0, x2: 0, y1: 0, y2: vbH, stroke: LINE_STRONG, strokeWidth: 1.5, vectorEffect: "non-scaling-stroke" }), _jsx("line", { x1: 0, x2: vbW, y1: vbH, y2: vbH, stroke: LINE_STRONG, strokeWidth: 1.5, vectorEffect: "non-scaling-stroke" }), frontierPath && (_jsx("path", { d: frontierPath, fill: "none", stroke: OK, strokeWidth: 2.2, strokeDasharray: "7 5", strokeLinecap: "round", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke", "data-jpareto": "frontier" }))] }), quadObj?.label && quadRect && (_jsx("span", { style: {
|
|
160
|
+
position: 'absolute',
|
|
161
|
+
left: quadCorner.endsWith('left') ? 10 : `${(quadRect.left / vbW) * 100 + 1}%`,
|
|
162
|
+
top: quadCorner.startsWith('top') ? 8 : quadRect.top + 8,
|
|
163
|
+
fontSize: 11.5,
|
|
164
|
+
fontWeight: 800,
|
|
165
|
+
color: OK,
|
|
166
|
+
pointerEvents: 'none',
|
|
167
|
+
zIndex: 1,
|
|
168
|
+
}, children: quadObj.label })), points.map((pt, index) => {
|
|
169
|
+
const isHighlight = pt.tier === 'highlight';
|
|
170
|
+
const isFrontier = pt.tier === 'frontier' || (pt.tier === undefined && frontierSet.has(pt));
|
|
171
|
+
const isDominated = pt.tier === 'dominated' || (pt.tier === undefined && !isFrontier && paretoCorner !== false);
|
|
172
|
+
const fill = pt.color
|
|
173
|
+
? vizColor(pt.color)
|
|
174
|
+
: isHighlight
|
|
175
|
+
? OK
|
|
176
|
+
: isFrontier
|
|
177
|
+
? ACCENT
|
|
178
|
+
: '#94a3b8';
|
|
179
|
+
const radius = typeof pt.r === 'number' && Number.isFinite(pt.r) ? pt.r : isHighlight ? 9 : isFrontier ? 7 : 6;
|
|
180
|
+
const pxPct = (xScale(pt.x) / vbW) * 100;
|
|
181
|
+
const pyPx = yScale(pt.y);
|
|
182
|
+
const pyPct = (pyPx / vbH) * 100;
|
|
183
|
+
return (_jsx(ScatterDot, { pt: pt, pxPct: pxPct, pyPx: pyPx, pyPct: pyPct, fill: fill, radius: radius, isHighlight: isHighlight, isDominated: isDominated, dimmed: isDimmed(pt.id, pt.label, pt.group), animate: animate, index: index, xUnit: xUnit, yUnit: yUnit, anchors: anchors }, pt.id ?? `${pt.label}_${index}`));
|
|
184
|
+
}), xTicks.map((tk, i) => (_jsx("span", { style: {
|
|
185
|
+
position: 'absolute',
|
|
186
|
+
left: `${(xScale(tk) / vbW) * 100}%`,
|
|
187
|
+
top: plotH + 8,
|
|
188
|
+
transform: i === 0 ? 'none' : i === xTicks.length - 1 ? 'translateX(-100%)' : 'translateX(-50%)',
|
|
189
|
+
fontFamily: MONO,
|
|
190
|
+
fontSize: 11,
|
|
191
|
+
color: DIMMED,
|
|
192
|
+
whiteSpace: 'nowrap',
|
|
193
|
+
}, children: formatNumber(tk, xUnit) }, tk))), typeof xLabel === 'string' && xLabel && (_jsx("span", { style: {
|
|
194
|
+
position: 'absolute',
|
|
195
|
+
right: 0,
|
|
196
|
+
top: plotH + 22,
|
|
197
|
+
fontSize: 11,
|
|
198
|
+
fontWeight: 700,
|
|
199
|
+
color: INK2,
|
|
200
|
+
whiteSpace: 'nowrap',
|
|
201
|
+
}, children: xLabel }))] })] })] }));
|
|
202
|
+
}
|