@ruckc/truss-chart 1.48.0 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BarChart.svelte +36 -5
- package/dist/BarChart.svelte.d.ts +15 -0
- package/dist/ChartFrame.svelte +20 -3
- package/dist/ChartFrame.svelte.d.ts +13 -0
- package/dist/ColorScale.svelte +15 -2
- package/dist/ColorScale.svelte.d.ts +6 -0
- package/dist/DensityChart.svelte +115 -21
- package/dist/DensityChart.svelte.d.ts +57 -0
- package/dist/DonutChart.svelte +45 -7
- package/dist/DonutChart.svelte.d.ts +20 -0
- package/dist/Histogram.svelte +39 -5
- package/dist/Histogram.svelte.d.ts +17 -0
- package/dist/LineChart.svelte +44 -7
- package/dist/LineChart.svelte.d.ts +19 -0
- package/dist/ScatterChart.svelte +53 -9
- package/dist/ScatterChart.svelte.d.ts +23 -0
- package/dist/StatTile.svelte +39 -5
- package/dist/StatTile.svelte.d.ts +15 -0
- package/dist/index.d.ts +8 -0
- package/dist/labels.d.ts +6 -0
- package/dist/labels.js +23 -0
- package/package.json +1 -1
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
export type StatTileLabels = {
|
|
2
|
+
/** Start of the accessible name: the tile's label and its value. */
|
|
3
|
+
value: (label: string, value: string) => string;
|
|
4
|
+
/** Comparison text when `deltaLabel` is not set. */
|
|
5
|
+
vsPrevious: string;
|
|
6
|
+
/** Accessible text when the change is zero: `deltaLabel` is the comparison text. */
|
|
7
|
+
noChange: (deltaLabel: string) => string;
|
|
8
|
+
/** Accessible text for a change: its direction, its size in percent (a number, without the sign), the comparison text, and whether it is the good direction. */
|
|
9
|
+
change: (up: boolean, percent: string, deltaLabel: string, favourable: boolean) => string;
|
|
10
|
+
/** Accessible text for the trend line: how many values, the first and the last. */
|
|
11
|
+
trend: (count: number, from: string, to: string) => string;
|
|
12
|
+
};
|
|
1
13
|
type $$ComponentProps = {
|
|
2
14
|
label: string;
|
|
3
15
|
value: number | string;
|
|
@@ -5,6 +17,7 @@ type $$ComponentProps = {
|
|
|
5
17
|
format?: (n: number) => string;
|
|
6
18
|
/** Change vs the previous period, in percent (4.2 means +4.2%). */
|
|
7
19
|
delta?: number;
|
|
20
|
+
/** Comparison text next to the change (default: "vs previous"). */
|
|
8
21
|
deltaLabel?: string;
|
|
9
22
|
/** Which direction of change is good: picks the success or danger colour. The arrow and signed text carry the meaning without colour. */
|
|
10
23
|
deltaGoodDirection?: 'up' | 'down';
|
|
@@ -12,6 +25,8 @@ type $$ComponentProps = {
|
|
|
12
25
|
spark?: number[];
|
|
13
26
|
/** `'auto'` makes the tile a width-based size container: the value size and padding follow the tile's width (`cqi`, clamped to 20-56px), so it needs no fixed size in a grid cell; it ignores height so it never collapses. `'sm'` uses `--tr-text-xl` for the value and tighter padding. The value size can also be set from outside with the `--trc-stat-value-size` custom property (default 28px). */
|
|
14
27
|
size?: 'sm' | 'md' | 'auto';
|
|
28
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
29
|
+
labels?: Partial<StatTileLabels>;
|
|
15
30
|
};
|
|
16
31
|
declare const StatTile: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
17
32
|
type StatTile = ReturnType<typeof StatTile>;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,3 +11,11 @@ export { seriesColor, niceTicks, linear, gradientFrom } from './util.js';
|
|
|
11
11
|
export type { ScaleKind } from './util.js';
|
|
12
12
|
export type { Series, ScatterPoint, Band, ReferenceLine, ChartSelection } from './types.js';
|
|
13
13
|
export type { DensityPoint, DensityHighlight, DensityHover } from './density.js';
|
|
14
|
+
export type { BarChartLabels } from './BarChart.svelte';
|
|
15
|
+
export type { ColorScaleLabels } from './ColorScale.svelte';
|
|
16
|
+
export type { DensityChartLabels } from './DensityChart.svelte';
|
|
17
|
+
export type { DonutChartLabels } from './DonutChart.svelte';
|
|
18
|
+
export type { HistogramLabels } from './Histogram.svelte';
|
|
19
|
+
export type { LineChartLabels } from './LineChart.svelte';
|
|
20
|
+
export type { ScatterChartLabels } from './ScatterChart.svelte';
|
|
21
|
+
export type { StatTileLabels } from './StatTile.svelte';
|
package/dist/labels.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** One label: a string, or a function for a string with values (`(n: number) => \`${n} selected\``). That covers plurals and word order without an ICU dependency. */
|
|
2
|
+
export type LabelValue = string | ((...args: never[]) => string);
|
|
3
|
+
/** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
|
|
4
|
+
export declare function useLabels<T extends object>(component: string, defaults: T, prop: () => Partial<T> | undefined): T;
|
|
5
|
+
/** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
|
|
6
|
+
export declare function labelFor<T extends LabelValue>(component: string, key: string, fallback: T): T;
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
const KEY = Symbol.for('@ruckc/truss-ui:labels');
|
|
3
|
+
const STATE = Symbol.for('@ruckc/truss-ui:labels-config');
|
|
4
|
+
// What `configureLabels` set for a component. Read-only here (no copy of this file has to create the state), and `Object(undefined)` is `{}`.
|
|
5
|
+
const config = (component) => Object(Object(globalThis[STATE])[component]);
|
|
6
|
+
// The strongest defined value wins (layers run from the weakest to the strongest). This reader is written without branches on purpose
|
|
7
|
+
// (`filter`, `Object(x)`, no `?.` / `??` / `if`): it is copied into every package, and V8 coverage counts each short-circuit as a branch,
|
|
8
|
+
// so a copy would need a test under every combination of context and config to reach the per-file coverage floor.
|
|
9
|
+
const none = () => undefined;
|
|
10
|
+
const pick = (...layers) => layers.filter((v) => v !== undefined).at(-1);
|
|
11
|
+
/** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
|
|
12
|
+
export function useLabels(component, defaults, prop) {
|
|
13
|
+
const lookup = [getContext(KEY), none].filter(Boolean)[0];
|
|
14
|
+
const out = {};
|
|
15
|
+
for (const k of Object.keys(defaults))
|
|
16
|
+
Object.defineProperty(out, k, { enumerable: true, get: () => pick(labelFor(component, k, defaults[k]), Object(lookup(component))[k], Object(prop())[k]) });
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
|
|
20
|
+
export function labelFor(component, key, fallback) {
|
|
21
|
+
return pick(fallback, config(component)[key]);
|
|
22
|
+
}
|
|
23
|
+
// </reader>
|