derive-dashboards 0.2.0 → 0.3.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/dist/cache.mjs +2 -1
- package/dist/cli/add.mjs +1 -1
- package/dist/cli/doctor.mjs +39 -24
- package/dist/core/document/display.d.mts +63 -0
- package/dist/core/document/display.mjs +139 -0
- package/dist/core/engine/version.d.mts +5 -4
- package/dist/core/engine/version.mjs +5 -4
- package/dist/core/error/codes.d.mts +2 -0
- package/dist/core/error/codes.mjs +2 -0
- package/dist/core/index.d.mts +9 -7
- package/dist/core/index.mjs +7 -5
- package/dist/core/model/validate/drill.mjs +6 -15
- package/dist/core/model/validate/fields.mjs +130 -0
- package/dist/core/model/validate/index.mjs +11 -3
- package/dist/core/model/validate/known-members.mjs +133 -0
- package/dist/core/model/validate/known-nested.mjs +85 -0
- package/dist/core/model/validate/known.mjs +94 -0
- package/dist/core/model/validate/source.mjs +8 -1
- package/dist/core/query/alias.mjs +11 -1
- package/dist/core/query/drill/selection.d.mts +7 -2
- package/dist/core/query/drill/selection.mjs +18 -15
- package/dist/core/result/columns.d.mts +10 -1
- package/dist/core/result/columns.mjs +21 -2
- package/dist/core/result/time-axis.d.mts +23 -0
- package/dist/core/result/time-axis.mjs +72 -0
- package/dist/core/result/types.d.mts +36 -1
- package/dist/core/schema/answer-parts.mjs +23 -1
- package/dist/core/schema/answers.d.mts +203 -0
- package/dist/core/schema/answers.mjs +1 -0
- package/dist/core/schema/tools.d.mts +2 -0
- package/dist/core/schema/tools.mjs +27 -1
- package/dist/core/time/bucket.mjs +8 -2
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/drill-change.mjs +1 -1
- package/dist/drill-seal.mjs +1 -0
- package/dist/endpoints/index.d.mts +3 -0
- package/dist/execute.mjs +13 -7
- package/dist/index.mjs +6 -1
- package/dist/react/Dashboard.d.mts +4 -0
- package/dist/react/Dashboard.mjs +12 -1
- package/dist/react/Tile.mjs +11 -4
- package/dist/react/context.d.mts +2 -1
- package/dist/react/drill/Bars.mjs +2 -2
- package/dist/react/drill/props.mjs +2 -1
- package/dist/react/index.d.mts +5 -2
- package/dist/react/index.mjs +4 -2
- package/dist/react/renderers/index.d.mts +3 -21
- package/dist/react/renderers/index.mjs +3 -3
- package/dist/react/renderers/list.d.mts +2 -1
- package/dist/react/renderers/list.mjs +8 -11
- package/dist/react/renderers/props.d.mts +26 -0
- package/dist/react/scope.d.mts +4 -0
- package/dist/react/scope.mjs +19 -2
- package/dist/react/series-slots.d.mts +37 -0
- package/dist/react/series-slots.mjs +71 -0
- package/dist/react/series.d.mts +19 -6
- package/dist/react/series.mjs +75 -74
- package/dist/recharts/bar.mjs +5 -4
- package/dist/recharts/line.mjs +5 -4
- package/dist/recharts/parts.mjs +29 -14
- package/dist/skills/derive-dashboards/SKILL.md +1 -1
- package/dist/store/apply.mjs +3 -1
- package/package.json +4 -4
package/dist/react/series.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CellFormat } from "./messages.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { SeriesSlots } from "./series-slots.mjs";
|
|
3
|
+
import { ResultColumn, TileAnswer, TimeBucket } from "derive-dashboards/core";
|
|
3
4
|
/** One point of a chart: its x label, its place (`#`, never an entry id) and a number per series key. */
|
|
4
5
|
export type Point = {
|
|
5
6
|
x: string;
|
|
@@ -7,12 +8,15 @@ export type Point = {
|
|
|
7
8
|
/**
|
|
8
9
|
* A drawn series: its key in each point, its label and the column it reads. `axis` is the side
|
|
9
10
|
* of the chart its scale is read on: values in another unit than the first get the right axis.
|
|
11
|
+
* `slot` is its place in the palette, which follows the series and not its position: a value of
|
|
12
|
+
* a field keeps its slot whatever else is drawn (`seriesSlots`). Other has none: it is the grey.
|
|
10
13
|
*/
|
|
11
14
|
export type Series = {
|
|
12
15
|
key: string;
|
|
13
16
|
label: string;
|
|
14
17
|
column: ResultColumn;
|
|
15
18
|
axis: "left" | "right";
|
|
19
|
+
slot?: number;
|
|
16
20
|
};
|
|
17
21
|
/** The series key a dimension's Other draws as. */
|
|
18
22
|
export declare const OTHER_KEY = "other";
|
|
@@ -24,8 +28,11 @@ export declare const OTHER_KEY = "other";
|
|
|
24
28
|
* Values in a second unit are read on a right axis; a third unit, or more values than a split can
|
|
25
29
|
* draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
|
|
26
30
|
* keyed by raw values, so two that read alike stay apart. Totals are not drawn.
|
|
31
|
+
*
|
|
32
|
+
* `slots` is the dashboard's book of palette places, so a value has one colour on every tile;
|
|
33
|
+
* left out, the chart keeps a book of its own.
|
|
27
34
|
*/
|
|
28
|
-
export declare function toSeries(answer:
|
|
35
|
+
export declare function toSeries(answer: Answer, format?: CellFormat, slots?: SeriesSlots): Drawn;
|
|
29
36
|
/**
|
|
30
37
|
* What a chart draws, and the way back from any chart kit's point to the answer's row:
|
|
31
38
|
* `rowAt(point, seriesKey)` gives the row's index in `answer.rows` (for a drill), or undefined
|
|
@@ -36,8 +43,15 @@ export type Drawn = {
|
|
|
36
43
|
series: Series[];
|
|
37
44
|
split: boolean;
|
|
38
45
|
notDrawn: ResultColumn[];
|
|
46
|
+
/**
|
|
47
|
+
* When the x axis is time: each point's bucket as instants, in the points' order, with
|
|
48
|
+
* `partial` on one whose value is not whole (the week still running). What a chart draws
|
|
49
|
+
* time on; the points' `x` is only the bucket's name.
|
|
50
|
+
*/
|
|
51
|
+
buckets?: readonly (TimeBucket | undefined)[];
|
|
39
52
|
rowAt: (point: number | Point, seriesKey: string) => number | undefined;
|
|
40
53
|
};
|
|
54
|
+
type Answer = Pick<TileAnswer, "columns" | "rows" | "time">;
|
|
41
55
|
/**
|
|
42
56
|
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
43
57
|
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
@@ -47,8 +61,7 @@ export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: str
|
|
|
47
61
|
/**
|
|
48
62
|
* Whether the answer's last time bucket is still running: the range ends before the bucket
|
|
49
63
|
* does, as this week does on its Monday. Its value is not final, so a chart marks it rather
|
|
50
|
-
* than draw it as a fall.
|
|
64
|
+
* than draw it as a fall. The server says so (`answer.time`), by the engine's own calendar.
|
|
51
65
|
*/
|
|
52
|
-
export declare function lastBucketOpen(answer: Pick<TileAnswer, "columns" | "rows">
|
|
53
|
-
|
|
54
|
-
}): boolean;
|
|
66
|
+
export declare function lastBucketOpen(answer: Pick<TileAnswer, "columns" | "rows" | "time">): boolean;
|
|
67
|
+
export {};
|
package/dist/react/series.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { formatCell, plotValue } from "./format.mjs";
|
|
2
2
|
import { ENGLISH } from "./english.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { seriesSlots } from "./series-slots.mjs";
|
|
4
|
+
import { isMark, roleOf } from "derive-dashboards/core";
|
|
4
5
|
// src/series.ts
|
|
5
|
-
const isValue = (c) => c
|
|
6
|
+
const isValue = (c) => roleOf(c) === "measure" || roleOf(c) === "calc";
|
|
6
7
|
/** The series key a dimension's Other draws as. */
|
|
7
8
|
const OTHER_KEY = "other";
|
|
8
9
|
const isAll = (cell) => isMark(cell) && cell.mark === "all";
|
|
@@ -20,45 +21,61 @@ const scaleOf = (c) => JSON.stringify([
|
|
|
20
21
|
* Values in a second unit are read on a right axis; a third unit, or more values than a split can
|
|
21
22
|
* draw, are not drawn and are named in `notDrawn`, never silently dropped. Points and series are
|
|
22
23
|
* keyed by raw values, so two that read alike stay apart. Totals are not drawn.
|
|
24
|
+
*
|
|
25
|
+
* `slots` is the dashboard's book of palette places, so a value has one colour on every tile;
|
|
26
|
+
* left out, the chart keeps a book of its own.
|
|
23
27
|
*/
|
|
24
|
-
function toSeries(answer, format = {}) {
|
|
28
|
+
function toSeries(answer, format = {}, slots) {
|
|
25
29
|
const at = /* @__PURE__ */ new Map();
|
|
26
|
-
const
|
|
30
|
+
const shape = shapeOf(answer, format, slots ?? seriesSlots(), (point, key, row) => {
|
|
27
31
|
at.set(`${String(point)}|${key}`, row);
|
|
28
32
|
});
|
|
33
|
+
const { xs, ...drawn } = drawSeries(answer, shape);
|
|
29
34
|
return {
|
|
30
35
|
...drawn,
|
|
36
|
+
...bucketsOf(answer, shape.keys, xs),
|
|
31
37
|
rowAt: (point, key) => {
|
|
32
38
|
const index = typeof point === "number" ? point : drawn.points.indexOf(point);
|
|
33
39
|
return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
|
|
34
40
|
}
|
|
35
41
|
};
|
|
36
42
|
}
|
|
43
|
+
/** Each point's time bucket, when the x axis is the answer's time column. */
|
|
44
|
+
function bucketsOf(answer, keys, xs) {
|
|
45
|
+
const x = answer.columns[keys[0] ?? -1];
|
|
46
|
+
if (answer.time === void 0 || x === void 0 || roleOf(x) !== "time") return {};
|
|
47
|
+
const named = new Map(answer.time.buckets.map((b) => [b.label, b]));
|
|
48
|
+
return { buckets: xs.map((cell) => typeof cell === "string" ? named.get(cell) : void 0) };
|
|
49
|
+
}
|
|
37
50
|
/** The values to draw: calcs when there are any (what the widget was built to see), else measures. */
|
|
38
51
|
function valuesOf(columns) {
|
|
39
52
|
const all = columns.filter((c) => isValue(c));
|
|
40
|
-
const calcs = all.filter((c) =>
|
|
53
|
+
const calcs = all.filter((c) => roleOf(c) === "calc");
|
|
41
54
|
return calcs.length > 0 ? calcs : all;
|
|
42
55
|
}
|
|
43
|
-
|
|
56
|
+
/** How an answer is read into a chart: its key columns, how a key reads, and the book of slots. */
|
|
57
|
+
function shapeOf(answer, format, slots, seen) {
|
|
44
58
|
const keys = answer.columns.flatMap((c, i) => isValue(c) ? [] : [i]);
|
|
45
|
-
const values = valuesOf(answer.columns);
|
|
46
|
-
const rows = answer.rows.map((row, index) => ({
|
|
47
|
-
row,
|
|
48
|
-
index
|
|
49
|
-
})).filter(({ row }) => !row.some((cell) => isAll(cell)));
|
|
50
59
|
const keyText = (cell, column) => {
|
|
51
60
|
if (cell !== null && cell !== "") return formatCell(cell, column, format);
|
|
52
61
|
const words = format.messages ?? ENGLISH;
|
|
53
62
|
return column === void 0 ? words.empty : words.drillNone(column.label);
|
|
54
63
|
};
|
|
55
|
-
|
|
64
|
+
return {
|
|
56
65
|
answer,
|
|
57
66
|
keys,
|
|
58
67
|
keyText,
|
|
59
|
-
seen
|
|
68
|
+
seen,
|
|
69
|
+
slots
|
|
60
70
|
};
|
|
61
|
-
|
|
71
|
+
}
|
|
72
|
+
function drawSeries(answer, shape) {
|
|
73
|
+
const values = valuesOf(answer.columns);
|
|
74
|
+
const rows = answer.rows.map((row, index) => ({
|
|
75
|
+
row,
|
|
76
|
+
index
|
|
77
|
+
})).filter(({ row }) => !row.some((cell) => isAll(cell)));
|
|
78
|
+
return shape.keys.length < 2 ? plainSeries(rows, values, shape) : splitSeries(rows, values, shape);
|
|
62
79
|
}
|
|
63
80
|
/** The x label of a row, from its first key. */
|
|
64
81
|
const xOf = (shape, row) => {
|
|
@@ -70,25 +87,29 @@ function plainSeries(rows, values, shape) {
|
|
|
70
87
|
const scales = [...new Set(values.map((c) => scaleOf(c)))];
|
|
71
88
|
const side = (c) => scales.indexOf(scaleOf(c));
|
|
72
89
|
const drawn = values.filter((c) => side(c) < 2);
|
|
73
|
-
const series = drawn.map((column) => ({
|
|
90
|
+
const series = drawn.map((column, slot) => ({
|
|
74
91
|
key: column.id,
|
|
75
92
|
label: column.label,
|
|
76
93
|
column,
|
|
77
|
-
axis: side(column) === 0 ? "left" : "right"
|
|
94
|
+
axis: side(column) === 0 ? "left" : "right",
|
|
95
|
+
slot
|
|
78
96
|
}));
|
|
97
|
+
const points = rows.map(({ row, index }, i) => {
|
|
98
|
+
shape.seen(i, "*", index);
|
|
99
|
+
const cells = drawn.map((c) => [c.id, plotValue(row[shape.answer.columns.indexOf(c)] ?? null)]);
|
|
100
|
+
return {
|
|
101
|
+
x: xOf(shape, row),
|
|
102
|
+
"#": i,
|
|
103
|
+
...Object.fromEntries(cells)
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
const xs = rows.map(({ row }) => row[shape.keys[0] ?? -1] ?? null);
|
|
79
107
|
return {
|
|
80
|
-
points
|
|
81
|
-
shape.seen(i, "*", index);
|
|
82
|
-
const cells = drawn.map((c) => [c.id, plotValue(row[shape.answer.columns.indexOf(c)] ?? null)]);
|
|
83
|
-
return {
|
|
84
|
-
x: xOf(shape, row),
|
|
85
|
-
"#": i,
|
|
86
|
-
...Object.fromEntries(cells)
|
|
87
|
-
};
|
|
88
|
-
}),
|
|
108
|
+
points,
|
|
89
109
|
series,
|
|
90
110
|
split: false,
|
|
91
|
-
notDrawn: values.filter((c) => side(c) >= 2)
|
|
111
|
+
notDrawn: values.filter((c) => side(c) >= 2),
|
|
112
|
+
xs
|
|
92
113
|
};
|
|
93
114
|
}
|
|
94
115
|
/** One value split into a series per combination of the keys after the first; other values are not drawn. */
|
|
@@ -98,18 +119,25 @@ function splitSeries(rows, values, shape) {
|
|
|
98
119
|
points: [],
|
|
99
120
|
series: [],
|
|
100
121
|
split: true,
|
|
101
|
-
notDrawn: []
|
|
122
|
+
notDrawn: [],
|
|
123
|
+
xs: []
|
|
102
124
|
};
|
|
103
125
|
const { answer, keys, keyText } = shape;
|
|
104
126
|
const valueAt = answer.columns.indexOf(first);
|
|
105
127
|
const byX = /* @__PURE__ */ new Map();
|
|
128
|
+
const xs = [];
|
|
106
129
|
const names = /* @__PURE__ */ new Map();
|
|
107
130
|
for (const { row, index } of rows) {
|
|
108
|
-
const
|
|
109
|
-
const key = splitKey(
|
|
110
|
-
const label =
|
|
111
|
-
names.set(key,
|
|
112
|
-
|
|
131
|
+
const cells = keys.slice(1).map((i) => row[i] ?? null);
|
|
132
|
+
const key = splitKey(cells);
|
|
133
|
+
const label = cells.map((cell, i) => keyText(cell, answer.columns[keys[i + 1] ?? -1]));
|
|
134
|
+
names.set(key, {
|
|
135
|
+
label: label.join(" · "),
|
|
136
|
+
cells
|
|
137
|
+
});
|
|
138
|
+
const x = row[keys[0] ?? 0] ?? null;
|
|
139
|
+
const xKey = JSON.stringify(x);
|
|
140
|
+
if (!byX.has(xKey)) xs.push(x);
|
|
113
141
|
const point = byX.get(xKey) ?? {
|
|
114
142
|
x: xOf(shape, row),
|
|
115
143
|
"#": byX.size
|
|
@@ -118,17 +146,24 @@ function splitSeries(rows, values, shape) {
|
|
|
118
146
|
byX.set(xKey, point);
|
|
119
147
|
shape.seen(Number(point["#"]), key, index);
|
|
120
148
|
}
|
|
121
|
-
const
|
|
149
|
+
const by = keys.slice(1).flatMap((i) => answer.columns[i] ?? []);
|
|
150
|
+
const series = [...names].map(([key, { label, cells }]) => ({
|
|
122
151
|
key,
|
|
123
152
|
label,
|
|
124
153
|
column: first,
|
|
125
|
-
axis: "left"
|
|
154
|
+
axis: "left",
|
|
155
|
+
...key === "other" ? {} : { slot: shape.slots.of({
|
|
156
|
+
by,
|
|
157
|
+
key,
|
|
158
|
+
cells
|
|
159
|
+
}) }
|
|
126
160
|
})).toSorted((a, b) => Number(a.key === OTHER_KEY) - Number(b.key === OTHER_KEY));
|
|
127
161
|
return {
|
|
128
162
|
points: [...byX.values()],
|
|
129
163
|
series,
|
|
130
164
|
split: true,
|
|
131
|
-
notDrawn: rest
|
|
165
|
+
notDrawn: rest,
|
|
166
|
+
xs
|
|
132
167
|
};
|
|
133
168
|
}
|
|
134
169
|
/** A series' key from its split cells: Other stays "other", any value is its raw JSON. */
|
|
@@ -143,49 +178,15 @@ function splitKey(cells) {
|
|
|
143
178
|
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
144
179
|
*/
|
|
145
180
|
const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
|
|
146
|
-
const DAY = 864e5;
|
|
147
|
-
const DAYS = {
|
|
148
|
-
day: 1,
|
|
149
|
-
week: 7
|
|
150
|
-
};
|
|
151
|
-
const MONTHS = {
|
|
152
|
-
month: 1,
|
|
153
|
-
quarter: 3,
|
|
154
|
-
year: 12
|
|
155
|
-
};
|
|
156
|
-
/** A calendar date ("2026-11-16") as the UTC midnight that names it. */
|
|
157
|
-
const dateOf = (text) => {
|
|
158
|
-
const [year = 0, month = 1, day = 1] = text.slice(0, 10).split("-").map(Number);
|
|
159
|
-
return Date.UTC(year, month - 1, day);
|
|
160
|
-
};
|
|
161
|
-
/** Where a bucket that starts on a calendar date ends, at its grain; none for a grain it cannot step. */
|
|
162
|
-
function bucketEnd(start, grain) {
|
|
163
|
-
const days = DAYS[grain];
|
|
164
|
-
if (days !== void 0) return start + days * DAY;
|
|
165
|
-
const months = MONTHS[grain];
|
|
166
|
-
if (months === void 0) return void 0;
|
|
167
|
-
const at = new Date(start);
|
|
168
|
-
return Date.UTC(at.getUTCFullYear(), at.getUTCMonth() + months, at.getUTCDate());
|
|
169
|
-
}
|
|
170
|
-
/** An instant as the calendar day it falls on in a zone, named as a bucket names its day. */
|
|
171
|
-
const dayIn = (instant, timeZone) => new Intl.DateTimeFormat("en-CA", {
|
|
172
|
-
timeZone,
|
|
173
|
-
year: "numeric",
|
|
174
|
-
month: "2-digit",
|
|
175
|
-
day: "2-digit"
|
|
176
|
-
}).format(new Date(instant));
|
|
177
181
|
/**
|
|
178
182
|
* Whether the answer's last time bucket is still running: the range ends before the bucket
|
|
179
183
|
* does, as this week does on its Monday. Its value is not final, so a chart marks it rather
|
|
180
|
-
* than draw it as a fall.
|
|
184
|
+
* than draw it as a fall. The server says so (`answer.time`), by the engine's own calendar.
|
|
181
185
|
*/
|
|
182
186
|
function lastBucketOpen(answer) {
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
if (!/^\d{4}-\d{2}-\d{2}/u.test(last)) return false;
|
|
188
|
-
const end = bucketEnd(dateOf(last), grain);
|
|
189
|
-
return end !== void 0 && dateOf(dayIn(to, answer.receipt.calendar.timezone)) + DAY < end;
|
|
187
|
+
const at = answer.columns.findIndex((c) => roleOf(c) === "time");
|
|
188
|
+
const last = answer.rows.findLast((row) => typeof row[at] === "string")?.[at];
|
|
189
|
+
const bucket = answer.time?.buckets.find((b) => b.label === last);
|
|
190
|
+
return bucket?.partial === "end" || bucket?.partial === "both";
|
|
190
191
|
}
|
|
191
192
|
export { OTHER_KEY, lastBucketOpen, rowAt, toSeries };
|
package/dist/recharts/bar.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { yAxis } from "./axis.mjs";
|
|
2
2
|
import { openPoint } from "./marks.mjs";
|
|
3
|
-
import { CHART, TOOLTIP,
|
|
3
|
+
import { CHART, TOOLTIP, legendText, runningLabel, seriesColors, tooltipFormat, tooltipLabel } from "./parts.mjs";
|
|
4
4
|
import { toSeries } from "./series.mjs";
|
|
5
5
|
import { Beside } from "./table.mjs";
|
|
6
6
|
import { useState } from "react";
|
|
@@ -81,8 +81,9 @@ function barAxes(overTime, values, points) {
|
|
|
81
81
|
function BarTile(props) {
|
|
82
82
|
const { answer, locale, drill } = props;
|
|
83
83
|
const [focused, setFocused] = useState(null);
|
|
84
|
-
const drawn = toSeries(answer, props);
|
|
84
|
+
const drawn = toSeries(answer, props, props.slots);
|
|
85
85
|
const { points, series, split } = drawn;
|
|
86
|
+
const painted = seriesColors(props, series);
|
|
86
87
|
const overTime = answer.columns[0]?.type === "time" || answer.columns[0]?.grain !== void 0;
|
|
87
88
|
const running = overTime ? runningLabel(props, points) : void 0;
|
|
88
89
|
const values = yAxis(series, points, locale, split);
|
|
@@ -113,10 +114,10 @@ function BarTile(props) {
|
|
|
113
114
|
itemSorter: null,
|
|
114
115
|
formatter: legendText
|
|
115
116
|
}) : null,
|
|
116
|
-
|
|
117
|
+
painted.map(({ series: s, color }, i) => /* @__PURE__ */ jsx(Bar, {
|
|
117
118
|
dataKey: s.key,
|
|
118
119
|
name: s.label,
|
|
119
|
-
fill: color
|
|
120
|
+
fill: color,
|
|
120
121
|
...split ? {
|
|
121
122
|
stackId: "split",
|
|
122
123
|
stroke: "var(--dd-surface)",
|
package/dist/recharts/line.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { yAxes } from "./axes.mjs";
|
|
2
2
|
import { openPoint } from "./marks.mjs";
|
|
3
|
-
import { CHART, TOOLTIP,
|
|
3
|
+
import { CHART, TOOLTIP, dashOf, legendText, runningLabel, seriesColors, tooltipFormat, tooltipLabel } from "./parts.mjs";
|
|
4
4
|
import { toSeries } from "./series.mjs";
|
|
5
5
|
import { Beside } from "./table.mjs";
|
|
6
6
|
import { useState } from "react";
|
|
@@ -50,8 +50,9 @@ function runningArea(props, points) {
|
|
|
50
50
|
function LineTile(props) {
|
|
51
51
|
const { answer, locale, drill } = props;
|
|
52
52
|
const [focused, setFocused] = useState(null);
|
|
53
|
-
const drawn = toSeries(answer, props);
|
|
53
|
+
const drawn = toSeries(answer, props, props.slots);
|
|
54
54
|
const { points, series } = drawn;
|
|
55
|
+
const painted = seriesColors(props, series);
|
|
55
56
|
const onClick = lineClick(drill, drawn);
|
|
56
57
|
const running = runningLabel(props, points);
|
|
57
58
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -87,11 +88,11 @@ function LineTile(props) {
|
|
|
87
88
|
itemSorter: null,
|
|
88
89
|
formatter: legendText
|
|
89
90
|
}) : null,
|
|
90
|
-
|
|
91
|
+
painted.map(({ series: s, color }, i) => /* @__PURE__ */ jsx(Line, {
|
|
91
92
|
dataKey: s.key,
|
|
92
93
|
name: s.label,
|
|
93
94
|
yAxisId: s.axis,
|
|
94
|
-
stroke: color
|
|
95
|
+
stroke: color,
|
|
95
96
|
strokeWidth: 2,
|
|
96
97
|
...dashOf(i),
|
|
97
98
|
legendType: "plainline",
|
package/dist/recharts/parts.mjs
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import { OTHER_KEY } from "./series.mjs";
|
|
2
2
|
import { cellText } from "./table.mjs";
|
|
3
|
-
import { lastBucketOpen } from "derive-dashboards/react";
|
|
3
|
+
import { chartColors, lastBucketOpen } from "derive-dashboards/react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { displayOf } from "derive-dashboards/core";
|
|
5
6
|
// src/parts.tsx
|
|
6
|
-
/** A series' colour: the palette in order, and Other always the quiet grey. */
|
|
7
7
|
/** Legend words in the text color: a series' hue marks its swatch, never its name. */
|
|
8
8
|
const legendText = (value) => /* @__PURE__ */ jsx("span", {
|
|
9
9
|
className: "dd-chart-legend",
|
|
10
10
|
children: value
|
|
11
11
|
});
|
|
12
|
-
/** A widget's own
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
/** A widget's own colour for a series, by its label (`display.colors`). */
|
|
13
|
+
const ownColor = (props, s) => displayOf("line", props.widget.display).colors?.[s.label];
|
|
14
|
+
/** The palette's colours, `--dd-series-1` to `--dd-series-6`. */
|
|
15
|
+
const PALETTE = 6;
|
|
16
|
+
/**
|
|
17
|
+
* Each series with its colour, in the series' order: the widget's own for it, else Other's quiet grey,
|
|
18
|
+
* else the palette's at the series' slot, which follows the series and not where it is drawn. In
|
|
19
|
+
* one chart two series share a colour only past the palette's six (`chartColors`).
|
|
20
|
+
*/
|
|
21
|
+
function seriesColors(props, series) {
|
|
22
|
+
const placed = series.map((s, at) => s.key === OTHER_KEY ? {} : { slot: s.slot ?? at });
|
|
23
|
+
const palette = chartColors(placed, PALETTE);
|
|
24
|
+
return series.map((s, at) => {
|
|
25
|
+
const place = palette[at];
|
|
26
|
+
const fallback = place === void 0 ? "var(--dd-other)" : `var(--dd-series-${place + 1})`;
|
|
27
|
+
return {
|
|
28
|
+
series: s,
|
|
29
|
+
color: ownColor(props, s) ?? fallback
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
22
33
|
/**
|
|
23
34
|
* A tooltip's value: the answer's own cell behind the point, in its own series' column, so an
|
|
24
35
|
* exact amount reads exactly and each series keeps its unit. Only the pixels use the float.
|
|
@@ -43,7 +54,11 @@ const DASHES = [
|
|
|
43
54
|
"2 3",
|
|
44
55
|
"10 3 2 3"
|
|
45
56
|
];
|
|
46
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The i-th line's dash, or none for the first: a solid line takes no dash at all. The dash goes
|
|
59
|
+
* by where the line is drawn, not by its series' slot: its job is to tell the lines of one chart
|
|
60
|
+
* apart without colour, and two slots four apart would share a dash.
|
|
61
|
+
*/
|
|
47
62
|
const dashOf = (i) => {
|
|
48
63
|
const dash = DASHES[i % DASHES.length];
|
|
49
64
|
return dash === void 0 ? {} : { strokeDasharray: dash };
|
|
@@ -85,4 +100,4 @@ const CHART = {
|
|
|
85
100
|
left: 0
|
|
86
101
|
}
|
|
87
102
|
};
|
|
88
|
-
export { CHART, TOOLTIP,
|
|
103
|
+
export { CHART, TOOLTIP, dashOf, legendText, runningLabel, seriesColors, tooltipFormat, tooltipLabel };
|
|
@@ -15,7 +15,7 @@ the `derive-dashboards` CLI. Docs: https://github.com/derive-to/dashboards/tree/
|
|
|
15
15
|
Check, and say what you found:
|
|
16
16
|
- Postgres (node-postgres `Pool`, or PGlite with a folder) is reachable. Other databases: a custom
|
|
17
17
|
data layer (`docs/custom-data-layer.md`).
|
|
18
|
-
- React 19 for the UI. Next.js: the provider and dashboards render from a `"use client"` file.
|
|
18
|
+
- React 18.3 or 19 for the UI (the filter bar that `add` copies into the app needs React 19). Next.js: the provider and dashboards render from a `"use client"` file.
|
|
19
19
|
- How the app knows who is signed in: the handler needs a `viewer(request)` that returns the
|
|
20
20
|
person (with tenant values when the model has tenant keys) or `null`.
|
|
21
21
|
|
package/dist/store/apply.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { sha256 } from "../cache.mjs";
|
|
|
2
2
|
import { HttpError } from "../http.mjs";
|
|
3
3
|
import { writeCommands } from "./commands.mjs";
|
|
4
4
|
import { advanceDraft, draftOf, expectRevision, inTransaction, namedOf, now, openDraft } from "./rows.mjs";
|
|
5
|
-
import { canonical, reduceAll } from "derive-dashboards/core";
|
|
5
|
+
import { canonical, editedDisplayIssues, reduceAll } from "derive-dashboards/core";
|
|
6
6
|
// src/store/apply.ts
|
|
7
7
|
/** Applying edits to a draft: each batch all or nothing, each command once. */
|
|
8
8
|
const bodyOf = ({ commandId: _id, ...body }) => body;
|
|
@@ -68,6 +68,8 @@ function applyDraft(db, a) {
|
|
|
68
68
|
expectRevision(row, a.expectedRevision);
|
|
69
69
|
const outcome = reduceAll(current.doc, fresh.map((c) => bodyOf(c)));
|
|
70
70
|
if (!outcome.ok) throw new HttpError(400, "EDIT_REFUSED", outcome.issue.message, { issues: [outcome.issue] });
|
|
71
|
+
const wrong = editedDisplayIssues(current.doc, outcome.doc);
|
|
72
|
+
if (wrong[0] !== void 0) throw new HttpError(400, "EDIT_REFUSED", wrong[0].message, { issues: wrong });
|
|
71
73
|
const revision = current.revision + 1;
|
|
72
74
|
const at = now();
|
|
73
75
|
const first = Number(row.next_seq);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "derive-dashboards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Open-source embedded dashboards for your product: the server, the engine, React components, charts and the CLI, in one package.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"@derive-to/dashboards-core": "0.0.0"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
|
-
"react": "^19.0.0",
|
|
91
|
-
"react-dom": "^19.0.0",
|
|
90
|
+
"react": "^18.3.0 || ^19.0.0",
|
|
91
|
+
"react-dom": "^18.3.0 || ^19.0.0",
|
|
92
92
|
"recharts": "^3.0.0",
|
|
93
93
|
"vitest": "^4.0.0 || ^5.0.0"
|
|
94
94
|
},
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"derive-dashboards": "./dist/cli/bin.mjs"
|
|
111
111
|
},
|
|
112
112
|
"engines": {
|
|
113
|
-
"node": ">=
|
|
113
|
+
"node": ">=22.18"
|
|
114
114
|
},
|
|
115
115
|
"keywords": [
|
|
116
116
|
"dashboards",
|