derive-dashboards 0.12.0 → 0.12.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/CHANGELOG.md +6 -0
- package/dist/drill-comparison.mjs +1 -1
- package/dist/drill-crumbs.mjs +29 -6
- package/dist/drill.mjs +1 -1
- package/dist/labels.mjs +38 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/drill-crumbs.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { execute } from "./execute.mjs";
|
|
2
|
+
import { namesOf } from "./labels.mjs";
|
|
1
3
|
import { bucketWithin, resultColumns } from "derive-dashboards/core";
|
|
2
4
|
// src/drill-crumbs.ts
|
|
3
5
|
/** A field's label as a column of the tile would read it. */
|
|
@@ -36,7 +38,7 @@ function groupCrumb(fields) {
|
|
|
36
38
|
* One step as a breadcrumb: its fields and its values; a time point with its grain and the part
|
|
37
39
|
* of it the window reads (`range`), so the panel says "so far" of a week still running.
|
|
38
40
|
*/
|
|
39
|
-
function crumbOf(o, step, range) {
|
|
41
|
+
function crumbOf(o, step, range, names) {
|
|
40
42
|
if ("bucket" in step) {
|
|
41
43
|
const { member, from, to, grain } = step.bucket;
|
|
42
44
|
return {
|
|
@@ -62,7 +64,7 @@ function crumbOf(o, step, range) {
|
|
|
62
64
|
};
|
|
63
65
|
return groupCrumb(step.group.map((g) => ({
|
|
64
66
|
label: fieldLabel(o, g.member),
|
|
65
|
-
value: g.value
|
|
67
|
+
value: typeof g.value === "string" ? names.get(g.member)?.[g.value] ?? g.value : g.value
|
|
66
68
|
})));
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
@@ -96,16 +98,37 @@ function selectionOf(steps) {
|
|
|
96
98
|
* One selection as a breadcrumb, marked when it is of the period before. A time step reads the
|
|
97
99
|
* part of its bucket that selection's own window covers.
|
|
98
100
|
*/
|
|
99
|
-
function selectionCrumb(o, selection) {
|
|
101
|
+
function selectionCrumb(o, selection, names) {
|
|
100
102
|
const range = selection.previous === true ? o.pinned.compare : o.pinned.range;
|
|
101
|
-
const crumb = selectionOf(selection.steps.map((step) => crumbOf(o, step, range)));
|
|
103
|
+
const crumb = selectionOf(selection.steps.map((step) => crumbOf(o, step, range, names)));
|
|
102
104
|
return selection.previous === true ? {
|
|
103
105
|
...crumb,
|
|
104
106
|
previous: true
|
|
105
107
|
} : crumb;
|
|
106
108
|
}
|
|
107
|
-
/** The path as
|
|
108
|
-
|
|
109
|
+
/** The names the path's grouped values read as, read under the drill's own viewer and lock. */
|
|
110
|
+
async function pathNames(o) {
|
|
111
|
+
const grouped = o.selections.flatMap((s) => s.steps.flatMap((step) => "group" in step ? step.group : []));
|
|
112
|
+
const values = Map.groupBy(grouped, (g) => g.member);
|
|
113
|
+
const { model } = o.x.rt.options;
|
|
114
|
+
const read = await Promise.all([...values].map(async ([member, steps]) => {
|
|
115
|
+
const at = {
|
|
116
|
+
source: o.x.query.source,
|
|
117
|
+
member,
|
|
118
|
+
keys: steps.map((g) => g.value)
|
|
119
|
+
};
|
|
120
|
+
return [member, await namesOf(model, at, (query) => execute({
|
|
121
|
+
...o.x,
|
|
122
|
+
query
|
|
123
|
+
}))];
|
|
124
|
+
}));
|
|
125
|
+
return new Map(read.flatMap(([m, n]) => n === void 0 ? [] : [[m, n]]));
|
|
126
|
+
}
|
|
127
|
+
/** The path as breadcrumbs, one per selection, in order, each value as people read it. */
|
|
128
|
+
async function crumbs(o) {
|
|
129
|
+
const names = await pathNames(o);
|
|
130
|
+
return o.selections.map((s) => selectionCrumb(o, s, names));
|
|
131
|
+
}
|
|
109
132
|
/**
|
|
110
133
|
* What of a receipt a viewer who did not draw the link may read: a fixed list, so a field added
|
|
111
134
|
* to receipts later is held back until it is listed here. The filter (it states the drill's
|
package/dist/drill.mjs
CHANGED
|
@@ -119,7 +119,7 @@ async function runDrill(rt, principal, request, body) {
|
|
|
119
119
|
const state = normalizedDrillState(body.state, r.o.path, plain);
|
|
120
120
|
return forOpener({
|
|
121
121
|
...r.summed === void 0 ? {} : { summary: r.summed.summary },
|
|
122
|
-
path: crumbs(r.o),
|
|
122
|
+
path: await crumbs(r.o),
|
|
123
123
|
state,
|
|
124
124
|
view: shown
|
|
125
125
|
}, r.o.foreign);
|
package/dist/labels.mjs
CHANGED
|
@@ -18,6 +18,37 @@ function cellsAt(index, sets) {
|
|
|
18
18
|
}));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
+
* The names of some values of a dimension shown as another, read by one query grouped by the
|
|
22
|
+
* value and its name under the same viewer and lock (the query's closure holds the names, so
|
|
23
|
+
* whoever may not read them was refused before). Undefined for a dimension shown as itself.
|
|
24
|
+
*/
|
|
25
|
+
async function namesOf(model, at, run) {
|
|
26
|
+
const shown = shownAsMember(model, at.source, at.member);
|
|
27
|
+
if (shown === void 0) return void 0;
|
|
28
|
+
const keys = [...new Set(at.keys.filter((v) => typeof v === "string"))];
|
|
29
|
+
if (keys.length === 0) return {};
|
|
30
|
+
return namesIn((await run({
|
|
31
|
+
kind: "aggregate",
|
|
32
|
+
source: at.source,
|
|
33
|
+
measures: [{
|
|
34
|
+
id: "m1",
|
|
35
|
+
measure: listingMeasure(model, at.member)
|
|
36
|
+
}],
|
|
37
|
+
dimensions: [{
|
|
38
|
+
id: "d1",
|
|
39
|
+
member: at.member
|
|
40
|
+
}, {
|
|
41
|
+
id: "d2",
|
|
42
|
+
member: shown
|
|
43
|
+
}],
|
|
44
|
+
filters: {
|
|
45
|
+
member: at.member,
|
|
46
|
+
op: "in",
|
|
47
|
+
values: keys
|
|
48
|
+
}
|
|
49
|
+
})).rows, 0, 1);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
21
52
|
* The labels of an answer's dimension columns that are `shownAs` another: from the answer's own
|
|
22
53
|
* rows when it groups by the names too, else by one query grouped by the value and its name,
|
|
23
54
|
* under the same viewer and lock (the query's closure holds the names, so whoever may not read
|
|
@@ -34,35 +65,16 @@ function labelColumns(model, answer, run) {
|
|
|
34
65
|
...column,
|
|
35
66
|
labels: namesIn(sets.flatMap((r) => r ?? []), i, named)
|
|
36
67
|
};
|
|
37
|
-
const keys =
|
|
38
|
-
|
|
39
|
-
...column,
|
|
40
|
-
labels: {}
|
|
41
|
-
};
|
|
42
|
-
const read = await run({
|
|
43
|
-
kind: "aggregate",
|
|
68
|
+
const keys = cellsAt(i, sets);
|
|
69
|
+
const at = {
|
|
44
70
|
source: query.source,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
});
|
|
71
|
+
member: column.member,
|
|
72
|
+
keys
|
|
73
|
+
};
|
|
62
74
|
return {
|
|
63
75
|
...column,
|
|
64
|
-
labels:
|
|
76
|
+
labels: await namesOf(model, at, run) ?? {}
|
|
65
77
|
};
|
|
66
78
|
}));
|
|
67
79
|
}
|
|
68
|
-
export { labelColumns };
|
|
80
|
+
export { labelColumns, namesOf };
|
package/package.json
CHANGED