@xemahq/ui-kernel 0.11.1 → 0.12.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/dist/errors/http-error-status.d.ts +17 -0
- package/dist/errors/http-error-status.d.ts.map +1 -0
- package/dist/errors/http-error-status.js +59 -0
- package/dist/errors/http-error-status.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/biome-host/errors.d.ts.map +1 -1
- package/dist/lib/biome-host/errors.js +1 -19
- package/dist/lib/biome-host/errors.js.map +1 -1
- package/dist/offline/index.d.ts.map +1 -1
- package/dist/offline/index.js.map +1 -1
- package/dist/offline/online-controller.d.ts.map +1 -1
- package/dist/offline/online-controller.js +6 -1
- package/dist/offline/online-controller.js.map +1 -1
- package/dist/offline/outbox.d.ts.map +1 -1
- package/dist/offline/outbox.js +2 -24
- package/dist/offline/outbox.js.map +1 -1
- package/package.json +1 -2
- package/src/index.ts +0 -17
- package/src/lib/biome-host/agent-validation.ts +0 -239
- package/src/lib/biome-host/biome-builders.ts +0 -112
- package/src/lib/biome-host/biome-mode.ts +0 -6
- package/src/lib/biome-host/biome-navigation.ts +0 -37
- package/src/lib/biome-host/biome-registry.ts +0 -299
- package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
- package/src/lib/biome-host/biome-scope.tsx +0 -52
- package/src/lib/biome-host/biome-scoped-query.ts +0 -134
- package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
- package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
- package/src/lib/biome-host/define-web-biome.ts +0 -222
- package/src/lib/biome-host/errors.ts +0 -220
- package/src/lib/biome-host/frontend-biome.ts +0 -256
- package/src/lib/biome-host/host-bridge.ts +0 -281
- package/src/lib/biome-host/host-sources.ts +0 -54
- package/src/lib/biome-host/i18n-hooks.ts +0 -51
- package/src/lib/biome-host/i18n-port.test.ts +0 -50
- package/src/lib/biome-host/i18n-port.ts +0 -96
- package/src/lib/biome-host/index.ts +0 -35
- package/src/lib/biome-host/realtime-hooks.ts +0 -75
- package/src/lib/biome-host/realtime-port.ts +0 -115
- package/src/lib/biome-host/session-contributions.ts +0 -296
- package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
- package/src/lib/biome-host/use-page-state.ts +0 -248
- package/src/lib/capabilities/capability-context.ts +0 -25
- package/src/lib/capabilities/capability-provider.tsx +0 -73
- package/src/lib/capabilities/index.ts +0 -17
- package/src/lib/capabilities/types.ts +0 -69
- package/src/lib/capabilities/use-capability.ts +0 -79
- package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
- package/src/lib/contribution-registry/contribution-registry.ts +0 -204
- package/src/lib/contribution-registry/index.ts +0 -9
- package/src/lib/contribution-registry/renderable-registry.ts +0 -142
- package/src/lib/system-bus/capability-invoke.ts +0 -92
- package/src/lib/system-bus/deeplink.ts +0 -210
- package/src/lib/system-bus/enums.ts +0 -86
- package/src/lib/system-bus/host-ports.ts +0 -93
- package/src/lib/system-bus/index.ts +0 -16
- package/src/lib/system-bus/intent-registry.ts +0 -109
- package/src/lib/system-bus/intents.ts +0 -113
- package/src/lib/system-bus/palette.ts +0 -78
- package/src/lib/system-bus/system-bus-builder.ts +0 -159
- package/src/lib/system-bus/system-bus.ts +0 -37
- package/src/lib/system-bus/windows.ts +0 -51
- package/src/offline/id.ts +0 -16
- package/src/offline/index.ts +0 -54
- package/src/offline/mutation.ts +0 -75
- package/src/offline/offline-status-badge.tsx +0 -51
- package/src/offline/online-controller.ts +0 -105
- package/src/offline/outbox.test.ts +0 -172
- package/src/offline/outbox.ts +0 -348
- package/src/offline/react-hooks.ts +0 -40
- package/src/offline/react.tsx +0 -32
- package/src/offline/storage.ts +0 -112
- package/src/offline/types.ts +0 -77
- package/src/org-db/components/DbResultTable.tsx +0 -176
- package/src/org-db/index.ts +0 -1
- package/src/pdf/index.ts +0 -11
- package/src/registry/index.ts +0 -9
- package/src/registry/lib/agent-validation-host.ts +0 -36
- package/src/registry/lib/biome-slot.tsx +0 -50
- package/src/registry/lib/biomes-enabled-context.ts +0 -20
- package/src/registry/lib/extension-points.ts +0 -134
- package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
- package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
- package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
- package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
- package/src/registry/lib/primitives/index.ts +0 -18
- package/src/registry/lib/session-context-builder.ts +0 -84
- package/src/registry/lib/session-context-provider.tsx +0 -33
- package/src/registry/lib/session-context.ts +0 -21
- package/src/registry/lib/session-selectors.ts +0 -272
- package/src/session/comments/CommentRail.tsx +0 -164
- package/src/session/index.ts +0 -3
- package/src/session/lib/cn.ts +0 -11
- package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
- package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
- package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
- package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
- package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
- package/src/session-kit/approvals/Obligation.tsx +0 -111
- package/src/session-kit/approvals/ScopedBody.tsx +0 -392
- package/src/session-kit/approvals/approval-icons.ts +0 -31
- package/src/session-kit/approvals/approval-model.ts +0 -204
- package/src/session-kit/approvals/index.ts +0 -22
- package/src/session-kit/approvals/obligation-display.ts +0 -100
- package/src/session-kit/approvals/risk-accent.ts +0 -47
- package/src/session-kit/approvals/scope-icons.ts +0 -19
- package/src/session-kit/combobox/Combobox.tsx +0 -358
- package/src/session-kit/combobox/use-click-outside.ts +0 -21
- package/src/session-kit/display/ContextHeader.tsx +0 -148
- package/src/session-kit/display/FileDiffCard.tsx +0 -140
- package/src/session-kit/display/MD.tsx +0 -162
- package/src/session-kit/display/MessageTurn.tsx +0 -157
- package/src/session-kit/display/ThinkingPanel.tsx +0 -81
- package/src/session-kit/display/TodoChecklist.tsx +0 -120
- package/src/session-kit/display/TokenMeter.tsx +0 -89
- package/src/session-kit/display/ToolStrip.tsx +0 -278
- package/src/session-kit/display/TypingDots.tsx +0 -24
- package/src/session-kit/index.ts +0 -44
- package/src/session-kit/lib/enums.ts +0 -66
- package/src/session-kit/lib/portal-accent.ts +0 -30
- package/src/session-kit/lib/status-dot.ts +0 -68
- package/src/session-kit/primitives/Avatar.tsx +0 -44
- package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
- package/src/session-kit/primitives/RiskPill.tsx +0 -95
- package/src/session-kit/primitives/ScopeDot.tsx +0 -47
- package/src/session-kit/primitives/Segmented.tsx +0 -71
- package/src/ui/branding/app-branding-context.ts +0 -20
- package/src/ui/branding/app-branding-provider.tsx +0 -123
- package/src/ui/branding/sanitize.ts +0 -89
- package/src/ui/breakpoints.ts +0 -14
- package/src/ui/capture/document-preview.tsx +0 -166
- package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
- package/src/ui/capture/field-spec-to-zod.ts +0 -174
- package/src/ui/capture/field-spec-validate.ts +0 -236
- package/src/ui/capture/field-spec.test.ts +0 -49
- package/src/ui/capture/field-spec.ts +0 -274
- package/src/ui/capture/index.ts +0 -51
- package/src/ui/capture/schema-field-input.tsx +0 -620
- package/src/ui/capture/schema-form.tsx +0 -149
- package/src/ui/capture/submit-values.test.ts +0 -70
- package/src/ui/capture/submit-values.ts +0 -63
- package/src/ui/capture/use-prefill.ts +0 -186
- package/src/ui/capture/use-schema-validation.ts +0 -145
- package/src/ui/capture/use-wizard.ts +0 -180
- package/src/ui/capture/value-format.ts +0 -32
- package/src/ui/capture/wizard.tsx +0 -105
- package/src/ui/charts/bar-chart.tsx +0 -139
- package/src/ui/charts/chart-frame.tsx +0 -125
- package/src/ui/charts/chart-types.ts +0 -52
- package/src/ui/charts/chart-utils.ts +0 -190
- package/src/ui/charts/charts.test.tsx +0 -204
- package/src/ui/charts/donut-chart.tsx +0 -129
- package/src/ui/charts/index.ts +0 -27
- package/src/ui/charts/line-chart.tsx +0 -202
- package/src/ui/charts/sparkline.tsx +0 -109
- package/src/ui/chrome/AsyncBoundary.tsx +0 -74
- package/src/ui/chrome/EmptyState.tsx +0 -257
- package/src/ui/chrome/ErrorCard.tsx +0 -63
- package/src/ui/chrome/LoadingState.tsx +0 -61
- package/src/ui/chrome/PageHeader.tsx +0 -137
- package/src/ui/chrome/RecordCardList.tsx +0 -98
- package/src/ui/chrome/StateCard.tsx +0 -150
- package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
- package/src/ui/chrome/page-shell.spec.tsx +0 -117
- package/src/ui/chrome/page-shell.tsx +0 -221
- package/src/ui/chrome/scope-badge.tsx +0 -40
- package/src/ui/chrome/status-badge.tsx +0 -79
- package/src/ui/cn.ts +0 -32
- package/src/ui/design-tokens.ts +0 -372
- package/src/ui/hooks/use-debounced-value.ts +0 -16
- package/src/ui/hooks/use-is-mobile.ts +0 -28
- package/src/ui/index.ts +0 -110
- package/src/ui/pdf/pdf-preview.tsx +0 -122
- package/src/ui/primitives/alert-dialog.tsx +0 -104
- package/src/ui/primitives/async-combobox.tsx +0 -182
- package/src/ui/primitives/badge-variants.ts +0 -21
- package/src/ui/primitives/badge.tsx +0 -25
- package/src/ui/primitives/button-variants.ts +0 -31
- package/src/ui/primitives/button.tsx +0 -29
- package/src/ui/primitives/card.tsx +0 -43
- package/src/ui/primitives/checkbox.tsx +0 -26
- package/src/ui/primitives/collapsible.tsx +0 -9
- package/src/ui/primitives/dialog.tsx +0 -103
- package/src/ui/primitives/dropdown-menu.tsx +0 -179
- package/src/ui/primitives/form-stepper.tsx +0 -94
- package/src/ui/primitives/form-stepper.types.ts +0 -15
- package/src/ui/primitives/input.tsx +0 -22
- package/src/ui/primitives/label.tsx +0 -17
- package/src/ui/primitives/overflow-tabs.tsx +0 -331
- package/src/ui/primitives/popover.tsx +0 -33
- package/src/ui/primitives/preview-device-frame.tsx +0 -213
- package/src/ui/primitives/radio-group.tsx +0 -36
- package/src/ui/primitives/resizable.tsx +0 -67
- package/src/ui/primitives/scroll-area.tsx +0 -38
- package/src/ui/primitives/select.tsx +0 -143
- package/src/ui/primitives/separator.tsx +0 -20
- package/src/ui/primitives/sheet.tsx +0 -107
- package/src/ui/primitives/skeleton.tsx +0 -99
- package/src/ui/primitives/switch.tsx +0 -27
- package/src/ui/primitives/table.tsx +0 -72
- package/src/ui/primitives/tabs.tsx +0 -53
- package/src/ui/primitives/tag-multi-select.tsx +0 -261
- package/src/ui/primitives/textarea.tsx +0 -21
- package/src/ui/primitives/tooltip.tsx +0 -30
- package/src/ui/primitives/url-preview-chrome.tsx +0 -103
- package/src/vista/GenericCatalogueSurface.tsx +0 -179
- package/src/vista/SurfaceFallbackCard.tsx +0 -109
- package/src/vista/VistaPanel.tsx +0 -163
- package/src/vista/form-payload.spec.ts +0 -139
- package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
- package/src/vista/html/CustomUiFrame.tsx +0 -206
- package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
- package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
- package/src/vista/html/custom-ui-frame-contract.ts +0 -88
- package/src/vista/html/custom-ui-intents.spec.ts +0 -135
- package/src/vista/html/custom-ui-intents.ts +0 -155
- package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
- package/src/vista/html/custom-ui-srcdoc.ts +0 -193
- package/src/vista/html/index.ts +0 -13
- package/src/vista/index.ts +0 -52
- package/src/vista/surface-catalogue.spec.ts +0 -140
- package/src/vista/surface-catalogue.ts +0 -90
- package/src/vista/surface-icons.ts +0 -57
- package/src/vista/surface-registry.ts +0 -56
- package/src/vista/surfaces/ChartSurface.tsx +0 -34
- package/src/vista/surfaces/FilesSurface.tsx +0 -202
- package/src/vista/surfaces/FormSurface.tsx +0 -380
- package/src/vista/surfaces/HtmlSurface.tsx +0 -43
- package/src/vista/surfaces/TableSurface.tsx +0 -100
- package/src/vista/surfaces/UrlSurface.tsx +0 -40
- package/src/vista/surfaces/blob-surfaces.tsx +0 -139
- package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
- package/src/vista/surfaces/elicitation-transport.ts +0 -367
- package/src/vista/surfaces/file-surface-utils.ts +0 -69
- package/src/vista/surfaces/index.ts +0 -24
- package/src/vista/surfaces/register-surfaces.tsx +0 -139
- package/src/vista/surfaces/text-surfaces.tsx +0 -132
- package/src/vista/use-vista-tabs.ts +0 -196
- package/src/vista/vista-code-renderer-context.ts +0 -16
- package/src/vista/vista-code-renderer.tsx +0 -35
- package/src/vista/vista-file-context.ts +0 -14
- package/src/vista/vista-file-source.tsx +0 -141
- package/src/vista/vista-form-context.ts +0 -20
- package/src/vista/vista-form-host.tsx +0 -48
- package/src/vista/vista-model.ts +0 -137
- package/src/vista/vista-open-context.tsx +0 -27
- package/src/vista/vista-open-state.ts +0 -11
- package/src/vista/vista-payloads.ts +0 -635
- package/src/vista/vista-tabs-manifest.ts +0 -138
- package/src/vista/vista-tools.ts +0 -232
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// Chart primitives — deterministic, pure helpers (Wave 9.2)
|
|
3
|
-
//
|
|
4
|
-
// Scale/tick maths, the themeable color palette, value formatting, finite-value
|
|
5
|
-
// filtering and aria-summary construction. Everything here is a pure function:
|
|
6
|
-
// given the same input it returns the same output (no Math.random, no Date.now)
|
|
7
|
-
// so the same data always yields the same SVG.
|
|
8
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
9
|
-
import type { ChartDatum, ChartValueFormatter } from './chart-types';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Themeable categorical palette. Each slot is a CSS custom property with a
|
|
13
|
-
* graceful fallback: a host that defines `--chart-N` (per theme) wins; slot 0
|
|
14
|
-
* additionally follows the app brand via `--app-primary-color`. The fallbacks
|
|
15
|
-
* are the platform's bold, dark-mode-safe primaries — used only when no token
|
|
16
|
-
* is defined, so a chart is never invisible. Data is NEVER conveyed by color
|
|
17
|
-
* alone: every primitive also renders the label + value.
|
|
18
|
-
*/
|
|
19
|
-
export const CHART_PALETTE: readonly string[] = [
|
|
20
|
-
'var(--app-primary-color, var(--chart-1, #00A4EF))',
|
|
21
|
-
'var(--chart-2, #7FBA00)',
|
|
22
|
-
'var(--chart-3, #FFB900)',
|
|
23
|
-
'var(--chart-4, #F25022)',
|
|
24
|
-
'var(--chart-5, #8B5CF6)',
|
|
25
|
-
'var(--chart-6, #EC4899)',
|
|
26
|
-
'var(--chart-7, #06B6D4)',
|
|
27
|
-
'var(--chart-8, #F59E0B)',
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
/** Resolve the color for the datum at `index`: explicit override wins, else palette (wraps). */
|
|
31
|
-
export function chartColorAt(index: number, override?: string): string {
|
|
32
|
-
if (override !== undefined && override.length > 0) {
|
|
33
|
-
return override;
|
|
34
|
-
}
|
|
35
|
-
const size = CHART_PALETTE.length;
|
|
36
|
-
// `index % size` alone is NOT a wrap: JS `%` keeps the sign, so a negative
|
|
37
|
-
// index lands on a negative slot and reads back `undefined` — which used to
|
|
38
|
-
// be returned as a `string` and rendered as a missing `fill`/`stroke`. Wrap
|
|
39
|
-
// forward instead. A non-finite index yields a NaN slot and falls through to
|
|
40
|
-
// the throw rather than silently painting the wrong series color.
|
|
41
|
-
const slot = ((Math.trunc(index) % size) + size) % size;
|
|
42
|
-
const color = CHART_PALETTE[slot];
|
|
43
|
-
if (color === undefined) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`chartColorAt: no palette color for index ${index} (resolved slot ${slot} of ${size}).`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return color;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Deterministic default value formatter. Integers render bare; fractions get a
|
|
53
|
-
* fixed 2 decimals (with trailing zeros trimmed). Locale-free on purpose so the
|
|
54
|
-
* SVG is byte-identical across machines/locales.
|
|
55
|
-
*/
|
|
56
|
-
export function defaultFormatValue(value: number): string {
|
|
57
|
-
if (!Number.isFinite(value)) {
|
|
58
|
-
return '—';
|
|
59
|
-
}
|
|
60
|
-
if (Number.isInteger(value)) {
|
|
61
|
-
return String(value);
|
|
62
|
-
}
|
|
63
|
-
return String(Number(value.toFixed(2)));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** A datum whose value is a finite number (post-filter). */
|
|
67
|
-
export interface FiniteDatum {
|
|
68
|
-
readonly label: string;
|
|
69
|
-
readonly value: number;
|
|
70
|
-
readonly color?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Keep only points with a finite numeric value — NaN/±Infinity are dropped, never plotted. */
|
|
74
|
-
export function finitePoints(points: readonly ChartDatum[]): FiniteDatum[] {
|
|
75
|
-
const out: FiniteDatum[] = [];
|
|
76
|
-
for (const p of points) {
|
|
77
|
-
if (Number.isFinite(p.value)) {
|
|
78
|
-
out.push({ label: p.label, value: p.value, color: p.color });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return out;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ── nice-number axis scale (deterministic) ──────────────────────────────────
|
|
85
|
-
|
|
86
|
-
function niceNum(range: number, round: boolean): number {
|
|
87
|
-
const exponent = Math.floor(Math.log10(range));
|
|
88
|
-
const pow = Math.pow(10, exponent);
|
|
89
|
-
const fraction = range / pow;
|
|
90
|
-
let niceFraction: number;
|
|
91
|
-
if (round) {
|
|
92
|
-
if (fraction < 1.5) {
|
|
93
|
-
niceFraction = 1;
|
|
94
|
-
} else if (fraction < 3) {
|
|
95
|
-
niceFraction = 2;
|
|
96
|
-
} else if (fraction < 7) {
|
|
97
|
-
niceFraction = 5;
|
|
98
|
-
} else {
|
|
99
|
-
niceFraction = 10;
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
if (fraction <= 1) {
|
|
103
|
-
niceFraction = 1;
|
|
104
|
-
} else if (fraction <= 2) {
|
|
105
|
-
niceFraction = 2;
|
|
106
|
-
} else if (fraction <= 5) {
|
|
107
|
-
niceFraction = 5;
|
|
108
|
-
} else {
|
|
109
|
-
niceFraction = 10;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return niceFraction * pow;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Trim binary-float dust so ticks like 0.30000000000000004 read as 0.3. */
|
|
116
|
-
function tidy(value: number): number {
|
|
117
|
-
return Number(value.toPrecision(12));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface NiceScale {
|
|
121
|
-
readonly min: number;
|
|
122
|
-
readonly max: number;
|
|
123
|
-
readonly ticks: readonly number[];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface NiceScaleOptions {
|
|
127
|
-
/**
|
|
128
|
-
* Pin the baseline at 0 so heights are proportional (bars, donuts). When
|
|
129
|
-
* `false` the domain hugs the data — better for line charts over a narrow
|
|
130
|
-
* band. Defaults to `true`.
|
|
131
|
-
*/
|
|
132
|
-
readonly pinZero?: boolean;
|
|
133
|
-
readonly maxTicks?: number;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Compute a "nice" axis domain + evenly-spaced ticks for `[dataMin, dataMax]`.
|
|
138
|
-
* With `pinZero` (default) the baseline is pinned at 0 so bar heights are
|
|
139
|
-
* proportional and negatives read below the axis. Fully deterministic; guards
|
|
140
|
-
* the degenerate all-equal / all-zero case instead of producing NaN.
|
|
141
|
-
*/
|
|
142
|
-
export function niceScale(
|
|
143
|
-
dataMin: number,
|
|
144
|
-
dataMax: number,
|
|
145
|
-
options: NiceScaleOptions = {},
|
|
146
|
-
): NiceScale {
|
|
147
|
-
const pinZero = options.pinZero ?? true;
|
|
148
|
-
const maxTicks = options.maxTicks ?? 5;
|
|
149
|
-
const lo = pinZero ? Math.min(0, dataMin) : dataMin;
|
|
150
|
-
let hi = pinZero ? Math.max(0, dataMax) : dataMax;
|
|
151
|
-
if (lo === hi) {
|
|
152
|
-
// Flat series (e.g. all equal): open a unit window so we never divide by 0.
|
|
153
|
-
hi = lo + 1;
|
|
154
|
-
}
|
|
155
|
-
const ticks: number[] = [];
|
|
156
|
-
const range = niceNum(hi - lo, false);
|
|
157
|
-
const step = niceNum(range / Math.max(1, maxTicks - 1), true);
|
|
158
|
-
const niceMin = Math.floor(lo / step) * step;
|
|
159
|
-
const niceMax = Math.ceil(hi / step) * step;
|
|
160
|
-
for (let v = niceMin; v <= niceMax + step * 0.5; v += step) {
|
|
161
|
-
ticks.push(tidy(v));
|
|
162
|
-
}
|
|
163
|
-
return { min: tidy(niceMin), max: tidy(niceMax), ticks };
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// ── aria summary ────────────────────────────────────────────────────────────
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Build a concise, deterministic aria-label summary from a title and the
|
|
170
|
-
* finite points. Keeps it readable: title, count, then up to `maxItems`
|
|
171
|
-
* "label value" pairs (with an ellipsis when truncated). Color is never the
|
|
172
|
-
* carrier of meaning — this text is.
|
|
173
|
-
*/
|
|
174
|
-
export function buildAriaSummary(
|
|
175
|
-
title: string,
|
|
176
|
-
points: readonly FiniteDatum[],
|
|
177
|
-
format: ChartValueFormatter,
|
|
178
|
-
noun: string,
|
|
179
|
-
maxItems = 8,
|
|
180
|
-
): string {
|
|
181
|
-
if (points.length === 0) {
|
|
182
|
-
return `${title}: no data.`;
|
|
183
|
-
}
|
|
184
|
-
const shown = points.slice(0, maxItems);
|
|
185
|
-
const pairs = shown.map((p) => `${p.label} ${format(p.value)}`).join(', ');
|
|
186
|
-
const suffix =
|
|
187
|
-
points.length > maxItems ? `, and ${points.length - maxItems} more` : '';
|
|
188
|
-
const count = points.length === 1 ? `1 ${noun}` : `${points.length} ${noun}s`;
|
|
189
|
-
return `${title}: ${count}. ${pairs}${suffix}.`;
|
|
190
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// Chart primitives — render proofs (Wave 9.2)
|
|
3
|
-
//
|
|
4
|
-
// Repo convention: `renderToStaticMarkup` (no @testing-library, effects DON'T
|
|
5
|
-
// run — so `useIsMobile` stays false and the desktop layout renders). We assert
|
|
6
|
-
// on the produced SVG markup: element counts, the fluid `viewBox` + width,
|
|
7
|
-
// the aria summary, the legend, and — critically — that no coordinate ever
|
|
8
|
-
// serializes as `NaN`.
|
|
9
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
10
|
-
import { renderToStaticMarkup } from 'react-dom/server';
|
|
11
|
-
import { describe, expect, it } from 'vitest';
|
|
12
|
-
|
|
13
|
-
import { BarChart } from './bar-chart';
|
|
14
|
-
import { DonutChart } from './donut-chart';
|
|
15
|
-
import { LineChart } from './line-chart';
|
|
16
|
-
import { Sparkline } from './sparkline';
|
|
17
|
-
|
|
18
|
-
const count = (markup: string, tag: string): number =>
|
|
19
|
-
markup.match(new RegExp(`<${tag}[\\s>]`, 'g'))?.length ?? 0;
|
|
20
|
-
|
|
21
|
-
describe('BarChart', () => {
|
|
22
|
-
const data = [
|
|
23
|
-
{ label: 'Q1', value: 120 },
|
|
24
|
-
{ label: 'Q2', value: 340 },
|
|
25
|
-
{ label: 'Q3', value: 210 },
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
it('renders one bar per datum, fluid SVG, legend and aria summary', () => {
|
|
29
|
-
const markup = renderToStaticMarkup(<BarChart title="Revenue" data={data} />);
|
|
30
|
-
expect(count(markup, 'rect')).toBe(3);
|
|
31
|
-
expect(markup).toContain('viewBox="0 0 640 360"');
|
|
32
|
-
expect(markup).toContain('width="100%"');
|
|
33
|
-
expect(markup).toContain('role="img"');
|
|
34
|
-
// aria summary carries the title + the values (data is never color-only).
|
|
35
|
-
expect(markup).toContain('aria-label="Revenue:');
|
|
36
|
-
expect(markup).toContain('Q2 340');
|
|
37
|
-
// legend beside the plot (desktop: effects don't run so useIsMobile=false).
|
|
38
|
-
expect(count(markup, 'li')).toBe(3);
|
|
39
|
-
expect(markup).not.toContain('NaN');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('renders an explicit empty state (no NaN) for an empty series', () => {
|
|
43
|
-
const markup = renderToStaticMarkup(<BarChart title="Revenue" data={[]} />);
|
|
44
|
-
expect(markup).toContain('role="img"');
|
|
45
|
-
expect(markup).toContain('aria-label="Revenue: No data"');
|
|
46
|
-
expect(count(markup, 'rect')).toBe(0);
|
|
47
|
-
expect(markup).not.toContain('NaN');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('skips a non-finite value instead of emitting NaN coordinates', () => {
|
|
51
|
-
const markup = renderToStaticMarkup(
|
|
52
|
-
<BarChart
|
|
53
|
-
title="Revenue"
|
|
54
|
-
data={[
|
|
55
|
-
{ label: 'Q1', value: 120 },
|
|
56
|
-
{ label: 'Q2', value: Number.NaN },
|
|
57
|
-
{ label: 'Q3', value: Number.POSITIVE_INFINITY },
|
|
58
|
-
]}
|
|
59
|
-
/>,
|
|
60
|
-
);
|
|
61
|
-
// only the one finite bar survives
|
|
62
|
-
expect(count(markup, 'rect')).toBe(1);
|
|
63
|
-
expect(markup).not.toContain('NaN');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('honours a custom value formatter', () => {
|
|
67
|
-
const markup = renderToStaticMarkup(
|
|
68
|
-
<BarChart title="Revenue" data={data} formatValue={(v) => `$${v}`} />,
|
|
69
|
-
);
|
|
70
|
-
expect(markup).toContain('$340');
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('LineChart', () => {
|
|
75
|
-
const series = [
|
|
76
|
-
{
|
|
77
|
-
name: 'Sessions',
|
|
78
|
-
points: [
|
|
79
|
-
{ label: 'Mon', value: 10 },
|
|
80
|
-
{ label: 'Tue', value: 30 },
|
|
81
|
-
{ label: 'Wed', value: 20 },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: 'Errors',
|
|
86
|
-
points: [
|
|
87
|
-
{ label: 'Mon', value: 2 },
|
|
88
|
-
{ label: 'Tue', value: 5 },
|
|
89
|
-
{ label: 'Wed', value: 1 },
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
it('renders a polyline per series with point markers, fluid + accessible', () => {
|
|
95
|
-
const markup = renderToStaticMarkup(<LineChart title="Traffic" series={series} />);
|
|
96
|
-
expect(count(markup, 'polyline')).toBe(2);
|
|
97
|
-
expect(count(markup, 'circle')).toBe(6);
|
|
98
|
-
expect(markup).toContain('viewBox="0 0 640 360"');
|
|
99
|
-
expect(markup).toContain('width="100%"');
|
|
100
|
-
expect(markup).toContain('role="img"');
|
|
101
|
-
expect(markup).toContain('aria-label="Traffic:');
|
|
102
|
-
// two named series => two legend rows
|
|
103
|
-
expect(count(markup, 'li')).toBe(2);
|
|
104
|
-
expect(markup).not.toContain('NaN');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('breaks the line at a non-finite gap (no NaN, one fewer marker)', () => {
|
|
108
|
-
const markup = renderToStaticMarkup(
|
|
109
|
-
<LineChart
|
|
110
|
-
title="Traffic"
|
|
111
|
-
series={[
|
|
112
|
-
{
|
|
113
|
-
name: 'Sessions',
|
|
114
|
-
points: [
|
|
115
|
-
{ label: 'Mon', value: 10 },
|
|
116
|
-
{ label: 'Tue', value: Number.NaN },
|
|
117
|
-
{ label: 'Wed', value: 20 },
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
]}
|
|
121
|
-
/>,
|
|
122
|
-
);
|
|
123
|
-
// gap splits the single line into two 1-point segments; markers only for finite points
|
|
124
|
-
expect(count(markup, 'circle')).toBe(2);
|
|
125
|
-
expect(markup).not.toContain('NaN');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('renders the empty state when no series has a finite point', () => {
|
|
129
|
-
const markup = renderToStaticMarkup(
|
|
130
|
-
<LineChart title="Traffic" series={[{ name: 'X', points: [] }]} />,
|
|
131
|
-
);
|
|
132
|
-
expect(markup).toContain('aria-label="Traffic: No data"');
|
|
133
|
-
expect(count(markup, 'polyline')).toBe(0);
|
|
134
|
-
expect(markup).not.toContain('NaN');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('Sparkline', () => {
|
|
139
|
-
it('renders a fluid trend polyline with an aria summary', () => {
|
|
140
|
-
const markup = renderToStaticMarkup(
|
|
141
|
-
<Sparkline title="Latency" values={[5, 8, 6, 9, 7]} />,
|
|
142
|
-
);
|
|
143
|
-
expect(count(markup, 'polyline')).toBe(1);
|
|
144
|
-
expect(markup).toContain('width="100%"');
|
|
145
|
-
expect(markup).toContain('viewBox="0 0 100 28"');
|
|
146
|
-
expect(markup).toContain('role="img"');
|
|
147
|
-
expect(markup).toContain('aria-label="Latency:');
|
|
148
|
-
expect(markup).not.toContain('NaN');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('renders an empty state for no finite values', () => {
|
|
152
|
-
const markup = renderToStaticMarkup(
|
|
153
|
-
<Sparkline title="Latency" values={[Number.NaN, Number.POSITIVE_INFINITY]} />,
|
|
154
|
-
);
|
|
155
|
-
expect(markup).toContain('aria-label="Latency: No data"');
|
|
156
|
-
expect(count(markup, 'polyline')).toBe(0);
|
|
157
|
-
expect(markup).not.toContain('NaN');
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('DonutChart', () => {
|
|
162
|
-
const data = [
|
|
163
|
-
{ label: 'Passed', value: 70 },
|
|
164
|
-
{ label: 'Failed', value: 20 },
|
|
165
|
-
{ label: 'Skipped', value: 10 },
|
|
166
|
-
];
|
|
167
|
-
|
|
168
|
-
it('renders one arc path per positive slice, with legend percentages', () => {
|
|
169
|
-
const markup = renderToStaticMarkup(<DonutChart title="Results" data={data} />);
|
|
170
|
-
expect(count(markup, 'path')).toBe(3);
|
|
171
|
-
expect(markup).toContain('viewBox="0 0 200 200"');
|
|
172
|
-
expect(markup).toContain('width="100%"');
|
|
173
|
-
expect(markup).toContain('role="img"');
|
|
174
|
-
expect(markup).toContain('aria-label="Results:');
|
|
175
|
-
// legend shows label + value + percent (never color-only)
|
|
176
|
-
expect(markup).toContain('70%');
|
|
177
|
-
expect(count(markup, 'li')).toBe(3);
|
|
178
|
-
expect(markup).not.toContain('NaN');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('skips negative / non-finite slices', () => {
|
|
182
|
-
const markup = renderToStaticMarkup(
|
|
183
|
-
<DonutChart
|
|
184
|
-
title="Results"
|
|
185
|
-
data={[
|
|
186
|
-
{ label: 'Passed', value: 70 },
|
|
187
|
-
{ label: 'Bad', value: -5 },
|
|
188
|
-
{ label: 'Worse', value: Number.NaN },
|
|
189
|
-
]}
|
|
190
|
-
/>,
|
|
191
|
-
);
|
|
192
|
-
expect(count(markup, 'path')).toBe(1);
|
|
193
|
-
expect(markup).not.toContain('NaN');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('renders the empty state when every value is zero', () => {
|
|
197
|
-
const markup = renderToStaticMarkup(
|
|
198
|
-
<DonutChart title="Results" data={[{ label: 'None', value: 0 }]} />,
|
|
199
|
-
);
|
|
200
|
-
expect(markup).toContain('aria-label="Results: No data"');
|
|
201
|
-
expect(count(markup, 'path')).toBe(0);
|
|
202
|
-
expect(markup).not.toContain('NaN');
|
|
203
|
-
});
|
|
204
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// DonutChart — proportional ring, pure SVG (Wave 9.2)
|
|
3
|
-
//
|
|
4
|
-
// Slices are built from finite, non-negative values (a slice needs a magnitude).
|
|
5
|
-
// If no finite positive value remains, an explicit empty state renders instead
|
|
6
|
-
// of a broken ring.
|
|
7
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
8
|
-
|
|
9
|
-
import { ChartEmpty, ChartFrame, type ChartLegendItem } from './chart-frame';
|
|
10
|
-
import {
|
|
11
|
-
buildAriaSummary,
|
|
12
|
-
chartColorAt,
|
|
13
|
-
defaultFormatValue,
|
|
14
|
-
} from './chart-utils';
|
|
15
|
-
|
|
16
|
-
import type { ChartBaseProps, ChartDatum } from './chart-types';
|
|
17
|
-
import type { ReactNode } from 'react';
|
|
18
|
-
|
|
19
|
-
const SIZE = 200;
|
|
20
|
-
const CX = SIZE / 2;
|
|
21
|
-
const CY = SIZE / 2;
|
|
22
|
-
const R_OUTER = 90;
|
|
23
|
-
const R_INNER = 56;
|
|
24
|
-
const FULL = Math.PI * 2;
|
|
25
|
-
|
|
26
|
-
export interface DonutChartProps extends ChartBaseProps {
|
|
27
|
-
/** The slices — one per labelled datum. Negative/non-finite values are skipped. */
|
|
28
|
-
readonly data: readonly ChartDatum[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Point on a circle at `angle` (radians, 0 = 12 o'clock, clockwise). */
|
|
32
|
-
function polar(radius: number, angle: number): [number, number] {
|
|
33
|
-
return [CX + radius * Math.sin(angle), CY - radius * Math.cos(angle)];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Annulus-segment path from `start` to `end` (radians). */
|
|
37
|
-
function slicePath(start: number, end: number): string {
|
|
38
|
-
const [ox1, oy1] = polar(R_OUTER, start);
|
|
39
|
-
const [ox2, oy2] = polar(R_OUTER, end);
|
|
40
|
-
const [ix2, iy2] = polar(R_INNER, end);
|
|
41
|
-
const [ix1, iy1] = polar(R_INNER, start);
|
|
42
|
-
const largeArc = end - start > Math.PI ? 1 : 0;
|
|
43
|
-
return [
|
|
44
|
-
`M ${ox1} ${oy1}`,
|
|
45
|
-
`A ${R_OUTER} ${R_OUTER} 0 ${largeArc} 1 ${ox2} ${oy2}`,
|
|
46
|
-
`L ${ix2} ${iy2}`,
|
|
47
|
-
`A ${R_INNER} ${R_INNER} 0 ${largeArc} 0 ${ix1} ${iy1}`,
|
|
48
|
-
'Z',
|
|
49
|
-
].join(' ');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function DonutChart({
|
|
53
|
-
data,
|
|
54
|
-
title,
|
|
55
|
-
ariaLabel,
|
|
56
|
-
formatValue,
|
|
57
|
-
className,
|
|
58
|
-
emptyLabel = 'No data',
|
|
59
|
-
}: DonutChartProps): ReactNode {
|
|
60
|
-
const format = formatValue ?? defaultFormatValue;
|
|
61
|
-
const slices = data.filter((d) => Number.isFinite(d.value) && d.value > 0);
|
|
62
|
-
const total = slices.reduce((sum, d) => sum + d.value, 0);
|
|
63
|
-
|
|
64
|
-
if (slices.length === 0 || total <= 0) {
|
|
65
|
-
return (
|
|
66
|
-
<ChartEmpty title={title} label={emptyLabel} className={className} />
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const legend: ChartLegendItem[] = slices.map((d, i) => ({
|
|
71
|
-
label: d.label,
|
|
72
|
-
value: `${format(d.value)} (${Math.round((d.value / total) * 100)}%)`,
|
|
73
|
-
color: chartColorAt(i, d.color),
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
const summaryPoints = slices.map((d) => ({ label: d.label, value: d.value }));
|
|
77
|
-
const summary =
|
|
78
|
-
ariaLabel ?? buildAriaSummary(title, summaryPoints, format, 'slice');
|
|
79
|
-
|
|
80
|
-
let cursor = 0;
|
|
81
|
-
const arcs = slices.map((d, i) => {
|
|
82
|
-
const start = cursor;
|
|
83
|
-
// A lone full-circle slice can't be drawn as a single arc (start===end):
|
|
84
|
-
// nudge the end just shy of a full turn so the ring still closes visually.
|
|
85
|
-
const sweep = slices.length === 1 ? FULL - 1e-3 : (d.value / total) * FULL;
|
|
86
|
-
const end = start + sweep;
|
|
87
|
-
cursor = end;
|
|
88
|
-
return {
|
|
89
|
-
path: slicePath(start, end),
|
|
90
|
-
color: chartColorAt(i, d.color),
|
|
91
|
-
key: `${d.label}-${i}`,
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const plot = (
|
|
96
|
-
<svg
|
|
97
|
-
role="img"
|
|
98
|
-
aria-label={summary}
|
|
99
|
-
width="100%"
|
|
100
|
-
viewBox={`0 0 ${SIZE} ${SIZE}`}
|
|
101
|
-
preserveAspectRatio="xMidYMid meet"
|
|
102
|
-
className="mx-auto block h-auto w-full max-w-[240px] text-ink-4"
|
|
103
|
-
>
|
|
104
|
-
{arcs.map((a) => (
|
|
105
|
-
<path
|
|
106
|
-
key={a.key}
|
|
107
|
-
d={a.path}
|
|
108
|
-
fill={a.color}
|
|
109
|
-
stroke="var(--card, transparent)"
|
|
110
|
-
strokeWidth={1}
|
|
111
|
-
/>
|
|
112
|
-
))}
|
|
113
|
-
<text
|
|
114
|
-
x={CX}
|
|
115
|
-
y={CY}
|
|
116
|
-
textAnchor="middle"
|
|
117
|
-
dominantBaseline="middle"
|
|
118
|
-
fontSize={20}
|
|
119
|
-
fontWeight={600}
|
|
120
|
-
fill="currentColor"
|
|
121
|
-
className="text-ink"
|
|
122
|
-
>
|
|
123
|
-
{format(total)}
|
|
124
|
-
</text>
|
|
125
|
-
</svg>
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
return <ChartFrame plot={plot} legend={legend} className={className} />;
|
|
129
|
-
}
|
package/src/ui/charts/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// Chart primitives (Wave 9.2) — pure-SVG, responsive-by-construction dashboard
|
|
3
|
-
// charts. The kernel ships NO chart library: a strict CSP blocks external
|
|
4
|
-
// scripts/fonts/images, so every chart is inline SVG built from React.
|
|
5
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
6
|
-
export type {
|
|
7
|
-
ChartDatum,
|
|
8
|
-
ChartLineSeries,
|
|
9
|
-
ChartValueFormatter,
|
|
10
|
-
ChartBaseProps,
|
|
11
|
-
} from './chart-types';
|
|
12
|
-
export {
|
|
13
|
-
CHART_PALETTE,
|
|
14
|
-
chartColorAt,
|
|
15
|
-
defaultFormatValue,
|
|
16
|
-
finitePoints,
|
|
17
|
-
niceScale,
|
|
18
|
-
buildAriaSummary,
|
|
19
|
-
type NiceScale,
|
|
20
|
-
type NiceScaleOptions,
|
|
21
|
-
type FiniteDatum,
|
|
22
|
-
} from './chart-utils';
|
|
23
|
-
export { ChartLegend, type ChartLegendItem } from './chart-frame';
|
|
24
|
-
export { BarChart, type BarChartProps } from './bar-chart';
|
|
25
|
-
export { LineChart, type LineChartProps } from './line-chart';
|
|
26
|
-
export { Sparkline, type SparklineProps } from './sparkline';
|
|
27
|
-
export { DonutChart, type DonutChartProps } from './donut-chart';
|