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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MICROS_PER_HOUR, formatTextTime } from "./instant.mjs";
|
|
1
|
+
import { MICROS_PER_HOUR, formatTextTime, parseDate, parseTextTime } from "./instant.mjs";
|
|
2
2
|
import { Temporal, zonedAt } from "./temporal.mjs";
|
|
3
3
|
import { lastChange, nextChange, startOfDate } from "./zone.mjs";
|
|
4
4
|
// src/time/bucket.ts
|
|
@@ -87,6 +87,12 @@ function bucketLabel(instant, grain, calendar) {
|
|
|
87
87
|
if (grain === "hour") return formatTextTime(start);
|
|
88
88
|
return zonedAt(start, calendar.timezone).toPlainDate().toString();
|
|
89
89
|
}
|
|
90
|
+
/** The instant a bucket's label starts at: a local date in the zone, or an hour's instant. */
|
|
91
|
+
function labelStart(label, grain, calendar) {
|
|
92
|
+
if (grain === "hour") return parseTextTime(label);
|
|
93
|
+
const date = parseDate(label);
|
|
94
|
+
return date === void 0 ? void 0 : startOfDate(date, calendar.timezone);
|
|
95
|
+
}
|
|
90
96
|
/** Every bucket label a span touches, in order, including a partial first bucket. */
|
|
91
97
|
function bucketLabels(span, grain, calendar) {
|
|
92
98
|
const labels = [];
|
|
@@ -100,4 +106,4 @@ function bucketLabels(span, grain, calendar) {
|
|
|
100
106
|
function epochDayLabel(epochDay) {
|
|
101
107
|
return new Temporal.PlainDate(1970, 1, 1).add({ days: epochDay }).toString();
|
|
102
108
|
}
|
|
103
|
-
export { bucketLabel, bucketLabels, bucketStart, epochDayLabel, hourStart, nextBucketStart, shiftBucket };
|
|
109
|
+
export { bucketLabel, bucketLabels, bucketStart, epochDayLabel, hourStart, labelStart, nextBucketStart, shiftBucket };
|
|
@@ -344,4 +344,4 @@ export type CoreContract = {
|
|
|
344
344
|
* than reading a shape it does not know. A test recomputes it from the answer schemas, so a
|
|
345
345
|
* change to an answer fails until this is updated.
|
|
346
346
|
*/
|
|
347
|
-
export declare const CONTRACT_VERSION = "
|
|
347
|
+
export declare const CONTRACT_VERSION = "ed1ec2bd454a1d16";
|
package/dist/core/types/api.mjs
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* than reading a shape it does not know. A test recomputes it from the answer schemas, so a
|
|
6
6
|
* change to an answer fails until this is updated.
|
|
7
7
|
*/
|
|
8
|
-
const CONTRACT_VERSION = "
|
|
8
|
+
const CONTRACT_VERSION = "ed1ec2bd454a1d16";
|
|
9
9
|
export { CONTRACT_VERSION };
|
package/dist/drill-change.mjs
CHANGED
|
@@ -45,7 +45,7 @@ function otherChange(answer) {
|
|
|
45
45
|
};
|
|
46
46
|
const total = answer.rows.find((r) => isAll(r));
|
|
47
47
|
const other = answer.rows.findIndex((r) => isOther(r));
|
|
48
|
-
const now = answer.columns.findIndex((c) => c.
|
|
48
|
+
const now = answer.columns.findIndex((c) => c.role === "measure");
|
|
49
49
|
if (places.before < 0 || total === void 0 || other < 0 || now < 0) return answer;
|
|
50
50
|
const kept = answer.rows.filter((r) => !isAll(r) && !isOther(r));
|
|
51
51
|
const row = answer.rows[other] ?? [];
|
package/dist/drill-seal.mjs
CHANGED
|
@@ -24,6 +24,7 @@ function spanOf(range) {
|
|
|
24
24
|
/** A column as a selection reads it: its id, member and grain only. */
|
|
25
25
|
const slim = (c) => ({
|
|
26
26
|
id: c.id,
|
|
27
|
+
...c.role === void 0 ? {} : { role: c.role },
|
|
27
28
|
label: "",
|
|
28
29
|
type: c.type,
|
|
29
30
|
...c.member === void 0 ? {} : { member: c.member },
|
|
@@ -304,9 +304,11 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
304
304
|
};
|
|
305
305
|
}, Omit<Answered, "cuts"> | {
|
|
306
306
|
drill: import("derive-dashboards/core").AnswerDrill;
|
|
307
|
+
time?: import("derive-dashboards/core").TimeAxis;
|
|
307
308
|
compare?: {
|
|
308
309
|
rows: import("derive-dashboards/core").ResultRows;
|
|
309
310
|
range: import("derive-dashboards/core").ResolvedRange;
|
|
311
|
+
time?: import("derive-dashboards/core").TimeAxis;
|
|
310
312
|
};
|
|
311
313
|
rows: import("derive-dashboards/core").ResultRows;
|
|
312
314
|
columns: readonly import("derive-dashboards/core").ResultColumn[];
|
|
@@ -682,6 +684,7 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
682
684
|
command: import("derive-dashboards/core/schema").JsonSchema;
|
|
683
685
|
query: import("derive-dashboards/core/schema").JsonSchema;
|
|
684
686
|
picks: import("derive-dashboards/core/schema").JsonSchema;
|
|
687
|
+
display: Record<string, import("derive-dashboards/core/schema").JsonSchema>;
|
|
685
688
|
}, "GET">;
|
|
686
689
|
memberValues: import("derive-dashboards/core").DashEndpoint<"/meta/values", {
|
|
687
690
|
member: string;
|
package/dist/execute.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { macHex } from "./cursor-seal.mjs";
|
|
|
4
4
|
import { adapterFor } from "./dashboards.mjs";
|
|
5
5
|
import { withReader } from "./reading.mjs";
|
|
6
6
|
import { logQuery } from "./store/log.mjs";
|
|
7
|
-
import { bindQueryViewer, bindViewer, canonical, isBound, markedRows, resultColumns } from "derive-dashboards/core";
|
|
7
|
+
import { bindQueryViewer, bindViewer, canonical, isBound, markedRows, resultColumns, withTime } from "derive-dashboards/core";
|
|
8
8
|
import { EngineError, readQuery } from "derive-dashboards/core/engine";
|
|
9
9
|
// src/execute.ts
|
|
10
10
|
/** An answer as a client reads it: without what only the server reads. */
|
|
@@ -86,13 +86,19 @@ async function compute(x, bound) {
|
|
|
86
86
|
message: `The answer was cut at ${bound.maxRows} rows.`,
|
|
87
87
|
path: []
|
|
88
88
|
}] : [];
|
|
89
|
+
const columns = resultColumns(x.rt.options.model, x.query);
|
|
90
|
+
const timed = (rows, range) => withTime(columns, rows, {
|
|
91
|
+
range,
|
|
92
|
+
calendar: x.calendar
|
|
93
|
+
});
|
|
94
|
+
const before = compare === void 0 ? void 0 : {
|
|
95
|
+
...timed(markedRows(x.query, compare), compare.range),
|
|
96
|
+
range: compare.range
|
|
97
|
+
};
|
|
89
98
|
return {
|
|
90
|
-
columns
|
|
91
|
-
|
|
92
|
-
...
|
|
93
|
-
rows: markedRows(x.query, compare),
|
|
94
|
-
range: compare.range
|
|
95
|
-
} },
|
|
99
|
+
columns,
|
|
100
|
+
...timed(markedRows(x.query, levels), value.range),
|
|
101
|
+
...before === void 0 ? {} : { compare: before },
|
|
96
102
|
status: truncated === true ? "truncated" : "complete",
|
|
97
103
|
...unreadable === true ? { unreadable } : {},
|
|
98
104
|
...cuts,
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { postgresConnection } from "./postgres-connection.mjs";
|
|
|
11
11
|
import { postgresStore } from "./postgres-store.mjs";
|
|
12
12
|
import { memoryStorage } from "./storage.mjs";
|
|
13
13
|
import { SchemaMismatchError, createTables, schemaDiff } from "./store/create-tables.mjs";
|
|
14
|
-
import { BASE_ERROR_CODES, defineModel, linkTemplateIssues } from "derive-dashboards/core";
|
|
14
|
+
import { BASE_ERROR_CODES, defineModel, documentDisplayIssues, linkTemplateIssues } from "derive-dashboards/core";
|
|
15
15
|
import { drillModel } from "derive-dashboards/core/engine";
|
|
16
16
|
import { loadDocument } from "derive-dashboards/core/schema";
|
|
17
17
|
// src/index.ts
|
|
@@ -26,6 +26,11 @@ function checkedDashboards(options) {
|
|
|
26
26
|
const problems = loaded.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
27
27
|
throw new Error(`The dashboard "${d.key}" is not a valid document: ${problems}`);
|
|
28
28
|
}
|
|
29
|
+
const wrong = documentDisplayIssues(loaded.doc);
|
|
30
|
+
if (wrong.length > 0) {
|
|
31
|
+
const problems = wrong.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
32
|
+
throw new Error(`The dashboard "${d.key}" has display options of the wrong type: ${problems}`);
|
|
33
|
+
}
|
|
29
34
|
return {
|
|
30
35
|
key: d.key,
|
|
31
36
|
document: loaded.doc
|
|
@@ -29,4 +29,8 @@ export type DashboardProps = {
|
|
|
29
29
|
/** The link Share copies for a view; by default, this page's address with the view in it. */
|
|
30
30
|
linkFor?: (view: ViewState) => string;
|
|
31
31
|
} & DashboardEvents & DashboardDrillProps;
|
|
32
|
+
/**
|
|
33
|
+
* One dashboard. Everything drawn in it, the builder's preview too, shares one book of series
|
|
34
|
+
* colours, kept for as long as this dashboard is shown.
|
|
35
|
+
*/
|
|
32
36
|
export declare function Dashboard(props: DashboardProps): import("react").JSX.Element;
|
package/dist/react/Dashboard.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { useDashboards } from "./context.mjs";
|
|
|
3
3
|
import { DrillScope } from "./drill/board.mjs";
|
|
4
4
|
import { BuildPage } from "./Editing.mjs";
|
|
5
5
|
import { Bars, Side } from "./Parts.mjs";
|
|
6
|
-
import { ScopeContext } from "./scope.mjs";
|
|
6
|
+
import { ScopeContext, SeriesSlotsContext, useSeriesSlots } from "./scope.mjs";
|
|
7
7
|
import { useBoard } from "./useBoard.mjs";
|
|
8
8
|
import { useState } from "react";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -50,7 +50,18 @@ function Unreachable() {
|
|
|
50
50
|
children: messages.dashboardUnreachable
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* One dashboard. Everything drawn in it, the builder's preview too, shares one book of series
|
|
55
|
+
* colours, kept for as long as this dashboard is shown.
|
|
56
|
+
*/
|
|
53
57
|
function Dashboard(props) {
|
|
58
|
+
const slots = useSeriesSlots(props.id);
|
|
59
|
+
return /* @__PURE__ */ jsx(SeriesSlotsContext.Provider, {
|
|
60
|
+
value: slots,
|
|
61
|
+
children: /* @__PURE__ */ jsx(Board, { ...props })
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function Board(props) {
|
|
54
65
|
const { messages } = useDashboards();
|
|
55
66
|
const board = useBoard(props);
|
|
56
67
|
const [building, setBuilding] = useState();
|
package/dist/react/Tile.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useDashboards } from "./context.mjs";
|
|
2
2
|
import { useTileDrill } from "./drill/host.mjs";
|
|
3
3
|
import { formatInstantAt } from "./format.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { SeriesSlotsContext } from "./scope.mjs";
|
|
5
|
+
import { seriesSlots } from "./series-slots.mjs";
|
|
6
|
+
import { memo, useContext, useState } from "react";
|
|
7
|
+
import { sharedDisplay } from "derive-dashboards/core";
|
|
5
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
9
|
// src/Tile.tsx
|
|
7
10
|
/** Refusals that last only until the dashboard is read again, never shown as errors. */
|
|
@@ -40,12 +43,15 @@ const drawable = (result) => result !== void 0 && !("error" in result) && result
|
|
|
40
43
|
/** The answer drawn: a memo of its own, so a change to the tile's buttons or badge never draws the chart again. */
|
|
41
44
|
const Body = memo(function Body({ widget, result, loading, drill }) {
|
|
42
45
|
const { renderers, locale, messages, link } = useDashboards();
|
|
46
|
+
const shared = useContext(SeriesSlotsContext);
|
|
47
|
+
const [own] = useState(seriesSlots);
|
|
48
|
+
const slots = shared ?? own;
|
|
43
49
|
if (!drawable(result)) {
|
|
44
|
-
const empty = widget.display
|
|
50
|
+
const { empty } = sharedDisplay(widget.display);
|
|
45
51
|
return /* @__PURE__ */ jsx(TileState, {
|
|
46
52
|
result,
|
|
47
53
|
loading,
|
|
48
|
-
empty:
|
|
54
|
+
empty: empty ?? messages.noData
|
|
49
55
|
});
|
|
50
56
|
}
|
|
51
57
|
const Renderer = renderers[widget.kind] ?? renderers.table;
|
|
@@ -55,7 +61,8 @@ const Body = memo(function Body({ widget, result, loading, drill }) {
|
|
|
55
61
|
messages,
|
|
56
62
|
...locale === void 0 ? {} : { locale },
|
|
57
63
|
...drill === void 0 ? {} : { drill },
|
|
58
|
-
...link === void 0 ? {} : { link }
|
|
64
|
+
...link === void 0 ? {} : { link },
|
|
65
|
+
slots
|
|
59
66
|
});
|
|
60
67
|
});
|
|
61
68
|
/** Notes under a tile: a viewer's filter that could not apply, or an answer cut at the row cap. */
|
package/dist/react/context.d.mts
CHANGED
|
@@ -2,7 +2,8 @@ import { DashboardsClient } from "./client.mjs";
|
|
|
2
2
|
import { FilterBarProps } from "./filters/hooks.mjs";
|
|
3
3
|
import "./FilterBar.mjs";
|
|
4
4
|
import { Messages } from "./messages.mjs";
|
|
5
|
-
import { TileRenderer } from "./renderers/
|
|
5
|
+
import { TileRenderer } from "./renderers/props.mjs";
|
|
6
|
+
import "./renderers/index.mjs";
|
|
6
7
|
import { ComponentType, MouseEvent, ReactNode } from "react";
|
|
7
8
|
import { Author } from "derive-dashboards/core";
|
|
8
9
|
/** The props every link the library draws passes: a router's link component takes them. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDashboards } from "../context.mjs";
|
|
2
2
|
import { formatBucket, formatCell, plotValue } from "../format.mjs";
|
|
3
3
|
import { rowEntry } from "./state.mjs";
|
|
4
|
-
import { isMark } from "derive-dashboards/core";
|
|
4
|
+
import { isMark, roleOf } from "derive-dashboards/core";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
// src/drill/Bars.tsx
|
|
7
7
|
/** A row's name: its time bucket or its group, as the tile names it ("No assignee" for no value). */
|
|
@@ -20,7 +20,7 @@ function valueName(cell, column, format) {
|
|
|
20
20
|
/** The line's column: the one named, else the first value column. */
|
|
21
21
|
const lineAt = (view, entry) => {
|
|
22
22
|
const named = view.answer.columns.findIndex((c) => c.id === entry);
|
|
23
|
-
return named >= 0 ? named : view.answer.columns.findIndex((c) => c
|
|
23
|
+
return named >= 0 ? named : view.answer.columns.findIndex((c) => roleOf(c) === "measure");
|
|
24
24
|
};
|
|
25
25
|
/** A change with its sign: "+6" when it went up. */
|
|
26
26
|
const signed = (text, size) => size > 0 && !text.startsWith("+") ? `+${text}` : text;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { formatCell } from "../format.mjs";
|
|
2
2
|
import { drillFrom } from "./state.mjs";
|
|
3
|
+
import { roleOf } from "derive-dashboards/core";
|
|
3
4
|
// src/drill/props.ts
|
|
4
|
-
const isLine = (c) => c
|
|
5
|
+
const isLine = (c) => roleOf(c) === "measure" || roleOf(c) === "calc";
|
|
5
6
|
/** A mark's name for a screen reader: its groups, then its value. */
|
|
6
7
|
function markLabel(answer, row, format, entry) {
|
|
7
8
|
const named = answer.columns.filter(isLine).length > 1 ? entry : void 0;
|
package/dist/react/index.d.mts
CHANGED
|
@@ -18,6 +18,7 @@ import { ENGLISH } from "./english.mjs";
|
|
|
18
18
|
import { DashboardDrillProps, DrillEvent } from "./drill/board.mjs";
|
|
19
19
|
import { DashboardTile, DashboardTileProps } from "./drill/DashboardTile.mjs";
|
|
20
20
|
import { DrillPanelProps } from "./drill/DrillPanel.mjs";
|
|
21
|
+
import { TileRenderer, TileRendererProps } from "./renderers/props.mjs";
|
|
21
22
|
import { ItemHelpers, ItemOptions } from "./drill/Items.mjs";
|
|
22
23
|
import { DrillPanel } from "./drill/lazy.mjs";
|
|
23
24
|
import { DrillMarkProps, TileDrill } from "./drill/props.mjs";
|
|
@@ -32,11 +33,13 @@ import { CellFormat, Messages } from "./messages.mjs";
|
|
|
32
33
|
import { ChangeList, Panel } from "./Panel.mjs";
|
|
33
34
|
import { ReviewPanel } from "./ReviewPanel.mjs";
|
|
34
35
|
import { ClientSchemas } from "./read.mjs";
|
|
35
|
-
import { NumberTile, TableTile
|
|
36
|
+
import { NumberTile, TableTile } from "./renderers/index.mjs";
|
|
36
37
|
import { ListDisplay, ListTile } from "./renderers/list.mjs";
|
|
37
38
|
import { Moved, Review, useReview } from "./review.mjs";
|
|
38
39
|
import { ENGLISH_REVIEW, ReviewMessages } from "./review-words.mjs";
|
|
40
|
+
import { SeriesSlotsContext } from "./scope.mjs";
|
|
39
41
|
import { Drawn, OTHER_KEY, Point, Series, lastBucketOpen, rowAt, toSeries } from "./series.mjs";
|
|
42
|
+
import { SeriesSlots, SplitSeries, chartColors, seriesSlots } from "./series-slots.mjs";
|
|
40
43
|
import { Tile } from "./Tile.mjs";
|
|
41
44
|
import { useBoard } from "./useBoard.mjs";
|
|
42
45
|
import { useDashboard } from "./useDashboard.mjs";
|
|
@@ -53,4 +56,4 @@ export interface Register {}
|
|
|
53
56
|
export type Item = Register extends {
|
|
54
57
|
server: infer S;
|
|
55
58
|
} ? ItemFor<S> : DrillItem;
|
|
56
|
-
export { type Attempt, type Builder, type CellFormat, ChangeList, type ClientOptions, type ClientSchemas, type Components, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, Popover, type Review, type ReviewMessages, ReviewPanel, type Series, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, createDashboardsClient, drillFrom, fieldOf, rules_d_exports as filterRules, formatBucket, formatCell, formatInstant, formatTick, lastBucketOpen, plotValue, rowAt, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
|
|
59
|
+
export { type Attempt, type Builder, type CellFormat, ChangeList, type ClientOptions, type ClientSchemas, type Components, Dashboard, type DashboardDrillProps, DashboardList, type DashboardProps, DashboardTile, type DashboardTileProps, type DashboardsClient, DashboardsError, type DashboardsErrorCode, DashboardsProvider, type DashboardsProviderProps, type DashboardsServer, type DraftClosed, type DraftEditor, type DraftStatus, type Drawn, type DrillChange, type DrillController, type DrillEvent, type DrillHistory, type DrillMarkProps, type DrillMessages, type DrillOptions, DrillPanel, type DrillPanelProps, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, type FilterBarOptions, type FilterBarProps, type FilterIcon, type FilterWords, HistoryPanel, type ItemFor, type ItemHelpers, type ItemOptions, type LinkComponent, type LinkProps, type ListDisplay, ListTile, type Messages, type Moved, NumberTile, OTHER_KEY, Panel, type Point, Popover, type Review, type ReviewMessages, ReviewPanel, type Series, type SeriesSlots, SeriesSlotsContext, type SplitSeries, TableTile, Tile, type TileDrill, type TileRenderer, type TileRendererProps, type TypedCall, VersionBar, type ViewChange, WidgetBuilder, type WidgetBuilderProps, WidgetPreview, chartColors, createDashboardsClient, drillFrom, fieldOf, rules_d_exports as filterRules, formatBucket, formatCell, formatInstant, formatTick, lastBucketOpen, plotValue, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
|
package/dist/react/index.mjs
CHANGED
|
@@ -11,9 +11,9 @@ import { DashboardTile } from "./drill/DashboardTile.mjs";
|
|
|
11
11
|
import { DrillPanel } from "./drill/lazy.mjs";
|
|
12
12
|
import { drillFrom } from "./drill/state.mjs";
|
|
13
13
|
import { useDrill } from "./drill/useDrill.mjs";
|
|
14
|
-
import { DashboardsError } from "./errors.mjs";
|
|
15
14
|
import { ENGLISH_DRILL } from "./drill/words.mjs";
|
|
16
15
|
import { EditBar } from "./EditBar.mjs";
|
|
16
|
+
import { DashboardsError } from "./errors.mjs";
|
|
17
17
|
import { ENGLISH_FILTERS } from "./filters/words.mjs";
|
|
18
18
|
import { FilterBar } from "./filters/bar.mjs";
|
|
19
19
|
import { fieldOf, useControlValues, useFilterFields } from "./filters/hooks.mjs";
|
|
@@ -28,9 +28,11 @@ import { NumberTile, TableTile } from "./renderers/index.mjs";
|
|
|
28
28
|
import { ListTile } from "./renderers/list.mjs";
|
|
29
29
|
import { useReview } from "./review.mjs";
|
|
30
30
|
import { ENGLISH_REVIEW } from "./review-words.mjs";
|
|
31
|
+
import { SeriesSlotsContext } from "./scope.mjs";
|
|
31
32
|
import { OTHER_KEY, lastBucketOpen, rowAt, toSeries } from "./series.mjs";
|
|
33
|
+
import { chartColors, seriesSlots } from "./series-slots.mjs";
|
|
32
34
|
import { Tile } from "./Tile.mjs";
|
|
33
35
|
import { useBoard } from "./useBoard.mjs";
|
|
34
36
|
import { useDashboard } from "./useDashboard.mjs";
|
|
35
37
|
import { useTiles } from "./useTiles.mjs";
|
|
36
|
-
export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, Popover, ReviewPanel, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, createDashboardsClient, drillFrom, fieldOf, rules_exports as filterRules, formatBucket, formatCell, formatInstant, formatTick, lastBucketOpen, plotValue, rowAt, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
|
|
38
|
+
export { ChangeList, Dashboard, DashboardList, DashboardTile, DashboardsError, DashboardsProvider, DrillPanel, ENGLISH, ENGLISH_DRILL, ENGLISH_FILTERS, ENGLISH_REVIEW, EditBar, FilterBar, HistoryPanel, ListTile, NumberTile, OTHER_KEY, Panel, Popover, ReviewPanel, SeriesSlotsContext, TableTile, Tile, VersionBar, WidgetBuilder, WidgetPreview, chartColors, createDashboardsClient, drillFrom, fieldOf, rules_exports as filterRules, formatBucket, formatCell, formatInstant, formatTick, lastBucketOpen, plotValue, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TileDrill } from "../drill/props.mjs";
|
|
3
|
-
import { Messages } from "../messages.mjs";
|
|
4
|
-
import { ReactNode } from "react";
|
|
5
|
-
import { TileAnswer, Widget } from "derive-dashboards/core";
|
|
6
|
-
/**
|
|
7
|
-
* What a renderer draws, and how: pass the props as `formatCell`'s format to use both. `drill`
|
|
8
|
-
* is there when drilling is on: spread `drill.props(row, entry)` on a mark to make it open.
|
|
9
|
-
*/
|
|
10
|
-
export type TileRendererProps = {
|
|
11
|
-
answer: TileAnswer;
|
|
12
|
-
widget: Widget;
|
|
13
|
-
locale?: string;
|
|
14
|
-
messages: Messages;
|
|
15
|
-
drill?: TileDrill;
|
|
16
|
-
/** The provider's link component, for a renderer that links rows into the app. */
|
|
17
|
-
link?: LinkComponent;
|
|
18
|
-
};
|
|
19
|
-
/** Draws one tile's answer. Register more by widget kind on the provider. */
|
|
20
|
-
export type TileRenderer = (props: TileRendererProps) => ReactNode;
|
|
1
|
+
import { TileRenderer, TileRendererProps } from "./props.mjs";
|
|
21
2
|
/**
|
|
22
3
|
* The first calc or value column, large, from the total row when there is one, else the first row;
|
|
23
4
|
* a change calc (a signed column) sits under it.
|
|
24
5
|
*/
|
|
25
6
|
export declare function NumberTile(props: TileRendererProps): import("react").JSX.Element;
|
|
26
7
|
/** Every row and column: the groups, then Other and the total under them. */
|
|
27
|
-
export declare function TableTile(props: TileRendererProps): import("react").JSX.Element;
|
|
8
|
+
export declare function TableTile(props: TileRendererProps): import("react").JSX.Element;
|
|
9
|
+
export type { TileRenderer, TileRendererProps };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { formatCell } from "../format.mjs";
|
|
2
2
|
import { ListTile } from "./list.mjs";
|
|
3
|
-
import { isMark } from "derive-dashboards/core";
|
|
3
|
+
import { isMark, roleOf } from "derive-dashboards/core";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/renderers/index.tsx
|
|
6
|
-
const isMeasure = (column) => column
|
|
6
|
+
const isMeasure = (column) => roleOf(column) === "measure" || roleOf(column) === "calc";
|
|
7
7
|
const isAll = (cell) => isMark(cell) && cell.mark === "all";
|
|
8
8
|
/** A calc is what the query was built to show (a share, a rate); else its first value. */
|
|
9
9
|
const shownIndex = (columns) => {
|
|
10
|
-
const calc = columns.findIndex((c) =>
|
|
10
|
+
const calc = columns.findIndex((c) => roleOf(c) === "calc" && c.signed !== true);
|
|
11
11
|
return calc === -1 ? columns.findIndex((c) => isMeasure(c)) : calc;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TileRendererProps } from "./
|
|
1
|
+
import { TileRendererProps } from "./props.mjs";
|
|
2
|
+
import "./index.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* How a list draws its rows, by the query's entry ids. Every key is optional: with none, the
|
|
4
5
|
* first group is the title, the other groups the subtitle, and the last value the number.
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { formatCell } from "../format.mjs";
|
|
2
2
|
import { RowBody } from "../RowBody.mjs";
|
|
3
|
-
import { isMark } from "derive-dashboards/core";
|
|
3
|
+
import { displayOf, isMark, roleOf } from "derive-dashboards/core";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
// src/renderers/list.tsx
|
|
6
6
|
const initials = (text) => text.split(/[\s._@-]+/u).filter(Boolean).slice(0, 2).map((word) => word[0]?.toUpperCase()).join("");
|
|
7
|
-
const
|
|
8
|
-
const asList = (value) => Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
|
|
9
|
-
const isValue = (c) => c.id.startsWith("m") || c.id.startsWith("c");
|
|
7
|
+
const isValue = (c) => roleOf(c) === "measure" || roleOf(c) === "calc";
|
|
10
8
|
/** With no display, the first group is the title, the others the subtitle, the last value the number. */
|
|
11
9
|
function defaults(columns) {
|
|
12
10
|
const groups = columns.filter((c) => !isValue(c)).map((c) => c.id);
|
|
@@ -31,17 +29,16 @@ function answerIds(widget) {
|
|
|
31
29
|
]);
|
|
32
30
|
}
|
|
33
31
|
function readDisplay(widget, columns) {
|
|
34
|
-
const display = widget.display
|
|
32
|
+
const display = displayOf("list", widget.display);
|
|
35
33
|
const ids = answerIds(widget);
|
|
36
34
|
const id = (entry) => entry === void 0 ? void 0 : ids.get(entry) ?? entry;
|
|
37
35
|
const fallback = defaults(columns);
|
|
38
|
-
const href = asText(display.href);
|
|
39
36
|
return {
|
|
40
|
-
title: id(
|
|
41
|
-
subtitle:
|
|
42
|
-
avatar: id(
|
|
43
|
-
meta: id(
|
|
44
|
-
href: href?.replaceAll(/\{([^}]+)\}/gu, (_, entry) => `{${id(entry) ?? entry}}`)
|
|
37
|
+
title: id(display.title) ?? fallback.title,
|
|
38
|
+
subtitle: display.subtitle?.map((entry) => id(entry) ?? entry) ?? fallback.subtitle,
|
|
39
|
+
avatar: id(display.avatar),
|
|
40
|
+
meta: id(display.meta) ?? fallback.meta,
|
|
41
|
+
href: display.href?.replaceAll(/\{([^}]+)\}/gu, (_, entry) => `{${id(entry) ?? entry}}`)
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
const text = ({ cells, at, props }, id) => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LinkComponent } from "../context.mjs";
|
|
2
|
+
import { TileDrill } from "../drill/props.mjs";
|
|
3
|
+
import { Messages } from "../messages.mjs";
|
|
4
|
+
import { SeriesSlots } from "../series-slots.mjs";
|
|
5
|
+
import { ReactNode } from "react";
|
|
6
|
+
import { TileAnswer, Widget } from "derive-dashboards/core";
|
|
7
|
+
/**
|
|
8
|
+
* What a renderer draws, and how: pass the props as `formatCell`'s format to use both. `drill`
|
|
9
|
+
* is there when drilling is on: spread `drill.props(row, entry)` on a mark to make it open.
|
|
10
|
+
*/
|
|
11
|
+
export type TileRendererProps = {
|
|
12
|
+
answer: TileAnswer;
|
|
13
|
+
widget: Widget;
|
|
14
|
+
locale?: string;
|
|
15
|
+
messages: Messages;
|
|
16
|
+
drill?: TileDrill;
|
|
17
|
+
/** The provider's link component, for a renderer that links rows into the app. */
|
|
18
|
+
link?: LinkComponent;
|
|
19
|
+
/**
|
|
20
|
+
* The dashboard's book of palette places: pass it to `toSeries`, and each series' `slot` is the
|
|
21
|
+
* same on every tile and under every filter.
|
|
22
|
+
*/
|
|
23
|
+
slots?: SeriesSlots;
|
|
24
|
+
};
|
|
25
|
+
/** Draws one tile's answer. Register more by widget kind on the provider. */
|
|
26
|
+
export type TileRenderer = (props: TileRendererProps) => ReactNode;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SeriesSlots } from "./series-slots.mjs";
|
|
2
|
+
import { Picks } from "derive-dashboards/core";
|
|
3
|
+
/** The dashboard's book of palette places, for every chart drawn in it; none outside a dashboard. */
|
|
4
|
+
export declare const SeriesSlotsContext: import("react").Context<SeriesSlots | undefined>;
|
package/dist/react/scope.mjs
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { seriesSlots } from "./series-slots.mjs";
|
|
2
|
+
import { createContext, useState } from "react";
|
|
2
3
|
// src/scope.tsx
|
|
3
4
|
const ScopeContext = createContext(null);
|
|
4
|
-
|
|
5
|
+
/** The dashboard's book of palette places, for every chart drawn in it; none outside a dashboard. */
|
|
6
|
+
const SeriesSlotsContext = createContext(void 0);
|
|
7
|
+
/** One book per dashboard shown: a new one when the dashboard changes, the same one otherwise. */
|
|
8
|
+
function useSeriesSlots(dashboardId) {
|
|
9
|
+
const [book, setBook] = useState(() => ({
|
|
10
|
+
id: dashboardId,
|
|
11
|
+
slots: seriesSlots()
|
|
12
|
+
}));
|
|
13
|
+
if (book.id === dashboardId) return book.slots;
|
|
14
|
+
const next = {
|
|
15
|
+
id: dashboardId,
|
|
16
|
+
slots: seriesSlots()
|
|
17
|
+
};
|
|
18
|
+
setBook(next);
|
|
19
|
+
return next.slots;
|
|
20
|
+
}
|
|
21
|
+
export { ScopeContext, SeriesSlotsContext, useSeriesSlots };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ResultCell, ResultColumn } from "derive-dashboards/core";
|
|
2
|
+
/** A series that is one value of the fields a chart splits by. */
|
|
3
|
+
export type SplitSeries = {
|
|
4
|
+
/** The columns the chart splits by, after its x axis. */
|
|
5
|
+
by: readonly ResultColumn[];
|
|
6
|
+
/** The series' key: its raw values, as `toSeries` keys them. */
|
|
7
|
+
key: string;
|
|
8
|
+
/** Its raw cells, one per column of `by`. */
|
|
9
|
+
cells: readonly ResultCell[];
|
|
10
|
+
};
|
|
11
|
+
/** A book of palette places: the same value of the same field, the same place, every time it is asked. */
|
|
12
|
+
export type SeriesSlots = {
|
|
13
|
+
of: (series: SplitSeries) => number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A new book. A value whose field declares its values in the model takes its place among them,
|
|
17
|
+
* so its colour is the same on every dashboard and every load. Any other value takes the next
|
|
18
|
+
* free place of its field the first time it is drawn, and keeps it while the book lives: a
|
|
19
|
+
* dashboard keeps one book, so a filter never repaints a series and every tile agrees.
|
|
20
|
+
*
|
|
21
|
+
* Known gap: a field that declares no values has no place that outlives the page, so after a
|
|
22
|
+
* reload its values are placed again in the order they are first drawn. Declare the field's
|
|
23
|
+
* `values` in the model, or a widget's `display.colors`, to fix a colour for good. A chart
|
|
24
|
+
* split by two fields places each pair of values, and series that are measures go by position.
|
|
25
|
+
*/
|
|
26
|
+
export declare function seriesSlots(): SeriesSlots;
|
|
27
|
+
/**
|
|
28
|
+
* The palette colour of each series of one chart, as an index into a palette of `size`
|
|
29
|
+
* colours; none for a series with no slot (Other). A series takes its slot's colour. Two slots
|
|
30
|
+
* a palette apart would take the same one, so when the chart has a colour to spare the series
|
|
31
|
+
* with the higher slot takes the first colour no series of the chart has: within one chart
|
|
32
|
+
* colours stay apart for as long as the palette allows, as they did when colour went by
|
|
33
|
+
* position. Only past the palette's size do two series share a colour.
|
|
34
|
+
*/
|
|
35
|
+
export declare function chartColors(series: readonly {
|
|
36
|
+
slot?: number;
|
|
37
|
+
}[], size: number): (number | undefined)[];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/series-slots.ts
|
|
2
|
+
/** The place the model gives a value: its index among the values its field declares, in the model's order. */
|
|
3
|
+
function declaredSlot(series) {
|
|
4
|
+
const [column, ...more] = series.by;
|
|
5
|
+
const [cell] = series.cells;
|
|
6
|
+
if (column?.values === void 0 || more.length > 0 || typeof cell !== "string") return void 0;
|
|
7
|
+
const index = column.values.indexOf(cell);
|
|
8
|
+
return index === -1 ? void 0 : index;
|
|
9
|
+
}
|
|
10
|
+
/** The lowest place no value of the field has, at or after the places its declared values hold. */
|
|
11
|
+
function freeSlot(taken, from) {
|
|
12
|
+
const used = new Set(taken.values());
|
|
13
|
+
let slot = from;
|
|
14
|
+
while (used.has(slot)) slot += 1;
|
|
15
|
+
return slot;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A new book. A value whose field declares its values in the model takes its place among them,
|
|
19
|
+
* so its colour is the same on every dashboard and every load. Any other value takes the next
|
|
20
|
+
* free place of its field the first time it is drawn, and keeps it while the book lives: a
|
|
21
|
+
* dashboard keeps one book, so a filter never repaints a series and every tile agrees.
|
|
22
|
+
*
|
|
23
|
+
* Known gap: a field that declares no values has no place that outlives the page, so after a
|
|
24
|
+
* reload its values are placed again in the order they are first drawn. Declare the field's
|
|
25
|
+
* `values` in the model, or a widget's `display.colors`, to fix a colour for good. A chart
|
|
26
|
+
* split by two fields places each pair of values, and series that are measures go by position.
|
|
27
|
+
*/
|
|
28
|
+
function seriesSlots() {
|
|
29
|
+
const fields = /* @__PURE__ */ new Map();
|
|
30
|
+
return { of(series) {
|
|
31
|
+
const field = series.by.map((c) => c.member ?? c.id).join("|");
|
|
32
|
+
const taken = fields.get(field) ?? /* @__PURE__ */ new Map();
|
|
33
|
+
fields.set(field, taken);
|
|
34
|
+
const had = declaredSlot(series) ?? taken.get(series.key);
|
|
35
|
+
if (had !== void 0) {
|
|
36
|
+
taken.set(series.key, had);
|
|
37
|
+
return had;
|
|
38
|
+
}
|
|
39
|
+
const slot = freeSlot(taken, series.by.length === 1 ? series.by[0]?.values?.length ?? 0 : 0);
|
|
40
|
+
taken.set(series.key, slot);
|
|
41
|
+
return slot;
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The palette colour of each series of one chart, as an index into a palette of `size`
|
|
46
|
+
* colours; none for a series with no slot (Other). A series takes its slot's colour. Two slots
|
|
47
|
+
* a palette apart would take the same one, so when the chart has a colour to spare the series
|
|
48
|
+
* with the higher slot takes the first colour no series of the chart has: within one chart
|
|
49
|
+
* colours stay apart for as long as the palette allows, as they did when colour went by
|
|
50
|
+
* position. Only past the palette's size do two series share a colour.
|
|
51
|
+
*/
|
|
52
|
+
function chartColors(series, size) {
|
|
53
|
+
const bySlot = series.flatMap((s, at) => s.slot === void 0 ? [] : [{
|
|
54
|
+
at,
|
|
55
|
+
slot: s.slot
|
|
56
|
+
}]).toSorted((a, b) => a.slot - b.slot);
|
|
57
|
+
const colors = /* @__PURE__ */ new Map();
|
|
58
|
+
const used = /* @__PURE__ */ new Set();
|
|
59
|
+
const take = (at, color) => {
|
|
60
|
+
colors.set(at, color);
|
|
61
|
+
used.add(color);
|
|
62
|
+
};
|
|
63
|
+
const waiting = bySlot.filter(({ at, slot }) => {
|
|
64
|
+
if (used.has(slot % size)) return true;
|
|
65
|
+
take(at, slot % size);
|
|
66
|
+
return false;
|
|
67
|
+
});
|
|
68
|
+
for (const { at, slot } of waiting) take(at, Array.from({ length: size }, (_v, i) => i).find((i) => !used.has(i)) ?? slot % size);
|
|
69
|
+
return series.map((_s, at) => colors.get(at));
|
|
70
|
+
}
|
|
71
|
+
export { chartColors, seriesSlots };
|