@motionscript/charts 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +40 -0
- package/README.md +30 -16
- package/dist/bar-chart/bar-chart.d.ts +133 -242
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +378 -569
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +35 -41
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +93 -115
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +50 -70
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +156 -210
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -2
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +3 -3
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +3 -3
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-XROBIRQK.js +2 -0
- package/dist/browser/chunks/chunk-XROBIRQK.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +8 -6
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +8 -6
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +44 -0
- package/dist/kit/cartesian.d.ts.map +1 -0
- package/dist/kit/cartesian.js +59 -0
- package/dist/kit/cartesian.js.map +1 -0
- package/dist/kit/chart-border.d.ts +10 -11
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +15 -32
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -21
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +33 -90
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +123 -64
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +129 -154
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +17 -0
- package/dist/kit/entries.d.ts.map +1 -0
- package/dist/kit/entries.js +19 -0
- package/dist/kit/entries.js.map +1 -0
- package/dist/kit/motion.d.ts +48 -0
- package/dist/kit/motion.d.ts.map +1 -0
- package/dist/kit/motion.js +63 -0
- package/dist/kit/motion.js.map +1 -0
- package/dist/kit/paints.d.ts +10 -0
- package/dist/kit/paints.d.ts.map +1 -0
- package/dist/kit/paints.js +12 -0
- package/dist/kit/paints.js.map +1 -0
- package/dist/kit/shared.d.ts +31 -3
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +42 -3
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +48 -61
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +97 -132
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +60 -77
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +100 -121
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +32 -33
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +31 -65
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +58 -64
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +94 -123
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -2
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +1 -1
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +156 -319
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +403 -663
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +3 -3
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +3 -3
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -2
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +108 -132
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +200 -271
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +84 -31
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +93 -107
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +160 -131
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +333 -391
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +2 -2
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +2 -2
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +415 -701
- package/src/bar-chart/category-axis.ts +95 -110
- package/src/bar-chart/chart-bars.ts +178 -200
- package/src/bar-chart/index.ts +2 -2
- package/src/bar-chart/shared.ts +3 -3
- package/src/engine.ts +8 -6
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +22 -33
- package/src/kit/chart-canvas.ts +44 -79
- package/src/kit/chart-legend.ts +173 -189
- package/src/kit/entries.ts +20 -0
- package/src/kit/motion.ts +90 -0
- package/src/kit/paints.ts +15 -0
- package/src/kit/shared.ts +52 -3
- package/src/kit/vertical-axis.ts +110 -140
- package/src/line-chart/chart-line.ts +102 -154
- package/src/line-chart/chart-region.ts +35 -80
- package/src/line-chart/horizontal-axis.ts +101 -152
- package/src/line-chart/index.ts +2 -2
- package/src/line-chart/line-chart.ts +449 -825
- package/src/line-chart/shared.ts +3 -3
- package/src/nodes.ts +8 -10
- package/src/pie-chart/index.ts +2 -2
- package/src/pie-chart/pie-chart.ts +221 -311
- package/src/pie-chart/pie-legend.ts +124 -114
- package/src/pie-chart/pie-ring.ts +386 -473
- package/src/pie-chart/shared.ts +2 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js +0 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-canvas.js","sourceRoot":"","sources":["../../src/kit/chart-canvas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chart-canvas.js","sourceRoot":"","sources":["../../src/kit/chart-canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,GAWV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,GAEf,MAAM,UAAU,CAAA;AA2BjB,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,EAAE,CACtC,KAAK,CAAC,MAAM,CAA2B,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAA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\n strokeOps,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps,\r\n type Shadow,\r\n type ShadowResolved,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"./entries\"\r\nimport { loadPaints } from \"./paints\"\r\nimport {\r\n DEFAULT_PLOT_AREA,\r\n DEFAULT_X_AXIS,\r\n DEFAULT_Y_AXIS,\r\n type Range,\r\n} from \"./shared\"\r\n\r\nexport interface ChartCanvasProps extends Node2DProps {\r\n /** Fill of the plot panel behind the marks. */\r\n fill: Fill\r\n /** Drop shadow of the panel. Default none. */\r\n shadow: Shadow\r\n /** Stroke of the vertical grid lines (one per {@link xMarkers}). */\r\n xGridStroke: Stroke\r\n /** Stroke of the horizontal grid lines (one per {@link yMarkers}). */\r\n yGridStroke: Stroke\r\n /**\r\n * Data-unit x positions to draw a vertical grid line at — one per horizontal\r\n * axis marker, so a line lands under every marker regardless of spacing.\r\n * Positions at (or past) an {@link xExtent} edge coincide with the border and\r\n * are skipped. Pass an empty list for a chart whose horizontal axis is\r\n * categorical and so has no numeric position to rule at.\r\n */\r\n xMarkers: number[]\r\n /** Data-unit y positions to draw a horizontal grid line at. */\r\n yMarkers: number[]\r\n /** `[min, max]` of the horizontal scale — maps {@link xMarkers} into the panel. */\r\n xExtent: Range\r\n /** `[min, max]` of the vertical scale — maps {@link yMarkers} into the panel. */\r\n yExtent: Range\r\n}\r\n\r\nconst strokeEntry = (initial: Stroke) =>\r\n Types.custom<Stroke, StrokeResolved[]>(initial, { resolve: strokeOps.resolve, lerp: strokeOps.lerp })\r\n\r\n/**\r\n * The plot **backdrop** of a cartesian chart: a filled panel with a grid of\r\n * faint lines spanning both directions across it, sized from its box and centred\r\n * on its origin.\r\n *\r\n * The thick frame is a **separate** {@link ChartBorder} node so it can be drawn\r\n * *over* the marks while this panel sits under them. Grid lines are placed from\r\n * the axis marker positions (in data units) mapped into the panel through\r\n * {@link ChartCanvasProps.xExtent}/`yExtent` — so each line lands under its\r\n * marker whether or not the markers are evenly spaced.\r\n */\r\nexport const ChartCanvas = component2d({\r\n key: \"chartCanvas\",\r\n state: {\r\n fill: Types.custom<Fill, FillResolved[]>(DEFAULT_PLOT_AREA.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),\r\n shadow: Types.custom<Shadow, ShadowResolved[]>(DEFAULT_PLOT_AREA.shadow, { resolve: shadowOps.resolve, lerp: shadowOps.lerp }),\r\n xGridStroke: strokeEntry(DEFAULT_X_AXIS.lineStyle),\r\n yGridStroke: strokeEntry(DEFAULT_Y_AXIS.lineStyle),\r\n xMarkers: fresh<number[]>(() => []),\r\n yMarkers: fresh<number[]>(() => []),\r\n xExtent: fresh<Range>(() => [0, 1]),\r\n yExtent: fresh<Range>(() => [0, 1]),\r\n },\r\n // The grid strokes are named past the conventional slots, so they are named here.\r\n load: (loader, state) =>\r\n loadPaints(loader, { fills: [state.fill], shadows: [state.shadow], strokes: [state.xGridStroke, state.yGridStroke] }),\r\n render: (ctx, state) => {\r\n const { width: W, height: H } = ctx.size\r\n if (W <= 0 || H <= 0) return\r\n\r\n // Plot panel, centred on the origin (node space is y-up, origin centre).\r\n ctx.draw(new Graphics2D().rect({ x: 0, y: 0, width: W, height: H }).shadow(state.shadow).fill(state.fill))\r\n\r\n const [xMin, xMax] = state.xExtent\r\n const [yMin, yMax] = state.yExtent\r\n // Fraction of a marker across its extent; guard a zero-width extent.\r\n const xFrac = (v: number) => (xMax <= xMin ? 0 : (v - xMin) / (xMax - xMin))\r\n const yFrac = (v: number) => (yMax <= yMin ? 0 : (v - yMin) / (yMax - yMin))\r\n // Skip markers landing on (or outside) the edges — they'd sit under the border.\r\n const interior = (f: number) => f > 1e-6 && f < 1 - 1e-6\r\n\r\n const xStroke = state.xGridStroke[0]\r\n if (xStroke) {\r\n const xGrid = new Graphics2D()\r\n for (const v of state.xMarkers) {\r\n const f = xFrac(v)\r\n if (!interior(f)) continue\r\n xGrid.rect({ x: -W / 2 + f * W, y: 0, width: xStroke.weight, height: H })\r\n }\r\n ctx.draw(xGrid.fill(xStroke.fill))\r\n }\r\n\r\n const yStroke = state.yGridStroke[0]\r\n if (yStroke) {\r\n const yGrid = new Graphics2D()\r\n for (const v of state.yMarkers) {\r\n const f = yFrac(v)\r\n if (!interior(f)) continue\r\n yGrid.rect({ x: 0, y: -H / 2 + f * H, width: W, height: yStroke.weight })\r\n }\r\n ctx.draw(yGrid.fill(yStroke.fill))\r\n }\r\n },\r\n})\r\n\r\nexport type ChartCanvas = NodeOf<typeof ChartCanvas>\r\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Seekable } from "@motionscript/sdk/component";
|
|
1
|
+
import { type Fill, type NodeOf, type RectProps, type Alignment as _Alignment, type CornerRadiusResolved as _CornerRadiusResolved, type CornerStyleResolved as _CornerStyleResolved, type FillResolved as _FillResolved, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type RectCornerRadius as _RectCornerRadius, type RectCornerStyle as _RectCornerStyle, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved, type Vector2 as _Vector2 } from "@motionscript/sdk";
|
|
3
2
|
import { type ChartSeries, type LegendConfig } from "./shared.js";
|
|
4
3
|
export interface ChartLegendProps extends RectProps {
|
|
5
4
|
/**
|
|
6
5
|
* One entry per series: legend `label`, its `enabled` default, and — through
|
|
7
6
|
* {@link ChartLegendProps.swatches} — the colour its chip is painted. A series
|
|
8
7
|
* that starts enabled (the default) is added to the row up front; one that
|
|
9
|
-
* starts `false` is hidden until a later
|
|
8
|
+
* starts `false` is hidden until a later `showSeries`.
|
|
10
9
|
*/
|
|
11
10
|
series: ChartSeries[];
|
|
12
11
|
/**
|
|
@@ -25,81 +24,141 @@ export interface ChartLegendProps extends RectProps {
|
|
|
25
24
|
* with a rounded colour swatch; only the swatch carries the series colour, the
|
|
26
25
|
* caption reads in the legend's neutral ink.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
27
|
+
* `showSeries`/`hideSeries` flip a series on or off — showing one grows its
|
|
28
|
+
* entry back in at its stable series position, hiding one shrinks it away. So
|
|
29
|
+
* the row only ever shows the currently-enabled series, in series order, and
|
|
30
|
+
* closes the gap when one leaves.
|
|
32
31
|
*
|
|
33
32
|
* This node *is* the row, so the parent places it (centred below the chart) and
|
|
34
33
|
* it hugs its entries.
|
|
35
34
|
*/
|
|
36
|
-
export declare
|
|
37
|
-
series: ChartSeries[]
|
|
38
|
-
swatches: Fill[]
|
|
39
|
-
legend: LegendConfig
|
|
40
|
-
/** One entry per series. **Every** entry is a child — see {@link reveal}. */
|
|
41
|
-
private items;
|
|
35
|
+
export declare const ChartLegend: import("@motionscript/sdk").Component<"chartLegend", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
36
|
+
readonly series: import("@motionscript/sdk").Type<ChartSeries[], ChartSeries[], false>;
|
|
37
|
+
readonly swatches: import("@motionscript/sdk").Type<Fill[], Fill[], false>;
|
|
38
|
+
readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
|
|
42
39
|
/**
|
|
43
40
|
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
44
41
|
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
45
42
|
* natural size.
|
|
46
43
|
*
|
|
47
|
-
* This replaces adding and removing the entry from the row
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* getting there means having run the add. Collapsed-but-present is the same
|
|
52
|
-
* picture reached by a route that *is* a function of `t`.
|
|
53
|
-
*
|
|
54
|
-
* One array in one slot, because the count is the series count, which is data.
|
|
55
|
-
* It is replaced rather than mutated: a write is a slot write, so the timeline
|
|
56
|
-
* sees it and restores it to the authored reveal before the command starts
|
|
57
|
-
* and after a seek back. The entries' props are bound to it, so writing it
|
|
58
|
-
* still moves the layout.
|
|
59
|
-
*/
|
|
60
|
-
private reveal;
|
|
61
|
-
constructor(props?: NodeConfig<ChartLegend, ChartLegendProps>);
|
|
62
|
-
/** One entry: the series caption beside its colour swatch. */
|
|
63
|
-
private buildItem;
|
|
64
|
-
/** True if series `index` is showing at all — see {@link reveal}. */
|
|
65
|
-
isEnabled(index: number): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Grow series `index`'s entry back in at its series-order position, the
|
|
68
|
-
* siblings sliding over to make room.
|
|
69
|
-
*
|
|
70
|
-
* A reveal tween rather than an animated `addChildAt`. The entry never left —
|
|
71
|
-
* see {@link reveal} — so there is no add to have happened, and the whole
|
|
72
|
-
* thing is a function of `t`.
|
|
73
|
-
*/
|
|
74
|
-
showSeries(args: CommandArgs<{
|
|
75
|
-
index: number;
|
|
76
|
-
}>): Seekable;
|
|
77
|
-
/**
|
|
78
|
-
* Shrink series `index`'s entry away, the gap closing behind it — the mirror
|
|
79
|
-
* of {@link showSeries}.
|
|
44
|
+
* This replaces adding and removing the entry from the row: a command is
|
|
45
|
+
* asked what it looks like at a time, and "is this node a child" is not a
|
|
46
|
+
* value a time can produce. Collapsed-but-present is the same picture reached
|
|
47
|
+
* by a route that *is* a function of `t`.
|
|
80
48
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
49
|
+
readonly reveal: import("@motionscript/sdk").Type<number[] | Readonly<Record<number, number>>, number[], false>;
|
|
50
|
+
readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
|
|
51
|
+
readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
|
|
52
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
53
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
54
|
+
readonly wrap: boolean;
|
|
55
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
56
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
57
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
58
|
+
readonly fill: import("@motionscript/sdk").Attribute<Fill, _FillResolved[]>;
|
|
59
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
60
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
61
|
+
readonly overlay: import("@motionscript/sdk").Attribute<Fill, _FillResolved[]>;
|
|
62
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
63
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
64
|
+
}>, {
|
|
65
|
+
readonly showSeries: {
|
|
66
|
+
readonly index: import("@motionscript/sdk").Type<number, number, false>;
|
|
67
|
+
};
|
|
68
|
+
readonly hideSeries: {
|
|
69
|
+
readonly index: import("@motionscript/sdk").Type<number, number, false>;
|
|
70
|
+
};
|
|
71
|
+
readonly spotlightSeries: {
|
|
72
|
+
readonly index: import("@motionscript/sdk").Type<number, number, false>;
|
|
73
|
+
};
|
|
74
|
+
readonly fillTo: readonly ["fill"];
|
|
75
|
+
readonly strokeTo: readonly ["stroke"];
|
|
76
|
+
readonly shadowTo: readonly ["shadow"];
|
|
77
|
+
readonly overlayTo: readonly ["overlay"];
|
|
78
|
+
readonly progressTo: readonly ["start", "end"];
|
|
79
|
+
readonly flash: {
|
|
80
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
81
|
+
};
|
|
82
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
83
|
+
readonly series: import("@motionscript/sdk").Type<ChartSeries[], ChartSeries[], false>;
|
|
84
|
+
readonly swatches: import("@motionscript/sdk").Type<Fill[], Fill[], false>;
|
|
85
|
+
readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
|
|
84
86
|
/**
|
|
85
|
-
*
|
|
87
|
+
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
88
|
+
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
89
|
+
* natural size.
|
|
86
90
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
+
* This replaces adding and removing the entry from the row: a command is
|
|
92
|
+
* asked what it looks like at a time, and "is this node a child" is not a
|
|
93
|
+
* value a time can produce. Collapsed-but-present is the same picture reached
|
|
94
|
+
* by a route that *is* a function of `t`.
|
|
91
95
|
*/
|
|
92
|
-
|
|
96
|
+
readonly reveal: import("@motionscript/sdk").Type<number[] | Readonly<Record<number, number>>, number[], false>;
|
|
97
|
+
readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
|
|
98
|
+
readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
|
|
99
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
100
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
101
|
+
readonly wrap: boolean;
|
|
102
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
103
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
104
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
105
|
+
readonly fill: import("@motionscript/sdk").Attribute<Fill, _FillResolved[]>;
|
|
106
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
107
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
108
|
+
readonly overlay: import("@motionscript/sdk").Attribute<Fill, _FillResolved[]>;
|
|
109
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
110
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
111
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
112
|
+
readonly series: import("@motionscript/sdk").Type<ChartSeries[], ChartSeries[], false>;
|
|
113
|
+
readonly swatches: import("@motionscript/sdk").Type<Fill[], Fill[], false>;
|
|
114
|
+
readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
|
|
93
115
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
116
|
+
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
117
|
+
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
118
|
+
* natural size.
|
|
97
119
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
120
|
+
* This replaces adding and removing the entry from the row: a command is
|
|
121
|
+
* asked what it looks like at a time, and "is this node a child" is not a
|
|
122
|
+
* value a time can produce. Collapsed-but-present is the same picture reached
|
|
123
|
+
* by a route that *is* a function of `t`.
|
|
100
124
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
125
|
+
readonly reveal: import("@motionscript/sdk").Type<number[] | Readonly<Record<number, number>>, number[], false>;
|
|
126
|
+
readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
|
|
127
|
+
readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
|
|
128
|
+
readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
|
|
129
|
+
readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
|
|
130
|
+
readonly wrap: boolean;
|
|
131
|
+
readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
132
|
+
readonly columns: import("@motionscript/sdk").Type<number, number, false>;
|
|
133
|
+
readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
|
|
134
|
+
readonly fill: import("@motionscript/sdk").Attribute<Fill, _FillResolved[]>;
|
|
135
|
+
readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
136
|
+
readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
137
|
+
readonly overlay: import("@motionscript/sdk").Attribute<Fill, _FillResolved[]>;
|
|
138
|
+
readonly start: import("@motionscript/sdk").Type<number, number, false>;
|
|
139
|
+
readonly end: import("@motionscript/sdk").Type<number, number, false>;
|
|
140
|
+
}>, {
|
|
141
|
+
readonly showSeries: {
|
|
142
|
+
readonly index: import("@motionscript/sdk").Type<number, number, false>;
|
|
143
|
+
};
|
|
144
|
+
readonly hideSeries: {
|
|
145
|
+
readonly index: import("@motionscript/sdk").Type<number, number, false>;
|
|
146
|
+
};
|
|
147
|
+
readonly spotlightSeries: {
|
|
148
|
+
readonly index: import("@motionscript/sdk").Type<number, number, false>;
|
|
149
|
+
};
|
|
150
|
+
readonly fillTo: readonly ["fill"];
|
|
151
|
+
readonly strokeTo: readonly ["stroke"];
|
|
152
|
+
readonly shadowTo: readonly ["shadow"];
|
|
153
|
+
readonly overlayTo: readonly ["overlay"];
|
|
154
|
+
readonly progressTo: readonly ["start", "end"];
|
|
155
|
+
readonly flash: {
|
|
156
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
157
|
+
};
|
|
158
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
159
|
+
/** Whether series `index` is showing at all on `legend`. */
|
|
160
|
+
export declare function legendShows(legend: {
|
|
161
|
+
readonly reveal: readonly number[];
|
|
162
|
+
}, index: number): boolean;
|
|
163
|
+
export type ChartLegend = NodeOf<typeof ChartLegend>;
|
|
105
164
|
//# sourceMappingURL=chart-legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-legend.d.ts","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"chart-legend.d.ts","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,IAAI,EACT,KAAK,MAAM,EACX,KAAK,SAAS,EAEd,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,oBAAoB,IAAI,qBAAqB,EAClD,KAAK,mBAAmB,IAAI,oBAAoB,EAChD,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,gBAAgB,IAAI,iBAAiB,EAC1C,KAAK,eAAe,IAAI,gBAAgB,EACxC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,OAAO,IAAI,QAAQ,EACzB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD;;;;;OAKG;IACH,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB;;;;;OAKG;IACH,QAAQ,EAAE,IAAI,EAAE,CAAA;IAChB,oFAAoF;IACpF,MAAM,EAAE,YAAY,CAAA;CACrB;AAsCD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW;;;;IAOpB;;;;;;;;;OASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IATH;;;;;;;;;OASG;;;;;;;;;;;;;;;;;;;;IATH;;;;;;;;;OASG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAuFL,CAAA;AAWF,4DAA4D;AAC5D,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAElG;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA"}
|
package/dist/kit/chart-legend.js
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Rect, Text, command, easeOut, property, textOps, } from "@motionscript/sdk";
|
|
8
|
-
import { drive, hold, together } from "@motionscript/sdk/component";
|
|
1
|
+
import { Flow, Paint, Rect, Shapes, Text, Types, component2d, textOps, } from "@motionscript/sdk";
|
|
2
|
+
import { fresh } from "./entries.js";
|
|
3
|
+
import { frameEase } from "./motion.js";
|
|
9
4
|
import { DEFAULT_LEGEND, SPOTLIGHT_DIM, } from "./shared.js";
|
|
5
|
+
/** A row's entries are a `Rect`'s: paint, the flow of its children, its corners. */
|
|
6
|
+
const row = { ...Paint.state, ...Flow.state, ...Shapes.corners };
|
|
10
7
|
/**
|
|
11
|
-
* One legend entry. It hugs its caption and swatch; `shown` scales that width
|
|
12
|
-
* nothing to the whole of it.
|
|
8
|
+
* One legend entry. It hugs its caption and swatch; `shown` scales that width
|
|
9
|
+
* from nothing to the whole of it.
|
|
13
10
|
*
|
|
14
11
|
* The width is taken from the content on every measure, at any reveal, so a frame
|
|
15
12
|
* never depends on whether the entry was once seen fully shown. A collapse needs a
|
|
16
13
|
* number to scale, and `"hug"` is not one until something measures it — this is
|
|
17
14
|
* the something.
|
|
18
15
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const LegendEntry = component2d({
|
|
17
|
+
key: "legendEntry",
|
|
18
|
+
state: { ...row, shown: Types.number(1) },
|
|
19
|
+
commands: { ...Paint.commands },
|
|
20
|
+
measure: (measurer, state, children) => {
|
|
21
|
+
const size = Flow.measure(measurer, state, children, Paint.inset(state));
|
|
22
|
+
return state.shown >= 1 ? size : { ...size, width: state.shown * size.width };
|
|
23
|
+
},
|
|
24
|
+
layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
|
|
25
|
+
render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* How far each entry is shown, written whole (a document, a `set`) or one
|
|
29
|
+
* entry at a time (a command, as `{ [index]: reveal }`), which leaves the others
|
|
30
|
+
* as the frame left them — so two series moving at once each move their own.
|
|
31
|
+
*/
|
|
32
|
+
function revealOf(value, previous) {
|
|
33
|
+
if (Array.isArray(value))
|
|
34
|
+
return value;
|
|
35
|
+
const next = [...(previous ?? [])];
|
|
36
|
+
for (const [index, reveal] of Object.entries(value))
|
|
37
|
+
next[Number(index)] = reveal;
|
|
38
|
+
return next;
|
|
30
39
|
}
|
|
31
40
|
/**
|
|
32
41
|
* The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out
|
|
@@ -34,155 +43,121 @@ class LegendEntry extends Rect {
|
|
|
34
43
|
* with a rounded colour swatch; only the swatch carries the series colour, the
|
|
35
44
|
* caption reads in the legend's neutral ink.
|
|
36
45
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
46
|
+
* `showSeries`/`hideSeries` flip a series on or off — showing one grows its
|
|
47
|
+
* entry back in at its stable series position, hiding one shrinks it away. So
|
|
48
|
+
* the row only ever shows the currently-enabled series, in series order, and
|
|
49
|
+
* closes the gap when one leaves.
|
|
41
50
|
*
|
|
42
51
|
* This node *is* the row, so the parent places it (centred below the chart) and
|
|
43
52
|
* it hugs its entries.
|
|
44
53
|
*/
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
export const ChartLegend = component2d({
|
|
55
|
+
key: "chartLegend",
|
|
56
|
+
state: {
|
|
57
|
+
...row,
|
|
58
|
+
series: fresh(() => []),
|
|
59
|
+
swatches: fresh(() => []),
|
|
60
|
+
legend: Types.custom(DEFAULT_LEGEND),
|
|
61
|
+
/**
|
|
62
|
+
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
63
|
+
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
64
|
+
* natural size.
|
|
65
|
+
*
|
|
66
|
+
* This replaces adding and removing the entry from the row: a command is
|
|
67
|
+
* asked what it looks like at a time, and "is this node a child" is not a
|
|
68
|
+
* value a time can produce. Collapsed-but-present is the same picture reached
|
|
69
|
+
* by a route that *is* a function of `t`.
|
|
70
|
+
*/
|
|
71
|
+
reveal: fresh(() => [], { resolve: revealOf }),
|
|
72
|
+
},
|
|
73
|
+
// This node *is* the row, so the direction is its own answer. It has to be
|
|
74
|
+
// stated — a `Rect` given no flow lays its children out `freeform`, which
|
|
75
|
+
// stacks every entry on the same spot. The gap and padding are the theme's.
|
|
76
|
+
defaults: {
|
|
77
|
+
flow: "horizontal",
|
|
78
|
+
width: "hug",
|
|
79
|
+
height: "hug",
|
|
80
|
+
gap: (state) => state.legend.itemGap,
|
|
81
|
+
padding: (state) => state.legend.padding,
|
|
82
|
+
reveal: (state) => state.series.map((s) => ((s.enabled ?? true) ? 1 : 0)),
|
|
83
|
+
},
|
|
84
|
+
// One entry per series, in series order, every one a child for good: order is
|
|
85
|
+
// fixed rather than depending on which siblings happen to be shown, so an entry
|
|
86
|
+
// always comes back where it belongs.
|
|
87
|
+
children: (state) => {
|
|
88
|
+
const marker = state.legend.markerStyle;
|
|
89
|
+
return state.series.map((series, index) => LegendEntry({
|
|
57
90
|
flow: "horizontal",
|
|
58
|
-
align: "center",
|
|
59
|
-
width: "hug",
|
|
60
|
-
height: "hug",
|
|
61
|
-
});
|
|
62
|
-
// Structure is one entry per series, so it's composed here from the resolved
|
|
63
|
-
// props super() applied. Fixed row geometry last, so it wins over super().
|
|
64
|
-
this.set({ gap: this.legend.itemGap, padding: this.legend.padding });
|
|
65
|
-
this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0));
|
|
66
|
-
this.items = this.series.map((s, i) => this.buildItem(s, i));
|
|
67
|
-
// All of them, in series order. Order is now fixed rather than depending on
|
|
68
|
-
// which siblings happen to be shown, so an entry always comes back where it
|
|
69
|
-
// belongs and `insertionIndex` has nothing left to compute.
|
|
70
|
-
for (const item of this.items)
|
|
71
|
-
this.add(item);
|
|
72
|
-
}
|
|
73
|
-
/** One entry: the series caption beside its colour swatch. */
|
|
74
|
-
buildItem(series, index) {
|
|
75
|
-
const marker = this.legend.markerStyle;
|
|
76
|
-
const item = new LegendEntry({ flow: "horizontal",
|
|
77
91
|
gap: 12,
|
|
78
92
|
align: "center",
|
|
79
|
-
// Bound to the reveal, so showing and hiding is a number moving rather
|
|
80
|
-
// than a child arriving and leaving. The width follows it in `measure`.
|
|
81
93
|
width: "hug",
|
|
82
|
-
opacity: () => this.reveal[index] ?? 0,
|
|
83
94
|
height: "hug",
|
|
95
|
+
// Bound to the reveal, so showing and hiding is a number moving rather
|
|
96
|
+
// than a child arriving and leaving. The width follows it in `measure`,
|
|
97
|
+
// and the flanking gap closes with the entry rather than snapping.
|
|
98
|
+
opacity: () => state.reveal[index] ?? 0,
|
|
99
|
+
gapScale: () => state.reveal[index] ?? 0,
|
|
100
|
+
shown: () => state.reveal[index] ?? 0,
|
|
84
101
|
children: [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
text: series.label,
|
|
88
|
-
}),
|
|
89
|
-
new Rect({
|
|
102
|
+
Text({ ...textOps.styleProps(state.legend.textStyle), text: series.label }),
|
|
103
|
+
Rect({
|
|
90
104
|
width: marker.width,
|
|
91
105
|
height: marker.height,
|
|
92
106
|
cornerRadius: marker.borderRadius,
|
|
93
|
-
fill:
|
|
107
|
+
fill: state.swatches[index] ?? "white",
|
|
94
108
|
stroke: marker.stroke,
|
|
95
109
|
shadow: marker.shadow,
|
|
96
110
|
}),
|
|
97
111
|
],
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that
|
|
149
|
-
* one back to full — the legend half of a chart's `spotlightSeries`. Entries
|
|
150
|
-
* stay in place; only their opacity moves, so the row doesn't reflow.
|
|
151
|
-
*
|
|
152
|
-
* Only the currently-shown entries are touched — a hidden series' entry is
|
|
153
|
-
* left as {@link hideSeries} left it.
|
|
154
|
-
*/
|
|
155
|
-
spotlightSeries(args) {
|
|
156
|
-
const { index = 0 } = args.data ?? {};
|
|
157
|
-
const duration = args.duration ?? 0.35;
|
|
158
|
-
const easing = args.easing ?? easeOut();
|
|
159
|
-
// Opacity only, on entries that are already in the row — no membership
|
|
160
|
-
// changes, so unlike {@link showSeries} this is a plain function of `t`.
|
|
161
|
-
return together(...this.items
|
|
162
|
-
.map((item, i) => ({ item, i }))
|
|
163
|
-
.filter(({ i }) => this.isEnabled(i))
|
|
164
|
-
.map(({ item, i }) => item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })));
|
|
165
|
-
}
|
|
112
|
+
}));
|
|
113
|
+
},
|
|
114
|
+
commands: {
|
|
115
|
+
...Paint.commands,
|
|
116
|
+
/**
|
|
117
|
+
* Grow series `index`'s entry back in at its series-order position, the
|
|
118
|
+
* siblings sliding over to make room. A reveal tween rather than an animated
|
|
119
|
+
* `addChildAt`: the entry never left, so the whole thing is a function of `t`.
|
|
120
|
+
*/
|
|
121
|
+
showSeries: {
|
|
122
|
+
args: { index: Types.number(0, { min: 0, step: 1 }) },
|
|
123
|
+
// An index that is not a series takes its slot and moves nothing.
|
|
124
|
+
run: (timeline, state) => (timeline.args.index in state.series
|
|
125
|
+
? timeline.animate(revealFrame(state, timeline.args.index, 1, frameEase(timeline)))
|
|
126
|
+
: timeline.wait(timeline.duration)),
|
|
127
|
+
},
|
|
128
|
+
/** Shrink series `index`'s entry away, the gap closing behind it — the mirror of `showSeries`. */
|
|
129
|
+
hideSeries: {
|
|
130
|
+
args: { index: Types.number(0, { min: 0, step: 1 }) },
|
|
131
|
+
run: (timeline, state) => (timeline.args.index in state.series
|
|
132
|
+
? timeline.animate(revealFrame(state, timeline.args.index, 0, frameEase(timeline)))
|
|
133
|
+
: timeline.wait(timeline.duration)),
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that
|
|
137
|
+
* one back to full — the legend half of a chart's `spotlightSeries`. Entries
|
|
138
|
+
* stay in place; only their opacity moves, so the row doesn't reflow. Only
|
|
139
|
+
* the entries shown when it is built are touched: a hidden series' entry is
|
|
140
|
+
* left as `hideSeries` left it.
|
|
141
|
+
*/
|
|
142
|
+
spotlightSeries: {
|
|
143
|
+
args: { index: Types.number(0, { min: 0, step: 1 }) },
|
|
144
|
+
run: (timeline, state, children) => timeline.together(children.flatMap((entry, i) => (state.reveal[i] ?? 0) > 0 ? [entry.to({ opacity: i === timeline.args.index ? 1 : SPOTLIGHT_DIM })] : [])),
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
|
|
148
|
+
layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
|
|
149
|
+
render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* One entry's reveal ramping to `target` from where the command finds it — so a
|
|
153
|
+
* hide that follows a show starts where the show left it.
|
|
154
|
+
*/
|
|
155
|
+
function revealFrame(state, index, target, ease) {
|
|
156
|
+
const from = state.reveal[index] ?? 0;
|
|
157
|
+
return (t) => ({ reveal: { [index]: from + (target - from) * ease(t) } });
|
|
158
|
+
}
|
|
159
|
+
/** Whether series `index` is showing at all on `legend`. */
|
|
160
|
+
export function legendShows(legend, index) {
|
|
161
|
+
return (legend.reveal[index] ?? 0) > 0;
|
|
166
162
|
}
|
|
167
|
-
__decorate([
|
|
168
|
-
property({ default: () => [] })
|
|
169
|
-
], ChartLegend.prototype, "series", void 0);
|
|
170
|
-
__decorate([
|
|
171
|
-
property({ default: () => [] })
|
|
172
|
-
], ChartLegend.prototype, "swatches", void 0);
|
|
173
|
-
__decorate([
|
|
174
|
-
property({ default: DEFAULT_LEGEND })
|
|
175
|
-
], ChartLegend.prototype, "legend", void 0);
|
|
176
|
-
__decorate([
|
|
177
|
-
property({ default: () => [] })
|
|
178
|
-
], ChartLegend.prototype, "reveal", void 0);
|
|
179
|
-
__decorate([
|
|
180
|
-
command()
|
|
181
|
-
], ChartLegend.prototype, "showSeries", null);
|
|
182
|
-
__decorate([
|
|
183
|
-
command()
|
|
184
|
-
], ChartLegend.prototype, "hideSeries", null);
|
|
185
|
-
__decorate([
|
|
186
|
-
command()
|
|
187
|
-
], ChartLegend.prototype, "spotlightSeries", null);
|
|
188
163
|
//# sourceMappingURL=chart-legend.js.map
|