@motionscript/charts 0.1.0-alpha.3 → 0.1.0-alpha.5
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 +41 -0
- package/LICENSE +201 -201
- package/NOTICE +48 -0
- package/README.md +85 -0
- package/dist/bar-chart/bar-chart.d.ts +28 -13
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +60 -56
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.js.map +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.js +3 -3
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-5ZPBV6BU.js +2 -0
- package/dist/browser/chunks/chunk-5ZPBV6BU.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 +3 -2
- package/dist/engine.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +4 -25
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +31 -55
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/shared.d.ts +29 -6
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +64 -8
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +2 -2
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +9 -1
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +32 -8
- 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 +19 -4
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +1 -1
- package/dist/line-chart/x-scale.js +1 -1
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +2 -2
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +9 -7
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.js +4 -4
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +13 -4
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +44 -14
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +3 -3
- package/dist/pie-chart/shared.js +3 -3
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +6 -5
- package/registry.json +23 -23
- package/src/bar-chart/bar-chart.ts +820 -814
- package/src/bar-chart/category-axis.ts +177 -177
- package/src/bar-chart/chart-bars.ts +310 -310
- package/src/bar-chart/index.ts +31 -31
- package/src/bar-chart/shared.ts +354 -354
- package/src/engine.ts +26 -26
- package/src/index.ts +5 -5
- package/src/kit/chart-border.ts +61 -61
- package/src/kit/chart-canvas.ts +157 -157
- package/src/kit/chart-legend.ts +245 -250
- package/src/kit/shared.ts +733 -675
- package/src/kit/vertical-axis.ts +224 -224
- package/src/line-chart/chart-line.ts +208 -208
- package/src/line-chart/chart-region.ts +135 -135
- package/src/line-chart/horizontal-axis.ts +202 -202
- package/src/line-chart/index.ts +39 -39
- package/src/line-chart/line-chart.ts +961 -929
- package/src/line-chart/shared.ts +473 -459
- package/src/line-chart/x-scale.ts +367 -367
- package/src/nodes.ts +20 -20
- package/src/pie-chart/index.ts +37 -37
- package/src/pie-chart/pie-chart.ts +383 -381
- package/src/pie-chart/pie-legend.ts +159 -159
- package/src/pie-chart/pie-ring.ts +935 -903
- package/src/pie-chart/shared.ts +490 -490
- package/dist/browser/chunks/chunk-RMHQ6GYU.js +0 -2
- package/dist/browser/chunks/chunk-RMHQ6GYU.js.map +0 -7
package/dist/browser/kit.js
CHANGED
|
@@ -1,2 +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-
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,J,K,L,M,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-5ZPBV6BU.js";export{d as CHART_PALETTE,J as ChartBorder,K as ChartCanvas,L as ChartLegend,n as DEFAULT_LEGEND,m as DEFAULT_PLOT_AREA,e as DEFAULT_SERIES_COLORS,p as DEFAULT_SERIES_FILLS,o as DEFAULT_SERIES_STROKES,k as DEFAULT_X_AXIS,l as DEFAULT_Y_AXIS,f as SPOTLIGHT_DIM,M as VerticalAxis,c as axisTweenTarget,g as clampUnit,I as enterBudget,D as formatMarker,F as formatPercent,r as lerpAxisConfig,b as lerpAxisDomain,v as lerpLegendConfig,t as lerpPlotArea,z as lerpSeriesFills,x as lerpSeriesStrokes,E as markerStep,G as markerValues,H as niceStep,h as num,j as numericFields,q as resolveAxisConfig,a as resolveAxisDomain,u as resolveLegendConfig,C as resolvePalettePaint,s as resolvePlotArea,B as resolveSeriesFill,y as resolveSeriesFills,A as resolveSeriesStroke,w as resolveSeriesStrokes,i as text};
|
|
2
2
|
//# sourceMappingURL=kit.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motionscript/charts",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": "dist/browser/index.js",
|
|
6
6
|
"./kit": "dist/browser/kit.js"
|
|
@@ -8,5 +8,6 @@
|
|
|
8
8
|
"peers": [
|
|
9
9
|
"@motionscript/sdk"
|
|
10
10
|
],
|
|
11
|
-
"assets": {}
|
|
11
|
+
"assets": {},
|
|
12
|
+
"thirdParty": []
|
|
12
13
|
}
|
package/dist/engine.js.map
CHANGED
|
@@ -1 +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,6BAA6B,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/sdk/component\"\n"]}
|
|
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,6BAA6B,CAAA","sourcesContent":["/**\r\n * The chart **kit**: everything the three charts share, and the one thing a\r\n * copied chart does not copy.\r\n *\r\n * `ms add line-chart` writes `line-chart/*` into your project and rewrites its\r\n * reach for these to `@motionscript/charts`, so the plot panel, the value\r\n * axis, the legend and the number formatting stay a real dependency. That is\r\n * not a size decision — it is the only arrangement that works.\r\n *\r\n * A chart identifies its own parts, and the engine keys signal machinery to\r\n * class identity: `@property` installs against the class it was applied with,\r\n * and the renderer asks `instanceof` about what it is drawing. Copy\r\n * `VerticalAxis` alongside your fork and there are now two of it — two classes\r\n * answering one name, and whichever one your chart did not get renders as\r\n * nothing at all, with no error. Keeping the kit external makes that\r\n * impossible rather than unlikely.\r\n *\r\n * It also means a fix to the axis reaches a forked chart without a re-add,\r\n * which is the half of the bargain you get back for it.\r\n */\r\nexport * from \"./kit/shared\"\r\nexport * from \"./kit/chart-border\"\r\nexport * from \"./kit/chart-canvas\"\r\nexport * from \"./kit/chart-legend\"\r\nexport * from \"./kit/vertical-axis\"\r\nexport * from \"@motionscript/sdk/component\"\r\n"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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"]}
|
|
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\";\r\nexport * from \"./bar-chart\";\r\nexport * from \"./pie-chart\";\r\nexport * from \"./engine\";\r\nexport { NODES } from \"./nodes\";\r\n"]}
|
|
@@ -1 +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,mBAAmB,CAAA;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAW3D;;;;;;;;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/sdk\"\n\nimport { DEFAULT_PLOT_AREA } from \"./shared\"\nimport { declarePaints } from \"@motionscript/sdk/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"]}
|
|
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,mBAAmB,CAAA;AAE1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAW3D;;;;;;;;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 {\r\n type AssetScope,\r\n Graphics2D,\r\n Node2D,\r\n strokeOps,\r\n property,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { DEFAULT_PLOT_AREA } from \"./shared\"\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\n\r\nexport interface ChartBorderProps extends Node2DProps {\r\n /**\r\n * The plot's thick frame stroke. The stroke resolver's default `align` is\r\n * `'inside'`, so the whole weight sits within the layout box unless the theme\r\n * overrides it.\r\n */\r\n stroke: Stroke\r\n}\r\n\r\n/**\r\n * The thick **frame** around a cartesian chart's plot: an empty rect wearing an\r\n * inside stroke, sized from its allocated `layoutBounds`.\r\n *\r\n * Split out of {@link ChartCanvas} (the filled + gridded backdrop) so it can be\r\n * placed *after* the marks in the tree — the box then frames the plot **over**\r\n * them, so a line or a column running to the edge tucks cleanly under the border\r\n * rather than sitting on top of it.\r\n */\r\nexport class ChartBorder extends Node2D<ChartBorderProps> {\r\n @property({\r\n default: DEFAULT_PLOT_AREA.stroke,\r\n mapper: strokeOps.resolve,\r\n tween: strokeOps.lerp,\r\n })\r\n declare stroke: Stroke\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const W = this.layoutBounds.width\r\n const H = this.layoutBounds.height\r\n if (W <= 0 || H <= 0) return\r\n\r\n // Empty rect (no fill) with the themed stroke, so the frame sits over the\r\n // marks but the box interior stays clear.\r\n ctx.draw(\r\n new Graphics2D().rect({ x: 0, y: 0, width: W, height: H }).stroke(this.stroke)\r\n )\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-canvas.js","sourceRoot":"","sources":["../../src/kit/chart-canvas.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM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CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;6CAA2B;AACjB;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,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/sdk\"\n\nimport {\n DEFAULT_PLOT_AREA,\n DEFAULT_X_AXIS,\n DEFAULT_Y_AXIS,\n type Range,\n} from \"./shared\"\nimport { declarePaints } from \"@motionscript/sdk/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"]}
|
|
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,mBAAmB,CAAA;AAE1B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,GAEf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AA2B3D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAwB;IA8BvD;;;;OAIG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE;YAC1B,OAAO,EAAE,CAAC,IAAI,CAAC,WAA+B,EAAE,IAAI,CAAC,WAA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C,IAAI,CAAC,CAAC,CAAA;QACpC,CAAC;IACH,CAAC;CACF;AAzFS;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,iBAAiB,CAAC,IAAI;QAC/B,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;yCACgB;AAMV;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,iBAAiB,CAAC,MAAM;QACjC,MAAM,EAAE,SAAS,CAAC,OAAO;QACzB,KAAK,EAAE,SAAS,CAAC,IAAI;KACtB,CAAC;2CACoB;AAMd;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,cAAc,CAAC,SAAS;QACjC,MAAM,EAAE,SAAS,CAAC,OAAO;QACzB,KAAK,EAAE,SAAS,CAAC,IAAI;KACtB,CAAC;gDACyB;AAMnB;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,cAAc,CAAC,SAAS;QACjC,MAAM,EAAE,SAAS,CAAC,OAAO;QACzB,KAAK,EAAE,SAAS,CAAC,IAAI;KACtB,CAAC;gDACyB;AAC0B;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;6CAA2B;AAClB;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;6CAA2B;AACjB;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,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 {\r\n type AssetScope,\r\n Graphics2D,\r\n Node2D,\r\n fillOps,\r\n shadowOps,\r\n strokeOps,\r\n property,\r\n type Fill,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n type Shadow,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\"\r\n\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\nimport { declarePaints } from \"@motionscript/sdk/component\"\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\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. Drawn as one {@link Graphics2D}\r\n * command list, sized from its allocated `layoutBounds` and centred on the node\r\n * 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 class ChartCanvas extends Node2D<ChartCanvasProps> {\r\n @property({\r\n default: DEFAULT_PLOT_AREA.fill,\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare fill: Fill\r\n @property({\r\n default: DEFAULT_PLOT_AREA.shadow,\r\n mapper: shadowOps.resolve,\r\n tween: shadowOps.lerp,\r\n })\r\n declare shadow: Shadow\r\n @property({\r\n default: DEFAULT_X_AXIS.lineStyle,\r\n mapper: strokeOps.resolve,\r\n tween: strokeOps.lerp,\r\n })\r\n declare xGridStroke: Stroke\r\n @property({\r\n default: DEFAULT_Y_AXIS.lineStyle,\r\n mapper: strokeOps.resolve,\r\n tween: strokeOps.lerp,\r\n })\r\n declare yGridStroke: Stroke\r\n @property({ default: () => [] as number[] }) declare xMarkers: number[]\r\n @property({ default: () => [] as number[] }) declare yMarkers: number[]\r\n @property({ default: () => [0, 1] as Range }) declare xExtent: Range\r\n @property({ default: () => [0, 1] as Range }) declare yExtent: Range\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}. The grid strokes are\r\n * named past the conventional slots, so they are passed explicitly.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets, {\r\n strokes: [this.xGridStroke as StrokeResolved[], this.yGridStroke as StrokeResolved[]],\r\n })\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const W = this.layoutBounds.width\r\n const H = this.layoutBounds.height\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(\r\n new Graphics2D()\r\n .rect({ x: 0, y: 0, width: W, height: H })\r\n .shadow(this.shadow)\r\n .fill(this.fill)\r\n )\r\n\r\n const [xMin, xMax] = this.xExtent\r\n const [yMin, yMax] = this.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 = (this.xGridStroke as StrokeResolved[])[0]\r\n if (xStroke) {\r\n const xGrid = new Graphics2D()\r\n for (const v of this.xMarkers) {\r\n const f = xFrac(v)\r\n if (!interior(f)) continue\r\n xGrid.rect({\r\n x: -W / 2 + f * W,\r\n y: 0,\r\n width: xStroke.weight,\r\n height: H,\r\n })\r\n }\r\n ctx.draw(xGrid.fill(xStroke.fill))\r\n }\r\n\r\n const yStroke = (this.yGridStroke as StrokeResolved[])[0]\r\n if (yStroke) {\r\n const yGrid = new Graphics2D()\r\n for (const v of this.yMarkers) {\r\n const f = yFrac(v)\r\n if (!interior(f)) continue\r\n yGrid.rect({\r\n x: 0,\r\n y: -H / 2 + f * H,\r\n width: W,\r\n height: yStroke.weight,\r\n })\r\n }\r\n ctx.draw(yGrid.fill(yStroke.fill))\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -51,35 +51,14 @@ export declare class ChartLegend extends Rect {
|
|
|
51
51
|
* getting there means having run the add. Collapsed-but-present is the same
|
|
52
52
|
* picture reached by a route that *is* a function of `t`.
|
|
53
53
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
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
|
|
56
58
|
* still moves the layout.
|
|
57
59
|
*/
|
|
58
60
|
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
61
|
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
62
|
/** One entry: the series caption beside its colour swatch. */
|
|
84
63
|
private buildItem;
|
|
85
64
|
/** True if series `index` is showing at all — see {@link reveal}. */
|
|
@@ -1 +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,
|
|
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,EAET,KAAK,UAAU,EACf,KAAK,SAAS,EAGf,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAElF,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;AAuBD;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAY,SAAQ,IAAI;IACuB,MAAM,EAAE,WAAW,EAAE,CAAA;IAC5B,QAAQ,EAAE,IAAI,EAAE,CAAA;IACpB,MAAM,EAAE,YAAY,CAAA;IAEnE,6EAA6E;IAC7E,OAAO,CAAC,KAAK,CAAoB;IACjC;;;;;;;;;;;;;;;;;OAiBG;IACH,QAA6D,MAAM,CAAU;gBAEjE,KAAK,CAAC,EAAE,UAAU,CAAC,WAAW,EAAE,gBAAgB,CAAC;IA4B7D,8DAA8D;IAC9D,OAAO,CAAC,SAAS;IAgCjB,qEAAqE;IACrE,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;;;OAOG;IAEH,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,QAAQ;IAK1D;;;OAGG;IAEH,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,QAAQ;IAK1D;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ;IAehB;;;;;;;OAOG;IAEH,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,QAAQ;CAehE"}
|
package/dist/kit/chart-legend.js
CHANGED
|
@@ -7,6 +7,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Rect, Text, command, easeOut, property, textOps, } from "@motionscript/sdk";
|
|
8
8
|
import { drive, hold, together } from "@motionscript/sdk/component";
|
|
9
9
|
import { DEFAULT_LEGEND, SPOTLIGHT_DIM, } from "./shared.js";
|
|
10
|
+
/**
|
|
11
|
+
* One legend entry. It hugs its caption and swatch; `shown` scales that width from
|
|
12
|
+
* nothing to the whole of it.
|
|
13
|
+
*
|
|
14
|
+
* The width is taken from the content on every measure, at any reveal, so a frame
|
|
15
|
+
* never depends on whether the entry was once seen fully shown. A collapse needs a
|
|
16
|
+
* number to scale, and `"hug"` is not one until something measures it — this is
|
|
17
|
+
* the something.
|
|
18
|
+
*/
|
|
19
|
+
class LegendEntry extends Rect {
|
|
20
|
+
_shown;
|
|
21
|
+
constructor(props, _shown) {
|
|
22
|
+
super(props);
|
|
23
|
+
this._shown = _shown;
|
|
24
|
+
}
|
|
25
|
+
measure(constraints, scope) {
|
|
26
|
+
const size = super.measure(constraints, scope);
|
|
27
|
+
const shown = this._shown();
|
|
28
|
+
return shown >= 1 ? size : { ...size, width: shown * (size.width ?? 0) };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
/**
|
|
11
32
|
* The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out
|
|
12
33
|
* left-to-right with the theme's `itemGap`. Each entry pairs the series label
|
|
@@ -24,33 +45,6 @@ import { DEFAULT_LEGEND, SPOTLIGHT_DIM, } from "./shared.js";
|
|
|
24
45
|
export class ChartLegend extends Rect {
|
|
25
46
|
/** One entry per series. **Every** entry is a child — see {@link reveal}. */
|
|
26
47
|
items = [];
|
|
27
|
-
/**
|
|
28
|
-
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
29
|
-
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
30
|
-
* natural size.
|
|
31
|
-
*
|
|
32
|
-
* This replaces adding and removing the entry from the row, which is what
|
|
33
|
-
* `showSeries`/`hideSeries` used to do. That could not be a command: a command
|
|
34
|
-
* is asked what it looks like at a time, and "is this node a child" is not a
|
|
35
|
-
* value a time can produce — the tree either contains it or it doesn't, and
|
|
36
|
-
* getting there means having run the add. Collapsed-but-present is the same
|
|
37
|
-
* picture reached by a route that *is* a function of `t`.
|
|
38
|
-
*
|
|
39
|
-
* A plain array rather than reactive props because the count is the series
|
|
40
|
-
* count, which is data. The entries' props are bound to it, so writing one
|
|
41
|
-
* still moves the layout.
|
|
42
|
-
*/
|
|
43
|
-
reveal = [];
|
|
44
|
-
/**
|
|
45
|
-
* Each entry's natural width, last time it was fully shown.
|
|
46
|
-
*
|
|
47
|
-
* A collapse needs numeric endpoints — `lerpSizeInput` snaps between a token
|
|
48
|
-
* and a number rather than interpolating — and `"hug"` is not a number until
|
|
49
|
-
* something measures it. Refreshed on every frame an entry is at full reveal
|
|
50
|
-
* (see {@link widthFor}), so it is current by the time a hide starts, and it
|
|
51
|
-
* tracks a relabelled series or a restyled legend without being told.
|
|
52
|
-
*/
|
|
53
|
-
natural = [];
|
|
54
48
|
constructor(props) {
|
|
55
49
|
// `flow` after the spread, with the rest of the geometry: this class *is*
|
|
56
50
|
// the row, so the direction is its own answer and not the caller's. It has
|
|
@@ -69,7 +63,6 @@ export class ChartLegend extends Rect {
|
|
|
69
63
|
// props super() applied. Fixed row geometry last, so it wins over super().
|
|
70
64
|
this.set({ gap: this.legend.itemGap, padding: this.legend.padding });
|
|
71
65
|
this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0));
|
|
72
|
-
this.natural = this.series.map(() => 0);
|
|
73
66
|
this.items = this.series.map((s, i) => this.buildItem(s, i));
|
|
74
67
|
// All of them, in series order. Order is now fixed rather than depending on
|
|
75
68
|
// which siblings happen to be shown, so an entry always comes back where it
|
|
@@ -77,37 +70,15 @@ export class ChartLegend extends Rect {
|
|
|
77
70
|
for (const item of this.items)
|
|
78
71
|
this.add(item);
|
|
79
72
|
}
|
|
80
|
-
/**
|
|
81
|
-
* An entry's width for its current reveal.
|
|
82
|
-
*
|
|
83
|
-
* `"hug"` at full reveal rather than the pinned number, so a shown entry stays
|
|
84
|
-
* responsive to its own content; the number only takes over while it is
|
|
85
|
-
* collapsing, which is the only time a token cannot express it.
|
|
86
|
-
*
|
|
87
|
-
* Records the natural width as a side effect, which is the honest place for it:
|
|
88
|
-
* this runs inside a binding, so it is already reading the layout every frame,
|
|
89
|
-
* and the value it wants is the one the layout just produced. It writes a plain
|
|
90
|
-
* array rather than a signal, so nothing is invalidated by it.
|
|
91
|
-
*/
|
|
92
|
-
widthFor(index) {
|
|
93
|
-
const shown = this.reveal[index] ?? 0;
|
|
94
|
-
if (shown >= 1) {
|
|
95
|
-
const measured = this.items[index]?.measuredWidth ?? 0;
|
|
96
|
-
if (measured > 0)
|
|
97
|
-
this.natural[index] = measured;
|
|
98
|
-
return "hug";
|
|
99
|
-
}
|
|
100
|
-
return shown * (this.natural[index] ?? 0);
|
|
101
|
-
}
|
|
102
73
|
/** One entry: the series caption beside its colour swatch. */
|
|
103
74
|
buildItem(series, index) {
|
|
104
75
|
const marker = this.legend.markerStyle;
|
|
105
|
-
const item = new
|
|
76
|
+
const item = new LegendEntry({ flow: "horizontal",
|
|
106
77
|
gap: 12,
|
|
107
78
|
align: "center",
|
|
108
79
|
// Bound to the reveal, so showing and hiding is a number moving rather
|
|
109
|
-
// than a child arriving and leaving.
|
|
110
|
-
width:
|
|
80
|
+
// than a child arriving and leaving. The width follows it in `measure`.
|
|
81
|
+
width: "hug",
|
|
111
82
|
opacity: () => this.reveal[index] ?? 0,
|
|
112
83
|
height: "hug",
|
|
113
84
|
children: [
|
|
@@ -124,7 +95,7 @@ export class ChartLegend extends Rect {
|
|
|
124
95
|
shadow: marker.shadow,
|
|
125
96
|
}),
|
|
126
97
|
],
|
|
127
|
-
});
|
|
98
|
+
}, () => this.reveal[index] ?? 0);
|
|
128
99
|
// `gapScale` is a `Node` prop rather than a container one, so it is bound here
|
|
129
100
|
// instead of in the config. It tracks the reveal so the flanking gap closes
|
|
130
101
|
// with the entry rather than snapping when it reaches zero.
|
|
@@ -168,7 +139,9 @@ export class ChartLegend extends Rect {
|
|
|
168
139
|
return hold(duration);
|
|
169
140
|
const from = this.reveal[index] ?? 0;
|
|
170
141
|
return drive(duration, (t) => {
|
|
171
|
-
this.reveal
|
|
142
|
+
const next = [...this.reveal];
|
|
143
|
+
next[index] = from + (target - from) * easing(t);
|
|
144
|
+
this.reveal = next;
|
|
172
145
|
});
|
|
173
146
|
}
|
|
174
147
|
/**
|
|
@@ -200,6 +173,9 @@ __decorate([
|
|
|
200
173
|
__decorate([
|
|
201
174
|
property({ default: DEFAULT_LEGEND })
|
|
202
175
|
], ChartLegend.prototype, "legend", void 0);
|
|
176
|
+
__decorate([
|
|
177
|
+
property({ default: () => [] })
|
|
178
|
+
], ChartLegend.prototype, "reveal", void 0);
|
|
203
179
|
__decorate([
|
|
204
180
|
command()
|
|
205
181
|
], ChartLegend.prototype, "showSeries", null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-legend.js","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,OAAO,GAMR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAiB,MAAM,6BAA6B,CAAA;AAElF,OAAO,EACL,cAAc,EACd,aAAa,GAGd,MAAM,UAAU,CAAA;AAqBjB;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,WAAY,SAAQ,IAAI;IAKnC,6EAA6E;IACrE,KAAK,GAAW,EAAE,CAAA;IAC1B;;;;;;;;;;;;;;;OAeG;IACK,MAAM,GAAa,EAAE,CAAA;IAC7B;;;;;;;;OAQG;IACK,OAAO,GAAa,EAAE,CAAA;IAE9B,YAAY,KAAiD;QAC3D,0EAA0E;QAC1E,2EAA2E;QAC3E,0EAA0E;QAC1E,2EAA2E;QAC3E,4EAA4E;QAC5E,yCAAyC;QACzC,KAAK,CAAC;YACJ,GAAI,KAAmB;YACvB,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,QAAQ;YACf,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,KAAK;SACd,CAAC,CAAA;QAEF,6EAA6E;QAC7E,2EAA2E;QAC3E,IAAI,CAAC,GAAG,CAAC,EAAE,G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AM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAA;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,OAAO,EAAE,CAAA;QACvC,uEAAuE;QACvE,yEAAyE;QACzE,OAAO,QAAQ,CACb,GAAG,IAAI,CAAC,KAAK;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;aAC/B,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;aACpC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CACnB,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAClF,CACJ,CAAA;IACH,CAAC;CACF;AAhM2D;IAAzD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAmB,EAAE,CAAC;2CAA8B;AAC5B;IAAlD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAY,EAAE,CAAC;6CAAyB;AACpB;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;2CAA6B;AAkInE;IADC,OAAO,EAAE;6CAIT;AAOD;IADC,OAAO,EAAE;6CAIT;AAgCD;IADC,OAAO,EAAE;kDAeT","sourcesContent":["import {\n Rect,\n Text,\n command,\n easeOut,\n property,\n textOps,\n type CommandArgs,\n type EasingFunction,\n type Fill,\n type NodeConfig,\n type RectProps,\n} from \"@motionscript/sdk\"\n\nimport { drive, hold, together, type Seekable } from \"@motionscript/sdk/component\"\n\nimport {\n DEFAULT_LEGEND,\n SPOTLIGHT_DIM,\n type ChartSeries,\n type LegendConfig,\n} from \"./shared\"\n\nexport interface ChartLegendProps extends RectProps {\n /**\n * One entry per series: legend `label`, its `enabled` default, and — through\n * {@link ChartLegendProps.swatches} — the colour its chip is painted. A series\n * that starts enabled (the default) is added to the row up front; one that\n * starts `false` is hidden until a later {@link ChartLegend.showSeries}.\n */\n series: ChartSeries[]\n /**\n * The swatch colour for each series, by index — resolved by the chart, whose\n * business it is whether a series' colour comes out of a stroke palette (a\n * line) or a fill palette (a bar). Shorter than the series list means the\n * missing entries fall back to white.\n */\n swatches: Fill[]\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\n legend: LegendConfig\n}\n\n/**\n * The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out\n * left-to-right with the theme's `itemGap`. Each entry pairs the series label\n * with a rounded colour swatch; only the swatch carries the series colour, the\n * caption reads in the legend's neutral ink.\n *\n * {@link showSeries}/{@link hideSeries} flip a series on or off — showing one\n * adds its entry back into the row at its stable series position and grows it\n * in, hiding one shrinks it away and removes it. So the row only ever holds the\n * currently-enabled series, in series order, and closes the gap when one leaves.\n *\n * This node *is* the row, so the parent places it (centred below the chart) and\n * it hugs its entries.\n */\nexport class ChartLegend extends Rect {\n @property({ default: () => [] as ChartSeries[] }) declare series: ChartSeries[]\n @property({ default: () => [] as Fill[] }) declare swatches: Fill[]\n @property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig\n\n /** One entry per series. **Every** entry is a child — see {@link reveal}. */\n private items: Rect[] = []\n /**\n * How far each entry is shown, `0`–`1`. Drives its width, opacity and gap\n * together, so `0` is an entry that takes no room and `1` is one at its\n * natural size.\n *\n * This replaces adding and removing the entry from the row, which is what\n * `showSeries`/`hideSeries` used to do. That could not be a command: a command\n * is asked what it looks like at a time, and \"is this node a child\" is not a\n * value a time can produce — the tree either contains it or it doesn't, and\n * getting there means having run the add. Collapsed-but-present is the same\n * picture reached by a route that *is* a function of `t`.\n *\n * A plain array rather than reactive props because the count is the series\n * count, which is data. The entries' props are bound to it, so writing one\n * still moves the layout.\n */\n private reveal: number[] = []\n /**\n * Each entry's natural width, last time it was fully shown.\n *\n * A collapse needs numeric endpoints — `lerpSizeInput` snaps between a token\n * and a number rather than interpolating — and `\"hug\"` is not a number until\n * something measures it. Refreshed on every frame an entry is at full reveal\n * (see {@link widthFor}), so it is current by the time a hide starts, and it\n * tracks a relabelled series or a restyled legend without being told.\n */\n private natural: number[] = []\n\n constructor(props?: NodeConfig<ChartLegend, ChartLegendProps>) {\n // `flow` after the spread, with the rest of the geometry: this class *is*\n // the row, so the direction is its own answer and not the caller's. It has\n // to be stated — a `Rect` given no flow lays its children out `freeform`,\n // which stacks every entry on the same spot. One series looks perfect that\n // way and three look like one smeared caption, so the failure only shows up\n // on the charts that most need a legend.\n super({\n ...(props as RectProps),\n flow: \"horizontal\",\n align: \"center\",\n width: \"hug\",\n height: \"hug\",\n })\n\n // Structure is one entry per series, so it's composed here from the resolved\n // props super() applied. Fixed row geometry last, so it wins over super().\n this.set({ gap: this.legend.itemGap, padding: this.legend.padding })\n\n this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0))\n this.natural = this.series.map(() => 0)\n this.items = this.series.map((s, i) => this.buildItem(s, i))\n\n // All of them, in series order. Order is now fixed rather than depending on\n // which siblings happen to be shown, so an entry always comes back where it\n // belongs and `insertionIndex` has nothing left to compute.\n for (const item of this.items) this.add(item)\n }\n\n /**\n * An entry's width for its current reveal.\n *\n * `\"hug\"` at full reveal rather than the pinned number, so a shown entry stays\n * responsive to its own content; the number only takes over while it is\n * collapsing, which is the only time a token cannot express it.\n *\n * Records the natural width as a side effect, which is the honest place for it:\n * this runs inside a binding, so it is already reading the layout every frame,\n * and the value it wants is the one the layout just produced. It writes a plain\n * array rather than a signal, so nothing is invalidated by it.\n */\n private widthFor(index: number): number | \"hug\" {\n const shown = this.reveal[index] ?? 0\n if (shown >= 1) {\n const measured = this.items[index]?.measuredWidth ?? 0\n if (measured > 0) this.natural[index] = measured\n return \"hug\"\n }\n return shown * (this.natural[index] ?? 0)\n }\n\n /** One entry: the series caption beside its colour swatch. */\n private buildItem(series: ChartSeries, index: number): Rect {\n const marker = this.legend.markerStyle\n const item = new Rect({ flow: \"horizontal\",\n gap: 12,\n align: \"center\",\n // Bound to the reveal, so showing and hiding is a number moving rather\n // than a child arriving and leaving.\n width: () => this.widthFor(index),\n opacity: () => this.reveal[index] ?? 0,\n height: \"hug\",\n children: [\n new Text({\n ...textOps.styleProps(this.legend.textStyle),\n text: series.label,\n }),\n new Rect({\n width: marker.width,\n height: marker.height,\n cornerRadius: marker.borderRadius,\n fill: this.swatches[index] ?? \"white\",\n stroke: marker.stroke,\n shadow: marker.shadow,\n }),\n ],\n })\n // `gapScale` is a `Node` prop rather than a container one, so it is bound here\n // instead of in the config. It tracks the reveal so the flanking gap closes\n // with the entry rather than snapping when it reaches zero.\n item.set({ gapScale: () => this.reveal[index] ?? 0 })\n return item\n }\n\n /** True if series `index` is showing at all — see {@link reveal}. */\n isEnabled(index: number): boolean {\n return (this.reveal[index] ?? 0) > 0\n }\n\n /**\n * Grow series `index`'s entry back in at its series-order position, the\n * siblings sliding over to make room.\n *\n * A reveal tween rather than an animated `addChildAt`. The entry never left —\n * see {@link reveal} — so there is no add to have happened, and the whole\n * thing is a function of `t`.\n */\n @command()\n showSeries(args: CommandArgs<{ index: number }>): Seekable {\n const { index = 0 } = args.data ?? {}\n return this.revealTo(index, 1, args.duration ?? 0.35, args.easing ?? easeOut())\n }\n\n /**\n * Shrink series `index`'s entry away, the gap closing behind it — the mirror\n * of {@link showSeries}.\n */\n @command()\n hideSeries(args: CommandArgs<{ index: number }>): Seekable {\n const { index = 0 } = args.data ?? {}\n return this.revealTo(index, 0, args.duration ?? 0.35, args.easing ?? easeOut())\n }\n\n /**\n * Ramp one entry's reveal to `target`.\n *\n * `from` is read when the command is built, which for a driven scene is with\n * the node in the state its own start time implies — so a hide that follows a\n * show starts where the show left it rather than at whatever the node happens\n * to hold now.\n */\n private revealTo(\n index: number,\n target: number,\n duration: number,\n easing: EasingFunction\n ): Seekable {\n if (this.items[index] === undefined) return hold(duration)\n const from = this.reveal[index] ?? 0\n return drive(duration, (t) => {\n this.reveal[index] = from + (target - from) * easing(t)\n })\n }\n\n /**\n * Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that\n * one back to full — the legend half of a chart's `spotlightSeries`. Entries\n * stay in place; only their opacity moves, so the row doesn't reflow.\n *\n * Only the currently-shown entries are touched — a hidden series' entry is\n * left as {@link hideSeries} left it.\n */\n @command()\n spotlightSeries(args: CommandArgs<{ index: number }>): Seekable {\n const { index = 0 } = args.data ?? {}\n const duration = args.duration ?? 0.35\n const easing = args.easing ?? easeOut()\n // Opacity only, on entries that are already in the row — no membership\n // changes, so unlike {@link showSeries} this is a plain function of `t`.\n return together(\n ...this.items\n .map((item, i) => ({ item, i }))\n .filter(({ i }) => this.isEnabled(i))\n .map(({ item, i }) =>\n item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })\n )\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chart-legend.js","sourceRoot":"","sources":["../../src/kit/chart-legend.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,OAAO,EACP,QAAQ,EACR,OAAO,GASR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAiB,MAAM,6BAA6B,CAAA;AAElF,OAAO,EACL,cAAc,EACd,aAAa,GAGd,MAAM,UAAU,CAAA;AAqBjB;;;;;;;;GAQG;AACH,MAAM,WAAY,SAAQ,IAAI;IACqC;IAAjE,YAAY,KAAkC,EAAmB,MAAoB;QACnF,KAAK,CAAC,KAAK,CAAC,CAAA;QADmD,WAAM,GAAN,MAAM,CAAc;IAErF,CAAC;IAEQ,OAAO,CAAC,WAA4B,EAAE,KAAuB;QACpE,MAAM,IAAI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5D,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;2CAAiC;AA6E7E;IADC,OAAO,EAAE;6CAIT;AAOD;IADC,OAAO,EAAE;6CAIT;AAkCD;IADC,OAAO,EAAE;kDAeT","sourcesContent":["import {\r\n Rect,\r\n Text,\r\n command,\r\n easeOut,\r\n property,\r\n textOps,\r\n type CommandArgs,\r\n type EasingFunction,\r\n type Fill,\r\n type MeasureContext2D,\r\n type NodeConfig,\r\n type RectProps,\r\n type Size2D,\r\n type SizeConstraints,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { drive, hold, together, type Seekable } from \"@motionscript/sdk/component\"\r\n\r\nimport {\r\n DEFAULT_LEGEND,\r\n SPOTLIGHT_DIM,\r\n type ChartSeries,\r\n type LegendConfig,\r\n} from \"./shared\"\r\n\r\nexport interface ChartLegendProps extends RectProps {\r\n /**\r\n * One entry per series: legend `label`, its `enabled` default, and — through\r\n * {@link ChartLegendProps.swatches} — the colour its chip is painted. A series\r\n * that starts enabled (the default) is added to the row up front; one that\r\n * starts `false` is hidden until a later {@link ChartLegend.showSeries}.\r\n */\r\n series: ChartSeries[]\r\n /**\r\n * The swatch colour for each series, by index — resolved by the chart, whose\r\n * business it is whether a series' colour comes out of a stroke palette (a\r\n * line) or a fill palette (a bar). Shorter than the series list means the\r\n * missing entries fall back to white.\r\n */\r\n swatches: Fill[]\r\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\r\n legend: LegendConfig\r\n}\r\n\r\n/**\r\n * One legend entry. It hugs its caption and swatch; `shown` scales that width from\r\n * nothing to the whole of it.\r\n *\r\n * The width is taken from the content on every measure, at any reveal, so a frame\r\n * never depends on whether the entry was once seen fully shown. A collapse needs a\r\n * number to scale, and `\"hug\"` is not one until something measures it — this is\r\n * the something.\r\n */\r\nclass LegendEntry extends Rect {\r\n constructor(props: NodeConfig<Rect, RectProps>, private readonly _shown: () => number) {\r\n super(props)\r\n }\r\n\r\n override measure(constraints: SizeConstraints, scope: MeasureContext2D): Partial<Size2D> {\r\n const size = super.measure(constraints, scope)\r\n const shown = this._shown()\r\n return shown >= 1 ? size : { ...size, width: shown * (size.width ?? 0) }\r\n }\r\n}\r\n\r\n/**\r\n * The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out\r\n * left-to-right with the theme's `itemGap`. Each entry pairs the series label\r\n * with a rounded colour swatch; only the swatch carries the series colour, the\r\n * caption reads in the legend's neutral ink.\r\n *\r\n * {@link showSeries}/{@link hideSeries} flip a series on or off — showing one\r\n * adds its entry back into the row at its stable series position and grows it\r\n * in, hiding one shrinks it away and removes it. So the row only ever holds the\r\n * currently-enabled series, in series order, and closes the gap when one leaves.\r\n *\r\n * This node *is* the row, so the parent places it (centred below the chart) and\r\n * it hugs its entries.\r\n */\r\nexport class ChartLegend extends Rect {\r\n @property({ default: () => [] as ChartSeries[] }) declare series: ChartSeries[]\r\n @property({ default: () => [] as Fill[] }) declare swatches: Fill[]\r\n @property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig\r\n\r\n /** One entry per series. **Every** entry is a child — see {@link reveal}. */\r\n private items: LegendEntry[] = []\r\n /**\r\n * How far each entry is shown, `0`–`1`. Drives its width, opacity and gap\r\n * together, so `0` is an entry that takes no room and `1` is one at its\r\n * natural size.\r\n *\r\n * This replaces adding and removing the entry from the row, which is what\r\n * `showSeries`/`hideSeries` used to do. That could not be a command: a command\r\n * is asked what it looks like at a time, and \"is this node a child\" is not a\r\n * value a time can produce — the tree either contains it or it doesn't, and\r\n * getting there means having run the add. Collapsed-but-present is the same\r\n * picture reached by a route that *is* a function of `t`.\r\n *\r\n * One array in one slot, because the count is the series count, which is data.\r\n * It is replaced rather than mutated: a write is a slot write, so the timeline\r\n * sees it and restores it to the authored reveal before the command starts\r\n * and after a seek back. The entries' props are bound to it, so writing it\r\n * still moves the layout.\r\n */\r\n @property({ default: () => [] as number[] }) private declare reveal: number[]\r\n\r\n constructor(props?: NodeConfig<ChartLegend, ChartLegendProps>) {\r\n // `flow` after the spread, with the rest of the geometry: this class *is*\r\n // the row, so the direction is its own answer and not the caller's. It has\r\n // to be stated — a `Rect` given no flow lays its children out `freeform`,\r\n // which stacks every entry on the same spot. One series looks perfect that\r\n // way and three look like one smeared caption, so the failure only shows up\r\n // on the charts that most need a legend.\r\n super({\r\n ...(props as RectProps),\r\n flow: \"horizontal\",\r\n align: \"center\",\r\n width: \"hug\",\r\n height: \"hug\",\r\n })\r\n\r\n // Structure is one entry per series, so it's composed here from the resolved\r\n // props super() applied. Fixed row geometry last, so it wins over super().\r\n this.set({ gap: this.legend.itemGap, padding: this.legend.padding })\r\n\r\n this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0))\r\n this.items = this.series.map((s, i) => this.buildItem(s, i))\r\n\r\n // All of them, in series order. Order is now fixed rather than depending on\r\n // which siblings happen to be shown, so an entry always comes back where it\r\n // belongs and `insertionIndex` has nothing left to compute.\r\n for (const item of this.items) this.add(item)\r\n }\r\n\r\n /** One entry: the series caption beside its colour swatch. */\r\n private buildItem(series: ChartSeries, index: number): LegendEntry {\r\n const marker = this.legend.markerStyle\r\n const item = new LegendEntry({ flow: \"horizontal\",\r\n gap: 12,\r\n align: \"center\",\r\n // Bound to the reveal, so showing and hiding is a number moving rather\r\n // than a child arriving and leaving. The width follows it in `measure`.\r\n width: \"hug\",\r\n opacity: () => this.reveal[index] ?? 0,\r\n height: \"hug\",\r\n children: [\r\n new Text({\r\n ...textOps.styleProps(this.legend.textStyle),\r\n text: series.label,\r\n }),\r\n new Rect({\r\n width: marker.width,\r\n height: marker.height,\r\n cornerRadius: marker.borderRadius,\r\n fill: this.swatches[index] ?? \"white\",\r\n stroke: marker.stroke,\r\n shadow: marker.shadow,\r\n }),\r\n ],\r\n }, () => this.reveal[index] ?? 0)\r\n // `gapScale` is a `Node` prop rather than a container one, so it is bound here\r\n // instead of in the config. It tracks the reveal so the flanking gap closes\r\n // with the entry rather than snapping when it reaches zero.\r\n item.set({ gapScale: () => this.reveal[index] ?? 0 })\r\n return item\r\n }\r\n\r\n /** True if series `index` is showing at all — see {@link reveal}. */\r\n isEnabled(index: number): boolean {\r\n return (this.reveal[index] ?? 0) > 0\r\n }\r\n\r\n /**\r\n * Grow series `index`'s entry back in at its series-order position, the\r\n * siblings sliding over to make room.\r\n *\r\n * A reveal tween rather than an animated `addChildAt`. The entry never left —\r\n * see {@link reveal} — so there is no add to have happened, and the whole\r\n * thing is a function of `t`.\r\n */\r\n @command()\r\n showSeries(args: CommandArgs<{ index: number }>): Seekable {\r\n const { index = 0 } = args.data ?? {}\r\n return this.revealTo(index, 1, args.duration ?? 0.35, args.easing ?? easeOut())\r\n }\r\n\r\n /**\r\n * Shrink series `index`'s entry away, the gap closing behind it — the mirror\r\n * of {@link showSeries}.\r\n */\r\n @command()\r\n hideSeries(args: CommandArgs<{ index: number }>): Seekable {\r\n const { index = 0 } = args.data ?? {}\r\n return this.revealTo(index, 0, args.duration ?? 0.35, args.easing ?? easeOut())\r\n }\r\n\r\n /**\r\n * Ramp one entry's reveal to `target`.\r\n *\r\n * `from` is read when the command is built, which for a driven scene is with\r\n * the node in the state its own start time implies — so a hide that follows a\r\n * show starts where the show left it rather than at whatever the node happens\r\n * to hold now.\r\n */\r\n private revealTo(\r\n index: number,\r\n target: number,\r\n duration: number,\r\n easing: EasingFunction\r\n ): Seekable {\r\n if (this.items[index] === undefined) return hold(duration)\r\n const from = this.reveal[index] ?? 0\r\n return drive(duration, (t) => {\r\n const next = [...this.reveal]\r\n next[index] = from + (target - from) * easing(t)\r\n this.reveal = next\r\n })\r\n }\r\n\r\n /**\r\n * Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that\r\n * one back to full — the legend half of a chart's `spotlightSeries`. Entries\r\n * stay in place; only their opacity moves, so the row doesn't reflow.\r\n *\r\n * Only the currently-shown entries are touched — a hidden series' entry is\r\n * left as {@link hideSeries} left it.\r\n */\r\n @command()\r\n spotlightSeries(args: CommandArgs<{ index: number }>): Seekable {\r\n const { index = 0 } = args.data ?? {}\r\n const duration = args.duration ?? 0.35\r\n const easing = args.easing ?? easeOut()\r\n // Opacity only, on entries that are already in the row — no membership\r\n // changes, so unlike {@link showSeries} this is a plain function of `t`.\r\n return together(\r\n ...this.items\r\n .map((item, i) => ({ item, i }))\r\n .filter(({ i }) => this.isEnabled(i))\r\n .map(({ item, i }) =>\r\n item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })\r\n )\r\n )\r\n }\r\n}\r\n"]}
|
package/dist/kit/shared.d.ts
CHANGED
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
* that three times would mean three answers to "how does a chart round its axis"
|
|
13
13
|
* within one app.
|
|
14
14
|
*
|
|
15
|
-
* Kept renderer-agnostic (no `Node` imports) so
|
|
16
|
-
* mappings can build a partial theme without pulling the node classes in
|
|
17
|
-
* same way `line-chart-props.ts` always has.
|
|
15
|
+
* Kept renderer-agnostic (no `Node` imports) so a host's own inspector
|
|
16
|
+
* mappings can build a partial theme without pulling the node classes in.
|
|
18
17
|
*
|
|
19
18
|
* **Two conventions run through every resolver and lerp below**, inherited from
|
|
20
19
|
* the shape system's `resolveStroke`/`resolveShadow`:
|
|
@@ -93,6 +92,20 @@ export declare function resolveAxisDomain(domain: AxisDomainConfig | undefined,
|
|
|
93
92
|
* auto-derive mode, step at the midpoint.
|
|
94
93
|
*/
|
|
95
94
|
export declare function lerpAxisDomain(from: AxisDomainConfig, to: AxisDomainConfig, t: number): AxisDomainConfig;
|
|
95
|
+
/**
|
|
96
|
+
* Where a generic `to()` of an axis domain should land, given the domain as it
|
|
97
|
+
* is *drawn* (`drawn`, with `range` and `ticks` resolved off the data), or
|
|
98
|
+
* `undefined` when the request states neither a `range` nor `ticks` and the
|
|
99
|
+
* plain property tween will do.
|
|
100
|
+
*
|
|
101
|
+
* The stored domain of an auto axis has no `range` and no `ticks`, and
|
|
102
|
+
* {@link lerpAxisDomain} steps an unset side at the midpoint, so tweening the
|
|
103
|
+
* stored value from an auto axis is a cut. The charts therefore tween between
|
|
104
|
+
* resolved domains, as their zoom does; this builds the destination. A `range`
|
|
105
|
+
* given without `ticks` keeps the tick *count* the axis already draws, so each
|
|
106
|
+
* marker slides from its old value to its new one instead of the row popping.
|
|
107
|
+
*/
|
|
108
|
+
export declare function axisTweenTarget(drawn: AxisDomainConfig, requested: AxisDomainConfig | undefined): AxisDomainConfig | undefined;
|
|
96
109
|
/**
|
|
97
110
|
* The low-level colour tokens the default themes are built from — a dark plot
|
|
98
111
|
* panel with warm-grey axis furniture.
|
|
@@ -119,7 +132,8 @@ export declare const SPOTLIGHT_DIM = 0.2;
|
|
|
119
132
|
/** Clamp a number into `[0, 1]` — the range every reveal signal here runs in. */
|
|
120
133
|
export declare function clampUnit(value: number): number;
|
|
121
134
|
/**
|
|
122
|
-
* Read a numeric field off a row, defaulting missing
|
|
135
|
+
* Read a numeric field off a row, defaulting missing, non-numeric and non-finite
|
|
136
|
+
* values to 0.
|
|
123
137
|
*
|
|
124
138
|
* A column left as strings silently plots as 0, which is why the CSV parser's
|
|
125
139
|
* numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
|
|
@@ -241,8 +255,17 @@ export declare function resolveSeriesFill(palette: Stroke[], series: ChartSeries
|
|
|
241
255
|
* simply the whole answer.
|
|
242
256
|
*/
|
|
243
257
|
export declare function resolvePalettePaint(palette: Fill[], override: Fill | undefined, index: number): Fill;
|
|
244
|
-
/**
|
|
245
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Format a marker value: integers plain, otherwise trimmed to one decimal, or to
|
|
260
|
+
* as many as the axis's tick `step` needs to tell neighbouring ticks apart.
|
|
261
|
+
*
|
|
262
|
+
* One decimal is the floor, so a step of 0.1 or more reads exactly as it always
|
|
263
|
+
* has; a finer step (a unit axis ticked every 0.05) gets two, instead of five
|
|
264
|
+
* ticks captioned `0.1 0.1 0.2 0.2 0.3`. Trailing zeros are dropped either way.
|
|
265
|
+
*/
|
|
266
|
+
export declare function formatMarker(value: number, step?: number): string;
|
|
267
|
+
/** The gap between neighbouring tick values, or `undefined` for fewer than two distinct ones. */
|
|
268
|
+
export declare function markerStep(markers: readonly number[]): number | undefined;
|
|
246
269
|
/** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */
|
|
247
270
|
export declare function formatPercent(fraction: number): string;
|
|
248
271
|
/** `markerCount` evenly-spaced tick values across `[min, max]`, ends inclusive. */
|
package/dist/kit/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/kit/shared.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/kit/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAOL,KAAK,UAAU,EACf,KAAK,IAAI,EAET,KAAK,MAAM,EAEX,KAAK,MAAM,EAEX,KAAK,MAAM,EAEX,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAA;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,+DAA+D;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,kDAAkD;AAClD,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAE9C;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,4EAA4E;IAC5E,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB;;;;;;;;O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;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,GACZ,MAAM,CAcR;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,GACZ,IAAI,CAGN;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,IAAI,EAAE,EACf,QAAQ,EAAE,IAAI,GAAG,SAAS,EAC1B,KAAK,EAAE,MAAM,GACZ,IAAI,CAIN;AAKD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAIjE;AAaD,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAQzE;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAG7E;AAKD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA"}
|
package/dist/kit/shared.js
CHANGED
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
* that three times would mean three answers to "how does a chart round its axis"
|
|
13
13
|
* within one app.
|
|
14
14
|
*
|
|
15
|
-
* Kept renderer-agnostic (no `Node` imports) so
|
|
16
|
-
* mappings can build a partial theme without pulling the node classes in
|
|
17
|
-
* same way `line-chart-props.ts` always has.
|
|
15
|
+
* Kept renderer-agnostic (no `Node` imports) so a host's own inspector
|
|
16
|
+
* mappings can build a partial theme without pulling the node classes in.
|
|
18
17
|
*
|
|
19
18
|
* **Two conventions run through every resolver and lerp below**, inherited from
|
|
20
19
|
* the shape system's `resolveStroke`/`resolveShadow`:
|
|
@@ -74,6 +73,29 @@ function lerpOptionalTicks(from, to, t) {
|
|
|
74
73
|
}
|
|
75
74
|
return out;
|
|
76
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Where a generic `to()` of an axis domain should land, given the domain as it
|
|
78
|
+
* is *drawn* (`drawn`, with `range` and `ticks` resolved off the data), or
|
|
79
|
+
* `undefined` when the request states neither a `range` nor `ticks` and the
|
|
80
|
+
* plain property tween will do.
|
|
81
|
+
*
|
|
82
|
+
* The stored domain of an auto axis has no `range` and no `ticks`, and
|
|
83
|
+
* {@link lerpAxisDomain} steps an unset side at the midpoint, so tweening the
|
|
84
|
+
* stored value from an auto axis is a cut. The charts therefore tween between
|
|
85
|
+
* resolved domains, as their zoom does; this builds the destination. A `range`
|
|
86
|
+
* given without `ticks` keeps the tick *count* the axis already draws, so each
|
|
87
|
+
* marker slides from its old value to its new one instead of the row popping.
|
|
88
|
+
*/
|
|
89
|
+
export function axisTweenTarget(drawn, requested) {
|
|
90
|
+
if (requested?.range === undefined && requested?.ticks === undefined)
|
|
91
|
+
return undefined;
|
|
92
|
+
const target = resolveAxisDomain(requested, drawn);
|
|
93
|
+
if (requested.ticks === undefined && requested.range !== undefined) {
|
|
94
|
+
const count = Math.max(2, drawn.ticks?.length ?? 2);
|
|
95
|
+
target.ticks = markerValues(requested.range, count - 1);
|
|
96
|
+
}
|
|
97
|
+
return target;
|
|
98
|
+
}
|
|
77
99
|
/**
|
|
78
100
|
* The low-level colour tokens the default themes are built from — a dark plot
|
|
79
101
|
* panel with warm-grey axis furniture.
|
|
@@ -109,7 +131,8 @@ export function clampUnit(value) {
|
|
|
109
131
|
}
|
|
110
132
|
// ---- Row readers ---------------------------------------------------------
|
|
111
133
|
/**
|
|
112
|
-
* Read a numeric field off a row, defaulting missing
|
|
134
|
+
* Read a numeric field off a row, defaulting missing, non-numeric and non-finite
|
|
135
|
+
* values to 0.
|
|
113
136
|
*
|
|
114
137
|
* A column left as strings silently plots as 0, which is why the CSV parser's
|
|
115
138
|
* numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
|
|
@@ -119,7 +142,9 @@ export function num(row, field) {
|
|
|
119
142
|
if (field === undefined)
|
|
120
143
|
return 0;
|
|
121
144
|
const v = row[field];
|
|
122
|
-
|
|
145
|
+
// A `NaN` or infinite cell is no more a measurement than a missing one: read
|
|
146
|
+
// as 0, it cannot poison the scale and turn every point into `NaN`.
|
|
147
|
+
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
123
148
|
}
|
|
124
149
|
/**
|
|
125
150
|
* Read a field off a row as its caption — the counterpart to {@link num} for
|
|
@@ -376,11 +401,42 @@ export function resolvePalettePaint(palette, override, index) {
|
|
|
376
401
|
return palette[index % palette.length];
|
|
377
402
|
}
|
|
378
403
|
// ---- Scales and formatting -----------------------------------------------
|
|
379
|
-
/**
|
|
380
|
-
|
|
404
|
+
/**
|
|
405
|
+
* Format a marker value: integers plain, otherwise trimmed to one decimal, or to
|
|
406
|
+
* as many as the axis's tick `step` needs to tell neighbouring ticks apart.
|
|
407
|
+
*
|
|
408
|
+
* One decimal is the floor, so a step of 0.1 or more reads exactly as it always
|
|
409
|
+
* has; a finer step (a unit axis ticked every 0.05) gets two, instead of five
|
|
410
|
+
* ticks captioned `0.1 0.1 0.2 0.2 0.3`. Trailing zeros are dropped either way.
|
|
411
|
+
*/
|
|
412
|
+
export function formatMarker(value, step) {
|
|
381
413
|
if (Number.isInteger(value))
|
|
382
414
|
return String(value);
|
|
383
|
-
|
|
415
|
+
const decimals = Math.max(1, step === undefined ? 1 : decimalsFor(step));
|
|
416
|
+
return value.toFixed(decimals).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
|
|
417
|
+
}
|
|
418
|
+
/** Decimal places needed to write `step` exactly, capped at six. */
|
|
419
|
+
function decimalsFor(step) {
|
|
420
|
+
if (!(step > 0) || !Number.isFinite(step))
|
|
421
|
+
return 1;
|
|
422
|
+
for (let d = 0; d <= 6; d++) {
|
|
423
|
+
const scaled = step * 10 ** d;
|
|
424
|
+
if (Math.abs(scaled - Math.round(scaled)) < 1e-6 * Math.max(1, scaled))
|
|
425
|
+
return d;
|
|
426
|
+
}
|
|
427
|
+
// An irrational-looking step (a third): as many places as separate the ticks.
|
|
428
|
+
return Math.min(6, Math.max(1, Math.ceil(-Math.log10(step)) + 1));
|
|
429
|
+
}
|
|
430
|
+
/** The gap between neighbouring tick values, or `undefined` for fewer than two distinct ones. */
|
|
431
|
+
export function markerStep(markers) {
|
|
432
|
+
const sorted = [...markers].filter(Number.isFinite).sort((a, b) => a - b);
|
|
433
|
+
let step;
|
|
434
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
435
|
+
const gap = sorted[i] - sorted[i - 1];
|
|
436
|
+
if (gap > 1e-12 && (step === undefined || gap < step))
|
|
437
|
+
step = gap;
|
|
438
|
+
}
|
|
439
|
+
return step;
|
|
384
440
|
}
|
|
385
441
|
/** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */
|
|
386
442
|
export function formatPercent(fraction) {
|