@motionscript/charts 0.0.0-stage → 0.1.0-alpha.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 +5 -0
- package/LICENSE +201 -0
- package/dist/bar-chart/bar-chart.d.ts +286 -0
- package/dist/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/bar-chart/bar-chart.js +610 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/category-axis.d.ts +77 -0
- package/dist/bar-chart/category-axis.d.ts.map +1 -0
- package/dist/bar-chart/category-axis.js +141 -0
- package/dist/bar-chart/category-axis.js.map +1 -0
- package/dist/bar-chart/chart-bars.d.ts +149 -0
- package/dist/bar-chart/chart-bars.d.ts.map +1 -0
- package/dist/bar-chart/chart-bars.js +236 -0
- package/dist/bar-chart/chart-bars.js.map +1 -0
- package/dist/bar-chart/index.d.ts +16 -0
- package/dist/bar-chart/index.d.ts.map +1 -0
- package/dist/bar-chart/index.js +12 -0
- package/dist/bar-chart/index.js.map +1 -0
- package/dist/bar-chart/shared.d.ts +146 -0
- package/dist/bar-chart/shared.d.ts.map +1 -0
- package/dist/bar-chart/shared.js +182 -0
- package/dist/bar-chart/shared.js.map +1 -0
- package/dist/browser/chunks/chunk-ZMBOBHYL.js +2 -0
- package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +12 -0
- package/dist/engine.d.ts +27 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +27 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/chart-border.d.ts +28 -0
- package/dist/kit/chart-border.d.ts.map +1 -0
- package/dist/kit/chart-border.js +45 -0
- package/dist/kit/chart-border.js.map +1 -0
- package/dist/kit/chart-canvas.d.ts +56 -0
- package/dist/kit/chart-canvas.d.ts.map +1 -0
- package/dist/kit/chart-canvas.js +125 -0
- package/dist/kit/chart-canvas.js.map +1 -0
- package/dist/kit/chart-legend.d.ts +126 -0
- package/dist/kit/chart-legend.d.ts.map +1 -0
- package/dist/kit/chart-legend.js +212 -0
- package/dist/kit/chart-legend.js.map +1 -0
- package/dist/kit/shared.d.ts +251 -0
- package/dist/kit/shared.d.ts.map +1 -0
- package/dist/kit/shared.js +401 -0
- package/dist/kit/shared.js.map +1 -0
- package/dist/kit/vertical-axis.d.ts +99 -0
- package/dist/kit/vertical-axis.d.ts.map +1 -0
- package/dist/kit/vertical-axis.js +176 -0
- package/dist/kit/vertical-axis.js.map +1 -0
- package/dist/line-chart/chart-line.d.ts +91 -0
- package/dist/line-chart/chart-line.d.ts.map +1 -0
- package/dist/line-chart/chart-line.js +156 -0
- package/dist/line-chart/chart-line.js.map +1 -0
- package/dist/line-chart/chart-region.d.ts +47 -0
- package/dist/line-chart/chart-region.d.ts.map +1 -0
- package/dist/line-chart/chart-region.js +101 -0
- package/dist/line-chart/chart-region.js.map +1 -0
- package/dist/line-chart/horizontal-axis.d.ts +85 -0
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
- package/dist/line-chart/horizontal-axis.js +158 -0
- package/dist/line-chart/horizontal-axis.js.map +1 -0
- package/dist/line-chart/index.d.ts +22 -0
- package/dist/line-chart/index.d.ts.map +1 -0
- package/dist/line-chart/index.js +19 -0
- package/dist/line-chart/index.js.map +1 -0
- package/dist/line-chart/line-chart.d.ts +347 -0
- package/dist/line-chart/line-chart.d.ts.map +1 -0
- package/dist/line-chart/line-chart.js +701 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/line-chart/shared.d.ts +171 -0
- package/dist/line-chart/shared.d.ts.map +1 -0
- package/dist/line-chart/shared.js +270 -0
- package/dist/line-chart/shared.js.map +1 -0
- package/dist/line-chart/x-scale.d.ts +84 -0
- package/dist/line-chart/x-scale.d.ts.map +1 -0
- package/dist/line-chart/x-scale.js +302 -0
- package/dist/line-chart/x-scale.js.map +1 -0
- package/dist/nodes.d.ts +20 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +20 -0
- package/dist/nodes.js.map +1 -0
- package/dist/pie-chart/index.d.ts +18 -0
- package/dist/pie-chart/index.d.ts.map +1 -0
- package/dist/pie-chart/index.js +14 -0
- package/dist/pie-chart/index.js.map +1 -0
- package/dist/pie-chart/pie-chart.d.ts +170 -0
- package/dist/pie-chart/pie-chart.d.ts.map +1 -0
- package/dist/pie-chart/pie-chart.js +291 -0
- package/dist/pie-chart/pie-chart.js.map +1 -0
- package/dist/pie-chart/pie-legend.d.ts +60 -0
- package/dist/pie-chart/pie-legend.d.ts.map +1 -0
- package/dist/pie-chart/pie-legend.js +131 -0
- package/dist/pie-chart/pie-legend.js.map +1 -0
- package/dist/pie-chart/pie-ring.d.ts +266 -0
- package/dist/pie-chart/pie-ring.d.ts.map +1 -0
- package/dist/pie-chart/pie-ring.js +708 -0
- package/dist/pie-chart/pie-ring.js.map +1 -0
- package/dist/pie-chart/shared.d.ts +210 -0
- package/dist/pie-chart/shared.d.ts.map +1 -0
- package/dist/pie-chart/shared.js +240 -0
- package/dist/pie-chart/shared.js.map +1 -0
- package/package.json +69 -3
- package/registry.json +23 -0
- package/src/bar-chart/bar-chart.ts +804 -0
- package/src/bar-chart/category-axis.ts +177 -0
- package/src/bar-chart/chart-bars.ts +310 -0
- package/src/bar-chart/index.ts +31 -0
- package/src/bar-chart/shared.ts +354 -0
- package/src/engine.ts +26 -0
- package/src/index.ts +5 -0
- package/src/kit/chart-border.ts +61 -0
- package/src/kit/chart-canvas.ts +157 -0
- package/src/kit/chart-legend.ts +250 -0
- package/src/kit/shared.ts +675 -0
- package/src/kit/vertical-axis.ts +224 -0
- package/src/line-chart/chart-line.ts +208 -0
- package/src/line-chart/chart-region.ts +135 -0
- package/src/line-chart/horizontal-axis.ts +202 -0
- package/src/line-chart/index.ts +39 -0
- package/src/line-chart/line-chart.ts +894 -0
- package/src/line-chart/shared.ts +459 -0
- package/src/line-chart/x-scale.ts +367 -0
- package/src/nodes.ts +20 -0
- package/src/pie-chart/index.ts +37 -0
- package/src/pie-chart/pie-chart.ts +374 -0
- package/src/pie-chart/pie-legend.ts +159 -0
- package/src/pie-chart/pie-ring.ts +903 -0
- package/src/pie-chart/shared.ts +490 -0
- package/README.md +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-region.js","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,OAAO,EACP,SAAS,EACT,QAAQ,GAOT,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,GAEV,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAqB5D;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAwB;IAgBvD;;;OAGG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7B,CAAC;IAES,UAAU,CAAC,GAAoB;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACpB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;YAAE,OAAM;QAE3B,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;QAC/C,IAAI,CAAC,IAAI,CAAC;YAAE,OAAM;QAElB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC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KAAK,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC;oBACH,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE;oBACnB,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE;iBACpB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;YAC5B,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC;oBACH,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE;oBACnB,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE;iBACpB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA7EwD;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAC;wCAAuB;AAM7D;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM;QAC1C,MAAM,EAAE,SAAS,CAAC,OAAO;QACzB,KAAK,EAAE,SAAS,CAAC,IAAI;KACtB,CAAC;2CACoB;AAMd;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,IAAI;QACxC,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;yCACgB;AACgB;IAAjC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;2CAAuB","sourcesContent":["import {\n type AssetScope,\n Graphics2D,\n Node2D,\n fillOps,\n strokeOps,\n property,\n type Fill,\n type FillResolved,\n type Node2DProps,\n type RenderContext2D,\n type Stroke,\n type StrokeResolved,\n} from \"@motionscript/core\"\n\nimport {\n DEFAULT_CHART_THEME,\n EMPTY_REGION_BOX,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\nimport { declarePaints } from \"@motionscript/core/component\"\n\nexport interface ChartRegionProps extends Node2DProps {\n /**\n * The highlighted slice, already resolved into this node's local pixel space\n * (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box\n * draws nothing.\n */\n box: RegionBox\n /** Dashed rule marking each *bounded* edge of the box. */\n stroke: Stroke\n /** Wash filling the box, under the series lines. */\n fill: Fill\n /**\n * Reveal of the annotation in `[0, 1]`: 0 hides it, 1 draws it fully. Driven\n * by the chart's own `regionReveal`, so the rules and the series' dimming move\n * as one.\n */\n reveal: number\n}\n\n/**\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\n * plot with a dashed rule down each edge the author actually bounded. Sized and\n * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather\n * than its own `layoutBounds` — the box already carries the plot geometry.\n *\n * It draws only the *marking*; fading the series outside the region is\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\n * the two can't disagree about where the boundary is.\n *\n * Only bounded edges get a rule: a region given just an `x` range spans the full\n * plot height, so its top and bottom edges are the plot's own border, not a data\n * bound — drawing dashes there would assert a limit the author didn't set.\n */\nexport class ChartRegion extends Node2D<ChartRegionProps> {\n @property({ default: () => EMPTY_REGION_BOX }) declare box: RegionBox\n @property({\n default: DEFAULT_CHART_THEME.region.stroke,\n mapper: strokeOps.resolve,\n tween: strokeOps.lerp,\n })\n declare stroke: Stroke\n @property({\n default: DEFAULT_CHART_THEME.region.fill,\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n @property({ default: 0 }) declare reveal: number\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets)\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const box = this.box\n if (!hasRegion(box)) return\n\n const r = Math.max(0, Math.min(1, this.reveal))\n if (r <= 0) return\n\n const width = box.right - box.left\n const height = box.top - box.bottom\n const cx = (box.left + box.right) / 2\n const cy = (box.bottom + box.top) / 2\n\n // Wash first, so the rules sit over their own tint.\n const layers = this.fill as FillResolved[]\n if (layers.length > 0) {\n ctx.draw(\n new Graphics2D()\n .rect({ x: cx, y: cy, width, height })\n .fill(this.fill)\n .opacity(r)\n )\n }\n\n // One rule per bounded edge, growing from the region's centre outward as\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\n const stroke = this.stroke as StrokeResolved[]\n if (stroke.length === 0) return\n\n // One `draw` per rule rather than four line ops under a single paint:\n // shapes chained before a `stroke()` are combined into one surface, and\n // stroking a union of disjoint open paths doesn't paint.\n const rule = (points: { x: number; y: number }[]) =>\n ctx.draw(new Graphics2D().line({ points }).stroke(this.stroke).opacity(r))\n\n if (box.xBounded) {\n const half = (height / 2) * r\n for (const x of [box.left, box.right]) {\n rule([\n { x, y: cy - half },\n { x, y: cy + half },\n ])\n }\n }\n if (box.yBounded) {\n const half = (width / 2) * r\n for (const y of [box.bottom, box.top]) {\n rule([\n { x: cx - half, y },\n { x: cx + half, y },\n ])\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Node2D, type CommandArgs, type NodeConfig, type Node2DProps } from "@motionscript/core";
|
|
2
|
+
import { type AxisConfig, type Range } from "../kit/shared.js";
|
|
3
|
+
import { type Seekable } from "@motionscript/core/component";
|
|
4
|
+
export interface HorizontalAxisProps extends Node2DProps {
|
|
5
|
+
/** `[min, max]` of the horizontal scale the markers are positioned within. */
|
|
6
|
+
range: Range;
|
|
7
|
+
/** Tick values (in data units) to draw along the axis. */
|
|
8
|
+
markers: number[];
|
|
9
|
+
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
10
|
+
axis: AxisConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Caption drawn centred in the gutter beneath the marker row. Empty string
|
|
13
|
+
* (the default) hides it.
|
|
14
|
+
*/
|
|
15
|
+
label: string;
|
|
16
|
+
}
|
|
17
|
+
/** How a tick value is captioned — see {@link HorizontalAxis.labelFor}. */
|
|
18
|
+
export type MarkerLabel = (value: number) => string;
|
|
19
|
+
/**
|
|
20
|
+
* The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,
|
|
21
|
+
* one per marker value, running left-to-right. Pure layout — the mirror of the
|
|
22
|
+
* kit's `VerticalAxis`, including its bound (not snapshotted) marker text and
|
|
23
|
+
* positions, and its landed resting state.
|
|
24
|
+
*
|
|
25
|
+
* Markers are always placed **by value** across the range, whatever they say:
|
|
26
|
+
* `2026-03` sits three months along, not three slots along. That is what keeps
|
|
27
|
+
* it distinct from a bar chart's bottom axis, which centres a caption on each
|
|
28
|
+
* slot and has no scale at all — the two only look alike. What the values are
|
|
29
|
+
* captioned *as* is the chart's to decide; see {@link labelFor}.
|
|
30
|
+
*
|
|
31
|
+
* {@link enter} staggers the markers in **left-to-right**: each starts lifted a
|
|
32
|
+
* little above its slot and transparent, then fades and slides down into place.
|
|
33
|
+
*/
|
|
34
|
+
export declare class HorizontalAxis extends Node2D<HorizontalAxisProps> {
|
|
35
|
+
range: Range;
|
|
36
|
+
markers: number[];
|
|
37
|
+
axis: AxisConfig;
|
|
38
|
+
label: string;
|
|
39
|
+
/**
|
|
40
|
+
* How a tick value is captioned. Defaults to the numeric formatting the
|
|
41
|
+
* vertical axis uses; a chart whose x column names months or categories
|
|
42
|
+
* replaces it (see `x-scale.ts`).
|
|
43
|
+
*
|
|
44
|
+
* A plain field rather than a `@property`, because it is a **policy, not a
|
|
45
|
+
* value**: there is nothing to tween between two formatters, and a signal
|
|
46
|
+
* holding a function is a signal every `set`/`to` on this node would have to
|
|
47
|
+
* know not to touch. Read inside each marker's `text` binding, so replacing it
|
|
48
|
+
* before the first frame is enough — which is when the chart does it.
|
|
49
|
+
*/
|
|
50
|
+
labelFor: MarkerLabel;
|
|
51
|
+
/** One text node per marker, ordered left → right, for the staggered enter. */
|
|
52
|
+
private markerNodes;
|
|
53
|
+
/** The caption node, or null when `label` is empty. */
|
|
54
|
+
private labelNode;
|
|
55
|
+
/** The live tick values, left → right — re-read every frame, not snapshotted. */
|
|
56
|
+
private get sortedMarkers();
|
|
57
|
+
private valueAt;
|
|
58
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
59
|
+
private fracAt;
|
|
60
|
+
constructor(props?: NodeConfig<HorizontalAxis, HorizontalAxisProps>);
|
|
61
|
+
/**
|
|
62
|
+
* Primes every marker (and the caption) at its pre-entrance state: lifted
|
|
63
|
+
* above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.
|
|
64
|
+
*/
|
|
65
|
+
arm(slide?: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Stagger the markers in left to right, then slide the caption in after them.
|
|
68
|
+
*
|
|
69
|
+
* A {@link Seekable} rather than a generator. The offsets were always static —
|
|
70
|
+
* `i * step` per marker — but expressed as `wait` inside a generator they only
|
|
71
|
+
* existed while it ran, so knowing what the axis looked like partway through
|
|
72
|
+
* meant running it from zero. Placed explicitly, the same stagger can be asked
|
|
73
|
+
* for a time, which is what lets a chart scene scrub in constant time.
|
|
74
|
+
*
|
|
75
|
+
* `duration` is the **whole** entrance — see {@link VerticalAxis.enter} and
|
|
76
|
+
* {@link enterBudget}.
|
|
77
|
+
*/
|
|
78
|
+
enter(args: CommandArgs<{
|
|
79
|
+
stagger?: number;
|
|
80
|
+
slide?: number;
|
|
81
|
+
}> & {
|
|
82
|
+
duration: number;
|
|
83
|
+
}): Seekable;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=horizontal-axis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"horizontal-axis.d.ts","sourceRoot":"","sources":["../../src/line-chart/horizontal-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MA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AAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAC7E,QAAQ;CA4BZ"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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 { command, Node2D, Rect, Text, easeOut, property, insetsOps, textOps, } from "@motionscript/core";
|
|
8
|
+
import { DEFAULT_X_AXIS, enterBudget, formatMarker, } from "../kit/shared.js";
|
|
9
|
+
import { at, compose } from "@motionscript/core/component";
|
|
10
|
+
/** How far a marker starts above its slot when it enters, in px. */
|
|
11
|
+
const SLIDE = 24;
|
|
12
|
+
/**
|
|
13
|
+
* The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,
|
|
14
|
+
* one per marker value, running left-to-right. Pure layout — the mirror of the
|
|
15
|
+
* kit's `VerticalAxis`, including its bound (not snapshotted) marker text and
|
|
16
|
+
* positions, and its landed resting state.
|
|
17
|
+
*
|
|
18
|
+
* Markers are always placed **by value** across the range, whatever they say:
|
|
19
|
+
* `2026-03` sits three months along, not three slots along. That is what keeps
|
|
20
|
+
* it distinct from a bar chart's bottom axis, which centres a caption on each
|
|
21
|
+
* slot and has no scale at all — the two only look alike. What the values are
|
|
22
|
+
* captioned *as* is the chart's to decide; see {@link labelFor}.
|
|
23
|
+
*
|
|
24
|
+
* {@link enter} staggers the markers in **left-to-right**: each starts lifted a
|
|
25
|
+
* little above its slot and transparent, then fades and slides down into place.
|
|
26
|
+
*/
|
|
27
|
+
export class HorizontalAxis extends Node2D {
|
|
28
|
+
/**
|
|
29
|
+
* How a tick value is captioned. Defaults to the numeric formatting the
|
|
30
|
+
* vertical axis uses; a chart whose x column names months or categories
|
|
31
|
+
* replaces it (see `x-scale.ts`).
|
|
32
|
+
*
|
|
33
|
+
* A plain field rather than a `@property`, because it is a **policy, not a
|
|
34
|
+
* value**: there is nothing to tween between two formatters, and a signal
|
|
35
|
+
* holding a function is a signal every `set`/`to` on this node would have to
|
|
36
|
+
* know not to touch. Read inside each marker's `text` binding, so replacing it
|
|
37
|
+
* before the first frame is enough — which is when the chart does it.
|
|
38
|
+
*/
|
|
39
|
+
labelFor = formatMarker;
|
|
40
|
+
/** One text node per marker, ordered left → right, for the staggered enter. */
|
|
41
|
+
markerNodes = [];
|
|
42
|
+
/** The caption node, or null when `label` is empty. */
|
|
43
|
+
labelNode = null;
|
|
44
|
+
/** The live tick values, left → right — re-read every frame, not snapshotted. */
|
|
45
|
+
get sortedMarkers() {
|
|
46
|
+
return [...this.markers].sort((a, b) => a - b);
|
|
47
|
+
}
|
|
48
|
+
valueAt(index) {
|
|
49
|
+
return this.sortedMarkers[index];
|
|
50
|
+
}
|
|
51
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
52
|
+
fracAt(index) {
|
|
53
|
+
const v = this.valueAt(index);
|
|
54
|
+
if (v === undefined)
|
|
55
|
+
return 0;
|
|
56
|
+
const [min, max] = this.range;
|
|
57
|
+
return max <= min ? 0 : (v - min) / (max - min);
|
|
58
|
+
}
|
|
59
|
+
constructor(props) {
|
|
60
|
+
super(props);
|
|
61
|
+
const tickPad = insetsOps.resolve(this.axis.tickPadding).top;
|
|
62
|
+
const titlePad = insetsOps.resolve(this.axis.titlePadding).top;
|
|
63
|
+
this.markerNodes = this.markers.map((_, i) => {
|
|
64
|
+
const marker = new Text({
|
|
65
|
+
...textOps.styleProps(this.axis.labelStyle),
|
|
66
|
+
text: () => {
|
|
67
|
+
const v = this.valueAt(i);
|
|
68
|
+
return v === undefined ? "" : this.labelFor(v);
|
|
69
|
+
},
|
|
70
|
+
x: () => {
|
|
71
|
+
const width = this.layoutBounds.width;
|
|
72
|
+
const centred = (this.fracAt(i) - 0.5) * width;
|
|
73
|
+
// Held inside the axis's right edge, which is also the *chart's*: the
|
|
74
|
+
// last marker is centred on the last grid line, so half of `2026-06`
|
|
75
|
+
// — or of `3300` — would be drawn outside the node's box and outside
|
|
76
|
+
// the rectangle the editor draws around it. Only the right edge is
|
|
77
|
+
// held, because the left one has the vertical axis's whole gutter
|
|
78
|
+
// beyond it, and a marker overhanging into that is inside the chart.
|
|
79
|
+
const limit = width / 2 - marker.layoutBounds.width / 2;
|
|
80
|
+
return Math.min(centred, limit);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return marker;
|
|
84
|
+
});
|
|
85
|
+
const children = [
|
|
86
|
+
new Rect({
|
|
87
|
+
width: "fill",
|
|
88
|
+
height: "hug",
|
|
89
|
+
padding: { top: tickPad },
|
|
90
|
+
children: this.markerNodes,
|
|
91
|
+
}),
|
|
92
|
+
];
|
|
93
|
+
if (this.label !== "") {
|
|
94
|
+
this.labelNode = new Text({
|
|
95
|
+
...textOps.styleProps(this.axis.titleStyle),
|
|
96
|
+
text: this.label,
|
|
97
|
+
});
|
|
98
|
+
children.push(this.labelNode);
|
|
99
|
+
}
|
|
100
|
+
this.add(new Rect({ flow: "vertical", gap: titlePad, height: "hug", width: "fill", children }));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Primes every marker (and the caption) at its pre-entrance state: lifted
|
|
104
|
+
* above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.
|
|
105
|
+
*/
|
|
106
|
+
arm(slide = SLIDE) {
|
|
107
|
+
for (const marker of this.markerNodes)
|
|
108
|
+
marker.set({ opacity: 0, y: slide });
|
|
109
|
+
this.labelNode?.set({ opacity: 0, y: slide });
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Stagger the markers in left to right, then slide the caption in after them.
|
|
113
|
+
*
|
|
114
|
+
* A {@link Seekable} rather than a generator. The offsets were always static —
|
|
115
|
+
* `i * step` per marker — but expressed as `wait` inside a generator they only
|
|
116
|
+
* existed while it ran, so knowing what the axis looked like partway through
|
|
117
|
+
* meant running it from zero. Placed explicitly, the same stagger can be asked
|
|
118
|
+
* for a time, which is what lets a chart scene scrub in constant time.
|
|
119
|
+
*
|
|
120
|
+
* `duration` is the **whole** entrance — see {@link VerticalAxis.enter} and
|
|
121
|
+
* {@link enterBudget}.
|
|
122
|
+
*/
|
|
123
|
+
enter(args) {
|
|
124
|
+
const { stagger, slide = SLIDE } = args.data ?? {};
|
|
125
|
+
const duration = args.duration;
|
|
126
|
+
const easing = args.easing ?? easeOut();
|
|
127
|
+
const nodes = this.markerNodes;
|
|
128
|
+
if (nodes.length === 0)
|
|
129
|
+
return compose([]);
|
|
130
|
+
const { step, per, caption } = enterBudget(duration, nodes.length, this.labelNode !== null, stagger);
|
|
131
|
+
this.arm(slide);
|
|
132
|
+
// Left marker leads: markerNodes is already left → right.
|
|
133
|
+
const markers = nodes.map((node, i) => at(i * step, node.to({ data: { opacity: 1, y: 0 }, duration: per, easing })));
|
|
134
|
+
const lastMarkerEnds = nodes.length === 0 ? 0 : (nodes.length - 1) * step + per;
|
|
135
|
+
return compose([
|
|
136
|
+
...markers,
|
|
137
|
+
...(this.labelNode
|
|
138
|
+
? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, y: 0 }, duration: caption, easing }))]
|
|
139
|
+
: []),
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
__decorate([
|
|
144
|
+
property({ default: () => [0, 1] })
|
|
145
|
+
], HorizontalAxis.prototype, "range", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
property({ default: () => [] })
|
|
148
|
+
], HorizontalAxis.prototype, "markers", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
property({ default: DEFAULT_X_AXIS })
|
|
151
|
+
], HorizontalAxis.prototype, "axis", void 0);
|
|
152
|
+
__decorate([
|
|
153
|
+
property({ default: "" })
|
|
154
|
+
], HorizontalAxis.prototype, "label", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
command()
|
|
157
|
+
], HorizontalAxis.prototype, "enter", null);
|
|
158
|
+
//# sourceMappingURL=horizontal-axis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"horizontal-axis.js","sourceRoot":"","sources":["../../src/line-chart/horizontal-axis.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,OAAO,GAIR,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,EAAE,EAAE,OAAO,EAAiB,MAAM,8BAA8B,CAAA;AAgBzE,oEAAoE;AACpE,MAAM,KAAK,GAAG,EAAE,CAAC;AAKjB;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,cAAe,SAAQ,MAA2B;IAM7D;;;;;;;;;;OAUG;IACH,QAAQ,GAAgB,YAAY,CAAC;IAErC,+EAA+E;IACvE,WAAW,GAAW,EAAE,CAAC;IACjC,uDAAuD;IAC/C,SAAS,GAAgB,IAAI,CAAC;IAEtC,iFAAiF;IACjF,IAAY,aAAa;QACvB,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IAEO,OAAO,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,uEAAuE;IAC/D,MAAM,CAAC,KAAa;QAC1B,M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AO,OAAO,CAAC;YACb,GAAG,OAAO;YACV,GAAG,CAAC,IAAI,CAAC,SAAS;gBAChB,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;gBACpG,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC;IACL,CAAC;CACF;AA9IuD;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAU,EAAE,CAAC;6CAAsB;AACd;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;+CAA2B;AACxB;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;4CAA0B;AAC7B;IAAlC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;6CAAuB;AA6GjD;IADC,OAAO,EAAE;2CA8BT","sourcesContent":["import {\n command,\n Node2D,\n Rect,\n Text,\n easeOut,\n property,\n insetsOps,\n textOps,\n type CommandArgs,\n type NodeConfig,\n type Node2DProps,\n} from \"@motionscript/core\";\n\nimport {\n DEFAULT_X_AXIS,\n enterBudget,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"../kit/shared\";\nimport { at, compose, type Seekable } from \"@motionscript/core/component\"\n\nexport interface HorizontalAxisProps extends Node2DProps {\n /** `[min, max]` of the horizontal scale the markers are positioned within. */\n range: Range;\n /** Tick values (in data units) to draw along the axis. */\n markers: number[];\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\n axis: AxisConfig;\n /**\n * Caption drawn centred in the gutter beneath the marker row. Empty string\n * (the default) hides it.\n */\n label: string;\n}\n\n/** How far a marker starts above its slot when it enters, in px. */\nconst SLIDE = 24;\n\n/** How a tick value is captioned — see {@link HorizontalAxis.labelFor}. */\nexport type MarkerLabel = (value: number) => string;\n\n/**\n * The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,\n * one per marker value, running left-to-right. Pure layout — the mirror of the\n * kit's `VerticalAxis`, including its bound (not snapshotted) marker text and\n * positions, and its landed resting state.\n *\n * Markers are always placed **by value** across the range, whatever they say:\n * `2026-03` sits three months along, not three slots along. That is what keeps\n * it distinct from a bar chart's bottom axis, which centres a caption on each\n * slot and has no scale at all — the two only look alike. What the values are\n * captioned *as* is the chart's to decide; see {@link labelFor}.\n *\n * {@link enter} staggers the markers in **left-to-right**: each starts lifted a\n * little above its slot and transparent, then fades and slides down into place.\n */\nexport class HorizontalAxis extends Node2D<HorizontalAxisProps> {\n @property({ default: () => [0, 1] as Range }) declare range: Range;\n @property({ default: () => [] as number[] }) declare markers: number[];\n @property({ default: DEFAULT_X_AXIS }) declare axis: AxisConfig;\n @property({ default: \"\" }) declare label: string;\n\n /**\n * How a tick value is captioned. Defaults to the numeric formatting the\n * vertical axis uses; a chart whose x column names months or categories\n * replaces it (see `x-scale.ts`).\n *\n * A plain field rather than a `@property`, because it is a **policy, not a\n * value**: there is nothing to tween between two formatters, and a signal\n * holding a function is a signal every `set`/`to` on this node would have to\n * know not to touch. Read inside each marker's `text` binding, so replacing it\n * before the first frame is enough — which is when the chart does it.\n */\n labelFor: MarkerLabel = formatMarker;\n\n /** One text node per marker, ordered left → right, for the staggered enter. */\n private markerNodes: Text[] = [];\n /** The caption node, or null when `label` is empty. */\n private labelNode: Text | null = null;\n\n /** The live tick values, left → right — re-read every frame, not snapshotted. */\n private get sortedMarkers(): number[] {\n return [...this.markers].sort((a, b) => a - b);\n }\n\n private valueAt(index: number): number | undefined {\n return this.sortedMarkers[index];\n }\n\n /** Tick `i`'s fraction across the live `range`, 0 at the left edge. */\n private fracAt(index: number): number {\n const v = this.valueAt(index);\n if (v === undefined) return 0;\n const [min, max] = this.range;\n return max <= min ? 0 : (v - min) / (max - min);\n }\n\n constructor(props?: NodeConfig<HorizontalAxis, HorizontalAxisProps>) {\n super(props);\n\n const tickPad = insetsOps.resolve(this.axis.tickPadding).top;\n const titlePad = insetsOps.resolve(this.axis.titlePadding).top;\n\n this.markerNodes = this.markers.map((_, i) => {\n const marker: Text = new Text({\n ...textOps.styleProps(this.axis.labelStyle),\n text: () => {\n const v = this.valueAt(i);\n return v === undefined ? \"\" : this.labelFor(v);\n },\n x: () => {\n const width = this.layoutBounds.width;\n const centred = (this.fracAt(i) - 0.5) * width;\n // Held inside the axis's right edge, which is also the *chart's*: the\n // last marker is centred on the last grid line, so half of `2026-06`\n // — or of `3300` — would be drawn outside the node's box and outside\n // the rectangle the editor draws around it. Only the right edge is\n // held, because the left one has the vertical axis's whole gutter\n // beyond it, and a marker overhanging into that is inside the chart.\n const limit = width / 2 - marker.layoutBounds.width / 2;\n return Math.min(centred, limit);\n },\n });\n return marker;\n });\n\n const children: Node2D[] = [\n new Rect({\n width: \"fill\",\n height: \"hug\",\n padding: { top: tickPad },\n children: this.markerNodes,\n }),\n ];\n if (this.label !== \"\") {\n this.labelNode = new Text({\n ...textOps.styleProps(this.axis.titleStyle),\n text: this.label,\n });\n children.push(this.labelNode);\n }\n\n this.add(\n new Rect({ flow: \"vertical\", gap: titlePad, height: \"hug\", width: \"fill\", children }),\n );\n }\n\n /**\n * Primes every marker (and the caption) at its pre-entrance state: lifted\n * above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.\n */\n arm(slide = SLIDE): void {\n for (const marker of this.markerNodes) marker.set({ opacity: 0, y: slide });\n this.labelNode?.set({ opacity: 0, y: slide });\n }\n\n /**\n * Stagger the markers in left to right, then slide the caption in after them.\n *\n * A {@link Seekable} rather than a generator. The offsets were always static —\n * `i * step` per marker — but expressed as `wait` inside a generator they only\n * existed while it ran, so knowing what the axis looked like partway through\n * meant running it from zero. Placed explicitly, the same stagger can be asked\n * for a time, which is what lets a chart scene scrub in constant time.\n *\n * `duration` is the **whole** entrance — see {@link VerticalAxis.enter} and\n * {@link enterBudget}.\n */\n @command()\n enter(\n args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number },\n ): Seekable {\n const { stagger, slide = SLIDE } = args.data ?? {};\n const duration = args.duration;\n const easing = args.easing ?? easeOut();\n const nodes = this.markerNodes;\n if (nodes.length === 0) return compose([]);\n const { step, per, caption } = enterBudget(\n duration,\n nodes.length,\n this.labelNode !== null,\n stagger,\n );\n\n this.arm(slide);\n\n // Left marker leads: markerNodes is already left → right.\n const markers = nodes.map((node, i) =>\n at(i * step, node.to({ data: { opacity: 1, y: 0 }, duration: per, easing })),\n );\n const lastMarkerEnds = nodes.length === 0 ? 0 : (nodes.length - 1) * step + per;\n\n return compose([\n ...markers,\n ...(this.labelNode\n ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, y: 0 }, duration: caption, easing }))]\n : []),\n ]);\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line chart: a cartesian plot with a traced polyline, spotlit regions and
|
|
3
|
+
* a staggered entrance.
|
|
4
|
+
*
|
|
5
|
+
* {@link LineChart} composes the parts below plus the shared ones in the kit
|
|
6
|
+
* (the plot panel, the value axis, the legend); each part is exported too, so
|
|
7
|
+
* another node type can reuse one on its own.
|
|
8
|
+
*
|
|
9
|
+
* These files are what `ms add line-chart` copies. Everything they reach for
|
|
10
|
+
* that is *not* here comes from the kit and stays a dependency — see
|
|
11
|
+
* `../engine.ts` for why that line is where it is.
|
|
12
|
+
*/
|
|
13
|
+
export { LineChart } from "./line-chart.js";
|
|
14
|
+
export type { LineChartProps } from "./line-chart.js";
|
|
15
|
+
export { ChartRegion } from "./chart-region.js";
|
|
16
|
+
export { ChartLine } from "./chart-line.js";
|
|
17
|
+
export { HorizontalAxis } from "./horizontal-axis.js";
|
|
18
|
+
export { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, lerpChartTheme, resolveChartTheme, resolveRegionBox, resolveYScale, seriesPoints, yExtent, } from "./shared.js";
|
|
19
|
+
export type { ChartConfig, ChartTheme, LineSeries, PlotRegion, RegionBox, RegionConfig, } from "./shared.js";
|
|
20
|
+
export { formatInstant, parseInstant, resolveXScale } from "./x-scale.js";
|
|
21
|
+
export type { XScale, XScaleKind } from "./x-scale.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-chart/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,OAAO,GACR,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAY,GACb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACtE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line chart: a cartesian plot with a traced polyline, spotlit regions and
|
|
3
|
+
* a staggered entrance.
|
|
4
|
+
*
|
|
5
|
+
* {@link LineChart} composes the parts below plus the shared ones in the kit
|
|
6
|
+
* (the plot panel, the value axis, the legend); each part is exported too, so
|
|
7
|
+
* another node type can reuse one on its own.
|
|
8
|
+
*
|
|
9
|
+
* These files are what `ms add line-chart` copies. Everything they reach for
|
|
10
|
+
* that is *not* here comes from the kit and stays a dependency — see
|
|
11
|
+
* `../engine.ts` for why that line is where it is.
|
|
12
|
+
*/
|
|
13
|
+
export { LineChart } from "./line-chart.js";
|
|
14
|
+
export { ChartRegion } from "./chart-region.js";
|
|
15
|
+
export { ChartLine } from "./chart-line.js";
|
|
16
|
+
export { HorizontalAxis } from "./horizontal-axis.js";
|
|
17
|
+
export { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, lerpChartTheme, resolveChartTheme, resolveRegionBox, resolveYScale, seriesPoints, yExtent, } from "./shared.js";
|
|
18
|
+
export { formatInstant, parseInstant, resolveXScale } from "./x-scale.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/line-chart/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,OAAO,GACR,MAAM,UAAU,CAAA;AASjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA","sourcesContent":["/**\n * The line chart: a cartesian plot with a traced polyline, spotlit regions and\n * a staggered entrance.\n *\n * {@link LineChart} composes the parts below plus the shared ones in the kit\n * (the plot panel, the value axis, the legend); each part is exported too, so\n * another node type can reuse one on its own.\n *\n * These files are what `ms add line-chart` copies. Everything they reach for\n * that is *not* here comes from the kit and stays a dependency — see\n * `../engine.ts` for why that line is where it is.\n */\nexport { LineChart } from \"./line-chart\"\nexport type { LineChartProps } from \"./line-chart\"\nexport { ChartRegion } from \"./chart-region\"\nexport { ChartLine } from \"./chart-line\"\nexport { HorizontalAxis } from \"./horizontal-axis\"\nexport {\n DEFAULT_CHART_THEME,\n EMPTY_REGION_BOX,\n clipPolylineToBox,\n hasRegion,\n lerpChartTheme,\n resolveChartTheme,\n resolveRegionBox,\n resolveYScale,\n seriesPoints,\n yExtent,\n} from \"./shared\"\nexport type {\n ChartConfig,\n ChartTheme,\n LineSeries,\n PlotRegion,\n RegionBox,\n RegionConfig,\n} from \"./shared\"\nexport { formatInstant, parseInstant, resolveXScale } from \"./x-scale\"\nexport type { XScale, XScaleKind } from \"./x-scale\"\n"]}
|