@schemacast/react 0.0.0-stage → 0.5.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 +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 +99 -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 +31 -0
- package/dist/views/chart-series-data.js +85 -0
- package/dist/views/chart-value-axes.d.ts +41 -0
- package/dist/views/chart-value-axes.js +209 -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 +94 -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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { buildNodeGraphData } from './build-node-graph-data.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the force-directed graph option. Edges are drawn with a line width scaled by the
|
|
4
|
+
* `edgeWeight` binding (when there is one) and the weight shows in the edge tooltip. Edge labels
|
|
5
|
+
* are never drawn on the graph; they appear on hover only.
|
|
6
|
+
*
|
|
7
|
+
* @returns The option, or `null` when the graph has no nodes.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const option = buildNodeGraphOption(spec, spec.primaryView.bindings);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function buildNodeGraphOption(spec, bindings) {
|
|
15
|
+
const graphData = buildNodeGraphData(spec, bindings);
|
|
16
|
+
if (graphData.nodes.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const categories = [...new Set(graphData.nodes.flatMap((node) => node.category ?? []))];
|
|
20
|
+
const nodeNames = new Map(graphData.nodes.map((node) => [node.id, node.name]));
|
|
21
|
+
return {
|
|
22
|
+
...(categories.length > 0
|
|
23
|
+
? { legend: { data: categories, top: 0, textStyle: { fontSize: 11 } } }
|
|
24
|
+
: {}),
|
|
25
|
+
tooltip: {
|
|
26
|
+
trigger: 'item',
|
|
27
|
+
renderMode: 'richText',
|
|
28
|
+
formatter: (params) => formatGraphTooltip(params, nodeNames, bindings.edgeWeight),
|
|
29
|
+
},
|
|
30
|
+
series: [
|
|
31
|
+
{
|
|
32
|
+
type: 'graph',
|
|
33
|
+
layout: 'force',
|
|
34
|
+
roam: true,
|
|
35
|
+
draggable: true,
|
|
36
|
+
left: '10%',
|
|
37
|
+
right: '10%',
|
|
38
|
+
top: categories.length > 0 ? '16%' : '10%',
|
|
39
|
+
bottom: '10%',
|
|
40
|
+
symbolSize: 24,
|
|
41
|
+
label: { show: true, formatter: '{b}', position: 'right', distance: 8 },
|
|
42
|
+
labelLayout: { moveOverlap: 'shiftY', hideOverlap: true },
|
|
43
|
+
force: {
|
|
44
|
+
initLayout: 'circular',
|
|
45
|
+
repulsion: 900,
|
|
46
|
+
edgeLength: 160,
|
|
47
|
+
gravity: 0.08,
|
|
48
|
+
layoutAnimation: !spec.isStreaming,
|
|
49
|
+
},
|
|
50
|
+
edgeSymbol: ['none', 'arrow'],
|
|
51
|
+
edgeSymbolSize: [0, 10],
|
|
52
|
+
categories: categories.map((name) => ({ name })),
|
|
53
|
+
data: graphData.nodes.map((node) => ({
|
|
54
|
+
id: node.id,
|
|
55
|
+
name: node.name,
|
|
56
|
+
...(node.category === undefined ? {} : { category: node.category }),
|
|
57
|
+
})),
|
|
58
|
+
links: graphData.links.map((link) => ({
|
|
59
|
+
source: link.source,
|
|
60
|
+
target: link.target,
|
|
61
|
+
name: link.label ?? '',
|
|
62
|
+
...(link.weight === undefined ? {} : { value: link.weight }),
|
|
63
|
+
...(link.width === undefined ? {} : { lineStyle: { width: link.width } }),
|
|
64
|
+
})),
|
|
65
|
+
// Labels stay hidden until hover (see `emphasis`) so a busy graph stays readable.
|
|
66
|
+
edgeLabel: {
|
|
67
|
+
show: false,
|
|
68
|
+
formatter: '{b}',
|
|
69
|
+
position: 'end',
|
|
70
|
+
rotate: 0,
|
|
71
|
+
fontSize: 10,
|
|
72
|
+
},
|
|
73
|
+
emphasis: { edgeLabel: { show: true } },
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Formats the node or edge tooltip. An edge shows its label, its direction, and its weight
|
|
80
|
+
* (`weight: 12`) when the graph binds an edge weight.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* formatGraphTooltip(params, nodeNames, 'weight');
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export function formatGraphTooltip(params, nodeNames, weightKey) {
|
|
88
|
+
if (!isRecord(params) || !isRecord(params.data)) {
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
const data = params.data;
|
|
92
|
+
if (params.dataType === 'edge') {
|
|
93
|
+
const source = typeof data.source === 'string' ? data.source : '';
|
|
94
|
+
const target = typeof data.target === 'string' ? data.target : '';
|
|
95
|
+
const direction = `${nodeNames.get(source) ?? source} → ${nodeNames.get(target) ?? target}`;
|
|
96
|
+
const lines = [
|
|
97
|
+
...(typeof data.name === 'string' && data.name !== '' ? [data.name] : []),
|
|
98
|
+
direction,
|
|
99
|
+
...(weightKey !== undefined && typeof data.value === 'number'
|
|
100
|
+
? [`${weightKey}: ${data.value}`]
|
|
101
|
+
: []),
|
|
102
|
+
];
|
|
103
|
+
return lines.join('\n');
|
|
104
|
+
}
|
|
105
|
+
const name = typeof data.name === 'string' ? data.name : '';
|
|
106
|
+
return typeof data.category === 'string' ? `${name}\n${data.category}` : name;
|
|
107
|
+
}
|
|
108
|
+
function isRecord(value) {
|
|
109
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=node-graph-options.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface NodeGraphViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ECharts force-directed `node-graph` with human-readable node labels.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <NodeGraphView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function NodeGraphView({ spec, bindings }: NodeGraphViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=node-graph-view.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { buildNodeGraphData } from './build-node-graph-data.js';
|
|
4
|
+
import { buildNodeGraphOption } from './node-graph-options.js';
|
|
5
|
+
import { useEcharts } from './use-echarts.js';
|
|
6
|
+
/**
|
|
7
|
+
* ECharts force-directed `node-graph` with human-readable node labels.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <NodeGraphView spec={spec} bindings={spec.primaryView.bindings} />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function NodeGraphView({ spec, bindings }) {
|
|
15
|
+
const graphData = useMemo(() => buildNodeGraphData(spec, bindings), [bindings, spec]);
|
|
16
|
+
const option = useMemo(() => buildNodeGraphOption(spec, bindings), [bindings, spec]);
|
|
17
|
+
const chartRef = useEcharts(option, spec.isStreaming, true);
|
|
18
|
+
if (spec.isStreaming && spec.data.length === 0) {
|
|
19
|
+
return _jsx("p", { "data-testid": "node-graph-streaming", children: "Preparing graph from stream\u2026" });
|
|
20
|
+
}
|
|
21
|
+
if (option === null) {
|
|
22
|
+
return _jsx("p", { "data-testid": "node-graph-empty", children: "No nodes in view data." });
|
|
23
|
+
}
|
|
24
|
+
return (_jsxs("div", { "data-testid": "node-graph-view", children: [_jsx("ul", { "data-testid": "node-graph-node-labels", className: "sr-only", children: graphData.nodes.map((node) => (_jsx("li", { children: node.name }, node.id))) }), _jsx("ul", { "data-testid": "node-graph-edge-labels", className: "sr-only", children: graphData.links.map((link, index) => (_jsxs("li", { children: [link.label ?? `${link.source}→${link.target}`, link.weight === undefined
|
|
25
|
+
? ''
|
|
26
|
+
: ` (${bindings.edgeWeight ?? 'weight'}: ${link.weight})`] }, `${link.source}-${link.target}-${index}`))) }), _jsx("div", { role: "region", "aria-label": "Scrollable node graph", tabIndex: 0, style: { width: '100%', overflowX: 'auto' }, children: _jsx("div", { ref: chartRef, style: { width: '100%', minWidth: 760, height: 480 } }) })] }));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=node-graph-view.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface PieChartViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ECharts `pie-chart` for part-to-whole metrics (lazy-loaded parent).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <PieChartView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function PieChartView({ spec, bindings }: PieChartViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=pie-chart-view.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { fieldByKey } from '../field-by-key.js';
|
|
4
|
+
import { formatFieldValue } from '../format-field-value.js';
|
|
5
|
+
import { numericSeries, seriesLabel } from './chart-series-data.js';
|
|
6
|
+
import { useEcharts } from './use-echarts.js';
|
|
7
|
+
/**
|
|
8
|
+
* ECharts `pie-chart` for part-to-whole metrics (lazy-loaded parent).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <PieChartView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function PieChartView({ spec, bindings }) {
|
|
16
|
+
const categoryKey = bindings.x;
|
|
17
|
+
const valueKey = bindings.y?.[0];
|
|
18
|
+
const option = useMemo(() => {
|
|
19
|
+
if (categoryKey === undefined || valueKey === undefined) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const values = numericSeries(spec.data, valueKey, spec.fields);
|
|
23
|
+
const slices = spec.data.flatMap((row, index) => {
|
|
24
|
+
const value = values[index];
|
|
25
|
+
if (value === null || value === undefined) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
name: formatFieldValue(row[categoryKey], fieldByKey(spec.fields, categoryKey)),
|
|
31
|
+
value,
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
tooltip: { trigger: 'item' },
|
|
37
|
+
series: [
|
|
38
|
+
{
|
|
39
|
+
name: seriesLabel(spec.fields, valueKey),
|
|
40
|
+
type: 'pie',
|
|
41
|
+
radius: '65%',
|
|
42
|
+
data: slices,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}, [categoryKey, spec.data, spec.fields, valueKey]);
|
|
47
|
+
const chartRef = useEcharts(option, spec.isStreaming, true);
|
|
48
|
+
if (spec.isStreaming && spec.data.length === 0) {
|
|
49
|
+
return _jsx("p", { "data-testid": "pie-chart-streaming", children: "Preparing chart from stream\u2026" });
|
|
50
|
+
}
|
|
51
|
+
if (option === null) {
|
|
52
|
+
return _jsx("p", { "data-testid": "pie-chart-empty", children: "Chart bindings are incomplete." });
|
|
53
|
+
}
|
|
54
|
+
return _jsx("div", { "data-testid": "pie-chart-view", ref: chartRef, style: { width: '100%', height: 320 } });
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=pie-chart-view.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface TimelineViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders time-ranged events as an ordered `timeline` list.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <TimelineView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function TimelineView({ spec, bindings }: TimelineViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=timeline-view.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { fieldByKey } from '../field-by-key.js';
|
|
3
|
+
import { formatFieldValue } from '../format-field-value.js';
|
|
4
|
+
const DATE_ONLY_PATTERN = /^(\d{4}-\d{2}-\d{2})$/;
|
|
5
|
+
const ISO_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2}T/;
|
|
6
|
+
/**
|
|
7
|
+
* Renders time-ranged events as an ordered `timeline` list.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <TimelineView spec={spec} bindings={spec.primaryView.bindings} />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function TimelineView({ spec, bindings }) {
|
|
15
|
+
const startKey = bindings.startDate;
|
|
16
|
+
const endKey = bindings.endDate;
|
|
17
|
+
const titleKey = bindings.title ?? bindings.subtitle;
|
|
18
|
+
if (startKey === undefined || titleKey === undefined) {
|
|
19
|
+
return _jsx("p", { "data-testid": "timeline-view", children: "Missing timeline bindings." });
|
|
20
|
+
}
|
|
21
|
+
return (_jsx("ol", { className: "schemacast-timeline", "data-testid": "timeline-view", children: spec.data.map((row, index) => {
|
|
22
|
+
const title = String(row[titleKey] ?? '');
|
|
23
|
+
const start = formatTimelineDate(row[startKey], fieldByKey(spec.fields, startKey));
|
|
24
|
+
const endDate = endKey !== undefined
|
|
25
|
+
? formatTimelineDate(row[endKey], fieldByKey(spec.fields, endKey))
|
|
26
|
+
: undefined;
|
|
27
|
+
const dateRange = formatTimelineRange(start, endDate);
|
|
28
|
+
return (_jsxs("li", { className: "schemacast-timeline-item", "data-testid": "timeline-item", children: [_jsx("span", { className: "schemacast-timeline-marker", "aria-hidden": "true" }), _jsxs("div", { className: "schemacast-timeline-content", children: [_jsx("strong", { className: "schemacast-timeline-title", "data-testid": "timeline-title", children: title }), _jsx("span", { className: "schemacast-timeline-date", "data-testid": "timeline-date", children: dateRange })] })] }, `${title}-${index}`));
|
|
29
|
+
}) }));
|
|
30
|
+
}
|
|
31
|
+
function formatTimelineDate(value, field) {
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
const dateOnlyMatch = DATE_ONLY_PATTERN.exec(value);
|
|
34
|
+
if (dateOnlyMatch !== null) {
|
|
35
|
+
const parsedDate = new Date(`${value}T00:00:00.000Z`);
|
|
36
|
+
if (Number.isFinite(parsedDate.getTime()) && parsedDate.toISOString().startsWith(value)) {
|
|
37
|
+
const dateLabel = new Intl.DateTimeFormat('en-US', {
|
|
38
|
+
dateStyle: 'medium',
|
|
39
|
+
timeZone: 'UTC',
|
|
40
|
+
}).format(parsedDate);
|
|
41
|
+
return {
|
|
42
|
+
text: dateLabel,
|
|
43
|
+
dayKey: dateLabel,
|
|
44
|
+
dateLabel,
|
|
45
|
+
isDateOnly: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (ISO_DATETIME_PATTERN.test(value)) {
|
|
50
|
+
const parsedDate = new Date(value);
|
|
51
|
+
if (Number.isFinite(parsedDate.getTime())) {
|
|
52
|
+
const formattedDate = formatFieldValue(value, field);
|
|
53
|
+
const dateLabel = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' }).format(parsedDate);
|
|
54
|
+
const timeLabel = new Intl.DateTimeFormat('en-US', { timeStyle: 'short' }).format(parsedDate);
|
|
55
|
+
return {
|
|
56
|
+
text: formattedDate === value ? `${dateLabel}, ${timeLabel}` : formattedDate,
|
|
57
|
+
dayKey: dateLabel,
|
|
58
|
+
dateLabel,
|
|
59
|
+
timeLabel,
|
|
60
|
+
isDateOnly: false,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
text: formatFieldValue(value, field),
|
|
67
|
+
isDateOnly: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function formatTimelineRange(start, end) {
|
|
71
|
+
if (end === undefined || end.text.length === 0) {
|
|
72
|
+
return start.text;
|
|
73
|
+
}
|
|
74
|
+
if (start.dayKey !== undefined && start.dayKey === end.dayKey) {
|
|
75
|
+
if (start.isDateOnly && end.isDateOnly) {
|
|
76
|
+
return start.text;
|
|
77
|
+
}
|
|
78
|
+
const sharedDate = start.dateLabel ?? end.dateLabel;
|
|
79
|
+
const timeRange = [start.timeLabel, end.timeLabel].filter((timeLabel) => timeLabel !== undefined);
|
|
80
|
+
if (sharedDate !== undefined && timeRange.length > 0) {
|
|
81
|
+
return `${sharedDate}, ${timeRange.join(' – ')}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return `${start.text} – ${end.text}`;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=timeline-view.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EChartsOption } from 'echarts';
|
|
2
|
+
import { type RefObject } from 'react';
|
|
3
|
+
export declare function useEcharts(option: EChartsOption | null, isStreaming: boolean, useAutoVisualTheme?: boolean): RefObject<HTMLDivElement | null>;
|
|
4
|
+
//# sourceMappingURL=use-echarts.d.ts.map
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { BarChart, GraphChart, LineChart, PieChart, TreeChart } from 'echarts/charts';
|
|
2
|
+
import { GridComponent, LegendComponent, TooltipComponent } from 'echarts/components';
|
|
3
|
+
import { init, use } from 'echarts/core';
|
|
4
|
+
import { SVGRenderer } from 'echarts/renderers';
|
|
5
|
+
import { useEffect, useRef } from 'react';
|
|
6
|
+
const PIE_PALETTE_FALLBACK = [
|
|
7
|
+
'#2867b2',
|
|
8
|
+
'#c44e52',
|
|
9
|
+
'#55a868',
|
|
10
|
+
'#8172b3',
|
|
11
|
+
'#cc8c2f',
|
|
12
|
+
'#4c9f9a',
|
|
13
|
+
'#b55d9e',
|
|
14
|
+
'#7a7a4e',
|
|
15
|
+
];
|
|
16
|
+
use([
|
|
17
|
+
BarChart,
|
|
18
|
+
GraphChart,
|
|
19
|
+
LineChart,
|
|
20
|
+
PieChart,
|
|
21
|
+
TreeChart,
|
|
22
|
+
GridComponent,
|
|
23
|
+
LegendComponent,
|
|
24
|
+
TooltipComponent,
|
|
25
|
+
SVGRenderer,
|
|
26
|
+
]);
|
|
27
|
+
export function useEcharts(option, isStreaming, useAutoVisualTheme = false) {
|
|
28
|
+
const containerRef = useRef(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const element = containerRef.current;
|
|
31
|
+
if (element === null || option === null) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const instance = init(element, undefined, { renderer: 'svg' });
|
|
35
|
+
const updateOption = () => {
|
|
36
|
+
const themedOption = useAutoVisualTheme ? applyAutoVisualTheme(option, element) : option;
|
|
37
|
+
instance.setOption({ ...themedOption, animation: !isStreaming });
|
|
38
|
+
};
|
|
39
|
+
updateOption();
|
|
40
|
+
const resizeObserver = typeof ResizeObserver === 'undefined'
|
|
41
|
+
? null
|
|
42
|
+
: new ResizeObserver(() => {
|
|
43
|
+
instance.resize();
|
|
44
|
+
});
|
|
45
|
+
resizeObserver?.observe(element);
|
|
46
|
+
const documentView = element.ownerDocument.defaultView;
|
|
47
|
+
const colorScheme = useAutoVisualTheme && documentView !== null && typeof documentView.matchMedia === 'function'
|
|
48
|
+
? documentView.matchMedia('(prefers-color-scheme: dark)')
|
|
49
|
+
: null;
|
|
50
|
+
const themeObserver = useAutoVisualTheme && typeof MutationObserver !== 'undefined'
|
|
51
|
+
? new MutationObserver(updateOption)
|
|
52
|
+
: null;
|
|
53
|
+
themeObserver?.observe(element.ownerDocument.documentElement, {
|
|
54
|
+
attributes: true,
|
|
55
|
+
attributeFilter: ['data-theme'],
|
|
56
|
+
});
|
|
57
|
+
colorScheme?.addEventListener('change', updateOption);
|
|
58
|
+
return () => {
|
|
59
|
+
colorScheme?.removeEventListener('change', updateOption);
|
|
60
|
+
themeObserver?.disconnect();
|
|
61
|
+
resizeObserver?.disconnect();
|
|
62
|
+
instance.dispose();
|
|
63
|
+
};
|
|
64
|
+
}, [isStreaming, option, useAutoVisualTheme]);
|
|
65
|
+
return containerRef;
|
|
66
|
+
}
|
|
67
|
+
function applyAutoVisualTheme(option, element) {
|
|
68
|
+
const themeRoot = element.closest('.schemacast-auto-visual') ?? element;
|
|
69
|
+
const computedStyle = themeRoot.ownerDocument.defaultView?.getComputedStyle(themeRoot);
|
|
70
|
+
const getThemeColor = (token, fallback) => computedStyle?.getPropertyValue(token).trim() || fallback;
|
|
71
|
+
const foreground = getThemeColor('--schemacast-foreground', '#202a36');
|
|
72
|
+
const muted = getThemeColor('--schemacast-muted', '#637083');
|
|
73
|
+
const tooltip = Array.isArray(option.tooltip) ? option.tooltip[0] : option.tooltip;
|
|
74
|
+
const border = getThemeColor('--schemacast-border', '#d7dee8');
|
|
75
|
+
const categoricalPalette = PIE_PALETTE_FALLBACK.map((fallback, index) => getThemeColor(`--schemacast-pie-color-${index + 1}`, fallback));
|
|
76
|
+
const legend = Array.isArray(option.legend)
|
|
77
|
+
? option.legend.map((item) => ({
|
|
78
|
+
...item,
|
|
79
|
+
textStyle: { ...item.textStyle, color: foreground },
|
|
80
|
+
}))
|
|
81
|
+
: option.legend === undefined
|
|
82
|
+
? undefined
|
|
83
|
+
: { ...option.legend, textStyle: { ...option.legend.textStyle, color: foreground } };
|
|
84
|
+
return {
|
|
85
|
+
...option,
|
|
86
|
+
color: [getThemeColor('--schemacast-accent', '#2867b2'), muted],
|
|
87
|
+
legend,
|
|
88
|
+
xAxis: themeXAxisOptions(option.xAxis, foreground, border),
|
|
89
|
+
yAxis: themeYAxisOptions(option.yAxis, foreground, border),
|
|
90
|
+
series: themeSeriesLabels(option.series, foreground, muted, categoricalPalette),
|
|
91
|
+
textStyle: { ...option.textStyle, color: foreground },
|
|
92
|
+
tooltip: {
|
|
93
|
+
...tooltip,
|
|
94
|
+
backgroundColor: getThemeColor('--schemacast-background', '#ffffff'),
|
|
95
|
+
borderColor: border,
|
|
96
|
+
textStyle: { ...tooltip?.textStyle, color: foreground },
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function themeSeriesLabels(series, foreground, muted, categoricalPalette) {
|
|
101
|
+
if (!Array.isArray(series)) {
|
|
102
|
+
return series;
|
|
103
|
+
}
|
|
104
|
+
return series.map((seriesOption) => {
|
|
105
|
+
if (seriesOption.type === 'pie') {
|
|
106
|
+
return themePieSeries(seriesOption, foreground, categoricalPalette);
|
|
107
|
+
}
|
|
108
|
+
if (seriesOption.type === 'graph') {
|
|
109
|
+
return themeGraphSeries(seriesOption, foreground, muted, categoricalPalette);
|
|
110
|
+
}
|
|
111
|
+
if (seriesOption.type === 'tree') {
|
|
112
|
+
return themeTreeSeries(seriesOption, foreground);
|
|
113
|
+
}
|
|
114
|
+
return seriesOption;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function themeGraphSeries(series, foreground, muted, palette) {
|
|
118
|
+
return {
|
|
119
|
+
...series,
|
|
120
|
+
itemStyle: { ...series.itemStyle, color: palette[0] },
|
|
121
|
+
lineStyle: { ...series.lineStyle, color: muted },
|
|
122
|
+
categories: series.categories?.map((category, index) => ({
|
|
123
|
+
...category,
|
|
124
|
+
itemStyle: { ...category.itemStyle, color: palette[index % palette.length] },
|
|
125
|
+
})),
|
|
126
|
+
label: {
|
|
127
|
+
...series.label,
|
|
128
|
+
color: foreground,
|
|
129
|
+
textBorderColor: 'transparent',
|
|
130
|
+
textBorderWidth: 0,
|
|
131
|
+
},
|
|
132
|
+
edgeLabel: {
|
|
133
|
+
...series.edgeLabel,
|
|
134
|
+
color: foreground,
|
|
135
|
+
textBorderColor: 'transparent',
|
|
136
|
+
textBorderWidth: 0,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function themePieSeries(series, foreground, palette) {
|
|
141
|
+
const label = typeof series.label === 'object' && series.label !== null ? series.label : {};
|
|
142
|
+
const data = series.data?.map((item, index) => {
|
|
143
|
+
if (typeof item !== 'object' || item === null || Array.isArray(item)) {
|
|
144
|
+
return item;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
...item,
|
|
148
|
+
itemStyle: {
|
|
149
|
+
...item.itemStyle,
|
|
150
|
+
color: palette[index % palette.length],
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
...series,
|
|
156
|
+
data,
|
|
157
|
+
label: {
|
|
158
|
+
...label,
|
|
159
|
+
color: foreground,
|
|
160
|
+
textBorderColor: 'transparent',
|
|
161
|
+
textBorderWidth: 0,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function themeTreeSeries(series, foreground) {
|
|
166
|
+
const label = typeof series.label === 'object' && series.label !== null ? series.label : {};
|
|
167
|
+
const leafLabel = typeof series.leaves?.label === 'object' && series.leaves.label !== null
|
|
168
|
+
? series.leaves.label
|
|
169
|
+
: {};
|
|
170
|
+
return {
|
|
171
|
+
...series,
|
|
172
|
+
label: {
|
|
173
|
+
...label,
|
|
174
|
+
color: foreground,
|
|
175
|
+
textBorderColor: 'transparent',
|
|
176
|
+
textBorderWidth: 0,
|
|
177
|
+
},
|
|
178
|
+
leaves: {
|
|
179
|
+
...series.leaves,
|
|
180
|
+
label: {
|
|
181
|
+
...leafLabel,
|
|
182
|
+
color: foreground,
|
|
183
|
+
textBorderColor: 'transparent',
|
|
184
|
+
textBorderWidth: 0,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function themeXAxisOptions(axes, foreground, border) {
|
|
190
|
+
if (Array.isArray(axes)) {
|
|
191
|
+
return axes.map((axis) => themeXAxis(axis, foreground, border));
|
|
192
|
+
}
|
|
193
|
+
return axes === undefined ? undefined : themeXAxis(axes, foreground, border);
|
|
194
|
+
}
|
|
195
|
+
function themeYAxisOptions(axes, foreground, border) {
|
|
196
|
+
if (Array.isArray(axes)) {
|
|
197
|
+
return axes.map((axis) => themeYAxis(axis, foreground, border));
|
|
198
|
+
}
|
|
199
|
+
return axes === undefined ? undefined : themeYAxis(axes, foreground, border);
|
|
200
|
+
}
|
|
201
|
+
function themeXAxis(axis, foreground, border) {
|
|
202
|
+
const axisLine = typeof axis.axisLine === 'object' && axis.axisLine !== null ? axis.axisLine : undefined;
|
|
203
|
+
const axisTick = typeof axis.axisTick === 'object' && axis.axisTick !== null ? axis.axisTick : undefined;
|
|
204
|
+
const splitLine = typeof axis.splitLine === 'object' && axis.splitLine !== null ? axis.splitLine : undefined;
|
|
205
|
+
return {
|
|
206
|
+
...axis,
|
|
207
|
+
axisLabel: {
|
|
208
|
+
...(typeof axis.axisLabel === 'object' && axis.axisLabel !== null ? axis.axisLabel : {}),
|
|
209
|
+
color: foreground,
|
|
210
|
+
},
|
|
211
|
+
axisLine: { ...axisLine, lineStyle: { ...axisLine?.lineStyle, color: border } },
|
|
212
|
+
axisTick: { ...axisTick, lineStyle: { ...axisTick?.lineStyle, color: border } },
|
|
213
|
+
splitLine: { ...splitLine, lineStyle: { ...splitLine?.lineStyle, color: border } },
|
|
214
|
+
nameTextStyle: { ...axis.nameTextStyle, color: foreground },
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function themeYAxis(axis, foreground, border) {
|
|
218
|
+
const axisLine = typeof axis.axisLine === 'object' && axis.axisLine !== null ? axis.axisLine : undefined;
|
|
219
|
+
const axisTick = typeof axis.axisTick === 'object' && axis.axisTick !== null ? axis.axisTick : undefined;
|
|
220
|
+
const splitLine = typeof axis.splitLine === 'object' && axis.splitLine !== null ? axis.splitLine : undefined;
|
|
221
|
+
return {
|
|
222
|
+
...axis,
|
|
223
|
+
axisLabel: {
|
|
224
|
+
...(typeof axis.axisLabel === 'object' && axis.axisLabel !== null ? axis.axisLabel : {}),
|
|
225
|
+
color: foreground,
|
|
226
|
+
},
|
|
227
|
+
axisLine: { ...axisLine, lineStyle: { ...axisLine?.lineStyle, color: border } },
|
|
228
|
+
axisTick: { ...axisTick, lineStyle: { ...axisTick?.lineStyle, color: border } },
|
|
229
|
+
splitLine: { ...splitLine, lineStyle: { ...splitLine?.lineStyle, color: border } },
|
|
230
|
+
nameTextStyle: { ...axis.nameTextStyle, color: foreground },
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=use-echarts.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import '../styles.css';
|
|
4
|
+
/**
|
|
5
|
+
* Props for {@link VisualSpecView}.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <VisualSpecView spec={spec} isStreaming={spec.isStreaming} />
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface VisualSpecViewProps {
|
|
13
|
+
/** Existing AST returned by `cast()`, `castStream()`, or `createStreamCaster()`. */
|
|
14
|
+
spec: VisualSpec;
|
|
15
|
+
/** Optional override for the streaming state carried by `spec`. */
|
|
16
|
+
isStreaming?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Renders an existing `VisualSpec` using the same view shell and renderers as `AutoVisual`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const spec = cast(data);
|
|
24
|
+
* return <VisualSpecView spec={spec} />;
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function VisualSpecView({ spec, isStreaming }: VisualSpecViewProps): ReactElement;
|
|
28
|
+
//# sourceMappingURL=visual-spec-view.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useSelectedViewId } from './use-selected-view-id.js';
|
|
4
|
+
import { isImplementedArchetype } from './implemented-archetypes.js';
|
|
5
|
+
import { ArchetypeView } from './views/archetype-view.js';
|
|
6
|
+
import { ViewSwitcher, viewTabPanelId } from './view-switcher.js';
|
|
7
|
+
import '../styles.css';
|
|
8
|
+
/**
|
|
9
|
+
* Renders an existing `VisualSpec` using the same view shell and renderers as `AutoVisual`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const spec = cast(data);
|
|
14
|
+
* return <VisualSpecView spec={spec} />;
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function VisualSpecView({ spec, isStreaming }) {
|
|
18
|
+
const renderSpec = useMemo(() => {
|
|
19
|
+
if (isStreaming === undefined || isStreaming === spec.isStreaming) {
|
|
20
|
+
return spec;
|
|
21
|
+
}
|
|
22
|
+
return { ...spec, isStreaming };
|
|
23
|
+
}, [isStreaming, spec]);
|
|
24
|
+
const [selectedViewId, setSelectedViewId] = useSelectedViewId(renderSpec);
|
|
25
|
+
const activeView = renderSpec.views.find((view) => view.id === selectedViewId) ?? renderSpec.primaryView;
|
|
26
|
+
const showStreamingPlaceholder = renderSpec.isStreaming && renderSpec.data.length === 0;
|
|
27
|
+
const showSwitcher = renderSpec.views.length > 1;
|
|
28
|
+
const canRenderView = !showStreamingPlaceholder && isImplementedArchetype(activeView.archetype);
|
|
29
|
+
return (_jsxs("section", { "aria-label": "Auto visual", className: "schemacast-auto-visual", "data-testid": "auto-visual", children: [showSwitcher ? (_jsx(ViewSwitcher, { views: renderSpec.views, selectedViewId: selectedViewId, onSelectViewId: setSelectedViewId })) : null, _jsxs("div", { role: "tabpanel", className: "schemacast-view-panel", id: viewTabPanelId(activeView.id), "aria-labelledby": showSwitcher ? `schemacast-tab-${activeView.id}` : undefined, "data-testid": "view-panel", children: [_jsx("header", { className: "schemacast-view-panel-header", children: _jsxs("details", { className: "schemacast-view-rationale", children: [_jsx("summary", { className: "schemacast-view-rationale-summary", children: "Why this view?" }), _jsxs("div", { className: "schemacast-view-rationale-content", children: [_jsxs("p", { className: "schemacast-view-rationale-item", children: [_jsx("span", { className: "schemacast-view-rationale-label", children: "View" }), _jsx("span", { "data-testid": "primary-archetype", children: activeView.archetype })] }), _jsxs("p", { className: "schemacast-view-rationale-item", children: [_jsx("span", { className: "schemacast-view-rationale-label", children: "Score" }), _jsx("span", { "data-testid": "primary-score", children: activeView.score.toFixed(2) })] }), _jsxs("p", { className: "schemacast-view-rationale-item", children: [_jsx("span", { className: "schemacast-view-rationale-label", children: "Reason" }), _jsx("span", { "data-testid": "primary-reason", children: activeView.reason })] })] })] }) }), showStreamingPlaceholder ? (_jsx("p", { "data-testid": "streaming-placeholder", children: "Preparing visual from stream\u2026" })) : canRenderView ? (_jsx(ArchetypeView, { spec: renderSpec, view: activeView })) : (_jsxs("p", { "data-testid": "view-placeholder", children: ["No renderer is available for archetype \u201C", activeView.archetype, "\u201D."] }))] })] }));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=visual-spec-view.js.map
|