derive-dashboards 0.12.0 → 0.13.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 +29 -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/dist/react/builder/Groups.mjs +44 -35
- package/dist/react/builder/KindNeeds.mjs +129 -0
- package/dist/react/builder/KindSketch.mjs +168 -0
- package/dist/react/builder/Preview.mjs +24 -4
- package/dist/react/builder/Sections.mjs +1 -1
- package/dist/react/builder/Time.mjs +1 -35
- package/dist/react/builder/WidgetBuilder.mjs +50 -32
- package/dist/react/builder/base.mjs +19 -3
- package/dist/react/builder/kind-needs.d.mts +8 -0
- package/dist/react/builder/kind-needs.mjs +64 -0
- package/dist/react/builder/ranges.mjs +68 -0
- package/dist/react/builder/state.mjs +2 -2
- package/dist/react/builder/useBuilder.mjs +1 -3
- package/dist/react/builder/words.d.mts +14 -0
- package/dist/react/builder/words.mjs +34 -2
- package/dist/react/renderers/table-cells.mjs +6 -3
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# derive-dashboards
|
|
2
2
|
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a2fc05f: The widget builder's first minute: what can be made is in sight from the start, and a kind picked draws what its name says.
|
|
8
|
+
|
|
9
|
+
- The first screen shows the chart kinds over a sketch of the one picked, beside a list of measures as tall as the window. It showed a short list and an empty box, and the kinds only after a measure was picked. A kind may be picked before the measure or after.
|
|
10
|
+
- A new widget starts in the search for its measure, where the keys under it ("↑↓ to move · Enter to add") work. It started in the title, so they did nothing until the search was clicked.
|
|
11
|
+
- Line, Area and Small multiples picked for one value draw it over time at once, at the grain its range reads best at. They drew one flat bar: each needs a time grain, and nothing said so.
|
|
12
|
+
- A kind that still lacks what it draws from says so over the preview and offers it, one press each: a bar or a list of one value, a heatmap short of two fields and a funnel short of steps offer the first fields to group by, and the widget's dates where those would do; a line grouped by a field offers its dates; a funnel drawn over time offers the whole period.
|
|
13
|
+
- Group by, opened with no field yet, is the search for one.
|
|
14
|
+
- On a phone the builder's title has a line of its own: Save was cut off at the screen's edge.
|
|
15
|
+
|
|
16
|
+
New words in `messages`, each with English: `kindSays`, `kindNeeds(kind, need)`, `moreFields`.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- b58a0b4: What opens says so under the pointer.
|
|
21
|
+
|
|
22
|
+
A headline number, the line under it ("↑ 16% from 4,236 in the 13 weeks before") and the value of a table cell are underlined under the pointer, as a link is, in their own ink. They opened what is behind them already, but only the pointer's shape said so: a headline number looked the same hovered as not. In a table it is the value under the pointer that is underlined, since each value of a row opens its own rows; its bar, its small chart and how it moved are not. A chart says it in its tooltip ("Open details"), as before.
|
|
23
|
+
|
|
24
|
+
For a theme of your own: a table cell's plain number is now always in a `.dd-table-value` element (it was only in the card layout), so a rule on `.dd-table-value` reaches the wide table too.
|
|
25
|
+
|
|
26
|
+
## 0.12.1
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- fb1fe09: A drill's path names a value shown as another by its name: drilling into a sheet's row reads "Outdoor brands", never its id.
|
|
31
|
+
|
|
3
32
|
## 0.12.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
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 };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useDashboards } from "../context.mjs";
|
|
2
2
|
import { fieldOptions } from "./options.mjs";
|
|
3
3
|
import { Picker } from "./Picker.mjs";
|
|
4
|
-
import { Chip, Entry, Section } from "./Sections.mjs";
|
|
5
|
-
import { useState } from "react";
|
|
4
|
+
import { Chip, Entry, OpenSection, Section } from "./Sections.mjs";
|
|
5
|
+
import { useContext, useState } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
// src/builder/Groups.tsx
|
|
8
8
|
/** The keys that move a group, and by how much. */
|
|
@@ -128,63 +128,72 @@ function GroupRow({ b, group, index, open, onOpen, onDrag, onDrop }) {
|
|
|
128
128
|
}) : null]
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
/** The search for a field to group by. */
|
|
132
|
-
function AddField(
|
|
131
|
+
/** The search for a field to group by: `onDone` once one is picked, `onClose` when it is left with none. */
|
|
132
|
+
function AddField(props) {
|
|
133
133
|
const { messages } = useDashboards();
|
|
134
|
+
const { b } = props;
|
|
134
135
|
return /* @__PURE__ */ jsx(Picker, {
|
|
135
136
|
options: fieldOptions(b.meta, b.state.query?.source ?? ""),
|
|
136
137
|
placeholder: messages.searchFields,
|
|
137
138
|
autoFocus: true,
|
|
138
139
|
onPick: (id) => {
|
|
139
140
|
b.addGroup(id);
|
|
140
|
-
onDone();
|
|
141
|
+
props.onDone();
|
|
141
142
|
},
|
|
142
|
-
onClose:
|
|
143
|
+
onClose: props.onClose
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* Group by: the fields that split the measure, in order; the first is the x axis. Opened with
|
|
148
|
+
* no field yet, or opened to search (`fold.search`), it is the search for one. Closing the
|
|
149
|
+
* search of a section with no field folds it back to its line: there is nothing else there.
|
|
150
|
+
*/
|
|
146
151
|
function GroupSection({ b }) {
|
|
147
152
|
const { messages } = useDashboards();
|
|
153
|
+
const fold = useContext(OpenSection);
|
|
148
154
|
const [adding, setAdding] = useState(false);
|
|
149
155
|
const [open, setOpen] = useState();
|
|
150
156
|
const [dragged, setDragged] = useState();
|
|
151
157
|
const query = b.state.query;
|
|
152
158
|
if (query === void 0) return null;
|
|
153
159
|
const groups = query.dimensions ?? [];
|
|
160
|
+
const none = groups.length === 0;
|
|
161
|
+
const asked = fold?.open === messages.groupBy && fold.search;
|
|
162
|
+
/** The search is done with: a field was picked, or it was left. */
|
|
163
|
+
const done = (folds) => {
|
|
164
|
+
setAdding(false);
|
|
165
|
+
fold?.setOpen(folds ? void 0 : messages.groupBy);
|
|
166
|
+
};
|
|
154
167
|
return /* @__PURE__ */ jsxs(Section, {
|
|
155
168
|
title: messages.groupBy,
|
|
156
169
|
summary: groups.length === 0 ? messages.noGroups : groups.map((g) => b.labelOf(g.member)).join(", "),
|
|
157
170
|
onAdd: () => {
|
|
158
171
|
setAdding(true);
|
|
159
172
|
},
|
|
160
|
-
children: [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
setAdding(false);
|
|
185
|
-
}
|
|
186
|
-
}) : null
|
|
187
|
-
]
|
|
173
|
+
children: [groups.map((g, i) => /* @__PURE__ */ jsx(GroupRow, {
|
|
174
|
+
b,
|
|
175
|
+
group: g,
|
|
176
|
+
index: i,
|
|
177
|
+
open: open === g.id,
|
|
178
|
+
onOpen: () => {
|
|
179
|
+
setOpen(open === g.id ? void 0 : g.id);
|
|
180
|
+
},
|
|
181
|
+
onDrag: () => {
|
|
182
|
+
setDragged(g.id);
|
|
183
|
+
},
|
|
184
|
+
onDrop: () => {
|
|
185
|
+
if (dragged !== void 0) b.moveGroup(dragged, i);
|
|
186
|
+
setDragged(void 0);
|
|
187
|
+
}
|
|
188
|
+
}, g.id)), adding || none || asked ? /* @__PURE__ */ jsx(AddField, {
|
|
189
|
+
b,
|
|
190
|
+
onDone: () => {
|
|
191
|
+
done(false);
|
|
192
|
+
},
|
|
193
|
+
onClose: () => {
|
|
194
|
+
done(none);
|
|
195
|
+
}
|
|
196
|
+
}) : null]
|
|
188
197
|
});
|
|
189
198
|
}
|
|
190
199
|
export { GroupSection };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { needOf } from "./kind-needs.mjs";
|
|
3
|
+
import { fieldOptions } from "./options.mjs";
|
|
4
|
+
import { grainFor } from "./ranges.mjs";
|
|
5
|
+
import { Chip, OpenSection } from "./Sections.mjs";
|
|
6
|
+
import { useContext, useRef } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// src/builder/KindNeeds.tsx
|
|
9
|
+
/** The fields offered at once; the rest are a search away, in Group by. */
|
|
10
|
+
const OFFERED = 4;
|
|
11
|
+
/** The fields of the widget's source it does not group by yet, in the model's order. */
|
|
12
|
+
function freeFields(b) {
|
|
13
|
+
const query = b.state.query;
|
|
14
|
+
const taken = new Set((query?.dimensions ?? []).map((d) => d.member));
|
|
15
|
+
return fieldOptions(b.meta, query?.source ?? "").filter((field) => !taken.has(field.id));
|
|
16
|
+
}
|
|
17
|
+
/** The fields to group by, the first few as chips and the rest behind one that opens Group by. */
|
|
18
|
+
function Fields({ b, taken, search }) {
|
|
19
|
+
const { messages } = useDashboards();
|
|
20
|
+
const fields = freeFields(b);
|
|
21
|
+
if (fields.length === 0) return null;
|
|
22
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx("span", {
|
|
24
|
+
className: "dd-muted",
|
|
25
|
+
children: messages.groupBy
|
|
26
|
+
}),
|
|
27
|
+
fields.slice(0, OFFERED).map((field) => /* @__PURE__ */ jsx(Chip, {
|
|
28
|
+
add: true,
|
|
29
|
+
on: false,
|
|
30
|
+
label: field.label,
|
|
31
|
+
onClick: () => {
|
|
32
|
+
b.addGroup(field.id);
|
|
33
|
+
taken();
|
|
34
|
+
}
|
|
35
|
+
}, field.id)),
|
|
36
|
+
fields.length > OFFERED ? /* @__PURE__ */ jsx(Chip, {
|
|
37
|
+
add: true,
|
|
38
|
+
on: false,
|
|
39
|
+
label: messages.moreFields,
|
|
40
|
+
onClick: search
|
|
41
|
+
}) : null
|
|
42
|
+
] });
|
|
43
|
+
}
|
|
44
|
+
/** The widget's dates, where it has them and is not drawn over them yet: at the grain its range reads best at. */
|
|
45
|
+
function OverTime({ b, taken }) {
|
|
46
|
+
const { messages } = useDashboards();
|
|
47
|
+
const time = b.state.query?.time;
|
|
48
|
+
if (time === void 0 || time.grain !== void 0) return null;
|
|
49
|
+
return /* @__PURE__ */ jsx(Chip, {
|
|
50
|
+
add: true,
|
|
51
|
+
on: false,
|
|
52
|
+
label: messages.overTime,
|
|
53
|
+
onClick: () => {
|
|
54
|
+
b.setTime({ grain: grainFor(time.range) });
|
|
55
|
+
taken();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** The whole period, for a kind with no time axis whose widget is drawn over time. */
|
|
60
|
+
function Whole({ b, taken }) {
|
|
61
|
+
const { messages } = useDashboards();
|
|
62
|
+
return /* @__PURE__ */ jsx(Chip, {
|
|
63
|
+
add: true,
|
|
64
|
+
on: false,
|
|
65
|
+
label: messages.allTime,
|
|
66
|
+
onClick: () => {
|
|
67
|
+
b.setTime({ grain: "total" });
|
|
68
|
+
taken();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** The needs a field answers. */
|
|
73
|
+
const BY_FIELD = /* @__PURE__ */ new Set([
|
|
74
|
+
"split",
|
|
75
|
+
"cross",
|
|
76
|
+
"steps"
|
|
77
|
+
]);
|
|
78
|
+
/** The needs the widget's dates answer: periods are compared as a field's values are, and are one of a heatmap's two. */
|
|
79
|
+
const BY_DATES = /* @__PURE__ */ new Set([
|
|
80
|
+
"time",
|
|
81
|
+
"split",
|
|
82
|
+
"cross"
|
|
83
|
+
]);
|
|
84
|
+
/** What would answer a need: fields, the widget's dates, or the whole period. */
|
|
85
|
+
function Offers({ need, ...offer }) {
|
|
86
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
87
|
+
className: "dd-chips",
|
|
88
|
+
children: [
|
|
89
|
+
BY_FIELD.has(need) ? /* @__PURE__ */ jsx(Fields, { ...offer }) : null,
|
|
90
|
+
BY_DATES.has(need) ? /* @__PURE__ */ jsx(OverTime, { ...offer }) : null,
|
|
91
|
+
need === "whole" ? /* @__PURE__ */ jsx(Whole, { ...offer }) : null
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The line that says what the kind asks for, and the offers after it. Its region is always
|
|
97
|
+
* there, empty while the kind has what it draws from, so a screen reader hears the line as it
|
|
98
|
+
* comes. An offer taken may answer the need, and the chip pressed is then gone: focus goes to
|
|
99
|
+
* the kind it was pressed for, the pressed chip over the note, never to the page.
|
|
100
|
+
*/
|
|
101
|
+
function KindNeeds({ b }) {
|
|
102
|
+
const { messages } = useDashboards();
|
|
103
|
+
const fold = useContext(OpenSection);
|
|
104
|
+
const root = useRef(null);
|
|
105
|
+
const need = needOf(b.state.kind, b.state.query);
|
|
106
|
+
const within = (selector) => root.current?.closest(".dd-builder")?.querySelector(selector);
|
|
107
|
+
const taken = () => {
|
|
108
|
+
within(".dd-kinds [aria-pressed=\"true\"]")?.focus();
|
|
109
|
+
};
|
|
110
|
+
const search = () => {
|
|
111
|
+
fold?.setOpen(messages.groupBy, true);
|
|
112
|
+
requestAnimationFrame(() => within(".dd-builder-panel .dd-picker .dd-search")?.focus());
|
|
113
|
+
};
|
|
114
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
115
|
+
ref: root,
|
|
116
|
+
className: "dd-builder-needs",
|
|
117
|
+
"data-need": need,
|
|
118
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
119
|
+
role: "status",
|
|
120
|
+
children: need === void 0 ? null : messages.kindNeeds(b.state.kind, need)
|
|
121
|
+
}), need === void 0 ? null : /* @__PURE__ */ jsx(Offers, {
|
|
122
|
+
b,
|
|
123
|
+
need,
|
|
124
|
+
taken,
|
|
125
|
+
search
|
|
126
|
+
})]
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export { KindNeeds };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
// src/builder/KindSketch.tsx
|
|
3
|
+
const BARS = [
|
|
4
|
+
22,
|
|
5
|
+
34,
|
|
6
|
+
28,
|
|
7
|
+
46,
|
|
8
|
+
40,
|
|
9
|
+
58
|
|
10
|
+
];
|
|
11
|
+
const ROWS = [
|
|
12
|
+
10,
|
|
13
|
+
24,
|
|
14
|
+
38,
|
|
15
|
+
52
|
|
16
|
+
];
|
|
17
|
+
const SHADES = [
|
|
18
|
+
.25,
|
|
19
|
+
.45,
|
|
20
|
+
.35,
|
|
21
|
+
.7,
|
|
22
|
+
.3,
|
|
23
|
+
.55,
|
|
24
|
+
.8,
|
|
25
|
+
.5,
|
|
26
|
+
.4,
|
|
27
|
+
.65,
|
|
28
|
+
.9,
|
|
29
|
+
.6
|
|
30
|
+
];
|
|
31
|
+
const TREND = "6,54 24,44 42,48 60,30 78,34 96,18 114,22";
|
|
32
|
+
/** Columns standing on a baseline. */
|
|
33
|
+
const columns = BARS.map((tall, at) => /* @__PURE__ */ jsx("rect", {
|
|
34
|
+
x: 8 + at * 18,
|
|
35
|
+
y: 64 - tall,
|
|
36
|
+
width: 12,
|
|
37
|
+
height: tall,
|
|
38
|
+
rx: 2
|
|
39
|
+
}, tall));
|
|
40
|
+
/** A line through a few points, drawn and not filled. */
|
|
41
|
+
const line = (points, key = "line") => /* @__PURE__ */ jsx("polyline", {
|
|
42
|
+
points,
|
|
43
|
+
fill: "none",
|
|
44
|
+
stroke: "currentColor",
|
|
45
|
+
strokeWidth: 2.5
|
|
46
|
+
}, key);
|
|
47
|
+
/** Rows of a table: a heading and three columns of figures. */
|
|
48
|
+
const table = ROWS.flatMap((y, row) => [
|
|
49
|
+
8,
|
|
50
|
+
56,
|
|
51
|
+
88
|
|
52
|
+
].map((x, column) => /* @__PURE__ */ jsx("rect", {
|
|
53
|
+
x,
|
|
54
|
+
y,
|
|
55
|
+
width: column === 0 ? 36 : 24,
|
|
56
|
+
height: 6,
|
|
57
|
+
rx: 2,
|
|
58
|
+
opacity: row === 0 ? .45 : 1
|
|
59
|
+
}, `${String(y)}-${String(x)}`)));
|
|
60
|
+
/** Rows of a list: who, what under it, and a figure at the end. */
|
|
61
|
+
const list = ROWS.map((y) => /* @__PURE__ */ jsxs("g", { children: [
|
|
62
|
+
/* @__PURE__ */ jsx("circle", {
|
|
63
|
+
cx: 13,
|
|
64
|
+
cy: y + 5,
|
|
65
|
+
r: 5
|
|
66
|
+
}),
|
|
67
|
+
/* @__PURE__ */ jsx("rect", {
|
|
68
|
+
x: 24,
|
|
69
|
+
y,
|
|
70
|
+
width: 52,
|
|
71
|
+
height: 4,
|
|
72
|
+
rx: 2
|
|
73
|
+
}),
|
|
74
|
+
/* @__PURE__ */ jsx("rect", {
|
|
75
|
+
x: 24,
|
|
76
|
+
y: y + 7,
|
|
77
|
+
width: 34,
|
|
78
|
+
height: 3,
|
|
79
|
+
rx: 1.5,
|
|
80
|
+
opacity: .5
|
|
81
|
+
}),
|
|
82
|
+
/* @__PURE__ */ jsx("rect", {
|
|
83
|
+
x: 98,
|
|
84
|
+
y: y + 2,
|
|
85
|
+
width: 14,
|
|
86
|
+
height: 5,
|
|
87
|
+
rx: 2,
|
|
88
|
+
opacity: .5
|
|
89
|
+
})
|
|
90
|
+
] }, y));
|
|
91
|
+
/** A grid of cells, each shaded by its value. */
|
|
92
|
+
const grid = SHADES.map((shade, at) => /* @__PURE__ */ jsx("rect", {
|
|
93
|
+
x: 8 + at % 4 * 27,
|
|
94
|
+
y: 8 + Math.floor(at / 4) * 20,
|
|
95
|
+
width: 24,
|
|
96
|
+
height: 17,
|
|
97
|
+
rx: 3,
|
|
98
|
+
opacity: shade
|
|
99
|
+
}, String(at)));
|
|
100
|
+
/** Steps in order, each shorter than the one before. */
|
|
101
|
+
const steps = [
|
|
102
|
+
104,
|
|
103
|
+
78,
|
|
104
|
+
52,
|
|
105
|
+
30
|
|
106
|
+
].map((wide, at) => /* @__PURE__ */ jsx("rect", {
|
|
107
|
+
x: 8,
|
|
108
|
+
y: 8 + at * 15,
|
|
109
|
+
width: wide,
|
|
110
|
+
height: 10,
|
|
111
|
+
rx: 2,
|
|
112
|
+
opacity: 1 - at * .18
|
|
113
|
+
}, wide));
|
|
114
|
+
/** Four small charts, side by side. */
|
|
115
|
+
const panels = [
|
|
116
|
+
0,
|
|
117
|
+
1,
|
|
118
|
+
2,
|
|
119
|
+
3
|
|
120
|
+
].map((at) => {
|
|
121
|
+
const [x, y] = [6 + at % 2 * 58, 4 + Math.floor(at / 2) * 34];
|
|
122
|
+
const points = [
|
|
123
|
+
[0, 22],
|
|
124
|
+
[14, 12 + at % 3 * 3],
|
|
125
|
+
[28, 16],
|
|
126
|
+
[44, 4 + at * 2]
|
|
127
|
+
].map(([dx, dy]) => `${String(x + (dx ?? 0))},${String(y + (dy ?? 0))}`).join(" ");
|
|
128
|
+
return line(points, `panel${String(at)}`);
|
|
129
|
+
});
|
|
130
|
+
const SKETCHES = {
|
|
131
|
+
number: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
|
|
132
|
+
x: 8,
|
|
133
|
+
y: 18,
|
|
134
|
+
width: 72,
|
|
135
|
+
height: 22,
|
|
136
|
+
rx: 4
|
|
137
|
+
}), /* @__PURE__ */ jsx("rect", {
|
|
138
|
+
x: 8,
|
|
139
|
+
y: 48,
|
|
140
|
+
width: 44,
|
|
141
|
+
height: 6,
|
|
142
|
+
rx: 3,
|
|
143
|
+
opacity: .5
|
|
144
|
+
})] }),
|
|
145
|
+
line: line(TREND),
|
|
146
|
+
bar: columns,
|
|
147
|
+
table,
|
|
148
|
+
list,
|
|
149
|
+
area: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("polygon", {
|
|
150
|
+
points: `6,64 ${TREND} 114,64`,
|
|
151
|
+
opacity: .35
|
|
152
|
+
}), line(TREND)] }),
|
|
153
|
+
multiples: panels,
|
|
154
|
+
heatmap: grid,
|
|
155
|
+
funnel: steps
|
|
156
|
+
};
|
|
157
|
+
/** The drawing of a kind; columns for a kind of the host's own, which may draw anything. */
|
|
158
|
+
function KindSketch({ kind }) {
|
|
159
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
160
|
+
className: "dd-kind-sketch",
|
|
161
|
+
"data-kind": kind,
|
|
162
|
+
viewBox: "0 0 120 72",
|
|
163
|
+
"aria-hidden": "true",
|
|
164
|
+
focusable: "false",
|
|
165
|
+
children: SKETCHES[kind] ?? columns
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
export { KindSketch };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useDashboards } from "../context.mjs";
|
|
2
2
|
import { TableTile } from "../renderers/table.mjs";
|
|
3
3
|
import { Loading, Refused, Unrendered, rendererOf } from "../TileState.mjs";
|
|
4
|
+
import { KindSketch } from "./KindSketch.mjs";
|
|
4
5
|
import { useBuilder } from "./useBuilder.mjs";
|
|
6
|
+
import { kindLine } from "./words.mjs";
|
|
5
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
// src/builder/Preview.tsx
|
|
7
9
|
/** What the preview's tile shows: the chart, or why there is none. */
|
|
@@ -60,14 +62,32 @@ function Data({ tile, widget }) {
|
|
|
60
62
|
})]
|
|
61
63
|
});
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* In the chart's place before a measure is picked: a sketch of the kind picked, what to do,
|
|
67
|
+
* and what that kind is in a line (for a kind with no line of its own, what a measure is).
|
|
68
|
+
*/
|
|
69
|
+
function Empty({ b }) {
|
|
70
|
+
const { messages } = useDashboards();
|
|
71
|
+
const { kind } = b.state;
|
|
72
|
+
const says = kindLine(messages, kind);
|
|
73
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
74
|
+
className: "dd-builder-empty",
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsx(KindSketch, { kind }),
|
|
77
|
+
/* @__PURE__ */ jsx("b", { children: messages.pickMeasure }),
|
|
78
|
+
says === void 0 ? /* @__PURE__ */ jsx("span", { children: messages.pickMeasureHint }) : /* @__PURE__ */ jsxs("span", { children: [
|
|
79
|
+
/* @__PURE__ */ jsx("i", { children: messages.kinds[kind] ?? kind }),
|
|
80
|
+
" ",
|
|
81
|
+
says
|
|
82
|
+
] })
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
63
86
|
/** The live chart, drawn by the same renderer a tile uses; with `data`, its rows under it. */
|
|
64
87
|
function Preview({ b, data = false }) {
|
|
65
88
|
const { messages } = useDashboards();
|
|
66
89
|
const widget = b.widget;
|
|
67
|
-
if (widget === void 0) return /* @__PURE__ */
|
|
68
|
-
className: "dd-builder-empty",
|
|
69
|
-
children: [/* @__PURE__ */ jsx("b", { children: messages.pickMeasure }), /* @__PURE__ */ jsx("span", { children: messages.pickMeasureHint })]
|
|
70
|
-
});
|
|
90
|
+
if (widget === void 0) return /* @__PURE__ */ jsx(Empty, { b });
|
|
71
91
|
const answer = b.preview.answer;
|
|
72
92
|
const tile = answer === void 0 ? void 0 : {
|
|
73
93
|
...answer,
|
|
@@ -5,7 +5,6 @@ import { Picker } from "./Picker.mjs";
|
|
|
5
5
|
import { createContext, useContext, useState } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
// src/builder/Sections.tsx
|
|
8
|
-
/** Which section of the panel is open: one at a time, the others folded to a line. */
|
|
9
8
|
const OpenSection = createContext(void 0);
|
|
10
9
|
/**
|
|
11
10
|
* A titled part of the builder's panel, with its add link. Inside an `OpenSection`, only the open
|
|
@@ -71,6 +70,7 @@ function Chip(props) {
|
|
|
71
70
|
type: "button",
|
|
72
71
|
className: props.add === true ? "dd-chip dd-chip-add" : "dd-chip",
|
|
73
72
|
"aria-pressed": props.add === true ? void 0 : props.on,
|
|
73
|
+
title: props.title,
|
|
74
74
|
onClick: props.onClick,
|
|
75
75
|
children: props.label
|
|
76
76
|
});
|