@dudousxd/nestjs-catalog-react 0.1.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-bklit +21 -0
- package/README.md +282 -0
- package/dist/AccessConsole.d.ts +40 -0
- package/dist/AccessConsole.js +160 -0
- package/dist/CatalogManager.d.ts +12 -0
- package/dist/CatalogManager.js +123 -0
- package/dist/ConnectionPanel.d.ts +41 -0
- package/dist/ConnectionPanel.js +228 -0
- package/dist/CoverageLedger.d.ts +16 -0
- package/dist/CoverageLedger.js +16 -0
- package/dist/DashboardBoard.d.ts +10 -0
- package/dist/DashboardBoard.js +206 -0
- package/dist/EditableField.d.ts +18 -0
- package/dist/EditableField.js +61 -0
- package/dist/FlowView.d.ts +13 -0
- package/dist/FlowView.js +93 -0
- package/dist/GovernanceTimeline.d.ts +16 -0
- package/dist/GovernanceTimeline.js +93 -0
- package/dist/ObjectExplorer.d.ts +9 -0
- package/dist/ObjectExplorer.js +153 -0
- package/dist/PipelineConsole.d.ts +20 -0
- package/dist/PipelineConsole.js +272 -0
- package/dist/QueryConsole.d.ts +11 -0
- package/dist/QueryConsole.js +144 -0
- package/dist/SavedQueryPanel.d.ts +16 -0
- package/dist/SavedQueryPanel.js +78 -0
- package/dist/TraceExplorer.d.ts +54 -0
- package/dist/TraceExplorer.js +342 -0
- package/dist/TransformEditor.d.ts +23 -0
- package/dist/TransformEditor.js +129 -0
- package/dist/WorkflowCanvas.d.ts +24 -0
- package/dist/WorkflowCanvas.js +701 -0
- package/dist/charts/bklit/animation.d.ts +19 -0
- package/dist/charts/bklit/animation.js +28 -0
- package/dist/charts/bklit/area-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/area-chart-loading.js +30 -0
- package/dist/charts/bklit/area-chart.d.ts +47 -0
- package/dist/charts/bklit/area-chart.js +65 -0
- package/dist/charts/bklit/area-gradient-defs.d.ts +28 -0
- package/dist/charts/bklit/area-gradient-defs.js +23 -0
- package/dist/charts/bklit/area.d.ts +75 -0
- package/dist/charts/bklit/area.js +112 -0
- package/dist/charts/bklit/bar-chart-loading.d.ts +16 -0
- package/dist/charts/bklit/bar-chart-loading.js +22 -0
- package/dist/charts/bklit/bar-chart.d.ts +54 -0
- package/dist/charts/bklit/bar-chart.js +440 -0
- package/dist/charts/bklit/bar-depth-geometry.d.ts +41 -0
- package/dist/charts/bklit/bar-depth-geometry.js +46 -0
- package/dist/charts/bklit/bar-squares-layout.d.ts +36 -0
- package/dist/charts/bklit/bar-squares-layout.js +46 -0
- package/dist/charts/bklit/bar-squares.d.ts +48 -0
- package/dist/charts/bklit/bar-squares.js +206 -0
- package/dist/charts/bklit/bar-x-axis.d.ts +13 -0
- package/dist/charts/bklit/bar-x-axis.js +81 -0
- package/dist/charts/bklit/bar-y-axis.d.ts +11 -0
- package/dist/charts/bklit/bar-y-axis.js +72 -0
- package/dist/charts/bklit/bar.d.ts +40 -0
- package/dist/charts/bklit/bar.js +207 -0
- package/dist/charts/bklit/chart-child-passthrough.d.ts +25 -0
- package/dist/charts/bklit/chart-child-passthrough.js +82 -0
- package/dist/charts/bklit/chart-config-context.d.ts +34 -0
- package/dist/charts/bklit/chart-config-context.js +55 -0
- package/dist/charts/bklit/chart-context.d.ts +207 -0
- package/dist/charts/bklit/chart-context.js +200 -0
- package/dist/charts/bklit/chart-defs.d.ts +21 -0
- package/dist/charts/bklit/chart-defs.js +57 -0
- package/dist/charts/bklit/chart-formatters.d.ts +16 -0
- package/dist/charts/bklit/chart-formatters.js +26 -0
- package/dist/charts/bklit/chart-legend-hover.d.ts +21 -0
- package/dist/charts/bklit/chart-legend-hover.js +26 -0
- package/dist/charts/bklit/chart-loading-label.d.ts +9 -0
- package/dist/charts/bklit/chart-loading-label.js +29 -0
- package/dist/charts/bklit/chart-phase.d.ts +39 -0
- package/dist/charts/bklit/chart-phase.js +20 -0
- package/dist/charts/bklit/chart-reveal-clip.d.ts +32 -0
- package/dist/charts/bklit/chart-reveal-clip.js +23 -0
- package/dist/charts/bklit/dash-tail-stroke.d.ts +17 -0
- package/dist/charts/bklit/dash-tail-stroke.js +21 -0
- package/dist/charts/bklit/decimate-time-series.d.ts +18 -0
- package/dist/charts/bklit/decimate-time-series.js +120 -0
- package/dist/charts/bklit/fade-edges.d.ts +42 -0
- package/dist/charts/bklit/fade-edges.js +34 -0
- package/dist/charts/bklit/filter-data-by-x-domain.d.ts +13 -0
- package/dist/charts/bklit/filter-data-by-x-domain.js +50 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.d.ts +24 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.js +33 -0
- package/dist/charts/bklit/grid.d.ts +57 -0
- package/dist/charts/bklit/grid.js +88 -0
- package/dist/charts/bklit/highlight-segment-bounds.d.ts +26 -0
- package/dist/charts/bklit/highlight-segment-bounds.js +35 -0
- package/dist/charts/bklit/highlight-segment.d.ts +30 -0
- package/dist/charts/bklit/highlight-segment.js +22 -0
- package/dist/charts/bklit/indicator-fade.d.ts +23 -0
- package/dist/charts/bklit/indicator-fade.js +41 -0
- package/dist/charts/bklit/line-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/line-chart-loading.js +30 -0
- package/dist/charts/bklit/line-chart.d.ts +45 -0
- package/dist/charts/bklit/line-chart.js +99 -0
- package/dist/charts/bklit/line-loading-pulse.d.ts +19 -0
- package/dist/charts/bklit/line-loading-pulse.js +132 -0
- package/dist/charts/bklit/line-loading-timing.d.ts +18 -0
- package/dist/charts/bklit/line-loading-timing.js +18 -0
- package/dist/charts/bklit/line-series-terminal-marker.d.ts +15 -0
- package/dist/charts/bklit/line-series-terminal-marker.js +54 -0
- package/dist/charts/bklit/line.d.ts +63 -0
- package/dist/charts/bklit/line.js +104 -0
- package/dist/charts/bklit/loading-sweep.d.ts +65 -0
- package/dist/charts/bklit/loading-sweep.js +182 -0
- package/dist/charts/bklit/motion-utils.d.ts +17 -0
- package/dist/charts/bklit/motion-utils.js +27 -0
- package/dist/charts/bklit/path-stroke-utils.d.ts +28 -0
- package/dist/charts/bklit/path-stroke-utils.js +64 -0
- package/dist/charts/bklit/pattern-area.d.ts +20 -0
- package/dist/charts/bklit/pattern-area.js +27 -0
- package/dist/charts/bklit/pattern-preset.d.ts +34 -0
- package/dist/charts/bklit/pattern-preset.js +82 -0
- package/dist/charts/bklit/projection-config.d.ts +19 -0
- package/dist/charts/bklit/projection-config.js +88 -0
- package/dist/charts/bklit/projection-line-end-marker.d.ts +14 -0
- package/dist/charts/bklit/projection-line-end-marker.js +35 -0
- package/dist/charts/bklit/projection-line.d.ts +39 -0
- package/dist/charts/bklit/projection-line.js +87 -0
- package/dist/charts/bklit/projection-utils.d.ts +54 -0
- package/dist/charts/bklit/projection-utils.js +252 -0
- package/dist/charts/bklit/reference-area-config.d.ts +18 -0
- package/dist/charts/bklit/reference-area-config.js +47 -0
- package/dist/charts/bklit/reference-area-registration-context.d.ts +7 -0
- package/dist/charts/bklit/reference-area-registration-context.js +15 -0
- package/dist/charts/bklit/series-bar-layout.d.ts +26 -0
- package/dist/charts/bklit/series-bar-layout.js +39 -0
- package/dist/charts/bklit/series-dash-tail-overlay.d.ts +16 -0
- package/dist/charts/bklit/series-dash-tail-overlay.js +47 -0
- package/dist/charts/bklit/series-highlight-layer.d.ts +31 -0
- package/dist/charts/bklit/series-highlight-layer.js +20 -0
- package/dist/charts/bklit/series-hover-dim.d.ts +28 -0
- package/dist/charts/bklit/series-hover-dim.js +34 -0
- package/dist/charts/bklit/series-markers.d.ts +13 -0
- package/dist/charts/bklit/series-markers.js +106 -0
- package/dist/charts/bklit/series-path-utils.d.ts +18 -0
- package/dist/charts/bklit/series-path-utils.js +68 -0
- package/dist/charts/bklit/series-point-marker.d.ts +47 -0
- package/dist/charts/bklit/series-point-marker.js +47 -0
- package/dist/charts/bklit/static-chart-preview-context.d.ts +15 -0
- package/dist/charts/bklit/static-chart-preview-context.js +20 -0
- package/dist/charts/bklit/time-series-chart-shell.d.ts +46 -0
- package/dist/charts/bklit/time-series-chart-shell.js +398 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.d.ts +75 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.js +158 -0
- package/dist/charts/bklit/tooltip/date-ticker.d.ts +10 -0
- package/dist/charts/bklit/tooltip/date-ticker.js +85 -0
- package/dist/charts/bklit/tooltip/index.d.ts +15 -0
- package/dist/charts/bklit/tooltip/index.js +15 -0
- package/dist/charts/bklit/tooltip/tooltip-box.d.ts +56 -0
- package/dist/charts/bklit/tooltip/tooltip-box.js +122 -0
- package/dist/charts/bklit/tooltip/tooltip-content.d.ts +26 -0
- package/dist/charts/bklit/tooltip/tooltip-content.js +8 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.d.ts +27 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.js +62 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.d.ts +44 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.js +73 -0
- package/dist/charts/bklit/use-animated-series-path.d.ts +18 -0
- package/dist/charts/bklit/use-animated-series-path.js +101 -0
- package/dist/charts/bklit/use-animated-y-domains.d.ts +13 -0
- package/dist/charts/bklit/use-animated-y-domains.js +158 -0
- package/dist/charts/bklit/use-chart-interaction.d.ts +40 -0
- package/dist/charts/bklit/use-chart-interaction.js +252 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.d.ts +22 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.js +147 -0
- package/dist/charts/bklit/use-enter-complete.d.ts +16 -0
- package/dist/charts/bklit/use-enter-complete.js +22 -0
- package/dist/charts/bklit/use-grid-shimmer.d.ts +15 -0
- package/dist/charts/bklit/use-grid-shimmer.js +71 -0
- package/dist/charts/bklit/use-highlight-segment.d.ts +22 -0
- package/dist/charts/bklit/use-highlight-segment.js +42 -0
- package/dist/charts/bklit/use-mount-progress.d.ts +12 -0
- package/dist/charts/bklit/use-mount-progress.js +30 -0
- package/dist/charts/bklit/use-scheduled-tooltip.d.ts +8 -0
- package/dist/charts/bklit/use-scheduled-tooltip.js +84 -0
- package/dist/charts/bklit/visx-pattern.d.ts +27 -0
- package/dist/charts/bklit/visx-pattern.js +28 -0
- package/dist/charts/bklit/x-axis.d.ts +26 -0
- package/dist/charts/bklit/x-axis.js +423 -0
- package/dist/charts/bklit/y-axis-scales.d.ts +34 -0
- package/dist/charts/bklit/y-axis-scales.js +80 -0
- package/dist/charts/bklit/y-axis-ticks.d.ts +20 -0
- package/dist/charts/bklit/y-axis-ticks.js +32 -0
- package/dist/charts/bklit/y-domain-utils.d.ts +26 -0
- package/dist/charts/bklit/y-domain-utils.js +96 -0
- package/dist/charts/bklit.d.ts +2 -0
- package/dist/charts/bklit.js +90 -0
- package/dist/charts/components/shimmering-text.d.ts +31 -0
- package/dist/charts/components/shimmering-text.js +39 -0
- package/dist/charts/css.d.ts +35 -0
- package/dist/charts/css.js +64 -0
- package/dist/charts/recharts.d.ts +28 -0
- package/dist/charts/recharts.js +48 -0
- package/dist/charts/registry.d.ts +34 -0
- package/dist/charts/registry.js +60 -0
- package/dist/charts/skeleton.d.ts +55 -0
- package/dist/charts/skeleton.js +66 -0
- package/dist/cn.d.ts +10 -0
- package/dist/cn.js +13 -0
- package/dist/context.d.ts +346 -0
- package/dist/context.js +95 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +65 -0
- package/dist/routes.d.ts +70 -0
- package/dist/routes.js +73 -0
- package/dist/source-fields.d.ts +111 -0
- package/dist/source-fields.js +204 -0
- package/dist/ui/chart.d.ts +54 -0
- package/dist/ui/chart.js +122 -0
- package/dist/ui/dialog.d.ts +27 -0
- package/dist/ui/dialog.js +24 -0
- package/dist/ui/field.d.ts +29 -0
- package/dist/ui/field.js +31 -0
- package/dist/ui/select.d.ts +42 -0
- package/dist/ui/select.js +30 -0
- package/dist/ui/sheet.d.ts +38 -0
- package/dist/ui/sheet.js +37 -0
- package/dist/ui/switch.d.ts +17 -0
- package/dist/ui/switch.js +14 -0
- package/dist/ui/tabs.d.ts +30 -0
- package/dist/ui/tabs.js +36 -0
- package/dist/ui/tooltip.d.ts +37 -0
- package/dist/ui/tooltip.js +43 -0
- package/dist/workflow/graph.d.ts +112 -0
- package/dist/workflow/graph.js +297 -0
- package/dist/workflow/index.d.ts +16 -0
- package/dist/workflow/index.js +16 -0
- package/dist/workflow/model.d.ts +151 -0
- package/dist/workflow/model.js +97 -0
- package/dist/workflow/name.d.ts +28 -0
- package/dist/workflow/name.js +28 -0
- package/dist/workflow/nodes.d.ts +40 -0
- package/dist/workflow/nodes.js +86 -0
- package/dist/workflow/validate.d.ts +104 -0
- package/dist/workflow/validate.js +199 -0
- package/package.json +148 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from bklit-ui — https://github.com/bklit/bklit-ui
|
|
3
|
+
* Copyright (c) 2026 uixmat. Released under the MIT licence; the full text is in
|
|
4
|
+
* LICENSE-bklit at the root of this package.
|
|
5
|
+
*
|
|
6
|
+
* Local change: the `@/lib/utils` import was repointed at this package's own
|
|
7
|
+
* `cn`, which is the same function. Nothing else is modified, so re-syncing
|
|
8
|
+
* with upstream stays a diff rather than a merge.
|
|
9
|
+
*/
|
|
10
|
+
import { scaleLinear } from '@visx/scale';
|
|
11
|
+
import { Y_DOMAIN_TWEEN_SKIP_THRESHOLD } from './chart-phase';
|
|
12
|
+
import { groupLinesByYAxisId, normalizeYAxisId } from './y-axis-scales';
|
|
13
|
+
/** Apply visx `nice()` to raw domain endpoints for stable grid ticks. */
|
|
14
|
+
export function niceYDomain(domain) {
|
|
15
|
+
const scale = scaleLinear({ domain, range: [0, 1], nice: true });
|
|
16
|
+
const niceDomain = scale.domain();
|
|
17
|
+
return [niceDomain[0] ?? domain[0], niceDomain[1] ?? domain[1]];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Skip Y tween when both endpoints move less than the threshold relative to span.
|
|
21
|
+
* When in doubt callers should tween — beauty wins over micro-optimization.
|
|
22
|
+
*/
|
|
23
|
+
export function shouldTweenYDomain(from, to) {
|
|
24
|
+
const span = Math.max(Math.abs(to[1] - to[0]), Math.abs(from[1] - from[0]), 1);
|
|
25
|
+
const deltaMin = Math.abs(to[0] - from[0]) / span;
|
|
26
|
+
const deltaMax = Math.abs(to[1] - from[1]) / span;
|
|
27
|
+
return deltaMin >= Y_DOMAIN_TWEEN_SKIP_THRESHOLD || deltaMax >= Y_DOMAIN_TWEEN_SKIP_THRESHOLD;
|
|
28
|
+
}
|
|
29
|
+
/** Phases where the chart shows loading chrome (shimmer, pulse, label). */
|
|
30
|
+
export function isLoadingChromePhase(phase) {
|
|
31
|
+
return phase === 'loading' || phase === 'revealingLoading';
|
|
32
|
+
}
|
|
33
|
+
/** Phases where grid lines use loading stroke styling (muted / dashed chrome). */
|
|
34
|
+
export function isLoadingGridChromePhase(phase) {
|
|
35
|
+
return phase === 'loading' || phase === 'exiting' || phase === 'gridTweenLoading';
|
|
36
|
+
}
|
|
37
|
+
/** Phases where Y-domain tween runs after the series has exited. */
|
|
38
|
+
export function isYDomainTweenPhase(phase) {
|
|
39
|
+
return phase === 'gridTweenLoading' || phase === 'gridTweenReady';
|
|
40
|
+
}
|
|
41
|
+
/** Phases where {@link ReferenceArea} bands are shown (fade in/out on transitions). */
|
|
42
|
+
export function isReferenceAreaVisiblePhase(phase) {
|
|
43
|
+
return phase === 'ready' || phase === 'revealing' || phase === 'gridTweenReady';
|
|
44
|
+
}
|
|
45
|
+
export function resolveAnimatedYDestinationDomains(chartPhase, skeletonByAxis, targetByAxis) {
|
|
46
|
+
switch (chartPhase) {
|
|
47
|
+
case 'loading':
|
|
48
|
+
case 'exiting':
|
|
49
|
+
case 'gridTweenLoading':
|
|
50
|
+
return skeletonByAxis;
|
|
51
|
+
case 'exitingReady':
|
|
52
|
+
case 'gridTweenReady':
|
|
53
|
+
case 'revealing':
|
|
54
|
+
case 'ready':
|
|
55
|
+
return targetByAxis;
|
|
56
|
+
default:
|
|
57
|
+
return targetByAxis;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function computeYDomainsByAxis({ lines, resolveDomain, }) {
|
|
61
|
+
const groups = groupLinesByYAxisId(lines);
|
|
62
|
+
const domains = {};
|
|
63
|
+
for (const [axisId, axisLines] of groups) {
|
|
64
|
+
const dataKeys = axisLines.map((line) => line.dataKey);
|
|
65
|
+
domains[normalizeYAxisId(axisId)] = niceYDomain(resolveDomain(dataKeys));
|
|
66
|
+
}
|
|
67
|
+
if (!domains.left) {
|
|
68
|
+
domains.left = niceYDomain([0, 100]);
|
|
69
|
+
}
|
|
70
|
+
return domains;
|
|
71
|
+
}
|
|
72
|
+
/** Merge domain maps, normalizing axis ids to strings. */
|
|
73
|
+
export function mergeYDomainRecords(...records) {
|
|
74
|
+
const merged = {};
|
|
75
|
+
for (const record of records) {
|
|
76
|
+
for (const [axisId, domain] of Object.entries(record)) {
|
|
77
|
+
merged[normalizeYAxisId(axisId)] = domain;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return merged;
|
|
81
|
+
}
|
|
82
|
+
export function domainsEqual(left, right) {
|
|
83
|
+
const leftKeys = Object.keys(left);
|
|
84
|
+
const rightKeys = Object.keys(right);
|
|
85
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
for (const axisId of leftKeys) {
|
|
89
|
+
const from = left[axisId];
|
|
90
|
+
const to = right[axisId];
|
|
91
|
+
if (!(from && to) || from[0] !== to[0] || from[1] !== to[1]) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Area } from './bklit/area';
|
|
4
|
+
import { AreaChart } from './bklit/area-chart';
|
|
5
|
+
import { Bar } from './bklit/bar';
|
|
6
|
+
import { BarChart } from './bklit/bar-chart';
|
|
7
|
+
import { Grid } from './bklit/grid';
|
|
8
|
+
import { Line } from './bklit/line';
|
|
9
|
+
import { LineChart } from './bklit/line-chart';
|
|
10
|
+
import { ChartTooltip } from './bklit/tooltip';
|
|
11
|
+
import { XAxis } from './bklit/x-axis';
|
|
12
|
+
import { CssBarChart, looksLikeTimeSeries } from './css';
|
|
13
|
+
import { CHART_COLORS, seriesFrom } from './registry';
|
|
14
|
+
/**
|
|
15
|
+
* The bklit-ui renderer.
|
|
16
|
+
*
|
|
17
|
+
* bklit-ui (https://github.com/bklit/bklit-ui, MIT, Copyright (c) 2026 uixmat)
|
|
18
|
+
* is vendored under `./bklit` rather than depended on, because it is a shadcn
|
|
19
|
+
* registry — components you own, not a package you install. The full licence is
|
|
20
|
+
* in LICENSE-bklit at the root of this package.
|
|
21
|
+
*
|
|
22
|
+
* Registered like any other library, so a host that never selects it pays for
|
|
23
|
+
* none of the visx, d3 or motion peers it needs:
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { registerChartRenderer } from "@dudousxd/nestjs-catalog-react";
|
|
27
|
+
* import { BklitRenderer } from "@dudousxd/nestjs-catalog-react/bklit";
|
|
28
|
+
*
|
|
29
|
+
* registerChartRenderer("bklit", BklitRenderer);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/** How many series a card can carry before the colours stop being telling apart. */
|
|
33
|
+
const MAX_SERIES = 5;
|
|
34
|
+
export function BklitRenderer({ result, visualization, height = 220 }) {
|
|
35
|
+
const { labelColumn, valueColumns } = seriesFrom(result, visualization);
|
|
36
|
+
const series = valueColumns.slice(0, MAX_SERIES);
|
|
37
|
+
/**
|
|
38
|
+
* bklit's line and area charts are time-series charts: they build a
|
|
39
|
+
* `scaleTime` and coerce the x value with `new Date(...)`. A saved query's
|
|
40
|
+
* label column is arbitrary — it may be a month, or it may be a vehicle type
|
|
41
|
+
* — and nothing in `QueryVisualization` distinguishes them.
|
|
42
|
+
*
|
|
43
|
+
* This is the failure worth spelling out, because it is silent rather than
|
|
44
|
+
* loud: `new Date("Cargo truck")` is `Invalid Date`, the axis extent becomes
|
|
45
|
+
* `NaN`, and the card renders as an empty box with no error anywhere. So the
|
|
46
|
+
* data is checked before a time scale is handed anything, and categorical
|
|
47
|
+
* data degrades to the built-in bars instead — a plainer chart, which is the
|
|
48
|
+
* documented behaviour, rather than a blank one.
|
|
49
|
+
*
|
|
50
|
+
* bklit's *bar* chart has no such constraint: it is banded and categorical,
|
|
51
|
+
* so it takes whatever the label column holds.
|
|
52
|
+
*/
|
|
53
|
+
const timeSeries = useMemo(() => looksLikeTimeSeries(result, labelColumn), [result, labelColumn]);
|
|
54
|
+
/**
|
|
55
|
+
* bklit reads its x value from a named key, so the label column is copied to
|
|
56
|
+
* the name it expects rather than the charts being told which column to read.
|
|
57
|
+
*
|
|
58
|
+
* Copied rather than renamed: the original column is left in place because
|
|
59
|
+
* the tooltip renders the row, and a row that lost the column somebody
|
|
60
|
+
* labelled the chart with is a tooltip missing its own heading.
|
|
61
|
+
*/
|
|
62
|
+
const data = useMemo(() => {
|
|
63
|
+
if (!timeSeries) {
|
|
64
|
+
return result.rows.map((row) => ({ ...row, name: row[labelColumn] }));
|
|
65
|
+
}
|
|
66
|
+
return result.rows.map((row) => {
|
|
67
|
+
const raw = row[labelColumn];
|
|
68
|
+
return {
|
|
69
|
+
...row,
|
|
70
|
+
date: raw instanceof Date ? raw : new Date(String(raw)),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}, [result.rows, labelColumn, timeSeries]);
|
|
74
|
+
// Nothing numeric to plot. Degrading rather than rendering empty axes, for
|
|
75
|
+
// the same reason as above: an empty chart looks like a chart that is still
|
|
76
|
+
// loading, and this one never will be.
|
|
77
|
+
if (series.length === 0) {
|
|
78
|
+
return _jsx(CssBarChart, { result: result, visualization: visualization, height: height });
|
|
79
|
+
}
|
|
80
|
+
if (visualization.kind === 'bar') {
|
|
81
|
+
return (_jsx("div", { style: { height }, children: _jsxs(BarChart, { data: data, xDataKey: "name", aspectRatio: "auto", className: "h-full", children: [_jsx(Grid, {}), _jsx(XAxis, {}), series.map((column, index) => (_jsx(Bar, { dataKey: column, fill: CHART_COLORS[index % CHART_COLORS.length] }, column))), _jsx(ChartTooltip, {})] }) }));
|
|
82
|
+
}
|
|
83
|
+
if (!timeSeries) {
|
|
84
|
+
return _jsx(CssBarChart, { result: result, visualization: visualization, height: height });
|
|
85
|
+
}
|
|
86
|
+
if (visualization.kind === 'area') {
|
|
87
|
+
return (_jsx("div", { style: { height }, children: _jsxs(AreaChart, { data: data, xDataKey: "date", aspectRatio: "auto", className: "h-full", children: [_jsx(Grid, {}), _jsx(XAxis, {}), series.map((column, index) => (_jsx(Area, { dataKey: column, fill: CHART_COLORS[index % CHART_COLORS.length], stroke: CHART_COLORS[index % CHART_COLORS.length] }, column))), _jsx(ChartTooltip, {})] }) }));
|
|
88
|
+
}
|
|
89
|
+
return (_jsx("div", { style: { height }, children: _jsxs(LineChart, { data: data, xDataKey: "date", aspectRatio: "auto", className: "h-full", children: [_jsx(Grid, {}), _jsx(XAxis, {}), series.map((column, index) => (_jsx(Line, { dataKey: column, stroke: CHART_COLORS[index % CHART_COLORS.length] }, column))), _jsx(ChartTooltip, {})] }) }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from bklit-ui — https://github.com/bklit/bklit-ui
|
|
3
|
+
* Copyright (c) 2026 uixmat. Released under the MIT licence; the full text is in
|
|
4
|
+
* LICENSE-bklit at the root of this package.
|
|
5
|
+
*
|
|
6
|
+
* Local change: the `@/lib/utils` import was repointed at this package's own
|
|
7
|
+
* `cn`, which is the same function. Nothing else is modified, so re-syncing
|
|
8
|
+
* with upstream stays a diff rather than a merge.
|
|
9
|
+
*/
|
|
10
|
+
import { motion } from 'motion/react';
|
|
11
|
+
import { type ComponentProps } from 'react';
|
|
12
|
+
export type ShimmeringTextProps = Omit<ComponentProps<typeof motion.span>, 'children'> & {
|
|
13
|
+
/** The text to render with the shimmering effect. */
|
|
14
|
+
text: string;
|
|
15
|
+
/**
|
|
16
|
+
* Duration in seconds for one shimmer cycle.
|
|
17
|
+
* @defaultValue 1
|
|
18
|
+
*/
|
|
19
|
+
duration?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Pause the shimmer (e.g. when the hero leaves the viewport).
|
|
22
|
+
* @defaultValue false
|
|
23
|
+
*/
|
|
24
|
+
paused?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Legacy alias for `paused`.
|
|
27
|
+
* @defaultValue false
|
|
28
|
+
*/
|
|
29
|
+
isStopped?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function ShimmeringText({ text, duration, isStopped, paused, className, ...props }: ShimmeringTextProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Vendored from bklit-ui — https://github.com/bklit/bklit-ui
|
|
5
|
+
* Copyright (c) 2026 uixmat. Released under the MIT licence; the full text is in
|
|
6
|
+
* LICENSE-bklit at the root of this package.
|
|
7
|
+
*
|
|
8
|
+
* Local change: the `@/lib/utils` import was repointed at this package's own
|
|
9
|
+
* `cn`, which is the same function. Nothing else is modified, so re-syncing
|
|
10
|
+
* with upstream stays a diff rather than a merge.
|
|
11
|
+
*/
|
|
12
|
+
import { motion, useReducedMotion } from 'motion/react';
|
|
13
|
+
import { useCallback } from 'react';
|
|
14
|
+
import { cn } from '../../cn';
|
|
15
|
+
export function ShimmeringText({ text, duration = 1, isStopped = false, paused = false, className, ...props }) {
|
|
16
|
+
const reducedMotion = useReducedMotion();
|
|
17
|
+
const stopped = isStopped || paused || reducedMotion === true;
|
|
18
|
+
const createCharVariants = useCallback((charIndex) => ({
|
|
19
|
+
running: {
|
|
20
|
+
color: ['var(--color)', 'var(--shimmering-color)', 'var(--color)'],
|
|
21
|
+
transition: {
|
|
22
|
+
duration,
|
|
23
|
+
repeat: Number.POSITIVE_INFINITY,
|
|
24
|
+
repeatType: 'loop',
|
|
25
|
+
repeatDelay: text.length * 0.05,
|
|
26
|
+
delay: (charIndex * duration) / text.length,
|
|
27
|
+
ease: 'easeInOut',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
stopped: {
|
|
31
|
+
color: 'var(--color)',
|
|
32
|
+
transition: {
|
|
33
|
+
duration: duration * 0.5,
|
|
34
|
+
ease: 'easeOut',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}), [duration, text.length]);
|
|
38
|
+
return (_jsxs(motion.span, { className: cn('inline-flex select-none items-center leading-none', '[--color:var(--muted-foreground)] [--shimmering-color:var(--foreground)]', className), ...props, children: [text.split('').map((char, index) => (_jsx(motion.span, { animate: stopped ? 'stopped' : 'running', "aria-hidden": true, className: "inline-block whitespace-pre leading-none", initial: "stopped", variants: createCharVariants(index), children: char }, index))), _jsx("span", { className: "sr-only", children: text })] }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CatalogQueryResult } from '@dudousxd/nestjs-catalog/client';
|
|
2
|
+
import { seriesFrom } from './registry';
|
|
3
|
+
import type { ChartRendererProps } from './registry';
|
|
4
|
+
/**
|
|
5
|
+
* A bar chart in CSS, not a charting library.
|
|
6
|
+
*
|
|
7
|
+
* Eight rows of one series is the shape a dashboard card actually holds, and a
|
|
8
|
+
* charting dependency would be larger than the whole package for it. When a
|
|
9
|
+
* card needs axes and tooltips, the honest answer is a real library — not a
|
|
10
|
+
* bigger version of this.
|
|
11
|
+
*
|
|
12
|
+
* Lifted out of `DashboardBoard` and given the `ChartRenderer` shape because it
|
|
13
|
+
* is not only the dashboard's fallback: it is *the* fallback, the thing every
|
|
14
|
+
* other renderer degrades to when it cannot draw what a saved query asked for.
|
|
15
|
+
* A registered library that hits data it does not support has to land somewhere,
|
|
16
|
+
* and before this it had nowhere to land but an error.
|
|
17
|
+
*/
|
|
18
|
+
export declare function CssBarChart({ result, visualization }: ChartRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a column holds something a time scale can actually place.
|
|
21
|
+
*
|
|
22
|
+
* This exists because a chart library that plots time and one that plots
|
|
23
|
+
* categories are not interchangeable, and the difference does not show up as an
|
|
24
|
+
* error — it shows up as `new Date("Cargo truck")` being `Invalid Date`, an
|
|
25
|
+
* axis whose extent is `NaN`, and a chart that renders as an empty box. A saved
|
|
26
|
+
* query's label column is arbitrary: it may be a month, or it may be a vehicle
|
|
27
|
+
* type, and nothing in the model distinguishes them.
|
|
28
|
+
*
|
|
29
|
+
* Deliberately strict. A bare number would parse as a millisecond timestamp, so
|
|
30
|
+
* "5 work orders" would silently become 1 January 1970, and a `snapshotId` of
|
|
31
|
+
* `20260301` would parse as a year. Strings only, and only ones that parse.
|
|
32
|
+
*/
|
|
33
|
+
export declare function looksLikeTimeSeries(result: CatalogQueryResult, labelColumn: string): boolean;
|
|
34
|
+
/** Re-exported so a renderer needs one import to read a result the shared way. */
|
|
35
|
+
export { seriesFrom };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { seriesFrom } from './registry';
|
|
3
|
+
/**
|
|
4
|
+
* A bar chart in CSS, not a charting library.
|
|
5
|
+
*
|
|
6
|
+
* Eight rows of one series is the shape a dashboard card actually holds, and a
|
|
7
|
+
* charting dependency would be larger than the whole package for it. When a
|
|
8
|
+
* card needs axes and tooltips, the honest answer is a real library — not a
|
|
9
|
+
* bigger version of this.
|
|
10
|
+
*
|
|
11
|
+
* Lifted out of `DashboardBoard` and given the `ChartRenderer` shape because it
|
|
12
|
+
* is not only the dashboard's fallback: it is *the* fallback, the thing every
|
|
13
|
+
* other renderer degrades to when it cannot draw what a saved query asked for.
|
|
14
|
+
* A registered library that hits data it does not support has to land somewhere,
|
|
15
|
+
* and before this it had nowhere to land but an error.
|
|
16
|
+
*/
|
|
17
|
+
export function CssBarChart({ result, visualization }) {
|
|
18
|
+
const label = visualization.labelColumn ?? result.columns[0];
|
|
19
|
+
const value = visualization.valueColumns?.[0] ??
|
|
20
|
+
result.columns.find((column) => column !== label && typeof result.rows[0]?.[column] === 'number') ??
|
|
21
|
+
result.columns[1];
|
|
22
|
+
const rows = result.rows.slice(0, 8);
|
|
23
|
+
const max = Math.max(...rows.map((row) => Number(row[value]) || 0).filter(Number.isFinite), 0);
|
|
24
|
+
return (_jsx("div", { className: "space-y-1.5", children: rows.map((row, index) => {
|
|
25
|
+
const raw = Number(row[value]) || 0;
|
|
26
|
+
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "w-24 shrink-0 truncate text-[11px]", children: String(row[label] ?? '—') }), _jsx("div", { className: "h-3 flex-1 overflow-hidden rounded-sm bg-zinc-100 dark:bg-zinc-800", children: _jsx("div", { className: "h-full rounded-sm bg-violet-500/80", style: { width: max > 0 ? `${(raw / max) * 100}%` : '0%' } }) }), _jsx("span", { className: "w-12 shrink-0 text-right font-mono text-[11px] tabular-nums", children: raw })] }, index));
|
|
27
|
+
}) }));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a column holds something a time scale can actually place.
|
|
31
|
+
*
|
|
32
|
+
* This exists because a chart library that plots time and one that plots
|
|
33
|
+
* categories are not interchangeable, and the difference does not show up as an
|
|
34
|
+
* error — it shows up as `new Date("Cargo truck")` being `Invalid Date`, an
|
|
35
|
+
* axis whose extent is `NaN`, and a chart that renders as an empty box. A saved
|
|
36
|
+
* query's label column is arbitrary: it may be a month, or it may be a vehicle
|
|
37
|
+
* type, and nothing in the model distinguishes them.
|
|
38
|
+
*
|
|
39
|
+
* Deliberately strict. A bare number would parse as a millisecond timestamp, so
|
|
40
|
+
* "5 work orders" would silently become 1 January 1970, and a `snapshotId` of
|
|
41
|
+
* `20260301` would parse as a year. Strings only, and only ones that parse.
|
|
42
|
+
*/
|
|
43
|
+
export function looksLikeTimeSeries(result, labelColumn) {
|
|
44
|
+
const sample = result.rows
|
|
45
|
+
.slice(0, 12)
|
|
46
|
+
.map((row) => row[labelColumn])
|
|
47
|
+
.filter((value) => value !== null && value !== undefined);
|
|
48
|
+
if (sample.length === 0)
|
|
49
|
+
return false;
|
|
50
|
+
return sample.every((value) => {
|
|
51
|
+
if (value instanceof Date)
|
|
52
|
+
return !Number.isNaN(value.getTime());
|
|
53
|
+
if (typeof value !== 'string')
|
|
54
|
+
return false;
|
|
55
|
+
// A plain integer string is a category far more often than it is a date,
|
|
56
|
+
// and `new Date("2026")` succeeds — which is exactly the silent misreading
|
|
57
|
+
// this guard is for.
|
|
58
|
+
if (/^\d+$/.test(value))
|
|
59
|
+
return false;
|
|
60
|
+
return !Number.isNaN(new Date(value).getTime());
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** Re-exported so a renderer needs one import to read a result the shared way. */
|
|
64
|
+
export { seriesFrom };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ChartRendererProps } from './registry';
|
|
2
|
+
/**
|
|
3
|
+
* The shadcn/ui chart renderer.
|
|
4
|
+
*
|
|
5
|
+
* Not "Recharts with our own styling" — the actual shadcn chart primitives,
|
|
6
|
+
* vendored in `../ui/chart`. A host already using shadcn gets charts that match
|
|
7
|
+
* the rest of their app because it is the same component they have.
|
|
8
|
+
*
|
|
9
|
+
* Series are coloured through `var(--color-<key>)`, which `ChartContainer`
|
|
10
|
+
* emits from the config. That is worth the indirection: a colour bound to a key
|
|
11
|
+
* survives a series being reordered or dropped, and an index into a palette
|
|
12
|
+
* array does not.
|
|
13
|
+
*
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { registerChartRenderer } from "@dudousxd/nestjs-catalog-react";
|
|
16
|
+
* import { ShadcnChartRenderer } from "@dudousxd/nestjs-catalog-react/recharts";
|
|
17
|
+
* registerChartRenderer("shadcn", ShadcnChartRenderer);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Every axis, grid and legend below is written out per chart rather than shared
|
|
21
|
+
* through a variable. Recharts finds them by walking its *direct* children, so
|
|
22
|
+
* a fragment becomes one child it does not recognise — the chart still draws
|
|
23
|
+
* its series and silently loses its axes, which reads as a styling problem and
|
|
24
|
+
* is not.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ShadcnChartRenderer({ result, visualization, height }: ChartRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
/** The name this shipped under before it used the shadcn primitives. */
|
|
28
|
+
export { ShadcnChartRenderer as RechartsRenderer };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Line, LineChart, XAxis, YAxis, } from 'recharts';
|
|
3
|
+
import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, } from '../ui/chart';
|
|
4
|
+
import { seriesFrom } from './registry';
|
|
5
|
+
/**
|
|
6
|
+
* The shadcn/ui chart renderer.
|
|
7
|
+
*
|
|
8
|
+
* Not "Recharts with our own styling" — the actual shadcn chart primitives,
|
|
9
|
+
* vendored in `../ui/chart`. A host already using shadcn gets charts that match
|
|
10
|
+
* the rest of their app because it is the same component they have.
|
|
11
|
+
*
|
|
12
|
+
* Series are coloured through `var(--color-<key>)`, which `ChartContainer`
|
|
13
|
+
* emits from the config. That is worth the indirection: a colour bound to a key
|
|
14
|
+
* survives a series being reordered or dropped, and an index into a palette
|
|
15
|
+
* array does not.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { registerChartRenderer } from "@dudousxd/nestjs-catalog-react";
|
|
19
|
+
* import { ShadcnChartRenderer } from "@dudousxd/nestjs-catalog-react/recharts";
|
|
20
|
+
* registerChartRenderer("shadcn", ShadcnChartRenderer);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Every axis, grid and legend below is written out per chart rather than shared
|
|
24
|
+
* through a variable. Recharts finds them by walking its *direct* children, so
|
|
25
|
+
* a fragment becomes one child it does not recognise — the chart still draws
|
|
26
|
+
* its series and silently loses its axes, which reads as a styling problem and
|
|
27
|
+
* is not.
|
|
28
|
+
*/
|
|
29
|
+
export function ShadcnChartRenderer({ result, visualization, height = 220 }) {
|
|
30
|
+
const { labelColumn, valueColumns, data } = seriesFrom(result, visualization);
|
|
31
|
+
// The five `--chart-*` variables shadcn's own charts use, so a host that
|
|
32
|
+
// themed them once gets these for free.
|
|
33
|
+
const config = Object.fromEntries(valueColumns.map((column, index) => [
|
|
34
|
+
column,
|
|
35
|
+
{ label: column, color: `var(--chart-${(index % 5) + 1})` },
|
|
36
|
+
]));
|
|
37
|
+
const axis = { tickLine: false, axisLine: false, tickMargin: 8 };
|
|
38
|
+
const style = { height };
|
|
39
|
+
if (visualization.kind === 'line') {
|
|
40
|
+
return (_jsx(ChartContainer, { config: config, className: "aspect-auto w-full", style: style, children: _jsxs(LineChart, { data: data, margin: { top: 4, right: 8 }, children: [_jsx(CartesianGrid, { vertical: false }), _jsx(XAxis, { dataKey: labelColumn, ...axis }), _jsx(YAxis, { width: 44, ...axis }), _jsx(ChartTooltip, { content: _jsx(ChartTooltipContent, {}) }), valueColumns.length > 1 && _jsx(ChartLegend, { content: _jsx(ChartLegendContent, {}) }), valueColumns.map((column) => (_jsx(Line, { type: "monotone", dataKey: column, stroke: `var(--color-${column})`, strokeWidth: 2, dot: false }, column)))] }) }));
|
|
41
|
+
}
|
|
42
|
+
if (visualization.kind === 'area') {
|
|
43
|
+
return (_jsx(ChartContainer, { config: config, className: "aspect-auto w-full", style: style, children: _jsxs(AreaChart, { data: data, margin: { top: 4, right: 8 }, children: [_jsx(CartesianGrid, { vertical: false }), _jsx(XAxis, { dataKey: labelColumn, ...axis }), _jsx(YAxis, { width: 44, ...axis }), _jsx(ChartTooltip, { content: _jsx(ChartTooltipContent, { indicator: "line" }) }), valueColumns.length > 1 && _jsx(ChartLegend, { content: _jsx(ChartLegendContent, {}) }), valueColumns.map((column) => (_jsx(Area, { type: "monotone", dataKey: column, stroke: `var(--color-${column})`, fill: `var(--color-${column})`, fillOpacity: 0.18, strokeWidth: 2 }, column)))] }) }));
|
|
44
|
+
}
|
|
45
|
+
return (_jsx(ChartContainer, { config: config, className: "aspect-auto w-full", style: style, children: _jsxs(BarChart, { data: data, margin: { top: 4, right: 8 }, children: [_jsx(CartesianGrid, { vertical: false }), _jsx(XAxis, { dataKey: labelColumn, ...axis }), _jsx(YAxis, { width: 44, ...axis }), _jsx(ChartTooltip, { content: _jsx(ChartTooltipContent, {}) }), valueColumns.length > 1 && _jsx(ChartLegend, { content: _jsx(ChartLegendContent, {}) }), valueColumns.map((column) => (_jsx(Bar, { dataKey: column, fill: `var(--color-${column})`, radius: [3, 3, 0, 0] }, column)))] }) }));
|
|
46
|
+
}
|
|
47
|
+
/** The name this shipped under before it used the shadcn primitives. */
|
|
48
|
+
export { ShadcnChartRenderer as RechartsRenderer };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CatalogQueryResult, QueryVisualization } from '@dudousxd/nestjs-catalog/client';
|
|
2
|
+
import type { ComponentType } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* What every chart renderer receives.
|
|
5
|
+
*
|
|
6
|
+
* The result and the visualization config, nothing else — a renderer that
|
|
7
|
+
* needed the catalog client could reach data the card's own query never
|
|
8
|
+
* returned, and a chart should never be able to widen its own access.
|
|
9
|
+
*/
|
|
10
|
+
export interface ChartRendererProps {
|
|
11
|
+
result: CatalogQueryResult;
|
|
12
|
+
visualization: QueryVisualization;
|
|
13
|
+
/** Rough pixel height the card has to spare. */
|
|
14
|
+
height?: number;
|
|
15
|
+
}
|
|
16
|
+
export type ChartRenderer = ComponentType<ChartRendererProps>;
|
|
17
|
+
export declare function registerChartRenderer(name: string, renderer: ChartRenderer): void;
|
|
18
|
+
export declare function getChartRenderer(name?: string): ChartRenderer | undefined;
|
|
19
|
+
/** Which libraries are available right now, for the picker in the console. */
|
|
20
|
+
export declare function registeredChartLibraries(): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Pull the label column and one numeric series out of a result.
|
|
23
|
+
*
|
|
24
|
+
* Shared by every renderer so they all read a saved query the same way — a
|
|
25
|
+
* chart that picks a different column than the one beside it is the kind of
|
|
26
|
+
* inconsistency nobody reports and everybody distrusts.
|
|
27
|
+
*/
|
|
28
|
+
export declare function seriesFrom(result: CatalogQueryResult, visualization: QueryVisualization): {
|
|
29
|
+
labelColumn: string;
|
|
30
|
+
valueColumns: string[];
|
|
31
|
+
data: Array<Record<string, unknown>>;
|
|
32
|
+
};
|
|
33
|
+
/** A palette that works in both themes, so a renderer need not invent one. */
|
|
34
|
+
export declare const CHART_COLORS: string[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart libraries, registered rather than imported.
|
|
3
|
+
*
|
|
4
|
+
* This package ships one renderer that needs no dependency at all, and takes
|
|
5
|
+
* none. Recharts (what shadcn/ui's charts are built on) and bklit-ui (which
|
|
6
|
+
* builds on visx, d3 and motion) are both perfectly good and both far larger
|
|
7
|
+
* than everything here put together — bundling either would make every consumer
|
|
8
|
+
* pay for a choice only some of them want.
|
|
9
|
+
*
|
|
10
|
+
* So a host installs the library it prefers and registers a renderer:
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { registerChartRenderer } from "@dudousxd/nestjs-catalog-react";
|
|
14
|
+
* import { ShadcnChartRenderer } from "@dudousxd/nestjs-catalog-react/recharts";
|
|
15
|
+
* import { BklitRenderer } from "@dudousxd/nestjs-catalog-react/bklit";
|
|
16
|
+
*
|
|
17
|
+
* registerChartRenderer("recharts", ShadcnChartRenderer);
|
|
18
|
+
* registerChartRenderer("bklit", BklitRenderer);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Saved queries then name a library in their visualization, and one that names
|
|
22
|
+
* a library nobody registered falls back to the built-in rather than failing —
|
|
23
|
+
* a dashboard should degrade to a plainer chart, not to an error. That matters
|
|
24
|
+
* more than it sounds: `library` is stored data, so a query saved when a
|
|
25
|
+
* renderer was registered outlives it, and a card naming a renderer that is no
|
|
26
|
+
* longer there must still draw something.
|
|
27
|
+
*/
|
|
28
|
+
const renderers = new Map();
|
|
29
|
+
export function registerChartRenderer(name, renderer) {
|
|
30
|
+
renderers.set(name, renderer);
|
|
31
|
+
}
|
|
32
|
+
export function getChartRenderer(name) {
|
|
33
|
+
if (!name)
|
|
34
|
+
return undefined;
|
|
35
|
+
return renderers.get(name);
|
|
36
|
+
}
|
|
37
|
+
/** Which libraries are available right now, for the picker in the console. */
|
|
38
|
+
export function registeredChartLibraries() {
|
|
39
|
+
return ['css', ...renderers.keys()];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pull the label column and one numeric series out of a result.
|
|
43
|
+
*
|
|
44
|
+
* Shared by every renderer so they all read a saved query the same way — a
|
|
45
|
+
* chart that picks a different column than the one beside it is the kind of
|
|
46
|
+
* inconsistency nobody reports and everybody distrusts.
|
|
47
|
+
*/
|
|
48
|
+
export function seriesFrom(result, visualization) {
|
|
49
|
+
const labelColumn = visualization.labelColumn ?? result.columns[0];
|
|
50
|
+
const declared = visualization.valueColumns?.filter((c) => result.columns.includes(c));
|
|
51
|
+
const numeric = result.columns.filter((column) => column !== labelColumn && result.rows.some((row) => typeof row[column] === 'number'));
|
|
52
|
+
const valueColumns = declared && declared.length > 0
|
|
53
|
+
? declared
|
|
54
|
+
: numeric.length > 0
|
|
55
|
+
? numeric.slice(0, 3)
|
|
56
|
+
: result.columns.slice(1, 2);
|
|
57
|
+
return { labelColumn, valueColumns, data: result.rows };
|
|
58
|
+
}
|
|
59
|
+
/** A palette that works in both themes, so a renderer need not invent one. */
|
|
60
|
+
export const CHART_COLORS = ['#8b5cf6', '#10b981', '#f59e0b', '#0ea5e9', '#f43f5e'];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { QueryVisualization } from '@dudousxd/nestjs-catalog/client';
|
|
2
|
+
/**
|
|
3
|
+
* The chart that is coming, drawn in grey.
|
|
4
|
+
*
|
|
5
|
+
* One skeleton shared by every renderer rather than one per renderer, and the
|
|
6
|
+
* reason is that a skeleton describes the *shape of the visualization*, not the
|
|
7
|
+
* library that will draw it: bars are bars whether Recharts or anything else
|
|
8
|
+
* ends up placing them. Per-renderer skeletons would drift — the day somebody
|
|
9
|
+
* tightens the spacing in one, the dashboard loads unevenly depending on which
|
|
10
|
+
* library each card happens to name, and nobody would ever look there for it.
|
|
11
|
+
*
|
|
12
|
+
* The one exception is a renderer that ships its own loading state as part of
|
|
13
|
+
* its own animation vocabulary; that renderer should use its own, because a
|
|
14
|
+
* generic pulse handing over to a bespoke sweep looks like two different things
|
|
15
|
+
* loading.
|
|
16
|
+
*
|
|
17
|
+
* Two rules this must not break:
|
|
18
|
+
*
|
|
19
|
+
* 1. It occupies exactly the space the real chart will. The renderers take a
|
|
20
|
+
* `height` and default to 220, so this takes the same one and defaults the
|
|
21
|
+
* same way. A skeleton of a different height is a layout shift the moment
|
|
22
|
+
* data lands, and on a dashboard of several cards that is the whole grid
|
|
23
|
+
* jumping under somebody's cursor.
|
|
24
|
+
* 2. It animates only for people who did not ask for less motion. The pulse is
|
|
25
|
+
* behind `motion-safe:`, which is a core Tailwind variant rather than a
|
|
26
|
+
* plugin — the placeholder stays, the movement goes.
|
|
27
|
+
*/
|
|
28
|
+
export interface ChartSkeletonProps {
|
|
29
|
+
kind: QueryVisualization['kind'];
|
|
30
|
+
/** Must match what the real renderer will be given. */
|
|
31
|
+
height?: number;
|
|
32
|
+
/** How many bars or points to suggest. Only affects the drawing. */
|
|
33
|
+
points?: number;
|
|
34
|
+
className?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function ChartSkeleton({ kind, height, points, className }: ChartSkeletonProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
/**
|
|
38
|
+
* What a card shows when the query finished and there was nothing to draw.
|
|
39
|
+
*
|
|
40
|
+
* Beside the skeleton, in the same file, because the bug this pair exists to
|
|
41
|
+
* prevent is the one where they are confused: a query that returned no rows is
|
|
42
|
+
* not loading, and leaving it under a placeholder means a chart that will never
|
|
43
|
+
* arrive looks like a chart that is about to. This project treats a failure
|
|
44
|
+
* that looks like something else as its worst class of bug.
|
|
45
|
+
*/
|
|
46
|
+
export declare function ChartEmpty({ height, message, }: {
|
|
47
|
+
height?: number;
|
|
48
|
+
message?: string;
|
|
49
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
/** And what it shows when the query failed, which is not the same thing at all. */
|
|
51
|
+
export declare function ChartFailed({ height, message, onRetry, }: {
|
|
52
|
+
height?: number;
|
|
53
|
+
message: string;
|
|
54
|
+
onRetry?: () => void;
|
|
55
|
+
}): import("react/jsx-runtime").JSX.Element;
|