derive-dashboards 0.2.0 → 0.4.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/README.md +4 -0
- 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/format.d.mts +6 -0
- package/dist/react/format.mjs +24 -18
- package/dist/react/index.d.mts +8 -4
- package/dist/react/index.mjs +8 -5
- package/dist/react/renderers/index.d.mts +9 -21
- package/dist/react/renderers/index.mjs +10 -7
- 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-points.d.mts +18 -0
- package/dist/react/series-points.mjs +19 -0
- package/dist/react/series-slots.d.mts +37 -0
- package/dist/react/series-slots.mjs +71 -0
- package/dist/react/series.d.mts +22 -12
- package/dist/react/series.mjs +80 -82
- package/dist/recharts/bar.mjs +5 -4
- package/dist/recharts/line.mjs +5 -4
- package/dist/recharts/parts.mjs +29 -14
- package/dist/recharts/table.mjs +10 -8
- 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/format.d.mts
CHANGED
|
@@ -22,4 +22,10 @@ export declare function formatTick(value: number, column?: ResultColumn, locale?
|
|
|
22
22
|
export declare function formatBucket(label: string, grain: Grain, locale?: string): string;
|
|
23
23
|
/** An instant (text time to the microsecond) as a date and time, in a zone (the dashboard's) or the viewer's own. */
|
|
24
24
|
export declare function formatInstant(text: string, locale?: string, timeZone?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* The bucket an instant starts, named at its grain in a zone, as a chart names it: "Nov 9" for
|
|
27
|
+
* a day or week, "Jul 2026" for a month, and a date with its clock time for an hour. A text
|
|
28
|
+
* that is not a time is given back as it is, as `formatInstant` gives it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatInstantAt(text: string, grain: Grain, locale?: string, timeZone?: string): string;
|
|
25
31
|
export {};
|
package/dist/react/format.mjs
CHANGED
|
@@ -26,6 +26,15 @@ function formatCell(cell, column, format = {}) {
|
|
|
26
26
|
if (typeof cell === "boolean") return cell ? messages.drillYes : messages.drillNo;
|
|
27
27
|
return numberText(cell, column, locale);
|
|
28
28
|
}
|
|
29
|
+
/** Number formats by locale and style: making one costs fifty times a format, and a table or a chart would make one for every cell. */
|
|
30
|
+
const FORMATS = /* @__PURE__ */ new Map();
|
|
31
|
+
/** The number format for a locale and a style, made once. */
|
|
32
|
+
function numberFormat(locale, style) {
|
|
33
|
+
const key = `${locale ?? ""}|${JSON.stringify(style)}`;
|
|
34
|
+
const made = FORMATS.get(key) ?? new Intl.NumberFormat(locale, style);
|
|
35
|
+
FORMATS.set(key, made);
|
|
36
|
+
return made;
|
|
37
|
+
}
|
|
29
38
|
/** A number by its column's format: a percent, a duration, money or a plain number. */
|
|
30
39
|
function numberText(cell, column, locale) {
|
|
31
40
|
if (column?.format === "percent") return percentText(cell, {
|
|
@@ -38,7 +47,7 @@ function numberText(cell, column, locale) {
|
|
|
38
47
|
style: "currency",
|
|
39
48
|
currency
|
|
40
49
|
};
|
|
41
|
-
if (typeof cell === "number") return
|
|
50
|
+
if (typeof cell === "number") return numberFormat(locale, {
|
|
42
51
|
maximumFractionDigits: 2,
|
|
43
52
|
...style
|
|
44
53
|
}).format(cell);
|
|
@@ -59,8 +68,8 @@ function percentText(cell, how, locale) {
|
|
|
59
68
|
maximumFractionDigits: places,
|
|
60
69
|
signDisplay: signed ? "exceptZero" : "auto"
|
|
61
70
|
};
|
|
62
|
-
if (typeof cell === "number") return
|
|
63
|
-
return
|
|
71
|
+
if (typeof cell === "number") return numberFormat(locale, style).format(how.fraction ? cell : cell / 100);
|
|
72
|
+
return numberFormat(locale, style).format(`${cell.v}${shift}`);
|
|
64
73
|
}
|
|
65
74
|
const DURATION_UNITS = [
|
|
66
75
|
["day", 86400],
|
|
@@ -72,7 +81,7 @@ const DURATION_UNITS = [
|
|
|
72
81
|
function durationText(seconds, locale) {
|
|
73
82
|
const size = Math.abs(seconds);
|
|
74
83
|
const [unit, per] = DURATION_UNITS.find(([, n]) => size >= n) ?? ["second", 1];
|
|
75
|
-
return
|
|
84
|
+
return numberFormat(locale, {
|
|
76
85
|
style: "unit",
|
|
77
86
|
unit,
|
|
78
87
|
unitDisplay: "short",
|
|
@@ -92,31 +101,27 @@ function exactText(text, currency, locale) {
|
|
|
92
101
|
currency
|
|
93
102
|
};
|
|
94
103
|
const places = /^0*$/u.test(cents) ? 0 : currency === void 0 ? Math.min(cents.length, 2) : 2;
|
|
95
|
-
|
|
104
|
+
return numberFormat(locale, {
|
|
96
105
|
minimumFractionDigits: places,
|
|
97
|
-
maximumFractionDigits: places
|
|
98
|
-
};
|
|
99
|
-
return new Intl.NumberFormat(locale, {
|
|
100
|
-
...fraction,
|
|
106
|
+
maximumFractionDigits: places,
|
|
101
107
|
...style
|
|
102
108
|
}).format(text);
|
|
103
109
|
}
|
|
104
110
|
/** A short axis label: 12K, $1.2M. */
|
|
105
111
|
function formatTick(value, column, locale) {
|
|
106
|
-
if (column?.format === "percent") return
|
|
112
|
+
if (column?.format === "percent") return numberFormat(locale, {
|
|
107
113
|
style: "percent",
|
|
108
114
|
maximumFractionDigits: 1
|
|
109
115
|
}).format(column.fraction === true ? value : value / 100);
|
|
110
116
|
if (column?.format === "duration") return durationText(value, locale);
|
|
111
117
|
const currency = currencyOf(column?.unit);
|
|
112
|
-
|
|
113
|
-
style: "currency",
|
|
114
|
-
currency
|
|
115
|
-
};
|
|
116
|
-
return new Intl.NumberFormat(locale, {
|
|
118
|
+
return numberFormat(locale, {
|
|
117
119
|
notation: "compact",
|
|
118
120
|
maximumFractionDigits: 1,
|
|
119
|
-
...
|
|
121
|
+
...currency === void 0 ? {} : {
|
|
122
|
+
style: "currency",
|
|
123
|
+
currency
|
|
124
|
+
}
|
|
120
125
|
}).format(value);
|
|
121
126
|
}
|
|
122
127
|
const DATE_LABEL = /^\d{4}-\d{2}-\d{2}$/u;
|
|
@@ -164,8 +169,9 @@ function formatInstant(text, locale, timeZone) {
|
|
|
164
169
|
}).format(date);
|
|
165
170
|
}
|
|
166
171
|
/**
|
|
167
|
-
* The bucket an instant starts, named at its grain in a zone, as
|
|
168
|
-
*
|
|
172
|
+
* The bucket an instant starts, named at its grain in a zone, as a chart names it: "Nov 9" for
|
|
173
|
+
* a day or week, "Jul 2026" for a month, and a date with its clock time for an hour. A text
|
|
174
|
+
* that is not a time is given back as it is, as `formatInstant` gives it.
|
|
169
175
|
*/
|
|
170
176
|
function formatInstantAt(text, grain, locale, timeZone) {
|
|
171
177
|
const date = new Date(text.replace(/(\.\d{3})\d+/u, "$1"));
|
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";
|
|
@@ -26,17 +27,20 @@ import { DrillController, DrillOptions, useDrill } from "./drill/useDrill.mjs";
|
|
|
26
27
|
import { DrillMessages, ENGLISH_DRILL } from "./drill/words.mjs";
|
|
27
28
|
import { EditBar } from "./EditBar.mjs";
|
|
28
29
|
import "./FilterBar.mjs";
|
|
29
|
-
import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
|
|
30
|
+
import { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, plotValue } from "./format.mjs";
|
|
30
31
|
import { HistoryPanel, VersionBar } from "./History.mjs";
|
|
31
32
|
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, exactDigits } 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";
|
|
39
|
-
import {
|
|
40
|
+
import { SeriesSlotsContext } from "./scope.mjs";
|
|
41
|
+
import { Drawn, OTHER_KEY, Point, Series, lastBucketOpen, toSeries } from "./series.mjs";
|
|
42
|
+
import { pointCell, pointText, rowAt } from "./series-points.mjs";
|
|
43
|
+
import { SeriesSlots, SplitSeries, chartColors, seriesSlots } from "./series-slots.mjs";
|
|
40
44
|
import { Tile } from "./Tile.mjs";
|
|
41
45
|
import { useBoard } from "./useBoard.mjs";
|
|
42
46
|
import { useDashboard } from "./useDashboard.mjs";
|
|
@@ -53,4 +57,4 @@ export interface Register {}
|
|
|
53
57
|
export type Item = Register extends {
|
|
54
58
|
server: infer S;
|
|
55
59
|
} ? 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 };
|
|
60
|
+
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, exactDigits, fieldOf, rules_d_exports as filterRules, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, lastBucketOpen, plotValue, pointCell, pointText, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
|
package/dist/react/index.mjs
CHANGED
|
@@ -11,26 +11,29 @@ 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";
|
|
20
20
|
import { rules_exports } from "./filters/rules.mjs";
|
|
21
21
|
import { Popover } from "./filters/popover.mjs";
|
|
22
|
-
import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
|
|
22
|
+
import { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, plotValue } from "./format.mjs";
|
|
23
23
|
import { HistoryPanel, VersionBar } from "./History.mjs";
|
|
24
24
|
import { ENGLISH } from "./english.mjs";
|
|
25
25
|
import { ChangeList, Panel } from "./Panel.mjs";
|
|
26
26
|
import { ReviewPanel } from "./ReviewPanel.mjs";
|
|
27
|
-
import { NumberTile, TableTile } from "./renderers/index.mjs";
|
|
27
|
+
import { NumberTile, TableTile, exactDigits } 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 {
|
|
31
|
+
import { SeriesSlotsContext } from "./scope.mjs";
|
|
32
|
+
import { OTHER_KEY, lastBucketOpen, toSeries } from "./series.mjs";
|
|
33
|
+
import { pointCell, pointText, rowAt } from "./series-points.mjs";
|
|
34
|
+
import { chartColors, seriesSlots } from "./series-slots.mjs";
|
|
32
35
|
import { Tile } from "./Tile.mjs";
|
|
33
36
|
import { useBoard } from "./useBoard.mjs";
|
|
34
37
|
import { useDashboard } from "./useDashboard.mjs";
|
|
35
38
|
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 };
|
|
39
|
+
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, exactDigits, fieldOf, rules_exports as filterRules, formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, lastBucketOpen, plotValue, pointCell, pointText, rowAt, seriesSlots, toSeries, useBoard, useBuilder, useControlValues, useDashboard, useDashboards, useDraft, useDrill, useFilterFields, useReview, useTiles };
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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";
|
|
2
|
+
import { ResultCell } from "derive-dashboards/core";
|
|
21
3
|
/**
|
|
22
4
|
* The first calc or value column, large, from the total row when there is one, else the first row;
|
|
23
5
|
* a change calc (a signed column) sits under it.
|
|
24
6
|
*/
|
|
25
7
|
export declare function NumberTile(props: TileRendererProps): import("react").JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* A cell's exact digits ("12.50"), when it has them: exact cells written as plain decimals, and
|
|
10
|
+
* whole numbers a float holds exactly; undefined for any other float, whose digits are not exact.
|
|
11
|
+
*/
|
|
12
|
+
export declare const exactDigits: (cell: ResultCell | undefined) => string | undefined;
|
|
26
13
|
/** Every row and column: the groups, then Other and the total under them. */
|
|
27
|
-
export declare function TableTile(props: TileRendererProps): import("react").JSX.Element;
|
|
14
|
+
export declare function TableTile(props: TileRendererProps): import("react").JSX.Element;
|
|
15
|
+
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
|
/**
|
|
@@ -48,8 +48,11 @@ const numberOf = (cell) => {
|
|
|
48
48
|
if (cell !== null && typeof cell === "object" && "v" in cell) return Number(cell.v);
|
|
49
49
|
};
|
|
50
50
|
const PLAIN_DECIMAL = /^-?\d+(\.\d+)?$/u;
|
|
51
|
-
/**
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* A cell's exact digits ("12.50"), when it has them: exact cells written as plain decimals, and
|
|
53
|
+
* whole numbers a float holds exactly; undefined for any other float, whose digits are not exact.
|
|
54
|
+
*/
|
|
55
|
+
const exactDigits = (cell) => {
|
|
53
56
|
if (typeof cell === "number") return Number.isSafeInteger(cell) ? String(cell) : void 0;
|
|
54
57
|
if (cell !== null && typeof cell === "object" && "v" in cell && typeof cell.v === "string") return PLAIN_DECIMAL.test(cell.v) ? cell.v : void 0;
|
|
55
58
|
};
|
|
@@ -87,7 +90,7 @@ function exactDifference(a, b, type) {
|
|
|
87
90
|
* floats; its sign and its size as a cell to format. Undefined when either is not a number.
|
|
88
91
|
*/
|
|
89
92
|
function difference(now, was) {
|
|
90
|
-
const [a, b] = [
|
|
93
|
+
const [a, b] = [exactDigits(now), exactDigits(was)];
|
|
91
94
|
if (a === void 0 || b === void 0) return floatDifference(now, was);
|
|
92
95
|
return exactDifference(a, b, typeof now === "object" && now !== null && "t" in now ? now.t : "decimal");
|
|
93
96
|
}
|
|
@@ -184,4 +187,4 @@ const BUILTIN_RENDERERS = {
|
|
|
184
187
|
table: TableTile,
|
|
185
188
|
list: ListTile
|
|
186
189
|
};
|
|
187
|
-
export { BUILTIN_RENDERERS, NumberTile, TableTile };
|
|
190
|
+
export { BUILTIN_RENDERERS, NumberTile, TableTile, exactDigits };
|
|
@@ -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 };
|