derive-dashboards 0.6.0 → 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/dist/charts/kinds/area-marks.mjs +2 -1
- package/dist/charts/kinds/funnel-words.mjs +1 -1
- package/dist/charts/kinds/grid-marks.mjs +9 -4
- package/dist/charts/theme.d.mts +13 -13
- package/dist/charts/theme.mjs +17 -14
- package/dist/charts-react/Overlay.mjs +1 -0
- package/dist/charts-react/chart-unlayered.css +1 -107
- package/dist/charts-react/chart.css +1 -121
- package/dist/charts-react/tip-place.mjs +30 -15
- package/dist/core/document/display-comparisons.mjs +49 -0
- 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 +6 -12
- package/dist/core/document/display.mjs +23 -48
- 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/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/index.d.mts +6 -5
- package/dist/core/index.mjs +8 -7
- package/dist/core/model/validate/fields.mjs +1 -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 +1 -1
- package/dist/core/query/drill/types.d.mts +7 -0
- package/dist/core/query/drill/types.mjs +3 -1
- package/dist/core/schema/answers.d.mts +1176 -362
- 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/tools.mjs +13 -0
- package/dist/core/time/index.d.mts +2 -2
- package/dist/core/time/text-time.d.mts +9 -2
- package/dist/core/time/text-time.mjs +18 -3
- 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/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 +19 -7
- package/dist/react/english.d.mts +1 -0
- package/dist/react/english.mjs +1 -0
- 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 +1 -0
- package/dist/react/format-time.mjs +39 -33
- package/dist/react/format.mjs +10 -1
- 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/theme-unlayered.css +1 -3148
- package/dist/react/theme.css +1 -3150
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +4 -2
- package/dist/store/apply.mjs +2 -2
- package/dist/store/editor.mjs +2 -2
- package/dist/store/writer.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,33 +1,43 @@
|
|
|
1
|
+
import { lastIncludedMillisecond } from "derive-dashboards/core";
|
|
1
2
|
// src/format-time.ts
|
|
2
3
|
/** Date formats by locale and style, made once: a table would make one for every cell of a time column. */
|
|
3
4
|
const FORMATS = /* @__PURE__ */ new Map();
|
|
4
|
-
/** The date format for a locale and a style, made once. */
|
|
5
|
-
function dateFormat(locale, style) {
|
|
6
|
-
const key = `${locale ?? ""}|${JSON.stringify(style)}`;
|
|
7
|
-
const made = FORMATS.get(key) ?? new Intl.DateTimeFormat(locale, style);
|
|
8
|
-
FORMATS.set(key, made);
|
|
9
|
-
return made;
|
|
10
|
-
}
|
|
11
5
|
const DATE_LABEL = /^\d{4}-\d{2}-\d{2}$/u;
|
|
12
|
-
const
|
|
6
|
+
const STYLES = {
|
|
13
7
|
day: {
|
|
14
8
|
month: "short",
|
|
15
9
|
day: "numeric"
|
|
16
10
|
},
|
|
17
|
-
|
|
18
|
-
month: "short",
|
|
19
|
-
day: "numeric"
|
|
20
|
-
},
|
|
21
|
-
month: {
|
|
11
|
+
dated: {
|
|
22
12
|
month: "short",
|
|
13
|
+
day: "numeric",
|
|
23
14
|
year: "numeric"
|
|
24
15
|
},
|
|
25
|
-
|
|
16
|
+
month: {
|
|
26
17
|
month: "short",
|
|
27
18
|
year: "numeric"
|
|
28
19
|
},
|
|
29
|
-
year: { year: "numeric" }
|
|
20
|
+
year: { year: "numeric" },
|
|
21
|
+
hour: {
|
|
22
|
+
dateStyle: "medium",
|
|
23
|
+
timeStyle: "short"
|
|
24
|
+
}
|
|
30
25
|
};
|
|
26
|
+
function styleFor(grain, withYear = false) {
|
|
27
|
+
if (grain === "week" || grain === "day") return withYear ? "dated" : "day";
|
|
28
|
+
return grain === "quarter" ? "month" : grain;
|
|
29
|
+
}
|
|
30
|
+
function dateFormat(locale, style, timeZone) {
|
|
31
|
+
const key = `${locale ?? ""}|${style}|${timeZone ?? ""}`;
|
|
32
|
+
const cached = FORMATS.get(key);
|
|
33
|
+
if (cached !== void 0) return cached;
|
|
34
|
+
const made = new Intl.DateTimeFormat(locale, {
|
|
35
|
+
...STYLES[style],
|
|
36
|
+
timeZone
|
|
37
|
+
});
|
|
38
|
+
FORMATS.set(key, made);
|
|
39
|
+
return made;
|
|
40
|
+
}
|
|
31
41
|
/**
|
|
32
42
|
* A time bucket's label for a person: "Nov 2" for a day or week, "Jun 2026" for a month or
|
|
33
43
|
* the month a (possibly fiscal) quarter starts. The label names a calendar date, so it is formatted as that date,
|
|
@@ -38,21 +48,13 @@ function formatBucket(label, grain, locale, withYear = false) {
|
|
|
38
48
|
const [year = 0, month = 1, day = 1] = label.split("-").map(Number);
|
|
39
49
|
const date = /* @__PURE__ */ new Date(0);
|
|
40
50
|
date.setUTCFullYear(year, month - 1, day);
|
|
41
|
-
return dateFormat(locale,
|
|
42
|
-
...BUCKET_FORMATS[grain],
|
|
43
|
-
...withYear ? { year: "numeric" } : {},
|
|
44
|
-
timeZone: "UTC"
|
|
45
|
-
}).format(date);
|
|
51
|
+
return dateFormat(locale, styleFor(grain, withYear), "UTC").format(date);
|
|
46
52
|
}
|
|
47
53
|
/** An instant (text time to the microsecond) as a date and time, in a zone (the dashboard's) or the viewer's own. */
|
|
48
54
|
function formatInstant(text, locale, timeZone) {
|
|
49
55
|
const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
|
|
50
56
|
if (Number.isNaN(date.getTime())) return text;
|
|
51
|
-
return dateFormat(locale,
|
|
52
|
-
dateStyle: "medium",
|
|
53
|
-
timeStyle: "short",
|
|
54
|
-
...timeZone === void 0 ? {} : { timeZone }
|
|
55
|
-
}).format(date);
|
|
57
|
+
return dateFormat(locale, "hour", timeZone).format(date);
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* The bucket an instant starts, named at its grain in a zone, as a chart names it: "Nov 9" for
|
|
@@ -62,12 +64,16 @@ function formatInstant(text, locale, timeZone) {
|
|
|
62
64
|
function formatInstantAt(text, grain, locale, timeZone) {
|
|
63
65
|
const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
|
|
64
66
|
if (Number.isNaN(date.getTime())) return text;
|
|
65
|
-
return dateFormat(locale,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
return dateFormat(locale, styleFor(grain), timeZone).format(date);
|
|
68
|
+
}
|
|
69
|
+
/** The included calendar days in a receipt, shared by tiles and every drill view. */
|
|
70
|
+
function formatPeriod(range, format, timeZone) {
|
|
71
|
+
const last = lastIncludedMillisecond(range);
|
|
72
|
+
if (last === void 0) return format.messages.noData;
|
|
73
|
+
const first = new Date(range.from);
|
|
74
|
+
const year = dateFormat(format.locale, "year", timeZone);
|
|
75
|
+
const crossesYear = year.format(first) !== year.format(last);
|
|
76
|
+
const day = dateFormat(format.locale, styleFor("day", crossesYear), timeZone);
|
|
77
|
+
return format.messages.drillRange(day.format(first), day.format(last));
|
|
72
78
|
}
|
|
73
|
-
export { formatBucket, formatInstant, formatInstantAt };
|
|
79
|
+
export { formatBucket, formatInstant, formatInstantAt, formatPeriod };
|
package/dist/react/format.mjs
CHANGED
|
@@ -17,6 +17,15 @@ function plotValue(cell) {
|
|
|
17
17
|
const value = Number(typeof cell === "string" ? cell : cell.v);
|
|
18
18
|
return Number.isFinite(value) ? value : null;
|
|
19
19
|
}
|
|
20
|
+
/** The unformatted key used for group matching, lexical sorting and template links. */
|
|
21
|
+
function rawCellText(cell) {
|
|
22
|
+
if (cell === void 0 || cell === null || isMark(cell)) return void 0;
|
|
23
|
+
return typeof cell === "object" ? cell.v : String(cell);
|
|
24
|
+
}
|
|
25
|
+
/** A dimension label identifies the missing field in tables and drill selections alike. */
|
|
26
|
+
function groupText(cell, column, format) {
|
|
27
|
+
return cell === null ? format.messages.drillNone(column?.label ?? "") : formatCell(cell, column, format);
|
|
28
|
+
}
|
|
20
29
|
/**
|
|
21
30
|
* A cell as text for a person, in their locale and words. A renderer can pass its own props as
|
|
22
31
|
* `format`: they carry both.
|
|
@@ -150,4 +159,4 @@ function formatTick(value, column, locale) {
|
|
|
150
159
|
...style
|
|
151
160
|
}).format(value);
|
|
152
161
|
}
|
|
153
|
-
export { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, plotValue };
|
|
162
|
+
export { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, groupText, plotValue, rawCellText };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isValue } from "../columns.mjs";
|
|
2
|
-
import { formatCell } from "../format.mjs";
|
|
2
|
+
import { formatCell, rawCellText } from "../format.mjs";
|
|
3
3
|
import { RowBody } from "../RowBody.mjs";
|
|
4
4
|
import { answerIds } from "./entries.mjs";
|
|
5
5
|
import { displayOf, isMark } from "derive-dashboards/core";
|
|
@@ -39,12 +39,12 @@ const text = ({ cells, at, props }, id) => {
|
|
|
39
39
|
const linkOf = (template, line) => {
|
|
40
40
|
let missing = false;
|
|
41
41
|
const href = template.replaceAll(/\{([^}]+)\}/gu, (_, id) => {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
42
|
+
const raw = rawCellText(line.cells[line.at(id)]);
|
|
43
|
+
if (raw === void 0) {
|
|
44
44
|
missing = true;
|
|
45
45
|
return "";
|
|
46
46
|
}
|
|
47
|
-
return encodeURIComponent(
|
|
47
|
+
return encodeURIComponent(raw);
|
|
48
48
|
});
|
|
49
49
|
return missing ? void 0 : href;
|
|
50
50
|
};
|
|
@@ -81,16 +81,14 @@ function ListTile(props) {
|
|
|
81
81
|
title: text(line, shown.title) || props.messages.empty,
|
|
82
82
|
meta: shown.subtitle.map((id) => text(line, id)).filter(Boolean),
|
|
83
83
|
lead: shown.avatar === void 0 ? void 0 : initials(text(line, shown.avatar)),
|
|
84
|
-
value: text(line, shown.meta)
|
|
84
|
+
value: text(line, shown.meta),
|
|
85
|
+
valueLabel: answer.columns[at(shown.meta)]?.label
|
|
85
86
|
};
|
|
86
|
-
const body = /* @__PURE__ */ jsx(RowBody, {
|
|
87
|
-
row,
|
|
88
|
-
family: "lines"
|
|
89
|
-
});
|
|
87
|
+
const body = /* @__PURE__ */ jsx(RowBody, { row });
|
|
90
88
|
const href = shown.href === void 0 ? void 0 : linkOf(shown.href, line);
|
|
91
89
|
return /* @__PURE__ */ jsx("li", { children: href === void 0 ? /* @__PURE__ */ jsx("div", {
|
|
92
90
|
className: "dd-lines-row",
|
|
93
|
-
...props.drill?.props(cells),
|
|
91
|
+
...props.drill?.props(cells, shown.meta),
|
|
94
92
|
children: body
|
|
95
93
|
}) : /* @__PURE__ */ jsx(Anchor, {
|
|
96
94
|
href,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isNumeric, isValue } from "../columns.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { compareGroupLabel } from "../drill/words.mjs";
|
|
3
|
+
import { formatCell, groupText, plotValue } from "../format.mjs";
|
|
3
4
|
import { depthOf, reachOf } from "./table-scale.mjs";
|
|
4
5
|
import { isMark } from "derive-dashboards/core";
|
|
5
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -37,7 +38,13 @@ function shadeOf(cell, how) {
|
|
|
37
38
|
* and its column's name is written before it for the eye alone, the header still naming it
|
|
38
39
|
* for a screen reader.
|
|
39
40
|
*/
|
|
40
|
-
const
|
|
41
|
+
const semantics = (at) => {
|
|
42
|
+
if (at.heading) return {
|
|
43
|
+
scope: "row",
|
|
44
|
+
role: at.cards ? "rowheader" : void 0
|
|
45
|
+
};
|
|
46
|
+
return at.cards ? { role: "cell" } : {};
|
|
47
|
+
};
|
|
41
48
|
/** The column's name before a card's cell. */
|
|
42
49
|
function Label({ column, at }) {
|
|
43
50
|
if (!at.cards) return null;
|
|
@@ -65,15 +72,16 @@ function valueBody(text, cell, at, how) {
|
|
|
65
72
|
/** A cell of a column of values: its number, with its bar or its shade when the column draws one. */
|
|
66
73
|
function ValueCell(props) {
|
|
67
74
|
const { cell, column, at, marks } = props;
|
|
75
|
+
const Tag = at.heading ? "th" : "td";
|
|
68
76
|
const how = at.total || cell === null ? void 0 : at.measured.get(column.id);
|
|
69
77
|
const text = how?.texts.get(at.place) ?? formatCell(cell, column, at.format);
|
|
70
78
|
const shade = shadeOf(cell, how);
|
|
71
|
-
return /* @__PURE__ */ jsxs(
|
|
79
|
+
return /* @__PURE__ */ jsxs(Tag, {
|
|
72
80
|
"data-numeric": "true",
|
|
73
81
|
"data-empty": cell === null ? "true" : void 0,
|
|
74
82
|
"data-heat": shade === void 0 ? void 0 : "true",
|
|
75
83
|
style: shade,
|
|
76
|
-
...
|
|
84
|
+
...semantics(at),
|
|
77
85
|
...marks,
|
|
78
86
|
children: [/* @__PURE__ */ jsx(Label, {
|
|
79
87
|
column,
|
|
@@ -83,8 +91,9 @@ function ValueCell(props) {
|
|
|
83
91
|
}
|
|
84
92
|
/** A cell of words: yes or no as a badge, anything else on one line, cut where it has no room. */
|
|
85
93
|
function WordCell({ cell, column, at }) {
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
const Tag = at.heading ? "th" : "td";
|
|
95
|
+
if (typeof cell === "boolean") return /* @__PURE__ */ jsxs(Tag, {
|
|
96
|
+
...semantics(at),
|
|
88
97
|
children: [/* @__PURE__ */ jsx(Label, {
|
|
89
98
|
column,
|
|
90
99
|
at
|
|
@@ -94,10 +103,10 @@ function WordCell({ cell, column, at }) {
|
|
|
94
103
|
children: formatCell(cell, column, at.format)
|
|
95
104
|
})]
|
|
96
105
|
});
|
|
97
|
-
const text =
|
|
98
|
-
return /* @__PURE__ */ jsxs(
|
|
106
|
+
const text = groupText(cell, column, at.format);
|
|
107
|
+
return /* @__PURE__ */ jsxs(Tag, {
|
|
99
108
|
"data-empty": cell === null ? "true" : void 0,
|
|
100
|
-
...
|
|
109
|
+
...semantics(at),
|
|
101
110
|
children: [/* @__PURE__ */ jsx(Label, {
|
|
102
111
|
column,
|
|
103
112
|
at
|
|
@@ -116,6 +125,26 @@ function Cell$1(props) {
|
|
|
116
125
|
role: at.cards ? "rowheader" : void 0,
|
|
117
126
|
children: formatCell(cell, column, at.format)
|
|
118
127
|
});
|
|
128
|
+
if (props.compare) {
|
|
129
|
+
const text = formatCell(cell, column, at.format);
|
|
130
|
+
const name = (at.format.messages.drillCompareGroup ?? compareGroupLabel)(props.compare.label);
|
|
131
|
+
return /* @__PURE__ */ jsxs("th", {
|
|
132
|
+
scope: "row",
|
|
133
|
+
role: at.cards ? "rowheader" : void 0,
|
|
134
|
+
children: [/* @__PURE__ */ jsx(Label, {
|
|
135
|
+
column,
|
|
136
|
+
at
|
|
137
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
138
|
+
type: "button",
|
|
139
|
+
className: "dd-compare-label",
|
|
140
|
+
"aria-label": name,
|
|
141
|
+
title: name,
|
|
142
|
+
"aria-haspopup": "dialog",
|
|
143
|
+
onClick: props.compare.open,
|
|
144
|
+
children: text
|
|
145
|
+
})]
|
|
146
|
+
});
|
|
147
|
+
}
|
|
119
148
|
return isValue(column) || isNumeric(column) && cell !== null ? /* @__PURE__ */ jsx(ValueCell, {
|
|
120
149
|
cell,
|
|
121
150
|
column,
|
|
@@ -18,12 +18,14 @@ function measure(asked, at, column, draws) {
|
|
|
18
18
|
heat: draws.shaded ? rangeOf(rows, at) : void 0
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
const NO_MEASURES = /* @__PURE__ */ new Map();
|
|
21
22
|
/**
|
|
22
23
|
* The value columns a widget draws beyond their numbers, by column id. `display.bars` and
|
|
23
24
|
* `display.heat` name entries as the widget's query does, or as the answer does.
|
|
24
25
|
*/
|
|
25
26
|
function measuredOf(asked) {
|
|
26
27
|
const display = displayOf("table", asked.widget.display);
|
|
28
|
+
if ((display.bars?.length ?? 0) === 0 && (display.heat?.length ?? 0) === 0) return NO_MEASURES;
|
|
27
29
|
const answerId = answerIds(asked.widget);
|
|
28
30
|
const bars = new Set((display.bars ?? []).map((entry) => answerId(entry)));
|
|
29
31
|
const heat = new Set((display.heat ?? []).map((entry) => answerId(entry)));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isValue } from "../columns.mjs";
|
|
2
|
+
import { groupText, rawCellText } from "../format.mjs";
|
|
2
3
|
import { Cell as Cell$1 } from "./table-cells.mjs";
|
|
3
4
|
import { isSummary, isTotal } from "./table-scale.mjs";
|
|
4
|
-
import { memo } from "react";
|
|
5
|
-
import { isMark } from "derive-dashboards/core";
|
|
5
|
+
import { memo, useMemo } from "react";
|
|
6
|
+
import { isMark, roleOf } from "derive-dashboards/core";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
// src/renderers/table-row.tsx
|
|
8
9
|
/** Cells as table cells: a run of equal marks is one cell spanning its columns. */
|
|
@@ -24,11 +25,63 @@ const markOf = (cells) => {
|
|
|
24
25
|
if (isTotal(cells)) return "all";
|
|
25
26
|
return isSummary(cells) ? "other" : void 0;
|
|
26
27
|
};
|
|
28
|
+
/** Keep a comparable row’s accessible name and action when sorting or resizing the table. */
|
|
29
|
+
function useComparisons(columns, groups, drill, format) {
|
|
30
|
+
const { locale, messages, timeZone } = format;
|
|
31
|
+
return useMemo(() => {
|
|
32
|
+
if (!groups || !drill?.compare) return;
|
|
33
|
+
const openGroup = drill.compare.bind(drill);
|
|
34
|
+
const place = columns.findIndex((c) => roleOf(c) === "dimension");
|
|
35
|
+
if (place < 0) return;
|
|
36
|
+
const labels = columns.flatMap((column, i) => isValue(column) ? [] : [{
|
|
37
|
+
column,
|
|
38
|
+
i
|
|
39
|
+
}]);
|
|
40
|
+
const known = /* @__PURE__ */ new WeakMap();
|
|
41
|
+
return (cells) => {
|
|
42
|
+
const cached = known.get(cells);
|
|
43
|
+
if (cached) return cached;
|
|
44
|
+
const name = rawCellText(cells[place]);
|
|
45
|
+
if (name === void 0 || !Object.hasOwn(groups, name) || isSummary(cells)) return;
|
|
46
|
+
const fields = groups[name];
|
|
47
|
+
if (!fields) return;
|
|
48
|
+
const [member, thenBy] = fields;
|
|
49
|
+
const open = openGroup(cells, {
|
|
50
|
+
by: "comparison",
|
|
51
|
+
member,
|
|
52
|
+
...thenBy !== void 0 && { thenBy }
|
|
53
|
+
});
|
|
54
|
+
if (!open) return;
|
|
55
|
+
const label = labels.map(({ column, i }) => groupText(cells[i] ?? null, column, {
|
|
56
|
+
locale,
|
|
57
|
+
messages,
|
|
58
|
+
timeZone
|
|
59
|
+
})).join(" · ");
|
|
60
|
+
const action = {
|
|
61
|
+
open,
|
|
62
|
+
place,
|
|
63
|
+
label
|
|
64
|
+
};
|
|
65
|
+
known.set(cells, action);
|
|
66
|
+
return action;
|
|
67
|
+
};
|
|
68
|
+
}, [
|
|
69
|
+
columns,
|
|
70
|
+
groups,
|
|
71
|
+
drill,
|
|
72
|
+
locale,
|
|
73
|
+
messages,
|
|
74
|
+
timeZone
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
27
77
|
/** One table row. A row that folds dimensions is a summary, labelled where it folds them. */
|
|
28
|
-
function RowOf(
|
|
78
|
+
function RowOf(props) {
|
|
79
|
+
const { cells, columns, ruled, drill, ...at } = props;
|
|
80
|
+
const compare = props.comparison?.(cells);
|
|
29
81
|
const mark = markOf(cells);
|
|
30
|
-
const whole = drill?.props(cells);
|
|
82
|
+
const whole = compare ? void 0 : drill?.props(cells);
|
|
31
83
|
const cellMarks = (column) => whole === void 0 && column !== void 0 && isValue(column) ? drill?.props(cells, column.id) : void 0;
|
|
84
|
+
const heading = columns.findIndex((column) => roleOf(column) === "dimension");
|
|
32
85
|
const cellAt = {
|
|
33
86
|
...at,
|
|
34
87
|
total: mark === "all",
|
|
@@ -46,8 +99,12 @@ function RowOf({ cells, columns, ruled, drill, ...at }) {
|
|
|
46
99
|
cell,
|
|
47
100
|
column,
|
|
48
101
|
span,
|
|
49
|
-
at:
|
|
50
|
-
|
|
102
|
+
at: {
|
|
103
|
+
...cellAt,
|
|
104
|
+
heading: place === heading
|
|
105
|
+
},
|
|
106
|
+
marks: cellMarks(column),
|
|
107
|
+
compare: compare?.place === place ? compare : void 0
|
|
51
108
|
}, column?.id ?? place);
|
|
52
109
|
})
|
|
53
110
|
});
|
|
@@ -58,4 +115,4 @@ function RowOf({ cells, columns, ruled, drill, ...at }) {
|
|
|
58
115
|
* object made anew at every draw.
|
|
59
116
|
*/
|
|
60
117
|
const Row = memo(RowOf);
|
|
61
|
-
export { Row };
|
|
118
|
+
export { Row, useComparisons };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNumeric, isValue } from "../columns.mjs";
|
|
2
|
+
import { rawCellText } from "../format.mjs";
|
|
2
3
|
import { compareExact, digitsOf } from "./exact.mjs";
|
|
3
4
|
import { isSummary } from "./table-scale.mjs";
|
|
4
|
-
import { isMark } from "derive-dashboards/core";
|
|
5
5
|
// src/renderers/table-sort.ts
|
|
6
6
|
/**
|
|
7
7
|
* Whether a table's rows can be sorted: every row that folds dimensions comes after every row
|
|
@@ -37,12 +37,6 @@ const floatOf = (cell) => {
|
|
|
37
37
|
if (typeof cell === "string") return cell.trim() === "" ? NaN : Number(cell);
|
|
38
38
|
return cell !== null && typeof cell === "object" && "v" in cell ? Number(cell.v) : NaN;
|
|
39
39
|
};
|
|
40
|
-
/** A cell as words to sort by: text as it is, yes after no, an exact value by its digits. */
|
|
41
|
-
function wordsOf(cell) {
|
|
42
|
-
if (typeof cell === "string") return cell;
|
|
43
|
-
if (typeof cell === "number" || typeof cell === "boolean") return String(cell);
|
|
44
|
-
return cell === null || isMark(cell) ? "" : cell.v;
|
|
45
|
-
}
|
|
46
40
|
/**
|
|
47
41
|
* Numbers by size. Each cell is read as a float once, before the sort. Two that differ as
|
|
48
42
|
* floats stand as their floats do, since a float never puts a larger decimal below a smaller
|
|
@@ -64,7 +58,7 @@ function byNumber(cells, floats) {
|
|
|
64
58
|
* anything else as words in the reader's language.
|
|
65
59
|
*/
|
|
66
60
|
function byWords(column, cells, locale) {
|
|
67
|
-
const words = cells.map((cell) =>
|
|
61
|
+
const words = cells.map((cell) => rawCellText(cell) ?? "");
|
|
68
62
|
if (column.type === "time") return (a, b) => words[a] === words[b] ? 0 : (words[a] ?? "") < (words[b] ?? "") ? -1 : 1;
|
|
69
63
|
const collator = new Intl.Collator(locale, {
|
|
70
64
|
numeric: true,
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { nameCut, useFit } from "./table-fit.mjs";
|
|
2
2
|
import { Head } from "./table-head.mjs";
|
|
3
3
|
import { drawnOf, measuredOf } from "./table-measure.mjs";
|
|
4
|
-
import { Row } from "./table-row.mjs";
|
|
4
|
+
import { Row, useComparisons } from "./table-row.mjs";
|
|
5
5
|
import { isSummary, isTotal } from "./table-scale.mjs";
|
|
6
6
|
import { orderOf, sortable } from "./table-sort.mjs";
|
|
7
7
|
import { useMemo, useState } from "react";
|
|
8
8
|
import { displayOf } from "derive-dashboards/core";
|
|
9
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
// src/renderers/table.tsx
|
|
11
11
|
/** Under a long table that draws its first rows only: the button that draws more. Nothing under a table drawn whole. */
|
|
12
|
-
function More({ hidden, of, onMore, tile }) {
|
|
12
|
+
function More({ hidden, of, onMore, table, tile }) {
|
|
13
13
|
if (hidden <= 0) return null;
|
|
14
14
|
const written = (count) => count.toLocaleString(tile.locale);
|
|
15
15
|
return /* @__PURE__ */ jsx("button", {
|
|
16
16
|
type: "button",
|
|
17
17
|
className: "dd-table-more",
|
|
18
|
-
onClick:
|
|
18
|
+
onClick: () => {
|
|
19
|
+
if (hidden <= 500) table.current?.focus();
|
|
20
|
+
onMore();
|
|
21
|
+
},
|
|
19
22
|
children: tile.messages.showMoreRows(written(Math.min(hidden, 500)), written(of))
|
|
20
23
|
});
|
|
21
24
|
}
|
|
@@ -78,16 +81,12 @@ function TableTile(props) {
|
|
|
78
81
|
const [table, fit] = useFit(props.answer);
|
|
79
82
|
const cards = fit === "cards";
|
|
80
83
|
const { measured, drawn, drawMore, plain, hidden } = useRows(props, sort);
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
const compact = displayOf("table", props.widget.display).compact === true;
|
|
86
|
-
const onSort = sortable(rows) ? setSort : void 0;
|
|
87
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("table", {
|
|
84
|
+
const { compact, comparisons } = displayOf("table", props.widget.display);
|
|
85
|
+
const comparison = useComparisons(columns, comparisons, props.drill, props);
|
|
86
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("table", {
|
|
88
87
|
ref: table,
|
|
89
88
|
className: "dd-table",
|
|
90
|
-
"data-density": compact ? "compact" : void 0,
|
|
89
|
+
"data-density": compact === true ? "compact" : void 0,
|
|
91
90
|
"data-layout": fit === "columns" ? void 0 : fit,
|
|
92
91
|
role: cards ? "table" : void 0,
|
|
93
92
|
tabIndex: -1,
|
|
@@ -95,7 +94,7 @@ function TableTile(props) {
|
|
|
95
94
|
children: [/* @__PURE__ */ jsx(Head, {
|
|
96
95
|
columns,
|
|
97
96
|
sort,
|
|
98
|
-
onSort,
|
|
97
|
+
onSort: sortable(rows) ? setSort : void 0,
|
|
99
98
|
cards,
|
|
100
99
|
messages: props.messages
|
|
101
100
|
}), /* @__PURE__ */ jsx("tbody", {
|
|
@@ -108,13 +107,15 @@ function TableTile(props) {
|
|
|
108
107
|
place,
|
|
109
108
|
cards,
|
|
110
109
|
ruled: isTotal(rows[drawn[i + 1] ?? -1] ?? []),
|
|
111
|
-
drill: props.drill
|
|
110
|
+
drill: props.drill,
|
|
111
|
+
comparison
|
|
112
112
|
}, place))
|
|
113
113
|
})]
|
|
114
114
|
}), /* @__PURE__ */ jsx(More, {
|
|
115
115
|
hidden,
|
|
116
116
|
of: plain,
|
|
117
|
-
onMore,
|
|
117
|
+
onMore: drawMore,
|
|
118
|
+
table,
|
|
118
119
|
tile: props
|
|
119
120
|
})] });
|
|
120
121
|
}
|