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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
# derive-dashboards
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 380c1a9: Group and filter by an id, shown by its name. A string dimension may name another it is `shownAs`: rows group and filter by the id, so two rows that share a name never merge, and the name is shown wherever the value is.
|
|
8
|
+
|
|
9
|
+
- An answer's dimension column carries `labels`, each id's name, read in one query under the same viewer, policy and lock as the answer. `formatCell` and the built-in renderers show them.
|
|
10
|
+
- A filter control on a labelled field lists ids with their names, searches by name, and shows names in its chips; the picks stay ids. `/dashboards/control-values` takes `keys` (read these values back, with their labels) and answers `labels`; `/meta` marks the field `labelled`.
|
|
11
|
+
- A `shownAs` that names no plain string dimension of the source is refused (`SHOWN_AS_UNKNOWN`).
|
|
12
|
+
- `/query/records` takes `order`: page a source's rows by any of its dimensions (the key breaks ties), so a host lists a long page of rows by name or date with a cursor, never an offset.
|
|
13
|
+
- 49296cb: A table says more than its numbers, and a heatmap shows its best cell.
|
|
14
|
+
|
|
15
|
+
A table's widget may ask for four more things in its value columns (`display`):
|
|
16
|
+
|
|
17
|
+
- `trend`: a small chart of each row's time buckets before its number, columns for a count and a line for a rate. It needs a query over time that also asks for its whole (`time.grain` and `time.whole`); the table then has one row for each group over the whole range, and none for a bucket.
|
|
18
|
+
- `parts`: two values, one a part of the other (accepted, of shown), as one bar: as long as the whole beside the column's largest, with the part filled inside it. The two colours are keyed in the two columns' headers.
|
|
19
|
+
- `dots`: each value as a dot on a scale its column shares, with a tick where the total row stands. For a rate or an average: how each row compares with all of them.
|
|
20
|
+
- `change`: how each value moved against the comparison period, written after it ("↑ 0.9 pts"), in the colour of better or worse where the measure says which is which. It needs `time.compare`.
|
|
21
|
+
|
|
22
|
+
The builder offers `trend` and `change` only where the query has what they need, and a table over time that ticks its first small chart asks for its whole.
|
|
23
|
+
|
|
24
|
+
A heatmap outlines the one cell that holds its best value (the highest, or the lowest of a measure that is better lower) and keys it after its legend. A heatmap of few rows draws its cells as tiles, taller and set apart; one of many rows is as it was. For a chart of your own, `Words.best` names the key in your language.
|
|
25
|
+
|
|
26
|
+
Known gaps: a table's small chart is hidden from a screen reader, and a heatmap by two fields has no totals of its rows and columns.
|
|
27
|
+
- 3b1748d: The top of a dashboard says what a reader needs and no more.
|
|
28
|
+
|
|
29
|
+
- The date control names dates that are counted back from now, before the dates: "Previous 13 weeks", then "Aug 17 to Nov 15". It said the dates alone, so a reader could not tell whether they move with today. Dates need no name before them, so the control's own ("Period") is said to a screen reader only, and a small arrow after the dates says they open a calendar.
|
|
30
|
+
- The Filter button says "Filter". It read "+ Filter +5 F": how many filters wait in its menu, and the key that opens it, are now in its name for a screen reader and its title for a pointer.
|
|
31
|
+
- "Your view · Reset" is "Reset". Its title says whose the picks are ("Only you see these filters"); "From a link" is still written beside it while the picks are a link's.
|
|
32
|
+
- The choice that leaves every widget its own dates is called "Dashboard default" (it was "Each widget's own").
|
|
33
|
+
|
|
34
|
+
For a bar of your own: `FilterBarProps.period` is the dashboard's dates in words when they are counted back from now, beside `span`. `messages.filterBar.yourView` and `widgetDates` have new English.
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- ea23912: - A column that averages days too small for a float (0, 0 and −5e−324) stands on the side of zero its average is on.
|
|
39
|
+
- A value axis with room for only its fewest round numbers ends on its top tick: 28,001 to 34,001 reads 30K to 36K, not 30K to 34K with 34,001 above the last line.
|
|
40
|
+
- aa6b424: A grid's legend writes the key of its outlined cell ("Highest") only beside the row names, so a narrower grid never shows a key a wider one left out.
|
|
41
|
+
- bc03e8b: Names shown for an id follow the same rules as the name field itself.
|
|
42
|
+
|
|
43
|
+
- A query that reads a dimension `shownAs` another reads that one too: a viewer who may not read the names, or for whom they are sensitive, is refused, on `/query/run` and `/meta/values` alike.
|
|
44
|
+
- An id with two names keeps a name, and no other id loses its own.
|
|
45
|
+
- A filter lists a named field's values in the order of their names, each once.
|
|
46
|
+
- `shownAs` with its own `values` list is refused (`SHOWN_AS_VALUES`).
|
|
47
|
+
- The records body type takes `draft` again.
|
|
48
|
+
|
|
49
|
+
## 0.10.0
|
|
50
|
+
|
|
51
|
+
### Minor Changes
|
|
52
|
+
|
|
53
|
+
- 324d913: A dashboard that is being edited is drawn as the page a reader gets. Pressing Edit used to turn the ruled sheet into dashed cards on rows of one height: a number's tile grew, a table lost its last rows and its total behind a scroll of its own, a list was cut mid-row and a chart was shorter, so an editor arranged a page nobody would read.
|
|
54
|
+
|
|
55
|
+
- It is the same sheet while editing (or the same cards, with `tiles="cards"`), and every tile is the height a reader sees it at. Nothing on the page moves when Edit is pressed but the edit bar coming in over it.
|
|
56
|
+
- A tile's grip sits in its own margin, so its title does not move, and its Edit and Remove float over the end of its header on hover or focus, as Rows and CSV do when it is read, so a header is as tall edited as read.
|
|
57
|
+
- A drag is measured against the rows as they are drawn, whatever their heights: a tile lands on the row its top is nearest, and a dragged corner ends it on the row whose end it is nearest. While a drag lasts the rows keep the heights they had when it began, so the tiles that make room move no row under the pointer.
|
|
58
|
+
- On a sheet, a mark (New, Edited), a review's highlight, a tile just saved and a tile being dragged are drawn just inside the tile's edge, where a card shows them on its border.
|
|
59
|
+
- A removed tile's place is as tall as the row it is in. It was drawn two grid rows tall, so removing a number made its row jump.
|
|
60
|
+
|
|
61
|
+
For a renderer of your own: `TileRendererProps.fit` is true while a dashboard is edited too. A theme of your own that styled `.dd-dashboard[data-editing="false"]` to reach the sheet or a row's height now finds those rules on `.dd-dashboard` alone.
|
|
62
|
+
|
|
63
|
+
Known gap: a place the saved layout leaves empty (beside a tile made narrower, or where one was removed) is bare sheet while editing, and a reader sees the tiles beside it widened into it.
|
|
64
|
+
- f4287f0: A list's `display.href` must be a path on this site ("/tasks/{id}"). Editors write it, so an off-site, `javascript:` or `data:` link is refused when a document is checked, and one already stored is not drawn.
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- 324d913: Editing on a phone shows the page. The edit bar, pinned to the bottom of a phone's screen, was still held to its top as it is on a wide page, so it stretched over the whole screen: an editor on a phone saw a blank page with Undo, Done and Review and publish in the middle of it. It is one row at the bottom again. A tile's title has a line of its own there while editing, over its buttons, where five buttons left it a few letters ("Lifetime boosted…").
|
|
69
|
+
|
|
3
70
|
## 0.9.0
|
|
4
71
|
|
|
5
72
|
### Minor Changes
|
package/dist/body.mjs
CHANGED
|
@@ -61,6 +61,8 @@ const bodies = {
|
|
|
61
61
|
dashboardId: id,
|
|
62
62
|
controlId: id,
|
|
63
63
|
search: z.string().max(200).exactOptional(),
|
|
64
|
+
/** Only these values: what a chosen pick shows, with its labels. */
|
|
65
|
+
keys: z.array(z.string().max(500)).max(200).readonly().exactOptional(),
|
|
64
66
|
limit: page.limit,
|
|
65
67
|
draft: z.literal(true).exactOptional()
|
|
66
68
|
}),
|
|
@@ -73,7 +75,9 @@ const bodies = {
|
|
|
73
75
|
queryBatch: strict({ queries: z.array(wireQuerySchema).min(1).max(50) }),
|
|
74
76
|
queryRecords: strict({
|
|
75
77
|
query: wireQuerySchema,
|
|
76
|
-
...page
|
|
78
|
+
...page,
|
|
79
|
+
/** The order to page in, by the source's dimensions; the source's key breaks every tie. */
|
|
80
|
+
order: z.array(z.tuple([z.string().min(1).max(200), z.enum(["asc", "desc"])]).readonly()).min(1).max(4).readonly().exactOptional()
|
|
77
81
|
}),
|
|
78
82
|
list: strict({}),
|
|
79
83
|
newDashboard: strict({
|
|
@@ -30,6 +30,11 @@ export type Words = {
|
|
|
30
30
|
* each bar: 90th percentile". English when left out.
|
|
31
31
|
*/
|
|
32
32
|
against?: (what: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Under a heatmap, names the one cell it outlines: the highest value, or the lowest of a
|
|
35
|
+
* measure that is better lower. English when left out.
|
|
36
|
+
*/
|
|
37
|
+
best?: (which: "highest" | "lowest") => string;
|
|
33
38
|
funnel: {
|
|
34
39
|
/** Between two steps: the share of the step above that went on, written as a percent. */
|
|
35
40
|
continues: (percent: string) => string;
|
|
@@ -9,6 +9,7 @@ const ENGLISH = {
|
|
|
9
9
|
averaged: (count) => `drawn as an average of ${String(count)}`,
|
|
10
10
|
merged: (count, grain, approximate) => "Each column is the average of " + (approximate ? "about " : "") + String(count) + " " + grain + (count === 1 ? "" : "s"),
|
|
11
11
|
against: (what) => `The line on each bar: ${what}`,
|
|
12
|
+
best: (which) => which === "highest" ? "Highest" : "Lowest",
|
|
12
13
|
funnel: {
|
|
13
14
|
continues: (percent) => `${percent} continue`,
|
|
14
15
|
largestDrop: "largest drop",
|
|
@@ -77,15 +77,18 @@ function valuedIn(series, slot) {
|
|
|
77
77
|
*/
|
|
78
78
|
function meanIn(values, slot, of) {
|
|
79
79
|
let mean = 0;
|
|
80
|
+
let sum = 0;
|
|
80
81
|
let count = 0;
|
|
81
82
|
for (let i = slot.from; i < slot.to; i++) {
|
|
82
83
|
const value = values[i] ?? null;
|
|
83
84
|
if (value === null) continue;
|
|
84
85
|
count += 1;
|
|
86
|
+
sum += value;
|
|
85
87
|
mean += value / count - mean / count;
|
|
86
88
|
}
|
|
87
89
|
if (count === 0) return null;
|
|
88
|
-
|
|
90
|
+
const kept = mean === 0 && Number.isFinite(sum) ? sum : mean;
|
|
91
|
+
return of === void 0 ? kept : kept * (count / of);
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
91
94
|
* The series as their columns are drawn: one value a column, the average of the column's
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { keyOf, pairKey } from "../data/rows.mjs";
|
|
2
|
+
import { wordsOf } from "../data/words.mjs";
|
|
2
3
|
import { shapesFor } from "../marks/budget.mjs";
|
|
3
4
|
import { widest } from "../text/measure.mjs";
|
|
4
5
|
import { LINE, MARK, SPACE, TEXT } from "../theme.mjs";
|
|
@@ -7,8 +8,39 @@ import { namesWidth, rowFrame, rowPlot } from "./row-chart.mjs";
|
|
|
7
8
|
// src/kinds/grid-layout.ts
|
|
8
9
|
/** The room the column names take over the cells: a line of them, and the grid's own gap under it. */
|
|
9
10
|
const HEAD = LINE.tick + 6;
|
|
10
|
-
/**
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A row is this tall at most: the rows of a grid share a height, so a grid of few rows draws
|
|
13
|
+
* them as tiles and a grid of many keeps them close.
|
|
14
|
+
*/
|
|
15
|
+
const TALLEST = {
|
|
16
|
+
few: 52,
|
|
17
|
+
many: 30,
|
|
18
|
+
shared: 208
|
|
19
|
+
};
|
|
20
|
+
/** The tallest a row may be in a grid of so many rows. */
|
|
21
|
+
const tallestFor = (rows) => Math.min(TALLEST.few, Math.max(TALLEST.many, TALLEST.shared / Math.max(1, rows)));
|
|
22
|
+
/**
|
|
23
|
+
* A cell as large as a tile is set apart from its neighbours by more than a hair, and rounded
|
|
24
|
+
* as a tile is: both sides of it are at least `least`.
|
|
25
|
+
*/
|
|
26
|
+
const TILE = {
|
|
27
|
+
least: 36,
|
|
28
|
+
gap: 3,
|
|
29
|
+
radius: 5
|
|
30
|
+
};
|
|
31
|
+
/** How cells are parted and rounded: as tiles where both their sides have the room, else by a hair. */
|
|
32
|
+
const partingOf = (rowHeight, step) => Math.min(rowHeight, step) >= TILE.least ? {
|
|
33
|
+
gap: TILE.gap,
|
|
34
|
+
radius: TILE.radius
|
|
35
|
+
} : {
|
|
36
|
+
gap: MARK.hair,
|
|
37
|
+
radius: MARK.round
|
|
38
|
+
};
|
|
39
|
+
/** The outlined square that keys the best cell in the legend, and the room before it. */
|
|
40
|
+
const BEST_KEY = {
|
|
41
|
+
size: 9,
|
|
42
|
+
lead: 14
|
|
43
|
+
};
|
|
12
44
|
/** The legend's ramp: how wide and how tall it is, and how many steps of shade it is made of. */
|
|
13
45
|
const RAMP = {
|
|
14
46
|
width: 96,
|
|
@@ -57,6 +89,22 @@ function endsWritten(ends, measure) {
|
|
|
57
89
|
* the height it is given.
|
|
58
90
|
*/
|
|
59
91
|
function legendFit(options, data, env, ends = colorsOf(data, options.range, options.diverging).ends) {
|
|
92
|
+
const fit = rampFit(options, data, env, ends);
|
|
93
|
+
if (fit === void 0) return void 0;
|
|
94
|
+
const { needs, beside, ...legend } = fit;
|
|
95
|
+
const which = bestOf(data, options.measure)?.which;
|
|
96
|
+
const word = which === void 0 ? void 0 : wordsOf(env).best(which);
|
|
97
|
+
const key = word === void 0 ? 0 : BEST_KEY.lead + BEST_KEY.size + SPACE.value + env.measure(word, TEXT.tick);
|
|
98
|
+
const edge = needs > beside;
|
|
99
|
+
const best = legend.named && !edge && needs + key <= beside ? word : void 0;
|
|
100
|
+
return {
|
|
101
|
+
...legend,
|
|
102
|
+
best,
|
|
103
|
+
edge
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** The legend's numbers, ramp and name, and the width they need. */
|
|
107
|
+
function rampFit(options, data, env, ends) {
|
|
60
108
|
const { label } = options.measure;
|
|
61
109
|
const words = endsWritten(ends, options.measure);
|
|
62
110
|
if (words === void 0) return void 0;
|
|
@@ -72,7 +120,31 @@ function legendFit(options, data, env, ends = colorsOf(data, options.range, opti
|
|
|
72
120
|
ends,
|
|
73
121
|
words,
|
|
74
122
|
named,
|
|
75
|
-
|
|
123
|
+
needs: named ? numbers + wide(label) : numbers,
|
|
124
|
+
beside
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The one cell that holds the best value, by the keys of its row and its column: the highest,
|
|
129
|
+
* or the lowest of a measure that is better lower. None when two cells share it (a grid whose
|
|
130
|
+
* every first month is 100% has no one best), and none for a grid of one cell.
|
|
131
|
+
*/
|
|
132
|
+
function bestOf(data, measure) {
|
|
133
|
+
const which = measure.better === "down" ? "lowest" : "highest";
|
|
134
|
+
const sign = which === "lowest" ? -1 : 1;
|
|
135
|
+
const cells = data.rows.flatMap((row, r) => data.columns.flatMap((column, c) => {
|
|
136
|
+
const value = data.values[r]?.[c] ?? null;
|
|
137
|
+
return value === null ? [] : [{
|
|
138
|
+
key: pairKey(keyOf(row), keyOf(column)),
|
|
139
|
+
value
|
|
140
|
+
}];
|
|
141
|
+
}));
|
|
142
|
+
const top = cells.reduce((most, cell) => Math.max(most, sign * cell.value), Number.NEGATIVE_INFINITY);
|
|
143
|
+
const best = cells.filter((cell) => sign * cell.value === top);
|
|
144
|
+
const [only] = best;
|
|
145
|
+
return cells.length < 2 || best.length !== 1 || only === void 0 ? void 0 : {
|
|
146
|
+
key: only.key,
|
|
147
|
+
which
|
|
76
148
|
};
|
|
77
149
|
}
|
|
78
150
|
/**
|
|
@@ -84,7 +156,7 @@ const rowRule = (options, data, env, legend = legendFit(options, data, env)) =>
|
|
|
84
156
|
header: options,
|
|
85
157
|
above: HEAD + (options.columnTitle === void 0 ? 0 : LINE.tick),
|
|
86
158
|
below: legend === void 0 ? 0 : LEGEND,
|
|
87
|
-
most:
|
|
159
|
+
most: tallestFor(data.rows.length),
|
|
88
160
|
cap: capOf(data, env)
|
|
89
161
|
});
|
|
90
162
|
/**
|
|
@@ -104,15 +176,19 @@ function layoutOf(data, options, env, ends) {
|
|
|
104
176
|
from: x,
|
|
105
177
|
to: x + width
|
|
106
178
|
};
|
|
179
|
+
const step = width / Math.max(1, data.columns.length);
|
|
107
180
|
const placed = {
|
|
108
181
|
frame,
|
|
109
182
|
sizes,
|
|
110
|
-
step
|
|
183
|
+
step,
|
|
184
|
+
...partingOf(frame.rowHeight, step),
|
|
111
185
|
plot: rowPlot(frame, across, frame.shown)
|
|
112
186
|
};
|
|
113
187
|
const filled = cellsOf(data, placed);
|
|
188
|
+
const best = bestOf(data, options.measure)?.key;
|
|
114
189
|
return {
|
|
115
190
|
...placed,
|
|
191
|
+
best: best === void 0 ? void 0 : filled.find((cell) => cell.key === best),
|
|
116
192
|
kept: data.rows.slice(0, frame.shown),
|
|
117
193
|
across,
|
|
118
194
|
filled,
|
|
@@ -126,8 +202,8 @@ function layoutOf(data, options, env, ends) {
|
|
|
126
202
|
const boxAt = (at, layout) => ({
|
|
127
203
|
x: layout.plot.x + at.column * layout.step,
|
|
128
204
|
y: layout.plot.y + at.row * layout.frame.rowHeight,
|
|
129
|
-
width: Math.max(MARK.least, layout.step -
|
|
130
|
-
height: Math.max(MARK.least, layout.frame.rowHeight -
|
|
205
|
+
width: Math.max(MARK.least, layout.step - layout.gap),
|
|
206
|
+
height: Math.max(MARK.least, layout.frame.rowHeight - layout.gap)
|
|
131
207
|
});
|
|
132
208
|
/** Every place of the rows drawn, with the value the data has there, if any. */
|
|
133
209
|
const placesOf = (data, shown) => data.rows.slice(0, shown).flatMap((named, row) => data.columns.map((across, column) => ({
|
|
@@ -149,4 +225,4 @@ const emptyOf = (data, layout) => placesOf(data, layout.frame.shown).flatMap(({
|
|
|
149
225
|
...place,
|
|
150
226
|
box: boxAt(place, layout)
|
|
151
227
|
}] : []);
|
|
152
|
-
export { RAMP, layoutOf, rowRule };
|
|
228
|
+
export { BEST_KEY, RAMP, layoutOf, rowRule };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RULE } from "../scene/paint.mjs";
|
|
1
|
+
import { INK, RULE } from "../scene/paint.mjs";
|
|
2
2
|
import { pathRound } from "../scene/markup.mjs";
|
|
3
3
|
import { LINE, MARK, SPACE, TEXT } from "../theme.mjs";
|
|
4
|
-
import { RAMP } from "./grid-layout.mjs";
|
|
5
|
-
import { fillOf } from "./grid-marks.mjs";
|
|
4
|
+
import { BEST_KEY, RAMP } from "./grid-layout.mjs";
|
|
5
|
+
import { OUTLINE, fillOf, roundedPath } from "./grid-marks.mjs";
|
|
6
6
|
// src/kinds/grid-legend.ts
|
|
7
7
|
/**
|
|
8
8
|
* The legend under the rows, the top of its room at `y`; nothing when there is none, or when the
|
|
@@ -49,12 +49,35 @@ function legendNodes(at, y) {
|
|
|
49
49
|
stroke: RULE,
|
|
50
50
|
strokeWidth: MARK.hair
|
|
51
51
|
};
|
|
52
|
+
const named = after(most, end);
|
|
52
53
|
return [
|
|
53
54
|
text(least, start),
|
|
54
55
|
...steps,
|
|
55
56
|
frame,
|
|
56
57
|
text(most, end),
|
|
57
|
-
...legend.named ? [text(measure.label,
|
|
58
|
+
...legend.named ? [text(measure.label, named)] : [],
|
|
59
|
+
...legend.best === void 0 || layout.best === void 0 ? [] : bestKey(legend.best, {
|
|
60
|
+
x: after(measure.label, named) - SPACE.value,
|
|
61
|
+
middle,
|
|
62
|
+
text
|
|
63
|
+
})
|
|
58
64
|
];
|
|
59
65
|
}
|
|
66
|
+
/** The key of the outlined cell, after the legend's name: a small outlined square, then its word. */
|
|
67
|
+
function bestKey(word, at) {
|
|
68
|
+
const x = at.x + BEST_KEY.lead;
|
|
69
|
+
const box = {
|
|
70
|
+
x,
|
|
71
|
+
y: at.middle - BEST_KEY.size / 2,
|
|
72
|
+
width: BEST_KEY.size,
|
|
73
|
+
height: BEST_KEY.size
|
|
74
|
+
};
|
|
75
|
+
return [{
|
|
76
|
+
kind: "path",
|
|
77
|
+
part: "legend",
|
|
78
|
+
d: roundedPath(box, MARK.round),
|
|
79
|
+
stroke: INK,
|
|
80
|
+
strokeWidth: OUTLINE
|
|
81
|
+
}, at.text(word, x + BEST_KEY.size + SPACE.value)];
|
|
82
|
+
}
|
|
60
83
|
export { legendNodes };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { keyOf } from "../data/rows.mjs";
|
|
2
|
-
import { MUTED, SURFACE } from "../scene/paint.mjs";
|
|
2
|
+
import { INK, MUTED, SURFACE } from "../scene/paint.mjs";
|
|
3
|
+
import { pathRound } from "../scene/markup.mjs";
|
|
3
4
|
import { fitOrNone, fitted, wholeOf } from "../text/measure.mjs";
|
|
4
5
|
import { LINE, MARK, SPACE, TEXT } from "../theme.mjs";
|
|
5
6
|
import { rowName } from "./row-marks.mjs";
|
|
@@ -135,7 +136,7 @@ const emptyNodes = (layout) => layout.empty.map(({ key, box }) => ({
|
|
|
135
136
|
y: box.y + MARK.hair / 2,
|
|
136
137
|
width: Math.max(0, box.width - MARK.hair),
|
|
137
138
|
height: Math.max(0, box.height - MARK.hair),
|
|
138
|
-
radius:
|
|
139
|
+
radius: layout.radius,
|
|
139
140
|
fill: SURFACE,
|
|
140
141
|
stroke: MUTED,
|
|
141
142
|
strokeWidth: MARK.hair
|
|
@@ -173,7 +174,7 @@ function cellNodes(cell, at) {
|
|
|
173
174
|
part: "cell",
|
|
174
175
|
key: cell.key,
|
|
175
176
|
...box,
|
|
176
|
-
radius:
|
|
177
|
+
radius: at.layout.radius,
|
|
177
178
|
...fillOf(cell, at)
|
|
178
179
|
}, ...write === void 0 ? [] : [{
|
|
179
180
|
kind: "text",
|
|
@@ -186,4 +187,55 @@ function cellNodes(cell, at) {
|
|
|
186
187
|
baseline: "middle"
|
|
187
188
|
}]];
|
|
188
189
|
}
|
|
189
|
-
|
|
190
|
+
/** How thick the best cell's outline is. */
|
|
191
|
+
const OUTLINE = 1.5;
|
|
192
|
+
/** How far short of a corner a curve's handles stop, as a share of the radius: a quarter of a circle, near enough. */
|
|
193
|
+
const HANDLE = .4477;
|
|
194
|
+
/**
|
|
195
|
+
* A box with rounded corners as a path of lines and curves: an outline has no fill, which a
|
|
196
|
+
* rectangle must have. Every point it names is inside the box.
|
|
197
|
+
*/
|
|
198
|
+
function roundedPath(box, radius) {
|
|
199
|
+
const r = Math.max(0, Math.min(radius, box.width / 2, box.height / 2));
|
|
200
|
+
const k = r * HANDLE;
|
|
201
|
+
const [left, top, right, bottom] = [
|
|
202
|
+
box.x,
|
|
203
|
+
box.y,
|
|
204
|
+
box.x + box.width,
|
|
205
|
+
box.y + box.height
|
|
206
|
+
];
|
|
207
|
+
const at = (x, y) => `${pathRound(x)},${pathRound(y)}`;
|
|
208
|
+
return [
|
|
209
|
+
`M${at(left + r, top)}L${at(right - r, top)}`,
|
|
210
|
+
`C${at(right - k, top)} ${at(right, top + k)} ${at(right, top + r)}L${at(right, bottom - r)}`,
|
|
211
|
+
`C${at(right, bottom - k)} ${at(right - k, bottom)} ${at(right - r, bottom)}L${at(left + r, bottom)}`,
|
|
212
|
+
`C${at(left + k, bottom)} ${at(left, bottom - k)} ${at(left, bottom - r)}L${at(left, top + r)}`,
|
|
213
|
+
`C${at(left, top + k)} ${at(left + k, top)} ${at(left + r, top)}Z`
|
|
214
|
+
].join("");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The outline of the one cell that holds the best value (`bestOf`), in ink, just inside the
|
|
218
|
+
* cell's own edge so it never runs past the picture: the cell a reader looks for is found
|
|
219
|
+
* without reading every number. It is no mark of the cell's own, so it has no key: a pointer
|
|
220
|
+
* finds the cell, not its outline. Nothing when no one cell is best, or it is not among the
|
|
221
|
+
* rows drawn.
|
|
222
|
+
*/
|
|
223
|
+
function bestNodes(at) {
|
|
224
|
+
const { best, radius } = at.layout;
|
|
225
|
+
if (best === void 0) return [];
|
|
226
|
+
const { box } = best;
|
|
227
|
+
const inset = OUTLINE / 2;
|
|
228
|
+
return [{
|
|
229
|
+
kind: "path",
|
|
230
|
+
part: "best",
|
|
231
|
+
d: roundedPath({
|
|
232
|
+
x: box.x + inset,
|
|
233
|
+
y: box.y + inset,
|
|
234
|
+
width: Math.max(0, box.width - OUTLINE),
|
|
235
|
+
height: Math.max(0, box.height - OUTLINE)
|
|
236
|
+
}, radius - inset),
|
|
237
|
+
stroke: INK,
|
|
238
|
+
strokeWidth: OUTLINE
|
|
239
|
+
}];
|
|
240
|
+
}
|
|
241
|
+
export { OUTLINE, bestNodes, cellNodes, colorOf, emptyNodes, fillOf, heads, roundedPath, sides, strengthOf };
|
|
@@ -6,7 +6,7 @@ import { rowsMore } from "./row-marks.mjs";
|
|
|
6
6
|
import { cleaned, colorsOf } from "./grid-data.mjs";
|
|
7
7
|
import { layoutOf, rowRule } from "./grid-layout.mjs";
|
|
8
8
|
import { legendNodes } from "./grid-legend.mjs";
|
|
9
|
-
import { cellNodes, emptyNodes, heads, sides } from "./grid-marks.mjs";
|
|
9
|
+
import { bestNodes, cellNodes, emptyNodes, heads, sides } from "./grid-marks.mjs";
|
|
10
10
|
import { fitTimeGrid } from "./grid-time.mjs";
|
|
11
11
|
import { describeGrid, matrixOf, stopsOf } from "./grid-words.mjs";
|
|
12
12
|
import { hasRoom, sizingOf, wantsOf } from "./row-chart.mjs";
|
|
@@ -77,6 +77,7 @@ function gridChart(given, options, env) {
|
|
|
77
77
|
...sides(options, at),
|
|
78
78
|
...emptyNodes(layout),
|
|
79
79
|
...layout.filled.flatMap((cell) => cellNodes(cell, at)),
|
|
80
|
+
...bestNodes(at),
|
|
80
81
|
...rowsMore(left, {
|
|
81
82
|
frame,
|
|
82
83
|
env
|
|
@@ -101,19 +101,26 @@ function ownEnds(low, high, count) {
|
|
|
101
101
|
for (let ask = 1; ask <= count + SPARE; ask++) {
|
|
102
102
|
const ticks = stepped(low, high, ask);
|
|
103
103
|
if (ticks.length < 2) continue;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
max: high,
|
|
107
|
-
ticks
|
|
108
|
-
};
|
|
109
|
-
const fit = [ticks, everyOther(ticks)].map((some) => toppedOff(some, high)).find((some) => {
|
|
104
|
+
const topped = [ticks, everyOther(ticks)].map((some) => toppedOff(some, high));
|
|
105
|
+
const keeps = (some) => {
|
|
110
106
|
const top = some.at(-1) ?? high;
|
|
111
107
|
const zeroBack = !holdsZero(low, high) && holdsZero(low, top);
|
|
112
|
-
return some.length >= 2 &&
|
|
108
|
+
return some.length >= 2 && !zeroBack && !stretched({
|
|
113
109
|
min: low,
|
|
114
110
|
max: top
|
|
115
111
|
}, low, high);
|
|
116
|
-
}
|
|
112
|
+
};
|
|
113
|
+
const top = topped[0] ?? ticks;
|
|
114
|
+
first ??= keeps(top) ? {
|
|
115
|
+
min: low,
|
|
116
|
+
max: Math.max(high, top.at(-1) ?? high),
|
|
117
|
+
ticks: top
|
|
118
|
+
} : {
|
|
119
|
+
min: low,
|
|
120
|
+
max: high,
|
|
121
|
+
ticks
|
|
122
|
+
};
|
|
123
|
+
const fit = topped.find((some) => keeps(some) && some.length <= count + 1);
|
|
117
124
|
if (fit !== void 0) return {
|
|
118
125
|
min: low,
|
|
119
126
|
max: Math.max(high, fit.at(-1) ?? high),
|
|
@@ -24,7 +24,7 @@ export type Box = {
|
|
|
24
24
|
* the two move as one when labels are spread apart): it is an `end-label`, not a `name` and a
|
|
25
25
|
* `value`.
|
|
26
26
|
*/
|
|
27
|
-
export type Part = "header" | "legend" | "more" | "grid" | "tick" | "zero" | "axis-name" | "column" | "reference" | "event" | "guide" | "series" | "line" | "wash" | "before" | "dot" | "end" | "from" | "to" | "link" | "leader" | "bar" | "lost" | "against" | "join" | "band" | "edge" | "settled" | "open" | "cell" | "name" | "value" | "size" | "change" | "share" | "rate" | "leak" | "end-label";
|
|
27
|
+
export type Part = "header" | "legend" | "more" | "grid" | "tick" | "zero" | "axis-name" | "column" | "reference" | "event" | "guide" | "series" | "line" | "wash" | "before" | "dot" | "end" | "from" | "to" | "link" | "leader" | "bar" | "lost" | "against" | "join" | "band" | "edge" | "settled" | "open" | "cell" | "best" | "name" | "value" | "size" | "change" | "share" | "rate" | "leak" | "end-label";
|
|
28
28
|
type Shared = {
|
|
29
29
|
/** What the mark is of, as the data names it: a row's, a series' or a cell's key. Every mark of one thing carries it (a row's name and its bar), and so does its hover stop. */
|
|
30
30
|
key?: string;
|
|
@@ -3,7 +3,14 @@ import { entryAliases, entryNamed } from "../query/to-wire.mjs";
|
|
|
3
3
|
/** The options of each kind that name values of the widget's query. */
|
|
4
4
|
const NAMES_VALUES = {
|
|
5
5
|
number: ["value", "secondary"],
|
|
6
|
-
table: [
|
|
6
|
+
table: [
|
|
7
|
+
"bars",
|
|
8
|
+
"heat",
|
|
9
|
+
"dots",
|
|
10
|
+
"parts",
|
|
11
|
+
"trend",
|
|
12
|
+
"change"
|
|
13
|
+
],
|
|
7
14
|
bar: ["against"]
|
|
8
15
|
};
|
|
9
16
|
/** The options of a kind that name values; none for a host's own kind. */
|
|
@@ -41,7 +48,7 @@ function valuesOf(widget) {
|
|
|
41
48
|
}
|
|
42
49
|
/**
|
|
43
50
|
* What a widget's display names that its query does not have: each option that names a value
|
|
44
|
-
* (a number's `value` and `secondary`, a table's `bars` and `
|
|
51
|
+
* (a number's `value` and `secondary`, a table's `bars`, `heat`, `dots`, `parts`, `trend` and `change`) with a name that is no
|
|
45
52
|
* measure or calc of the widget's main query, at the option's path. None for a kind with no
|
|
46
53
|
* such option, a widget with no main query, or a display that is not an object.
|
|
47
54
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** The types an option may have. */
|
|
2
|
-
export type OptionType = "boolean" | "text" | "texts" | "colors" | "comparisons";
|
|
2
|
+
export type OptionType = "boolean" | "text" | "link" | "texts" | "colors" | "comparisons";
|
|
3
3
|
/** The first field groups the selected row; the second optionally groups its children. */
|
|
4
4
|
type DistinctPair<First extends string, All extends string = First> = First extends unknown ? readonly [First, Exclude<All, First>] : never;
|
|
5
5
|
export type ComparisonFields<Field extends string = string> = readonly [Field] | (string extends Field ? readonly [Field, Field] : DistinctPair<Field>);
|
|
6
|
-
type ValueOf<T, Field extends string = string> = T extends "comparisons" ? Readonly<Record<string, ComparisonFields<Field>>> : T extends "boolean" ? boolean : T extends "text" ? string : T extends "texts" ? readonly string[] : Readonly<Record<string, string>>;
|
|
6
|
+
type ValueOf<T, Field extends string = string> = T extends "comparisons" ? Readonly<Record<string, ComparisonFields<Field>>> : T extends "boolean" ? boolean : T extends "text" | "link" ? string : T extends "texts" ? readonly string[] : Readonly<Record<string, string>>;
|
|
7
7
|
/** Options every widget takes. */
|
|
8
8
|
declare const SHARED: {
|
|
9
9
|
readonly keepDateRange: "boolean";
|
|
@@ -24,6 +24,10 @@ export declare const DISPLAY_OPTIONS: {
|
|
|
24
24
|
readonly table: {
|
|
25
25
|
readonly bars: "texts";
|
|
26
26
|
readonly heat: "texts";
|
|
27
|
+
readonly dots: "texts";
|
|
28
|
+
readonly parts: "texts";
|
|
29
|
+
readonly trend: "texts";
|
|
30
|
+
readonly change: "texts";
|
|
27
31
|
readonly compact: "boolean";
|
|
28
32
|
readonly comparisons: "comparisons";
|
|
29
33
|
readonly full: "boolean";
|
|
@@ -35,7 +39,7 @@ export declare const DISPLAY_OPTIONS: {
|
|
|
35
39
|
readonly subtitle: "texts";
|
|
36
40
|
readonly avatar: "text";
|
|
37
41
|
readonly meta: "text";
|
|
38
|
-
readonly href: "
|
|
42
|
+
readonly href: "link";
|
|
39
43
|
readonly keepDateRange: "boolean";
|
|
40
44
|
readonly empty: "text";
|
|
41
45
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { didYouMean } from "../model/validate/fields.mjs";
|
|
2
|
+
import { linkWhereIssues } from "../query/drill/links.mjs";
|
|
2
3
|
// src/document/display.ts
|
|
3
4
|
/** Options every widget takes. */
|
|
4
5
|
const SHARED = {
|
|
@@ -24,6 +25,10 @@ const DISPLAY_OPTIONS = {
|
|
|
24
25
|
...SHARED,
|
|
25
26
|
bars: "texts",
|
|
26
27
|
heat: "texts",
|
|
28
|
+
dots: "texts",
|
|
29
|
+
parts: "texts",
|
|
30
|
+
trend: "texts",
|
|
31
|
+
change: "texts",
|
|
27
32
|
compact: "boolean",
|
|
28
33
|
comparisons: "comparisons",
|
|
29
34
|
full: "boolean"
|
|
@@ -34,7 +39,7 @@ const DISPLAY_OPTIONS = {
|
|
|
34
39
|
subtitle: "texts",
|
|
35
40
|
avatar: "text",
|
|
36
41
|
meta: "text",
|
|
37
|
-
href: "
|
|
42
|
+
href: "link"
|
|
38
43
|
},
|
|
39
44
|
line: CHART,
|
|
40
45
|
bar: {
|
|
@@ -61,6 +66,10 @@ const DISPLAY_HELP = {
|
|
|
61
66
|
full: "Write amounts in full: a number tile's large value, and a table's column of amounts that are all a thousand or more, are otherwise rounded to whole units.",
|
|
62
67
|
bars: "Query entries drawn with a bar in each cell, as long as the value is beside the column's largest.",
|
|
63
68
|
heat: "Query entries whose cells are shaded by their value, darker for more.",
|
|
69
|
+
dots: "Query entries drawn as a dot on a scale their column shares, with a tick where the total row stands: how each row compares with all of them. For a rate or an average, which is no length.",
|
|
70
|
+
parts: "Two query entries, one a part of the other (accepted, of shown): the whole's column draws a bar as long as its value beside the column's largest, with the part filled inside it.",
|
|
71
|
+
change: "Query entries whose change from the comparison period is written after their value: which way, and how far (points for a rate, a percent of where it was for an amount). The query needs time.compare, and over time buckets time.whole too.",
|
|
72
|
+
trend: "Query entries drawn with a small chart of their time buckets beside each row's value. The query needs a time grain and time.whole: the table then has one row for each group over the whole range, not one for each bucket.",
|
|
64
73
|
comparisons: "For a value of the first grouping column, name the drill field for its comparison table and optionally the field to expand each group by.",
|
|
65
74
|
compact: "Draw a table's rows closer together.",
|
|
66
75
|
colors: "A colour per series, by the series' label: any CSS colour.",
|
|
@@ -71,7 +80,7 @@ const DISPLAY_HELP = {
|
|
|
71
80
|
subtitle: "Query entries shown under the title, joined with a dot.",
|
|
72
81
|
avatar: "The query entry whose initials make the row's avatar.",
|
|
73
82
|
meta: "The query entry shown as the number at the end of the row.",
|
|
74
|
-
href: "A link per row, with {entry} replaced by that entry's value: \"/tasks/{id}\"."
|
|
83
|
+
href: "A link per row, a path on this site, with {entry} replaced by that entry's value: \"/tasks/{id}\"."
|
|
75
84
|
};
|
|
76
85
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
77
86
|
const isText = (value) => typeof value === "string";
|
|
@@ -85,6 +94,10 @@ const TYPES = {
|
|
|
85
94
|
fits: isText,
|
|
86
95
|
takes: "text"
|
|
87
96
|
},
|
|
97
|
+
link: {
|
|
98
|
+
fits: (v) => isText(v) && linkWhereIssues(v, false).length === 0,
|
|
99
|
+
takes: "a path on this site, starting with one \"/\" (\"/tasks/{id}\")"
|
|
100
|
+
},
|
|
88
101
|
texts: {
|
|
89
102
|
fits: (v) => Array.isArray(v) && v.every((entry) => isText(entry)),
|
|
90
103
|
takes: "a list of texts"
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* older code, or in an older shape, is never read. `test/engine-version.test.ts` checks it
|
|
6
6
|
* against the files and prints the new value when they change.
|
|
7
7
|
*/
|
|
8
|
-
export declare const ENGINE_VERSION = "
|
|
8
|
+
export declare const ENGINE_VERSION = "0184cbc78d9b6863";
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* older code, or in an older shape, is never read. `test/engine-version.test.ts` checks it
|
|
7
7
|
* against the files and prints the new value when they change.
|
|
8
8
|
*/
|
|
9
|
-
const ENGINE_VERSION = "
|
|
9
|
+
const ENGINE_VERSION = "0184cbc78d9b6863";
|
|
10
10
|
export { ENGINE_VERSION };
|
|
@@ -56,6 +56,8 @@ export declare const MODEL_ISSUES: {
|
|
|
56
56
|
readonly REF_JOIN_TO_MANY: "A dimension reference goes through a join to many rows.";
|
|
57
57
|
readonly REF_JOIN_UNKNOWN: "A dimension reference names a join that does not exist.";
|
|
58
58
|
readonly SHARED_DIMENSIONS_RESERVED: "The model declares shared dimensions, which are reserved.";
|
|
59
|
+
readonly SHOWN_AS_UNKNOWN: "A dimension's shownAs names no string dimension of its source, or one shown as another itself.";
|
|
60
|
+
readonly SHOWN_AS_VALUES: "A dimension shown as another also declares its own list of values.";
|
|
59
61
|
readonly SOURCES_EMPTY: "The model has no source.";
|
|
60
62
|
readonly TABLE_EMPTY: "A source's table name is empty.";
|
|
61
63
|
readonly TABLE_AND_SQL: "A source gives both a table and sql; it reads one of them.";
|
|
@@ -59,6 +59,8 @@ const MODEL_ISSUES = {
|
|
|
59
59
|
REF_JOIN_TO_MANY: "A dimension reference goes through a join to many rows.",
|
|
60
60
|
REF_JOIN_UNKNOWN: "A dimension reference names a join that does not exist.",
|
|
61
61
|
SHARED_DIMENSIONS_RESERVED: "The model declares shared dimensions, which are reserved.",
|
|
62
|
+
SHOWN_AS_UNKNOWN: "A dimension's shownAs names no string dimension of its source, or one shown as another itself.",
|
|
63
|
+
SHOWN_AS_VALUES: "A dimension shown as another also declares its own list of values.",
|
|
62
64
|
SOURCES_EMPTY: "The model has no source.",
|
|
63
65
|
TABLE_EMPTY: "A source's table name is empty.",
|
|
64
66
|
TABLE_AND_SQL: "A source gives both a table and sql; it reads one of them.",
|