derive-dashboards 0.3.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/react/format.d.mts +6 -0
- package/dist/react/format.mjs +24 -18
- package/dist/react/index.d.mts +5 -4
- package/dist/react/index.mjs +5 -4
- package/dist/react/renderers/index.d.mts +6 -0
- package/dist/react/renderers/index.mjs +7 -4
- package/dist/react/series-points.d.mts +18 -0
- package/dist/react/series-points.mjs +19 -0
- package/dist/react/series.d.mts +7 -10
- package/dist/react/series.mjs +6 -9
- package/dist/recharts/table.mjs +10 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,10 @@ Strongest first. [AGENTS.md](https://github.com/derive-to/dashboards/blob/main/A
|
|
|
72
72
|
tile at p95.
|
|
73
73
|
6. **Example tests**: one case per validation rule, endpoint and adapter.
|
|
74
74
|
|
|
75
|
+
On top of the checks, six audits (engineering, developer experience, UX, performance and
|
|
76
|
+
build against spec, twice) grade every PR against a fixed bar of the best open-source projects.
|
|
77
|
+
To run one, ask your coding agent for `/full-audit pr <n>`; see [how to run an audit](https://github.com/derive-to/dashboards/blob/main/docs/audits/README.md).
|
|
78
|
+
|
|
75
79
|
Dates and time zones use TC39 Temporal with the IANA zone database: buckets, ranges and
|
|
76
80
|
comparisons are checked in nine zones chosen for their daylight-saving and offset quirks, and
|
|
77
81
|
on hand-worked New York clock-change days.
|
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
|
@@ -27,18 +27,19 @@ import { DrillController, DrillOptions, useDrill } from "./drill/useDrill.mjs";
|
|
|
27
27
|
import { DrillMessages, ENGLISH_DRILL } from "./drill/words.mjs";
|
|
28
28
|
import { EditBar } from "./EditBar.mjs";
|
|
29
29
|
import "./FilterBar.mjs";
|
|
30
|
-
import { formatBucket, formatCell, formatInstant, formatTick, plotValue } from "./format.mjs";
|
|
30
|
+
import { formatBucket, formatCell, formatInstant, formatInstantAt, formatTick, plotValue } from "./format.mjs";
|
|
31
31
|
import { HistoryPanel, VersionBar } from "./History.mjs";
|
|
32
32
|
import { CellFormat, Messages } from "./messages.mjs";
|
|
33
33
|
import { ChangeList, Panel } from "./Panel.mjs";
|
|
34
34
|
import { ReviewPanel } from "./ReviewPanel.mjs";
|
|
35
35
|
import { ClientSchemas } from "./read.mjs";
|
|
36
|
-
import { NumberTile, TableTile } from "./renderers/index.mjs";
|
|
36
|
+
import { NumberTile, TableTile, exactDigits } from "./renderers/index.mjs";
|
|
37
37
|
import { ListDisplay, ListTile } from "./renderers/list.mjs";
|
|
38
38
|
import { Moved, Review, useReview } from "./review.mjs";
|
|
39
39
|
import { ENGLISH_REVIEW, ReviewMessages } from "./review-words.mjs";
|
|
40
40
|
import { SeriesSlotsContext } from "./scope.mjs";
|
|
41
|
-
import { Drawn, OTHER_KEY, Point, Series, lastBucketOpen,
|
|
41
|
+
import { Drawn, OTHER_KEY, Point, Series, lastBucketOpen, toSeries } from "./series.mjs";
|
|
42
|
+
import { pointCell, pointText, rowAt } from "./series-points.mjs";
|
|
42
43
|
import { SeriesSlots, SplitSeries, chartColors, seriesSlots } from "./series-slots.mjs";
|
|
43
44
|
import { Tile } from "./Tile.mjs";
|
|
44
45
|
import { useBoard } from "./useBoard.mjs";
|
|
@@ -56,4 +57,4 @@ export interface Register {}
|
|
|
56
57
|
export type Item = Register extends {
|
|
57
58
|
server: infer S;
|
|
58
59
|
} ? ItemFor<S> : DrillItem;
|
|
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 };
|
|
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
|
@@ -19,20 +19,21 @@ 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
31
|
import { SeriesSlotsContext } from "./scope.mjs";
|
|
32
|
-
import { OTHER_KEY, lastBucketOpen,
|
|
32
|
+
import { OTHER_KEY, lastBucketOpen, toSeries } from "./series.mjs";
|
|
33
|
+
import { pointCell, pointText, rowAt } from "./series-points.mjs";
|
|
33
34
|
import { chartColors, seriesSlots } from "./series-slots.mjs";
|
|
34
35
|
import { Tile } from "./Tile.mjs";
|
|
35
36
|
import { useBoard } from "./useBoard.mjs";
|
|
36
37
|
import { useDashboard } from "./useDashboard.mjs";
|
|
37
38
|
import { useTiles } from "./useTiles.mjs";
|
|
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 };
|
|
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,9 +1,15 @@
|
|
|
1
1
|
import { TileRenderer, TileRendererProps } from "./props.mjs";
|
|
2
|
+
import { ResultCell } from "derive-dashboards/core";
|
|
2
3
|
/**
|
|
3
4
|
* The first calc or value column, large, from the total row when there is one, else the first row;
|
|
4
5
|
* a change calc (a signed column) sits under it.
|
|
5
6
|
*/
|
|
6
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;
|
|
7
13
|
/** Every row and column: the groups, then Other and the total under them. */
|
|
8
14
|
export declare function TableTile(props: TileRendererProps): import("react").JSX.Element;
|
|
9
15
|
export type { TileRenderer, TileRendererProps };
|
|
@@ -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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CellFormat } from "./messages.mjs";
|
|
2
|
+
import { Drawn, Point, Series } from "./series.mjs";
|
|
3
|
+
import { ResultCell, TileAnswer } from "derive-dashboards/core";
|
|
4
|
+
/**
|
|
5
|
+
* The answer's row behind a point (or its place) of a series, for `drill.open(row,
|
|
6
|
+
* series.column.id)`; undefined for a point no row stands behind.
|
|
7
|
+
*/
|
|
8
|
+
export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
|
|
9
|
+
/** The answer's own cell behind a point of a series; none when no row stands behind it. */
|
|
10
|
+
export declare function pointCell(answer: Pick<TileAnswer, "columns" | "rows">, drawn: Drawn, at: {
|
|
11
|
+
point: number | Point;
|
|
12
|
+
series: Series;
|
|
13
|
+
}): ResultCell | undefined;
|
|
14
|
+
/** The answer's own cell behind a point of a series, as its column writes it; none with no row. */
|
|
15
|
+
export declare function pointText(answer: Pick<TileAnswer, "columns" | "rows">, drawn: Drawn, at: {
|
|
16
|
+
point: number | Point;
|
|
17
|
+
series: Series;
|
|
18
|
+
}, format?: CellFormat): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { formatCell } from "./format.mjs";
|
|
2
|
+
// src/series-points.ts
|
|
3
|
+
/**
|
|
4
|
+
* The answer's row behind a point (or its place) of a series, for `drill.open(row,
|
|
5
|
+
* series.column.id)`; undefined for a point no row stands behind.
|
|
6
|
+
*/
|
|
7
|
+
const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
|
|
8
|
+
/** The answer's own cell behind a point of a series; none when no row stands behind it. */
|
|
9
|
+
function pointCell(answer, drawn, at) {
|
|
10
|
+
const row = drawn.rowAt(at.point, at.series.key);
|
|
11
|
+
const column = answer.columns.indexOf(at.series.column);
|
|
12
|
+
return row === void 0 ? void 0 : answer.rows[row]?.[column];
|
|
13
|
+
}
|
|
14
|
+
/** The answer's own cell behind a point of a series, as its column writes it; none with no row. */
|
|
15
|
+
function pointText(answer, drawn, at, format = {}) {
|
|
16
|
+
const cell = pointCell(answer, drawn, at);
|
|
17
|
+
return cell === void 0 ? void 0 : formatCell(cell, at.series.column, format);
|
|
18
|
+
}
|
|
19
|
+
export { pointCell, pointText, rowAt };
|
package/dist/react/series.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CellFormat } from "./messages.mjs";
|
|
2
2
|
import { SeriesSlots } from "./series-slots.mjs";
|
|
3
|
-
import { ResultColumn, TileAnswer, TimeBucket } from "derive-dashboards/core";
|
|
3
|
+
import { ResultCell, ResultColumn, TileAnswer, TimeBucket } from "derive-dashboards/core";
|
|
4
4
|
/** One point of a chart: its x label, its place (`#`, never an entry id) and a number per series key. */
|
|
5
5
|
export type Point = {
|
|
6
6
|
x: string;
|
|
@@ -44,20 +44,17 @@ export type Drawn = {
|
|
|
44
44
|
split: boolean;
|
|
45
45
|
notDrawn: ResultColumn[];
|
|
46
46
|
/**
|
|
47
|
-
* When the x axis is time: each point's bucket as instants, in the points' order,
|
|
48
|
-
*
|
|
49
|
-
* time on; the points' `x` is only the bucket's name.
|
|
47
|
+
* When the x axis is time: each point's bucket as instants, in the points' order, `partial`
|
|
48
|
+
* on one not whole (the week still running). A chart draws time on these; `x` only names it.
|
|
50
49
|
*/
|
|
51
50
|
buckets?: readonly (TimeBucket | undefined)[];
|
|
51
|
+
/** Whether a point stands for the values a limit folded together: its x is Other. */
|
|
52
|
+
isOther: (point: number) => boolean;
|
|
53
|
+
/** A point's raw x cell, as the answer has it; null for a point with none. What a point is of, however it reads. */
|
|
54
|
+
xAt: (point: number) => ResultCell;
|
|
52
55
|
rowAt: (point: number | Point, seriesKey: string) => number | undefined;
|
|
53
56
|
};
|
|
54
57
|
type Answer = Pick<TileAnswer, "columns" | "rows" | "time">;
|
|
55
|
-
/**
|
|
56
|
-
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
57
|
-
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
58
|
-
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
59
|
-
*/
|
|
60
|
-
export declare const rowAt: (drawn: Drawn, point: number | Point, seriesKey: string) => number | undefined;
|
|
61
58
|
/**
|
|
62
59
|
* Whether the answer's last time bucket is still running: the range ends before the bucket
|
|
63
60
|
* does, as this week does on its Monday. Its value is not final, so a chart marks it rather
|
package/dist/react/series.mjs
CHANGED
|
@@ -6,7 +6,8 @@ import { isMark, roleOf } from "derive-dashboards/core";
|
|
|
6
6
|
const isValue = (c) => roleOf(c) === "measure" || roleOf(c) === "calc";
|
|
7
7
|
/** The series key a dimension's Other draws as. */
|
|
8
8
|
const OTHER_KEY = "other";
|
|
9
|
-
|
|
9
|
+
/** Whether a cell is the given mark: Other, or the total row's All. */
|
|
10
|
+
const isMarked = (cell, mark) => isMark(cell) && cell.mark === mark;
|
|
10
11
|
/** What a value is read against: two columns share an axis only when this is equal. */
|
|
11
12
|
const scaleOf = (c) => JSON.stringify([
|
|
12
13
|
c.unit ?? null,
|
|
@@ -34,6 +35,8 @@ function toSeries(answer, format = {}, slots) {
|
|
|
34
35
|
return {
|
|
35
36
|
...drawn,
|
|
36
37
|
...bucketsOf(answer, shape.keys, xs),
|
|
38
|
+
isOther: (point) => isMarked(xs[point] ?? null, "other"),
|
|
39
|
+
xAt: (point) => xs[point] ?? null,
|
|
37
40
|
rowAt: (point, key) => {
|
|
38
41
|
const index = typeof point === "number" ? point : drawn.points.indexOf(point);
|
|
39
42
|
return at.get(`${String(index)}|${key}`) ?? at.get(`${String(index)}|*`);
|
|
@@ -74,7 +77,7 @@ function drawSeries(answer, shape) {
|
|
|
74
77
|
const rows = answer.rows.map((row, index) => ({
|
|
75
78
|
row,
|
|
76
79
|
index
|
|
77
|
-
})).filter(({ row }) => !row.some((cell) =>
|
|
80
|
+
})).filter(({ row }) => !row.some((cell) => isMarked(cell, "all")));
|
|
78
81
|
return shape.keys.length < 2 ? plainSeries(rows, values, shape) : splitSeries(rows, values, shape);
|
|
79
82
|
}
|
|
80
83
|
/** The x label of a row, from its first key. */
|
|
@@ -173,12 +176,6 @@ function splitKey(cells) {
|
|
|
173
176
|
return `s${JSON.stringify(cells.length === 1 ? only ?? null : cells)}`;
|
|
174
177
|
}
|
|
175
178
|
/**
|
|
176
|
-
* The row of the answer behind a point of any chart kit's series, by the point's place (or the
|
|
177
|
-
* point) and the series key; undefined for a point no row stands behind. Pass it to
|
|
178
|
-
* `drill.open(row, series.column.id)` to open what is behind the point.
|
|
179
|
-
*/
|
|
180
|
-
const rowAt = (drawn, point, seriesKey) => drawn.rowAt(point, seriesKey);
|
|
181
|
-
/**
|
|
182
179
|
* Whether the answer's last time bucket is still running: the range ends before the bucket
|
|
183
180
|
* does, as this week does on its Monday. Its value is not final, so a chart marks it rather
|
|
184
181
|
* than draw it as a fall. The server says so (`answer.time`), by the engine's own calendar.
|
|
@@ -189,4 +186,4 @@ function lastBucketOpen(answer) {
|
|
|
189
186
|
const bucket = answer.time?.buckets.find((b) => b.label === last);
|
|
190
187
|
return bucket?.partial === "end" || bucket?.partial === "both";
|
|
191
188
|
}
|
|
192
|
-
export { OTHER_KEY, lastBucketOpen,
|
|
189
|
+
export { OTHER_KEY, lastBucketOpen, toSeries };
|
package/dist/recharts/table.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NotDrawn } from "./axes.mjs";
|
|
2
2
|
import { Marks } from "./marks.mjs";
|
|
3
|
-
import { formatCell } from "derive-dashboards/react";
|
|
3
|
+
import { formatCell, pointText } from "derive-dashboards/react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/table.tsx
|
|
6
6
|
/**
|
|
@@ -8,10 +8,12 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
* reads exactly and each series keeps its unit; the drawn number when no row stands behind it.
|
|
9
9
|
*/
|
|
10
10
|
function cellText(props, drawn, at) {
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const point = typeof at.place === "number" ? at.place : void 0;
|
|
12
|
+
const own = point === void 0 ? void 0 : pointText(props.answer, drawn, {
|
|
13
|
+
point,
|
|
14
|
+
series: at.series
|
|
15
|
+
}, props);
|
|
16
|
+
if (own !== void 0) return own;
|
|
15
17
|
if (typeof at.value === "number") return formatCell(at.value, at.series.column, props);
|
|
16
18
|
const v = at.value;
|
|
17
19
|
return typeof v === "string" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : "";
|
|
@@ -23,9 +25,9 @@ function cellText(props, drawn, at) {
|
|
|
23
25
|
*/
|
|
24
26
|
function ChartTable({ drawn, props, kind }) {
|
|
25
27
|
const { points, series } = drawn;
|
|
26
|
-
return /* @__PURE__ */
|
|
28
|
+
return /* @__PURE__ */ jsx("div", {
|
|
27
29
|
className: "dd-sr-only",
|
|
28
|
-
children: [
|
|
30
|
+
children: /* @__PURE__ */ jsxs("table", { children: [
|
|
29
31
|
/* @__PURE__ */ jsx("caption", { children: props.messages.chartTable({
|
|
30
32
|
title: props.widget.title,
|
|
31
33
|
kind,
|
|
@@ -43,7 +45,7 @@ function ChartTable({ drawn, props, kind }) {
|
|
|
43
45
|
series: s,
|
|
44
46
|
value: point[s.key]
|
|
45
47
|
}) }, s.key))] }, point.x)) })
|
|
46
|
-
]
|
|
48
|
+
] })
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
/** What sits beside every chart: its keyboard path, what it does not draw, and its data table. */
|
package/package.json
CHANGED