@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,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { fieldByKey } from '../field-by-key.js';
|
|
4
|
+
import { formatFieldValue } from '../format-field-value.js';
|
|
5
|
+
/**
|
|
6
|
+
* Renders a single-record `detail-card` from `VisualSpec.data[0]` and field bindings.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <DetailCardView spec={spec} bindings={spec.primaryView.bindings} />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function DetailCardView({ spec, bindings }) {
|
|
14
|
+
const row = spec.data[0];
|
|
15
|
+
if (row === undefined) {
|
|
16
|
+
return _jsx("p", { "data-testid": "detail-card-empty", children: "No record in view data." });
|
|
17
|
+
}
|
|
18
|
+
const titleKey = bindings.title;
|
|
19
|
+
const subtitleKey = bindings.subtitle;
|
|
20
|
+
const columns = bindings.columns ?? [];
|
|
21
|
+
const title = titleKey !== undefined
|
|
22
|
+
? formatFieldValue(row[titleKey], fieldByKey(spec.fields, titleKey))
|
|
23
|
+
: '';
|
|
24
|
+
const subtitle = subtitleKey !== undefined
|
|
25
|
+
? formatFieldValue(row[subtitleKey], fieldByKey(spec.fields, subtitleKey))
|
|
26
|
+
: '';
|
|
27
|
+
return (_jsxs("article", { className: "schemacast-detail-card", "data-testid": "detail-card-view", children: [title.length > 0 || subtitle.length > 0 ? (_jsxs("header", { className: "schemacast-detail-card-header", children: [title.length > 0 ? _jsx("h3", { "data-testid": "detail-card-title", children: title }) : null, subtitle.length > 0 ? _jsx("p", { "data-testid": "detail-card-subtitle", children: subtitle }) : null] })) : null, _jsx("dl", { className: "schemacast-detail-card-grid", "data-testid": "detail-card-table", children: columns.map((key) => {
|
|
28
|
+
const field = fieldByKey(spec.fields, key);
|
|
29
|
+
const value = row[key];
|
|
30
|
+
return (_jsxs("div", { className: "schemacast-detail-card-row", children: [_jsx("dt", { className: "schemacast-detail-card-label", "data-testid": `detail-card-label-${key}`, children: labelFor(key, spec.fields) }), _jsx("dd", { className: "schemacast-detail-card-value", "data-testid": `detail-card-value-${key}`, children: _jsx(DetailCardValue, { field: field, fieldKey: key, value: value }) })] }, key));
|
|
31
|
+
}) })] }));
|
|
32
|
+
}
|
|
33
|
+
function DetailCardValue({ field, fieldKey, value }) {
|
|
34
|
+
if (typeof value === 'boolean') {
|
|
35
|
+
const booleanLabel = booleanLabelFor(fieldKey, value);
|
|
36
|
+
return (_jsx("span", { className: "schemacast-detail-card-badge", "data-testid": `detail-card-boolean-${fieldKey}`, children: booleanLabel }));
|
|
37
|
+
}
|
|
38
|
+
if (field?.semanticType === 'image-url' && typeof value === 'string' && value.length > 0) {
|
|
39
|
+
return _jsx(ImageUrlValue, { fieldKey: fieldKey, label: field.label, url: value });
|
|
40
|
+
}
|
|
41
|
+
return _jsx("span", { children: formatFieldValue(value, field) });
|
|
42
|
+
}
|
|
43
|
+
function booleanLabelFor(fieldKey, value) {
|
|
44
|
+
if (!fieldKey.startsWith('is_')) {
|
|
45
|
+
return value ? 'Yes' : 'No';
|
|
46
|
+
}
|
|
47
|
+
return value ? 'Active' : 'Inactive';
|
|
48
|
+
}
|
|
49
|
+
function ImageUrlValue({ fieldKey, label, url }) {
|
|
50
|
+
const [failedUrl, setFailedUrl] = useState(null);
|
|
51
|
+
const imageFailed = failedUrl === url;
|
|
52
|
+
return (_jsxs("span", { className: "schemacast-detail-card-image-value", children: [_jsx("img", { className: "schemacast-detail-card-avatar", "data-testid": `detail-card-avatar-${fieldKey}`, src: url, alt: imageFailed ? '' : label, hidden: imageFailed, onError: () => {
|
|
53
|
+
setFailedUrl(url);
|
|
54
|
+
} }), _jsx("span", { className: "schemacast-detail-card-url-fallback", "data-testid": `detail-card-url-fallback-${fieldKey}`, hidden: !imageFailed, children: url })] }));
|
|
55
|
+
}
|
|
56
|
+
function labelFor(key, fields) {
|
|
57
|
+
return fieldByKey(fields, key)?.label ?? key;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=detail-card-view.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Thinnest edge line, in pixels: the lightest weight, and any edge without a numeric weight. */
|
|
2
|
+
export declare const EDGE_WIDTH_MIN = 1;
|
|
3
|
+
/** Thickest edge line, in pixels: the heaviest weight. */
|
|
4
|
+
export declare const EDGE_WIDTH_MAX = 6;
|
|
5
|
+
/**
|
|
6
|
+
* Reads an edge weight as a finite number, or `undefined` when it is missing or not numeric.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* readEdgeWeight('3.5'); // 3.5
|
|
10
|
+
* readEdgeWeight('heavy'); // undefined
|
|
11
|
+
*/
|
|
12
|
+
export declare function readEdgeWeight(value: unknown): number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Maps edge weights to line widths, linearly from `EDGE_WIDTH_MIN` (lightest) to
|
|
15
|
+
* `EDGE_WIDTH_MAX` (heaviest) across the weight range. Equal weights share the middle width;
|
|
16
|
+
* missing or non-numeric weights get `EDGE_WIDTH_MIN`. A width is never negative.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* scaleEdgeWidths([1, 5, 9, undefined]); // [1, 3.5, 6, 1]
|
|
20
|
+
* scaleEdgeWidths([4, 4]); // [3.5, 3.5]
|
|
21
|
+
*/
|
|
22
|
+
export declare function scaleEdgeWidths(weights: readonly (number | undefined)[]): number[];
|
|
23
|
+
//# sourceMappingURL=edge-weight-width.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Thinnest edge line, in pixels: the lightest weight, and any edge without a numeric weight. */
|
|
2
|
+
export const EDGE_WIDTH_MIN = 1;
|
|
3
|
+
/** Thickest edge line, in pixels: the heaviest weight. */
|
|
4
|
+
export const EDGE_WIDTH_MAX = 6;
|
|
5
|
+
/**
|
|
6
|
+
* Reads an edge weight as a finite number, or `undefined` when it is missing or not numeric.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* readEdgeWeight('3.5'); // 3.5
|
|
10
|
+
* readEdgeWeight('heavy'); // undefined
|
|
11
|
+
*/
|
|
12
|
+
export function readEdgeWeight(value) {
|
|
13
|
+
if (typeof value === 'number') {
|
|
14
|
+
return Number.isFinite(value) ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
17
|
+
const parsed = Number(value);
|
|
18
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Maps edge weights to line widths, linearly from `EDGE_WIDTH_MIN` (lightest) to
|
|
24
|
+
* `EDGE_WIDTH_MAX` (heaviest) across the weight range. Equal weights share the middle width;
|
|
25
|
+
* missing or non-numeric weights get `EDGE_WIDTH_MIN`. A width is never negative.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* scaleEdgeWidths([1, 5, 9, undefined]); // [1, 3.5, 6, 1]
|
|
29
|
+
* scaleEdgeWidths([4, 4]); // [3.5, 3.5]
|
|
30
|
+
*/
|
|
31
|
+
export function scaleEdgeWidths(weights) {
|
|
32
|
+
const finiteWeights = weights.filter((weight) => weight !== undefined);
|
|
33
|
+
const lightest = Math.min(...finiteWeights);
|
|
34
|
+
const heaviest = Math.max(...finiteWeights);
|
|
35
|
+
const middleWidth = (EDGE_WIDTH_MIN + EDGE_WIDTH_MAX) / 2;
|
|
36
|
+
return weights.map((weight) => {
|
|
37
|
+
if (weight === undefined) {
|
|
38
|
+
return EDGE_WIDTH_MIN;
|
|
39
|
+
}
|
|
40
|
+
if (heaviest === lightest) {
|
|
41
|
+
return middleWidth;
|
|
42
|
+
}
|
|
43
|
+
const share = (weight - lightest) / (heaviest - lightest);
|
|
44
|
+
return Math.max(0, EDGE_WIDTH_MIN + share * (EDGE_WIDTH_MAX - EDGE_WIDTH_MIN));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=edge-weight-width.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface HierarchyTreeViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ECharts `hierarchy-tree` for nested tree JSON (lazy-loaded parent).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <HierarchyTreeView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function HierarchyTreeView({ spec, bindings }: HierarchyTreeViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=hierarchy-tree-view.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { buildHierarchyTreeData, collectHierarchyNames } from './build-hierarchy-tree-data.js';
|
|
4
|
+
import { useEcharts } from './use-echarts.js';
|
|
5
|
+
/**
|
|
6
|
+
* ECharts `hierarchy-tree` for nested tree JSON (lazy-loaded parent).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <HierarchyTreeView spec={spec} bindings={spec.primaryView.bindings} />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function HierarchyTreeView({ spec, bindings }) {
|
|
14
|
+
const treeData = useMemo(() => buildHierarchyTreeData(spec.data[0], bindings), [bindings, spec.data]);
|
|
15
|
+
const option = useMemo(() => {
|
|
16
|
+
if (treeData === null) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
tooltip: { trigger: 'item', triggerOn: 'mousemove' },
|
|
21
|
+
series: [
|
|
22
|
+
{
|
|
23
|
+
type: 'tree',
|
|
24
|
+
data: [treeData],
|
|
25
|
+
top: '8%',
|
|
26
|
+
left: '12%',
|
|
27
|
+
bottom: '8%',
|
|
28
|
+
right: '24%',
|
|
29
|
+
symbolSize: 8,
|
|
30
|
+
label: {
|
|
31
|
+
position: 'left',
|
|
32
|
+
verticalAlign: 'middle',
|
|
33
|
+
align: 'right',
|
|
34
|
+
},
|
|
35
|
+
leaves: {
|
|
36
|
+
label: {
|
|
37
|
+
position: 'right',
|
|
38
|
+
verticalAlign: 'middle',
|
|
39
|
+
align: 'left',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
expandAndCollapse: true,
|
|
43
|
+
initialTreeDepth: -1,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}, [treeData]);
|
|
48
|
+
const chartRef = useEcharts(option, spec.isStreaming, true);
|
|
49
|
+
const labels = treeData !== null ? collectHierarchyNames(treeData) : [];
|
|
50
|
+
if (spec.isStreaming && spec.data.length === 0) {
|
|
51
|
+
return _jsx("p", { "data-testid": "hierarchy-tree-streaming", children: "Preparing tree from stream\u2026" });
|
|
52
|
+
}
|
|
53
|
+
if (option === null) {
|
|
54
|
+
return _jsx("p", { "data-testid": "hierarchy-tree-empty", children: "No hierarchy root in view data." });
|
|
55
|
+
}
|
|
56
|
+
return (_jsxs("div", { "data-testid": "hierarchy-tree-view", children: [_jsx("ul", { "data-testid": "hierarchy-tree-labels", className: "sr-only", children: labels.map((label) => (_jsx("li", { children: label }, label))) }), _jsx("div", { ref: chartRef, style: { width: '100%', height: 420 } })] }));
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=hierarchy-tree-view.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface JsonTreeViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Displays raw VisualSpec data as an expandable JSON tree.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <JsonTreeView spec={spec} />
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function JsonTreeView({ spec }: JsonTreeViewProps): ReactElement;
|
|
15
|
+
//# sourceMappingURL=json-tree-view.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Displays raw VisualSpec data as an expandable JSON tree.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <JsonTreeView spec={spec} />
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export function JsonTreeView({ spec }) {
|
|
12
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
13
|
+
const normalizedQuery = searchQuery.trim().toLowerCase();
|
|
14
|
+
const roots = useMemo(() => buildJsonRoots(spec), [spec]);
|
|
15
|
+
return (_jsxs("div", { className: "schemacast-json-tree", "data-testid": "json-tree-view", children: [_jsxs("label", { className: "schemacast-json-tree-search", children: ["Search", _jsx("input", { className: "schemacast-json-tree-search-input", type: "search", value: searchQuery, onChange: (event) => {
|
|
16
|
+
setSearchQuery(event.target.value);
|
|
17
|
+
}, "aria-label": "Search JSON tree" })] }), roots.map((root) => (_jsx(JsonTreeSection, { label: root.label, value: root.value, path: root.label, searchQuery: normalizedQuery }, root.label)))] }));
|
|
18
|
+
}
|
|
19
|
+
function buildJsonRoots(spec) {
|
|
20
|
+
const roots = [{ label: 'data', value: spec.data }];
|
|
21
|
+
if (spec.meta !== undefined) {
|
|
22
|
+
roots.push({ label: 'meta', value: spec.meta });
|
|
23
|
+
}
|
|
24
|
+
if (spec.edges !== undefined) {
|
|
25
|
+
roots.push({ label: 'edges', value: spec.edges });
|
|
26
|
+
}
|
|
27
|
+
return roots;
|
|
28
|
+
}
|
|
29
|
+
function JsonTreeSection({ label, value, path, searchQuery }) {
|
|
30
|
+
return (_jsxs("section", { className: "schemacast-json-tree-section", "data-testid": `json-tree-section-${label}`, children: [_jsx("h4", { className: "schemacast-json-tree-section-title", children: label }), _jsx(JsonTreeNode, { label: null, value: value, path: path, searchQuery: searchQuery, depth: 0 })] }));
|
|
31
|
+
}
|
|
32
|
+
function JsonTreeNode({ label, value, path, searchQuery, depth, }) {
|
|
33
|
+
const [isExpanded, setIsExpanded] = useState(depth === 0);
|
|
34
|
+
const hasChildren = isBranchValue(value);
|
|
35
|
+
if (!nodeMatchesQuery(label, value, path, searchQuery)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (!hasChildren) {
|
|
39
|
+
return (_jsxs("div", { className: "schemacast-json-tree-line schemacast-json-tree-leaf", "data-testid": "json-tree-leaf", style: { paddingLeft: `${depth * 1.25}rem` }, children: [label === null ? null : (_jsxs("span", { className: "schemacast-json-tree-key", children: [JSON.stringify(label), ":"] })), _jsx("span", { className: `schemacast-json-tree-value schemacast-json-tree-value--${valueType(value)}`, children: formatRawValue(value) })] }));
|
|
40
|
+
}
|
|
41
|
+
const children = branchEntries(value, path);
|
|
42
|
+
const isExpandedForSearch = isExpanded || searchQuery.length > 0;
|
|
43
|
+
const openingBracket = Array.isArray(value) ? '[' : '{';
|
|
44
|
+
const closingBracket = Array.isArray(value) ? ']' : '}';
|
|
45
|
+
const branchSummary = isExpandedForSearch
|
|
46
|
+
? openingBracket
|
|
47
|
+
: `${openingBracket}${children.length}${closingBracket}`;
|
|
48
|
+
return (_jsxs("div", { className: "schemacast-json-tree-node", "data-testid": "json-tree-node", children: [_jsx("div", { className: "schemacast-json-tree-line", style: { paddingLeft: `${depth * 1.25}rem` }, children: _jsxs("button", { className: "schemacast-json-tree-toggle", type: "button", "aria-expanded": isExpandedForSearch, "data-testid": `json-tree-toggle-${path}`, onClick: () => {
|
|
49
|
+
setIsExpanded((expanded) => !expanded);
|
|
50
|
+
}, children: [_jsx("span", { className: "schemacast-json-tree-arrow", "aria-hidden": "true", children: isExpandedForSearch ? '▾' : '▸' }), label === null ? null : (_jsxs("span", { className: "schemacast-json-tree-key", children: [JSON.stringify(label), ":"] })), _jsx("span", { className: "schemacast-json-tree-bracket", children: branchSummary })] }) }), isExpandedForSearch ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "schemacast-json-tree-children", children: children.map((child) => (_jsx(JsonTreeNode, { label: child.label, value: child.value, path: child.path, searchQuery: searchQuery, depth: depth + 1 }, child.path))) }), _jsx("div", { className: "schemacast-json-tree-line schemacast-json-tree-closing-bracket", style: { paddingLeft: `${depth * 1.25}rem` }, "aria-hidden": "true", children: closingBracket })] })) : null] }));
|
|
51
|
+
}
|
|
52
|
+
function nodeMatchesQuery(label, value, path, searchQuery) {
|
|
53
|
+
if (searchQuery.length === 0) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const haystack = `${label ?? ''} ${path} ${formatLeaf(value)}`.toLowerCase();
|
|
57
|
+
if (haystack.includes(searchQuery)) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (!isBranchValue(value)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return branchEntries(value, path).some((child) => nodeMatchesQuery(child.label, child.value, child.path, searchQuery));
|
|
64
|
+
}
|
|
65
|
+
function isBranchValue(value) {
|
|
66
|
+
return Array.isArray(value) || (typeof value === 'object' && value !== null);
|
|
67
|
+
}
|
|
68
|
+
function branchEntries(value, path) {
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
return value.map((entry, index) => ({
|
|
71
|
+
label: null,
|
|
72
|
+
value: entry,
|
|
73
|
+
path: `${path}[${index}]`,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === 'object' && value !== null) {
|
|
77
|
+
return Object.entries(value).map(([key, childValue]) => ({
|
|
78
|
+
label: key,
|
|
79
|
+
value: childValue,
|
|
80
|
+
path: `${path}.${key}`,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
function valueType(value) {
|
|
86
|
+
if (value === null) {
|
|
87
|
+
return 'null';
|
|
88
|
+
}
|
|
89
|
+
if (typeof value === 'string') {
|
|
90
|
+
return 'string';
|
|
91
|
+
}
|
|
92
|
+
if (typeof value === 'number') {
|
|
93
|
+
return 'number';
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'boolean') {
|
|
96
|
+
return 'boolean';
|
|
97
|
+
}
|
|
98
|
+
return 'other';
|
|
99
|
+
}
|
|
100
|
+
function formatRawValue(value) {
|
|
101
|
+
if (typeof value === 'string') {
|
|
102
|
+
return JSON.stringify(value) ?? '""';
|
|
103
|
+
}
|
|
104
|
+
return String(value);
|
|
105
|
+
}
|
|
106
|
+
function formatLeaf(value) {
|
|
107
|
+
if (value === null || value === undefined) {
|
|
108
|
+
return String(value);
|
|
109
|
+
}
|
|
110
|
+
if (typeof value === 'object') {
|
|
111
|
+
return '[…]';
|
|
112
|
+
}
|
|
113
|
+
return String(value);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=json-tree-view.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface KanbanViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders uniform-array tasks grouped into kanban columns by status.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <KanbanView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function KanbanView({ spec, bindings }: KanbanViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=kanban-view.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Renders uniform-array tasks grouped into kanban columns by status.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* <KanbanView spec={spec} bindings={spec.primaryView.bindings} />
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export function KanbanView({ spec, bindings }) {
|
|
11
|
+
const laneKey = bindings.groupBy;
|
|
12
|
+
const titleKey = bindings.title;
|
|
13
|
+
const subtitleKey = bindings.subtitle;
|
|
14
|
+
if (laneKey === undefined || titleKey === undefined) {
|
|
15
|
+
return _jsx("p", { "data-testid": "kanban-view", children: "Missing kanban bindings." });
|
|
16
|
+
}
|
|
17
|
+
const lanes = new Map();
|
|
18
|
+
for (const row of spec.data) {
|
|
19
|
+
const lane = String(row[laneKey] ?? 'unknown');
|
|
20
|
+
const existing = lanes.get(lane) ?? [];
|
|
21
|
+
lanes.set(lane, [...existing, row]);
|
|
22
|
+
}
|
|
23
|
+
const laneNames = Array.from(lanes.keys()).sort((left, right) => left.localeCompare(right));
|
|
24
|
+
return (_jsx("div", { className: "schemacast-kanban-board", "data-testid": "kanban-view", children: laneNames.map((lane) => {
|
|
25
|
+
const cards = lanes.get(lane) ?? [];
|
|
26
|
+
const displayLane = humanizeLane(lane);
|
|
27
|
+
return (_jsxs("section", { className: "schemacast-kanban-column", "data-testid": `kanban-lane-${lane}`, "aria-label": lane, children: [_jsx("header", { className: "schemacast-kanban-column-header", children: _jsxs("h4", { children: [displayLane, " ", _jsxs("span", { children: ["(", cards.length, ")"] })] }) }), _jsx("ul", { className: "schemacast-kanban-card-list", children: cards.map((card, index) => {
|
|
28
|
+
const title = String(card[titleKey] ?? '');
|
|
29
|
+
const subtitle = subtitleKey !== undefined ? String(card[subtitleKey] ?? '') : '';
|
|
30
|
+
return (_jsxs("li", { className: "schemacast-kanban-card", "data-testid": "kanban-card", children: [_jsx("span", { children: title }), subtitle.length > 0 ? _jsx("small", { children: subtitle }) : null] }, `${lane}-${index}`));
|
|
31
|
+
}) })] }, lane));
|
|
32
|
+
}) }));
|
|
33
|
+
}
|
|
34
|
+
function humanizeLane(lane) {
|
|
35
|
+
const words = lane.replace(/_/g, ' ');
|
|
36
|
+
const firstCharacter = words.charAt(0);
|
|
37
|
+
return firstCharacter.length === 0
|
|
38
|
+
? words
|
|
39
|
+
: `${firstCharacter.toLocaleUpperCase()}${words.slice(1)}`;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=kanban-view.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface KpiGridViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders scalar metrics as a `kpi-grid` using bound quantitative fields.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <KpiGridView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function KpiGridView({ spec, bindings }: KpiGridViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=kpi-grid-view.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
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 groupedNumberFormatter = new Intl.NumberFormat('en-US', {
|
|
5
|
+
maximumSignificantDigits: 21,
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Renders scalar metrics as a `kpi-grid` using bound quantitative fields.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <KpiGridView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function KpiGridView({ spec, bindings }) {
|
|
16
|
+
const row = spec.data[0];
|
|
17
|
+
const metricKeys = bindings.y ?? [];
|
|
18
|
+
return (_jsx("div", { "data-testid": "kpi-grid-view", children: _jsx("ul", { className: "schemacast-kpi-grid", children: metricKeys.map((key) => {
|
|
19
|
+
const field = fieldByKey(spec.fields, key);
|
|
20
|
+
const value = row !== undefined ? row[key] : undefined;
|
|
21
|
+
return (_jsxs("li", { className: "schemacast-kpi-card", "data-testid": `kpi-tile-${key}`, children: [_jsx("span", { className: "schemacast-kpi-label", "data-testid": `kpi-label-${key}`, children: field?.label ?? key }), _jsx("strong", { className: "schemacast-kpi-value", "data-testid": `kpi-value-${key}`, children: formatKpiValue(value, field) })] }, key));
|
|
22
|
+
}) }) }));
|
|
23
|
+
}
|
|
24
|
+
function formatKpiValue(value, field) {
|
|
25
|
+
if (field?.semanticType !== 'number' || value === null || value === undefined) {
|
|
26
|
+
return formatFieldValue(value, field);
|
|
27
|
+
}
|
|
28
|
+
const numericValue = typeof value === 'number' ? value : Number(value);
|
|
29
|
+
if (!Number.isFinite(numericValue)) {
|
|
30
|
+
return formatFieldValue(value, field);
|
|
31
|
+
}
|
|
32
|
+
return groupedNumberFormatter.format(numericValue);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=kpi-grid-view.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LINE_SAMPLING_MIN_POINTS } from '@schemacast/core';
|
|
2
|
+
export { LINE_SAMPLING_MIN_POINTS };
|
|
3
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
4
|
+
import type { EChartsOption } from 'echarts';
|
|
5
|
+
/**
|
|
6
|
+
* Builds a line-chart option with shared unit-aware value-axis behavior. A numeric x (a step,
|
|
7
|
+
* epoch or version) gets a `value` axis and `[x, y]` points; date and category x keep the
|
|
8
|
+
* category axis.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const option = buildLineChartOption(spec, spec.primaryView.bindings);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildLineChartOption(spec: VisualSpec, bindings: FieldBindings): EChartsOption | null;
|
|
16
|
+
//# sourceMappingURL=line-chart-options.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { buildLongFormatLine, LINE_SAMPLING_MIN_POINTS } from '@schemacast/core';
|
|
2
|
+
export { LINE_SAMPLING_MIN_POINTS };
|
|
3
|
+
import { fieldByKey } from '../field-by-key.js';
|
|
4
|
+
import { buildCategoryAxis, buildNumericXAxis, isNumericAxisField, numericSeries, numericXSeries, readNumericSeriesValue, seriesLabel, } from './chart-series-data.js';
|
|
5
|
+
import { buildValueAxis, buildValueAxisPlan, formatChartTooltip } from './chart-value-axes.js';
|
|
6
|
+
/**
|
|
7
|
+
* Builds a line-chart option with shared unit-aware value-axis behavior. A numeric x (a step,
|
|
8
|
+
* epoch or version) gets a `value` axis and `[x, y]` points; date and category x keep the
|
|
9
|
+
* category axis.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const option = buildLineChartOption(spec, spec.primaryView.bindings);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function buildLineChartOption(spec, bindings) {
|
|
17
|
+
const xKey = bindings.x;
|
|
18
|
+
const yKeys = bindings.y ?? [];
|
|
19
|
+
if (xKey === undefined || yKeys.length === 0) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (bindings.groupBy !== undefined) {
|
|
23
|
+
return buildLongFormatLineOption(spec, xKey, yKeys[0], bindings.groupBy);
|
|
24
|
+
}
|
|
25
|
+
const hasNumericX = isNumericAxisField(fieldByKey(spec.fields, xKey));
|
|
26
|
+
const axisPlan = buildValueAxisPlan(spec, yKeys, spec.data, true);
|
|
27
|
+
const axes = axisPlan.axes.map((axis) => buildValueAxis(spec.fields, axis));
|
|
28
|
+
return {
|
|
29
|
+
tooltip: {
|
|
30
|
+
trigger: 'axis',
|
|
31
|
+
formatter: (parameters) => formatChartTooltip(parameters, spec.fields, yKeys),
|
|
32
|
+
},
|
|
33
|
+
legend: { data: yKeys.map((key) => seriesLabel(spec.fields, key)) },
|
|
34
|
+
grid: {
|
|
35
|
+
left: axes.length > 1 ? 104 : 88,
|
|
36
|
+
right: axes.length > 1 ? 104 : 24,
|
|
37
|
+
containLabel: true,
|
|
38
|
+
},
|
|
39
|
+
xAxis: hasNumericX
|
|
40
|
+
? buildNumericXAxis(spec.fields, xKey)
|
|
41
|
+
: buildCategoryAxis(spec.data, xKey, spec.fields),
|
|
42
|
+
yAxis: axes.length === 1 ? axes[0] : axes,
|
|
43
|
+
series: yKeys.map((yKey, index) => ({
|
|
44
|
+
name: seriesLabel(spec.fields, yKey),
|
|
45
|
+
type: 'line',
|
|
46
|
+
yAxisIndex: axisPlan.seriesAxisIndexes[index] ?? 0,
|
|
47
|
+
...(spec.data.length >= LINE_SAMPLING_MIN_POINTS ? { sampling: 'lttb' } : {}),
|
|
48
|
+
data: hasNumericX
|
|
49
|
+
? numericXSeries(spec.data, xKey, yKey, spec.fields)
|
|
50
|
+
: numericSeries(spec.data, yKey, spec.fields),
|
|
51
|
+
})),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One line per group value over a shared, sorted x axis. A group with no row at an x holds
|
|
56
|
+
* `null` there, so the line breaks (a gap) and never drops to zero. All lines share one y axis
|
|
57
|
+
* because they plot the same metric.
|
|
58
|
+
*/
|
|
59
|
+
function buildLongFormatLineOption(spec, xKey, yKey, groupKey) {
|
|
60
|
+
if (yKey === undefined) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const line = buildLongFormatLine(spec.data, { xKey, groupKey, yKey }, spec.fields);
|
|
64
|
+
const xField = fieldByKey(spec.fields, xKey);
|
|
65
|
+
const hasNumericX = isNumericAxisField(xField);
|
|
66
|
+
const axisPlan = buildValueAxisPlan(spec, [yKey], spec.data, true);
|
|
67
|
+
const axes = axisPlan.axes.map((axis) => buildValueAxis(spec.fields, axis));
|
|
68
|
+
const seriesYKeys = line.series.map(() => yKey);
|
|
69
|
+
const xNumbers = line.xValues.map((value) => readNumericSeriesValue(value, xField?.semanticType));
|
|
70
|
+
return {
|
|
71
|
+
tooltip: {
|
|
72
|
+
trigger: 'axis',
|
|
73
|
+
formatter: (parameters) => formatChartTooltip(parameters, spec.fields, seriesYKeys),
|
|
74
|
+
},
|
|
75
|
+
legend: { data: line.series.map((series) => series.name) },
|
|
76
|
+
grid: { left: 88, right: 24, containLabel: true },
|
|
77
|
+
xAxis: hasNumericX
|
|
78
|
+
? buildNumericXAxis(spec.fields, xKey)
|
|
79
|
+
: buildCategoryAxis(line.xValues.map((value) => ({ [xKey]: value })), xKey, spec.fields),
|
|
80
|
+
yAxis: axes[0],
|
|
81
|
+
series: line.series.map((series) => ({
|
|
82
|
+
name: series.name,
|
|
83
|
+
type: 'line',
|
|
84
|
+
...(line.xValues.length >= LINE_SAMPLING_MIN_POINTS ? { sampling: 'lttb' } : {}),
|
|
85
|
+
data: hasNumericX
|
|
86
|
+
? series.values.map((value, index) => [
|
|
87
|
+
xNumbers[index] ?? null,
|
|
88
|
+
value,
|
|
89
|
+
])
|
|
90
|
+
: series.values,
|
|
91
|
+
})),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=line-chart-options.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface LineChartViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ECharts `line-chart` for time series or ordered categories (lazy-loaded parent).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <LineChartView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function LineChartView({ spec, bindings }: LineChartViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=line-chart-view.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { buildLineChartOption } from './line-chart-options.js';
|
|
4
|
+
import { useEcharts } from './use-echarts.js';
|
|
5
|
+
/**
|
|
6
|
+
* ECharts `line-chart` for time series or ordered categories (lazy-loaded parent).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <LineChartView spec={spec} bindings={spec.primaryView.bindings} />
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function LineChartView({ spec, bindings }) {
|
|
14
|
+
const xKey = bindings.x;
|
|
15
|
+
const yKeys = bindings.y ?? [];
|
|
16
|
+
const groupKey = bindings.groupBy;
|
|
17
|
+
const option = useMemo(() => buildLineChartOption(spec, {
|
|
18
|
+
x: xKey,
|
|
19
|
+
y: yKeys,
|
|
20
|
+
...(groupKey === undefined ? {} : { groupBy: groupKey }),
|
|
21
|
+
}), [spec.data, spec.fields, xKey, yKeys, groupKey]);
|
|
22
|
+
const chartRef = useEcharts(option, spec.isStreaming, true);
|
|
23
|
+
if (spec.isStreaming && spec.data.length === 0) {
|
|
24
|
+
return _jsx("p", { "data-testid": "line-chart-streaming", children: "Preparing chart from stream\u2026" });
|
|
25
|
+
}
|
|
26
|
+
if (option === null) {
|
|
27
|
+
return _jsx("p", { "data-testid": "line-chart-empty", children: "Chart bindings are incomplete." });
|
|
28
|
+
}
|
|
29
|
+
return (_jsx("div", { "data-testid": "line-chart-view", "data-y-keys": yKeys.join(','), ref: chartRef, style: { width: '100%', height: 320 } }));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=line-chart-view.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { EChartsOption } from 'echarts';
|
|
3
|
+
/**
|
|
4
|
+
* Builds the force-directed graph option. Edges are drawn with a line width scaled by the
|
|
5
|
+
* `edgeWeight` binding (when there is one) and the weight shows in the edge tooltip. Edge labels
|
|
6
|
+
* are never drawn on the graph; they appear on hover only.
|
|
7
|
+
*
|
|
8
|
+
* @returns The option, or `null` when the graph has no nodes.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const option = buildNodeGraphOption(spec, spec.primaryView.bindings);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildNodeGraphOption(spec: VisualSpec, bindings: FieldBindings): EChartsOption | null;
|
|
16
|
+
/**
|
|
17
|
+
* Formats the node or edge tooltip. An edge shows its label, its direction, and its weight
|
|
18
|
+
* (`weight: 12`) when the graph binds an edge weight.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* formatGraphTooltip(params, nodeNames, 'weight');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatGraphTooltip(params: unknown, nodeNames: ReadonlyMap<string, string>, weightKey?: string): string;
|
|
26
|
+
//# sourceMappingURL=node-graph-options.d.ts.map
|