derive-dashboards 0.5.1 → 0.7.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 +4 -2
- package/dist/body.mjs +2 -2
- package/dist/charts/data/buckets.d.mts +11 -0
- package/dist/charts/data/buckets.mjs +66 -0
- package/dist/charts/data/clean.mjs +55 -0
- package/dist/charts/data/format.d.mts +19 -0
- package/dist/charts/data/format.mjs +174 -0
- package/dist/charts/data/input-error.d.mts +5 -0
- package/dist/charts/data/input-error.mjs +11 -0
- package/dist/charts/data/range.mjs +14 -0
- package/dist/charts/data/rows.d.mts +13 -0
- package/dist/charts/data/rows.mjs +31 -0
- package/dist/charts/data/shares.mjs +55 -0
- package/dist/charts/data/types.d.mts +106 -0
- package/dist/charts/data/words.d.mts +44 -0
- package/dist/charts/data/words.mjs +31 -0
- package/dist/charts/describe.mjs +110 -0
- package/dist/charts/index.d.mts +34 -0
- package/dist/charts/index.mjs +24 -0
- package/dist/charts/kinds/area-marks.mjs +120 -0
- package/dist/charts/kinds/area.d.mts +23 -0
- package/dist/charts/kinds/area.mjs +71 -0
- package/dist/charts/kinds/bars-data.d.mts +11 -0
- package/dist/charts/kinds/bars-data.mjs +30 -0
- package/dist/charts/kinds/bars-layout.mjs +30 -0
- package/dist/charts/kinds/bars-marks.mjs +93 -0
- package/dist/charts/kinds/bars-words.mjs +56 -0
- package/dist/charts/kinds/bars.d.mts +17 -0
- package/dist/charts/kinds/bars.mjs +68 -0
- package/dist/charts/kinds/columns-data.mjs +116 -0
- package/dist/charts/kinds/columns-layout.mjs +29 -0
- package/dist/charts/kinds/columns-marks.mjs +200 -0
- package/dist/charts/kinds/columns-words.mjs +26 -0
- package/dist/charts/kinds/columns.d.mts +13 -0
- package/dist/charts/kinds/columns.mjs +80 -0
- package/dist/charts/kinds/dumbbell-data.d.mts +22 -0
- package/dist/charts/kinds/dumbbell-data.mjs +59 -0
- package/dist/charts/kinds/dumbbell-layout.mjs +113 -0
- package/dist/charts/kinds/dumbbell-marks.mjs +119 -0
- package/dist/charts/kinds/dumbbell-words.d.mts +7 -0
- package/dist/charts/kinds/dumbbell-words.mjs +94 -0
- package/dist/charts/kinds/dumbbell.d.mts +14 -0
- package/dist/charts/kinds/dumbbell.mjs +67 -0
- package/dist/charts/kinds/funnel-data.d.mts +11 -0
- package/dist/charts/kinds/funnel-data.mjs +70 -0
- package/dist/charts/kinds/funnel-layout.mjs +32 -0
- package/dist/charts/kinds/funnel-marks.mjs +204 -0
- package/dist/charts/kinds/funnel-words.mjs +77 -0
- package/dist/charts/kinds/funnel.d.mts +11 -0
- package/dist/charts/kinds/funnel.mjs +75 -0
- package/dist/charts/kinds/grid-data.d.mts +18 -0
- package/dist/charts/kinds/grid-data.mjs +35 -0
- package/dist/charts/kinds/grid-layout.mjs +77 -0
- package/dist/charts/kinds/grid-marks.mjs +140 -0
- package/dist/charts/kinds/grid-time.mjs +41 -0
- package/dist/charts/kinds/grid-words.mjs +86 -0
- package/dist/charts/kinds/grid.d.mts +22 -0
- package/dist/charts/kinds/grid.mjs +55 -0
- package/dist/charts/kinds/histogram-data.mjs +142 -0
- package/dist/charts/kinds/histogram-layout.mjs +144 -0
- package/dist/charts/kinds/histogram-marks.mjs +110 -0
- package/dist/charts/kinds/histogram-words.mjs +104 -0
- package/dist/charts/kinds/histogram.d.mts +15 -0
- package/dist/charts/kinds/histogram.mjs +47 -0
- package/dist/charts/kinds/line-marks.mjs +36 -0
- package/dist/charts/kinds/line.d.mts +17 -0
- package/dist/charts/kinds/line.mjs +52 -0
- package/dist/charts/kinds/multiples-grid.mjs +107 -0
- package/dist/charts/kinds/multiples-head.mjs +44 -0
- package/dist/charts/kinds/multiples-layout.mjs +159 -0
- package/dist/charts/kinds/multiples-marks.mjs +95 -0
- package/dist/charts/kinds/multiples-words.mjs +110 -0
- package/dist/charts/kinds/multiples.d.mts +26 -0
- package/dist/charts/kinds/multiples.mjs +42 -0
- package/dist/charts/kinds/row-chart.mjs +112 -0
- package/dist/charts/kinds/row-marks.mjs +121 -0
- package/dist/charts/kinds/scatter-data.d.mts +18 -0
- package/dist/charts/kinds/scatter-data.mjs +123 -0
- package/dist/charts/kinds/scatter-layout.mjs +189 -0
- package/dist/charts/kinds/scatter-marks.mjs +149 -0
- package/dist/charts/kinds/scatter-words.mjs +80 -0
- package/dist/charts/kinds/scatter.d.mts +21 -0
- package/dist/charts/kinds/scatter.mjs +72 -0
- package/dist/charts/kinds/stat-data.mjs +91 -0
- package/dist/charts/kinds/stat-layout.mjs +108 -0
- package/dist/charts/kinds/stat-marks.mjs +85 -0
- package/dist/charts/kinds/stat-words.mjs +57 -0
- package/dist/charts/kinds/stat.d.mts +28 -0
- package/dist/charts/kinds/stat.mjs +35 -0
- package/dist/charts/kinds/time-chart.mjs +74 -0
- package/dist/charts/kinds/time-frame.mjs +113 -0
- package/dist/charts/kinds/time-notes.mjs +36 -0
- package/dist/charts/kinds/time-plan.d.mts +8 -0
- package/dist/charts/kinds/time-plan.mjs +57 -0
- package/dist/charts/kinds/time-plot.mjs +56 -0
- package/dist/charts/kinds/time-stops.mjs +56 -0
- package/dist/charts/kinds/value-plot.mjs +33 -0
- package/dist/charts/kinds/waterfall-data.d.mts +7 -0
- package/dist/charts/kinds/waterfall-data.mjs +71 -0
- package/dist/charts/kinds/waterfall-layout.mjs +38 -0
- package/dist/charts/kinds/waterfall-marks.mjs +82 -0
- package/dist/charts/kinds/waterfall-words.mjs +118 -0
- package/dist/charts/kinds/waterfall.d.mts +17 -0
- package/dist/charts/kinds/waterfall.mjs +66 -0
- package/dist/charts/layout/boxes.mjs +28 -0
- package/dist/charts/layout/dodge.mjs +75 -0
- package/dist/charts/layout/extent.mjs +25 -0
- package/dist/charts/layout/frame.mjs +97 -0
- package/dist/charts/layout/place-labels.mjs +101 -0
- package/dist/charts/layout/stack.mjs +31 -0
- package/dist/charts/marks/axes.mjs +137 -0
- package/dist/charts/marks/dot.mjs +31 -0
- package/dist/charts/marks/end-labels.mjs +124 -0
- package/dist/charts/marks/legend.mjs +141 -0
- package/dist/charts/marks/lines.d.mts +2 -0
- package/dist/charts/marks/lines.mjs +38 -0
- package/dist/charts/marks/lit.d.mts +3 -0
- package/dist/charts/marks/lit.mjs +63 -0
- package/dist/charts/marks/more.mjs +18 -0
- package/dist/charts/marks/notes.mjs +253 -0
- package/dist/charts/marks/series-line.mjs +110 -0
- package/dist/charts/marks/thin.mjs +138 -0
- package/dist/charts/marks/x-axis.mjs +32 -0
- package/dist/charts/scale/calendar.mjs +174 -0
- package/dist/charts/scale/time-ticks.mjs +154 -0
- package/dist/charts/scale/time.mjs +33 -0
- package/dist/charts/scale/value.mjs +161 -0
- package/dist/charts/scene/defs.mjs +33 -0
- package/dist/charts/scene/markup.mjs +35 -0
- package/dist/charts/scene/nearest.d.mts +11 -0
- package/dist/charts/scene/nearest.mjs +49 -0
- package/dist/charts/scene/paint.d.mts +12 -0
- package/dist/charts/scene/paint.mjs +13 -0
- package/dist/charts/scene/svg.d.mts +18 -0
- package/dist/charts/scene/svg.mjs +185 -0
- package/dist/charts/scene/types.d.mts +177 -0
- package/dist/charts/text/measure.d.mts +9 -0
- package/dist/charts/text/measure.mjs +123 -0
- package/dist/charts/theme.d.mts +47 -0
- package/dist/charts/theme.mjs +239 -0
- package/dist/charts-react/Chart.d.mts +91 -0
- package/dist/charts-react/Chart.mjs +166 -0
- package/dist/charts-react/Overlay.mjs +171 -0
- package/dist/charts-react/Picture.mjs +22 -0
- package/dist/charts-react/Reader.mjs +147 -0
- package/dist/charts-react/bucket-names.mjs +29 -0
- package/dist/charts-react/chart-unlayered.css +1 -0
- package/dist/charts-react/chart-unlayered.css.d.ts +1 -0
- package/dist/charts-react/chart.css +1 -0
- package/dist/charts-react/chart.css.d.ts +1 -0
- package/dist/charts-react/events.mjs +72 -0
- package/dist/charts-react/exact-sum.mjs +24 -0
- package/dist/charts-react/from-answer.mjs +185 -0
- package/dist/charts-react/index.d.mts +3 -0
- package/dist/charts-react/index.mjs +4 -0
- package/dist/charts-react/keys.mjs +117 -0
- package/dist/charts-react/opens.mjs +28 -0
- package/dist/charts-react/plan-bars.mjs +95 -0
- package/dist/charts-react/plan-funnel.mjs +120 -0
- package/dist/charts-react/plan-grid.mjs +121 -0
- package/dist/charts-react/plan-parts.d.mts +2 -0
- package/dist/charts-react/plan-parts.mjs +30 -0
- package/dist/charts-react/plan-time.mjs +84 -0
- package/dist/charts-react/plan.d.mts +3 -0
- package/dist/charts-react/plan.mjs +37 -0
- package/dist/charts-react/point-keys.mjs +22 -0
- package/dist/charts-react/pointer.mjs +99 -0
- package/dist/charts-react/reader-page.d.mts +8 -0
- package/dist/charts-react/reader-page.mjs +116 -0
- package/dist/charts-react/tiles.d.mts +24 -0
- package/dist/charts-react/tiles.mjs +142 -0
- package/dist/charts-react/tip-place.mjs +107 -0
- package/dist/charts-react/tip-room.mjs +31 -0
- package/dist/charts-react/useClientLayoutEffect.mjs +8 -0
- package/dist/charts-react/useScene.mjs +76 -0
- package/dist/charts-react/useSize.mjs +44 -0
- package/dist/charts-react/useStop.mjs +68 -0
- package/dist/core/conformance/memory/aggregate.mjs +2 -1
- package/dist/core/conformance/memory/rows.mjs +1 -1
- package/dist/core/conformance/memory/source.mjs +3 -2
- package/dist/core/document/display-comparisons.mjs +49 -0
- package/dist/core/document/display-entries.mjs +2 -1
- package/dist/core/document/display-validation.d.mts +12 -0
- package/dist/core/document/display-validation.mjs +56 -0
- package/dist/core/document/display.d.mts +27 -12
- package/dist/core/document/display.mjs +40 -49
- package/dist/core/document/view-layout.mjs +16 -0
- package/dist/core/engine/access.mjs +4 -2
- package/dist/core/engine/context.mjs +5 -7
- package/dist/core/engine/custom/cells.mjs +1 -1
- package/dist/core/engine/custom/records.mjs +2 -1
- package/dist/core/engine/dialect.d.mts +2 -0
- package/dist/core/engine/index.mjs +1 -1
- package/dist/core/engine/levels.mjs +33 -1
- package/dist/core/engine/plan.d.mts +2 -0
- package/dist/core/engine/postgres.mjs +1 -0
- package/dist/core/engine/rank.mjs +1 -1
- package/dist/core/engine/reader.d.mts +4 -0
- package/dist/core/engine/sql-partition.mjs +45 -0
- package/dist/core/engine/sql-reads.mjs +4 -1
- package/dist/core/engine/statement.mjs +4 -4
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +1 -1
- package/dist/core/error/codes.mjs +1 -1
- package/dist/core/exact/decimal.d.mts +1 -4
- package/dist/core/exact/decimal.mjs +1 -14
- package/dist/core/exact/text.d.mts +5 -0
- package/dist/core/exact/text.mjs +19 -0
- package/dist/core/index.d.mts +9 -6
- package/dist/core/index.mjs +11 -8
- package/dist/core/model/types.d.mts +2 -0
- package/dist/core/model/validate/fields.mjs +1 -1
- package/dist/core/model/validate/known-members.mjs +2 -0
- package/dist/core/model/validate/shape.mjs +5 -1
- package/dist/core/oracle/visibility.mjs +2 -2
- package/dist/core/policy/bind.mjs +29 -1
- package/dist/core/query/drill/compose.d.mts +2 -0
- package/dist/core/query/drill/compose.mjs +1 -1
- package/dist/core/query/drill/synthetic.mjs +2 -1
- package/dist/core/query/drill/types.d.mts +7 -0
- package/dist/core/query/drill/types.mjs +3 -1
- package/dist/core/result/number.mjs +2 -1
- package/dist/core/result/time-axis.mjs +2 -1
- package/dist/core/schema/answers.d.mts +1176 -362
- package/dist/core/schema/commands.mjs +2 -1
- package/dist/core/schema/document.mjs +27 -2
- package/dist/core/schema/drill-answers.mjs +19 -1
- package/dist/core/schema/drill.d.mts +21 -6
- package/dist/core/schema/drill.mjs +7 -1
- package/dist/core/schema/index.d.mts +2 -1
- package/dist/core/schema/index.mjs +2 -1
- package/dist/core/schema/null-ops.d.mts +6 -0
- package/dist/core/schema/null-ops.mjs +18 -0
- package/dist/core/schema/query.mjs +30 -4
- package/dist/core/schema/tools.mjs +13 -0
- package/dist/core/schema/union-error.mjs +38 -0
- package/dist/core/time/bucket.mjs +2 -1
- package/dist/core/time/index.d.mts +3 -2
- package/dist/core/time/instant.d.mts +1 -2
- package/dist/core/time/instant.mjs +2 -30
- package/dist/core/time/range.mjs +2 -1
- package/dist/core/time/stored.mjs +2 -1
- package/dist/core/time/text-time.d.mts +10 -0
- package/dist/core/time/text-time.mjs +80 -0
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +22 -2
- package/dist/dashboard-documents.d.mts +8 -0
- package/dist/dashboard-documents.mjs +52 -0
- package/dist/drill-access.mjs +40 -3
- package/dist/drill-comparison.mjs +71 -0
- package/dist/drill-crumbs.mjs +21 -2
- package/dist/drill-group-seal.mjs +13 -0
- package/dist/drill-open.mjs +7 -1
- package/dist/drill-seal.mjs +4 -6
- package/dist/drill-views.mjs +5 -13
- package/dist/drill.mjs +28 -58
- package/dist/editing.mjs +1 -1
- package/dist/endpoints/drill.mjs +2 -3
- package/dist/endpoints/index.d.mts +20 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +6 -27
- package/dist/llms.txt +1 -1
- package/dist/react/Cell.mjs +2 -2
- package/dist/react/DashboardList.mjs +3 -3
- package/dist/react/Editing.mjs +3 -3
- package/dist/react/Header.mjs +2 -2
- package/dist/react/History.mjs +3 -3
- package/dist/react/Parts.mjs +2 -2
- package/dist/react/RowBody.d.mts +2 -4
- package/dist/react/RowBody.mjs +14 -39
- package/dist/react/Tile.mjs +4 -5
- package/dist/react/builder/FilterEditor.mjs +2 -2
- package/dist/react/builder/Picker.mjs +3 -3
- package/dist/react/builder/RangeEditor.mjs +3 -3
- package/dist/react/builder/Time.mjs +3 -3
- package/dist/react/builder/Values.mjs +2 -2
- package/dist/react/builder/WidgetBuilder.mjs +2 -2
- package/dist/react/digits.mjs +1 -1
- package/dist/react/drill/Bars.mjs +34 -38
- package/dist/react/drill/Comparison.mjs +204 -0
- package/dist/react/drill/Controls.mjs +8 -12
- package/dist/react/drill/DrillDrawer.mjs +42 -0
- package/dist/react/drill/DrillPanel.mjs +61 -41
- package/dist/react/drill/Header.mjs +65 -35
- package/dist/react/drill/ItemLink.mjs +40 -0
- package/dist/react/drill/Items.d.mts +2 -1
- package/dist/react/drill/Items.mjs +126 -99
- package/dist/react/drill/ItemsBody.mjs +38 -0
- package/dist/react/drill/ItemsFoot.mjs +24 -19
- package/dist/react/drill/Notes.mjs +23 -13
- package/dist/react/drill/PanelBody.mjs +7 -25
- package/dist/react/drill/RecordRow.mjs +47 -0
- package/dist/react/drill/Trend.mjs +186 -0
- package/dist/react/drill/board.mjs +21 -11
- package/dist/react/drill/drawer-context.mjs +5 -0
- package/dist/react/drill/item-parts.mjs +53 -35
- package/dist/react/drill/item-type.d.mts +2 -2
- package/dist/react/drill/lazy.d.mts +1 -4
- package/dist/react/drill/lazy.mjs +29 -11
- package/dist/react/drill/panel-focus.mjs +18 -7
- package/dist/react/drill/props.d.mts +7 -1
- package/dist/react/drill/props.mjs +39 -8
- package/dist/react/drill/record-page.mjs +61 -0
- package/dist/react/drill/state.mjs +17 -2
- package/dist/react/drill/trend-touch.mjs +33 -0
- package/dist/react/drill/useDrill.d.mts +3 -3
- package/dist/react/drill/useDrill.mjs +35 -15
- package/dist/react/drill/words.d.mts +14 -0
- package/dist/react/drill/words.mjs +20 -8
- package/dist/react/english.d.mts +4 -1
- package/dist/react/english.mjs +17 -2
- package/dist/react/filters/chip.mjs +2 -2
- package/dist/react/filters/menu-search.mjs +5 -5
- package/dist/react/filters/menu.mjs +2 -2
- package/dist/react/filters/number.mjs +2 -2
- package/dist/react/filters/operator.mjs +2 -2
- package/dist/react/filters/phone.mjs +2 -2
- package/dist/react/filters/values.mjs +4 -4
- package/dist/react/format-time.d.mts +2 -1
- package/dist/react/format-time.mjs +42 -34
- package/dist/react/format.mjs +15 -3
- package/dist/react/index.d.mts +4 -3
- package/dist/react/index.mjs +4 -3
- package/dist/react/messages.d.mts +23 -2
- package/dist/react/renderers/entries.d.mts +11 -0
- package/dist/react/renderers/list.mjs +8 -10
- package/dist/react/renderers/table-cells.mjs +38 -9
- package/dist/react/renderers/table-measure.mjs +2 -0
- package/dist/react/renderers/table-row.mjs +64 -7
- package/dist/react/renderers/table-sort.mjs +2 -8
- package/dist/react/renderers/table.mjs +16 -15
- package/dist/react/series.mjs +8 -3
- package/dist/react/theme-unlayered.css +1 -3144
- package/dist/react/theme.css +1 -3146
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +10 -5
- package/dist/store/apply.mjs +2 -2
- package/dist/store/editor.mjs +2 -2
- package/dist/store/writer.mjs +2 -2
- package/package.json +27 -2
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { ReaderPage } from "./reader-page.mjs";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/Reader.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The table's columns: the scene's own when it says them (every series of a chart over time,
|
|
7
|
+
* one with no value too), else the items', in the order they first appear. An item's key says
|
|
8
|
+
* what its value is of and is the same at every stop, so it is the item's column; the column
|
|
9
|
+
* is headed by the label of its first item. No two items of a stop share a key, so a cell
|
|
10
|
+
* holds one value.
|
|
11
|
+
*/
|
|
12
|
+
function columnsOf(hover) {
|
|
13
|
+
if (hover.columns !== void 0) return hover.columns;
|
|
14
|
+
const columns = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const item of hover.stops.flatMap((stop) => stop.items)) if (!columns.has(item.key)) columns.set(item.key, {
|
|
16
|
+
key: item.key,
|
|
17
|
+
label: item.label
|
|
18
|
+
});
|
|
19
|
+
return [...columns.values()];
|
|
20
|
+
}
|
|
21
|
+
/** An item's value and what it is read against. */
|
|
22
|
+
const cellText = (item) => item.aside === void 0 ? item.value : `${item.value} (${item.aside})`;
|
|
23
|
+
/** A stop's title as a row's heading, with what is said beside it. */
|
|
24
|
+
const rowTitle = (stop) => stop.note === void 0 ? stop.title : `${stop.title} (${stop.note})`;
|
|
25
|
+
/** These elements must stay outside the measured stage's flex layout, even without a theme. */
|
|
26
|
+
const readerStyle = {
|
|
27
|
+
position: "absolute",
|
|
28
|
+
contain: "strict",
|
|
29
|
+
width: 1,
|
|
30
|
+
height: 1,
|
|
31
|
+
padding: 0,
|
|
32
|
+
margin: -1,
|
|
33
|
+
overflow: "hidden",
|
|
34
|
+
clipPath: "inset(50%)",
|
|
35
|
+
whiteSpace: "nowrap",
|
|
36
|
+
border: 0
|
|
37
|
+
};
|
|
38
|
+
/** The same axes the chart uses. A panel's stop is one cell, while a line stop holds a whole row. */
|
|
39
|
+
function tableOf(scene) {
|
|
40
|
+
const hover = scene.hover;
|
|
41
|
+
if (hover === void 0) return {
|
|
42
|
+
columns: [],
|
|
43
|
+
rows: []
|
|
44
|
+
};
|
|
45
|
+
const { matrix, stops } = hover;
|
|
46
|
+
if (matrix !== void 0) {
|
|
47
|
+
const rows = matrix.rows.map((row) => ({
|
|
48
|
+
...row,
|
|
49
|
+
cells: []
|
|
50
|
+
}));
|
|
51
|
+
for (const { cell, items } of stops) {
|
|
52
|
+
const row = cell === void 0 ? void 0 : rows[cell[0]];
|
|
53
|
+
const item = items[0];
|
|
54
|
+
if (row !== void 0 && cell !== void 0 && item !== void 0) row.cells[cell[1]] = cellText(item);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
columns: matrix.columns,
|
|
58
|
+
rows,
|
|
59
|
+
heading: matrix.heading
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const columns = columnsOf(hover);
|
|
63
|
+
const slots = new Map(columns.map((c, i) => [c.key, i]));
|
|
64
|
+
return {
|
|
65
|
+
columns,
|
|
66
|
+
rows: stops.map((stop) => {
|
|
67
|
+
const cells = [];
|
|
68
|
+
for (const item of stop.items) {
|
|
69
|
+
const i = slots.get(item.key);
|
|
70
|
+
if (i !== void 0) cells[i] = cellText(item);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
key: stop.key,
|
|
74
|
+
label: rowTitle(stop),
|
|
75
|
+
cells
|
|
76
|
+
};
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const TABLES = /* @__PURE__ */ new WeakMap();
|
|
81
|
+
function readTable(scene) {
|
|
82
|
+
const known = TABLES.get(scene);
|
|
83
|
+
if (known !== void 0) return known;
|
|
84
|
+
const table = tableOf(scene);
|
|
85
|
+
TABLES.set(scene, table);
|
|
86
|
+
return table;
|
|
87
|
+
}
|
|
88
|
+
function TableOfScene({ scene, caption, noValue = "", pages }) {
|
|
89
|
+
const data = readTable(scene);
|
|
90
|
+
if (data.rows.length === 0) return null;
|
|
91
|
+
return /* @__PURE__ */ jsx(ReaderPage, {
|
|
92
|
+
data,
|
|
93
|
+
caption,
|
|
94
|
+
noValue,
|
|
95
|
+
words: pages,
|
|
96
|
+
hidden: readerStyle
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const sameHeading = (a, b) => a.key === b?.key && a.label === b.label;
|
|
100
|
+
function sameWords(a, b) {
|
|
101
|
+
if (a.heading !== b.heading || a.rows.length !== b.rows.length || a.columns.length !== b.columns.length) return false;
|
|
102
|
+
if (!a.columns.every((c, i) => sameHeading(c, b.columns[i]))) return false;
|
|
103
|
+
return a.rows.every((row, i) => {
|
|
104
|
+
const other = b.rows[i];
|
|
105
|
+
return sameHeading(row, other) && a.columns.every((_c, j) => row.cells[j] === other?.cells[j]);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const sameTable = (a, b) => a.pages === b.pages && a.caption === b.caption && a.noValue === b.noValue && (a.scene === b.scene || sameWords(readTable(a.scene), readTable(b.scene)));
|
|
109
|
+
/**
|
|
110
|
+
* The hidden table, made again only when it would read differently. A pointer moving over the
|
|
111
|
+
* chart lights a new stop many times a second, and a box that changes size is drawn again at
|
|
112
|
+
* each step with the same words in it: the table is most of a chart's elements, and neither
|
|
113
|
+
* makes it again.
|
|
114
|
+
*/
|
|
115
|
+
const SceneTable = memo(TableOfScene, sameTable);
|
|
116
|
+
/** An item as a phrase: its name, its value, and what it is read against. */
|
|
117
|
+
const itemText = (item) => [`${item.label} ${item.value}`, item.aside].filter((part) => part !== void 0).join(", ");
|
|
118
|
+
/** A stop's title, with what is said beside it. */
|
|
119
|
+
const headOf = (stop) => stop.note === void 0 ? stop.title : `${stop.title}, ${stop.note}`;
|
|
120
|
+
/** Phrases as sentences, each closed by a full stop unless it already ends one. */
|
|
121
|
+
const sentences = (phrases) => phrases.reduce((text, phrase) => text === "" ? phrase : `${text}${/[.!?]$/u.test(text) ? "" : "."} ${phrase}`, "");
|
|
122
|
+
/**
|
|
123
|
+
* What the live region says: nothing for a stop the pointer lit, so a mouse is silent; the stop
|
|
124
|
+
* a key moved to, value by value, or `noValue` at a stop with none (a gap), as the table writes
|
|
125
|
+
* it; or, when a key across the way the stops run chose another value in it, that value. The
|
|
126
|
+
* value chosen is said in its spoken form when it has one (`said`: what a screen reader hears
|
|
127
|
+
* for a value that opens, which names it and says it opens), else as it reads.
|
|
128
|
+
*/
|
|
129
|
+
function liveText(lit, stop, saying = {}) {
|
|
130
|
+
if (lit?.via !== "key" || stop === void 0) return "";
|
|
131
|
+
const { said, noValue = "" } = saying;
|
|
132
|
+
const chosen = stop.items[lit.item];
|
|
133
|
+
const phrase = (item) => item === chosen ? said ?? itemText(item) : itemText(item);
|
|
134
|
+
if (lit.moved === "item" && chosen !== void 0) return phrase(chosen);
|
|
135
|
+
const values = stop.items.length === 0 ? [noValue] : stop.items.map((item) => phrase(item));
|
|
136
|
+
return sentences([headOf(stop), ...values.filter((value) => value !== "")]);
|
|
137
|
+
}
|
|
138
|
+
/** The polite live region a chart says its keyboard moves in. */
|
|
139
|
+
function Live({ said }) {
|
|
140
|
+
return /* @__PURE__ */ jsx("div", {
|
|
141
|
+
className: "dd-sr-only",
|
|
142
|
+
style: readerStyle,
|
|
143
|
+
"aria-live": "polite",
|
|
144
|
+
children: said
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export { Live, SceneTable, itemText, liveText, readerStyle, sameTable };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { formatBucket, formatInstantAt } from "derive-dashboards/react";
|
|
2
|
+
// src/bucket-names.ts
|
|
3
|
+
/** The zone's short name at an instant ("PDT"), in the locale; none when Intl gives none. */
|
|
4
|
+
function zoneNamer(at) {
|
|
5
|
+
const format = new Intl.DateTimeFormat(at.locale, {
|
|
6
|
+
timeZoneName: "short",
|
|
7
|
+
...at.zone === void 0 ? {} : { timeZone: at.zone }
|
|
8
|
+
});
|
|
9
|
+
return (from) => format.formatToParts(new Date(from)).find((part) => part.type === "timeZoneName")?.value;
|
|
10
|
+
}
|
|
11
|
+
/** Each hour's name, with its zone's short name where another hour of the list reads alike. */
|
|
12
|
+
function hoursApart(placed, at) {
|
|
13
|
+
const titles = placed.map((p) => formatInstantAt(p.given.from, "hour", at.locale, at.zone));
|
|
14
|
+
const counts = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const title of titles) counts.set(title, (counts.get(title) ?? 0) + 1);
|
|
16
|
+
const zoneAt = zoneNamer(at);
|
|
17
|
+
return titles.map((title, i) => {
|
|
18
|
+
const from = placed[i]?.bucket.from;
|
|
19
|
+
const zone = from === void 0 || (counts.get(title) ?? 0) < 2 ? void 0 : zoneAt(from);
|
|
20
|
+
return zone === void 0 ? title : `${title} ${zone}`;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Every bucket's whole name, in the order given. */
|
|
24
|
+
function titlesOf(placed, at) {
|
|
25
|
+
if (at.grain === "hour") return hoursApart(placed, at);
|
|
26
|
+
if (placed[0]?.given.label.slice(0, 4) !== placed.at(-1)?.given.label.slice(0, 4) && (at.grain === "day" || at.grain === "week")) return placed.map((p) => formatBucket(p.given.label, at.grain, at.locale, true));
|
|
27
|
+
return placed.map((p) => p.name);
|
|
28
|
+
}
|
|
29
|
+
export { titlesOf };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.dd-chart:focus-visible{border-radius:var(--dd-radius);outline:2px solid var(--dd-accent);outline-offset:2px}.dd-chart[data-opens=true]>.dd-c-stage{cursor:pointer}.dd-c-stage>.dd-chart-picture>svg{display:block;overflow:visible}.dd-c-tip{display:grid;grid-template-columns:auto minmax(0,1fr) minmax(0,auto);row-gap:4px;align-items:center;box-sizing:border-box;min-width:min(146px,100%);max-width:min(304px,100%);max-height:100%;overflow:auto;padding:9px 12px;background:var(--dd-surface);color:var(--dd-ink);border:1px solid var(--dd-line);border-radius:var(--dd-tooltip-radius, 5px);box-shadow:0 1px 2px rgb(0 0 0 / 0.06),0 5px 14px -4px rgb(0 0 0 / 0.16);font-family:var(--dd-font, system-ui, sans-serif);font-size:12px;line-height:16px;font-variant-numeric:tabular-nums;white-space:normal;overflow-wrap:anywhere;z-index:2}.dd-c-tip-title{grid-column:1 / -1;margin-bottom:3px;font-weight:600;white-space:normal;overflow-wrap:anywhere}.dd-c-tip-note{margin-left:6px;color:var(--dd-muted);font-weight:400}.dd-c-tip-row{display:contents}.dd-c-swatch{grid-column:1;margin-right:7px;width:8px;height:8px;border-radius:2px}.dd-c-tip-label{grid-column:2;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--dd-muted)}.dd-c-tip-row[data-chosen] .dd-c-tip-label{color:var(--dd-ink);font-weight:600}.dd-c-tip-value{grid-column:3;padding-left:14px;font-weight:600;text-align:right}.dd-c-tip-aside{grid-column:1 / -1;color:var(--dd-muted);text-align:start}.dd-c-tip[data-single] .dd-c-tip-title{grid-column:1 / 3;grid-row:1;margin:0}.dd-c-tip[data-single] .dd-c-tip-value{grid-row:1;font-size:13px}.dd-c-tip[data-single] .dd-c-swatch,.dd-c-tip[data-single] .dd-c-tip-label{grid-row:2}.dd-c-tip[data-single] .dd-c-tip-label{grid-column:2 / -1;white-space:normal}.dd-c-tip-empty{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-more{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-hint{grid-column:1 / -1;margin-top:2px;padding-top:5px;border-top:1px solid var(--dd-line-soft, var(--dd-line));color:var(--dd-muted)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer derive-dashboards{.dd-chart:focus-visible{border-radius:var(--dd-radius);outline:2px solid var(--dd-accent);outline-offset:2px}.dd-chart[data-opens=true]>.dd-c-stage{cursor:pointer}.dd-c-stage>.dd-chart-picture>svg{display:block;overflow:visible}.dd-c-tip{display:grid;grid-template-columns:auto minmax(0,1fr) minmax(0,auto);row-gap:4px;align-items:center;box-sizing:border-box;min-width:min(146px,100%);max-width:min(304px,100%);max-height:100%;overflow:auto;padding:9px 12px;background:var(--dd-surface);color:var(--dd-ink);border:1px solid var(--dd-line);border-radius:var(--dd-tooltip-radius, 5px);box-shadow:0 1px 2px rgb(0 0 0 / 0.06),0 5px 14px -4px rgb(0 0 0 / 0.16);font-family:var(--dd-font, system-ui, sans-serif);font-size:12px;line-height:16px;font-variant-numeric:tabular-nums;white-space:normal;overflow-wrap:anywhere;z-index:2}.dd-c-tip-title{grid-column:1 / -1;margin-bottom:3px;font-weight:600;white-space:normal;overflow-wrap:anywhere}.dd-c-tip-note{margin-left:6px;color:var(--dd-muted);font-weight:400}.dd-c-tip-row{display:contents}.dd-c-swatch{grid-column:1;margin-right:7px;width:8px;height:8px;border-radius:2px}.dd-c-tip-label{grid-column:2;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color:var(--dd-muted)}.dd-c-tip-row[data-chosen] .dd-c-tip-label{color:var(--dd-ink);font-weight:600}.dd-c-tip-value{grid-column:3;padding-left:14px;font-weight:600;text-align:right}.dd-c-tip-aside{grid-column:1 / -1;color:var(--dd-muted);text-align:start}.dd-c-tip[data-single] .dd-c-tip-title{grid-column:1 / 3;grid-row:1;margin:0}.dd-c-tip[data-single] .dd-c-tip-value{grid-row:1;font-size:13px}.dd-c-tip[data-single] .dd-c-swatch,.dd-c-tip[data-single] .dd-c-tip-label{grid-row:2}.dd-c-tip[data-single] .dd-c-tip-label{grid-column:2 / -1;white-space:normal}.dd-c-tip-empty{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-more{grid-column:1 / -1;color:var(--dd-muted)}.dd-c-tip-hint{grid-column:1 / -1;margin-top:2px;padding-top:5px;border-top:1px solid var(--dd-line-soft, var(--dd-line));color:var(--dd-muted)}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { stepHover, stepItem } from "./keys.mjs";
|
|
2
|
+
import { opens, valued } from "./opens.mjs";
|
|
3
|
+
import { usePointer } from "./pointer.mjs";
|
|
4
|
+
import { useStop } from "./useStop.mjs";
|
|
5
|
+
// src/events.ts
|
|
6
|
+
const isSelect = (key) => key === "Enter" || key === " ";
|
|
7
|
+
/** The stop the keyboard is on, when it has a value, with the item chosen in it. */
|
|
8
|
+
function chosenOf(stops, was) {
|
|
9
|
+
if (was === void 0) return;
|
|
10
|
+
const found = valued(stops, was.index);
|
|
11
|
+
const item = found?.stop.items[was.item];
|
|
12
|
+
return found === void 0 || item === void 0 ? void 0 : {
|
|
13
|
+
stop: found.stop,
|
|
14
|
+
item,
|
|
15
|
+
place: was.item,
|
|
16
|
+
count: found.stop.items.length
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Where a key moves: to another stop, else to another item of the chosen stop; nowhere for none. */
|
|
20
|
+
function moveOf(key, hover, was, chosen) {
|
|
21
|
+
const next = stepHover(key, hover, was?.index);
|
|
22
|
+
if (next !== void 0) return { stop: next };
|
|
23
|
+
const item = chosen === void 0 ? void 0 : stepItem(key, hover.snap, {
|
|
24
|
+
index: chosen.place,
|
|
25
|
+
count: chosen.count
|
|
26
|
+
});
|
|
27
|
+
return item === void 0 ? void 0 : { item };
|
|
28
|
+
}
|
|
29
|
+
/** What a key does: clear, select the chosen item, step to another stop, or choose another item. */
|
|
30
|
+
function keyHandler(scene, callbacks, at) {
|
|
31
|
+
return (event) => {
|
|
32
|
+
const hover = scene?.hover;
|
|
33
|
+
if (hover === void 0) return;
|
|
34
|
+
if (event.key === "Escape") {
|
|
35
|
+
at.clear();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const was = at.current();
|
|
39
|
+
const chosen = chosenOf(hover.stops, was);
|
|
40
|
+
if (isSelect(event.key) && chosen !== void 0 && opens(callbacks, chosen.stop, chosen.item)) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
callbacks.onSelect?.(chosen.stop, chosen.item);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const move = moveOf(event.key, hover, was, chosen);
|
|
46
|
+
if (move === void 0) return;
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
if ("stop" in move) at.light(move.stop, "key");
|
|
49
|
+
else at.choose(move.item);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The lit stop and chosen item, and the handlers that light, clear and select them. */
|
|
53
|
+
function useChartEvents(scene, callbacks, stage) {
|
|
54
|
+
const stopped = useStop(scene, callbacks.onHover);
|
|
55
|
+
const pointer = usePointer({
|
|
56
|
+
scene,
|
|
57
|
+
callbacks,
|
|
58
|
+
stage,
|
|
59
|
+
stopped
|
|
60
|
+
});
|
|
61
|
+
const onKeyDown = keyHandler(scene, callbacks, stopped);
|
|
62
|
+
return {
|
|
63
|
+
lit: stopped.lit,
|
|
64
|
+
stop: stopped.stop,
|
|
65
|
+
handlers: {
|
|
66
|
+
...pointer,
|
|
67
|
+
onKeyDown,
|
|
68
|
+
onBlur: stopped.clear
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export { useChartEvents };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { formatExact, parseExact, sumLinear } from "derive-dashboards/core";
|
|
2
|
+
import { exactDigits } from "derive-dashboards/react";
|
|
3
|
+
// src/exact-sum.ts
|
|
4
|
+
/** How many places after the point a decimal text has. */
|
|
5
|
+
const placesOf = (text) => text.split(".")[1]?.length ?? 0;
|
|
6
|
+
/**
|
|
7
|
+
* The exact sum of some cells, as a decimal cell at the longest scale among them; undefined when
|
|
8
|
+
* there are none, or one has no exact digits (a float that is not whole).
|
|
9
|
+
*/
|
|
10
|
+
function exactSum(cells) {
|
|
11
|
+
const texts = cells.map((cell) => exactDigits(cell));
|
|
12
|
+
const scale = Math.max(0, ...texts.map((text) => text === void 0 ? 0 : placesOf(text)));
|
|
13
|
+
const parts = texts.flatMap((text) => {
|
|
14
|
+
const part = text === void 0 ? void 0 : parseExact(text, scale);
|
|
15
|
+
return part === void 0 ? [] : [[part]];
|
|
16
|
+
});
|
|
17
|
+
if (parts.length === 0 || parts.length !== cells.length) return void 0;
|
|
18
|
+
const { sum } = sumLinear([1n], parts);
|
|
19
|
+
return sum === null ? void 0 : {
|
|
20
|
+
t: "decimal",
|
|
21
|
+
v: formatExact(sum, scale)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { exactSum };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { titlesOf } from "./bucket-names.mjs";
|
|
2
|
+
import { exactSum } from "./exact-sum.mjs";
|
|
3
|
+
import { keyedPoints } from "./point-keys.mjs";
|
|
4
|
+
import { addsUp, parseTextTime } from "derive-dashboards/core";
|
|
5
|
+
import { OTHER_KEY, formatCell, formatTick, pointCell, pointText } from "derive-dashboards/react";
|
|
6
|
+
// src/from-answer.ts
|
|
7
|
+
/**
|
|
8
|
+
* How a series' values read: by its column's type, unit and format, in the reader's locale. A
|
|
9
|
+
* percent is a share: a change in one is never written as a percent of a percent.
|
|
10
|
+
*
|
|
11
|
+
* Whether a column's values add up is the answer's to say (a measure by the model's merge
|
|
12
|
+
* rule, a calc by its formula), and core's `addsUp` is the one reader of it: the parts of a
|
|
13
|
+
* split are summed or stacked only where it says so, never for an answer that does not say.
|
|
14
|
+
*/
|
|
15
|
+
function measureOf(column, format) {
|
|
16
|
+
return {
|
|
17
|
+
label: column.label,
|
|
18
|
+
tick: (value) => formatTick(value, column, format.locale),
|
|
19
|
+
text: (value) => formatCell(value, column, format),
|
|
20
|
+
...column.type === "int" ? { whole: true } : {},
|
|
21
|
+
additive: addsUp(column),
|
|
22
|
+
...column.format === "percent" ? { share: true } : {}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Text time as milliseconds, by core's one reader of it (which brings no calendar library to
|
|
27
|
+
* the page); undefined when it is not an instant.
|
|
28
|
+
*/
|
|
29
|
+
function millisOf(text) {
|
|
30
|
+
const micros = parseTextTime(text);
|
|
31
|
+
return micros === void 0 ? void 0 : micros / 1e3;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A point's time bucket as the charts read it, or undefined when it is missing or unreadable.
|
|
35
|
+
* It keeps the answer's own name for it: a day's name is its local date, which the charts read
|
|
36
|
+
* as it is, where its first instant would read a day early east of UTC.
|
|
37
|
+
*/
|
|
38
|
+
function bucketOf(bucket) {
|
|
39
|
+
if (bucket === void 0) return void 0;
|
|
40
|
+
const from = millisOf(bucket.from);
|
|
41
|
+
const to = millisOf(bucket.to);
|
|
42
|
+
if (from === void 0 || to === void 0) return void 0;
|
|
43
|
+
return {
|
|
44
|
+
label: bucket.label,
|
|
45
|
+
from,
|
|
46
|
+
to,
|
|
47
|
+
...bucket.partial === void 0 ? {} : { partial: bucket.partial }
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A drawn series as the charts take it, at the given points: its values, their cells' text,
|
|
52
|
+
* its slot and colour, and whether it is Other.
|
|
53
|
+
*/
|
|
54
|
+
function chartSeries(drawn, s, at) {
|
|
55
|
+
const color = at.colors?.[s.label];
|
|
56
|
+
return {
|
|
57
|
+
key: s.key,
|
|
58
|
+
label: s.label,
|
|
59
|
+
measure: measureOf(s.column, at.format),
|
|
60
|
+
values: at.points.map((i) => {
|
|
61
|
+
const value = drawn.points[i]?.[s.key];
|
|
62
|
+
return typeof value === "number" ? value : null;
|
|
63
|
+
}),
|
|
64
|
+
texts: at.points.map((point) => pointText(at.answer, drawn, {
|
|
65
|
+
point,
|
|
66
|
+
series: s
|
|
67
|
+
}, at.format)),
|
|
68
|
+
...s.slot === void 0 ? {} : { slot: s.slot },
|
|
69
|
+
...color === void 0 ? {} : { color },
|
|
70
|
+
...s.key === OTHER_KEY ? { other: true } : {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The series over time, when the answer's x axis is time; undefined otherwise. The buckets run
|
|
75
|
+
* in the order core sends them, which is time order (`answer.time.buckets`), whatever order the
|
|
76
|
+
* rows came in (a query may sort by a measure, or newest first). A bucket's key is its label,
|
|
77
|
+
* its name `titlesOf`'s. A point with no bucket among `time.buckets` (a row with no time) has
|
|
78
|
+
* no place on a time axis: it is not drawn, and is named in `unplaced` by its own name, the dashboards' word for it
|
|
79
|
+
* ("No week"), for the note under the chart. With none left, the time axis is empty.
|
|
80
|
+
*/
|
|
81
|
+
function timeTableOf(drawn, at) {
|
|
82
|
+
const time = at.answer.time;
|
|
83
|
+
if (drawn.buckets === void 0 || time === void 0) return void 0;
|
|
84
|
+
const order = new Map(time.buckets.map((b, i) => [b.label, i]));
|
|
85
|
+
const all = drawn.points.map((point, i) => {
|
|
86
|
+
const given = drawn.buckets?.[i];
|
|
87
|
+
const bucket = bucketOf(given);
|
|
88
|
+
const place = given === void 0 ? void 0 : order.get(given.label);
|
|
89
|
+
return bucket === void 0 || given === void 0 || place === void 0 ? { point } : {
|
|
90
|
+
point,
|
|
91
|
+
placed: {
|
|
92
|
+
i,
|
|
93
|
+
bucket,
|
|
94
|
+
given,
|
|
95
|
+
name: point.x,
|
|
96
|
+
place
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
const placed = all.flatMap((p) => p.placed === void 0 ? [] : [p.placed]).toSorted((a, b) => a.place - b.place);
|
|
101
|
+
const points = placed.map((p) => p.i);
|
|
102
|
+
return {
|
|
103
|
+
data: {
|
|
104
|
+
x: {
|
|
105
|
+
grain: time.grain,
|
|
106
|
+
buckets: placed.map((p) => p.bucket),
|
|
107
|
+
titles: titlesOf(placed, {
|
|
108
|
+
grain: time.grain,
|
|
109
|
+
locale: at.format.locale,
|
|
110
|
+
zone: at.zone
|
|
111
|
+
}),
|
|
112
|
+
...at.zone === void 0 ? {} : { zone: at.zone }
|
|
113
|
+
},
|
|
114
|
+
series: at.series.map((s) => chartSeries(drawn, s, {
|
|
115
|
+
...at,
|
|
116
|
+
points
|
|
117
|
+
}))
|
|
118
|
+
},
|
|
119
|
+
pointOf: new Map(placed.map((p) => [p.bucket.label, p.i])),
|
|
120
|
+
unplaced: all.flatMap((p) => p.placed === void 0 ? [p.point.x] : [])
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** The sum of a point's values in the series; none when it has none. */
|
|
124
|
+
function sumOf(point, series) {
|
|
125
|
+
const values = series.flatMap((s) => {
|
|
126
|
+
const value = point[s.key];
|
|
127
|
+
return typeof value === "number" ? [value] : [];
|
|
128
|
+
});
|
|
129
|
+
return values.length === 0 ? null : values.reduce((sum, value) => sum + value, 0);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A summed bar's value as the answer would write it: the exact sum of its parts' cells, in their
|
|
133
|
+
* column; undefined when a part has no cell or none core reads exactly.
|
|
134
|
+
*/
|
|
135
|
+
function sumText(drawn, point, at) {
|
|
136
|
+
const parts = at.series.filter((s) => typeof drawn.points[point]?.[s.key] === "number");
|
|
137
|
+
const cells = parts.map((s) => pointCell(at.answer, drawn, {
|
|
138
|
+
point,
|
|
139
|
+
series: s
|
|
140
|
+
}));
|
|
141
|
+
const [first] = parts;
|
|
142
|
+
const known = cells.flatMap((cell) => cell === void 0 ? [] : [cell]);
|
|
143
|
+
const sum = known.length === cells.length ? exactSum(known) : void 0;
|
|
144
|
+
return sum === void 0 || first === void 0 ? void 0 : formatCell(sum, first.column, at.format);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A bar's value as the answer writes it: the cell of its one series, or the exact sum of the
|
|
148
|
+
* cells of several (a split's parts).
|
|
149
|
+
*/
|
|
150
|
+
function textOf(drawn, point, at) {
|
|
151
|
+
const [only] = at.series;
|
|
152
|
+
const text = only !== void 0 && at.series.length === 1 ? pointText(at.answer, drawn, {
|
|
153
|
+
point,
|
|
154
|
+
series: only
|
|
155
|
+
}, at.format) : sumText(drawn, point, at);
|
|
156
|
+
return text === void 0 ? {} : { text };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Bars by category, a row per point in the answer's order, keyed by its raw x cell (`keyedPoints`);
|
|
160
|
+
* `pointOf` leads from a key back to its point. A row's
|
|
161
|
+
* value is its series' value, or the sum of several (a split's parts), empty when none has one.
|
|
162
|
+
* Bars of one series wear that series' own colour, as the dashboards' other tiles paint it. The
|
|
163
|
+
* colour is the series', not a row's: the row that is Other keeps its grey. A sum of several
|
|
164
|
+
* series has no one colour.
|
|
165
|
+
*/
|
|
166
|
+
function barRowsOf(drawn, at) {
|
|
167
|
+
const [only] = at.series;
|
|
168
|
+
const own = only === void 0 || at.series.length !== 1 ? void 0 : at.colors?.[only.label];
|
|
169
|
+
const keyed = keyedPoints(drawn);
|
|
170
|
+
return {
|
|
171
|
+
data: keyed.map(({ point, i, key }) => {
|
|
172
|
+
const other = drawn.isOther(i);
|
|
173
|
+
return {
|
|
174
|
+
key,
|
|
175
|
+
label: point.x,
|
|
176
|
+
value: sumOf(point, at.series),
|
|
177
|
+
...textOf(drawn, i, at),
|
|
178
|
+
...other ? { other: true } : {},
|
|
179
|
+
...own === void 0 || other ? {} : { color: own }
|
|
180
|
+
};
|
|
181
|
+
}),
|
|
182
|
+
pointOf: new Map(keyed.map(({ key, i }) => [key, i]))
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export { barRowsOf, measureOf, timeTableOf };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Chart, ChartProps } from "./Chart.mjs";
|
|
2
|
+
import { AreaTile, BarTile, CHARTS_RENDERERS, FunnelTile, HeatmapTile, LineTile, MultiplesTile } from "./tiles.mjs";
|
|
3
|
+
export { AreaTile, BarTile, CHARTS_RENDERERS, Chart, type ChartProps, FunnelTile, HeatmapTile, LineTile, MultiplesTile };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Chart } from "./Chart.mjs";
|
|
3
|
+
import { AreaTile, BarTile, CHARTS_RENDERERS, FunnelTile, HeatmapTile, LineTile, MultiplesTile } from "./tiles.mjs";
|
|
4
|
+
export { AreaTile, BarTile, CHARTS_RENDERERS, Chart, FunnelTile, HeatmapTile, LineTile, MultiplesTile };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/keys.ts
|
|
2
|
+
/** The keys that step forward and back: across for stops along x, up and down for stops along y. */
|
|
3
|
+
const STEPS = {
|
|
4
|
+
x: {
|
|
5
|
+
back: "ArrowLeft",
|
|
6
|
+
on: "ArrowRight"
|
|
7
|
+
},
|
|
8
|
+
nearest: {
|
|
9
|
+
back: "ArrowLeft",
|
|
10
|
+
on: "ArrowRight"
|
|
11
|
+
},
|
|
12
|
+
y: {
|
|
13
|
+
back: "ArrowUp",
|
|
14
|
+
on: "ArrowDown"
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The stop a key moves to from `at` (none lit yet when undefined) among `count`; undefined for
|
|
19
|
+
* a key that does not move. The first step forward lights the first stop, the first back the last.
|
|
20
|
+
*/
|
|
21
|
+
function cellStep(key, at, count, across) {
|
|
22
|
+
if (at === void 0) {
|
|
23
|
+
if (key === "ArrowLeft" || key === "ArrowUp") return count - 1;
|
|
24
|
+
return key === "ArrowDown" || key === "ArrowRight" ? 0 : void 0;
|
|
25
|
+
}
|
|
26
|
+
const row = Math.floor(at / across) * across;
|
|
27
|
+
return {
|
|
28
|
+
ArrowLeft: Math.max(row, at - 1),
|
|
29
|
+
ArrowRight: Math.min(count - 1, row + across - 1, at + 1),
|
|
30
|
+
ArrowUp: at < across ? at : at - across,
|
|
31
|
+
ArrowDown: at + across >= count ? at : at + across
|
|
32
|
+
}[key];
|
|
33
|
+
}
|
|
34
|
+
/** Up and down on small multiples keep the period when moving between panels. If a panel
|
|
35
|
+
* has a gap on that date, use its closest reading. The stops are ordered by panel, then time. */
|
|
36
|
+
function stepPanel(key, stops, index) {
|
|
37
|
+
if (key !== "ArrowUp" && key !== "ArrowDown") return;
|
|
38
|
+
const step = key === "ArrowUp" ? -1 : 1;
|
|
39
|
+
if (index === void 0) return step === 1 ? 0 : stops.length - 1;
|
|
40
|
+
const cell = stops[index]?.cell;
|
|
41
|
+
if (cell === void 0) return;
|
|
42
|
+
return nearestPanelPeriod(stops, {
|
|
43
|
+
index,
|
|
44
|
+
step,
|
|
45
|
+
cell
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/** Inspect only the neighbouring panel, stopping as soon as dates grow farther away. */
|
|
49
|
+
function nearestPanelPeriod(stops, at) {
|
|
50
|
+
const end = at.step > 0 ? stops.length : -1;
|
|
51
|
+
let nearest = at.index;
|
|
52
|
+
let distance = Infinity;
|
|
53
|
+
let panel;
|
|
54
|
+
for (let i = at.index + at.step; i !== end; i += at.step) {
|
|
55
|
+
const next = stops[i]?.cell;
|
|
56
|
+
if (next === void 0 || next[1] === at.cell[1]) continue;
|
|
57
|
+
panel ??= next[1];
|
|
58
|
+
if (next[1] !== panel) break;
|
|
59
|
+
const gap = Math.abs(next[0] - at.cell[0]);
|
|
60
|
+
if (gap >= distance) break;
|
|
61
|
+
nearest = i;
|
|
62
|
+
distance = gap;
|
|
63
|
+
}
|
|
64
|
+
return nearest;
|
|
65
|
+
}
|
|
66
|
+
function stepStop(key, snap, at) {
|
|
67
|
+
const last = at.count - 1;
|
|
68
|
+
if (at.count === 0) return void 0;
|
|
69
|
+
if (key === "Home") return 0;
|
|
70
|
+
if (key === "End") return last;
|
|
71
|
+
if (at.across !== void 0 && at.across > 0) return cellStep(key, at.index, at.count, at.across);
|
|
72
|
+
if (key === STEPS[snap].on) return at.index === void 0 ? 0 : Math.min(at.index + 1, last);
|
|
73
|
+
if (key === STEPS[snap].back) return at.index === void 0 ? last : Math.max(at.index - 1, 0);
|
|
74
|
+
}
|
|
75
|
+
/** The next reading in a grid, across panels or along a chart's primary axis. */
|
|
76
|
+
function stepHover(key, hover, index) {
|
|
77
|
+
const { matrix, stops } = hover;
|
|
78
|
+
if (matrix !== void 0 && matrix.rowMajor !== true && stops.length > 0) {
|
|
79
|
+
const panel = stepPanel(key, stops, index);
|
|
80
|
+
if (panel !== void 0) return panel;
|
|
81
|
+
}
|
|
82
|
+
return stepStop(key, hover.snap, {
|
|
83
|
+
index,
|
|
84
|
+
count: stops.length,
|
|
85
|
+
across: matrix?.rowMajor === true ? matrix.columns.length : void 0
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The keys that choose among a stop's values: across the way the stops run, so they never step
|
|
90
|
+
* to another stop. Where stops run down the chart (bars, a dumbbell's rows), left and right;
|
|
91
|
+
* where they run across it or lie anywhere, up and down.
|
|
92
|
+
*/
|
|
93
|
+
const CHOOSE = {
|
|
94
|
+
x: {
|
|
95
|
+
back: "ArrowUp",
|
|
96
|
+
on: "ArrowDown"
|
|
97
|
+
},
|
|
98
|
+
nearest: {
|
|
99
|
+
back: "ArrowUp",
|
|
100
|
+
on: "ArrowDown"
|
|
101
|
+
},
|
|
102
|
+
y: {
|
|
103
|
+
back: "ArrowLeft",
|
|
104
|
+
on: "ArrowRight"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The item a key moves to within a stop of `count` items, from `at`, by the stop's own values: a
|
|
109
|
+
* stop of one value has nothing to choose, so no key does anything there. A dumbbell's row holds
|
|
110
|
+
* two values, where it was and where it is; a ranked bar's row one. Undefined for any other key.
|
|
111
|
+
*/
|
|
112
|
+
function stepItem(key, snap, at) {
|
|
113
|
+
if (at.count < 2) return void 0;
|
|
114
|
+
if (key === CHOOSE[snap].on) return Math.min(at.index + 1, at.count - 1);
|
|
115
|
+
if (key === CHOOSE[snap].back) return Math.max(at.index - 1, 0);
|
|
116
|
+
}
|
|
117
|
+
export { stepHover, stepItem, stepStop };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/opens.ts
|
|
2
|
+
/** Whether selecting a value does something: there is `onSelect`, and the value opens. */
|
|
3
|
+
const opens = (callbacks, stop, item) => callbacks.onSelect !== void 0 && (callbacks.selectable?.(stop, item) ?? true);
|
|
4
|
+
/** Whether some value of the scene opens: what the chart is marked drillable and described by. */
|
|
5
|
+
const opensAny = (callbacks, scene) => callbacks.onSelect !== void 0 && (scene?.hover?.stops ?? []).some((stop) => stop.items.some((item) => opens(callbacks, stop, item)));
|
|
6
|
+
/** The item the lit stop means: the one the keyboard chose, or the one nearest the pointer. */
|
|
7
|
+
function chosenItem(lit, stop) {
|
|
8
|
+
return lit === void 0 ? void 0 : stop?.items[lit.item];
|
|
9
|
+
}
|
|
10
|
+
/** Whether the lit stop offers something to select: whether the item it means opens. */
|
|
11
|
+
function offers(callbacks, lit, stop) {
|
|
12
|
+
const item = chosenItem(lit, stop);
|
|
13
|
+
return stop !== void 0 && item !== void 0 && opens(callbacks, stop, item);
|
|
14
|
+
}
|
|
15
|
+
/** What a screen reader hears for the item the lit stop means, when it opens and has a spoken form. */
|
|
16
|
+
function spokenOf(callbacks, lit, stop) {
|
|
17
|
+
const item = chosenItem(lit, stop);
|
|
18
|
+
return stop === void 0 || item === void 0 || !offers(callbacks, lit, stop) ? void 0 : callbacks.spoken?.(stop, item);
|
|
19
|
+
}
|
|
20
|
+
/** A stop with a value to open, with its place; undefined for none or a gap. */
|
|
21
|
+
const valued = (stops, index) => {
|
|
22
|
+
const found = index === void 0 ? void 0 : stops[index];
|
|
23
|
+
return index === void 0 || found === void 0 || found.items.length === 0 ? void 0 : {
|
|
24
|
+
index,
|
|
25
|
+
stop: found
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export { offers, opens, opensAny, spokenOf, valued };
|