@motionscript/charts 0.1.0-alpha.3 → 0.1.0-alpha.6

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