@motionscript/charts 0.1.0-alpha.5 → 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 (141) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +30 -16
  3. package/dist/bar-chart/bar-chart.d.ts +93 -246
  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 +24 -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 +36 -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 +8 -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 +23 -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 +79 -67
  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 +36 -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 +25 -51
  70. package/dist/line-chart/chart-line.d.ts.map +1 -1
  71. package/dist/line-chart/chart-line.js +89 -120
  72. package/dist/line-chart/chart-line.js.map +1 -1
  73. package/dist/line-chart/chart-region.d.ts +14 -14
  74. package/dist/line-chart/chart-region.d.ts.map +1 -1
  75. package/dist/line-chart/chart-region.js +26 -64
  76. package/dist/line-chart/chart-region.js.map +1 -1
  77. package/dist/line-chart/horizontal-axis.d.ts +32 -56
  78. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  79. package/dist/line-chart/horizontal-axis.js +85 -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 +111 -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 +77 -134
  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 +54 -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 +142 -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/package.json +4 -4
  114. package/src/bar-chart/bar-chart.ts +415 -701
  115. package/src/bar-chart/category-axis.ts +95 -110
  116. package/src/bar-chart/chart-bars.ts +178 -200
  117. package/src/bar-chart/index.ts +2 -2
  118. package/src/bar-chart/shared.ts +3 -3
  119. package/src/engine.ts +8 -6
  120. package/src/kit/cartesian.ts +81 -0
  121. package/src/kit/chart-border.ts +22 -33
  122. package/src/kit/chart-canvas.ts +44 -79
  123. package/src/kit/chart-legend.ts +173 -189
  124. package/src/kit/entries.ts +20 -0
  125. package/src/kit/motion.ts +90 -0
  126. package/src/kit/paints.ts +15 -0
  127. package/src/kit/shared.ts +52 -3
  128. package/src/kit/vertical-axis.ts +110 -140
  129. package/src/line-chart/chart-line.ts +95 -122
  130. package/src/line-chart/chart-region.ts +30 -59
  131. package/src/line-chart/horizontal-axis.ts +99 -135
  132. package/src/line-chart/index.ts +2 -2
  133. package/src/line-chart/line-chart.ts +449 -825
  134. package/src/line-chart/shared.ts +3 -3
  135. package/src/nodes.ts +8 -10
  136. package/src/pie-chart/index.ts +2 -2
  137. package/src/pie-chart/pie-chart.ts +221 -311
  138. package/src/pie-chart/pie-legend.ts +124 -114
  139. package/src/pie-chart/pie-ring.ts +386 -473
  140. package/dist/browser/chunks/chunk-5ZPBV6BU.js +0 -2
  141. package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +0 -7
@@ -1 +1 @@
1
- {"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,OAAO,GAIR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,EAAE,EAAE,OAAO,EAAiB,MAAM,6BAA6B,CAAA;AAqBxE,8EAA8E;AAC9E,MAAM,KAAK,GAAG,E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G,EAAE,CAAC,EAAc,EAAE,CAAC;6CAA0B;AACvB;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;0CAAyB;AAC5B;IAAlC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;2CAAsB;AA2HhD;IADC,OAAO,EAAE;yCA6BT","sourcesContent":["import {\r\n command,\r\n Node2D,\r\n Rect,\r\n RotatedBox,\r\n Text,\r\n easeOut,\r\n property,\r\n insetsOps,\r\n textOps,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type Node2DProps,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport {\r\n DEFAULT_Y_AXIS,\r\n enterBudget,\r\n formatMarker,\r\n type AxisConfig,\r\n type Range,\r\n} from \"./shared\"\r\nimport { at, compose, type Seekable } from \"@motionscript/sdk/component\"\r\n\r\nexport interface VerticalAxisProps extends Node2DProps {\r\n /** `[min, max]` of the vertical scale the markers are positioned within. */\r\n range: Range\r\n /**\r\n * Tick values (in data units) to draw up the axis, each placed by its fraction\r\n * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include\r\n * the ends.\r\n */\r\n markers: number[]\r\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\r\n axis: AxisConfig\r\n /**\r\n * Rotated caption drawn in the gutter to the left of the marker column. Empty\r\n * string (the default) hides it — no caption node is built and no label gutter\r\n * is reserved.\r\n */\r\n label: string\r\n}\r\n\r\n/** How far a marker starts to the right of its slot when it enters, in px. */\r\nconst SLIDE = 24\r\n\r\n/** How a tick value is captioned — see {@link VerticalAxis.labelFor}. */\r\nexport type MarkerLabel = (value: number) => string\r\n\r\n/**\r\n * The numeric vertical axis shared by the cartesian charts: a **column of\r\n * {@link Text} nodes**, one per marker value, running top-to-bottom (highest\r\n * value at the top). Pure layout — no `Graphics` — so the markers are real text\r\n * nodes the scene can measure, restyle, or animate individually.\r\n *\r\n * Each marker is positioned so its centre lands exactly on its value's fraction\r\n * across `range` within the axis's filled height, so unevenly-spaced markers\r\n * land where their values fall. Both the caption and the position are *bound*,\r\n * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)\r\n * tweens `range`/`markers` live. Only the marker **count** is fixed at\r\n * construction.\r\n *\r\n * {@link enter} staggers them in **bottom-to-top**: each marker starts pushed a\r\n * little to the right and transparent, then fades and slides left into place.\r\n * The resting state is the landed one, so a chart that is never told to enter\r\n * still reads as a finished chart.\r\n */\r\nexport class VerticalAxis extends Node2D<VerticalAxisProps> {\r\n @property({ default: () => [0, 1] as Range }) declare range: Range\r\n @property({ default: () => [] as number[] }) declare markers: number[]\r\n @property({ default: DEFAULT_Y_AXIS }) declare axis: AxisConfig\r\n @property({ default: \"\" }) declare label: string\r\n\r\n /**\r\n * How a tick value is captioned. Defaults to the bare numeric reading; a\r\n * chart with a number format on this axis replaces it (see `number-format`).\r\n *\r\n * A plain field rather than a `@property`, for the reason the horizontal\r\n * axis's twin spells out: it is a policy, not a value, and there is nothing\r\n * to tween between two formatters.\r\n */\r\n labelFor: MarkerLabel = formatMarker\r\n\r\n /** One text node per marker, ordered top → bottom, for the staggered enter. */\r\n private markerNodes: Text[] = []\r\n /** The caption node, or null when `label` is empty. Entered after the markers. */\r\n private labelNode: Text | null = null\r\n\r\n /** The live tick values, top → bottom (highest first) — re-read every frame. */\r\n private get sortedMarkers(): number[] {\r\n return [...this.markers].sort((a, b) => b - a)\r\n }\r\n\r\n /**\r\n * Tick `i`'s value, or `undefined` once the live `markers` list is shorter\r\n * than the column of text nodes built for it — a slot with no value renders as\r\n * empty text rather than repeating its neighbour.\r\n */\r\n private valueAt(index: number): number | undefined {\r\n return this.sortedMarkers[index]\r\n }\r\n\r\n /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */\r\n private fracAt(index: number): number {\r\n const v = this.valueAt(index)\r\n if (v === undefined) return 0\r\n const [min, max] = this.range\r\n return max <= min ? 0 : (v - min) / (max - min)\r\n }\r\n\r\n constructor(props?: NodeConfig<VerticalAxis, VerticalAxisProps>) {\r\n super(props)\r\n\r\n // Composed from plain props (range/markers/label) — no context needed, so\r\n // it's built here. super() applied the props, so the reads below resolve.\r\n const tickPad = insetsOps.resolve(this.axis.tickPadding).right\r\n const titlePad = insetsOps.resolve(this.axis.titlePadding).right\r\n\r\n this.markerNodes = this.markers.map((_, i) => {\r\n const marker: Text = new Text({\r\n ...textOps.styleProps(this.axis.labelStyle),\r\n text: () => {\r\n const v = this.valueAt(i)\r\n return v === undefined ? \"\" : this.labelFor(v)\r\n },\r\n y: () => {\r\n // Node2D space is y-up, so the fraction runs from the bottom.\r\n const height = this.layoutBounds.height\r\n const centred = (this.fracAt(i) - 0.5) * height\r\n // Held inside the axis's top edge — the backstop for a chart whose\r\n // headroom is smaller than its marker text is tall, which a theme with\r\n // much larger markers can arrange. Only the top, because what lies\r\n // below the axis is the chart's own horizontal axis and legend.\r\n const limit = height / 2 - marker.layoutBounds.height / 2\r\n return Math.min(centred, limit)\r\n },\r\n })\r\n return marker\r\n })\r\n\r\n const children: Node2D[] = []\r\n if (this.label !== \"\") {\r\n this.labelNode = new Text({\r\n ...textOps.styleProps(this.axis.titleStyle),\r\n text: this.label,\r\n })\r\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\r\n children.push(\r\n new RotatedBox({\r\n angle: -90,\r\n width: \"hug\",\r\n height: \"hug\",\r\n children: this.labelNode,\r\n })\r\n )\r\n }\r\n children.push(\r\n new Rect({\r\n height: \"fill\",\r\n width: \"hug\",\r\n padding: { right: tickPad },\r\n children: this.markerNodes,\r\n })\r\n )\r\n\r\n this.add(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\r\n }\r\n\r\n /**\r\n * Primes every marker (and the caption) at its pre-entrance state: shifted\r\n * right and transparent. Idempotent, and separate from {@link enter} so the\r\n * chart can arm its whole composition before the first frame is drawn.\r\n */\r\n arm(slide = SLIDE): void {\r\n for (const marker of this.markerNodes) marker.set({ opacity: 0, x: slide })\r\n this.labelNode?.set({ opacity: 0, x: slide })\r\n }\r\n\r\n /**\r\n * Stagger the markers in bottom to top, then slide the caption in from the\r\n * right after them.\r\n *\r\n * A {@link Seekable} rather than a generator — see the note on the horizontal\r\n * axis's `enter`. The offsets were always static; expressing them as `wait`\r\n * inside a generator is what made them reachable only by running it.\r\n *\r\n * `args.duration` is the **whole** entrance, not one marker's slide: the\r\n * stagger and the caption are carved out of it rather than added on top. See\r\n * {@link enterBudget} for why that distinction matters here.\r\n *\r\n * `args.data.stagger` is seconds between successive markers (derived when\r\n * omitted); `args.data.slide` is the starting rightward offset in px.\r\n */\r\n @command()\r\n enter(args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number }): Seekable {\r\n const { stagger, slide = SLIDE } = args.data ?? {}\r\n const easing = args.easing ?? easeOut()\r\n const nodes = this.markerNodes\r\n if (nodes.length === 0) return compose([])\r\n const { step, per, caption } = enterBudget(\r\n args.duration,\r\n nodes.length,\r\n this.labelNode !== null,\r\n stagger\r\n )\r\n\r\n this.arm(slide)\r\n\r\n // Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.\r\n const markers = nodes.map((node, i) => {\r\n const order = nodes.length - 1 - i // bottom-most = 0\r\n return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }))\r\n })\r\n const lastMarkerEnds = (nodes.length - 1) * step + per\r\n\r\n // Once every marker has landed, the caption slides in from the right.\r\n return compose([\r\n ...markers,\r\n ...(this.labelNode\r\n ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]\r\n : []),\r\n ])\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAIR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM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E,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC1E,CAAC;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import {\r\n Rect,\r\n RotatedBox,\r\n Text,\r\n Types,\r\n component2d,\r\n insetsOps,\r\n textOps,\r\n type NodeOf,\r\n type Node2D,\r\n type Node2DProps,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { asParts, fresh } from \"./entries\"\r\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"./motion\"\r\nimport {\r\n DEFAULT_Y_AXIS,\r\n enterBudget,\r\n formatMarker,\r\n type AxisConfig,\r\n type Range,\r\n} from \"./shared\"\r\n\r\nexport interface VerticalAxisProps extends Node2DProps {\r\n /** `[min, max]` of the vertical scale the markers are positioned within. */\r\n range: Range\r\n /**\r\n * Tick values (in data units) to draw up the axis, each placed by its fraction\r\n * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include\r\n * the ends.\r\n */\r\n markers: number[]\r\n /**\r\n * How each marker is captioned, one per entry of `markers` and in its order.\r\n * Empty (the default), or short, captions a marker with its bare numeric\r\n * reading; a chart with a number format on this axis writes them through it.\r\n */\r\n captions: string[]\r\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\r\n axis: AxisConfig\r\n /**\r\n * Rotated caption drawn in the gutter to the left of the marker column. Empty\r\n * string (the default) hides it — no caption node is built and no label gutter\r\n * is reserved.\r\n */\r\n label: string\r\n}\r\n\r\n/** How far a marker starts to the right of its slot when it enters, in px. */\r\nconst SLIDE = 24\r\n\r\n/** How a tick value is captioned — see {@link VerticalAxisProps.captions}. */\r\nexport type MarkerLabel = (value: number) => string\r\n\r\n/** What a marker's caption reads: the one listed for its value, else its bare reading. */\r\nexport function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {\r\n const index = s.markers.indexOf(value)\r\n return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)\r\n}\r\n\r\n/**\r\n * The numeric vertical axis shared by the cartesian charts: a **column of\r\n * {@link Text} nodes**, one per marker value, running top-to-bottom (highest\r\n * value at the top). Pure layout — no `Graphics` — so the markers are real text\r\n * nodes the scene can measure, restyle, or animate individually.\r\n *\r\n * Each marker is positioned so its centre lands exactly on its value's fraction\r\n * across `range` within the axis's filled height, so unevenly-spaced markers\r\n * land where their values fall. Both the caption and the position are *bound*,\r\n * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)\r\n * tweens `range`/`markers` live. Only the marker **count** is fixed at\r\n * construction.\r\n *\r\n * `enter` staggers them in **bottom-to-top**: each marker starts pushed a\r\n * little to the right and transparent, then fades and slides left into place.\r\n * The resting state is the landed one, so a chart that is never told to enter\r\n * still reads as a finished chart.\r\n */\r\nexport const VerticalAxis = component2d({\r\n key: \"verticalAxis\",\r\n state: {\r\n range: fresh<Range>(() => [0, 1]),\r\n markers: fresh<number[]>(() => []),\r\n captions: fresh<string[]>(() => []),\r\n axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),\r\n label: \"\",\r\n arrivals: arrivalsEntry(),\r\n },\r\n // A plain node filled its parent; one made of its markers would hug them.\r\n defaults: { width: \"fill\", height: \"fill\" },\r\n children: (state) => {\r\n // Composed from plain entries (range/markers/label), so it's built once here.\r\n const tickPad = insetsOps.resolve(state.axis.tickPadding).right\r\n const titlePad = insetsOps.resolve(state.axis.titlePadding).right\r\n\r\n const row: Node2D[] = []\r\n // The row's parent is the axis: its box is what the markers are placed in.\r\n const box = () => (row[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 }\r\n /** The live tick values, top → bottom (highest first) — re-read every frame. */\r\n const sorted = () => [...state.markers].sort((a, b) => b - a)\r\n /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */\r\n const fracAt = (value: number | undefined) => {\r\n if (value === undefined) return 0\r\n const [min, max] = state.range\r\n return max <= min ? 0 : (value - min) / (max - min)\r\n }\r\n\r\n // One text node per marker, ordered top → bottom. A slot with no value (the\r\n // live list is shorter than the column built for it) renders as empty text\r\n // rather than repeating its neighbour.\r\n const markers = state.markers.map((_, i) => {\r\n const marker: Node2D = new Text({\r\n ...textOps.styleProps(state.axis.labelStyle),\r\n text: () => {\r\n const value = sorted()[i]\r\n return value === undefined ? \"\" : markerCaption(state, value)\r\n },\r\n y: () => {\r\n // Node2D space is y-up, so the fraction runs from the bottom.\r\n const height = box().height\r\n const centred = (fracAt(sorted()[i]) - 0.5) * height\r\n // Held inside the axis's top edge — the backstop for a chart whose\r\n // headroom is smaller than its marker text is tall, which a theme with\r\n // much larger markers can arrange. Only the top, because what lies\r\n // below the axis is the chart's own horizontal axis and legend.\r\n const limit = height / 2 - marker.layoutBounds.height / 2\r\n return Math.min(centred, limit)\r\n },\r\n opacity: () => arrivalOf(state.arrivals, i).opacity,\r\n x: () => arrivalOf(state.arrivals, i).shift,\r\n })\r\n return marker\r\n })\r\n\r\n const children: Node2D[] = []\r\n if (state.label !== \"\") {\r\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\r\n children.push(\r\n new RotatedBox({\r\n angle: -90,\r\n width: \"hug\",\r\n height: \"hug\",\r\n children: new Text({\r\n ...textOps.styleProps(state.axis.titleStyle),\r\n text: state.label,\r\n opacity: () => arrivalOf(state.arrivals, \"label\").opacity,\r\n x: () => arrivalOf(state.arrivals, \"label\").shift,\r\n }),\r\n })\r\n )\r\n }\r\n children.push(new Rect({ height: \"fill\", width: \"hug\", padding: { right: tickPad }, children: markers }))\r\n row.push(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\r\n return asParts(row)\r\n },\r\n commands: {\r\n /**\r\n * Stagger the markers in bottom to top, then slide the caption in from the\r\n * right after them. Its first frame arms them all: shifted right by `slide`\r\n * and transparent.\r\n *\r\n * The timeline's duration is the **whole** entrance, not one marker's slide:\r\n * the stagger and the caption are carved out of it rather than added on top.\r\n * See {@link enterBudget} for why that distinction matters here.\r\n *\r\n * `stagger` is seconds between successive markers (derived when omitted);\r\n * `slide` is the starting rightward offset in px.\r\n */\r\n enter: {\r\n args: {\r\n stagger: Types.custom<number | undefined>(undefined),\r\n slide: Types.number(SLIDE),\r\n },\r\n run: (timeline, state) => {\r\n const { stagger, slide } = timeline.args\r\n const count = state.markers.length\r\n const captioned = state.label !== \"\"\r\n const from: Arrival = { opacity: 0, shift: slide }\r\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])]\r\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))\r\n if (count === 0) return arm\r\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)\r\n const ease = frameEase(timeline)\r\n // Bottom marker leads: the column is top → bottom, so walk it in reverse.\r\n const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))\r\n // Once every marker has landed, the caption slides in from the right.\r\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : []\r\n return timeline.together([arm, beats(timeline, [...markers, ...label])])\r\n },\r\n },\r\n },\r\n})\r\n\r\nexport type VerticalAxis = NodeOf<typeof VerticalAxis>\r\n"]}
@@ -1,4 +1,4 @@
1
- import { type AssetScope, Node2D, type Command, type CommandArgs, type EasingFunction, type Node2DProps, type RenderContext2D, type Stroke, type Vector2 } from "@motionscript/sdk";
1
+ import { type NodeOf, type Node2D as _Node2D, type Node2DProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
2
2
  import { type RegionBox } from "./shared.js";
3
3
  export interface ChartLineProps extends Node2DProps {
4
4
  /**
@@ -15,8 +15,8 @@ export interface ChartLineProps extends Node2DProps {
15
15
  * Defaults to **1**, unlike the standalone chart this was ported from: in an
16
16
  * editor a node's resting state is what the paused editor canvas paints, so a
17
17
  * chart that only appeared once a command had run would edit blind. {@link
18
- * enter} drives it from 0 regardless of where it rests, so the animation is
19
- * unchanged.
18
+ * ChartLine.enter} drives it from 0 regardless of where it rests, so the
19
+ * animation is unchanged.
20
20
  */
21
21
  progress: number;
22
22
  /**
@@ -39,53 +39,27 @@ export interface ChartLineProps extends Node2DProps {
39
39
  * Sized and positioned by the parent, which shares the plot's coordinate frame.
40
40
  *
41
41
  * Two signals drive it: {@link ChartLineProps.progress} traces the line in
42
- * (animated by {@link enter}) and `enabled` shows or hides it wholesale.
42
+ * (animated by `enter`) and `enabled` shows or hides it wholesale.
43
43
  */
44
- export declare class ChartLine extends Node2D<ChartLineProps> {
45
- points: Vector2[];
46
- stroke: Stroke;
47
- progress: number;
48
- enabled: boolean;
49
- spotlight: RegionBox;
50
- dimOpacity: number;
51
- /**
52
- * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
53
- * paint props it carries — see {@link declarePaints}.
54
- */
55
- declareAssets(assets: AssetScope): void;
56
- protected renderSelf(ctx: RenderContext2D): void;
57
- /**
58
- * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
59
- * by *cumulative arc length* so the line traces at a steady pace regardless of
60
- * uneven point spacing. Returns the whole-point prefix plus one interpolated
61
- * point partway along the active segment.
62
- */
63
- private tracePoints;
64
- /**
65
- * Trace the line in from its left end to its right over `duration` seconds.
66
- * Drives `progress` `0 → 1`.
67
- *
68
- * A `Command` rather than a generator, so the trace can be *evaluated* at a
69
- * time instead of run to one — which is what lets a scene containing this
70
- * chart be scrubbed in constant time. It no longer needs to prime `progress`
71
- * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces
72
- * by definition rather than by having reset something.
73
- */
74
- enter(args: CommandArgs<Record<string, never>> & {
75
- duration: number;
76
- }): Command<ChartLineProps>;
77
- /**
78
- * The trace, with both ends stated: `progress` runs `from` → `to`.
79
- *
80
- * What {@link LineChart.showSeries} and `hideSeries` are both made of — they
81
- * are the same motion in opposite directions, and expressing them as one thing
82
- * with endpoints is what stops the pair drifting apart.
83
- *
84
- * `enabled` rides along in the same value rather than being set before or after
85
- * the command. A line is drawable for every `t` the trace covers and undrawn
86
- * outside it, which is what makes arriving at a time backwards show what
87
- * arriving forwards does — a flag flipped by a side effect would not.
88
- */
89
- enterFrom(from: number, duration: number, easing?: EasingFunction, to?: number): Command<ChartLineProps>;
90
- }
44
+ export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
45
+ readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
46
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
47
+ readonly progress: 1;
48
+ readonly enabled: true;
49
+ readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
50
+ readonly dimOpacity: 0.2;
51
+ }>, {
52
+ readonly enter: {
53
+ readonly from: import("@motionscript/sdk").Type<number, number, false>;
54
+ readonly to: import("@motionscript/sdk").Type<number, number, false>;
55
+ };
56
+ }, null, _Node2D<Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
57
+ readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
58
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
59
+ readonly progress: 1;
60
+ readonly enabled: true;
61
+ readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
62
+ readonly dimOpacity: 0.2;
63
+ }>, null>>;
64
+ export type ChartLine = NodeOf<typeof ChartLine>;
91
65
  //# sourceMappingURL=chart-line.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-line.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,MAAM,EAKN,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EAEX,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAGj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WAAW,EAChB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD;;;OAGG;IACH,MAAM,EAAE,OAAO,EAAE,CAAA;IACjB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAA;IACd;;;;;;;;;OASG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;;;OAIG;IACH,SAAS,EAAE,SAAS,CAAA;IACpB,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAA;CACnB;AAuCD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;UA0EpB,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
@@ -1,45 +1,106 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { Graphics2D, Node2D, command, easeOut, strokeOps, property, } from "@motionscript/sdk";
1
+ import { Graphics2D, Types, component2d, strokeOps, } from "@motionscript/sdk";
2
+ import { fresh } from "../kit/entries.js";
3
+ import { frameEase } from "../kit/motion.js";
4
+ import { loadPaints } from "../kit/paints.js";
8
5
  import { SPOTLIGHT_DIM } from "../kit/shared.js";
9
6
  import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
10
- import { declarePaints } from "@motionscript/sdk/component";
7
+ /**
8
+ * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
9
+ * by *cumulative arc length* so the line traces at a steady pace regardless of
10
+ * uneven point spacing. Returns the whole-point prefix plus one interpolated
11
+ * point partway along the active segment.
12
+ */
13
+ function tracePoints(pts, p) {
14
+ if (p >= 1 || pts.length < 2)
15
+ return pts;
16
+ if (p <= 0)
17
+ return [];
18
+ const segLen = [];
19
+ let total = 0;
20
+ for (let i = 1; i < pts.length; i++) {
21
+ const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
22
+ segLen.push(d);
23
+ total += d;
24
+ }
25
+ if (total === 0)
26
+ return pts;
27
+ let target = total * p;
28
+ const out = [pts[0]];
29
+ for (let i = 0; i < segLen.length; i++) {
30
+ if (target >= segLen[i]) {
31
+ out.push(pts[i + 1]);
32
+ target -= segLen[i];
33
+ }
34
+ else {
35
+ const t = segLen[i] === 0 ? 0 : target / segLen[i];
36
+ out.push({
37
+ x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
38
+ y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
39
+ });
40
+ break;
41
+ }
42
+ }
43
+ return out;
44
+ }
11
45
  /**
12
46
  * A single series line of a {@link LineChart}: one rounded polyline traced
13
47
  * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
14
48
  * Sized and positioned by the parent, which shares the plot's coordinate frame.
15
49
  *
16
50
  * Two signals drive it: {@link ChartLineProps.progress} traces the line in
17
- * (animated by {@link enter}) and `enabled` shows or hides it wholesale.
51
+ * (animated by `enter`) and `enabled` shows or hides it wholesale.
18
52
  */
19
- export class ChartLine extends Node2D {
20
- /**
21
- * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
22
- * paint props it carries — see {@link declarePaints}.
23
- */
24
- declareAssets(assets) {
25
- super.declareAssets(assets);
26
- declarePaints(this, assets);
27
- }
28
- renderSelf(ctx) {
29
- if (!this.enabled)
53
+ export const ChartLine = component2d({
54
+ key: "chartLine",
55
+ state: {
56
+ points: fresh(() => []),
57
+ stroke: Types.custom([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
58
+ progress: 1,
59
+ enabled: true,
60
+ spotlight: fresh(() => EMPTY_REGION_BOX),
61
+ dimOpacity: SPOTLIGHT_DIM,
62
+ },
63
+ load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
64
+ commands: {
65
+ /**
66
+ * Trace the line from `from` to `to` over the command — by default in from
67
+ * its left end to its right. `showSeries` and `hideSeries` are the same
68
+ * motion in opposite directions, so both are this with their ends stated.
69
+ *
70
+ * `enabled` rides along in the same value rather than being set before or
71
+ * after the command: a line is drawable for every `t` the trace covers and
72
+ * undrawn outside it, which is what makes arriving at a time backwards show
73
+ * what arriving forwards does.
74
+ */
75
+ enter: {
76
+ args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },
77
+ run: (timeline) => {
78
+ const { from, to } = timeline.args;
79
+ const ease = frameEase(timeline);
80
+ return timeline.animate((t) => {
81
+ const progress = from + (to - from) * ease(t);
82
+ // Hidden only once it has fully retraced, so the last frame of a hide is
83
+ // the empty plot rather than a line that vanished a frame early.
84
+ return { progress, enabled: progress > 0 };
85
+ });
86
+ },
87
+ },
88
+ },
89
+ render: (ctx, state) => {
90
+ if (!state.enabled)
30
91
  return;
31
- const pts = this.points;
92
+ const pts = state.points;
32
93
  if (pts.length < 2)
33
94
  return;
34
- const p = Math.max(0, Math.min(1, this.progress));
95
+ const p = Math.max(0, Math.min(1, state.progress));
35
96
  if (p <= 0)
36
97
  return;
37
- const drawn = this.tracePoints(pts, p);
98
+ const drawn = tracePoints(pts, p);
38
99
  if (drawn.length < 2)
39
100
  return;
40
- const stroke = this.stroke;
101
+ const stroke = state.stroke;
41
102
  const radius = (stroke[0]?.weight ?? 0) * 2; // round the joins
42
- const box = this.spotlight;
103
+ const box = state.spotlight;
43
104
  if (!hasRegion(box)) {
44
105
  ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke));
45
106
  return;
@@ -52,105 +113,13 @@ export class ChartLine extends Node2D {
52
113
  ctx.draw(new Graphics2D()
53
114
  .line({ points: drawn, radius })
54
115
  .stroke(stroke)
55
- .opacity(Math.max(0, Math.min(1, this.dimOpacity))));
116
+ .opacity(Math.max(0, Math.min(1, state.dimOpacity))));
56
117
  // One `draw` per run: shapes chained before a `stroke()` are combined into a
57
118
  // single surface, and stroking a union of disjoint open paths doesn't paint
58
119
  // — so a line that leaves the region and comes back would lose both halves.
59
120
  for (const run of clipPolylineToBox(drawn, box)) {
60
121
  ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
61
122
  }
62
- }
63
- /**
64
- * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
65
- * by *cumulative arc length* so the line traces at a steady pace regardless of
66
- * uneven point spacing. Returns the whole-point prefix plus one interpolated
67
- * point partway along the active segment.
68
- */
69
- tracePoints(pts, p) {
70
- if (p >= 1 || pts.length < 2)
71
- return pts;
72
- if (p <= 0)
73
- return [];
74
- const segLen = [];
75
- let total = 0;
76
- for (let i = 1; i < pts.length; i++) {
77
- const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
78
- segLen.push(d);
79
- total += d;
80
- }
81
- if (total === 0)
82
- return pts;
83
- let target = total * p;
84
- const out = [pts[0]];
85
- for (let i = 0; i < segLen.length; i++) {
86
- if (target >= segLen[i]) {
87
- out.push(pts[i + 1]);
88
- target -= segLen[i];
89
- }
90
- else {
91
- const t = segLen[i] === 0 ? 0 : target / segLen[i];
92
- out.push({
93
- x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
94
- y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
95
- });
96
- break;
97
- }
98
- }
99
- return out;
100
- }
101
- /**
102
- * Trace the line in from its left end to its right over `duration` seconds.
103
- * Drives `progress` `0 → 1`.
104
- *
105
- * A `Command` rather than a generator, so the trace can be *evaluated* at a
106
- * time instead of run to one — which is what lets a scene containing this
107
- * chart be scrubbed in constant time. It no longer needs to prime `progress`
108
- * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces
109
- * by definition rather than by having reset something.
110
- */
111
- enter(args) {
112
- return this.enterFrom(0, args.duration, args.easing ?? easeOut());
113
- }
114
- /**
115
- * The trace, with both ends stated: `progress` runs `from` → `to`.
116
- *
117
- * What {@link LineChart.showSeries} and `hideSeries` are both made of — they
118
- * are the same motion in opposite directions, and expressing them as one thing
119
- * with endpoints is what stops the pair drifting apart.
120
- *
121
- * `enabled` rides along in the same value rather than being set before or after
122
- * the command. A line is drawable for every `t` the trace covers and undrawn
123
- * outside it, which is what makes arriving at a time backwards show what
124
- * arriving forwards does — a flag flipped by a side effect would not.
125
- */
126
- enterFrom(from, duration, easing = easeOut(), to = 1) {
127
- return this.command((t) => {
128
- const progress = from + (to - from) * t;
129
- // Hidden only once it has fully retraced, so the last frame of a hide is
130
- // the empty plot rather than a line that vanished a frame early.
131
- return { progress, enabled: progress > 0 };
132
- }, duration, easing);
133
- }
134
- }
135
- __decorate([
136
- property({ default: () => [] })
137
- ], ChartLine.prototype, "points", void 0);
138
- __decorate([
139
- property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })
140
- ], ChartLine.prototype, "stroke", void 0);
141
- __decorate([
142
- property({ default: 1 })
143
- ], ChartLine.prototype, "progress", void 0);
144
- __decorate([
145
- property({ default: true })
146
- ], ChartLine.prototype, "enabled", void 0);
147
- __decorate([
148
- property({ default: () => EMPTY_REGION_BOX })
149
- ], ChartLine.prototype, "spotlight", void 0);
150
- __decorate([
151
- property({ default: SPOTLIGHT_DIM })
152
- ], ChartLine.prototype, "dimOpacity", void 0);
153
- __decorate([
154
- command()
155
- ], ChartLine.prototype, "enter", null);
123
+ },
124
+ });
156
125
  //# sourceMappingURL=chart-line.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-line.js","sourceRoot":"","sources":["../../src/line-ch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,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAC;4CAA6B;AAC7B;IAA7C,QAAQ,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;6CAA2B;AAkGhE;IADC,OAAO,EAAE;sCAGT","sourcesContent":["import {\r\n type AssetScope,\r\n Graphics2D,\r\n Node2D,\r\n command,\r\n easeOut,\r\n strokeOps,\r\n property,\r\n type Command,\r\n type CommandArgs,\r\n type EasingFunction,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\r\nimport {\r\n EMPTY_REGION_BOX,\r\n clipPolylineToBox,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\n\r\nexport interface ChartLineProps extends Node2DProps {\r\n /**\r\n * The series polyline, already mapped into this node's local pixel space\r\n * (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x.\r\n */\r\n points: Vector2[]\r\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\r\n stroke: Stroke\r\n /**\r\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\r\n * end to its right.\r\n *\r\n * Defaults to **1**, unlike the standalone chart this was ported from: in an\r\n * editor a node's resting state is what the paused editor canvas paints, so a\r\n * chart that only appeared once a command had run would edit blind. {@link\r\n * enter} drives it from 0 regardless of where it rests, so the animation is\r\n * unchanged.\r\n */\r\n progress: number\r\n /**\r\n * Whether this line is drawn at all. `false` hides it outright — the switch\r\n * the chart flips alongside its legend's per-series toggle.\r\n */\r\n enabled: boolean\r\n /**\r\n * A slice of the plot to spotlight, in this node's own pixel space. When set\r\n * to a real box, the stretches of the line *outside* it drop to\r\n * {@link ChartLineProps.dimOpacity} while the stretches inside stay full.\r\n */\r\n spotlight: RegionBox\r\n /** Opacity the out-of-region stretches fade to. */\r\n dimOpacity: number\r\n}\r\n\r\n/**\r\n * A single series line of a {@link LineChart}: one rounded polyline traced\r\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\r\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\r\n *\r\n * Two signals drive it: {@link ChartLineProps.progress} traces the line in\r\n * (animated by {@link enter}) and `enabled` shows or hides it wholesale.\r\n */\r\nexport class ChartLine extends Node2D<ChartLineProps> {\r\n @property({ default: () => [] as Vector2[] }) declare points: Vector2[]\r\n @property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })\r\n declare stroke: Stroke\r\n @property({ default: 1 }) declare progress: number\r\n @property({ default: true }) declare enabled: boolean\r\n @property({ default: () => EMPTY_REGION_BOX }) declare spotlight: RegionBox\r\n @property({ default: SPOTLIGHT_DIM }) declare dimOpacity: number\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n if (!this.enabled) return\r\n const pts = this.points\r\n if (pts.length < 2) return\r\n\r\n const p = Math.max(0, Math.min(1, this.progress))\r\n if (p <= 0) return\r\n\r\n const drawn = this.tracePoints(pts, p)\r\n if (drawn.length < 2) return\r\n const stroke = this.stroke as StrokeResolved[]\r\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\r\n\r\n const box = this.spotlight\r\n if (!hasRegion(box)) {\r\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\r\n return\r\n }\r\n\r\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\r\n // inside the region are re-drawn over it at full strength. Two passes rather\r\n // than one dim + one bright *complementary* pair, so the bright run has\r\n // continuous geometry through the region and its joins round the way an\r\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\r\n ctx.draw(\r\n new Graphics2D()\r\n .line({ points: drawn, radius })\r\n .stroke(stroke)\r\n .opacity(Math.max(0, Math.min(1, this.dimOpacity)))\r\n )\r\n\r\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\r\n // single surface, and stroking a union of disjoint open paths doesn't paint\r\n // — so a line that leaves the region and comes back would lose both halves.\r\n for (const run of clipPolylineToBox(drawn, box)) {\r\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\r\n }\r\n }\r\n\r\n /**\r\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\r\n * by *cumulative arc length* so the line traces at a steady pace regardless of\r\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\r\n * point partway along the active segment.\r\n */\r\n private tracePoints(pts: Vector2[], p: number): Vector2[] {\r\n if (p >= 1 || pts.length < 2) return pts\r\n if (p <= 0) return []\r\n\r\n const segLen: number[] = []\r\n let total = 0\r\n for (let i = 1; i < pts.length; i++) {\r\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\r\n segLen.push(d)\r\n total += d\r\n }\r\n if (total === 0) return pts\r\n\r\n let target = total * p\r\n const out: Vector2[] = [pts[0]]\r\n for (let i = 0; i < segLen.length; i++) {\r\n if (target >= segLen[i]) {\r\n out.push(pts[i + 1])\r\n target -= segLen[i]\r\n } else {\r\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\r\n out.push({\r\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\r\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\r\n })\r\n break\r\n }\r\n }\r\n return out\r\n }\r\n\r\n /**\r\n * Trace the line in from its left end to its right over `duration` seconds.\r\n * Drives `progress` `0 → 1`.\r\n *\r\n * A `Command` rather than a generator, so the trace can be *evaluated* at a\r\n * time instead of run to one — which is what lets a scene containing this\r\n * chart be scrubbed in constant time. It no longer needs to prime `progress`\r\n * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces\r\n * by definition rather than by having reset something.\r\n */\r\n @command()\r\n enter(args: CommandArgs<Record<string, never>> & { duration: number }): Command<ChartLineProps> {\r\n return this.enterFrom(0, args.duration, args.easing ?? easeOut())\r\n }\r\n\r\n /**\r\n * The trace, with both ends stated: `progress` runs `from` → `to`.\r\n *\r\n * What {@link LineChart.showSeries} and `hideSeries` are both made of — they\r\n * are the same motion in opposite directions, and expressing them as one thing\r\n * with endpoints is what stops the pair drifting apart.\r\n *\r\n * `enabled` rides along in the same value rather than being set before or after\r\n * the command. A line is drawable for every `t` the trace covers and undrawn\r\n * outside it, which is what makes arriving at a time backwards show what\r\n * arriving forwards does — a flag flipped by a side effect would not.\r\n */\r\n enterFrom(\r\n from: number,\r\n duration: number,\r\n easing: EasingFunction = easeOut(),\r\n to = 1\r\n ): Command<ChartLineProps> {\r\n return this.command<ChartLineProps>(\r\n (t) => {\r\n const progress = from + (to - from) * t\r\n // Hidden only once it has fully retraced, so the last frame of a hide is\r\n // the empty plot rather than a line that vanished a frame early.\r\n return { progress, enabled: progress > 0 }\r\n },\r\n duration,\r\n easing\r\n )\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"chart-line.js","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,SAAS,GAQV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GAEV,MAAM,UAAU,CAAA;AAoCjB;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAc,EAAE,CAAS;IAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC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M,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA,CAAC,kBAAkB;QAE9D,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAA;QAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;YACzE,OAAM;QACR,CAAC;QAED,wEAAwE;QACxE,6EAA6E;QAC7E,wEAAwE;QACxE,wEAAwE;QACxE,8EAA8E;QAC9E,GAAG,CAAC,IAAI,CACN,IAAI,UAAU,EAAE;aACb,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;aAC/B,MAAM,CAAC,MAAM,CAAC;aACd,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CACvD,CAAA;QAED,6EAA6E;QAC7E,4EAA4E;QAC5E,4EAA4E;QAC5E,KAAK,MAAM,GAAG,IAAI,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n strokeOps,\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 Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { frameEase } from \"../kit/motion\"\r\nimport { loadPaints } from \"../kit/paints\"\r\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\r\nimport {\r\n EMPTY_REGION_BOX,\r\n clipPolylineToBox,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\n\r\nexport interface ChartLineProps extends Node2DProps {\r\n /**\r\n * The series polyline, already mapped into this node's local pixel space\r\n * (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x.\r\n */\r\n points: Vector2[]\r\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\r\n stroke: Stroke\r\n /**\r\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\r\n * end to its right.\r\n *\r\n * Defaults to **1**, unlike the standalone chart this was ported from: in an\r\n * editor a node's resting state is what the paused editor canvas paints, so a\r\n * chart that only appeared once a command had run would edit blind. {@link\r\n * ChartLine.enter} drives it from 0 regardless of where it rests, so the\r\n * animation is unchanged.\r\n */\r\n progress: number\r\n /**\r\n * Whether this line is drawn at all. `false` hides it outright — the switch\r\n * the chart flips alongside its legend's per-series toggle.\r\n */\r\n enabled: boolean\r\n /**\r\n * A slice of the plot to spotlight, in this node's own pixel space. When set\r\n * to a real box, the stretches of the line *outside* it drop to\r\n * {@link ChartLineProps.dimOpacity} while the stretches inside stay full.\r\n */\r\n spotlight: RegionBox\r\n /** Opacity the out-of-region stretches fade to. */\r\n dimOpacity: number\r\n}\r\n\r\n/**\r\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\r\n * by *cumulative arc length* so the line traces at a steady pace regardless of\r\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\r\n * point partway along the active segment.\r\n */\r\nfunction tracePoints(pts: Vector2[], p: number): Vector2[] {\r\n if (p >= 1 || pts.length < 2) return pts\r\n if (p <= 0) return []\r\n\r\n const segLen: number[] = []\r\n let total = 0\r\n for (let i = 1; i < pts.length; i++) {\r\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\r\n segLen.push(d)\r\n total += d\r\n }\r\n if (total === 0) return pts\r\n\r\n let target = total * p\r\n const out: Vector2[] = [pts[0]]\r\n for (let i = 0; i < segLen.length; i++) {\r\n if (target >= segLen[i]) {\r\n out.push(pts[i + 1])\r\n target -= segLen[i]\r\n } else {\r\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\r\n out.push({\r\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\r\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\r\n })\r\n break\r\n }\r\n }\r\n return out\r\n}\r\n\r\n/**\r\n * A single series line of a {@link LineChart}: one rounded polyline traced\r\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\r\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\r\n *\r\n * Two signals drive it: {@link ChartLineProps.progress} traces the line in\r\n * (animated by `enter`) and `enabled` shows or hides it wholesale.\r\n */\r\nexport const ChartLine = component2d({\r\n key: \"chartLine\",\r\n state: {\r\n points: fresh<Vector2[]>(() => []),\r\n stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\r\n progress: 1,\r\n enabled: true,\r\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\r\n dimOpacity: SPOTLIGHT_DIM,\r\n },\r\n load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),\r\n commands: {\r\n /**\r\n * Trace the line from `from` to `to` over the command — by default in from\r\n * its left end to its right. `showSeries` and `hideSeries` are the same\r\n * motion in opposite directions, so both are this with their ends stated.\r\n *\r\n * `enabled` rides along in the same value rather than being set before or\r\n * after the command: a line is drawable for every `t` the trace covers and\r\n * undrawn outside it, which is what makes arriving at a time backwards show\r\n * what arriving forwards does.\r\n */\r\n enter: {\r\n args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },\r\n run: (timeline) => {\r\n const { from, to } = timeline.args\r\n const ease = frameEase(timeline)\r\n return timeline.animate((t) => {\r\n const progress = from + (to - from) * ease(t)\r\n // Hidden only once it has fully retraced, so the last frame of a hide is\r\n // the empty plot rather than a line that vanished a frame early.\r\n return { progress, enabled: progress > 0 }\r\n })\r\n },\r\n },\r\n },\r\n render: (ctx, state) => {\r\n if (!state.enabled) return\r\n const pts = state.points\r\n if (pts.length < 2) return\r\n\r\n const p = Math.max(0, Math.min(1, state.progress))\r\n if (p <= 0) return\r\n\r\n const drawn = tracePoints(pts, p)\r\n if (drawn.length < 2) return\r\n const stroke = state.stroke\r\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\r\n\r\n const box = state.spotlight\r\n if (!hasRegion(box)) {\r\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\r\n return\r\n }\r\n\r\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\r\n // inside the region are re-drawn over it at full strength. Two passes rather\r\n // than one dim + one bright *complementary* pair, so the bright run has\r\n // continuous geometry through the region and its joins round the way an\r\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\r\n ctx.draw(\r\n new Graphics2D()\r\n .line({ points: drawn, radius })\r\n .stroke(stroke)\r\n .opacity(Math.max(0, Math.min(1, state.dimOpacity)))\r\n )\r\n\r\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\r\n // single surface, and stroking a union of disjoint open paths doesn't paint\r\n // — so a line that leaves the region and comes back would lose both halves.\r\n for (const run of clipPolylineToBox(drawn, box)) {\r\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\r\n }\r\n },\r\n})\r\n\r\nexport type ChartLine = NodeOf<typeof ChartLine>\r\n"]}
@@ -1,4 +1,4 @@
1
- import { type AssetScope, Node2D, type Fill, type Node2DProps, type RenderContext2D, type Stroke } from "@motionscript/sdk";
1
+ import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps, type Stroke, type StrokeResolved } from "@motionscript/sdk";
2
2
  import { type RegionBox } from "./shared.js";
3
3
  export interface ChartRegionProps extends Node2DProps {
4
4
  /**
@@ -22,7 +22,7 @@ export interface ChartRegionProps extends Node2DProps {
22
22
  * The **region call-out** of a {@link LineChart}: a washed rectangle over the
23
23
  * plot with a dashed rule down each edge the author actually bounded. Sized and
24
24
  * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather
25
- * than its own `layoutBounds` — the box already carries the plot geometry.
25
+ * than its own box — the region already carries the plot geometry.
26
26
  *
27
27
  * It draws only the *marking*; fading the series outside the region is
28
28
  * {@link ChartLine}'s job (it clips its own polyline against the same box), so
@@ -32,16 +32,16 @@ export interface ChartRegionProps extends Node2DProps {
32
32
  * plot height, so its top and bottom edges are the plot's own border, not a data
33
33
  * bound — drawing dashes there would assert a limit the author didn't set.
34
34
  */
35
- export declare class ChartRegion extends Node2D<ChartRegionProps> {
36
- box: RegionBox;
37
- stroke: Stroke;
38
- fill: Fill;
39
- reveal: number;
40
- /**
41
- * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
42
- * paint props it carries — see {@link declarePaints}.
43
- */
44
- declareAssets(assets: AssetScope): void;
45
- protected renderSelf(ctx: RenderContext2D): void;
46
- }
35
+ export declare const ChartRegion: import("@motionscript/sdk").Component<"chartRegion", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
36
+ readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
37
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
38
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
39
+ readonly reveal: 0;
40
+ }>, {}, null, _Node2D<Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
41
+ readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
42
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
43
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
44
+ readonly reveal: 0;
45
+ }>, null>>;
46
+ export type ChartRegion = NodeOf<typeof ChartRegion>;
47
47
  //# sourceMappingURL=chart-region.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-region.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,MAAM,EAIN,KAAK,IAAI,EAET,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EAEZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAGjB,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD;;;;OAIG;IACH,GAAG,EAAE,SAAS,CAAA;IACd,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAA;IACd,oDAAoD;IACpD,IAAI,EAAE,IAAI,CAAA;IACV;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAY,SAAQ,MAAM,CAAC,gBAAgB,CAAC;IACA,GAAG,EAAE,SAAS,CAAA;IAM7D,MAAM,EAAE,MAAM,CAAA;IAMd,IAAI,EAAE,IAAI,CAAA;IACgB,MAAM,EAAE,MAAM,CAAA;IAEhD;;;OAGG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;CAqDjD"}
1
+ {"version":3,"file":"chart-region.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAIL,KAAK,SAAS,E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