@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.
Files changed (43) hide show
  1. package/LICENSE +97 -0
  2. package/dist/catalog.d.ts +8 -0
  3. package/dist/catalog.js +178 -0
  4. package/dist/components.d.ts +236 -0
  5. package/dist/components.js +55 -0
  6. package/dist/effects.d.ts +27 -0
  7. package/dist/effects.js +32 -0
  8. package/dist/guide.d.ts +3 -0
  9. package/dist/guide.js +79 -0
  10. package/dist/labels.json +12 -0
  11. package/dist/plugin.d.ts +6 -0
  12. package/dist/plugin.js +312 -0
  13. package/dist/runtime/bar-chart.d.ts +4 -0
  14. package/dist/runtime/bar-chart.js +204 -0
  15. package/dist/runtime/delta-bar.d.ts +4 -0
  16. package/dist/runtime/delta-bar.js +165 -0
  17. package/dist/runtime/heatmap.d.ts +4 -0
  18. package/dist/runtime/heatmap.js +138 -0
  19. package/dist/runtime/hooks.d.ts +36 -0
  20. package/dist/runtime/hooks.js +54 -0
  21. package/dist/runtime/line-chart.d.ts +4 -0
  22. package/dist/runtime/line-chart.js +197 -0
  23. package/dist/runtime/radar.d.ts +4 -0
  24. package/dist/runtime/radar.js +101 -0
  25. package/dist/runtime/ratio-bar.d.ts +4 -0
  26. package/dist/runtime/ratio-bar.js +77 -0
  27. package/dist/runtime/sankey.d.ts +4 -0
  28. package/dist/runtime/sankey.js +171 -0
  29. package/dist/runtime/scatter-plot.d.ts +4 -0
  30. package/dist/runtime/scatter-plot.js +202 -0
  31. package/dist/runtime/time-lanes.d.ts +4 -0
  32. package/dist/runtime/time-lanes.js +179 -0
  33. package/dist/runtime/tokens.d.ts +11 -0
  34. package/dist/runtime/tokens.js +51 -0
  35. package/dist/runtime/waterfall.d.ts +4 -0
  36. package/dist/runtime/waterfall.js +119 -0
  37. package/dist/runtime.d.ts +2 -0
  38. package/dist/runtime.js +26 -0
  39. package/dist/schema.d.ts +202 -0
  40. package/dist/schema.js +255 -0
  41. package/dist/version.json +3 -0
  42. package/package.json +67 -3
  43. package/README.md +0 -3
@@ -0,0 +1,179 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { scaleLinear } from 'd3-scale';
3
+ import { motion, useRoot } from '@joplo-app/kit/renderer';
4
+ import { Fragment } from 'react';
5
+ import { layoutTimeLanes, readTimeLanes } from "../schema.js";
6
+ import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
7
+ import { ACCENT, DANGER, DIMMED, EASE_OUT_EXPO, INFO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SUBTLE, VIZ_FONT_SANS, WARN, dim, str, tint, vizColor, } from "./tokens.js";
8
+ const STATUS_TONE = {
9
+ ok: OK,
10
+ warn: WARN,
11
+ fail: DANGER,
12
+ info: INFO,
13
+ accent: ACCENT,
14
+ };
15
+ function LaneBar({ span, row, rowHeight, barHeight, domain: [min, max], unit, dimmed, animate, anchors, }) {
16
+ const fullLabel = span.label ?? span.id;
17
+ const anchorProps = useAnchorAttrs(anchors, span.id, fullLabel);
18
+ const startPct = ((span.start - min) / (max - min)) * 100;
19
+ const widthPct = ((span.end - span.start) / (max - min)) * 100;
20
+ const accent = span.color ? vizColor(span.color) : span.status ? STATUS_TONE[span.status] ?? INFO : INFO;
21
+ const description = `${fullLabel} · ${span.lane} · ${span.start}–${span.end} ${unit}${span.status ? ' · ' + span.status : ''}`;
22
+ const isNarrow = !!span.shortLabel || (widthPct < 24 && fullLabel.length > 7);
23
+ const insideText = span.shortLabel ?? (widthPct >= 14 ? fullLabel : '');
24
+ const rangeText = span.rangeLabel ?? (widthPct >= 26 ? `${span.start}–${span.end} ${unit}` : '');
25
+ const topOffset = row * rowHeight + (rowHeight - barHeight) / 2;
26
+ // Place external label on the roomier side of the track (left if bar sits near right edge, else right)
27
+ const floatLeft = startPct > 45;
28
+ return (_jsxs(_Fragment, { children: [isNarrow && (_jsxs("div", { style: {
29
+ position: 'absolute',
30
+ top: topOffset,
31
+ height: barHeight,
32
+ ...(floatLeft ? { right: `${100 - startPct + 1.4}%` } : { left: `${startPct + widthPct + 1.4}%` }),
33
+ display: 'flex',
34
+ alignItems: 'center',
35
+ gap: 8,
36
+ whiteSpace: 'nowrap',
37
+ opacity: dimmed ? 0.36 : 1,
38
+ transition: animate ? 'opacity 260ms ease' : undefined,
39
+ pointerEvents: 'none',
40
+ }, children: [_jsx("span", { style: { fontSize: Math.max(12.5, barHeight * 0.29), fontWeight: 750, color: INK2 }, children: fullLabel }), _jsx("span", { style: { fontFamily: MONO, fontSize: Math.max(11, barHeight * 0.24), fontWeight: 700, color: accent }, children: span.rangeLabel ?? `${span.start}–${span.end} ${unit}` })] })), _jsxs("div", { ...anchorProps, role: "img", "aria-label": description, title: description, style: {
41
+ position: 'absolute',
42
+ top: topOffset,
43
+ left: `${startPct}%`,
44
+ width: widthPct === 0 ? 2 : `${widthPct}%`,
45
+ height: barHeight,
46
+ borderRadius: 8,
47
+ color: INK,
48
+ backgroundColor: dimmed ? SUBTLE : tint(accent, 16),
49
+ borderLeft: `${widthPct === 0 ? 2 : 4}px solid ${dimmed ? LINE_STRONG : accent}`,
50
+ borderTop: `1px solid ${dimmed ? LINE : accent}`,
51
+ borderRight: `1px solid ${dimmed ? LINE : accent}`,
52
+ borderBottom: `1px solid ${dimmed ? LINE : accent}`,
53
+ boxSizing: 'border-box',
54
+ padding: widthPct === 0 ? 0 : '0 12px',
55
+ display: 'flex',
56
+ alignItems: 'center',
57
+ justifyContent: isNarrow ? 'center' : 'space-between',
58
+ gap: 10,
59
+ overflow: 'hidden',
60
+ opacity: dimmed ? 0.5 : 1,
61
+ transition: animate ? 'opacity 260ms ease, background-color 260ms ease' : undefined,
62
+ }, children: [insideText && (_jsx("span", { style: {
63
+ fontSize: Math.max(12.5, barHeight * 0.3),
64
+ fontWeight: dimmed ? 650 : 800,
65
+ color: dimmed ? INK2 : INK,
66
+ whiteSpace: 'nowrap',
67
+ overflow: 'hidden',
68
+ textOverflow: 'ellipsis',
69
+ }, children: insideText })), !isNarrow && rangeText && (_jsx("span", { style: {
70
+ fontFamily: MONO,
71
+ fontSize: Math.max(11, barHeight * 0.24),
72
+ fontWeight: 700,
73
+ color: dimmed ? DIMMED : accent,
74
+ whiteSpace: 'nowrap',
75
+ flexShrink: 0,
76
+ }, children: rangeText }))] })] }));
77
+ }
78
+ export function TimeLanesView({ ctx }) {
79
+ const { node, p, animate, snap, anchors, isDimmed } = useVizChart(ctx);
80
+ const { title, subtitle, domain: _d, spans: _s, unit: _u, ticks: rawTicks, cursor: propCursor, cursorLabel: propCursorLabel, spanIds: _sids, compact, w, h, ...rest } = p;
81
+ const root = useRoot(node, rest, {
82
+ style: {
83
+ width: dim(w) ?? '100%',
84
+ height: dim(h),
85
+ minWidth: 0,
86
+ fontFamily: VIZ_FONT_SANS,
87
+ color: INK,
88
+ },
89
+ });
90
+ const chart = readTimeLanes(p);
91
+ if (!chart.data)
92
+ return _jsxs("div", { ...root, role: "status", children: ["TimeLanes \u00B7 ", chart.error] });
93
+ const { domain, spans, unit } = chart.data;
94
+ const [min, max] = domain;
95
+ const scale = scaleLinear().domain([min, max]).range([0, 100]);
96
+ const ticks = Array.isArray(rawTicks) && rawTicks.every((t) => typeof t === 'number')
97
+ ? rawTicks
98
+ : scale.ticks(Math.min(8, Math.max(4, Math.round(max - min))));
99
+ const rowHeight = compact === true ? 40 : 62;
100
+ const barHeight = compact === true ? 30 : 46;
101
+ const rowGap = compact === true ? 8 : 14;
102
+ const lanes = layoutTimeLanes(spans);
103
+ // Cursor: effect snapshot wins over prop
104
+ const activeCursor = snap.cursor !== undefined ? snap.cursor : typeof propCursor === 'number' ? { value: propCursor, label: typeof propCursorLabel === 'string' ? propCursorLabel : undefined } : null;
105
+ const cursorNum = activeCursor && typeof activeCursor.value === 'number' && Number.isFinite(activeCursor.value) ? activeCursor.value : null;
106
+ const cursorPct = cursorNum !== null ? Math.max(0, Math.min(100, scale(cursorNum))) : null;
107
+ return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'TimeLanes', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: 'minmax(92px, 132px) minmax(0, 1fr)', columnGap: 18, alignItems: 'end', marginBottom: 12 }, children: [_jsx("span", { style: { fontSize: 12, fontWeight: 700, color: DIMMED } }), _jsx("div", { style: { position: 'relative', height: 24, borderBottom: `1.5px solid ${LINE_STRONG}` }, children: ticks.map((tk, i) => {
108
+ const pct = scale(tk);
109
+ const isFirst = i === 0;
110
+ const isLast = i === ticks.length - 1;
111
+ return (_jsxs("span", { style: {
112
+ position: 'absolute',
113
+ left: `${pct}%`,
114
+ bottom: 5,
115
+ transform: isFirst ? 'none' : isLast ? 'translateX(-100%)' : 'translateX(-50%)',
116
+ fontFamily: MONO,
117
+ fontSize: 12.5,
118
+ fontWeight: 700,
119
+ color: INK2,
120
+ whiteSpace: 'nowrap',
121
+ }, children: [tk, " ", unit] }, tk));
122
+ }) })] }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: 'minmax(92px, 132px) minmax(0, 1fr)', columnGap: 18, paddingBottom: cursorPct !== null ? 28 : 0 }, children: [_jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: rowGap }, children: lanes.map(({ lane, rows }) => (_jsx("div", { style: {
123
+ height: rows * rowHeight,
124
+ display: 'flex',
125
+ alignItems: 'center',
126
+ fontSize: compact === true ? 13.5 : 15,
127
+ fontWeight: 800,
128
+ color: INK,
129
+ overflowWrap: 'anywhere',
130
+ }, children: lane }, lane))) }), _jsxs("div", { style: { position: 'relative', display: 'flex', flexDirection: 'column', gap: rowGap }, children: [ticks.map((tk, i) => {
131
+ const pct = scale(tk);
132
+ if (i === 0 || i === ticks.length - 1)
133
+ return null;
134
+ return (_jsx("div", { style: {
135
+ position: 'absolute',
136
+ left: `${pct}%`,
137
+ top: 0,
138
+ bottom: 0,
139
+ borderLeft: `1px dashed ${LINE}`,
140
+ pointerEvents: 'none',
141
+ } }, tk));
142
+ }), lanes.map(({ lane, bars, rows }) => (_jsx("div", { style: {
143
+ position: 'relative',
144
+ height: rows * rowHeight,
145
+ borderRadius: 8,
146
+ background: SUBTLE,
147
+ }, children: bars.map(({ span, row }) => (_jsx(Fragment, { children: _jsx(LaneBar, { span: span, row: row, rowHeight: rowHeight, barHeight: barHeight, domain: domain, unit: unit, dimmed: isDimmed(span.id, span.lane), animate: animate, anchors: anchors }) }, span.id))) }, lane))), cursorPct !== null && (_jsxs(motion.div, { initial: false, animate: { left: `${cursorPct}%` }, transition: animate ? { duration: 0.65, ease: EASE_OUT_EXPO } : { duration: 0 }, style: {
148
+ position: 'absolute',
149
+ top: -12,
150
+ bottom: -6,
151
+ width: 2.5,
152
+ background: ACCENT,
153
+ pointerEvents: 'none',
154
+ zIndex: 5,
155
+ }, children: [_jsx("span", { style: {
156
+ position: 'absolute',
157
+ top: -4,
158
+ left: '50%',
159
+ transform: 'translateX(-50%)',
160
+ width: 8,
161
+ height: 8,
162
+ borderRadius: '50%',
163
+ background: ACCENT,
164
+ } }), _jsx("span", { style: {
165
+ position: 'absolute',
166
+ bottom: -24,
167
+ left: cursorPct > 86 ? undefined : cursorPct < 14 ? 0 : '50%',
168
+ right: cursorPct > 86 ? 0 : undefined,
169
+ transform: cursorPct > 86 || cursorPct < 14 ? 'none' : 'translateX(-50%)',
170
+ padding: '2px 9px',
171
+ borderRadius: 999,
172
+ background: ACCENT,
173
+ color: '#ffffff',
174
+ fontFamily: MONO,
175
+ fontSize: 11.5,
176
+ fontWeight: 800,
177
+ whiteSpace: 'nowrap',
178
+ }, children: activeCursor?.label ?? `${str(cursorNum)} ${unit}` })] }))] })] })] }));
179
+ }
@@ -0,0 +1,11 @@
1
+ import { ACCENT, DANGER, DIMMED, INFO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SUBTLE, SURFACE, WARN, color, dim, tint } from '@joplo-app/kit/renderer-style';
2
+ export { ACCENT, DANGER, DIMMED, INFO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SUBTLE, SURFACE, WARN, color, dim, tint };
3
+ export declare const VIZ_SERIES_PALETTE: readonly ["#2231dd", "#0f9f6e", "#d97706", "#0284c7", "#dc2626", "#7c3aed"];
4
+ export declare const VIZ_FONT_SANS = "var(--jp-font-sans, ui-sans-serif, -apple-system, BlinkMacSystemFont, \"PingFang SC\", \"Noto Sans SC\", sans-serif)";
5
+ export declare const vizColor: (value: unknown, fallbackIndex?: number) => string;
6
+ export declare const num: (v: unknown, fallback?: number) => number | undefined;
7
+ export declare const str: (v: unknown, fallback?: string) => string;
8
+ export declare const arr: (v: unknown) => unknown[];
9
+ export declare function formatNumber(n: number, unit?: string): string;
10
+ export declare const EASE_OUT_EXPO: [number, number, number, number];
11
+ export declare const EASE_OUT_CUBIC: [number, number, number, number];
@@ -0,0 +1,51 @@
1
+ import { ACCENT, DANGER, DIMMED, INFO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SUBTLE, SURFACE, WARN, color, dim, tint, } from '@joplo-app/kit/renderer-style';
2
+ export { ACCENT, DANGER, DIMMED, INFO, INK, INK2, LINE, LINE_STRONG, MONO, OK, SUBTLE, SURFACE, WARN, color, dim, tint };
3
+ export const VIZ_SERIES_PALETTE = [
4
+ '#2231dd', // crisp editorial indigo
5
+ '#0f9f6e', // emerald
6
+ '#d97706', // amber
7
+ '#0284c7', // sky/cyan
8
+ '#dc2626', // crimson
9
+ '#7c3aed', // violet
10
+ ];
11
+ export const VIZ_FONT_SANS = 'var(--jp-font-sans, ui-sans-serif, -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", sans-serif)';
12
+ export const vizColor = (value, fallbackIndex = 0) => {
13
+ if (typeof value === 'string' && value.trim()) {
14
+ if (value === 'accent')
15
+ return ACCENT;
16
+ if (value === 'ok' || value === 'emerald')
17
+ return OK;
18
+ if (value === 'warn' || value === 'amber')
19
+ return WARN;
20
+ if (value === 'danger' || value === 'crimson')
21
+ return DANGER;
22
+ if (value === 'info')
23
+ return INFO;
24
+ if (value === 'muted')
25
+ return DIMMED;
26
+ const mapped = color(value);
27
+ if (mapped)
28
+ return mapped;
29
+ }
30
+ return VIZ_SERIES_PALETTE[fallbackIndex % VIZ_SERIES_PALETTE.length];
31
+ };
32
+ export const num = (v, fallback) => typeof v === 'number' && Number.isFinite(v) ? v : fallback;
33
+ export const str = (v, fallback = '') => v === undefined || v === null ? fallback : String(v);
34
+ export const arr = (v) => (Array.isArray(v) ? v : []);
35
+ export function formatNumber(n, unit = '') {
36
+ if (!Number.isFinite(n))
37
+ return '';
38
+ const abs = Math.abs(n);
39
+ let body;
40
+ if (Number.isInteger(n))
41
+ body = abs >= 1000 ? n.toLocaleString('en-US') : String(n);
42
+ else
43
+ body = abs >= 100 ? String(Math.round(n * 10) / 10) : String(Number(n.toPrecision(3)));
44
+ if (!unit)
45
+ return body;
46
+ if (/^[$¥€£]$/.test(unit))
47
+ return `${unit}${body}`;
48
+ return `${body}${unit}`;
49
+ }
50
+ export const EASE_OUT_EXPO = [0.16, 1, 0.3, 1];
51
+ export const EASE_OUT_CUBIC = [0.22, 1, 0.36, 1];
@@ -0,0 +1,4 @@
1
+ import type { ComponentCtx } from '@joplo-app/kit/plugin';
2
+ export declare function WaterfallView({ ctx }: {
3
+ ctx: ComponentCtx;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,119 @@
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 { computeWaterfall } from "../schema.js";
5
+ import { ChartHeader, useAnchorAttrs, useVizChart } from "./hooks.js";
6
+ import { ACCENT, DANGER, DIMMED, EASE_OUT_EXPO, INK, LINE, LINE_STRONG, MONO, OK, VIZ_FONT_SANS, arr, dim, formatNumber, num, str, vizColor, } from "./tokens.js";
7
+ function WaterfallColumn({ bar, nextBar, scale, plotH, unit, lowerIsBetter, visible, dimmed, animate, anchors, }) {
8
+ const anchorProps = useAnchorAttrs(anchors, bar.id, bar.label);
9
+ const topVal = Math.max(bar.start, bar.end);
10
+ const botVal = Math.min(bar.start, bar.end);
11
+ const topY = scale(topVal);
12
+ const botY = scale(botVal);
13
+ const barH = Math.max(8, botY - topY);
14
+ const isTotal = bar.kind === 'total' || bar.kind === 'subtotal';
15
+ const isStart = bar.kind === 'start';
16
+ const improved = lowerIsBetter ? bar.value < 0 : bar.value > 0;
17
+ const fill = bar.color
18
+ ? vizColor(bar.color)
19
+ : isStart
20
+ ? '#475569'
21
+ : isTotal
22
+ ? ACCENT
23
+ : improved
24
+ ? OK
25
+ : DANGER;
26
+ const badgeText = bar.deltaLabel ??
27
+ (isStart || isTotal
28
+ ? formatNumber(bar.end, unit)
29
+ : `${bar.value > 0 ? '+' : '−'}${formatNumber(Math.abs(bar.value), unit)}`);
30
+ const endY = scale(bar.end);
31
+ return (_jsxs("div", { ...anchorProps, "data-jstep": bar.id ?? bar.label, style: {
32
+ flex: 1,
33
+ minWidth: 0,
34
+ position: 'relative',
35
+ height: plotH,
36
+ opacity: !visible ? 0.12 : dimmed ? 0.24 : 1,
37
+ transition: animate ? 'opacity 300ms ease' : undefined,
38
+ }, children: [_jsx(motion.div, { initial: animate ? { scaleY: 0.2, opacity: 0 } : false, animate: { scaleY: visible ? 1 : 0.2, opacity: visible ? 1 : 0.12 }, transition: animate ? { duration: 0.52, delay: bar.index * 0.08, ease: EASE_OUT_EXPO } : { duration: 0 }, style: {
39
+ position: 'absolute',
40
+ left: '16%',
41
+ right: '16%',
42
+ top: topY,
43
+ height: barH,
44
+ borderRadius: 7,
45
+ background: fill,
46
+ transformOrigin: bar.value < 0 && !isStart && !isTotal ? 'top' : 'bottom',
47
+ boxShadow: '0 2px 6px rgba(23, 24, 26, 0.08)',
48
+ } }), _jsx("span", { style: {
49
+ position: 'absolute',
50
+ left: '50%',
51
+ top: Math.max(0, topY - 22),
52
+ transform: 'translateX(-50%)',
53
+ fontFamily: MONO,
54
+ fontSize: 12,
55
+ fontWeight: 850,
56
+ color: fill,
57
+ whiteSpace: 'nowrap',
58
+ fontVariantNumeric: 'tabular-nums',
59
+ }, children: badgeText }), nextBar && visible && (_jsx("div", { style: {
60
+ position: 'absolute',
61
+ left: '84%',
62
+ width: '48%',
63
+ top: endY,
64
+ borderTop: `1.5px dashed ${LINE_STRONG}`,
65
+ pointerEvents: 'none',
66
+ zIndex: 1,
67
+ } }))] }));
68
+ }
69
+ export function WaterfallView({ ctx }) {
70
+ const { node, p, animate, snap, anchors, isDimmed } = useVizChart(ctx);
71
+ const { title, subtitle, steps: rawSteps, unit: rawUnit, lowerIsBetter, stepIds: _sids, w, h, ...rest } = p;
72
+ const H = num(h, 250);
73
+ const root = useRoot(node, rest, {
74
+ style: {
75
+ width: dim(w) ?? '100%',
76
+ minWidth: 0,
77
+ fontFamily: VIZ_FONT_SANS,
78
+ color: INK,
79
+ },
80
+ });
81
+ const steps = arr(rawSteps).filter((s) => !!s && typeof s === 'object' && typeof s.value === 'number');
82
+ if (!steps.length)
83
+ return _jsx("div", { ...root, role: "status", children: "Waterfall \u00B7 no steps" });
84
+ const unit = str(rawUnit);
85
+ const bars = computeWaterfall(steps);
86
+ const allVals = [0, ...bars.flatMap((b) => [b.start, b.end])];
87
+ const minVal = Math.min(...allVals);
88
+ const maxVal = Math.max(1, ...allVals);
89
+ const plotH = Math.max(140, H - 52);
90
+ const scale = scaleLinear()
91
+ .domain([minVal, maxVal * 1.16])
92
+ .range([plotH - 6, 26]);
93
+ // Progressive reveal support via revealTo(chart, indexOrId)
94
+ let visibleCount = bars.length;
95
+ if (typeof snap.reveal === 'number' && Number.isFinite(snap.reveal)) {
96
+ visibleCount = Math.max(1, Math.min(bars.length, Math.round(snap.reveal)));
97
+ }
98
+ else if (typeof snap.reveal === 'string') {
99
+ const idx = bars.findIndex((b) => b.id === snap.reveal || b.label === snap.reveal);
100
+ if (idx >= 0)
101
+ visibleCount = idx + 1;
102
+ }
103
+ const ticks = scale.ticks(4);
104
+ return (_jsxs("figure", { ...root, style: { ...root.style, margin: 0 }, "aria-label": typeof title === 'string' ? title : 'Waterfall', children: [_jsx(ChartHeader, { title: typeof title === 'string' ? title : undefined, subtitle: typeof subtitle === 'string' ? subtitle : undefined }), _jsxs("div", { style: { position: 'relative', height: plotH, display: 'flex', alignItems: 'stretch', gap: 10, borderBottom: `1.5px solid ${LINE_STRONG}` }, children: [ticks.map((tk) => (_jsx("div", { style: {
105
+ position: 'absolute',
106
+ left: 0,
107
+ right: 0,
108
+ top: scale(tk),
109
+ borderTop: tk === 0 ? `1.5px solid ${LINE_STRONG}` : `1px solid ${LINE}`,
110
+ pointerEvents: 'none',
111
+ } }, tk))), bars.map((bar, idx) => (_jsx(WaterfallColumn, { bar: bar, nextBar: bars[idx + 1], scale: scale, plotH: plotH, unit: unit, lowerIsBetter: lowerIsBetter === true, visible: idx < visibleCount, dimmed: isDimmed(bar.id, bar.label), animate: animate, anchors: anchors }, bar.id ?? `${bar.label}_${idx}`)))] }), _jsx("div", { style: { display: 'flex', gap: 10, paddingTop: 9 }, children: bars.map((bar, idx) => (_jsx("div", { style: {
112
+ flex: 1,
113
+ minWidth: 0,
114
+ textAlign: 'center',
115
+ fontSize: 12,
116
+ fontWeight: bar.kind === 'total' || bar.kind === 'start' ? 800 : 650,
117
+ color: idx < visibleCount ? INK : DIMMED,
118
+ }, children: bar.label }, bar.id ?? idx))) })] }));
119
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@joplo-app/kit/plugin").PluginRuntime;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ import { defineRuntime } from '@joplo-app/kit/plugin';
2
+ import { BarChartView } from "./runtime/bar-chart.js";
3
+ import { DeltaBarView } from "./runtime/delta-bar.js";
4
+ import { HeatmapView } from "./runtime/heatmap.js";
5
+ import { LineChartView } from "./runtime/line-chart.js";
6
+ import { RadarView } from "./runtime/radar.js";
7
+ import { RatioBarView } from "./runtime/ratio-bar.js";
8
+ import { SankeyView } from "./runtime/sankey.js";
9
+ import { ScatterPlotView } from "./runtime/scatter-plot.js";
10
+ import { TimeLanesView } from "./runtime/time-lanes.js";
11
+ import { WaterfallView } from "./runtime/waterfall.js";
12
+ export default defineRuntime({
13
+ id: 'viz',
14
+ components: {
15
+ DeltaBar: { react: DeltaBarView },
16
+ BarChart: { react: BarChartView },
17
+ RatioBar: { react: RatioBarView },
18
+ LineChart: { react: LineChartView },
19
+ TimeLanes: { react: TimeLanesView },
20
+ ScatterPlot: { react: ScatterPlotView },
21
+ Heatmap: { react: HeatmapView },
22
+ Sankey: { react: SankeyView },
23
+ Waterfall: { react: WaterfallView },
24
+ Radar: { react: RadarView },
25
+ },
26
+ });
@@ -0,0 +1,202 @@
1
+ import { z } from 'zod';
2
+ export declare const VizOpS: z.ZodUnion<readonly [z.ZodObject<{
3
+ kind: z.ZodLiteral<"focus">;
4
+ chart: z.ZodString;
5
+ targets: z.ZodNullable<z.ZodArray<z.ZodString>>;
6
+ }, z.core.$strict>, z.ZodObject<{
7
+ kind: z.ZodLiteral<"reveal">;
8
+ chart: z.ZodString;
9
+ cutoff: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
10
+ }, z.core.$strict>, z.ZodObject<{
11
+ kind: z.ZodLiteral<"pinBaseline">;
12
+ chart: z.ZodString;
13
+ }, z.core.$strict>, z.ZodObject<{
14
+ kind: z.ZodLiteral<"cursor">;
15
+ chart: z.ZodString;
16
+ value: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
17
+ label: z.ZodOptional<z.ZodString>;
18
+ }, z.core.$strict>]>;
19
+ export type VizOp = z.infer<typeof VizOpS>;
20
+ export declare const VizChartSnapshotS: z.ZodObject<{
21
+ focus: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
22
+ reveal: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
23
+ cursor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
24
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
25
+ label: z.ZodOptional<z.ZodString>;
26
+ }, z.core.$strict>>>;
27
+ baselines: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
28
+ }, z.core.$strict>;
29
+ export type VizChartSnapshot = z.infer<typeof VizChartSnapshotS>;
30
+ export declare const VizFrameS: z.ZodObject<{
31
+ charts: z.ZodRecord<z.ZodString, z.ZodObject<{
32
+ focus: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
33
+ reveal: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
34
+ cursor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
35
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
36
+ label: z.ZodOptional<z.ZodString>;
37
+ }, z.core.$strict>>>;
38
+ baselines: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
39
+ }, z.core.$strict>>;
40
+ }, z.core.$strict>;
41
+ export type VizFrame = z.infer<typeof VizFrameS>;
42
+ /** Step slot accepts raw effect ops before frame() lowers them into deterministic per-chart snapshots. */
43
+ export declare const StepDataS: z.ZodUnion<readonly [z.ZodObject<{
44
+ ops: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
45
+ kind: z.ZodLiteral<"focus">;
46
+ chart: z.ZodString;
47
+ targets: z.ZodNullable<z.ZodArray<z.ZodString>>;
48
+ }, z.core.$strict>, z.ZodObject<{
49
+ kind: z.ZodLiteral<"reveal">;
50
+ chart: z.ZodString;
51
+ cutoff: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
52
+ }, z.core.$strict>, z.ZodObject<{
53
+ kind: z.ZodLiteral<"pinBaseline">;
54
+ chart: z.ZodString;
55
+ }, z.core.$strict>, z.ZodObject<{
56
+ kind: z.ZodLiteral<"cursor">;
57
+ chart: z.ZodString;
58
+ value: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
59
+ label: z.ZodOptional<z.ZodString>;
60
+ }, z.core.$strict>]>>;
61
+ }, z.core.$strict>, z.ZodObject<{
62
+ charts: z.ZodRecord<z.ZodString, z.ZodObject<{
63
+ focus: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
64
+ reveal: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
65
+ cursor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
66
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
67
+ label: z.ZodOptional<z.ZodString>;
68
+ }, z.core.$strict>>>;
69
+ baselines: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
70
+ }, z.core.$strict>>;
71
+ }, z.core.$strict>]>;
72
+ export type RatioSegment = {
73
+ id?: string;
74
+ label?: string;
75
+ value: number;
76
+ color?: string;
77
+ };
78
+ export type RatioProps = {
79
+ total?: unknown;
80
+ left?: unknown;
81
+ right?: unknown;
82
+ threshold?: unknown;
83
+ segments?: unknown;
84
+ };
85
+ export declare function ratioError(p: RatioProps, isBinding?: (v: unknown) => boolean): string | undefined;
86
+ export declare function ratioParts(p: RatioProps): {
87
+ mode: "segments";
88
+ total: number;
89
+ segments: RatioSegment[];
90
+ remainder: number;
91
+ percentages: number[];
92
+ remainderPct: number;
93
+ threshold: number | undefined;
94
+ counts?: undefined;
95
+ } | {
96
+ mode: "pair";
97
+ total: number;
98
+ counts: readonly [number, number, number];
99
+ percentages: number[];
100
+ threshold: number | undefined;
101
+ segments?: undefined;
102
+ remainder?: undefined;
103
+ remainderPct?: undefined;
104
+ } | null;
105
+ export declare const TimeSpanS: z.ZodObject<{
106
+ id: z.ZodString;
107
+ lane: z.ZodString;
108
+ start: z.ZodNumber;
109
+ end: z.ZodNumber;
110
+ label: z.ZodOptional<z.ZodString>;
111
+ shortLabel: z.ZodOptional<z.ZodString>;
112
+ rangeLabel: z.ZodOptional<z.ZodString>;
113
+ status: z.ZodOptional<z.ZodEnum<{
114
+ info: "info";
115
+ ok: "ok";
116
+ warn: "warn";
117
+ fail: "fail";
118
+ accent: "accent";
119
+ }>>;
120
+ color: z.ZodOptional<z.ZodString>;
121
+ }, z.core.$strip>;
122
+ export type TimeSpan = z.infer<typeof TimeSpanS>;
123
+ export declare function readTimeLanes(props: Record<string, unknown>): {
124
+ data: {
125
+ domain: [number, number];
126
+ spans: {
127
+ id: string;
128
+ lane: string;
129
+ start: number;
130
+ end: number;
131
+ label?: string | undefined;
132
+ shortLabel?: string | undefined;
133
+ rangeLabel?: string | undefined;
134
+ status?: "info" | "ok" | "warn" | "fail" | "accent" | undefined;
135
+ color?: string | undefined;
136
+ }[];
137
+ unit: string;
138
+ };
139
+ error?: undefined;
140
+ } | {
141
+ error: string;
142
+ data?: undefined;
143
+ };
144
+ /** Lane order follows the author. Within a lane overlapping intervals occupy separate sub-rows. */
145
+ export declare function layoutTimeLanes(spans: readonly TimeSpan[]): {
146
+ lane: string;
147
+ bars: {
148
+ span: {
149
+ id: string;
150
+ lane: string;
151
+ start: number;
152
+ end: number;
153
+ label?: string | undefined;
154
+ shortLabel?: string | undefined;
155
+ rangeLabel?: string | undefined;
156
+ status?: "info" | "ok" | "warn" | "fail" | "accent" | undefined;
157
+ color?: string | undefined;
158
+ };
159
+ row: number;
160
+ }[];
161
+ rows: number;
162
+ }[];
163
+ export type ParetoCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
164
+ export declare function computeParetoFrontier<T extends {
165
+ x: number;
166
+ y: number;
167
+ }>(points: readonly T[], corner: ParetoCorner): T[];
168
+ export type WaterfallStepInput = {
169
+ id?: string;
170
+ label: string;
171
+ value: number;
172
+ kind?: 'start' | 'delta' | 'subtotal' | 'total';
173
+ deltaLabel?: string;
174
+ color?: string;
175
+ };
176
+ export type WaterfallBar = WaterfallStepInput & {
177
+ index: number;
178
+ start: number;
179
+ end: number;
180
+ kind: 'start' | 'delta' | 'subtotal' | 'total';
181
+ };
182
+ export declare function computeWaterfall(steps: readonly WaterfallStepInput[]): WaterfallBar[];
183
+ export type DeltaBarItemInput = {
184
+ id?: string;
185
+ label: string;
186
+ sub?: string;
187
+ baseline?: number;
188
+ value: number;
189
+ deltaLabel?: string;
190
+ note?: string;
191
+ color?: string;
192
+ lowerIsBetter?: boolean;
193
+ };
194
+ export declare function formatDeltaPercent(baseline: number, current: number, customLabel?: string): string;
195
+ export type ChartSeriesInput = {
196
+ name: string;
197
+ label?: string;
198
+ color?: string;
199
+ area?: boolean;
200
+ dashed?: boolean;
201
+ };
202
+ export declare function validateChartArray(name: string, prop: string, val: unknown, isBinding: (v: unknown) => boolean): string | undefined;