derive-dashboards 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/cli/check.mjs +36 -1
- package/dist/cli/doctor.mjs +2 -2
- package/dist/core/document/display-entries.mjs +48 -0
- package/dist/core/document/display.d.mts +15 -3
- package/dist/core/document/display.mjs +35 -11
- package/dist/core/engine/filter.mjs +4 -2
- 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 -0
- package/dist/core/error/codes.mjs +2 -0
- package/dist/core/index.d.mts +4 -3
- package/dist/core/index.mjs +8 -7
- package/dist/core/model/catalog/check.mjs +11 -5
- package/dist/core/model/member.mjs +6 -1
- package/dist/core/model/validate/members.mjs +31 -1
- package/dist/core/oracle/visibility.mjs +3 -1
- package/dist/core/query/drill/line.mjs +2 -2
- package/dist/core/query/to-wire.d.mts +7 -0
- package/dist/core/query/to-wire.mjs +18 -7
- package/dist/core/result/additive.d.mts +9 -0
- package/dist/core/result/additive.mjs +59 -0
- package/dist/core/result/columns.mjs +8 -2
- package/dist/core/result/types.d.mts +12 -0
- package/dist/core/schema/answer-parts.mjs +2 -1
- package/dist/core/schema/answers.d.mts +6 -0
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/handler.mjs +10 -2
- package/dist/index.mjs +1 -1
- package/dist/llms.txt +1 -1
- package/dist/react/History.mjs +1 -1
- package/dist/react/Tile.mjs +18 -10
- package/dist/react/builder/FilterEditor.mjs +2 -7
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/columns.mjs +15 -0
- package/dist/react/context.d.mts +7 -0
- package/dist/react/context.mjs +3 -0
- package/dist/react/digits.mjs +46 -0
- package/dist/react/drill/Bars.mjs +2 -1
- package/dist/react/drill/Controls.mjs +2 -1
- package/dist/react/drill/Header.mjs +2 -1
- package/dist/react/drill/Items.mjs +6 -1
- package/dist/react/drill/Notes.mjs +2 -1
- package/dist/react/drill/item-parts.mjs +2 -1
- package/dist/react/english.mjs +4 -0
- package/dist/react/export/ExportButton.mjs +23 -0
- package/dist/react/export/csv.d.mts +9 -0
- package/dist/react/export/csv.mjs +42 -0
- package/dist/react/export/download.d.mts +5 -0
- package/dist/react/export/download.mjs +61 -0
- package/dist/react/format-time.d.mts +15 -0
- package/dist/react/format-time.mjs +71 -0
- package/dist/react/format.d.mts +6 -16
- package/dist/react/format.mjs +48 -86
- package/dist/react/index.d.mts +8 -3
- package/dist/react/index.mjs +8 -3
- package/dist/react/messages.d.mts +8 -0
- package/dist/react/renderers/entries.mjs +15 -0
- package/dist/react/renderers/exact.d.mts +6 -0
- package/dist/react/renderers/exact.mjs +68 -0
- package/dist/react/renderers/index.d.mts +5 -11
- package/dist/react/renderers/index.mjs +70 -84
- package/dist/react/renderers/list.mjs +5 -17
- package/dist/react/renderers/table-cells.mjs +130 -0
- package/dist/react/renderers/table-fit.mjs +52 -0
- package/dist/react/renderers/table-head.mjs +47 -0
- package/dist/react/renderers/table-measure.mjs +49 -0
- package/dist/react/renderers/table-row.mjs +61 -0
- package/dist/react/renderers/table-scale.mjs +70 -0
- package/dist/react/renderers/table-sort.mjs +99 -0
- package/dist/react/renderers/table.d.mts +3 -0
- package/dist/react/renderers/table.mjs +121 -0
- package/dist/react/series.mjs +1 -1
- package/dist/react/theme-unlayered.css +3144 -0
- package/dist/react/theme-unlayered.css.d.ts +1 -0
- package/dist/react/theme.css +379 -8
- package/dist/recharts/axes.mjs +13 -10
- package/dist/recharts/axis.mjs +25 -1
- package/dist/recharts/bar.d.mts +2 -1
- package/dist/recharts/bar.mjs +29 -6
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +13 -1
- package/package.json +42 -4
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { isNumeric, isValue } from "../columns.mjs";
|
|
2
|
+
import { compareExact, digitsOf } from "./exact.mjs";
|
|
3
|
+
import { isSummary } from "./table-scale.mjs";
|
|
4
|
+
import { isMark } from "derive-dashboards/core";
|
|
5
|
+
// src/renderers/table-sort.ts
|
|
6
|
+
/**
|
|
7
|
+
* Whether a table's rows can be sorted: every row that folds dimensions comes after every row
|
|
8
|
+
* that does not. A table with a subtotal between its groups keeps the order it was given, since
|
|
9
|
+
* sorting would part a subtotal from its rows.
|
|
10
|
+
*/
|
|
11
|
+
function sortable(rows) {
|
|
12
|
+
const first = rows.findIndex((cells) => isSummary(cells));
|
|
13
|
+
return first === -1 || rows.slice(first).every((cells) => isSummary(cells));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The sort after a click on a column's header: values largest first and words A to Z, then the
|
|
17
|
+
* other way round, then the answer's own order again.
|
|
18
|
+
*/
|
|
19
|
+
function nextSort(sort, column) {
|
|
20
|
+
const first = isValue(column) ? "descending" : "ascending";
|
|
21
|
+
if (sort?.id !== column.id) return {
|
|
22
|
+
id: column.id,
|
|
23
|
+
way: first
|
|
24
|
+
};
|
|
25
|
+
if (sort.way !== first) return void 0;
|
|
26
|
+
return {
|
|
27
|
+
id: column.id,
|
|
28
|
+
way: first === "ascending" ? "descending" : "ascending"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A number's cell as a float, for a first comparison: past what a float holds it is infinite,
|
|
33
|
+
* and a cell that is no number (a text that is none, a fold) is not a number here either.
|
|
34
|
+
*/
|
|
35
|
+
const floatOf = (cell) => {
|
|
36
|
+
if (typeof cell === "number") return cell;
|
|
37
|
+
if (typeof cell === "string") return cell.trim() === "" ? NaN : Number(cell);
|
|
38
|
+
return cell !== null && typeof cell === "object" && "v" in cell ? Number(cell.v) : NaN;
|
|
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
|
+
/**
|
|
47
|
+
* Numbers by size. Each cell is read as a float once, before the sort. Two that differ as
|
|
48
|
+
* floats stand as their floats do, since a float never puts a larger decimal below a smaller
|
|
49
|
+
* one; two a float cannot tell apart are told apart by their digits, an exact amount's own
|
|
50
|
+
* and a float's as it is written.
|
|
51
|
+
*/
|
|
52
|
+
function byNumber(cells, floats) {
|
|
53
|
+
return (a, b) => {
|
|
54
|
+
const [p, q] = [floats[a] ?? 0, floats[b] ?? 0];
|
|
55
|
+
if (p !== q) return p < q ? -1 : 1;
|
|
56
|
+
if (typeof cells[a] === "number" && typeof cells[b] === "number") return 0;
|
|
57
|
+
const [x, y] = [digitsOf(cells[a]), digitsOf(cells[b])];
|
|
58
|
+
return x !== void 0 && y !== void 0 ? compareExact(x, y) : 0;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* How the rows stand in a column of words, smaller first, from the column's cell of each row
|
|
63
|
+
* by its place: a time by its text, which is written to sort as its instant does, and
|
|
64
|
+
* anything else as words in the reader's language.
|
|
65
|
+
*/
|
|
66
|
+
function byWords(column, cells, locale) {
|
|
67
|
+
const words = cells.map((cell) => wordsOf(cell));
|
|
68
|
+
if (column.type === "time") return (a, b) => words[a] === words[b] ? 0 : (words[a] ?? "") < (words[b] ?? "") ? -1 : 1;
|
|
69
|
+
const collator = new Intl.Collator(locale, {
|
|
70
|
+
numeric: true,
|
|
71
|
+
sensitivity: "base"
|
|
72
|
+
});
|
|
73
|
+
return (a, b) => collator.compare(words[a] ?? "", words[b] ?? "");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The rows in a viewer's order, each named by its place in the answer: those that fold
|
|
77
|
+
* dimensions where they were, the rest by the column, a row with no value there last whichever
|
|
78
|
+
* way. Rows that stand alike keep the answer's order. With no sort, or a table that cannot be
|
|
79
|
+
* sorted, the answer's own order. A place names one row, so two rows that read alike stay two.
|
|
80
|
+
*/
|
|
81
|
+
function orderOf(rows, columns, how) {
|
|
82
|
+
const all = rows.map((_, place) => place);
|
|
83
|
+
const at = columns.findIndex((column) => column.id === how.sort?.id);
|
|
84
|
+
const column = columns[at];
|
|
85
|
+
if (how.sort === void 0 || column === void 0 || !sortable(rows)) return all;
|
|
86
|
+
const cells = rows.map((row) => row[at] ?? null);
|
|
87
|
+
const floats = isNumeric(column) ? cells.map((cell) => floatOf(cell)) : void 0;
|
|
88
|
+
const compare = floats === void 0 ? byWords(column, cells, how.locale) : byNumber(cells, floats);
|
|
89
|
+
const valued = (place) => cells[place] !== null && !(floats !== void 0 && Number.isNaN(floats[place]));
|
|
90
|
+
const turn = how.sort.way === "ascending" ? 1 : -1;
|
|
91
|
+
const folds = all.filter((place) => isSummary(rows[place] ?? []));
|
|
92
|
+
const plain = all.filter((place) => !isSummary(rows[place] ?? []));
|
|
93
|
+
return [
|
|
94
|
+
...plain.filter((place) => valued(place)).toSorted((a, b) => turn * compare(a, b)),
|
|
95
|
+
...plain.filter((place) => !valued(place)),
|
|
96
|
+
...folds
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
export { nextSort, orderOf, sortable };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { nameCut, useFit } from "./table-fit.mjs";
|
|
2
|
+
import { Head } from "./table-head.mjs";
|
|
3
|
+
import { drawnOf, measuredOf } from "./table-measure.mjs";
|
|
4
|
+
import { Row } from "./table-row.mjs";
|
|
5
|
+
import { isSummary, isTotal } from "./table-scale.mjs";
|
|
6
|
+
import { orderOf, sortable } from "./table-sort.mjs";
|
|
7
|
+
import { useMemo, useState } from "react";
|
|
8
|
+
import { displayOf } from "derive-dashboards/core";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/renderers/table.tsx
|
|
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 }) {
|
|
13
|
+
if (hidden <= 0) return null;
|
|
14
|
+
const written = (count) => count.toLocaleString(tile.locale);
|
|
15
|
+
return /* @__PURE__ */ jsx("button", {
|
|
16
|
+
type: "button",
|
|
17
|
+
className: "dd-table-more",
|
|
18
|
+
onClick: onMore,
|
|
19
|
+
children: tile.messages.showMoreRows(written(Math.min(hidden, 500)), written(of))
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The rows a table draws, in a viewer's order, and what its value columns are measured against:
|
|
24
|
+
* each worked out once for an answer, a sort and the rows drawn, not on every draw. A long
|
|
25
|
+
* table draws its first rows, and more with each press of its button.
|
|
26
|
+
*/
|
|
27
|
+
function useRows({ answer, widget, locale, messages }, sort) {
|
|
28
|
+
const { columns, rows } = answer;
|
|
29
|
+
const [limit, setLimit] = useState(500);
|
|
30
|
+
const [seen, setSeen] = useState(answer);
|
|
31
|
+
if (seen !== answer) {
|
|
32
|
+
setSeen(answer);
|
|
33
|
+
setLimit(500);
|
|
34
|
+
}
|
|
35
|
+
const order = useMemo(() => orderOf(rows, columns, {
|
|
36
|
+
sort,
|
|
37
|
+
locale
|
|
38
|
+
}), [
|
|
39
|
+
rows,
|
|
40
|
+
columns,
|
|
41
|
+
sort,
|
|
42
|
+
locale
|
|
43
|
+
]);
|
|
44
|
+
const drawn = useMemo(() => drawnOf(order, rows, limit), [
|
|
45
|
+
order,
|
|
46
|
+
rows,
|
|
47
|
+
limit
|
|
48
|
+
]);
|
|
49
|
+
const written = drawn.length < rows.length ? drawn : void 0;
|
|
50
|
+
const measured = useMemo(() => measuredOf({
|
|
51
|
+
answer,
|
|
52
|
+
widget,
|
|
53
|
+
locale,
|
|
54
|
+
messages,
|
|
55
|
+
drawn: written
|
|
56
|
+
}), [
|
|
57
|
+
answer,
|
|
58
|
+
widget,
|
|
59
|
+
locale,
|
|
60
|
+
messages,
|
|
61
|
+
written
|
|
62
|
+
]);
|
|
63
|
+
const drawMore = () => {
|
|
64
|
+
setLimit((now) => now + 500);
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
measured,
|
|
68
|
+
drawn,
|
|
69
|
+
drawMore,
|
|
70
|
+
plain: useMemo(() => rows.filter((cells) => !isSummary(cells)).length, [rows]),
|
|
71
|
+
hidden: order.length - drawn.length
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Every row and column: the groups, then Other and the total under them. */
|
|
75
|
+
function TableTile(props) {
|
|
76
|
+
const { columns, rows } = props.answer;
|
|
77
|
+
const [sort, setSort] = useState();
|
|
78
|
+
const [table, fit] = useFit(props.answer);
|
|
79
|
+
const cards = fit === "cards";
|
|
80
|
+
const { measured, drawn, drawMore, plain, hidden } = useRows(props, sort);
|
|
81
|
+
const onMore = () => {
|
|
82
|
+
if (hidden <= 500) table.current?.focus();
|
|
83
|
+
drawMore();
|
|
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", {
|
|
88
|
+
ref: table,
|
|
89
|
+
className: "dd-table",
|
|
90
|
+
"data-density": compact ? "compact" : void 0,
|
|
91
|
+
"data-layout": fit === "columns" ? void 0 : fit,
|
|
92
|
+
role: cards ? "table" : void 0,
|
|
93
|
+
tabIndex: -1,
|
|
94
|
+
onPointerOver: nameCut,
|
|
95
|
+
children: [/* @__PURE__ */ jsx(Head, {
|
|
96
|
+
columns,
|
|
97
|
+
sort,
|
|
98
|
+
onSort,
|
|
99
|
+
cards,
|
|
100
|
+
messages: props.messages
|
|
101
|
+
}), /* @__PURE__ */ jsx("tbody", {
|
|
102
|
+
role: cards ? "rowgroup" : void 0,
|
|
103
|
+
children: drawn.map((place, i) => /* @__PURE__ */ jsx(Row, {
|
|
104
|
+
cells: rows[place] ?? [],
|
|
105
|
+
columns,
|
|
106
|
+
format: props,
|
|
107
|
+
measured,
|
|
108
|
+
place,
|
|
109
|
+
cards,
|
|
110
|
+
ruled: isTotal(rows[drawn[i + 1] ?? -1] ?? []),
|
|
111
|
+
drill: props.drill
|
|
112
|
+
}, place))
|
|
113
|
+
})]
|
|
114
|
+
}), /* @__PURE__ */ jsx(More, {
|
|
115
|
+
hidden,
|
|
116
|
+
of: plain,
|
|
117
|
+
onMore,
|
|
118
|
+
tile: props
|
|
119
|
+
})] });
|
|
120
|
+
}
|
|
121
|
+
export { TableTile };
|
package/dist/react/series.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { isValue } from "./columns.mjs";
|
|
1
2
|
import { formatCell, plotValue } from "./format.mjs";
|
|
2
3
|
import { ENGLISH } from "./english.mjs";
|
|
3
4
|
import { seriesSlots } from "./series-slots.mjs";
|
|
4
5
|
import { isMark, roleOf } from "derive-dashboards/core";
|
|
5
6
|
// src/series.ts
|
|
6
|
-
const isValue = (c) => roleOf(c) === "measure" || roleOf(c) === "calc";
|
|
7
7
|
/** The series key a dimension's Other draws as. */
|
|
8
8
|
const OTHER_KEY = "other";
|
|
9
9
|
/** Whether a cell is the given mark: Other, or the total row's All. */
|