@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { fieldByKey } from '../field-by-key.js';
|
|
4
|
+
import { formatFieldValue } from '../format-field-value.js';
|
|
5
|
+
import { DATA_TABLE_PAGE_SIZE } from './data-table-constants.js';
|
|
6
|
+
import { filterRows, paginateRows, resolveTableColumns, sortRows, } from './data-table-rows.js';
|
|
7
|
+
function isQuantitativeField(field) {
|
|
8
|
+
return (field?.semanticType === 'number' ||
|
|
9
|
+
field?.semanticType === 'currency' ||
|
|
10
|
+
field?.semanticType === 'percentage');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Sortable, filterable, paginated `data-table` over `VisualSpec.data`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <DataTableView spec={spec} bindings={spec.primaryView.bindings} />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function DataTableView({ spec, bindings }) {
|
|
21
|
+
const columns = resolveTableColumns(bindings.columns, spec.fields);
|
|
22
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
23
|
+
const [sortKey, setSortKey] = useState(undefined);
|
|
24
|
+
const [sortDirection, setSortDirection] = useState('asc');
|
|
25
|
+
const [pageIndex, setPageIndex] = useState(0);
|
|
26
|
+
const displayRows = useMemo(() => {
|
|
27
|
+
const filtered = filterRows(spec.data, columns, spec.fields, searchQuery);
|
|
28
|
+
const sorted = sortRows(filtered, sortKey, sortDirection, spec.fields);
|
|
29
|
+
return sorted;
|
|
30
|
+
}, [columns, searchQuery, sortDirection, sortKey, spec.data, spec.fields]);
|
|
31
|
+
const pageCount = Math.max(1, Math.ceil(displayRows.length / DATA_TABLE_PAGE_SIZE));
|
|
32
|
+
const currentPageIndex = Math.min(pageIndex, pageCount - 1);
|
|
33
|
+
const pageRows = useMemo(() => paginateRows(displayRows, currentPageIndex, DATA_TABLE_PAGE_SIZE), [currentPageIndex, displayRows]);
|
|
34
|
+
const canGoNext = currentPageIndex < pageCount - 1;
|
|
35
|
+
const canGoPrev = currentPageIndex > 0;
|
|
36
|
+
const showStreamingEmpty = spec.isStreaming && displayRows.length === 0;
|
|
37
|
+
const showPagination = pageCount > 1;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (pageIndex !== currentPageIndex) {
|
|
40
|
+
setPageIndex(currentPageIndex);
|
|
41
|
+
}
|
|
42
|
+
}, [currentPageIndex, pageIndex]);
|
|
43
|
+
const handleSort = (columnKey) => {
|
|
44
|
+
if (sortKey === columnKey) {
|
|
45
|
+
setSortDirection((direction) => (direction === 'asc' ? 'desc' : 'asc'));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setSortKey(columnKey);
|
|
49
|
+
setSortDirection('asc');
|
|
50
|
+
setPageIndex(0);
|
|
51
|
+
};
|
|
52
|
+
return (_jsxs("div", { className: "schemacast-data-table-view", "data-testid": "data-table-view", children: [_jsx("div", { className: "schemacast-data-table-toolbar", children: _jsxs("label", { className: "schemacast-data-table-search", children: [_jsx("span", { children: "Search" }), _jsx("input", { type: "search", className: "schemacast-data-table-search-input", "data-testid": "data-table-search", placeholder: "Search rows...", value: searchQuery, onChange: (event) => {
|
|
53
|
+
setSearchQuery(event.target.value);
|
|
54
|
+
setPageIndex(0);
|
|
55
|
+
} })] }) }), showStreamingEmpty ? (_jsx("p", { "data-testid": "data-table-streaming-empty", children: "Preparing table rows from stream\u2026" })) : null, _jsx("div", { className: "schemacast-data-table-scroll", children: _jsxs("table", { className: "schemacast-data-table", children: [_jsx("thead", { children: _jsx("tr", { children: columns.map((columnKey) => {
|
|
56
|
+
const field = fieldByKey(spec.fields, columnKey);
|
|
57
|
+
const label = field?.label ?? columnKey;
|
|
58
|
+
const isSorted = sortKey === columnKey;
|
|
59
|
+
const isQuantitative = isQuantitativeField(field);
|
|
60
|
+
return (_jsx("th", { className: isQuantitative
|
|
61
|
+
? 'schemacast-data-table-header schemacast-data-table-header--numeric'
|
|
62
|
+
: 'schemacast-data-table-header', scope: "col", children: _jsxs("button", { type: "button", className: "schemacast-data-table-sort-button", "data-testid": `data-table-sort-${columnKey}`, "aria-sort": isSorted ? (sortDirection === 'asc' ? 'ascending' : 'descending') : 'none', onClick: () => {
|
|
63
|
+
handleSort(columnKey);
|
|
64
|
+
}, children: [label, isSorted ? (_jsx("span", { className: "schemacast-data-table-sort-indicator", "data-testid": `data-table-sort-indicator-${columnKey}`, "aria-hidden": "true", children: sortDirection === 'asc' ? '↑' : '↓' })) : null] }) }, columnKey));
|
|
65
|
+
}) }) }), _jsx("tbody", { children: pageRows.map((row, rowIndex) => (_jsx("tr", { className: "schemacast-data-table-row", "data-testid": "data-table-row", children: columns.map((columnKey) => {
|
|
66
|
+
const field = fieldByKey(spec.fields, columnKey);
|
|
67
|
+
return (_jsx("td", { className: isQuantitativeField(field)
|
|
68
|
+
? 'schemacast-data-table-cell schemacast-data-table-cell--numeric'
|
|
69
|
+
: 'schemacast-data-table-cell', children: formatFieldValue(row[columnKey], field) }, columnKey));
|
|
70
|
+
}) }, `row-${currentPageIndex}-${rowIndex}`))) })] }) }), !showStreamingEmpty && displayRows.length === 0 ? (_jsx("p", { "data-testid": "data-table-no-matches", children: "No rows match the current filter." })) : null, showPagination ? (_jsxs("div", { className: "schemacast-data-table-pagination", "data-testid": "data-table-pagination", children: [_jsxs("span", { children: ["Page ", currentPageIndex + 1, " of ", pageCount] }), _jsxs("div", { className: "schemacast-data-table-pagination-controls", children: [_jsx("button", { type: "button", className: "schemacast-data-table-pagination-button", "data-testid": "data-table-page-prev", disabled: !canGoPrev, onClick: () => {
|
|
71
|
+
setPageIndex(currentPageIndex - 1);
|
|
72
|
+
}, children: "Previous" }), _jsx("button", { type: "button", className: "schemacast-data-table-pagination-button", "data-testid": "data-table-page-next", disabled: !canGoNext, onClick: () => {
|
|
73
|
+
setPageIndex(currentPageIndex + 1);
|
|
74
|
+
}, children: "Next" })] })] })) : null] }));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=data-table-view.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldBindings, VisualSpec } from '@schemacast/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
export interface DetailCardViewProps {
|
|
4
|
+
readonly spec: VisualSpec;
|
|
5
|
+
readonly bindings: FieldBindings;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders a single-record `detail-card` from `VisualSpec.data[0]` and field bindings.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <DetailCardView spec={spec} bindings={spec.primaryView.bindings} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function DetailCardView({ spec, bindings }: DetailCardViewProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=detail-card-view.d.ts.map
|
|
@@ -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
|