@motionscript/charts 0.1.0-alpha.5 → 0.1.0-alpha.7

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