derive-dashboards 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -0
- package/dist/body.mjs +5 -1
- package/dist/charts/data/words.d.mts +5 -0
- package/dist/charts/data/words.mjs +1 -0
- package/dist/charts/kinds/columns-data.mjs +4 -1
- package/dist/charts/kinds/grid-layout.mjs +84 -8
- package/dist/charts/kinds/grid-legend.mjs +27 -4
- package/dist/charts/kinds/grid-marks.mjs +56 -4
- package/dist/charts/kinds/grid.mjs +2 -1
- package/dist/charts/scale/value.mjs +15 -8
- package/dist/charts/scene/types.d.mts +1 -1
- package/dist/core/document/display-entries.mjs +9 -2
- package/dist/core/document/display.d.mts +7 -3
- package/dist/core/document/display.mjs +15 -2
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +2 -0
- package/dist/core/error/codes.mjs +2 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +3 -3
- package/dist/core/model/member.d.mts +6 -0
- package/dist/core/model/member.mjs +11 -1
- package/dist/core/model/types.d.mts +6 -0
- package/dist/core/model/validate/known-members.mjs +1 -0
- package/dist/core/model/validate/members.mjs +12 -1
- package/dist/core/query/closure.mjs +2 -0
- package/dist/core/query/drill/links.mjs +16 -4
- package/dist/core/result/columns.mjs +15 -2
- package/dist/core/result/types.d.mts +2 -0
- package/dist/core/schema/answer-parts.mjs +1 -0
- package/dist/core/schema/answers.d.mts +14 -0
- package/dist/core/schema/answers.mjs +4 -2
- package/dist/core/schema/tools.mjs +4 -0
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/endpoints/index.d.mts +5 -4
- package/dist/endpoints/meta.mjs +30 -12
- package/dist/endpoints/query.mjs +11 -5
- package/dist/endpoints/values.mjs +38 -24
- package/dist/execute.mjs +22 -1
- package/dist/labels.mjs +68 -0
- package/dist/listing.mjs +13 -0
- package/dist/react/Canvas.mjs +28 -2
- package/dist/react/Cell.mjs +1 -1
- package/dist/react/Dashboard.d.mts +2 -3
- package/dist/react/Tile.d.mts +1 -1
- package/dist/react/arrange-steps.mjs +99 -11
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/base.mjs +11 -6
- package/dist/react/builder/display.mjs +16 -2
- package/dist/react/builder/state.mjs +3 -3
- package/dist/react/builder/words.mjs +8 -0
- package/dist/react/dates-shown.mjs +27 -9
- package/dist/react/filters/bar.d.mts +1 -1
- package/dist/react/filters/bar.mjs +17 -7
- package/dist/react/filters/chip.mjs +5 -3
- package/dist/react/filters/context.mjs +2 -2
- package/dist/react/filters/dates-said.mjs +29 -11
- package/dist/react/filters/hooks.d.mts +8 -0
- package/dist/react/filters/hooks.mjs +39 -2
- package/dist/react/filters/menu.mjs +8 -18
- package/dist/react/filters/phone.mjs +3 -3
- package/dist/react/filters/values.mjs +47 -28
- package/dist/react/filters/words.mjs +2 -2
- package/dist/react/format.d.mts +1 -1
- package/dist/react/format.mjs +8 -2
- package/dist/react/renderers/moved.mjs +160 -0
- package/dist/react/renderers/number-before.mjs +2 -157
- package/dist/react/renderers/props.d.mts +3 -3
- package/dist/react/renderers/table-cells.mjs +97 -11
- package/dist/react/renderers/table-head.mjs +7 -1
- package/dist/react/renderers/table-measure.mjs +147 -25
- package/dist/react/renderers/table-over.mjs +72 -0
- package/dist/react/renderers/table-scale.mjs +54 -1
- package/dist/react/renderers/table-trend.mjs +55 -0
- package/dist/react/renderers/table.d.mts +5 -1
- package/dist/react/renderers/table.mjs +29 -6
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { amountExact, pointsExact, pointsText, wentFor } from "../change-text.mjs";
|
|
2
|
+
import { formatCell, numberSent } from "../format.mjs";
|
|
3
|
+
import { headlineWriterOf } from "../headline.mjs";
|
|
4
|
+
import { exactDifference, exactDigits } from "./exact.mjs";
|
|
5
|
+
import { MINUS, cellDigits } from "derive-dashboards/core";
|
|
6
|
+
// src/renderers/moved.ts
|
|
7
|
+
/**
|
|
8
|
+
* A cell as its number is read: a number a driver sent as text, in a column of numbers, is its
|
|
9
|
+
* digits, as the headline above writes it (`numberSent`). Any other cell is itself.
|
|
10
|
+
*/
|
|
11
|
+
function readOf(cell, column) {
|
|
12
|
+
const sent = typeof cell === "string" ? numberSent(cell, column) : void 0;
|
|
13
|
+
return sent === void 0 ? cell : {
|
|
14
|
+
t: "decimal",
|
|
15
|
+
v: sent.v
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** A cell's number as it is held: a float, or an exact amount's digits read as one. */
|
|
19
|
+
const held = (cell) => cell !== null && typeof cell === "object" && "v" in cell ? Number(cell.v) : NaN;
|
|
20
|
+
/**
|
|
21
|
+
* A cell as a number to compare, for the change against the period before. None for what is no
|
|
22
|
+
* amount: no value, words, and a float that is not a number or has no end (NaN, an infinity).
|
|
23
|
+
*/
|
|
24
|
+
const numberOf = (cell) => {
|
|
25
|
+
const value = typeof cell === "number" ? cell : held(cell);
|
|
26
|
+
return Number.isFinite(value) ? value : void 0;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Two floats that agree to this many parts are one number written twice: the average of 0.1,
|
|
30
|
+
* 0.2 and 0.6 is 0.30000000000000004, which did not move from 0.3.
|
|
31
|
+
*/
|
|
32
|
+
const FLOAT_NOISE = 1e-12;
|
|
33
|
+
/**
|
|
34
|
+
* now − was of two floats as each is written (the shortest digits that read back as it), so
|
|
35
|
+
* 0.440000001 less 0.44 is 0.000000001, where the floats' own difference is 9.99999971718E−10.
|
|
36
|
+
* None when either is not written as a plain decimal.
|
|
37
|
+
*/
|
|
38
|
+
function writtenDifference(now, was) {
|
|
39
|
+
const [a, b] = [cellDigits(now), cellDigits(was)];
|
|
40
|
+
return a === void 0 || b === void 0 ? void 0 : exactDifference(a, b, "decimal").size;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* now − was in floats, for values that are not exact digits. None when either is no number to
|
|
44
|
+
* compare, or their difference is past what a float holds: the line then says only what it was.
|
|
45
|
+
* Which way it went, whether it moved at all and how far a reader takes it to have moved are
|
|
46
|
+
* the floats' own; how far it moved as it is, is by their written digits where they have them.
|
|
47
|
+
*/
|
|
48
|
+
function floatDifference(now, was) {
|
|
49
|
+
const [x, y] = [numberOf(now), numberOf(was)];
|
|
50
|
+
if (x === void 0 || y === void 0 || !Number.isFinite(x - y)) return void 0;
|
|
51
|
+
const size = Math.abs(x - y);
|
|
52
|
+
const same = size <= FLOAT_NOISE * Math.max(Math.abs(x), Math.abs(y));
|
|
53
|
+
const written = writtenDifference(now, was);
|
|
54
|
+
return {
|
|
55
|
+
sign: same ? 0 : Math.sign(x - y),
|
|
56
|
+
size,
|
|
57
|
+
...written === void 0 ? {} : { written }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* now − was exactly, where both are exact digits and their column is not one of floats (a 2^53
|
|
62
|
+
* amount that moved by 1 moved by 1). A column of floats is held to a float's figures though
|
|
63
|
+
* its values be whole numbers: 1,000,000,000,001 did not move from 1,000,000,000,000 there.
|
|
64
|
+
*/
|
|
65
|
+
function exactOf(now, was, column) {
|
|
66
|
+
const [a, b] = [exactDigits(now), exactDigits(was)];
|
|
67
|
+
if (column.type === "float" || a === void 0 || b === void 0) return void 0;
|
|
68
|
+
const type = typeof now === "object" && now !== null && "t" in now ? now.t : "decimal";
|
|
69
|
+
return exactDifference(a, b, type);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* now − was, exactly where it can be (`exactOf`), else in floats; its sign and its size as a
|
|
73
|
+
* cell to format. Undefined when either is not a number, and for a rate whose move no float
|
|
74
|
+
* holds (exact digits past a float's range): its points cannot be written, and as an amount it
|
|
75
|
+
* would read as an infinite percent, so the line says only what it was.
|
|
76
|
+
*/
|
|
77
|
+
function difference(now, was, column) {
|
|
78
|
+
const delta = exactOf(now, was, column) ?? floatDifference(now, was);
|
|
79
|
+
return column.format === "percent" && numberOf(delta?.size) === void 0 ? void 0 : delta;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The size of a rate's change, as its column holds its values (a fraction of one, or points).
|
|
83
|
+
* Two floats' change is read from their written digits, so half a tenth of a point is that
|
|
84
|
+
* whatever rate it moved from, where the floats' own difference falls a hair to either side.
|
|
85
|
+
* None for a column that is no rate.
|
|
86
|
+
*/
|
|
87
|
+
const rateSize = (delta, column) => column.format === "percent" ? numberOf(delta.written ?? delta.size) : void 0;
|
|
88
|
+
/** The least share worth writing: under a twentieth of a percent it would read as no change. */
|
|
89
|
+
const LEAST_SHARE = 5e-4;
|
|
90
|
+
/** The share from which the amount says more: a hundredfold is 10,000%, which no one takes in. */
|
|
91
|
+
const MOST_SHARE = 100;
|
|
92
|
+
/**
|
|
93
|
+
* An amount's change as a share of where it was ("14%"), written as any percent is: none from
|
|
94
|
+
* nothing or from less than nothing, where a share says nothing, none where the share is too
|
|
95
|
+
* small to write (an amount of 2^53 that moved by 1), and none from a hundredfold up (a move
|
|
96
|
+
* from next to nothing). The amount is said then.
|
|
97
|
+
*/
|
|
98
|
+
function shareText(size, was, props) {
|
|
99
|
+
const [moved, base] = [numberOf(size), numberOf(was)];
|
|
100
|
+
if (moved === void 0 || base === void 0 || base <= 0) return void 0;
|
|
101
|
+
const share = moved / base;
|
|
102
|
+
if (!(share >= LEAST_SHARE) || share >= MOST_SHARE) return void 0;
|
|
103
|
+
return formatCell(share, {
|
|
104
|
+
format: "percent",
|
|
105
|
+
fraction: true
|
|
106
|
+
}, props);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* An amount that moved, written beside the headline: a length of time in the unit the headline
|
|
110
|
+
* is written in ("0.8 days" by "4.8 days", never "19.2 hr"). It is written by its own size, not
|
|
111
|
+
* in the headline's places: a move of 51 cents under "$27,001" is "$0.51", never "$1".
|
|
112
|
+
*/
|
|
113
|
+
function amountMoved(size, at) {
|
|
114
|
+
const shown = numberOf(at.now);
|
|
115
|
+
const beside = shown === void 0 ? at.column : {
|
|
116
|
+
...at.column,
|
|
117
|
+
beside: shown
|
|
118
|
+
};
|
|
119
|
+
return headlineWriterOf(at.props.widget)(size, beside, at.props);
|
|
120
|
+
}
|
|
121
|
+
/** How far the number moved, as a reader takes it in: points for a rate, else a share, else the amount. */
|
|
122
|
+
function movedText(delta, was, at) {
|
|
123
|
+
const { column, props } = at;
|
|
124
|
+
const rate = rateSize(delta, column);
|
|
125
|
+
if (rate !== void 0) return pointsText(rate, column, props);
|
|
126
|
+
return shareText(delta.size, was, props) ?? amountMoved(delta.size, at);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The change as it is, without a sign, for whoever asks: a rate's in points, never as a percent
|
|
130
|
+
* of a percent; an amount's with every digit it holds, where the line itself rounds.
|
|
131
|
+
*/
|
|
132
|
+
function exactText(delta, column, props) {
|
|
133
|
+
const float = delta.written !== void 0;
|
|
134
|
+
const size = delta.written ?? delta.size;
|
|
135
|
+
return rateSize(delta, column) === void 0 ? amountExact(size, column, {
|
|
136
|
+
...props,
|
|
137
|
+
float
|
|
138
|
+
}) : pointsExact(size, column, {
|
|
139
|
+
...props,
|
|
140
|
+
float
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** How the number moved from what it was, or undefined when it did not. */
|
|
144
|
+
function movedOf(delta, was, at) {
|
|
145
|
+
if (delta.sign === 0) return void 0;
|
|
146
|
+
const up = delta.sign > 0;
|
|
147
|
+
const { signed: _signed, ...plain } = at.column;
|
|
148
|
+
const way = up ? "up" : "down";
|
|
149
|
+
const went = wentFor(at.column, way);
|
|
150
|
+
return {
|
|
151
|
+
way,
|
|
152
|
+
size: movedText(delta, was, {
|
|
153
|
+
...at,
|
|
154
|
+
column: plain
|
|
155
|
+
}),
|
|
156
|
+
exact: `${up ? "+" : MINUS}${exactText(delta, plain, at.props)}`,
|
|
157
|
+
...went === void 0 ? {} : { went }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export { difference, movedOf, readOf };
|
|
@@ -1,164 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatCell, numberSent } from "../format.mjs";
|
|
1
|
+
import { betterMark } from "../change-text.mjs";
|
|
3
2
|
import { headlineWriterOf } from "../headline.mjs";
|
|
4
|
-
import {
|
|
3
|
+
import { difference, movedOf, readOf } from "./moved.mjs";
|
|
5
4
|
import { daysBefore } from "./number-period.mjs";
|
|
6
|
-
import { MINUS, cellDigits } from "derive-dashboards/core";
|
|
7
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
6
|
// src/renderers/number-before.tsx
|
|
9
|
-
/**
|
|
10
|
-
* A cell as its number is read: a number a driver sent as text, in a column of numbers, is its
|
|
11
|
-
* digits, as the headline above writes it (`numberSent`). Any other cell is itself.
|
|
12
|
-
*/
|
|
13
|
-
function readOf(cell, column) {
|
|
14
|
-
const sent = typeof cell === "string" ? numberSent(cell, column) : void 0;
|
|
15
|
-
return sent === void 0 ? cell : {
|
|
16
|
-
t: "decimal",
|
|
17
|
-
v: sent.v
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/** A cell's number as it is held: a float, or an exact amount's digits read as one. */
|
|
21
|
-
const held = (cell) => cell !== null && typeof cell === "object" && "v" in cell ? Number(cell.v) : NaN;
|
|
22
|
-
/**
|
|
23
|
-
* A cell as a number to compare, for the change against the period before. None for what is no
|
|
24
|
-
* amount: no value, words, and a float that is not a number or has no end (NaN, an infinity).
|
|
25
|
-
*/
|
|
26
|
-
const numberOf = (cell) => {
|
|
27
|
-
const value = typeof cell === "number" ? cell : held(cell);
|
|
28
|
-
return Number.isFinite(value) ? value : void 0;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Two floats that agree to this many parts are one number written twice: the average of 0.1,
|
|
32
|
-
* 0.2 and 0.6 is 0.30000000000000004, which did not move from 0.3.
|
|
33
|
-
*/
|
|
34
|
-
const FLOAT_NOISE = 1e-12;
|
|
35
|
-
/**
|
|
36
|
-
* now − was of two floats as each is written (the shortest digits that read back as it), so
|
|
37
|
-
* 0.440000001 less 0.44 is 0.000000001, where the floats' own difference is 9.99999971718E−10.
|
|
38
|
-
* None when either is not written as a plain decimal.
|
|
39
|
-
*/
|
|
40
|
-
function writtenDifference(now, was) {
|
|
41
|
-
const [a, b] = [cellDigits(now), cellDigits(was)];
|
|
42
|
-
return a === void 0 || b === void 0 ? void 0 : exactDifference(a, b, "decimal").size;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* now − was in floats, for values that are not exact digits. None when either is no number to
|
|
46
|
-
* compare, or their difference is past what a float holds: the line then says only what it was.
|
|
47
|
-
* Which way it went, whether it moved at all and how far a reader takes it to have moved are
|
|
48
|
-
* the floats' own; how far it moved as it is, is by their written digits where they have them.
|
|
49
|
-
*/
|
|
50
|
-
function floatDifference(now, was) {
|
|
51
|
-
const [x, y] = [numberOf(now), numberOf(was)];
|
|
52
|
-
if (x === void 0 || y === void 0 || !Number.isFinite(x - y)) return void 0;
|
|
53
|
-
const size = Math.abs(x - y);
|
|
54
|
-
const same = size <= FLOAT_NOISE * Math.max(Math.abs(x), Math.abs(y));
|
|
55
|
-
const written = writtenDifference(now, was);
|
|
56
|
-
return {
|
|
57
|
-
sign: same ? 0 : Math.sign(x - y),
|
|
58
|
-
size,
|
|
59
|
-
...written === void 0 ? {} : { written }
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* now − was exactly, where both are exact digits and their column is not one of floats (a 2^53
|
|
64
|
-
* amount that moved by 1 moved by 1). A column of floats is held to a float's figures though
|
|
65
|
-
* its values be whole numbers: 1,000,000,000,001 did not move from 1,000,000,000,000 there.
|
|
66
|
-
*/
|
|
67
|
-
function exactOf(now, was, column) {
|
|
68
|
-
const [a, b] = [exactDigits(now), exactDigits(was)];
|
|
69
|
-
if (column.type === "float" || a === void 0 || b === void 0) return void 0;
|
|
70
|
-
const type = typeof now === "object" && now !== null && "t" in now ? now.t : "decimal";
|
|
71
|
-
return exactDifference(a, b, type);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* now − was, exactly where it can be (`exactOf`), else in floats; its sign and its size as a
|
|
75
|
-
* cell to format. Undefined when either is not a number, and for a rate whose move no float
|
|
76
|
-
* holds (exact digits past a float's range): its points cannot be written, and as an amount it
|
|
77
|
-
* would read as an infinite percent, so the line says only what it was.
|
|
78
|
-
*/
|
|
79
|
-
function difference(now, was, column) {
|
|
80
|
-
const delta = exactOf(now, was, column) ?? floatDifference(now, was);
|
|
81
|
-
return column.format === "percent" && numberOf(delta?.size) === void 0 ? void 0 : delta;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The size of a rate's change, as its column holds its values (a fraction of one, or points).
|
|
85
|
-
* Two floats' change is read from their written digits, so half a tenth of a point is that
|
|
86
|
-
* whatever rate it moved from, where the floats' own difference falls a hair to either side.
|
|
87
|
-
* None for a column that is no rate.
|
|
88
|
-
*/
|
|
89
|
-
const rateSize = (delta, column) => column.format === "percent" ? numberOf(delta.written ?? delta.size) : void 0;
|
|
90
|
-
/** The least share worth writing: under a twentieth of a percent it would read as no change. */
|
|
91
|
-
const LEAST_SHARE = 5e-4;
|
|
92
|
-
/** The share from which the amount says more: a hundredfold is 10,000%, which no one takes in. */
|
|
93
|
-
const MOST_SHARE = 100;
|
|
94
|
-
/**
|
|
95
|
-
* An amount's change as a share of where it was ("14%"), written as any percent is: none from
|
|
96
|
-
* nothing or from less than nothing, where a share says nothing, none where the share is too
|
|
97
|
-
* small to write (an amount of 2^53 that moved by 1), and none from a hundredfold up (a move
|
|
98
|
-
* from next to nothing). The amount is said then.
|
|
99
|
-
*/
|
|
100
|
-
function shareText(size, was, props) {
|
|
101
|
-
const [moved, base] = [numberOf(size), numberOf(was)];
|
|
102
|
-
if (moved === void 0 || base === void 0 || base <= 0) return void 0;
|
|
103
|
-
const share = moved / base;
|
|
104
|
-
if (!(share >= LEAST_SHARE) || share >= MOST_SHARE) return void 0;
|
|
105
|
-
return formatCell(share, {
|
|
106
|
-
format: "percent",
|
|
107
|
-
fraction: true
|
|
108
|
-
}, props);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* An amount that moved, written beside the headline: a length of time in the unit the headline
|
|
112
|
-
* is written in ("0.8 days" by "4.8 days", never "19.2 hr"). It is written by its own size, not
|
|
113
|
-
* in the headline's places: a move of 51 cents under "$27,001" is "$0.51", never "$1".
|
|
114
|
-
*/
|
|
115
|
-
function amountMoved(size, at) {
|
|
116
|
-
const shown = numberOf(at.now);
|
|
117
|
-
const beside = shown === void 0 ? at.column : {
|
|
118
|
-
...at.column,
|
|
119
|
-
beside: shown
|
|
120
|
-
};
|
|
121
|
-
return headlineWriterOf(at.props.widget)(size, beside, at.props);
|
|
122
|
-
}
|
|
123
|
-
/** How far the number moved, as a reader takes it in: points for a rate, else a share, else the amount. */
|
|
124
|
-
function movedText(delta, was, at) {
|
|
125
|
-
const { column, props } = at;
|
|
126
|
-
const rate = rateSize(delta, column);
|
|
127
|
-
if (rate !== void 0) return pointsText(rate, column, props);
|
|
128
|
-
return shareText(delta.size, was, props) ?? amountMoved(delta.size, at);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* The change as it is, without a sign, for whoever asks: a rate's in points, never as a percent
|
|
132
|
-
* of a percent; an amount's with every digit it holds, where the line itself rounds.
|
|
133
|
-
*/
|
|
134
|
-
function exactText(delta, column, props) {
|
|
135
|
-
const float = delta.written !== void 0;
|
|
136
|
-
const size = delta.written ?? delta.size;
|
|
137
|
-
return rateSize(delta, column) === void 0 ? amountExact(size, column, {
|
|
138
|
-
...props,
|
|
139
|
-
float
|
|
140
|
-
}) : pointsExact(size, column, {
|
|
141
|
-
...props,
|
|
142
|
-
float
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
/** How the number moved from what it was, or undefined when it did not. */
|
|
146
|
-
function movedOf(delta, was, at) {
|
|
147
|
-
if (delta.sign === 0) return void 0;
|
|
148
|
-
const up = delta.sign > 0;
|
|
149
|
-
const { signed: _signed, ...plain } = at.column;
|
|
150
|
-
const way = up ? "up" : "down";
|
|
151
|
-
const went = wentFor(at.column, way);
|
|
152
|
-
return {
|
|
153
|
-
way,
|
|
154
|
-
size: movedText(delta, was, {
|
|
155
|
-
...at,
|
|
156
|
-
column: plain
|
|
157
|
-
}),
|
|
158
|
-
exact: `${up ? "+" : MINUS}${exactText(delta, plain, at.props)}`,
|
|
159
|
-
...went === void 0 ? {} : { went }
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
7
|
const ARROW = {
|
|
163
8
|
up: "↑",
|
|
164
9
|
down: "↓"
|
|
@@ -28,12 +28,12 @@ export type TileRendererProps = {
|
|
|
28
28
|
*/
|
|
29
29
|
timeZone?: string;
|
|
30
30
|
/**
|
|
31
|
-
* Whether the tile is as tall as what it holds, which it is
|
|
31
|
+
* Whether the tile is as tall as what it holds, which it is on a dashboard, read or edited: a
|
|
32
32
|
* table then draws its first rows and a button for the rest, a list likewise, and a chart of
|
|
33
33
|
* rows lying down as many as it has, and the tile's row on the grid is as tall as that. A
|
|
34
34
|
* renderer that sizes itself so says it on its root (`{...fitted(fit)}`); one that does
|
|
35
|
-
* not fills the rows its tile was given. Left out
|
|
36
|
-
*
|
|
35
|
+
* not fills the rows its tile was given. Left out for a tile on a page of the host's own:
|
|
36
|
+
* there a tile fills its box, and scrolls inside it.
|
|
37
37
|
*/
|
|
38
38
|
fit?: boolean;
|
|
39
39
|
};
|
|
@@ -4,8 +4,9 @@ import { isNumeric, isValue } from "../columns.mjs";
|
|
|
4
4
|
import { compareGroupLabel } from "../drill/words.mjs";
|
|
5
5
|
import { formatCell, plotValue } from "../format.mjs";
|
|
6
6
|
import { depthOf, reachOf } from "./table-scale.mjs";
|
|
7
|
+
import { Trend } from "./table-trend.mjs";
|
|
7
8
|
import { valueText } from "./table-whole.mjs";
|
|
8
|
-
import { isMark } from "derive-dashboards/core";
|
|
9
|
+
import { addsUp, isMark } from "derive-dashboards/core";
|
|
9
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
11
|
// src/renderers/table-cells.tsx
|
|
11
12
|
/** A row that opens whole: the row takes a click anywhere, the button in its heading cell the keyboard. */
|
|
@@ -43,15 +44,32 @@ function toneOf(cell, other) {
|
|
|
43
44
|
if (other) return "other";
|
|
44
45
|
return (plotValue(cell) ?? 0) < 0 ? "negative" : "series";
|
|
45
46
|
}
|
|
46
|
-
/** A
|
|
47
|
+
/** A length or a share as a CSS percent, to a tenth. */
|
|
48
|
+
const percent = (share) => `${String(Math.round(share * 1e3) / 10)}%`;
|
|
49
|
+
/** How a bar is drawn: a dot on its scale, a whole with its part inside, or a plain length. */
|
|
50
|
+
const formOf = (at, part) => {
|
|
51
|
+
if (at.dot !== void 0) return "dot";
|
|
52
|
+
return part === void 0 ? void 0 : "parts";
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A value with its bar: the bar in a track every row shares the length of, then the number in
|
|
56
|
+
* room every row shares. A column of dots draws a dot where the value stands and a tick where
|
|
57
|
+
* the total does; the whole of two parts draws its part filled inside its own length.
|
|
58
|
+
*/
|
|
47
59
|
function Bar({ text, cell, at }) {
|
|
48
|
-
const
|
|
60
|
+
const part = at.parts?.get(at.place);
|
|
61
|
+
const against = at.dot?.against;
|
|
49
62
|
const vars = {
|
|
50
|
-
"--dd-fill":
|
|
51
|
-
"--dd-chars": String(at.chars)
|
|
63
|
+
"--dd-fill": percent(reachOf(cell, at.scale)),
|
|
64
|
+
"--dd-chars": String(at.chars),
|
|
65
|
+
...part === void 0 ? {} : { "--dd-part": String(Math.round(part * 1e3) / 1e3) },
|
|
66
|
+
...against === void 0 ? {} : { "--dd-against": percent(against) }
|
|
52
67
|
};
|
|
53
68
|
return /* @__PURE__ */ jsxs("span", {
|
|
54
69
|
className: "dd-table-bar",
|
|
70
|
+
"data-form": formOf(at, part),
|
|
71
|
+
"data-against": against === void 0 ? void 0 : "true",
|
|
72
|
+
"data-total": at.total ? "true" : void 0,
|
|
55
73
|
"data-tone": toneOf(cell, at.other),
|
|
56
74
|
style: vars,
|
|
57
75
|
children: [/* @__PURE__ */ jsx("span", { className: "dd-table-bar-track" }), /* @__PURE__ */ jsx("span", {
|
|
@@ -87,8 +105,17 @@ function Label({ column, at }) {
|
|
|
87
105
|
children: column.label
|
|
88
106
|
});
|
|
89
107
|
}
|
|
90
|
-
/**
|
|
91
|
-
|
|
108
|
+
/**
|
|
109
|
+
* What a cell is drawn with, of what its column is. A total, and a cell with no value, are
|
|
110
|
+
* drawn plain: no bar, no shade, no chart. A total of a column of dots alone keeps its scale,
|
|
111
|
+
* and stands on it as the tick the rows above are read against.
|
|
112
|
+
*/
|
|
113
|
+
function drawnWith(measured, cell, at) {
|
|
114
|
+
if (cell === null) return void 0;
|
|
115
|
+
return at.total && measured?.dot === void 0 ? void 0 : measured;
|
|
116
|
+
}
|
|
117
|
+
/** A value cell's number: with its bar, or alone (in a card, as an element of its own, to sit opposite its name). */
|
|
118
|
+
function figureOf(text, cell, at, how) {
|
|
92
119
|
if (how?.bar === true) return /* @__PURE__ */ jsx(Bar, {
|
|
93
120
|
text,
|
|
94
121
|
cell,
|
|
@@ -102,6 +129,59 @@ function valueBody(text, cell, at, how) {
|
|
|
102
129
|
children: text
|
|
103
130
|
}) : text;
|
|
104
131
|
}
|
|
132
|
+
const ARROW = {
|
|
133
|
+
up: "↑",
|
|
134
|
+
down: "↓"
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* How a value moved against the period before, after its number: an arrow and how far, in the
|
|
138
|
+
* colour of better or worse where the column says which is which, and the whole of it in words
|
|
139
|
+
* a pointer away and for a screen reader. A row that did not move keeps the room, so the
|
|
140
|
+
* numbers before it stay in line.
|
|
141
|
+
*/
|
|
142
|
+
function MovedMark({ moved }) {
|
|
143
|
+
if (moved === void 0) return /* @__PURE__ */ jsx("span", { className: "dd-table-moved" });
|
|
144
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
145
|
+
className: "dd-table-moved",
|
|
146
|
+
"data-way": moved.way,
|
|
147
|
+
...betterMark(moved.went),
|
|
148
|
+
title: moved.said,
|
|
149
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
150
|
+
"aria-hidden": "true",
|
|
151
|
+
children: [
|
|
152
|
+
ARROW[moved.way],
|
|
153
|
+
" ",
|
|
154
|
+
moved.size
|
|
155
|
+
]
|
|
156
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
157
|
+
className: "dd-sr-only",
|
|
158
|
+
children: moved.said
|
|
159
|
+
})]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** What a value cell holds: its number and bar, after the small chart of its buckets when the column draws them, and before how it moved. */
|
|
163
|
+
function valueBody(props) {
|
|
164
|
+
const { text, cell, column, at } = props;
|
|
165
|
+
const measured = at.measured.get(column.id);
|
|
166
|
+
const how = drawnWith(measured, cell, at);
|
|
167
|
+
const figure = figureOf(text, cell, at, how);
|
|
168
|
+
const course = how?.courses?.get(at.place);
|
|
169
|
+
const moved = measured?.moved;
|
|
170
|
+
if (course === void 0 && moved === void 0) return figure;
|
|
171
|
+
const vars = moved === void 0 ? void 0 : { "--dd-moved-chars": String(moved.chars) };
|
|
172
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
173
|
+
className: "dd-table-figure",
|
|
174
|
+
style: vars,
|
|
175
|
+
children: [
|
|
176
|
+
course === void 0 ? null : /* @__PURE__ */ jsx(Trend, {
|
|
177
|
+
course,
|
|
178
|
+
line: !addsUp(column)
|
|
179
|
+
}),
|
|
180
|
+
figure,
|
|
181
|
+
moved === void 0 ? null : /* @__PURE__ */ jsx(MovedMark, { moved: moved.rows.get(at.place) })
|
|
182
|
+
]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
105
185
|
/**
|
|
106
186
|
* Whether a cell of a column of changes is for the better or the worse, by its own value's
|
|
107
187
|
* sign, where the column says which way is better. None for no change, no value, or a column
|
|
@@ -138,9 +218,10 @@ function fullOn(text, props) {
|
|
|
138
218
|
function ValueCell(props) {
|
|
139
219
|
const { cell, column, at, mark } = props;
|
|
140
220
|
const Tag = at.heading ? "th" : "td";
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
221
|
+
const measured = at.measured.get(column.id);
|
|
222
|
+
const how = drawnWith(measured, cell, at);
|
|
223
|
+
const text = measured?.texts.get(at.place) ?? valueText(cell, column, at);
|
|
224
|
+
const shade = at.total ? void 0 : shadeOf(cell, how);
|
|
144
225
|
const went = wentOf(cell, column);
|
|
145
226
|
return /* @__PURE__ */ jsx(Tag, {
|
|
146
227
|
"data-numeric": "true",
|
|
@@ -156,7 +237,12 @@ function ValueCell(props) {
|
|
|
156
237
|
column,
|
|
157
238
|
at
|
|
158
239
|
}),
|
|
159
|
-
children: [valueBody(
|
|
240
|
+
children: [valueBody({
|
|
241
|
+
text,
|
|
242
|
+
cell,
|
|
243
|
+
column,
|
|
244
|
+
at
|
|
245
|
+
}), /* @__PURE__ */ jsx(WentWord, {
|
|
160
246
|
went,
|
|
161
247
|
messages: at.format.messages
|
|
162
248
|
})]
|
|
@@ -4,6 +4,11 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
// src/renderers/table-head.tsx
|
|
5
5
|
/** A column's name past this many characters breaks over lines; a shorter one keeps to one. */
|
|
6
6
|
const LONG_NAME = 16;
|
|
7
|
+
/** Which of a bar's two colours a column is drawn in, when it is the whole or the part of `display.parts`. */
|
|
8
|
+
const keyOf = (parts, at) => {
|
|
9
|
+
if (parts?.whole === at) return "whole";
|
|
10
|
+
return parts?.part === at ? "part" : void 0;
|
|
11
|
+
};
|
|
7
12
|
/** A column's name as a button that sorts by it, with an arrow for the eye: `aria-sort` says the way to a screen reader. */
|
|
8
13
|
function SortButton({ column, sort, onSort, messages }) {
|
|
9
14
|
return /* @__PURE__ */ jsxs("button", {
|
|
@@ -27,13 +32,14 @@ function Head(props) {
|
|
|
27
32
|
role: cards ? "rowgroup" : void 0,
|
|
28
33
|
children: /* @__PURE__ */ jsx("tr", {
|
|
29
34
|
role: cards ? "row" : void 0,
|
|
30
|
-
children: columns.map((column) => {
|
|
35
|
+
children: columns.map((column, at) => {
|
|
31
36
|
const way = sorts && sort?.id === column.id ? sort.way : void 0;
|
|
32
37
|
return /* @__PURE__ */ jsx("th", {
|
|
33
38
|
scope: "col",
|
|
34
39
|
role: cards ? "columnheader" : void 0,
|
|
35
40
|
"data-numeric": isNumeric(column),
|
|
36
41
|
"data-long": column.label.length > LONG_NAME ? "true" : void 0,
|
|
42
|
+
"data-key": keyOf(props.parts, at),
|
|
37
43
|
"aria-sort": way,
|
|
38
44
|
children: sorts ? /* @__PURE__ */ jsx(SortButton, {
|
|
39
45
|
...props,
|