derive-dashboards 0.9.0 → 0.11.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/CHANGELOG.md +67 -0
- package/dist/body.mjs +5 -1
- package/dist/charts/data/words.d.mts +5 -0
- package/dist/charts/data/words.mjs +1 -0
- package/dist/charts/kinds/columns-data.mjs +4 -1
- package/dist/charts/kinds/grid-layout.mjs +84 -8
- package/dist/charts/kinds/grid-legend.mjs +27 -4
- package/dist/charts/kinds/grid-marks.mjs +56 -4
- package/dist/charts/kinds/grid.mjs +2 -1
- package/dist/charts/scale/value.mjs +15 -8
- package/dist/charts/scene/types.d.mts +1 -1
- package/dist/core/document/display-entries.mjs +9 -2
- package/dist/core/document/display.d.mts +7 -3
- package/dist/core/document/display.mjs +15 -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 +2 -2
- package/dist/core/index.mjs +3 -3
- package/dist/core/model/member.d.mts +6 -0
- package/dist/core/model/member.mjs +11 -1
- package/dist/core/model/types.d.mts +6 -0
- package/dist/core/model/validate/known-members.mjs +1 -0
- package/dist/core/model/validate/members.mjs +12 -1
- package/dist/core/query/closure.mjs +2 -0
- package/dist/core/query/drill/links.mjs +16 -4
- package/dist/core/result/columns.mjs +15 -2
- package/dist/core/result/types.d.mts +2 -0
- package/dist/core/schema/answer-parts.mjs +1 -0
- package/dist/core/schema/answers.d.mts +14 -0
- package/dist/core/schema/answers.mjs +4 -2
- package/dist/core/schema/tools.mjs +4 -0
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/endpoints/index.d.mts +5 -4
- package/dist/endpoints/meta.mjs +30 -12
- package/dist/endpoints/query.mjs +11 -5
- package/dist/endpoints/values.mjs +38 -24
- package/dist/execute.mjs +22 -1
- package/dist/labels.mjs +68 -0
- package/dist/listing.mjs +13 -0
- package/dist/react/Canvas.mjs +28 -2
- package/dist/react/Cell.mjs +1 -1
- package/dist/react/Dashboard.d.mts +2 -3
- package/dist/react/Tile.d.mts +1 -1
- package/dist/react/arrange-steps.mjs +99 -11
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/base.mjs +11 -6
- package/dist/react/builder/display.mjs +16 -2
- package/dist/react/builder/state.mjs +3 -3
- package/dist/react/builder/words.mjs +8 -0
- package/dist/react/dates-shown.mjs +27 -9
- package/dist/react/filters/bar.d.mts +1 -1
- package/dist/react/filters/bar.mjs +17 -7
- package/dist/react/filters/chip.mjs +5 -3
- package/dist/react/filters/context.mjs +2 -2
- package/dist/react/filters/dates-said.mjs +29 -11
- package/dist/react/filters/hooks.d.mts +8 -0
- package/dist/react/filters/hooks.mjs +39 -2
- package/dist/react/filters/menu.mjs +8 -18
- package/dist/react/filters/phone.mjs +3 -3
- package/dist/react/filters/values.mjs +47 -28
- package/dist/react/filters/words.mjs +2 -2
- package/dist/react/format.d.mts +1 -1
- package/dist/react/format.mjs +8 -2
- package/dist/react/renderers/moved.mjs +160 -0
- package/dist/react/renderers/number-before.mjs +2 -157
- package/dist/react/renderers/props.d.mts +3 -3
- package/dist/react/renderers/table-cells.mjs +97 -11
- package/dist/react/renderers/table-head.mjs +7 -1
- package/dist/react/renderers/table-measure.mjs +147 -25
- package/dist/react/renderers/table-over.mjs +72 -0
- package/dist/react/renderers/table-scale.mjs +54 -1
- package/dist/react/renderers/table-trend.mjs +55 -0
- package/dist/react/renderers/table.d.mts +5 -1
- package/dist/react/renderers/table.mjs +29 -6
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/package.json +1 -1
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
import { execute } from "../execute.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { listingMeasure } from "../listing.mjs";
|
|
3
3
|
import { calendarOf } from "../request.mjs";
|
|
4
|
-
import { isMark, parseMemberId } from "derive-dashboards/core";
|
|
4
|
+
import { isMark, parseMemberId, shownAsMember } from "derive-dashboards/core";
|
|
5
5
|
// src/endpoints/values.ts
|
|
6
6
|
const DEFAULT_LIMIT = 100;
|
|
7
|
-
/** A query listing a member's distinct values in code-point order, narrowed by a search. */
|
|
8
|
-
function valuesQuery(x,
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
7
|
+
/** A query listing a member's distinct values in code-point order (by name, for one shown as another), narrowed by a search. */
|
|
8
|
+
function valuesQuery(x, a, limit) {
|
|
9
|
+
const { model } = x.rt.options;
|
|
10
|
+
const { member, search } = a;
|
|
11
|
+
const source = parseMemberId(member)?.source ?? "";
|
|
12
|
+
const shown = shownAsMember(model, source, member);
|
|
13
|
+
const filters = [...search === void 0 || search === "" ? [] : [{
|
|
14
|
+
member: shown ?? member,
|
|
15
|
+
op: "contains",
|
|
16
|
+
values: [search]
|
|
17
|
+
}], ...a.keys === void 0 ? [] : [{
|
|
18
|
+
member,
|
|
19
|
+
op: "in",
|
|
20
|
+
values: [...a.keys]
|
|
21
|
+
}]];
|
|
14
22
|
return {
|
|
15
23
|
kind: "aggregate",
|
|
16
|
-
source
|
|
24
|
+
source,
|
|
17
25
|
measures: [{
|
|
18
26
|
id: "m1",
|
|
19
|
-
measure:
|
|
27
|
+
measure: listingMeasure(model, member)
|
|
20
28
|
}],
|
|
21
29
|
dimensions: [{
|
|
22
30
|
id: "d1",
|
|
23
31
|
member
|
|
24
|
-
}]
|
|
25
|
-
|
|
26
|
-
member
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
}, ...shown === void 0 ? [] : [{
|
|
33
|
+
id: "d2",
|
|
34
|
+
member: shown
|
|
35
|
+
}]],
|
|
36
|
+
...filters.length === 0 ? {} : { filters: { all: filters } },
|
|
37
|
+
order: [...shown === void 0 ? [] : [{
|
|
38
|
+
by: "d2",
|
|
39
|
+
dir: "asc"
|
|
40
|
+
}], {
|
|
31
41
|
by: "d1",
|
|
32
42
|
dir: "asc"
|
|
33
43
|
}],
|
|
@@ -40,19 +50,23 @@ function valuesQuery(x, member, search, limit) {
|
|
|
40
50
|
*/
|
|
41
51
|
async function memberValues(x, a) {
|
|
42
52
|
const limit = a.limit ?? DEFAULT_LIMIT;
|
|
43
|
-
const query = valuesQuery(x, a
|
|
44
|
-
const
|
|
53
|
+
const query = valuesQuery(x, a, limit);
|
|
54
|
+
const answer = await execute({
|
|
45
55
|
...x,
|
|
46
56
|
query,
|
|
47
57
|
calendar: calendarOf(x.rt.options)
|
|
48
|
-
})
|
|
58
|
+
});
|
|
59
|
+
const values = [...new Set(answer.rows.flatMap((row) => {
|
|
49
60
|
const cell = row[0] ?? null;
|
|
50
61
|
if (cell === null || typeof cell !== "object") return [cell];
|
|
51
62
|
return isMark(cell) ? [] : [cell.v];
|
|
52
|
-
});
|
|
63
|
+
}))];
|
|
64
|
+
const page = values.slice(0, limit);
|
|
65
|
+
const labels = answer.columns[0]?.labels;
|
|
53
66
|
return {
|
|
54
|
-
values:
|
|
55
|
-
more: values.length > limit
|
|
67
|
+
values: page,
|
|
68
|
+
more: values.length > limit,
|
|
69
|
+
...labels === void 0 ? {} : { labels }
|
|
56
70
|
};
|
|
57
71
|
}
|
|
58
72
|
export { memberValues };
|
package/dist/execute.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { checkSensitive } from "./authorize.mjs";
|
|
|
2
2
|
import { manifest } from "./cache.mjs";
|
|
3
3
|
import { macHex } from "./cursor-seal.mjs";
|
|
4
4
|
import { adapterFor } from "./dashboards.mjs";
|
|
5
|
+
import { labelColumns } from "./labels.mjs";
|
|
5
6
|
import { withReader } from "./reading.mjs";
|
|
6
7
|
import { logQuery } from "./store/log.mjs";
|
|
7
8
|
import { answerStatus, bindQueryViewer, bindViewer, canonical, formatTextTime, isBound, markedRows, markedWhole, requestInstant, resultColumns, unreadWarnings, withTime } from "derive-dashboards/core";
|
|
@@ -144,10 +145,30 @@ async function compute(x, bound) {
|
|
|
144
145
|
* request (same bound query, policies, calendar and source epochs) is answered from it.
|
|
145
146
|
*/
|
|
146
147
|
async function execute(x) {
|
|
147
|
-
const answer = await answered(x);
|
|
148
|
+
const answer = await labelled(x, await answered(x));
|
|
148
149
|
record(x, answer);
|
|
149
150
|
return answer;
|
|
150
151
|
}
|
|
152
|
+
/** The answer with the labels of each dimension column shown as another, read under the same viewer and lock. */
|
|
153
|
+
async function labelled(x, answer) {
|
|
154
|
+
const sets = [
|
|
155
|
+
answer.rows,
|
|
156
|
+
answer.compare?.rows,
|
|
157
|
+
answer.whole?.rows
|
|
158
|
+
];
|
|
159
|
+
const columns = await labelColumns(x.rt.options.model, {
|
|
160
|
+
query: x.query,
|
|
161
|
+
columns: answer.columns,
|
|
162
|
+
sets
|
|
163
|
+
}, (query) => answered({
|
|
164
|
+
...x,
|
|
165
|
+
query
|
|
166
|
+
}));
|
|
167
|
+
return {
|
|
168
|
+
...answer,
|
|
169
|
+
columns
|
|
170
|
+
};
|
|
171
|
+
}
|
|
151
172
|
/** With `queryLog`, one row per answer, written where the host runs background work; never fails a request. */
|
|
152
173
|
function record(x, answer) {
|
|
153
174
|
const { options } = x.rt;
|
package/dist/labels.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { listingMeasure } from "./listing.mjs";
|
|
2
|
+
import { isMark, shownAsMember } from "derive-dashboards/core";
|
|
3
|
+
// src/labels.ts
|
|
4
|
+
/** Each value's name from rows that hold the value at `key` and its name at `name`; the first wins. */
|
|
5
|
+
function namesIn(rows, key, name) {
|
|
6
|
+
const labels = {};
|
|
7
|
+
for (const row of rows) {
|
|
8
|
+
const [k, n] = [row[key], row[name]];
|
|
9
|
+
if (typeof k === "string" && typeof n === "string" && !(k in labels)) labels[k] = n;
|
|
10
|
+
}
|
|
11
|
+
return labels;
|
|
12
|
+
}
|
|
13
|
+
/** The cells of one column across row sets, skipping marks. */
|
|
14
|
+
function cellsAt(index, sets) {
|
|
15
|
+
return sets.flatMap((rows) => (rows ?? []).flatMap((row) => {
|
|
16
|
+
const cell = row[index];
|
|
17
|
+
return cell === void 0 || isMark(cell) ? [] : [cell];
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The labels of an answer's dimension columns that are `shownAs` another: from the answer's own
|
|
22
|
+
* rows when it groups by the names too, else by one query grouped by the value and its name,
|
|
23
|
+
* under the same viewer and lock (the query's closure holds the names, so whoever may not read
|
|
24
|
+
* them was refused before). A value with no name is left out, and shows as itself.
|
|
25
|
+
*/
|
|
26
|
+
function labelColumns(model, answer, run) {
|
|
27
|
+
const { query, columns, sets } = answer;
|
|
28
|
+
return Promise.all(columns.map(async (column, i) => {
|
|
29
|
+
if (column.role !== "dimension" || column.member === void 0) return column;
|
|
30
|
+
const shown = shownAsMember(model, query.source, column.member);
|
|
31
|
+
if (shown === void 0) return column;
|
|
32
|
+
const named = columns.findIndex((c) => c.role === "dimension" && c.member === shown);
|
|
33
|
+
if (named !== -1) return {
|
|
34
|
+
...column,
|
|
35
|
+
labels: namesIn(sets.flatMap((r) => r ?? []), i, named)
|
|
36
|
+
};
|
|
37
|
+
const keys = [...new Set(cellsAt(i, sets).filter((v) => typeof v === "string"))];
|
|
38
|
+
if (keys.length === 0) return {
|
|
39
|
+
...column,
|
|
40
|
+
labels: {}
|
|
41
|
+
};
|
|
42
|
+
const read = await run({
|
|
43
|
+
kind: "aggregate",
|
|
44
|
+
source: query.source,
|
|
45
|
+
measures: [{
|
|
46
|
+
id: "m1",
|
|
47
|
+
measure: listingMeasure(model, column.member)
|
|
48
|
+
}],
|
|
49
|
+
dimensions: [{
|
|
50
|
+
id: "d1",
|
|
51
|
+
member: column.member
|
|
52
|
+
}, {
|
|
53
|
+
id: "d2",
|
|
54
|
+
member: shown
|
|
55
|
+
}],
|
|
56
|
+
filters: {
|
|
57
|
+
member: column.member,
|
|
58
|
+
op: "in",
|
|
59
|
+
values: keys
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
...column,
|
|
64
|
+
labels: namesIn(read.rows, 0, 1)
|
|
65
|
+
};
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
export { labelColumns };
|
package/dist/listing.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HttpError } from "./http.mjs";
|
|
2
|
+
import { parseMemberId } from "derive-dashboards/core";
|
|
3
|
+
// src/listing.ts
|
|
4
|
+
/** The measure a query lists a source's values with: a plain count, the cheapest, else the first. */
|
|
5
|
+
function listingMeasure(model, member) {
|
|
6
|
+
const ref = parseMemberId(member);
|
|
7
|
+
const source = ref === void 0 ? void 0 : model.sources[ref.source];
|
|
8
|
+
const measures = source === void 0 ? [] : Object.entries(source.measures);
|
|
9
|
+
const measure = (measures.find(([, m]) => m.kind === "count" && !("distinct" in m)) ?? measures[0])?.[0];
|
|
10
|
+
if (ref === void 0 || measure === void 0) throw new HttpError(400, "QUERY_INVALID", `"${member}" is not a member whose values can be listed.`);
|
|
11
|
+
return `${ref.source}.${measure}`;
|
|
12
|
+
}
|
|
13
|
+
export { listingMeasure };
|
package/dist/react/Canvas.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useDashboards } from "./context.mjs";
|
|
2
|
-
import { datesKey, datesShown, useDatesKept } from "./dates-shown.mjs";
|
|
2
|
+
import { datesKey, datesShown, sharedWidget, useDatesKept } from "./dates-shown.mjs";
|
|
3
3
|
import { Grid } from "./Grid.mjs";
|
|
4
4
|
import { Header } from "./Header.mjs";
|
|
5
5
|
import { SaysDatesContext, useDatesSaid, useSaid } from "./says-dates.mjs";
|
|
6
6
|
import { TabStrip } from "./TabStrip.mjs";
|
|
7
7
|
import { linkTo } from "./view.mjs";
|
|
8
|
+
import { sharedDisplay } from "derive-dashboards/core";
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
// src/Canvas.tsx
|
|
10
11
|
/** The filters a link carried that this dashboard does not have, named once. */
|
|
@@ -47,6 +48,28 @@ function useDatesText(board, tab) {
|
|
|
47
48
|
return useDatesKept(datesShown(board.tiles, format), datesKey(tab.id, board.view.picks));
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
51
|
+
* The range a widget's answer is of when the viewer has picked no dates: the dashboard's own,
|
|
52
|
+
* unless the widget keeps its query's (`keepDateRange`) or the dashboard has none.
|
|
53
|
+
*/
|
|
54
|
+
function ownRange(doc, widgetId) {
|
|
55
|
+
const widget = doc.widgets[widgetId];
|
|
56
|
+
const own = widget?.queries["main"]?.time?.range;
|
|
57
|
+
return sharedDisplay(widget?.display).keepDateRange === true ? own : doc.scope.dateRange ?? own;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The dates shown in words, when they are counted back from now ("Last 13 weeks"): what the
|
|
61
|
+
* widget they are read from asks for. The date control says it before the dates while nothing
|
|
62
|
+
* is picked, so a reader knows the dates move with today. Undefined for dates that are fixed,
|
|
63
|
+
* or that the tiles do not share; kept while the tiles wait, as the dates are.
|
|
64
|
+
*/
|
|
65
|
+
function usePeriodText(board, doc, tab) {
|
|
66
|
+
const { messages } = useDashboards();
|
|
67
|
+
const widget = sharedWidget(board.tiles);
|
|
68
|
+
const range = typeof widget === "string" ? ownRange(doc, widget) : void 0;
|
|
69
|
+
const named = range !== void 0 && "last" in range ? messages.range(range) : void 0;
|
|
70
|
+
return useDatesKept(widget === null ? null : named, datesKey(tab.id, board.view.picks));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
50
73
|
* The host's filter bar (the built-in one by default), told the zone dates are read in and
|
|
51
74
|
* the dates most tiles cover, which its date control says.
|
|
52
75
|
*/
|
|
@@ -59,7 +82,8 @@ function Filters(props) {
|
|
|
59
82
|
picks: board.view.picks,
|
|
60
83
|
onChange: board.view.setPicks,
|
|
61
84
|
timezone: doc.scope.timezone ?? answeredZone(board.tiles.results),
|
|
62
|
-
span: props.span
|
|
85
|
+
span: props.span,
|
|
86
|
+
period: props.period ?? void 0
|
|
63
87
|
});
|
|
64
88
|
}
|
|
65
89
|
/**
|
|
@@ -85,6 +109,7 @@ function Canvas(props) {
|
|
|
85
109
|
};
|
|
86
110
|
const dates = useDatesSaid();
|
|
87
111
|
const span = useDatesText(board, shown.tab);
|
|
112
|
+
const period = usePeriodText(board, shown.doc, shown.tab);
|
|
88
113
|
return /* @__PURE__ */ jsxs(SaysDatesContext.Provider, {
|
|
89
114
|
value: dates.claim,
|
|
90
115
|
children: [
|
|
@@ -103,6 +128,7 @@ function Canvas(props) {
|
|
|
103
128
|
board,
|
|
104
129
|
doc: shown.doc,
|
|
105
130
|
span,
|
|
131
|
+
period,
|
|
106
132
|
options: props.dashboard.filterBar
|
|
107
133
|
})
|
|
108
134
|
}),
|
package/dist/react/Cell.mjs
CHANGED
|
@@ -31,9 +31,8 @@ export type DashboardProps = {
|
|
|
31
31
|
/** The link Share copies for a view; by default, this page's address with the view in it. */
|
|
32
32
|
linkFor?: (view: ViewState) => string;
|
|
33
33
|
/**
|
|
34
|
-
* How tiles sit
|
|
35
|
-
*
|
|
36
|
-
* While editing they are always cards, with room to drag into.
|
|
34
|
+
* How tiles sit, read and edited alike: "sheet" (the default) joins them as one ruled sheet,
|
|
35
|
+
* sharing hairline rules; "cards" keeps each a card of its own, with room between.
|
|
37
36
|
*/
|
|
38
37
|
tiles?: "sheet" | "cards";
|
|
39
38
|
/**
|
package/dist/react/Tile.d.mts
CHANGED
|
@@ -13,7 +13,7 @@ type Props = {
|
|
|
13
13
|
badge?: ReactNode;
|
|
14
14
|
/** The span most tiles cover (`spanKey`), said once for the dashboard, not on each tile. */
|
|
15
15
|
sharedSpan?: string | undefined;
|
|
16
|
-
/** Whether the tile is as tall as what it holds: on a dashboard
|
|
16
|
+
/** Whether the tile is as tall as what it holds: on a dashboard, read or edited. */
|
|
17
17
|
fit?: boolean | undefined;
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
@@ -23,23 +23,107 @@ function pixels(length, fallback) {
|
|
|
23
23
|
const n = Number(length.replace(/px$/u, ""));
|
|
24
24
|
return length !== "" && Number.isFinite(n) ? n : fallback;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/** A row's height where the page is not laid out, as a test's is not. */
|
|
27
|
+
const ROW = 72;
|
|
28
|
+
/** The rows between two that were seen, spaced evenly: no tile starts or ends on them. */
|
|
29
|
+
function between(from, to) {
|
|
30
|
+
const rows = to.row - from.row;
|
|
31
|
+
return Array.from({ length: rows }, (_, i) => from.at + (to.at - from.at) * i / rows);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Where each row starts, from where tiles were seen to start and end: `[0]` alone when nothing
|
|
35
|
+
* was seen below the top, as on a page that is not laid out.
|
|
36
|
+
*/
|
|
37
|
+
function rowStarts(seen) {
|
|
38
|
+
const known = /* @__PURE__ */ new Map([[0, 0]]);
|
|
39
|
+
for (const { row, at } of seen) if (!known.has(row)) known.set(row, at);
|
|
40
|
+
const sorted = [...known].map(([row, at]) => ({
|
|
41
|
+
row,
|
|
42
|
+
at
|
|
43
|
+
})).toSorted((a, b) => a.row - b.row);
|
|
44
|
+
const last = sorted.at(-1);
|
|
45
|
+
if (last === void 0 || last.at <= 0) return [0];
|
|
46
|
+
return [...sorted.slice(1).flatMap((to, i) => between(sorted[i] ?? to, to)), last.at];
|
|
47
|
+
}
|
|
48
|
+
/** Where every tile drawn starts and ends on the grid: its rows by its place, its edges as drawn. */
|
|
49
|
+
function seenIn(grid, layout, gap) {
|
|
50
|
+
const top = grid.getBoundingClientRect().top;
|
|
51
|
+
const places = new Map(layout.map((item) => [item.widget, item]));
|
|
52
|
+
return [...grid.querySelectorAll(".dd-cell[data-widget]")].flatMap((cell) => {
|
|
53
|
+
const item = places.get(cell.dataset["widget"] ?? "");
|
|
54
|
+
if (item === void 0) return [];
|
|
55
|
+
const box = cell.getBoundingClientRect();
|
|
56
|
+
return [{
|
|
57
|
+
row: item.y,
|
|
58
|
+
at: box.top - top
|
|
59
|
+
}, {
|
|
60
|
+
row: item.y + item.h,
|
|
61
|
+
at: box.bottom - top + gap
|
|
62
|
+
}];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** A row of the dragged tile's own, with the gap after it: what one more row past the last is. */
|
|
66
|
+
function ownRow(cell, rows, gap) {
|
|
67
|
+
const height = cell?.getBoundingClientRect().height ?? 0;
|
|
68
|
+
return height > 0 ? (height + gap) / rows : ROW + gap;
|
|
69
|
+
}
|
|
70
|
+
/** The grid's steps as it is drawn, for a drag of `cell` that starts now. */
|
|
71
|
+
function stepsOf(grid, layout, tile) {
|
|
28
72
|
if (grid === null) return {
|
|
29
73
|
x: 1,
|
|
30
|
-
|
|
74
|
+
starts: [0],
|
|
75
|
+
y: 1,
|
|
76
|
+
gap: 0
|
|
31
77
|
};
|
|
32
78
|
const style = getComputedStyle(grid);
|
|
33
79
|
const columnGap = pixels(style.columnGap, 0);
|
|
34
80
|
const rowGap = pixels(style.rowGap, 0);
|
|
35
|
-
const column = (grid.clientWidth - columnGap * 11) / 12;
|
|
36
|
-
const row = pixels(style.gridAutoRows, 72);
|
|
37
81
|
return {
|
|
38
|
-
x:
|
|
39
|
-
|
|
82
|
+
x: (grid.clientWidth - columnGap * (GRID_COLUMNS - 1)) / GRID_COLUMNS + columnGap,
|
|
83
|
+
starts: rowStarts(seenIn(grid, layout, rowGap)),
|
|
84
|
+
y: ownRow(tile.cell, tile.rows, rowGap),
|
|
85
|
+
gap: rowGap
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** A length as a track is written, to a hundredth of a pixel. */
|
|
89
|
+
const track = (length) => `${String(Math.round(length * 100) / 100)}px`;
|
|
90
|
+
/**
|
|
91
|
+
* The grid's rows as a drag holds them: each row drawn at the height it has, and any row past
|
|
92
|
+
* the last a row of the dragged tile's own.
|
|
93
|
+
*/
|
|
94
|
+
function heldRows(step) {
|
|
95
|
+
return {
|
|
96
|
+
rows: step.starts.slice(1).map((start, i) => start - (step.starts[i] ?? 0) - step.gap).map((height) => track(height)).join(" "),
|
|
97
|
+
more: track(step.y - step.gap)
|
|
40
98
|
};
|
|
41
99
|
}
|
|
42
100
|
/**
|
|
101
|
+
* Holds the grid's rows at the heights they are drawn at while a drag lasts, or lets them go
|
|
102
|
+
* (`undefined`). Rows are as tall as their tiles, so tiles making room for the dragged one
|
|
103
|
+
* would otherwise move every row under the pointer, and the place it lands with them.
|
|
104
|
+
*/
|
|
105
|
+
function hold(grid, step) {
|
|
106
|
+
if (grid === null) return;
|
|
107
|
+
const held = step === void 0 ? void 0 : heldRows(step);
|
|
108
|
+
grid.style.gridTemplateRows = held?.rows ?? "";
|
|
109
|
+
grid.style.gridAutoRows = held?.more ?? "";
|
|
110
|
+
grid.toggleAttribute("data-arranging", held !== void 0);
|
|
111
|
+
}
|
|
112
|
+
/** Where a row starts: as drawn, and past the last drawn by even steps. */
|
|
113
|
+
function startOf(step, row) {
|
|
114
|
+
const last = step.starts.length - 1;
|
|
115
|
+
return row <= last ? step.starts[row] ?? 0 : (step.starts[last] ?? 0) + (row - last) * step.y;
|
|
116
|
+
}
|
|
117
|
+
/** The row whose start is nearest a place down the grid. */
|
|
118
|
+
function rowAt(step, at) {
|
|
119
|
+
const last = step.starts.length - 1;
|
|
120
|
+
const end = step.starts[last] ?? 0;
|
|
121
|
+
if (at >= end) return last + Math.round((at - end) / step.y);
|
|
122
|
+
let nearest = 0;
|
|
123
|
+
for (const [row, start] of step.starts.entries()) if (Math.abs(start - at) < Math.abs((step.starts[nearest] ?? 0) - at)) nearest = row;
|
|
124
|
+
return nearest;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
43
127
|
* The item moved or resized by whole cells: a move keeps the size; a resize keeps the top left,
|
|
44
128
|
* stops at the grid's edge, and never makes a tile smaller than its kind reads at (core's
|
|
45
129
|
* `smallestFor`; one already smaller stays as it is).
|
|
@@ -57,13 +141,17 @@ function shifted(item, how, by) {
|
|
|
57
141
|
h: Math.max(Math.min(least.h, item.h), item.h + dy)
|
|
58
142
|
};
|
|
59
143
|
}
|
|
60
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* Where a drag puts the item: whole columns from where the pointer went down, and the row whose
|
|
146
|
+
* start the dragged edge is nearest (a move's top, a resize's bottom).
|
|
147
|
+
*/
|
|
61
148
|
function dragged(d, event) {
|
|
62
149
|
const dx = Math.round((event.clientX - d.x0) / d.step.x);
|
|
63
|
-
const
|
|
150
|
+
const edge = d.mode === "move" ? d.start.y : d.start.y + d.start.h;
|
|
151
|
+
const row = rowAt(d.step, startOf(d.step, edge) + event.clientY - d.y0);
|
|
64
152
|
return shifted(d.start, d, {
|
|
65
153
|
dx,
|
|
66
|
-
dy
|
|
154
|
+
dy: row - edge
|
|
67
155
|
});
|
|
68
156
|
}
|
|
69
157
|
/**
|
|
@@ -108,4 +196,4 @@ async function commit(edit, tab, wanted, show) {
|
|
|
108
196
|
}]);
|
|
109
197
|
show();
|
|
110
198
|
}
|
|
111
|
-
export { KEYS, commit, dragged, follow, nextStep, same,
|
|
199
|
+
export { KEYS, commit, dragged, follow, heldRows, hold, nextStep, rowStarts, same, stepsOf };
|
package/dist/react/arrange.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KEYS, commit, dragged, follow, nextStep, same,
|
|
1
|
+
import { KEYS, commit, dragged, follow, hold, nextStep, same, stepsOf } from "./arrange-steps.mjs";
|
|
2
2
|
import { useDashboards } from "./context.mjs";
|
|
3
3
|
import { useStable } from "./stable.mjs";
|
|
4
4
|
import { placeItem, smallestFor } from "derive-dashboards/core";
|
|
@@ -54,14 +54,19 @@ function handlers(a, drag, show) {
|
|
|
54
54
|
drag.current = void 0;
|
|
55
55
|
if (d === void 0) return;
|
|
56
56
|
follow(d);
|
|
57
|
+
hold(a.grid());
|
|
57
58
|
send(dragged(d, at ?? d.last));
|
|
58
59
|
};
|
|
59
60
|
return (item, mode) => ({
|
|
60
61
|
onPointerDown: (event) => {
|
|
61
62
|
if (a.edit().busy || event.button !== 0) return;
|
|
62
63
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
63
|
-
const step = stepOf(a.grid());
|
|
64
64
|
const cell = event.currentTarget.closest(".dd-cell");
|
|
65
|
+
const step = stepsOf(a.grid(), a.tab().layout, {
|
|
66
|
+
cell,
|
|
67
|
+
rows: item.h
|
|
68
|
+
});
|
|
69
|
+
hold(a.grid(), step);
|
|
65
70
|
const { clientX: x0, clientY: y0 } = event;
|
|
66
71
|
drag.current = {
|
|
67
72
|
mode,
|
|
@@ -97,6 +102,7 @@ function handlers(a, drag, show) {
|
|
|
97
102
|
onPointerCancel: () => {
|
|
98
103
|
if (drag.current !== void 0) follow(drag.current);
|
|
99
104
|
drag.current = void 0;
|
|
105
|
+
hold(a.grid());
|
|
100
106
|
show();
|
|
101
107
|
},
|
|
102
108
|
onKeyDown: onKey(a, send, item, mode)
|
|
@@ -105,7 +111,8 @@ function handlers(a, drag, show) {
|
|
|
105
111
|
/**
|
|
106
112
|
* Moving and resizing tiles on one tab of a draft. While a tile is dragged it follows the
|
|
107
113
|
* pointer, an outline shows where it will land, snapped to the grid, and the tiles `placeItem`
|
|
108
|
-
* must move for it make room; nothing else moves
|
|
114
|
+
* must move for it make room; nothing else moves, and the rows keep the heights they had when
|
|
115
|
+
* the drag began. Letting go sends one `widget.move`. The arrow
|
|
109
116
|
* keys on a tile's handle move it a cell at a time, and with Shift resize it. The preview holds
|
|
110
117
|
* until the draft has the move, so nothing jumps back. `handle` keeps one identity, so tiles
|
|
111
118
|
* that did not move are not drawn again.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { keepsOthers, pruned } from "./display.mjs";
|
|
2
2
|
import { fittingTitle, sourceIn } from "./labels.mjs";
|
|
3
|
-
import { parseMemberId } from "derive-dashboards/core";
|
|
3
|
+
import { displayOf, parseMemberId } from "derive-dashboards/core";
|
|
4
4
|
// src/builder/base.ts
|
|
5
5
|
/** A new widget's range: the last 7 days, today included. */
|
|
6
6
|
const DEFAULT_RANGE = {
|
|
@@ -93,15 +93,20 @@ function fitDisplay(before, given) {
|
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Whether a widget asks for its whole beside its buckets (`time.whole`): a number over time,
|
|
96
|
-
* whose headline is the whole range's and never a bucket's
|
|
96
|
+
* whose headline is the whole range's and never a bucket's, and a table over time that draws
|
|
97
|
+
* each row's buckets as a small chart (`display.trend`), whose rows are the whole's.
|
|
97
98
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
function wantsWhole(state, time) {
|
|
100
|
+
if (time.grain === void 0) return false;
|
|
101
|
+
if (state.kind === "number") return true;
|
|
102
|
+
return state.kind === "table" && (displayOf("table", state.display).trend ?? []).length > 0;
|
|
103
|
+
}
|
|
104
|
+
/** The state with its query's time asking for its whole exactly when its kind, grain and display want it. */
|
|
100
105
|
function fitWhole(state) {
|
|
101
106
|
const query = state.query;
|
|
102
107
|
const time = query?.time;
|
|
103
108
|
if (query === void 0 || time === void 0) return state;
|
|
104
|
-
const wants = wantsWhole(state
|
|
109
|
+
const wants = wantsWhole(state, time);
|
|
105
110
|
if (time.whole === true === wants) return state;
|
|
106
111
|
const { whole: _had, ...without } = time;
|
|
107
112
|
return {
|
|
@@ -191,4 +196,4 @@ function widgetOf(state) {
|
|
|
191
196
|
...Object.keys(display).length === 0 ? {} : { display }
|
|
192
197
|
};
|
|
193
198
|
}
|
|
194
|
-
export { DEFAULT_RANGE, cleared, defaultTime, emptyBuilder, freshId, keptAside, lastPart, refersTo, setKind, setTitle, widgetOf, withQuery };
|
|
199
|
+
export { DEFAULT_RANGE, cleared, defaultTime, emptyBuilder, fitWhole, freshId, keptAside, lastPart, refersTo, setKind, setTitle, widgetOf, withQuery };
|
|
@@ -21,7 +21,8 @@ const NAMES_ANY = /* @__PURE__ */ new Set([
|
|
|
21
21
|
const LEAST = {
|
|
22
22
|
value: 2,
|
|
23
23
|
secondary: 2,
|
|
24
|
-
against: 2
|
|
24
|
+
against: 2,
|
|
25
|
+
parts: 2
|
|
25
26
|
};
|
|
26
27
|
/** Which entries an option of a kind names: values by core's rule, any by the list's; else none. */
|
|
27
28
|
function namesOf(kind, name) {
|
|
@@ -35,6 +36,7 @@ function namesOf(kind, name) {
|
|
|
35
36
|
*/
|
|
36
37
|
function ruleOf(kind, name, type) {
|
|
37
38
|
if (type === "boolean") return { shape: "boolean" };
|
|
39
|
+
if (type === "link") return { shape: "text" };
|
|
38
40
|
if (type !== "text" && type !== "texts") return void 0;
|
|
39
41
|
const names = namesOf(kind, name);
|
|
40
42
|
if (names !== void 0) return {
|
|
@@ -68,11 +70,23 @@ function entriesFor(names, query) {
|
|
|
68
70
|
];
|
|
69
71
|
}
|
|
70
72
|
/**
|
|
73
|
+
* What a query must have for an option to draw anything: a small chart is of time buckets, and
|
|
74
|
+
* a change is from a period the query compares with.
|
|
75
|
+
*/
|
|
76
|
+
const NEEDS = {
|
|
77
|
+
trend: (query) => query.time?.grain !== void 0,
|
|
78
|
+
change: (query) => query.time?.compare !== void 0
|
|
79
|
+
};
|
|
80
|
+
/** Whether an option would draw anything for a query: one that needs what the query lacks would not. */
|
|
81
|
+
const applies = (name, query) => !Object.hasOwn(NEEDS, name) || query !== void 0 && NEEDS[name]?.(query) === true;
|
|
82
|
+
/**
|
|
71
83
|
* What the builder offers for a kind and a query, in the order it shows them. An option that
|
|
72
|
-
* names entries is left out when the query has fewer than it needs to make a choice
|
|
84
|
+
* names entries is left out when the query has fewer than it needs to make a choice, and one
|
|
85
|
+
* that would draw nothing for the query (`NEEDS`) is left out too.
|
|
73
86
|
*/
|
|
74
87
|
function offers(kind, query) {
|
|
75
88
|
return editedRules(kind).flatMap(([name, rule]) => {
|
|
89
|
+
if (!applies(name, query)) return [];
|
|
76
90
|
if (!("names" in rule)) return [{
|
|
77
91
|
name,
|
|
78
92
|
shape: rule.shape,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_RANGE, cleared, defaultTime, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
|
|
1
|
+
import { DEFAULT_RANGE, cleared, defaultTime, fitWhole, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
|
|
2
2
|
import { setOption, toggleEntry } from "./display.mjs";
|
|
3
3
|
import { addCondition, removeNode, setMode } from "./filter-tree.mjs";
|
|
4
4
|
import { formulaRefs, parseMemberId } from "derive-dashboards/core";
|
|
@@ -201,9 +201,9 @@ function setDisplay(_meta, state, name, value) {
|
|
|
201
201
|
/** Ticks or unticks one entry of an option that names several (a table's bars, a list's subtitle). */
|
|
202
202
|
function toggleDisplay(_meta, state, change) {
|
|
203
203
|
const { dropped: _last, ...rest } = state;
|
|
204
|
-
return {
|
|
204
|
+
return fitWhole({
|
|
205
205
|
...rest,
|
|
206
206
|
display: toggleEntry(displayIn(state), state.query, change)
|
|
207
|
-
};
|
|
207
|
+
});
|
|
208
208
|
}
|
|
209
209
|
export { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setDisplay, setFilterMode, setTime, toggleDisplay };
|
|
@@ -75,6 +75,10 @@ const ENGLISH_BUILDER = {
|
|
|
75
75
|
full: "Write amounts in full",
|
|
76
76
|
bars: "Bars",
|
|
77
77
|
heat: "Shade by value",
|
|
78
|
+
dots: "Dot against the total",
|
|
79
|
+
parts: "Part inside its whole",
|
|
80
|
+
trend: "Small chart over time",
|
|
81
|
+
change: "Change from the period before",
|
|
78
82
|
compact: "Closer rows",
|
|
79
83
|
title: "Row title",
|
|
80
84
|
subtitle: "Under the title",
|
|
@@ -93,6 +97,10 @@ const ENGLISH_BUILDER = {
|
|
|
93
97
|
full: "Write every amount in full. Without it, amounts of a thousand or more are rounded to whole units.",
|
|
94
98
|
bars: "Draw a bar beside each value, its length measured against the column's largest value.",
|
|
95
99
|
heat: "Shade each cell by its value, darker for more.",
|
|
100
|
+
dots: "Draw each value as a dot on a scale, with a tick where the total stands. For a rate or an average.",
|
|
101
|
+
parts: "Pick two values, one a part of the other: the part is drawn inside the whole's bar.",
|
|
102
|
+
change: "Write how each value moved against the period before, after the value. The tile needs a period to compare with.",
|
|
103
|
+
trend: "Draw how each row went over time, small, beside its value. The table then has one row for each group over the whole period.",
|
|
96
104
|
compact: "Draw the rows closer together.",
|
|
97
105
|
title: "What each row is titled by.",
|
|
98
106
|
subtitle: "What is written under the title.",
|