@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,2 @@
|
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,J,K,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunks/chunk-ZMBOBHYL.js";export{c as CHART_PALETTE,H as ChartBorder,I as ChartCanvas,J as ChartLegend,m as DEFAULT_LEGEND,l as DEFAULT_PLOT_AREA,d as DEFAULT_SERIES_COLORS,o as DEFAULT_SERIES_FILLS,n as DEFAULT_SERIES_STROKES,j as DEFAULT_X_AXIS,k as DEFAULT_Y_AXIS,e as SPOTLIGHT_DIM,K as VerticalAxis,f as clampUnit,G as enterBudget,C as formatMarker,D as formatPercent,q as lerpAxisConfig,b as lerpAxisDomain,u as lerpLegendConfig,s as lerpPlotArea,y as lerpSeriesFills,w as lerpSeriesStrokes,E as markerValues,F as niceStep,g as num,i as numericFields,p as resolveAxisConfig,a as resolveAxisDomain,t as resolveLegendConfig,B as resolvePalettePaint,r as resolvePlotArea,A as resolveSeriesFill,x as resolveSeriesFills,z as resolveSeriesStroke,v as resolveSeriesStrokes,h as text};
|
|
2
|
+
//# sourceMappingURL=kit.js.map
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart **kit**: everything the three charts share, and the one thing a
|
|
3
|
+
* copied chart does not copy.
|
|
4
|
+
*
|
|
5
|
+
* `ms add line-chart` writes `line-chart/*` into your project and rewrites its
|
|
6
|
+
* reach for these to `@motionscript/charts`, so the plot panel, the value
|
|
7
|
+
* axis, the legend and the number formatting stay a real dependency. That is
|
|
8
|
+
* not a size decision — it is the only arrangement that works.
|
|
9
|
+
*
|
|
10
|
+
* A chart identifies its own parts, and the engine keys signal machinery to
|
|
11
|
+
* class identity: `@property` installs against the class it was applied with,
|
|
12
|
+
* and the renderer asks `instanceof` about what it is drawing. Copy
|
|
13
|
+
* `VerticalAxis` alongside your fork and there are now two of it — two classes
|
|
14
|
+
* answering one name, and whichever one your chart did not get renders as
|
|
15
|
+
* nothing at all, with no error. Keeping the kit external makes that
|
|
16
|
+
* impossible rather than unlikely.
|
|
17
|
+
*
|
|
18
|
+
* It also means a fix to the axis reaches a forked chart without a re-add,
|
|
19
|
+
* which is the half of the bargain you get back for it.
|
|
20
|
+
*/
|
|
21
|
+
export * from "./kit/shared.js";
|
|
22
|
+
export * from "./kit/chart-border.js";
|
|
23
|
+
export * from "./kit/chart-canvas.js";
|
|
24
|
+
export * from "./kit/chart-legend.js";
|
|
25
|
+
export * from "./kit/vertical-axis.js";
|
|
26
|
+
export * from "@motionscript/core/component";
|
|
27
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,8BAA8B,CAAA"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart **kit**: everything the three charts share, and the one thing a
|
|
3
|
+
* copied chart does not copy.
|
|
4
|
+
*
|
|
5
|
+
* `ms add line-chart` writes `line-chart/*` into your project and rewrites its
|
|
6
|
+
* reach for these to `@motionscript/charts`, so the plot panel, the value
|
|
7
|
+
* axis, the legend and the number formatting stay a real dependency. That is
|
|
8
|
+
* not a size decision — it is the only arrangement that works.
|
|
9
|
+
*
|
|
10
|
+
* A chart identifies its own parts, and the engine keys signal machinery to
|
|
11
|
+
* class identity: `@property` installs against the class it was applied with,
|
|
12
|
+
* and the renderer asks `instanceof` about what it is drawing. Copy
|
|
13
|
+
* `VerticalAxis` alongside your fork and there are now two of it — two classes
|
|
14
|
+
* answering one name, and whichever one your chart did not get renders as
|
|
15
|
+
* nothing at all, with no error. Keeping the kit external makes that
|
|
16
|
+
* impossible rather than unlikely.
|
|
17
|
+
*
|
|
18
|
+
* It also means a fix to the axis reaches a forked chart without a re-add,
|
|
19
|
+
* which is the half of the bargain you get back for it.
|
|
20
|
+
*/
|
|
21
|
+
export * from "./kit/shared.js";
|
|
22
|
+
export * from "./kit/chart-border.js";
|
|
23
|
+
export * from "./kit/chart-canvas.js";
|
|
24
|
+
export * from "./kit/chart-legend.js";
|
|
25
|
+
export * from "./kit/vertical-axis.js";
|
|
26
|
+
export * from "@motionscript/core/component";
|
|
27
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,8BAA8B,CAAA","sourcesContent":["/**\n * The chart **kit**: everything the three charts share, and the one thing a\n * copied chart does not copy.\n *\n * `ms add line-chart` writes `line-chart/*` into your project and rewrites its\n * reach for these to `@motionscript/charts`, so the plot panel, the value\n * axis, the legend and the number formatting stay a real dependency. That is\n * not a size decision — it is the only arrangement that works.\n *\n * A chart identifies its own parts, and the engine keys signal machinery to\n * class identity: `@property` installs against the class it was applied with,\n * and the renderer asks `instanceof` about what it is drawing. Copy\n * `VerticalAxis` alongside your fork and there are now two of it — two classes\n * answering one name, and whichever one your chart did not get renders as\n * nothing at all, with no error. Keeping the kit external makes that\n * impossible rather than unlikely.\n *\n * It also means a fix to the axis reaches a forked chart without a re-add,\n * which is the half of the bargain you get back for it.\n */\nexport * from \"./kit/shared\"\nexport * from \"./kit/chart-border\"\nexport * from \"./kit/chart-canvas\"\nexport * from \"./kit/chart-legend\"\nexport * from \"./kit/vertical-axis\"\nexport * from \"@motionscript/core/component\"\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export * from \"./line-chart\";\nexport * from \"./bar-chart\";\nexport * from \"./pie-chart\";\nexport * from \"./engine\";\nexport { NODES } from \"./nodes\";\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AssetScope, Node2D, type Node2DProps, type RenderContext2D, type Stroke } from "@motionscript/core";
|
|
2
|
+
export interface ChartBorderProps extends Node2DProps {
|
|
3
|
+
/**
|
|
4
|
+
* The plot's thick frame stroke. The stroke resolver's default `align` is
|
|
5
|
+
* `'inside'`, so the whole weight sits within the layout box unless the theme
|
|
6
|
+
* overrides it.
|
|
7
|
+
*/
|
|
8
|
+
stroke: Stroke;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The thick **frame** around a cartesian chart's plot: an empty rect wearing an
|
|
12
|
+
* inside stroke, sized from its allocated `layoutBounds`.
|
|
13
|
+
*
|
|
14
|
+
* Split out of {@link ChartCanvas} (the filled + gridded backdrop) so it can be
|
|
15
|
+
* placed *after* the marks in the tree — the box then frames the plot **over**
|
|
16
|
+
* them, so a line or a column running to the edge tucks cleanly under the border
|
|
17
|
+
* rather than sitting on top of it.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ChartBorder extends Node2D<ChartBorderProps> {
|
|
20
|
+
stroke: Stroke;
|
|
21
|
+
/**
|
|
22
|
+
* This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
|
|
23
|
+
* paint props it carries — see {@link declarePaints}.
|
|
24
|
+
*/
|
|
25
|
+
declareAssets(assets: AssetScope): void;
|
|
26
|
+
protected renderSelf(ctx: RenderContext2D): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=chart-border.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-border.d.ts","sourceRoot":"","sources":["../../src/kit/chart-border.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,MAAM,EAGN,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAA;AAK3B,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,MAAM,CAAC,gBAAgB,CAAC;IAM/C,MAAM,EAAE,MAAM,CAAA;IAEtB;;;OAGG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;CAWjD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { Graphics2D, Node2D, strokeOps, property, } from "@motionscript/core";
|
|
8
|
+
import { DEFAULT_PLOT_AREA } from "./shared.js";
|
|
9
|
+
import { declarePaints } from "@motionscript/core/component";
|
|
10
|
+
/**
|
|
11
|
+
* The thick **frame** around a cartesian chart's plot: an empty rect wearing an
|
|
12
|
+
* inside stroke, sized from its allocated `layoutBounds`.
|
|
13
|
+
*
|
|
14
|
+
* Split out of {@link ChartCanvas} (the filled + gridded backdrop) so it can be
|
|
15
|
+
* placed *after* the marks in the tree — the box then frames the plot **over**
|
|
16
|
+
* them, so a line or a column running to the edge tucks cleanly under the border
|
|
17
|
+
* rather than sitting on top of it.
|
|
18
|
+
*/
|
|
19
|
+
export class ChartBorder extends Node2D {
|
|
20
|
+
/**
|
|
21
|
+
* This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
|
|
22
|
+
* paint props it carries — see {@link declarePaints}.
|
|
23
|
+
*/
|
|
24
|
+
declareAssets(assets) {
|
|
25
|
+
super.declareAssets(assets);
|
|
26
|
+
declarePaints(this, assets);
|
|
27
|
+
}
|
|
28
|
+
renderSelf(ctx) {
|
|
29
|
+
const W = this.layoutBounds.width;
|
|
30
|
+
const H = this.layoutBounds.height;
|
|
31
|
+
if (W <= 0 || H <= 0)
|
|
32
|
+
return;
|
|
33
|
+
// Empty rect (no fill) with the themed stroke, so the frame sits over the
|
|
34
|
+
// marks but the box interior stays clear.
|
|
35
|
+
ctx.draw(new Graphics2D().rect({ x: 0, y: 0, width: W, height: H }).stroke(this.stroke));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
__decorate([
|
|
39
|
+
property({
|
|
40
|
+
default: DEFAULT_PLOT_AREA.stroke,
|
|
41
|
+
mapper: strokeOps.resolve,
|
|
42
|
+
tween: strokeOps.lerp,
|
|
43
|
+
})
|
|
44
|
+
], ChartBorder.prototype, "stroke", void 0);
|
|
45
|
+
//# sourceMappingURL=chart-border.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-border.js","sourceRoot":"","sources":["../../src/kit/chart-border.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAAQ,GAIT,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAW5D;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAwB;IAQvD;;;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,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAA;QACjC,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAA;QAClC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAM;QAE5B,0EAA0E;QAC1E,0CAA0C;QAC1C,GAAG,CAAC,IAAI,CACN,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAC/E,CAAA;IACH,CAAC;CACF;AAtBS;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,iBAAiB,CAAC,MAAM;QACjC,MAAM,EAAE,SAAS,CAAC,OAAO;QACzB,KAAK,EAAE,SAAS,CAAC,IAAI;KACtB,CAAC;2CACoB","sourcesContent":["import {\n type AssetScope,\n Graphics2D,\n Node2D,\n strokeOps,\n property,\n type Node2DProps,\n type RenderContext2D,\n type Stroke,\n} from \"@motionscript/core\"\n\nimport { DEFAULT_PLOT_AREA } from \"./shared\"\nimport { declarePaints } from \"@motionscript/core/component\"\n\nexport interface ChartBorderProps extends Node2DProps {\n /**\n * The plot's thick frame stroke. The stroke resolver's default `align` is\n * `'inside'`, so the whole weight sits within the layout box unless the theme\n * overrides it.\n */\n stroke: Stroke\n}\n\n/**\n * The thick **frame** around a cartesian chart's plot: an empty rect wearing an\n * inside stroke, sized from its allocated `layoutBounds`.\n *\n * Split out of {@link ChartCanvas} (the filled + gridded backdrop) so it can be\n * placed *after* the marks in the tree — the box then frames the plot **over**\n * them, so a line or a column running to the edge tucks cleanly under the border\n * rather than sitting on top of it.\n */\nexport class ChartBorder extends Node2D<ChartBorderProps> {\n @property({\n default: DEFAULT_PLOT_AREA.stroke,\n mapper: strokeOps.resolve,\n tween: strokeOps.lerp,\n })\n declare stroke: Stroke\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 W = this.layoutBounds.width\n const H = this.layoutBounds.height\n if (W <= 0 || H <= 0) return\n\n // Empty rect (no fill) with the themed stroke, so the frame sits over the\n // marks but the box interior stays clear.\n ctx.draw(\n new Graphics2D().rect({ x: 0, y: 0, width: W, height: H }).stroke(this.stroke)\n )\n }\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type AssetScope, Node2D, type Fill, type Node2DProps, type RenderContext2D, type Shadow, type Stroke } from "@motionscript/core";
|
|
2
|
+
import { type Range } from "./shared.js";
|
|
3
|
+
export interface ChartCanvasProps extends Node2DProps {
|
|
4
|
+
/** Fill of the plot panel behind the marks. */
|
|
5
|
+
fill: Fill;
|
|
6
|
+
/** Drop shadow of the panel. Default none. */
|
|
7
|
+
shadow: Shadow;
|
|
8
|
+
/** Stroke of the vertical grid lines (one per {@link xMarkers}). */
|
|
9
|
+
xGridStroke: Stroke;
|
|
10
|
+
/** Stroke of the horizontal grid lines (one per {@link yMarkers}). */
|
|
11
|
+
yGridStroke: Stroke;
|
|
12
|
+
/**
|
|
13
|
+
* Data-unit x positions to draw a vertical grid line at — one per horizontal
|
|
14
|
+
* axis marker, so a line lands under every marker regardless of spacing.
|
|
15
|
+
* Positions at (or past) an {@link xExtent} edge coincide with the border and
|
|
16
|
+
* are skipped. Pass an empty list for a chart whose horizontal axis is
|
|
17
|
+
* categorical and so has no numeric position to rule at.
|
|
18
|
+
*/
|
|
19
|
+
xMarkers: number[];
|
|
20
|
+
/** Data-unit y positions to draw a horizontal grid line at. */
|
|
21
|
+
yMarkers: number[];
|
|
22
|
+
/** `[min, max]` of the horizontal scale — maps {@link xMarkers} into the panel. */
|
|
23
|
+
xExtent: Range;
|
|
24
|
+
/** `[min, max]` of the vertical scale — maps {@link yMarkers} into the panel. */
|
|
25
|
+
yExtent: Range;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The plot **backdrop** of a cartesian chart: a filled panel with a grid of
|
|
29
|
+
* faint lines spanning both directions across it. Drawn as one {@link Graphics2D}
|
|
30
|
+
* command list, sized from its allocated `layoutBounds` and centred on the node
|
|
31
|
+
* origin.
|
|
32
|
+
*
|
|
33
|
+
* The thick frame is a **separate** {@link ChartBorder} node so it can be drawn
|
|
34
|
+
* *over* the marks while this panel sits under them. Grid lines are placed from
|
|
35
|
+
* the axis marker positions (in data units) mapped into the panel through
|
|
36
|
+
* {@link ChartCanvasProps.xExtent}/`yExtent` — so each line lands under its
|
|
37
|
+
* marker whether or not the markers are evenly spaced.
|
|
38
|
+
*/
|
|
39
|
+
export declare class ChartCanvas extends Node2D<ChartCanvasProps> {
|
|
40
|
+
fill: Fill;
|
|
41
|
+
shadow: Shadow;
|
|
42
|
+
xGridStroke: Stroke;
|
|
43
|
+
yGridStroke: Stroke;
|
|
44
|
+
xMarkers: number[];
|
|
45
|
+
yMarkers: number[];
|
|
46
|
+
xExtent: Range;
|
|
47
|
+
yExtent: Range;
|
|
48
|
+
/**
|
|
49
|
+
* This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
|
|
50
|
+
* paint props it carries — see {@link declarePaints}. The grid strokes are
|
|
51
|
+
* named past the conventional slots, so they are passed explicitly.
|
|
52
|
+
*/
|
|
53
|
+
declareAssets(assets: AssetScope): void;
|
|
54
|
+
protected renderSelf(ctx: RenderContext2D): void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=chart-canvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-canvas.d.ts","sourceRoot":"","sources":["../../src/kit/chart-canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,MAAM,EAKN,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAIL,KAAK,KAAK,EACX,MAAM,UAAU,CAAA;AAGjB,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,+CAA+C;IAC/C,IAAI,EAAE,IAAI,CAAA;IACV,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAA;IACnB,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAA;IACnB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,mFAAmF;IACnF,OAAO,EAAE,KAAK,CAAA;IACd,iFAAiF;IACjF,OAAO,EAAE,KAAK,CAAA;CACf;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,WAAY,SAAQ,MAAM,CAAC,gBAAgB,CAAC;IAM/C,IAAI,EAAE,IAAI,CAAA;IAMV,MAAM,EAAE,MAAM,CAAA;IAMd,WAAW,EAAE,MAAM,CAAA;IAMnB,WAAW,EAAE,MAAM,CAAA;IAC0B,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,KAAK,CAAA;IACd,OAAO,EAAE,KAAK,CAAA;IAEpE;;;;OAIG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAOhD,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;CAqDjD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { Graphics2D, Node2D, fillOps, shadowOps, strokeOps, property, } from "@motionscript/core";
|
|
8
|
+
import { DEFAULT_PLOT_AREA, DEFAULT_X_AXIS, DEFAULT_Y_AXIS, } from "./shared.js";
|
|
9
|
+
import { declarePaints } from "@motionscript/core/component";
|
|
10
|
+
/**
|
|
11
|
+
* The plot **backdrop** of a cartesian chart: a filled panel with a grid of
|
|
12
|
+
* faint lines spanning both directions across it. Drawn as one {@link Graphics2D}
|
|
13
|
+
* command list, sized from its allocated `layoutBounds` and centred on the node
|
|
14
|
+
* origin.
|
|
15
|
+
*
|
|
16
|
+
* The thick frame is a **separate** {@link ChartBorder} node so it can be drawn
|
|
17
|
+
* *over* the marks while this panel sits under them. Grid lines are placed from
|
|
18
|
+
* the axis marker positions (in data units) mapped into the panel through
|
|
19
|
+
* {@link ChartCanvasProps.xExtent}/`yExtent` — so each line lands under its
|
|
20
|
+
* marker whether or not the markers are evenly spaced.
|
|
21
|
+
*/
|
|
22
|
+
export class ChartCanvas extends Node2D {
|
|
23
|
+
/**
|
|
24
|
+
* This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
|
|
25
|
+
* paint props it carries — see {@link declarePaints}. The grid strokes are
|
|
26
|
+
* named past the conventional slots, so they are passed explicitly.
|
|
27
|
+
*/
|
|
28
|
+
declareAssets(assets) {
|
|
29
|
+
super.declareAssets(assets);
|
|
30
|
+
declarePaints(this, assets, {
|
|
31
|
+
strokes: [this.xGridStroke, this.yGridStroke],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
renderSelf(ctx) {
|
|
35
|
+
const W = this.layoutBounds.width;
|
|
36
|
+
const H = this.layoutBounds.height;
|
|
37
|
+
if (W <= 0 || H <= 0)
|
|
38
|
+
return;
|
|
39
|
+
// Plot panel, centred on the origin (node space is y-up, origin centre).
|
|
40
|
+
ctx.draw(new Graphics2D()
|
|
41
|
+
.rect({ x: 0, y: 0, width: W, height: H })
|
|
42
|
+
.shadow(this.shadow)
|
|
43
|
+
.fill(this.fill));
|
|
44
|
+
const [xMin, xMax] = this.xExtent;
|
|
45
|
+
const [yMin, yMax] = this.yExtent;
|
|
46
|
+
// Fraction of a marker across its extent; guard a zero-width extent.
|
|
47
|
+
const xFrac = (v) => (xMax <= xMin ? 0 : (v - xMin) / (xMax - xMin));
|
|
48
|
+
const yFrac = (v) => (yMax <= yMin ? 0 : (v - yMin) / (yMax - yMin));
|
|
49
|
+
// Skip markers landing on (or outside) the edges — they'd sit under the border.
|
|
50
|
+
const interior = (f) => f > 1e-6 && f < 1 - 1e-6;
|
|
51
|
+
const xStroke = this.xGridStroke[0];
|
|
52
|
+
if (xStroke) {
|
|
53
|
+
const xGrid = new Graphics2D();
|
|
54
|
+
for (const v of this.xMarkers) {
|
|
55
|
+
const f = xFrac(v);
|
|
56
|
+
if (!interior(f))
|
|
57
|
+
continue;
|
|
58
|
+
xGrid.rect({
|
|
59
|
+
x: -W / 2 + f * W,
|
|
60
|
+
y: 0,
|
|
61
|
+
width: xStroke.weight,
|
|
62
|
+
height: H,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
ctx.draw(xGrid.fill(xStroke.fill));
|
|
66
|
+
}
|
|
67
|
+
const yStroke = this.yGridStroke[0];
|
|
68
|
+
if (yStroke) {
|
|
69
|
+
const yGrid = new Graphics2D();
|
|
70
|
+
for (const v of this.yMarkers) {
|
|
71
|
+
const f = yFrac(v);
|
|
72
|
+
if (!interior(f))
|
|
73
|
+
continue;
|
|
74
|
+
yGrid.rect({
|
|
75
|
+
x: 0,
|
|
76
|
+
y: -H / 2 + f * H,
|
|
77
|
+
width: W,
|
|
78
|
+
height: yStroke.weight,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
ctx.draw(yGrid.fill(yStroke.fill));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
__decorate([
|
|
86
|
+
property({
|
|
87
|
+
default: DEFAULT_PLOT_AREA.fill,
|
|
88
|
+
mapper: fillOps.resolve,
|
|
89
|
+
tween: fillOps.lerp,
|
|
90
|
+
})
|
|
91
|
+
], ChartCanvas.prototype, "fill", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
property({
|
|
94
|
+
default: DEFAULT_PLOT_AREA.shadow,
|
|
95
|
+
mapper: shadowOps.resolve,
|
|
96
|
+
tween: shadowOps.lerp,
|
|
97
|
+
})
|
|
98
|
+
], ChartCanvas.prototype, "shadow", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
property({
|
|
101
|
+
default: DEFAULT_X_AXIS.lineStyle,
|
|
102
|
+
mapper: strokeOps.resolve,
|
|
103
|
+
tween: strokeOps.lerp,
|
|
104
|
+
})
|
|
105
|
+
], ChartCanvas.prototype, "xGridStroke", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
property({
|
|
108
|
+
default: DEFAULT_Y_AXIS.lineStyle,
|
|
109
|
+
mapper: strokeOps.resolve,
|
|
110
|
+
tween: strokeOps.lerp,
|
|
111
|
+
})
|
|
112
|
+
], ChartCanvas.prototype, "yGridStroke", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
property({ default: () => [] })
|
|
115
|
+
], ChartCanvas.prototype, "xMarkers", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
property({ default: () => [] })
|
|
118
|
+
], ChartCanvas.prototype, "yMarkers", void 0);
|
|
119
|
+
__decorate([
|
|
120
|
+
property({ default: () => [0, 1] })
|
|
121
|
+
], ChartCanvas.prototype, "xExtent", void 0);
|
|
122
|
+
__decorate([
|
|
123
|
+
property({ default: () => [0, 1] })
|
|
124
|
+
], ChartCanvas.prototype, "yExtent", void 0);
|
|
125
|
+
//# sourceMappingURL=chart-canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-canvas.js","sourceRoot":"","sources":["../../src/kit/chart-canvas.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,OAAO,EACP,SAAS,EACT,SAAS,EACT,QAAQ,GAOT,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,GAEf,MAAM,UAAU,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C,EAAE,CAAC,CAAU,EAAE,CAAC;4CAAuB;AACd;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAU,EAAE,CAAC;4CAAuB","sourcesContent":["import {\n type AssetScope,\n Graphics2D,\n Node2D,\n fillOps,\n shadowOps,\n strokeOps,\n property,\n type Fill,\n type Node2DProps,\n type RenderContext2D,\n type Shadow,\n type Stroke,\n type StrokeResolved,\n} from \"@motionscript/core\"\n\nimport {\n DEFAULT_PLOT_AREA,\n DEFAULT_X_AXIS,\n DEFAULT_Y_AXIS,\n type Range,\n} from \"./shared\"\nimport { declarePaints } from \"@motionscript/core/component\"\n\nexport interface ChartCanvasProps extends Node2DProps {\n /** Fill of the plot panel behind the marks. */\n fill: Fill\n /** Drop shadow of the panel. Default none. */\n shadow: Shadow\n /** Stroke of the vertical grid lines (one per {@link xMarkers}). */\n xGridStroke: Stroke\n /** Stroke of the horizontal grid lines (one per {@link yMarkers}). */\n yGridStroke: Stroke\n /**\n * Data-unit x positions to draw a vertical grid line at — one per horizontal\n * axis marker, so a line lands under every marker regardless of spacing.\n * Positions at (or past) an {@link xExtent} edge coincide with the border and\n * are skipped. Pass an empty list for a chart whose horizontal axis is\n * categorical and so has no numeric position to rule at.\n */\n xMarkers: number[]\n /** Data-unit y positions to draw a horizontal grid line at. */\n yMarkers: number[]\n /** `[min, max]` of the horizontal scale — maps {@link xMarkers} into the panel. */\n xExtent: Range\n /** `[min, max]` of the vertical scale — maps {@link yMarkers} into the panel. */\n yExtent: Range\n}\n\n/**\n * The plot **backdrop** of a cartesian chart: a filled panel with a grid of\n * faint lines spanning both directions across it. Drawn as one {@link Graphics2D}\n * command list, sized from its allocated `layoutBounds` and centred on the node\n * origin.\n *\n * The thick frame is a **separate** {@link ChartBorder} node so it can be drawn\n * *over* the marks while this panel sits under them. Grid lines are placed from\n * the axis marker positions (in data units) mapped into the panel through\n * {@link ChartCanvasProps.xExtent}/`yExtent` — so each line lands under its\n * marker whether or not the markers are evenly spaced.\n */\nexport class ChartCanvas extends Node2D<ChartCanvasProps> {\n @property({\n default: DEFAULT_PLOT_AREA.fill,\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n @property({\n default: DEFAULT_PLOT_AREA.shadow,\n mapper: shadowOps.resolve,\n tween: shadowOps.lerp,\n })\n declare shadow: Shadow\n @property({\n default: DEFAULT_X_AXIS.lineStyle,\n mapper: strokeOps.resolve,\n tween: strokeOps.lerp,\n })\n declare xGridStroke: Stroke\n @property({\n default: DEFAULT_Y_AXIS.lineStyle,\n mapper: strokeOps.resolve,\n tween: strokeOps.lerp,\n })\n declare yGridStroke: Stroke\n @property({ default: () => [] as number[] }) declare xMarkers: number[]\n @property({ default: () => [] as number[] }) declare yMarkers: number[]\n @property({ default: () => [0, 1] as Range }) declare xExtent: Range\n @property({ default: () => [0, 1] as Range }) declare yExtent: Range\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}. The grid strokes are\n * named past the conventional slots, so they are passed explicitly.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets, {\n strokes: [this.xGridStroke as StrokeResolved[], this.yGridStroke as StrokeResolved[]],\n })\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const W = this.layoutBounds.width\n const H = this.layoutBounds.height\n if (W <= 0 || H <= 0) return\n\n // Plot panel, centred on the origin (node space is y-up, origin centre).\n ctx.draw(\n new Graphics2D()\n .rect({ x: 0, y: 0, width: W, height: H })\n .shadow(this.shadow)\n .fill(this.fill)\n )\n\n const [xMin, xMax] = this.xExtent\n const [yMin, yMax] = this.yExtent\n // Fraction of a marker across its extent; guard a zero-width extent.\n const xFrac = (v: number) => (xMax <= xMin ? 0 : (v - xMin) / (xMax - xMin))\n const yFrac = (v: number) => (yMax <= yMin ? 0 : (v - yMin) / (yMax - yMin))\n // Skip markers landing on (or outside) the edges — they'd sit under the border.\n const interior = (f: number) => f > 1e-6 && f < 1 - 1e-6\n\n const xStroke = (this.xGridStroke as StrokeResolved[])[0]\n if (xStroke) {\n const xGrid = new Graphics2D()\n for (const v of this.xMarkers) {\n const f = xFrac(v)\n if (!interior(f)) continue\n xGrid.rect({\n x: -W / 2 + f * W,\n y: 0,\n width: xStroke.weight,\n height: H,\n })\n }\n ctx.draw(xGrid.fill(xStroke.fill))\n }\n\n const yStroke = (this.yGridStroke as StrokeResolved[])[0]\n if (yStroke) {\n const yGrid = new Graphics2D()\n for (const v of this.yMarkers) {\n const f = yFrac(v)\n if (!interior(f)) continue\n yGrid.rect({\n x: 0,\n y: -H / 2 + f * H,\n width: W,\n height: yStroke.weight,\n })\n }\n ctx.draw(yGrid.fill(yStroke.fill))\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Rect, type CommandArgs, type Fill, type NodeConfig, type RectProps } from "@motionscript/core";
|
|
2
|
+
import { type Seekable } from "@motionscript/core/component";
|
|
3
|
+
import { type ChartSeries, type LegendConfig } from "./shared.js";
|
|
4
|
+
export interface ChartLegendProps extends RectProps {
|
|
5
|
+
/**
|
|
6
|
+
* One entry per series: legend `label`, its `enabled` default, and — through
|
|
7
|
+
* {@link ChartLegendProps.swatches} — the colour its chip is painted. A series
|
|
8
|
+
* that starts enabled (the default) is added to the row up front; one that
|
|
9
|
+
* starts `false` is hidden until a later {@link ChartLegend.showSeries}.
|
|
10
|
+
*/
|
|
11
|
+
series: ChartSeries[];
|
|
12
|
+
/**
|
|
13
|
+
* The swatch colour for each series, by index — resolved by the chart, whose
|
|
14
|
+
* business it is whether a series' colour comes out of a stroke palette (a
|
|
15
|
+
* line) or a fill palette (a bar). Shorter than the series list means the
|
|
16
|
+
* missing entries fall back to white.
|
|
17
|
+
*/
|
|
18
|
+
swatches: Fill[];
|
|
19
|
+
/** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */
|
|
20
|
+
legend: LegendConfig;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out
|
|
24
|
+
* left-to-right with the theme's `itemGap`. Each entry pairs the series label
|
|
25
|
+
* with a rounded colour swatch; only the swatch carries the series colour, the
|
|
26
|
+
* caption reads in the legend's neutral ink.
|
|
27
|
+
*
|
|
28
|
+
* {@link showSeries}/{@link hideSeries} flip a series on or off — showing one
|
|
29
|
+
* adds its entry back into the row at its stable series position and grows it
|
|
30
|
+
* in, hiding one shrinks it away and removes it. So the row only ever holds the
|
|
31
|
+
* currently-enabled series, in series order, and closes the gap when one leaves.
|
|
32
|
+
*
|
|
33
|
+
* This node *is* the row, so the parent places it (centred below the chart) and
|
|
34
|
+
* it hugs its entries.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ChartLegend extends Rect {
|
|
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;
|
|
42
|
+
/**
|
|
43
|
+
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
44
|
+
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
45
|
+
* natural size.
|
|
46
|
+
*
|
|
47
|
+
* This replaces adding and removing the entry from the row, which is what
|
|
48
|
+
* `showSeries`/`hideSeries` used to do. That could not be a command: a command
|
|
49
|
+
* is asked what it looks like at a time, and "is this node a child" is not a
|
|
50
|
+
* value a time can produce — the tree either contains it or it doesn't, and
|
|
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
|
+
* A plain array rather than reactive props because the count is the series
|
|
55
|
+
* count, which is data. The entries' props are bound to it, so writing one
|
|
56
|
+
* still moves the layout.
|
|
57
|
+
*/
|
|
58
|
+
private reveal;
|
|
59
|
+
/**
|
|
60
|
+
* Each entry's natural width, last time it was fully shown.
|
|
61
|
+
*
|
|
62
|
+
* A collapse needs numeric endpoints — `lerpSizeInput` snaps between a token
|
|
63
|
+
* and a number rather than interpolating — and `"hug"` is not a number until
|
|
64
|
+
* something measures it. Refreshed on every frame an entry is at full reveal
|
|
65
|
+
* (see {@link widthFor}), so it is current by the time a hide starts, and it
|
|
66
|
+
* tracks a relabelled series or a restyled legend without being told.
|
|
67
|
+
*/
|
|
68
|
+
private natural;
|
|
69
|
+
constructor(props?: NodeConfig<ChartLegend, ChartLegendProps>);
|
|
70
|
+
/**
|
|
71
|
+
* An entry's width for its current reveal.
|
|
72
|
+
*
|
|
73
|
+
* `"hug"` at full reveal rather than the pinned number, so a shown entry stays
|
|
74
|
+
* responsive to its own content; the number only takes over while it is
|
|
75
|
+
* collapsing, which is the only time a token cannot express it.
|
|
76
|
+
*
|
|
77
|
+
* Records the natural width as a side effect, which is the honest place for it:
|
|
78
|
+
* this runs inside a binding, so it is already reading the layout every frame,
|
|
79
|
+
* and the value it wants is the one the layout just produced. It writes a plain
|
|
80
|
+
* array rather than a signal, so nothing is invalidated by it.
|
|
81
|
+
*/
|
|
82
|
+
private widthFor;
|
|
83
|
+
/** One entry: the series caption beside its colour swatch. */
|
|
84
|
+
private buildItem;
|
|
85
|
+
/** True if series `index` is showing at all — see {@link reveal}. */
|
|
86
|
+
isEnabled(index: number): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Grow series `index`'s entry back in at its series-order position, the
|
|
89
|
+
* siblings sliding over to make room.
|
|
90
|
+
*
|
|
91
|
+
* A reveal tween rather than an animated `addChildAt`. The entry never left —
|
|
92
|
+
* see {@link reveal} — so there is no add to have happened, and the whole
|
|
93
|
+
* thing is a function of `t`.
|
|
94
|
+
*/
|
|
95
|
+
showSeries(args: CommandArgs<{
|
|
96
|
+
index: number;
|
|
97
|
+
}>): Seekable;
|
|
98
|
+
/**
|
|
99
|
+
* Shrink series `index`'s entry away, the gap closing behind it — the mirror
|
|
100
|
+
* of {@link showSeries}.
|
|
101
|
+
*/
|
|
102
|
+
hideSeries(args: CommandArgs<{
|
|
103
|
+
index: number;
|
|
104
|
+
}>): Seekable;
|
|
105
|
+
/**
|
|
106
|
+
* Ramp one entry's reveal to `target`.
|
|
107
|
+
*
|
|
108
|
+
* `from` is read when the command is built, which for a driven scene is with
|
|
109
|
+
* the node in the state its own start time implies — so a hide that follows a
|
|
110
|
+
* show starts where the show left it rather than at whatever the node happens
|
|
111
|
+
* to hold now.
|
|
112
|
+
*/
|
|
113
|
+
private revealTo;
|
|
114
|
+
/**
|
|
115
|
+
* Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that
|
|
116
|
+
* one back to full — the legend half of a chart's `spotlightSeries`. Entries
|
|
117
|
+
* stay in place; only their opacity moves, so the row doesn't reflow.
|
|
118
|
+
*
|
|
119
|
+
* Only the currently-shown entries are touched — a hidden series' entry is
|
|
120
|
+
* left as {@link hideSeries} left it.
|
|
121
|
+
*/
|
|
122
|
+
spotlightSeries(args: CommandArgs<{
|
|
123
|
+
index: number;
|
|
124
|
+
}>): Seekable;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=chart-legend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-legend.d.ts","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAMJ,KAAK,WAAW,EAEhB,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAEnF,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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