@schemacast/react 0.0.0-stage → 0.5.1
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 +21 -0
- package/README.md +37 -2
- package/dist/auto-visual.d.ts +32 -0
- package/dist/auto-visual.js +27 -0
- package/dist/field-by-key.d.ts +3 -0
- package/dist/field-by-key.js +7 -0
- package/dist/format-field-value.d.ts +16 -0
- package/dist/format-field-value.js +84 -0
- package/dist/implemented-archetypes.d.ts +2 -0
- package/dist/implemented-archetypes.js +17 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +10 -0
- package/dist/use-selected-view-id.d.ts +6 -0
- package/dist/use-selected-view-id.js +17 -0
- package/dist/view-switcher.d.ts +26 -0
- package/dist/view-switcher.js +63 -0
- package/dist/views/archetype-view.d.ts +16 -0
- package/dist/views/archetype-view.js +71 -0
- package/dist/views/bar-chart-options.d.ts +22 -0
- package/dist/views/bar-chart-options.js +103 -0
- package/dist/views/bar-chart-view.d.ts +17 -0
- package/dist/views/bar-chart-view.js +25 -0
- package/dist/views/build-hierarchy-tree-data.d.ts +8 -0
- package/dist/views/build-hierarchy-tree-data.js +32 -0
- package/dist/views/build-node-graph-data.d.ts +20 -0
- package/dist/views/build-node-graph-data.js +44 -0
- package/dist/views/chart-series-data.d.ts +61 -0
- package/dist/views/chart-series-data.js +150 -0
- package/dist/views/chart-value-axes.d.ts +45 -0
- package/dist/views/chart-value-axes.js +214 -0
- package/dist/views/data-table-constants.d.ts +3 -0
- package/dist/views/data-table-constants.js +3 -0
- package/dist/views/data-table-rows.d.ts +8 -0
- package/dist/views/data-table-rows.js +50 -0
- package/dist/views/data-table-view.d.ts +16 -0
- package/dist/views/data-table-view.js +76 -0
- package/dist/views/detail-card-view.d.ts +16 -0
- package/dist/views/detail-card-view.js +59 -0
- package/dist/views/edge-weight-width.d.ts +23 -0
- package/dist/views/edge-weight-width.js +47 -0
- package/dist/views/hierarchy-tree-view.d.ts +16 -0
- package/dist/views/hierarchy-tree-view.js +58 -0
- package/dist/views/json-tree-view.d.ts +15 -0
- package/dist/views/json-tree-view.js +115 -0
- package/dist/views/kanban-view.d.ts +16 -0
- package/dist/views/kanban-view.js +41 -0
- package/dist/views/kpi-grid-view.d.ts +16 -0
- package/dist/views/kpi-grid-view.js +34 -0
- package/dist/views/line-chart-options.d.ts +16 -0
- package/dist/views/line-chart-options.js +98 -0
- package/dist/views/line-chart-view.d.ts +16 -0
- package/dist/views/line-chart-view.js +31 -0
- package/dist/views/node-graph-options.d.ts +26 -0
- package/dist/views/node-graph-options.js +111 -0
- package/dist/views/node-graph-view.d.ts +16 -0
- package/dist/views/node-graph-view.js +28 -0
- package/dist/views/pie-chart-view.d.ts +16 -0
- package/dist/views/pie-chart-view.js +56 -0
- package/dist/views/timeline-view.d.ts +16 -0
- package/dist/views/timeline-view.js +86 -0
- package/dist/views/use-echarts.d.ts +4 -0
- package/dist/views/use-echarts.js +233 -0
- package/dist/visual-spec-view.d.ts +28 -0
- package/dist/visual-spec-view.js +31 -0
- package/package.json +56 -3
- package/styles.css +688 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wael Zohny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@schemacast/react`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React renderer for schemacast `VisualSpec` output (`AutoVisual`, `VisualSpecView`).
|
|
4
|
+
|
|
5
|
+
**0.x — API may change.**
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @schemacast/react @schemacast/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Import styles when your bundler needs an explicit CSS entry:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import '@schemacast/react/styles.css';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { AutoVisual } from '@schemacast/react';
|
|
23
|
+
import '@schemacast/react/styles.css';
|
|
24
|
+
|
|
25
|
+
export function Dashboard({ metrics }: { metrics: unknown }) {
|
|
26
|
+
return <AutoVisual data={metrics} />;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or render an existing spec:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { cast } from '@schemacast/core';
|
|
34
|
+
import { VisualSpecView } from '@schemacast/react';
|
|
35
|
+
|
|
36
|
+
const spec = cast(data);
|
|
37
|
+
return <VisualSpecView spec={spec} />;
|
|
38
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for {@link AutoVisual}.
|
|
4
|
+
*/
|
|
5
|
+
export interface AutoVisualProps {
|
|
6
|
+
/** Raw JSON value, object, array, or JSON string passed to `cast()` */
|
|
7
|
+
data: unknown;
|
|
8
|
+
/** Optional natural-language intent forwarded as `CastOptions.intent` */
|
|
9
|
+
intent?: string;
|
|
10
|
+
/**
|
|
11
|
+
* When `true`, forwards `isStreaming` to `cast()` so incomplete streams
|
|
12
|
+
* avoid empty-state errors in the UI (see `docs/03-VISUAL-AST-SPEC.md` §4).
|
|
13
|
+
*/
|
|
14
|
+
isStreaming?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Runs `cast()` once on `data`, renders the primary view, and lists ranked fallbacks in an
|
|
18
|
+
* accessible view switcher when `VisualSpec.views` has more than one entry. Forwards `intent`
|
|
19
|
+
* and `isStreaming` to `cast()`; while streaming with empty row data, shows a preparing state
|
|
20
|
+
* instead of a "No data" empty view.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* import { AutoVisual } from '@schemacast/react';
|
|
25
|
+
*
|
|
26
|
+
* export function Dashboard({ metrics }: { metrics: unknown }) {
|
|
27
|
+
* return <AutoVisual data={metrics} intent="show trends over time" />;
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function AutoVisual({ data, intent, isStreaming }: AutoVisualProps): ReactElement;
|
|
32
|
+
//# sourceMappingURL=auto-visual.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cast } from '@schemacast/core';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { VisualSpecView } from './visual-spec-view.js';
|
|
5
|
+
/**
|
|
6
|
+
* Runs `cast()` once on `data`, renders the primary view, and lists ranked fallbacks in an
|
|
7
|
+
* accessible view switcher when `VisualSpec.views` has more than one entry. Forwards `intent`
|
|
8
|
+
* and `isStreaming` to `cast()`; while streaming with empty row data, shows a preparing state
|
|
9
|
+
* instead of a "No data" empty view.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { AutoVisual } from '@schemacast/react';
|
|
14
|
+
*
|
|
15
|
+
* export function Dashboard({ metrics }: { metrics: unknown }) {
|
|
16
|
+
* return <AutoVisual data={metrics} intent="show trends over time" />;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function AutoVisual({ data, intent, isStreaming }) {
|
|
21
|
+
const spec = useMemo(() => {
|
|
22
|
+
const options = intent !== undefined || isStreaming !== undefined ? { intent, isStreaming } : undefined;
|
|
23
|
+
return cast(data, options);
|
|
24
|
+
}, [data, intent, isStreaming]);
|
|
25
|
+
return _jsx(VisualSpecView, { spec: spec });
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=auto-visual.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type FieldDescriptor } from '@schemacast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a field's currency or percent unit may be shown. Units guessed only from the field
|
|
4
|
+
* name (`unitSource: 'name'`) stay hidden; hand-built specs without a source keep their unit.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* isUnitConfirmed({ ...field, unitSource: 'name' }); // false
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function isUnitConfirmed(field: FieldDescriptor | undefined): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Formats a cell using `FieldDescriptor` metadata from the VisualSpec.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatFieldValue(value: unknown, field: FieldDescriptor | undefined): string;
|
|
16
|
+
//# sourceMappingURL=format-field-value.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { parseNumericValue } from '@schemacast/core';
|
|
2
|
+
const HAS_CURRENCY_SYMBOL_REGEX = /(?:[$€£]|SAR|AED)/i;
|
|
3
|
+
function formatCurrency(value, currencyHint) {
|
|
4
|
+
if (typeof value === 'string' && HAS_CURRENCY_SYMBOL_REGEX.test(value)) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
const amount = parseNumericValue(value, 'currency');
|
|
8
|
+
if (amount === null) {
|
|
9
|
+
return String(value);
|
|
10
|
+
}
|
|
11
|
+
if (currencyHint === 'USD') {
|
|
12
|
+
return new Intl.NumberFormat('en-US', {
|
|
13
|
+
style: 'currency',
|
|
14
|
+
currency: 'USD',
|
|
15
|
+
maximumFractionDigits: 2,
|
|
16
|
+
}).format(amount);
|
|
17
|
+
}
|
|
18
|
+
return `${amount} ${currencyHint}`;
|
|
19
|
+
}
|
|
20
|
+
function formatPercent(value) {
|
|
21
|
+
if (typeof value === 'string' && value.trim().endsWith('%')) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
const amount = parseNumericValue(value, 'percentage');
|
|
25
|
+
if (amount === null) {
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
const normalized = amount <= 1 && amount >= 0 ? amount * 100 : amount;
|
|
29
|
+
return `${normalized.toFixed(1)}%`;
|
|
30
|
+
}
|
|
31
|
+
function formatIsoDate(value) {
|
|
32
|
+
if (typeof value !== 'string') {
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
const parsed = Date.parse(value);
|
|
36
|
+
if (!Number.isFinite(parsed)) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
return new Intl.DateTimeFormat('en-US', {
|
|
40
|
+
dateStyle: 'medium',
|
|
41
|
+
timeStyle: 'short',
|
|
42
|
+
}).format(new Date(parsed));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether a field's currency or percent unit may be shown. Units guessed only from the field
|
|
46
|
+
* name (`unitSource: 'name'`) stay hidden; hand-built specs without a source keep their unit.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* isUnitConfirmed({ ...field, unitSource: 'name' }); // false
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function isUnitConfirmed(field) {
|
|
54
|
+
return field?.unitSource !== 'name';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Formats a cell using `FieldDescriptor` metadata from the VisualSpec.
|
|
58
|
+
*/
|
|
59
|
+
export function formatFieldValue(value, field) {
|
|
60
|
+
if (value === null || value === undefined) {
|
|
61
|
+
return '—';
|
|
62
|
+
}
|
|
63
|
+
if (field === undefined) {
|
|
64
|
+
return formatScalar(value);
|
|
65
|
+
}
|
|
66
|
+
const isPercent = field.formatHint === 'percent' || field.semanticType === 'percentage';
|
|
67
|
+
if (isPercent && isUnitConfirmed(field)) {
|
|
68
|
+
return formatPercent(value);
|
|
69
|
+
}
|
|
70
|
+
if (field.formatHint === 'iso-date' || field.semanticType === 'timestamp') {
|
|
71
|
+
return formatIsoDate(value);
|
|
72
|
+
}
|
|
73
|
+
if (field.semanticType === 'currency' && isUnitConfirmed(field)) {
|
|
74
|
+
return formatCurrency(value, field.formatHint ?? 'USD');
|
|
75
|
+
}
|
|
76
|
+
return formatScalar(value);
|
|
77
|
+
}
|
|
78
|
+
function formatScalar(value) {
|
|
79
|
+
if (typeof value === 'object') {
|
|
80
|
+
return JSON.stringify(value);
|
|
81
|
+
}
|
|
82
|
+
return String(value);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=format-field-value.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const IMPLEMENTED_ARCHETYPES = new Set([
|
|
2
|
+
'detail-card',
|
|
3
|
+
'kpi-grid',
|
|
4
|
+
'json-tree',
|
|
5
|
+
'kanban',
|
|
6
|
+
'timeline',
|
|
7
|
+
'data-table',
|
|
8
|
+
'line-chart',
|
|
9
|
+
'bar-chart',
|
|
10
|
+
'pie-chart',
|
|
11
|
+
'node-graph',
|
|
12
|
+
'hierarchy-tree',
|
|
13
|
+
]);
|
|
14
|
+
export function isImplementedArchetype(archetype) {
|
|
15
|
+
return IMPLEMENTED_ARCHETYPES.has(archetype);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=implemented-archetypes.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @schemacast/react
|
|
3
|
+
*
|
|
4
|
+
* React bindings for schemacast `VisualSpec` output.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { AutoVisual } from './auto-visual.js';
|
|
9
|
+
export type { AutoVisualProps } from './auto-visual.js';
|
|
10
|
+
export { VisualSpecView } from './visual-spec-view.js';
|
|
11
|
+
export type { VisualSpecViewProps } from './visual-spec-view.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @schemacast/react
|
|
3
|
+
*
|
|
4
|
+
* React bindings for schemacast `VisualSpec` output.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { AutoVisual } from './auto-visual.js';
|
|
9
|
+
export { VisualSpecView } from './visual-spec-view.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { VisualSpec } from '@schemacast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks the active view tab across `spec` updates without mutating the AST.
|
|
4
|
+
*/
|
|
5
|
+
export declare function useSelectedViewId(spec: VisualSpec): readonly [string, (viewId: string) => void];
|
|
6
|
+
//# sourceMappingURL=use-selected-view-id.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks the active view tab across `spec` updates without mutating the AST.
|
|
4
|
+
*/
|
|
5
|
+
export function useSelectedViewId(spec) {
|
|
6
|
+
const [selectedViewId, setSelectedViewId] = useState(spec.primaryView.id);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
setSelectedViewId((current) => {
|
|
9
|
+
if (spec.views.some((view) => view.id === current)) {
|
|
10
|
+
return current;
|
|
11
|
+
}
|
|
12
|
+
return spec.primaryView.id;
|
|
13
|
+
});
|
|
14
|
+
}, [spec]);
|
|
15
|
+
return [selectedViewId, setSelectedViewId];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=use-selected-view-id.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ViewCandidate } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface ViewSwitcherProps {
|
|
4
|
+
readonly views: readonly ViewCandidate[];
|
|
5
|
+
readonly selectedViewId: string;
|
|
6
|
+
readonly onSelectViewId: (viewId: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Accessible ranked view tabs per `docs/03-VISUAL-AST-SPEC.md` §4 (keyboard arrows, ARIA tabs).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <ViewSwitcher views={spec.views} selectedViewId={id} onSelectViewId={setId} />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function ViewSwitcher({ views, selectedViewId, onSelectViewId, }: ViewSwitcherProps): ReactElement;
|
|
17
|
+
/**
|
|
18
|
+
* Stable DOM id for a view tab panel linked from {@link ViewSwitcher}.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* viewTabPanelId('view-2'); // 'schemacast-panel-view-2'
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function viewTabPanelId(viewId: string): string;
|
|
26
|
+
//# sourceMappingURL=view-switcher.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
function panelId(viewId) {
|
|
4
|
+
return `schemacast-panel-${viewId}`;
|
|
5
|
+
}
|
|
6
|
+
function tabId(viewId) {
|
|
7
|
+
return `schemacast-tab-${viewId}`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Accessible ranked view tabs per `docs/03-VISUAL-AST-SPEC.md` §4 (keyboard arrows, ARIA tabs).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* <ViewSwitcher views={spec.views} selectedViewId={id} onSelectViewId={setId} />
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function ViewSwitcher({ views, selectedViewId, onSelectViewId, }) {
|
|
18
|
+
const handleKeyDown = useCallback((event) => {
|
|
19
|
+
const currentIndex = views.findIndex((view) => view.id === selectedViewId);
|
|
20
|
+
if (currentIndex < 0) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let nextIndex = currentIndex;
|
|
24
|
+
if (event.key === 'ArrowRight') {
|
|
25
|
+
nextIndex = (currentIndex + 1) % views.length;
|
|
26
|
+
}
|
|
27
|
+
else if (event.key === 'ArrowLeft') {
|
|
28
|
+
nextIndex = (currentIndex - 1 + views.length) % views.length;
|
|
29
|
+
}
|
|
30
|
+
else if (event.key === 'Home') {
|
|
31
|
+
nextIndex = 0;
|
|
32
|
+
}
|
|
33
|
+
else if (event.key === 'End') {
|
|
34
|
+
nextIndex = views.length - 1;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
const nextView = views[nextIndex];
|
|
41
|
+
if (nextView !== undefined) {
|
|
42
|
+
onSelectViewId(nextView.id);
|
|
43
|
+
}
|
|
44
|
+
}, [onSelectViewId, selectedViewId, views]);
|
|
45
|
+
return (_jsx("div", { role: "tablist", "aria-label": "Visual views", className: "schemacast-view-switcher", onKeyDown: handleKeyDown, "data-testid": "view-tablist", children: views.map((view) => {
|
|
46
|
+
const isSelected = view.id === selectedViewId;
|
|
47
|
+
return (_jsx("button", { type: "button", role: "tab", className: "schemacast-view-switcher-tab", id: tabId(view.id), "aria-selected": isSelected, "aria-controls": panelId(view.id), tabIndex: isSelected ? 0 : -1, onClick: () => {
|
|
48
|
+
onSelectViewId(view.id);
|
|
49
|
+
}, children: view.label }, view.id));
|
|
50
|
+
}) }));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Stable DOM id for a view tab panel linked from {@link ViewSwitcher}.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* viewTabPanelId('view-2'); // 'schemacast-panel-view-2'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function viewTabPanelId(viewId) {
|
|
61
|
+
return panelId(viewId);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=view-switcher.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ViewCandidate, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface ArchetypeViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly view: ViewCandidate;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Dispatches a ranked `ViewCandidate` to its archetype-specific React view (lazy charts/graphs).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <ArchetypeView spec={spec} view={spec.primaryView} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function ArchetypeView({ spec, view }: ArchetypeViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=archetype-view.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, lazy } from 'react';
|
|
3
|
+
import { DetailCardView } from './detail-card-view.js';
|
|
4
|
+
import { JsonTreeView } from './json-tree-view.js';
|
|
5
|
+
import { KanbanView } from './kanban-view.js';
|
|
6
|
+
import { KpiGridView } from './kpi-grid-view.js';
|
|
7
|
+
import { TimelineView } from './timeline-view.js';
|
|
8
|
+
const LazyDataTableView = lazy(async () => {
|
|
9
|
+
const module = await import('./data-table-view.js');
|
|
10
|
+
return { default: module.DataTableView };
|
|
11
|
+
});
|
|
12
|
+
const LazyLineChartView = lazy(async () => {
|
|
13
|
+
const module = await import('./line-chart-view.js');
|
|
14
|
+
return { default: module.LineChartView };
|
|
15
|
+
});
|
|
16
|
+
const LazyBarChartView = lazy(async () => {
|
|
17
|
+
const module = await import('./bar-chart-view.js');
|
|
18
|
+
return { default: module.BarChartView };
|
|
19
|
+
});
|
|
20
|
+
const LazyPieChartView = lazy(async () => {
|
|
21
|
+
const module = await import('./pie-chart-view.js');
|
|
22
|
+
return { default: module.PieChartView };
|
|
23
|
+
});
|
|
24
|
+
const LazyNodeGraphView = lazy(async () => {
|
|
25
|
+
const module = await import('./node-graph-view.js');
|
|
26
|
+
return { default: module.NodeGraphView };
|
|
27
|
+
});
|
|
28
|
+
const LazyHierarchyTreeView = lazy(async () => {
|
|
29
|
+
const module = await import('./hierarchy-tree-view.js');
|
|
30
|
+
return { default: module.HierarchyTreeView };
|
|
31
|
+
});
|
|
32
|
+
function ChartSuspense({ testId, children, }) {
|
|
33
|
+
return (_jsx(Suspense, { fallback: _jsx("p", { "data-testid": `${testId}-loading`, children: "Loading chart\u2026" }), children: children }));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Dispatches a ranked `ViewCandidate` to its archetype-specific React view (lazy charts/graphs).
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <ArchetypeView spec={spec} view={spec.primaryView} />
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function ArchetypeView({ spec, view }) {
|
|
44
|
+
switch (view.archetype) {
|
|
45
|
+
case 'detail-card':
|
|
46
|
+
return _jsx(DetailCardView, { spec: spec, bindings: view.bindings });
|
|
47
|
+
case 'kpi-grid':
|
|
48
|
+
return _jsx(KpiGridView, { spec: spec, bindings: view.bindings });
|
|
49
|
+
case 'json-tree':
|
|
50
|
+
return _jsx(JsonTreeView, { spec: spec });
|
|
51
|
+
case 'kanban':
|
|
52
|
+
return _jsx(KanbanView, { spec: spec, bindings: view.bindings });
|
|
53
|
+
case 'timeline':
|
|
54
|
+
return _jsx(TimelineView, { spec: spec, bindings: view.bindings });
|
|
55
|
+
case 'data-table':
|
|
56
|
+
return (_jsx(Suspense, { fallback: _jsx("p", { "data-testid": "data-table-loading", children: "Loading table\u2026" }), children: _jsx(LazyDataTableView, { spec: spec, bindings: view.bindings }) }));
|
|
57
|
+
case 'line-chart':
|
|
58
|
+
return (_jsx(ChartSuspense, { testId: "line-chart", children: _jsx(LazyLineChartView, { spec: spec, bindings: view.bindings }) }));
|
|
59
|
+
case 'bar-chart':
|
|
60
|
+
return (_jsx(ChartSuspense, { testId: "bar-chart", children: _jsx(LazyBarChartView, { spec: spec, bindings: view.bindings, data: view.data }) }));
|
|
61
|
+
case 'pie-chart':
|
|
62
|
+
return (_jsx(ChartSuspense, { testId: "pie-chart", children: _jsx(LazyPieChartView, { spec: spec, bindings: view.bindings }) }));
|
|
63
|
+
case 'node-graph':
|
|
64
|
+
return (_jsx(ChartSuspense, { testId: "node-graph", children: _jsx(LazyNodeGraphView, { spec: spec, bindings: view.bindings }) }));
|
|
65
|
+
case 'hierarchy-tree':
|
|
66
|
+
return (_jsx(ChartSuspense, { testId: "hierarchy-tree", children: _jsx(LazyHierarchyTreeView, { spec: spec, bindings: view.bindings }) }));
|
|
67
|
+
default:
|
|
68
|
+
return (_jsxs("p", { "data-testid": "view-placeholder", children: ["No renderer is available for archetype \u201C", view.archetype, "\u201D."] }));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=archetype-view.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { EChartsOption } from 'echarts';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the row array plotted by a `bar-chart` view, preferring view-scoped
|
|
5
|
+
* bucketed rows when available while keeping `spec.data` untouched.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const rows = resolveBarChartRows(spec, spec.primaryView.bindings, spec.primaryView.data);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveBarChartRows(spec: VisualSpec, bindings: FieldBindings, viewData?: readonly Record<string, unknown>[]): readonly Record<string, unknown>[];
|
|
13
|
+
/**
|
|
14
|
+
* Builds a bar-chart option from the bar view's rows (`view.data ?? spec.data`) and field bindings.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const option = buildBarChartOption(spec, spec.primaryView.bindings);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildBarChartOption(spec: VisualSpec, bindings: FieldBindings, viewData?: readonly Record<string, unknown>[]): EChartsOption | null;
|
|
22
|
+
//# sourceMappingURL=bar-chart-options.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { buildLongFormatLine } from '@schemacast/core';
|
|
2
|
+
import { buildCategoryAxis, buildSeriesLegend, numericSeries, seriesLabel, shouldOmitSingleSeriesYAxisName, } from './chart-series-data.js';
|
|
3
|
+
import { buildValueAxis, buildValueAxisPlan, formatChartTooltip } from './chart-value-axes.js';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the row array plotted by a `bar-chart` view, preferring view-scoped
|
|
6
|
+
* bucketed rows when available while keeping `spec.data` untouched.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const rows = resolveBarChartRows(spec, spec.primaryView.bindings, spec.primaryView.data);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function resolveBarChartRows(spec, bindings, viewData) {
|
|
14
|
+
if (viewData !== undefined) {
|
|
15
|
+
return viewData;
|
|
16
|
+
}
|
|
17
|
+
const matchingView = spec.views.find((view) => view.archetype === 'bar-chart' &&
|
|
18
|
+
view.data !== undefined &&
|
|
19
|
+
matchesBarBindings(view.bindings, bindings));
|
|
20
|
+
if (matchingView?.data !== undefined) {
|
|
21
|
+
return matchingView.data;
|
|
22
|
+
}
|
|
23
|
+
if (spec.primaryView.archetype === 'bar-chart' &&
|
|
24
|
+
spec.primaryView.data !== undefined &&
|
|
25
|
+
matchesBarBindings(spec.primaryView.bindings, bindings)) {
|
|
26
|
+
return spec.primaryView.data;
|
|
27
|
+
}
|
|
28
|
+
return spec.data;
|
|
29
|
+
}
|
|
30
|
+
function matchesBarBindings(viewBindings, bindings) {
|
|
31
|
+
return (viewBindings === bindings ||
|
|
32
|
+
(viewBindings.x === bindings.x && viewBindings.y?.[0] === bindings.y?.[0]));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds a bar-chart option from the bar view's rows (`view.data ?? spec.data`) and field bindings.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const option = buildBarChartOption(spec, spec.primaryView.bindings);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function buildBarChartOption(spec, bindings, viewData) {
|
|
43
|
+
const xKey = bindings.x;
|
|
44
|
+
const yKeys = bindings.y ?? [];
|
|
45
|
+
const firstYKey = yKeys[0];
|
|
46
|
+
if (xKey === undefined || firstYKey === undefined) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (bindings.groupBy !== undefined) {
|
|
50
|
+
return buildGroupedBarOption(spec, xKey, firstYKey, bindings.groupBy);
|
|
51
|
+
}
|
|
52
|
+
const rows = resolveBarChartRows(spec, bindings, viewData);
|
|
53
|
+
const seriesNames = yKeys.map((key) => seriesLabel(spec.fields, key));
|
|
54
|
+
const omitYAxisName = shouldOmitSingleSeriesYAxisName(seriesNames, undefined);
|
|
55
|
+
const axisPlan = buildValueAxisPlan(spec, yKeys, rows);
|
|
56
|
+
const axes = axisPlan.axes.map((axis) => buildValueAxis(spec.fields, axis, { omitName: omitYAxisName }));
|
|
57
|
+
return {
|
|
58
|
+
tooltip: {
|
|
59
|
+
trigger: 'axis',
|
|
60
|
+
formatter: (parameters) => formatChartTooltip(parameters, spec.fields, yKeys),
|
|
61
|
+
},
|
|
62
|
+
legend: buildSeriesLegend(seriesNames),
|
|
63
|
+
grid: {
|
|
64
|
+
left: axes.length > 1 ? 104 : 88,
|
|
65
|
+
right: axes.length > 1 ? 104 : 24,
|
|
66
|
+
containLabel: true,
|
|
67
|
+
},
|
|
68
|
+
xAxis: buildCategoryAxis(rows, xKey, spec.fields),
|
|
69
|
+
yAxis: axes.length === 1 ? axes[0] : axes,
|
|
70
|
+
series: yKeys.map((yKey, index) => ({
|
|
71
|
+
name: seriesLabel(spec.fields, yKey),
|
|
72
|
+
type: 'bar',
|
|
73
|
+
yAxisIndex: axisPlan.seriesAxisIndexes[index] ?? 0,
|
|
74
|
+
data: numericSeries(rows, yKey, spec.fields),
|
|
75
|
+
})),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* One bar series per group value over a shared category x axis (long-format rows).
|
|
80
|
+
*/
|
|
81
|
+
function buildGroupedBarOption(spec, xKey, yKey, groupKey) {
|
|
82
|
+
const line = buildLongFormatLine(spec.data, { xKey, groupKey, yKey }, spec.fields);
|
|
83
|
+
const seriesNames = line.series.map((series) => series.name);
|
|
84
|
+
const omitYAxisName = shouldOmitSingleSeriesYAxisName(seriesNames, undefined);
|
|
85
|
+
const axisPlan = buildValueAxisPlan(spec, [yKey], spec.data);
|
|
86
|
+
const axes = axisPlan.axes.map((axis) => buildValueAxis(spec.fields, axis, { omitName: omitYAxisName }));
|
|
87
|
+
return {
|
|
88
|
+
tooltip: {
|
|
89
|
+
trigger: 'axis',
|
|
90
|
+
formatter: (parameters) => formatChartTooltip(parameters, spec.fields, line.series.map(() => yKey)),
|
|
91
|
+
},
|
|
92
|
+
legend: buildSeriesLegend(seriesNames),
|
|
93
|
+
grid: { left: 88, right: 24, containLabel: true },
|
|
94
|
+
xAxis: buildCategoryAxis(line.xValues.map((value) => ({ [xKey]: value })), xKey, spec.fields),
|
|
95
|
+
yAxis: axes[0],
|
|
96
|
+
series: line.series.map((series) => ({
|
|
97
|
+
name: series.name,
|
|
98
|
+
type: 'bar',
|
|
99
|
+
data: series.values,
|
|
100
|
+
})),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=bar-chart-options.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface BarChartViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
readonly data?: readonly Record<string, unknown>[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* ECharts `bar-chart` for categorical breakdowns (lazy-loaded parent).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <BarChartView spec={spec} bindings={spec.primaryView.bindings} data={spec.primaryView.data} />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function BarChartView({ spec, bindings, data }: BarChartViewProps): ReactElement;
|
|
17
|
+
//# sourceMappingURL=bar-chart-view.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { buildBarChartOption, resolveBarChartRows } from './bar-chart-options.js';
|
|
4
|
+
import { useEcharts } from './use-echarts.js';
|
|
5
|
+
/**
|
|
6
|
+
* ECharts `bar-chart` for categorical breakdowns (lazy-loaded parent).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <BarChartView spec={spec} bindings={spec.primaryView.bindings} data={spec.primaryView.data} />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function BarChartView({ spec, bindings, data }) {
|
|
14
|
+
const rows = resolveBarChartRows(spec, bindings, data);
|
|
15
|
+
const option = useMemo(() => buildBarChartOption(spec, bindings, rows), [bindings, rows, spec]);
|
|
16
|
+
const chartRef = useEcharts(option, spec.isStreaming, true);
|
|
17
|
+
if (spec.isStreaming && rows.length === 0) {
|
|
18
|
+
return _jsx("p", { "data-testid": "bar-chart-streaming", children: "Preparing chart from stream\u2026" });
|
|
19
|
+
}
|
|
20
|
+
if (option === null) {
|
|
21
|
+
return _jsx("p", { "data-testid": "bar-chart-empty", children: "Chart bindings are incomplete." });
|
|
22
|
+
}
|
|
23
|
+
return _jsx("div", { "data-testid": "bar-chart-view", ref: chartRef, style: { width: '100%', height: 320 } });
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=bar-chart-view.js.map
|