derive-dashboards 0.1.1 → 0.2.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/README.md +5 -3
- package/dist/cli/add.mjs +130 -0
- package/dist/cli/cli.mjs +14 -12
- package/dist/cli/config.mjs +12 -1
- package/dist/cli/doctor.mjs +147 -0
- package/dist/cli/init.mjs +3 -2
- package/dist/cli/json.mjs +21 -0
- package/dist/cli/layers.mjs +33 -0
- package/dist/core/document/layout.mjs +1 -1
- package/dist/core/document/view-layout.d.mts +14 -0
- package/dist/core/document/view-layout.mjs +157 -0
- package/dist/core/engine/filter.mjs +2 -2
- package/dist/core/engine/leaf.mjs +9 -4
- package/dist/core/engine/members.mjs +1 -1
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +2 -1
- package/dist/core/error/codes.mjs +2 -1
- package/dist/core/index.d.mts +5 -3
- package/dist/core/index.mjs +5 -3
- package/dist/core/model/member.mjs +5 -2
- package/dist/core/model/types.d.mts +13 -13
- package/dist/core/model/validate/members.mjs +7 -4
- package/dist/core/policy/bind-query.d.mts +12 -0
- package/dist/core/policy/bind-query.mjs +53 -0
- package/dist/core/query/filter.d.mts +6 -0
- package/dist/core/query/picks.d.mts +8 -2
- package/dist/core/query/picks.mjs +11 -4
- package/dist/core/query/segments.mjs +2 -1
- package/dist/core/result/columns.mjs +6 -3
- package/dist/core/schema/aliases.d.mts +7 -0
- package/dist/core/schema/aliases.mjs +77 -0
- package/dist/core/schema/answers.d.mts +1 -0
- package/dist/core/schema/answers.mjs +1 -0
- package/dist/core/schema/index.d.mts +3 -2
- package/dist/core/schema/index.mjs +3 -2
- package/dist/core/schema/query.d.mts +81 -0
- package/dist/core/schema/query.mjs +9 -5
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/dashboards.mjs +4 -0
- package/dist/editing.mjs +2 -2
- package/dist/endpoints/dashboards.mjs +17 -2
- package/dist/endpoints/index.d.mts +12 -2
- package/dist/endpoints/meta.mjs +10 -1
- package/dist/execute.mjs +20 -11
- package/dist/handler.mjs +5 -1
- package/dist/llms.txt +22 -0
- package/dist/mcp/format.mjs +42 -8
- package/dist/mcp/query.mjs +34 -4
- package/dist/postgres-store.mjs +1 -0
- package/dist/react/Canvas.mjs +28 -5
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.mjs +15 -3
- package/dist/react/DashboardList.mjs +22 -22
- package/dist/react/DashboardListRow.mjs +49 -0
- package/dist/react/Discard.mjs +5 -2
- package/dist/react/Editing.mjs +19 -5
- package/dist/react/FilterBar.d.mts +7 -9
- package/dist/react/Grid.mjs +7 -19
- package/dist/react/Header.mjs +1 -1
- package/dist/react/History.mjs +5 -0
- package/dist/react/ReadFailed.mjs +23 -0
- package/dist/react/Spaces.mjs +15 -1
- package/dist/react/Tile.d.mts +2 -0
- package/dist/react/Tile.mjs +35 -7
- package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/react/arrange-steps.mjs +16 -13
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/Calcs.mjs +35 -11
- package/dist/react/builder/FilterEditor.mjs +196 -0
- package/dist/react/builder/Filters.mjs +172 -116
- package/dist/react/builder/Formula.mjs +82 -0
- package/dist/react/builder/Groups.mjs +1 -0
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/builder/RangeEditor.mjs +184 -0
- package/dist/react/builder/Sections.mjs +41 -6
- package/dist/react/builder/Time.mjs +138 -60
- package/dist/react/builder/Values.mjs +85 -0
- package/dist/react/builder/WidgetBuilder.mjs +50 -49
- package/dist/react/builder/base.d.mts +5 -0
- package/dist/react/builder/base.mjs +33 -8
- package/dist/react/builder/calc.mjs +15 -1
- package/dist/react/builder/escape.d.mts +1 -0
- package/dist/react/builder/escape.mjs +62 -0
- package/dist/react/builder/filter-tree.d.mts +9 -0
- package/dist/react/builder/filter-tree.mjs +186 -0
- package/dist/react/builder/formula-parse.d.mts +18 -0
- package/dist/react/builder/formula-parse.mjs +136 -0
- package/dist/react/builder/labels.d.mts +1 -1
- package/dist/react/builder/state.d.mts +2 -1
- package/dist/react/builder/state.mjs +23 -37
- package/dist/react/builder/useBuilder.d.mts +12 -1
- package/dist/react/builder/useBuilder.mjs +6 -3
- package/dist/react/builder/words.d.mts +59 -0
- package/dist/react/builder/words.mjs +73 -0
- package/dist/react/context.d.mts +13 -0
- package/dist/react/context.mjs +9 -3
- package/dist/react/drill/useDrill.d.mts +1 -1
- package/dist/react/drill/words.d.mts +3 -0
- package/dist/react/drill/words.mjs +2 -0
- package/dist/react/english.mjs +20 -5
- package/dist/react/filters/bar.d.mts +12 -0
- package/dist/react/filters/bar.mjs +135 -0
- package/dist/react/filters/calendar.mjs +193 -0
- package/dist/react/filters/chip.mjs +174 -0
- package/dist/react/filters/context.d.mts +22 -0
- package/dist/react/filters/context.mjs +78 -0
- package/dist/react/filters/dates.mjs +89 -0
- package/dist/react/filters/days.d.mts +36 -0
- package/dist/react/filters/days.mjs +87 -0
- package/dist/react/filters/field-step.mjs +81 -0
- package/dist/react/filters/hooks.d.mts +34 -0
- package/dist/react/filters/hooks.mjs +94 -0
- package/dist/react/filters/listbox.mjs +131 -0
- package/dist/react/filters/logic.d.mts +59 -0
- package/dist/react/filters/logic.mjs +109 -0
- package/dist/react/filters/menu-search.mjs +211 -0
- package/dist/react/filters/menu.mjs +85 -0
- package/dist/react/filters/number.mjs +127 -0
- package/dist/react/filters/numbers.d.mts +47 -0
- package/dist/react/filters/numbers.mjs +151 -0
- package/dist/react/filters/operator.mjs +104 -0
- package/dist/react/filters/phone.mjs +104 -0
- package/dist/react/filters/popover.d.mts +19 -0
- package/dist/react/filters/popover.mjs +153 -0
- package/dist/react/filters/rules.d.mts +8 -0
- package/dist/react/filters/rules.mjs +55 -0
- package/dist/react/filters/sheet.mjs +196 -0
- package/dist/react/filters/state.mjs +132 -0
- package/dist/react/filters/suggest.d.mts +47 -0
- package/dist/react/filters/suggest.mjs +97 -0
- package/dist/react/filters/values.mjs +166 -0
- package/dist/react/filters/words.d.mts +81 -0
- package/dist/react/filters/words.mjs +73 -0
- package/dist/react/format.mjs +11 -4
- package/dist/react/index.d.mts +11 -5
- package/dist/react/index.mjs +8 -4
- package/dist/react/messages.d.mts +34 -2
- package/dist/react/place.mjs +7 -3
- package/dist/react/renderers/index.mjs +65 -3
- package/dist/react/renderers/list.mjs +6 -6
- package/dist/react/series.d.mts +25 -8
- package/dist/react/series.mjs +135 -39
- package/dist/react/theme.css +930 -19
- package/dist/react/useBoard.d.mts +2 -0
- package/dist/react/useDashboard.d.mts +3 -0
- package/dist/react/useDashboard.mjs +6 -0
- package/dist/react/view-grid.mjs +16 -0
- package/dist/recharts/axes.mjs +28 -0
- package/dist/recharts/axis.mjs +84 -0
- package/dist/recharts/bar.d.mts +7 -0
- package/dist/recharts/bar.mjs +140 -0
- package/dist/recharts/charts.d.mts +4 -5
- package/dist/recharts/charts.mjs +2 -208
- package/dist/recharts/index.d.mts +3 -1
- package/dist/recharts/index.mjs +4 -1
- package/dist/recharts/line.d.mts +2 -0
- package/dist/recharts/line.mjs +111 -0
- package/dist/recharts/marks.mjs +47 -18
- package/dist/recharts/parts.mjs +88 -0
- package/dist/recharts/table.mjs +71 -0
- package/dist/records-read.mjs +1 -1
- package/dist/registry/filter-bar.json +26 -0
- package/dist/skills/derive-dashboards/SKILL.md +69 -0
- package/package.json +6 -2
- package/dist/react/FilterBar.mjs +0 -119
|
@@ -2,6 +2,7 @@ import { Moved } from "./review.mjs";
|
|
|
2
2
|
import { PanelName, Showing } from "./board.mjs";
|
|
3
3
|
import "./index.mjs";
|
|
4
4
|
import { Attempt, DraftStatus } from "./draft.mjs";
|
|
5
|
+
import { DashboardsError } from "./errors.mjs";
|
|
5
6
|
import { DrillHistory } from "./drill/state.mjs";
|
|
6
7
|
import { DashboardProps } from "./Dashboard.mjs";
|
|
7
8
|
import { JustPublished } from "./Notice.mjs";
|
|
@@ -79,6 +80,7 @@ export declare function useBoard(props: DashboardProps): {
|
|
|
79
80
|
waiting: boolean;
|
|
80
81
|
unpublished: boolean;
|
|
81
82
|
error: boolean;
|
|
83
|
+
failure: DashboardsError | undefined;
|
|
82
84
|
unreachable: boolean;
|
|
83
85
|
missing: boolean;
|
|
84
86
|
doc: import("derive-dashboards/core").Doc | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Attempt, DraftClosed, DraftStatus } from "./draft.mjs";
|
|
2
|
+
import { DashboardsError } from "./errors.mjs";
|
|
2
3
|
import { PublishResponse } from "derive-dashboards/core";
|
|
3
4
|
/**
|
|
4
5
|
* The dashboard as stored, and the viewer's draft of it once they start editing. The viewer's
|
|
@@ -45,6 +46,8 @@ export declare function useDashboard(id: string, events: DashboardEvents, editab
|
|
|
45
46
|
/** Made by this viewer and never published: discarding its draft deletes it. */
|
|
46
47
|
unpublished: boolean;
|
|
47
48
|
error: boolean;
|
|
49
|
+
/** Why it failed, when the handler said: its code and message, for whoever can act on it. */
|
|
50
|
+
failure: DashboardsError | undefined;
|
|
48
51
|
unreachable: boolean;
|
|
49
52
|
/** The dashboard is not there for this viewer: not published yet, removed, or not theirs. */
|
|
50
53
|
missing: boolean;
|
|
@@ -29,6 +29,10 @@ function rights(data, editable) {
|
|
|
29
29
|
unpublished: data?.unpublished === true
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
/** Why a read failed with nothing to show, when the handler said: its code and message. */
|
|
33
|
+
function failureOf(loaded) {
|
|
34
|
+
return loaded.data === void 0 && loaded.error instanceof DashboardsError ? loaded.error : void 0;
|
|
35
|
+
}
|
|
32
36
|
function useDashboard(id, events, editable, onClosed) {
|
|
33
37
|
const { client } = useDashboards();
|
|
34
38
|
const { mutate } = useSWRConfig();
|
|
@@ -45,6 +49,8 @@ function useDashboard(id, events, editable, onClosed) {
|
|
|
45
49
|
useOpenOnce(editable && loaded.data?.unpublished === true, edit.start);
|
|
46
50
|
return {
|
|
47
51
|
error: loaded.error !== void 0 && loaded.data === void 0,
|
|
52
|
+
/** Why it failed, when the handler said: its code and message, for whoever can act on it. */
|
|
53
|
+
failure: failureOf(loaded),
|
|
48
54
|
unreachable: loaded.error !== void 0 && loaded.data !== void 0,
|
|
49
55
|
/** The dashboard is not there for this viewer: not published yet, removed, or not theirs. */
|
|
50
56
|
missing: loaded.error instanceof DashboardsError && loaded.error.code === "NOT_FOUND",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { sharedSpan } from "./Tile.mjs";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { viewLayout } from "derive-dashboards/core";
|
|
4
|
+
// src/view-grid.ts
|
|
5
|
+
/**
|
|
6
|
+
* The grid as a viewer sees it. The layout holds only the tiles there are widgets for, each at
|
|
7
|
+
* least the size its kind reads at, with no holes and every row full (core's `viewLayout`); an
|
|
8
|
+
* editor arranges the layout as saved. The span most tiles cover is said once, not per tile.
|
|
9
|
+
*/
|
|
10
|
+
function useViewGrid(layout, widgets, results) {
|
|
11
|
+
return {
|
|
12
|
+
layout: useMemo(() => viewLayout(layout.filter((item) => widgets[item.widget] !== void 0), (widget) => widgets[widget]?.kind), [layout, widgets]),
|
|
13
|
+
sharedSpan: useMemo(() => sharedSpan(results), [results])
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export { useViewGrid };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { yAxis } from "./axis.mjs";
|
|
2
|
+
import { YAxis } from "recharts";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/axes.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The value axes: the first unit on the left; a second unit, when the chart has one, on the
|
|
7
|
+
* right, so dollars and counts are never read on one scale.
|
|
8
|
+
*/
|
|
9
|
+
function yAxes(drawn, locale) {
|
|
10
|
+
return ["left", "right"].filter((side) => drawn.series.some((s) => s.axis === side)).map((side) => /* @__PURE__ */ jsx(YAxis, {
|
|
11
|
+
yAxisId: side,
|
|
12
|
+
orientation: side,
|
|
13
|
+
tickLine: false,
|
|
14
|
+
axisLine: false,
|
|
15
|
+
stroke: "var(--dd-muted)",
|
|
16
|
+
width: 56,
|
|
17
|
+
...yAxis(drawn.series.filter((s) => s.axis === side), drawn.points, locale)
|
|
18
|
+
}, side));
|
|
19
|
+
}
|
|
20
|
+
/** The values a chart leaves to the table (a third unit, or more than a split draws), named. */
|
|
21
|
+
function NotDrawn({ drawn, props }) {
|
|
22
|
+
if (drawn.notDrawn.length === 0) return null;
|
|
23
|
+
return /* @__PURE__ */ jsx("p", {
|
|
24
|
+
className: "dd-chart-note",
|
|
25
|
+
children: props.messages.notDrawn(drawn.notDrawn.map((c) => c.label))
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export { NotDrawn, yAxes };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { formatTick } from "derive-dashboards/react";
|
|
2
|
+
// src/axis.ts
|
|
3
|
+
/**
|
|
4
|
+
* A percent axis's ticks: from 0 up past the data in a step a person reads (5%, 10%, 25%...),
|
|
5
|
+
* so it reads 0, 10, 20, 30% and never 6.5%. All zero reaches 100%, not 400% of nothing.
|
|
6
|
+
*/
|
|
7
|
+
function percentTicks(max, full) {
|
|
8
|
+
const top = max > 0 ? max : full;
|
|
9
|
+
const step = [
|
|
10
|
+
.05,
|
|
11
|
+
.1,
|
|
12
|
+
.2,
|
|
13
|
+
.25,
|
|
14
|
+
.5,
|
|
15
|
+
1
|
|
16
|
+
].map((s) => s * full).find((s) => top / s <= 5) ?? full;
|
|
17
|
+
const count = Math.ceil(top / step - 1e-9);
|
|
18
|
+
return Array.from({ length: count + 1 }, (_v, i) => Number((i * step).toFixed(6)));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A value axis's ticks: from 0 up past the data in a step a person reads (1, 2, 2.5 or 5 times
|
|
22
|
+
* a power of ten), four or five steps, so it reads 0, 50, 100, 150 and never 35, 70, 105. A
|
|
23
|
+
* count steps in whole numbers only.
|
|
24
|
+
*/
|
|
25
|
+
function niceTicks(max, whole) {
|
|
26
|
+
if (!(max > 0)) return [0, 1];
|
|
27
|
+
const rough = max / 4;
|
|
28
|
+
const power = 10 ** Math.floor(Math.log10(rough));
|
|
29
|
+
const step = [
|
|
30
|
+
1,
|
|
31
|
+
2,
|
|
32
|
+
2.5,
|
|
33
|
+
5,
|
|
34
|
+
10
|
|
35
|
+
].map((m) => m * power).filter((s) => !whole || Number.isInteger(s)).find((s) => max / s <= 5) ?? Math.max(1, Math.ceil(rough));
|
|
36
|
+
const count = Math.ceil(max / step - 1e-9);
|
|
37
|
+
return Array.from({ length: count + 1 }, (_v, i) => Number((i * step).toPrecision(12)));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A value axis that reads at a glance: counts tick in whole numbers (no 2.5 tasks), percents on
|
|
41
|
+
* round steps of the whole, anything else on round steps from 0; a stacked chart reaches its
|
|
42
|
+
* tallest stack. Data below zero keeps the kit's own ticks, which reach both ways.
|
|
43
|
+
*/
|
|
44
|
+
function yAxis(series, points, locale, stacked = false) {
|
|
45
|
+
const { whole, percentOf } = shapeOf(series[0]?.column);
|
|
46
|
+
const values = points.flatMap((p) => series.map((s) => p[s.key]).filter((v) => typeof v === "number"));
|
|
47
|
+
const top = Math.max(0, ...stacked ? stackedTops(series, points) : [], ...values);
|
|
48
|
+
const ticks = values.some((v) => v < 0) ? void 0 : ticksFor(top, percentOf, whole);
|
|
49
|
+
return {
|
|
50
|
+
allowDecimals: !whole,
|
|
51
|
+
interval: 0,
|
|
52
|
+
tickFormatter: axisFormat(series, locale),
|
|
53
|
+
...ticks === void 0 ? {} : {
|
|
54
|
+
ticks,
|
|
55
|
+
domain: [0, ticks.at(-1) ?? 1]
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** What an axis reads of its column: whole counts, and a percent's whole (1 or 100). */
|
|
60
|
+
function shapeOf(column) {
|
|
61
|
+
if (column === void 0) return {
|
|
62
|
+
whole: false,
|
|
63
|
+
percentOf: void 0
|
|
64
|
+
};
|
|
65
|
+
const percentOf = column.format === "percent" ? column.fraction === true ? 1 : 100 : void 0;
|
|
66
|
+
return {
|
|
67
|
+
whole: column.type === "int",
|
|
68
|
+
percentOf
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** A percent axis ticks on steps of its whole; any other on round steps from 0. */
|
|
72
|
+
const ticksFor = (top, percentOf, whole) => percentOf === void 0 ? niceTicks(top, whole) : percentTicks(top, percentOf);
|
|
73
|
+
/** Each point's total over its series: a stacked bar reaches its sum, not its tallest part. */
|
|
74
|
+
function stackedTops(series, points) {
|
|
75
|
+
return points.map((p) => series.reduce((sum, s) => {
|
|
76
|
+
const v = p[s.key];
|
|
77
|
+
return typeof v === "number" && v > 0 ? sum + v : sum;
|
|
78
|
+
}, 0));
|
|
79
|
+
}
|
|
80
|
+
function axisFormat(series, locale) {
|
|
81
|
+
const column = series[0]?.column;
|
|
82
|
+
return (value) => formatTick(value, column, locale);
|
|
83
|
+
}
|
|
84
|
+
export { niceTicks, percentTicks, yAxis };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TileRendererProps } from "derive-dashboards/react";
|
|
2
|
+
/**
|
|
3
|
+
* Bars per x value; when a second field splits them, its values stack, Other on top. Bars over
|
|
4
|
+
* time stand up, the bucket still running drawn faint; bars by category lie down, so every
|
|
5
|
+
* name has room to be read and none is skipped.
|
|
6
|
+
*/
|
|
7
|
+
export declare function BarTile(props: TileRendererProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { yAxis } from "./axis.mjs";
|
|
2
|
+
import { openPoint } from "./marks.mjs";
|
|
3
|
+
import { CHART, TOOLTIP, color, legendText, runningLabel, tooltipFormat, tooltipLabel } from "./parts.mjs";
|
|
4
|
+
import { toSeries } from "./series.mjs";
|
|
5
|
+
import { Beside } from "./table.mjs";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { Bar, BarChart, CartesianGrid, Legend, Rectangle, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/bar.tsx
|
|
10
|
+
/** Category labels are cut to this many characters, with the whole name in the tooltip. */
|
|
11
|
+
const LABEL = 24;
|
|
12
|
+
const cut = (label) => {
|
|
13
|
+
const text = String(label);
|
|
14
|
+
return text.length > LABEL ? `${text.slice(0, 23)}…` : text;
|
|
15
|
+
};
|
|
16
|
+
/** Room for the longest category label, in pixels, between a floor and a ceiling. */
|
|
17
|
+
const labelWidth = (points) => Math.min(180, Math.max(48, 12 + 7 * Math.max(0, ...points.map((p) => cut(p.x).length))));
|
|
18
|
+
/** A click on a bar opens the row behind it, with its series' line. */
|
|
19
|
+
const barClick = (drill, drawn, s) => drill === void 0 ? {} : { onClick: (_bar, point) => {
|
|
20
|
+
openPoint(drill, drawn, {
|
|
21
|
+
point,
|
|
22
|
+
series: s
|
|
23
|
+
});
|
|
24
|
+
} };
|
|
25
|
+
/** A bar's shape: outlined when the keyboard is on it, faint when its bucket is still running. */
|
|
26
|
+
const barShape = (focused, key, running) => (props) => /* @__PURE__ */ jsx(Rectangle, {
|
|
27
|
+
...props,
|
|
28
|
+
...props.index === running ? { fillOpacity: .45 } : {},
|
|
29
|
+
...focused?.key === key && focused.point === props.index ? {
|
|
30
|
+
className: "dd-chart-focus",
|
|
31
|
+
stroke: "var(--dd-ink)",
|
|
32
|
+
strokeWidth: 2
|
|
33
|
+
} : {}
|
|
34
|
+
});
|
|
35
|
+
/** Round ends on the bar's outer end only: its top standing up, its right end lying down. */
|
|
36
|
+
const barRadius = (inner, upright) => inner ? 0 : upright ? [
|
|
37
|
+
4,
|
|
38
|
+
4,
|
|
39
|
+
0,
|
|
40
|
+
0
|
|
41
|
+
] : [
|
|
42
|
+
0,
|
|
43
|
+
4,
|
|
44
|
+
4,
|
|
45
|
+
0
|
|
46
|
+
];
|
|
47
|
+
const AXIS = {
|
|
48
|
+
tickLine: false,
|
|
49
|
+
axisLine: false,
|
|
50
|
+
stroke: "var(--dd-muted)"
|
|
51
|
+
};
|
|
52
|
+
/** Bars over time: time along the bottom, values up the side. By category: names down the side. */
|
|
53
|
+
function barAxes(overTime, values, points) {
|
|
54
|
+
return overTime ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(XAxis, {
|
|
55
|
+
dataKey: "x",
|
|
56
|
+
...AXIS,
|
|
57
|
+
interval: "preserveStartEnd",
|
|
58
|
+
minTickGap: 12
|
|
59
|
+
}), /* @__PURE__ */ jsx(YAxis, {
|
|
60
|
+
...AXIS,
|
|
61
|
+
width: 56,
|
|
62
|
+
...values
|
|
63
|
+
})] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(XAxis, {
|
|
64
|
+
type: "number",
|
|
65
|
+
...AXIS,
|
|
66
|
+
...values
|
|
67
|
+
}), /* @__PURE__ */ jsx(YAxis, {
|
|
68
|
+
type: "category",
|
|
69
|
+
dataKey: "x",
|
|
70
|
+
...AXIS,
|
|
71
|
+
interval: 0,
|
|
72
|
+
width: labelWidth(points),
|
|
73
|
+
tickFormatter: cut
|
|
74
|
+
})] });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Bars per x value; when a second field splits them, its values stack, Other on top. Bars over
|
|
78
|
+
* time stand up, the bucket still running drawn faint; bars by category lie down, so every
|
|
79
|
+
* name has room to be read and none is skipped.
|
|
80
|
+
*/
|
|
81
|
+
function BarTile(props) {
|
|
82
|
+
const { answer, locale, drill } = props;
|
|
83
|
+
const [focused, setFocused] = useState(null);
|
|
84
|
+
const drawn = toSeries(answer, props);
|
|
85
|
+
const { points, series, split } = drawn;
|
|
86
|
+
const overTime = answer.columns[0]?.type === "time" || answer.columns[0]?.grain !== void 0;
|
|
87
|
+
const running = overTime ? runningLabel(props, points) : void 0;
|
|
88
|
+
const values = yAxis(series, points, locale, split);
|
|
89
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
90
|
+
className: "dd-chart",
|
|
91
|
+
"data-drillable": drill !== void 0,
|
|
92
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
93
|
+
className: "dd-chart-picture",
|
|
94
|
+
"aria-hidden": "true",
|
|
95
|
+
children: /* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(BarChart, {
|
|
96
|
+
...CHART,
|
|
97
|
+
data: points,
|
|
98
|
+
maxBarSize: overTime ? 56 : 28,
|
|
99
|
+
layout: overTime ? "horizontal" : "vertical",
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
102
|
+
stroke: "var(--dd-line)",
|
|
103
|
+
vertical: !overTime,
|
|
104
|
+
horizontal: overTime
|
|
105
|
+
}),
|
|
106
|
+
barAxes(overTime, values, points),
|
|
107
|
+
/* @__PURE__ */ jsx(Tooltip, {
|
|
108
|
+
...TOOLTIP,
|
|
109
|
+
formatter: tooltipFormat(props, drawn),
|
|
110
|
+
labelFormatter: tooltipLabel(props, running)
|
|
111
|
+
}),
|
|
112
|
+
series.length > 1 ? /* @__PURE__ */ jsx(Legend, {
|
|
113
|
+
itemSorter: null,
|
|
114
|
+
formatter: legendText
|
|
115
|
+
}) : null,
|
|
116
|
+
series.map((s, i) => /* @__PURE__ */ jsx(Bar, {
|
|
117
|
+
dataKey: s.key,
|
|
118
|
+
name: s.label,
|
|
119
|
+
fill: color(props, s, i),
|
|
120
|
+
...split ? {
|
|
121
|
+
stackId: "split",
|
|
122
|
+
stroke: "var(--dd-surface)",
|
|
123
|
+
strokeWidth: 2
|
|
124
|
+
} : {},
|
|
125
|
+
radius: barRadius(split && i < series.length - 1, overTime),
|
|
126
|
+
isAnimationActive: false,
|
|
127
|
+
...barClick(drill, drawn, s),
|
|
128
|
+
shape: barShape(focused, s.key, running === void 0 ? -1 : points.length - 1)
|
|
129
|
+
}, s.key))
|
|
130
|
+
]
|
|
131
|
+
}) })
|
|
132
|
+
}), /* @__PURE__ */ jsx(Beside, {
|
|
133
|
+
drawn,
|
|
134
|
+
props,
|
|
135
|
+
kind: "bar",
|
|
136
|
+
onFocusMark: setFocused
|
|
137
|
+
})]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
export { BarTile };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/** Bars per x value; when a second field splits them, its values stack, Other on top. */
|
|
4
|
-
export declare function BarTile(props: TileRendererProps): import("react").JSX.Element;
|
|
1
|
+
import { BarTile } from "./bar.mjs";
|
|
2
|
+
import { LineTile } from "./line.mjs";
|
|
5
3
|
/** Register with `<DashboardsProvider renderers={RECHARTS_RENDERERS}>`. */
|
|
6
4
|
export declare const RECHARTS_RENDERERS: {
|
|
7
5
|
line: typeof LineTile;
|
|
8
6
|
bar: typeof BarTile;
|
|
9
|
-
};
|
|
7
|
+
};
|
|
8
|
+
export { BarTile, LineTile };
|
package/dist/recharts/charts.mjs
CHANGED
|
@@ -1,212 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { formatCell, formatTick } from "derive-dashboards/react";
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
import { Bar, BarChart, CartesianGrid, Legend, Line, LineChart, Rectangle, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { BarTile } from "./bar.mjs";
|
|
2
|
+
import { LineTile } from "./line.mjs";
|
|
7
3
|
// src/charts.tsx
|
|
8
|
-
/** A series' colour: the palette in order, and Other always the quiet grey. */
|
|
9
|
-
/** Legend words in the text color: a series' hue marks its swatch, never its name. */
|
|
10
|
-
const legendText = (value) => /* @__PURE__ */ jsx("span", {
|
|
11
|
-
className: "dd-chart-legend",
|
|
12
|
-
children: value
|
|
13
|
-
});
|
|
14
|
-
/** A widget's own colors by series label (`display.colors`), else the palette in order. */
|
|
15
|
-
const colorsOf = (props) => {
|
|
16
|
-
const colors = props.widget.display?.["colors"];
|
|
17
|
-
return typeof colors === "object" && colors !== null ? new Map(Object.entries(colors)) : /* @__PURE__ */ new Map();
|
|
18
|
-
};
|
|
19
|
-
const color = (props, s, i) => {
|
|
20
|
-
const own = colorsOf(props).get(s.label);
|
|
21
|
-
if (typeof own === "string") return own;
|
|
22
|
-
return s.key === OTHER_KEY ? "var(--dd-other)" : `var(--dd-series-${i % 6 + 1})`;
|
|
23
|
-
};
|
|
24
|
-
function axisFormat(series, locale) {
|
|
25
|
-
const column = series[0]?.column;
|
|
26
|
-
return (value) => formatTick(value, column, locale);
|
|
27
|
-
}
|
|
28
|
-
function tooltipFormat(series, format) {
|
|
29
|
-
const column = series[0]?.column;
|
|
30
|
-
return (value) => typeof value === "number" ? formatCell(value, column, format) : String(value);
|
|
31
|
-
}
|
|
32
|
-
/** A tooltip's title, with what a click does when the chart drills. */
|
|
33
|
-
const tooltipLabel = (props) => (label) => props.drill === void 0 ? String(label) : `${String(label)} · ${props.messages.drillHint}`;
|
|
34
|
-
/** A click on a bar opens the row behind it, with its series' line. */
|
|
35
|
-
const barClick = (drill, drawn, s) => drill === void 0 ? {} : { onClick: (_bar, point) => {
|
|
36
|
-
openPoint(drill, drawn, {
|
|
37
|
-
point,
|
|
38
|
-
series: s
|
|
39
|
-
});
|
|
40
|
-
} };
|
|
41
|
-
/** A bar's shape: outlined when the keyboard is on it. */
|
|
42
|
-
const barShape = (focused, key) => (props) => /* @__PURE__ */ jsx(Rectangle, {
|
|
43
|
-
...props,
|
|
44
|
-
...focused?.key === key && focused.point === props.index ? {
|
|
45
|
-
className: "dd-chart-focus",
|
|
46
|
-
stroke: "var(--dd-ink)",
|
|
47
|
-
strokeWidth: 2
|
|
48
|
-
} : {}
|
|
49
|
-
});
|
|
50
|
-
/** A line's dots: only the one the keyboard is on, ringed. */
|
|
51
|
-
const lineDot = (focused, key) => focused?.key === key ? (dot) => dot.index === focused.point ? /* @__PURE__ */ jsx("circle", {
|
|
52
|
-
className: "dd-chart-focus",
|
|
53
|
-
cx: dot.cx,
|
|
54
|
-
cy: dot.cy,
|
|
55
|
-
r: 5
|
|
56
|
-
}, dot.index) : /* @__PURE__ */ jsx("g", {}, dot.index) : false;
|
|
57
|
-
/** A click on a single line opens the point under it; with several, each opens from its own list. */
|
|
58
|
-
function lineClick(drill, drawn) {
|
|
59
|
-
const [only] = drawn.series;
|
|
60
|
-
return (state) => {
|
|
61
|
-
const point = Number(state.activeTooltipIndex);
|
|
62
|
-
if (only !== void 0 && drawn.series.length === 1 && Number.isInteger(point)) openPoint(drill, drawn, {
|
|
63
|
-
point,
|
|
64
|
-
series: only
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/** A line per series over the x axis, usually time buckets. */
|
|
69
|
-
/**
|
|
70
|
-
* What every chart is drawn with: the marks list is the keyboard path, so the chart itself is
|
|
71
|
-
* not a second, empty tab stop (Recharts' own layer).
|
|
72
|
-
*/
|
|
73
|
-
const CHART = {
|
|
74
|
-
accessibilityLayer: false,
|
|
75
|
-
margin: {
|
|
76
|
-
top: 4,
|
|
77
|
-
right: 8,
|
|
78
|
-
bottom: 0,
|
|
79
|
-
left: 0
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
function LineTile(props) {
|
|
83
|
-
const { answer, locale, drill } = props;
|
|
84
|
-
const [focused, setFocused] = useState(null);
|
|
85
|
-
const drawn = toSeries(answer, props);
|
|
86
|
-
const { points, series } = drawn;
|
|
87
|
-
const onClick = lineClick(drill, drawn);
|
|
88
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
89
|
-
className: "dd-chart",
|
|
90
|
-
"data-drillable": drill !== void 0,
|
|
91
|
-
children: [/* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(LineChart, {
|
|
92
|
-
...CHART,
|
|
93
|
-
data: points,
|
|
94
|
-
...drill === void 0 ? {} : { onClick },
|
|
95
|
-
children: [
|
|
96
|
-
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
97
|
-
stroke: "var(--dd-line)",
|
|
98
|
-
vertical: false
|
|
99
|
-
}),
|
|
100
|
-
/* @__PURE__ */ jsx(XAxis, {
|
|
101
|
-
dataKey: "x",
|
|
102
|
-
tickLine: false,
|
|
103
|
-
axisLine: false,
|
|
104
|
-
stroke: "var(--dd-muted)",
|
|
105
|
-
minTickGap: 16
|
|
106
|
-
}),
|
|
107
|
-
/* @__PURE__ */ jsx(YAxis, {
|
|
108
|
-
tickLine: false,
|
|
109
|
-
axisLine: false,
|
|
110
|
-
stroke: "var(--dd-muted)",
|
|
111
|
-
width: 56,
|
|
112
|
-
tickFormatter: axisFormat(series, locale)
|
|
113
|
-
}),
|
|
114
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
115
|
-
separator: ": ",
|
|
116
|
-
formatter: tooltipFormat(series, props),
|
|
117
|
-
labelFormatter: tooltipLabel(props)
|
|
118
|
-
}),
|
|
119
|
-
series.length > 1 ? /* @__PURE__ */ jsx(Legend, {
|
|
120
|
-
itemSorter: null,
|
|
121
|
-
formatter: legendText
|
|
122
|
-
}) : null,
|
|
123
|
-
series.map((s, i) => /* @__PURE__ */ jsx(Line, {
|
|
124
|
-
dataKey: s.key,
|
|
125
|
-
name: s.label,
|
|
126
|
-
stroke: color(props, s, i),
|
|
127
|
-
strokeWidth: 2,
|
|
128
|
-
dot: lineDot(focused, s.key),
|
|
129
|
-
isAnimationActive: false
|
|
130
|
-
}, s.key))
|
|
131
|
-
]
|
|
132
|
-
}) }), /* @__PURE__ */ jsx(Marks, {
|
|
133
|
-
drill,
|
|
134
|
-
drawn,
|
|
135
|
-
rows: answer.rows.length,
|
|
136
|
-
onFocusMark: setFocused
|
|
137
|
-
})]
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/** Bars per x value; when a second field splits them, its values stack, Other on top. */
|
|
141
|
-
function BarTile(props) {
|
|
142
|
-
const { answer, locale, drill } = props;
|
|
143
|
-
const [focused, setFocused] = useState(null);
|
|
144
|
-
const drawn = toSeries(answer, props);
|
|
145
|
-
const { points, series, split } = drawn;
|
|
146
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
147
|
-
className: "dd-chart",
|
|
148
|
-
"data-drillable": drill !== void 0,
|
|
149
|
-
children: [/* @__PURE__ */ jsx(ResponsiveContainer, { children: /* @__PURE__ */ jsxs(BarChart, {
|
|
150
|
-
...CHART,
|
|
151
|
-
data: points,
|
|
152
|
-
maxBarSize: 56,
|
|
153
|
-
children: [
|
|
154
|
-
/* @__PURE__ */ jsx(CartesianGrid, {
|
|
155
|
-
stroke: "var(--dd-line)",
|
|
156
|
-
vertical: false
|
|
157
|
-
}),
|
|
158
|
-
/* @__PURE__ */ jsx(XAxis, {
|
|
159
|
-
dataKey: "x",
|
|
160
|
-
tickLine: false,
|
|
161
|
-
axisLine: false,
|
|
162
|
-
stroke: "var(--dd-muted)",
|
|
163
|
-
interval: "preserveStartEnd",
|
|
164
|
-
minTickGap: 12
|
|
165
|
-
}),
|
|
166
|
-
/* @__PURE__ */ jsx(YAxis, {
|
|
167
|
-
tickLine: false,
|
|
168
|
-
axisLine: false,
|
|
169
|
-
stroke: "var(--dd-muted)",
|
|
170
|
-
width: 56,
|
|
171
|
-
tickFormatter: axisFormat(series, locale)
|
|
172
|
-
}),
|
|
173
|
-
/* @__PURE__ */ jsx(Tooltip, {
|
|
174
|
-
separator: ": ",
|
|
175
|
-
formatter: tooltipFormat(series, props),
|
|
176
|
-
labelFormatter: tooltipLabel(props)
|
|
177
|
-
}),
|
|
178
|
-
series.length > 1 ? /* @__PURE__ */ jsx(Legend, {
|
|
179
|
-
itemSorter: null,
|
|
180
|
-
formatter: legendText
|
|
181
|
-
}) : null,
|
|
182
|
-
series.map((s, i) => /* @__PURE__ */ jsx(Bar, {
|
|
183
|
-
dataKey: s.key,
|
|
184
|
-
name: s.label,
|
|
185
|
-
fill: color(props, s, i),
|
|
186
|
-
...split ? {
|
|
187
|
-
stackId: "split",
|
|
188
|
-
stroke: "var(--dd-surface)",
|
|
189
|
-
strokeWidth: 2
|
|
190
|
-
} : {},
|
|
191
|
-
radius: split && i < series.length - 1 ? 0 : [
|
|
192
|
-
4,
|
|
193
|
-
4,
|
|
194
|
-
0,
|
|
195
|
-
0
|
|
196
|
-
],
|
|
197
|
-
isAnimationActive: false,
|
|
198
|
-
...barClick(drill, drawn, s),
|
|
199
|
-
shape: barShape(focused, s.key)
|
|
200
|
-
}, s.key))
|
|
201
|
-
]
|
|
202
|
-
}) }), /* @__PURE__ */ jsx(Marks, {
|
|
203
|
-
drill,
|
|
204
|
-
drawn,
|
|
205
|
-
rows: answer.rows.length,
|
|
206
|
-
onFocusMark: setFocused
|
|
207
|
-
})]
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
4
|
/** Register with `<DashboardsProvider renderers={RECHARTS_RENDERERS}>`. */
|
|
211
5
|
const RECHARTS_RENDERERS = {
|
|
212
6
|
line: LineTile,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { BarTile
|
|
1
|
+
import { BarTile } from "./bar.mjs";
|
|
2
|
+
import { LineTile } from "./line.mjs";
|
|
3
|
+
import { RECHARTS_RENDERERS } from "./charts.mjs";
|
|
2
4
|
import { Drawn, Point, Series, rowAt, toSeries } from "./series.mjs";
|
|
3
5
|
export { BarTile, type Drawn, LineTile, type Point, RECHARTS_RENDERERS, type Series, rowAt, toSeries };
|
package/dist/recharts/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { RECHARTS_RENDERERS } from "./charts.mjs";
|
|
3
|
+
import { BarTile } from "./bar.mjs";
|
|
4
|
+
import { LineTile } from "./line.mjs";
|
|
2
5
|
import { rowAt, toSeries } from "./series.mjs";
|
|
3
6
|
export { BarTile, LineTile, RECHARTS_RENDERERS, rowAt, toSeries };
|