@motionscript/charts 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (152) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/NOTICE +49 -0
  3. package/README.md +99 -0
  4. package/dist/bar-chart/bar-chart.d.ts +133 -228
  5. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  6. package/dist/bar-chart/bar-chart.js +386 -565
  7. package/dist/bar-chart/bar-chart.js.map +1 -1
  8. package/dist/bar-chart/category-axis.d.ts +35 -41
  9. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  10. package/dist/bar-chart/category-axis.js +93 -115
  11. package/dist/bar-chart/category-axis.js.map +1 -1
  12. package/dist/bar-chart/chart-bars.d.ts +50 -70
  13. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  14. package/dist/bar-chart/chart-bars.js +155 -210
  15. package/dist/bar-chart/chart-bars.js.map +1 -1
  16. package/dist/bar-chart/index.d.ts +2 -2
  17. package/dist/bar-chart/index.d.ts.map +1 -1
  18. package/dist/bar-chart/index.js +1 -1
  19. package/dist/bar-chart/index.js.map +1 -1
  20. package/dist/bar-chart/shared.d.ts +7 -7
  21. package/dist/bar-chart/shared.d.ts.map +1 -1
  22. package/dist/bar-chart/shared.js +7 -7
  23. package/dist/bar-chart/shared.js.map +1 -1
  24. package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
  25. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +7 -0
  26. package/dist/browser/index.js +1 -1
  27. package/dist/browser/index.js.map +3 -3
  28. package/dist/browser/kit.js +1 -1
  29. package/dist/browser/manifest.json +4 -3
  30. package/dist/engine.d.ts +10 -8
  31. package/dist/engine.d.ts.map +1 -1
  32. package/dist/engine.js +10 -8
  33. package/dist/engine.js.map +1 -1
  34. package/dist/kit/cartesian.d.ts +44 -0
  35. package/dist/kit/cartesian.d.ts.map +1 -0
  36. package/dist/kit/cartesian.js +59 -0
  37. package/dist/kit/cartesian.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +10 -11
  39. package/dist/kit/chart-border.d.ts.map +1 -1
  40. package/dist/kit/chart-border.js +15 -32
  41. package/dist/kit/chart-border.js.map +1 -1
  42. package/dist/kit/chart-canvas.d.ts +32 -21
  43. package/dist/kit/chart-canvas.d.ts.map +1 -1
  44. package/dist/kit/chart-canvas.js +33 -90
  45. package/dist/kit/chart-canvas.js.map +1 -1
  46. package/dist/kit/chart-legend.d.ts +123 -85
  47. package/dist/kit/chart-legend.d.ts.map +1 -1
  48. package/dist/kit/chart-legend.js +137 -186
  49. package/dist/kit/chart-legend.js.map +1 -1
  50. package/dist/kit/entries.d.ts +17 -0
  51. package/dist/kit/entries.d.ts.map +1 -0
  52. package/dist/kit/entries.js +19 -0
  53. package/dist/kit/entries.js.map +1 -0
  54. package/dist/kit/motion.d.ts +48 -0
  55. package/dist/kit/motion.d.ts.map +1 -0
  56. package/dist/kit/motion.js +63 -0
  57. package/dist/kit/motion.js.map +1 -0
  58. package/dist/kit/paints.d.ts +10 -0
  59. package/dist/kit/paints.d.ts.map +1 -0
  60. package/dist/kit/paints.js +12 -0
  61. package/dist/kit/paints.js.map +1 -0
  62. package/dist/kit/shared.d.ts +61 -10
  63. package/dist/kit/shared.d.ts.map +1 -1
  64. package/dist/kit/shared.js +108 -13
  65. package/dist/kit/shared.js.map +1 -1
  66. package/dist/kit/vertical-axis.d.ts +48 -61
  67. package/dist/kit/vertical-axis.d.ts.map +1 -1
  68. package/dist/kit/vertical-axis.js +97 -132
  69. package/dist/kit/vertical-axis.js.map +1 -1
  70. package/dist/line-chart/chart-line.d.ts +60 -77
  71. package/dist/line-chart/chart-line.d.ts.map +1 -1
  72. package/dist/line-chart/chart-line.js +100 -121
  73. package/dist/line-chart/chart-line.js.map +1 -1
  74. package/dist/line-chart/chart-region.d.ts +32 -33
  75. package/dist/line-chart/chart-region.d.ts.map +1 -1
  76. package/dist/line-chart/chart-region.js +31 -65
  77. package/dist/line-chart/chart-region.js.map +1 -1
  78. package/dist/line-chart/horizontal-axis.d.ts +58 -64
  79. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  80. package/dist/line-chart/horizontal-axis.js +94 -123
  81. package/dist/line-chart/horizontal-axis.js.map +1 -1
  82. package/dist/line-chart/index.d.ts +3 -3
  83. package/dist/line-chart/index.d.ts.map +1 -1
  84. package/dist/line-chart/index.js +2 -2
  85. package/dist/line-chart/index.js.map +1 -1
  86. package/dist/line-chart/line-chart.d.ts +156 -303
  87. package/dist/line-chart/line-chart.d.ts.map +1 -1
  88. package/dist/line-chart/line-chart.js +410 -638
  89. package/dist/line-chart/line-chart.js.map +1 -1
  90. package/dist/line-chart/shared.d.ts +7 -7
  91. package/dist/line-chart/shared.d.ts.map +1 -1
  92. package/dist/line-chart/shared.js +23 -8
  93. package/dist/line-chart/shared.js.map +1 -1
  94. package/dist/line-chart/x-scale.d.ts +4 -11
  95. package/dist/line-chart/x-scale.d.ts.map +1 -1
  96. package/dist/line-chart/x-scale.js +16 -5
  97. package/dist/line-chart/x-scale.js.map +1 -1
  98. package/dist/nodes.d.ts +6 -9
  99. package/dist/nodes.d.ts.map +1 -1
  100. package/dist/nodes.js +7 -9
  101. package/dist/nodes.js.map +1 -1
  102. package/dist/pie-chart/index.d.ts +2 -2
  103. package/dist/pie-chart/index.d.ts.map +1 -1
  104. package/dist/pie-chart/index.js +1 -1
  105. package/dist/pie-chart/index.js.map +1 -1
  106. package/dist/pie-chart/pie-chart.d.ts +108 -126
  107. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  108. package/dist/pie-chart/pie-chart.js +202 -271
  109. package/dist/pie-chart/pie-chart.js.map +1 -1
  110. package/dist/pie-chart/pie-legend.d.ts +84 -31
  111. package/dist/pie-chart/pie-legend.d.ts.map +1 -1
  112. package/dist/pie-chart/pie-legend.js +93 -107
  113. package/dist/pie-chart/pie-legend.js.map +1 -1
  114. package/dist/pie-chart/pie-ring.d.ts +160 -122
  115. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  116. package/dist/pie-chart/pie-ring.js +333 -361
  117. package/dist/pie-chart/pie-ring.js.map +1 -1
  118. package/dist/pie-chart/shared.d.ts +12 -6
  119. package/dist/pie-chart/shared.d.ts.map +1 -1
  120. package/dist/pie-chart/shared.js +14 -8
  121. package/dist/pie-chart/shared.js.map +1 -1
  122. package/package.json +7 -4
  123. package/src/bar-chart/bar-chart.ts +424 -686
  124. package/src/bar-chart/category-axis.ts +96 -111
  125. package/src/bar-chart/chart-bars.ts +178 -201
  126. package/src/bar-chart/index.ts +2 -2
  127. package/src/bar-chart/shared.ts +7 -7
  128. package/src/engine.ts +10 -8
  129. package/src/kit/cartesian.ts +81 -0
  130. package/src/kit/chart-border.ts +23 -34
  131. package/src/kit/chart-canvas.ts +45 -80
  132. package/src/kit/chart-legend.ts +185 -206
  133. package/src/kit/entries.ts +20 -0
  134. package/src/kit/motion.ts +90 -0
  135. package/src/kit/paints.ts +15 -0
  136. package/src/kit/shared.ts +120 -13
  137. package/src/kit/vertical-axis.ts +111 -141
  138. package/src/line-chart/chart-line.ts +103 -155
  139. package/src/line-chart/chart-region.ts +36 -81
  140. package/src/line-chart/horizontal-axis.ts +102 -153
  141. package/src/line-chart/index.ts +3 -3
  142. package/src/line-chart/line-chart.ts +463 -759
  143. package/src/line-chart/shared.ts +22 -8
  144. package/src/line-chart/x-scale.ts +20 -5
  145. package/src/nodes.ts +8 -10
  146. package/src/pie-chart/index.ts +2 -2
  147. package/src/pie-chart/pie-chart.ts +225 -303
  148. package/src/pie-chart/pie-legend.ts +125 -115
  149. package/src/pie-chart/pie-ring.ts +388 -443
  150. package/src/pie-chart/shared.ts +14 -8
  151. package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
  152. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
@@ -5,14 +5,14 @@
5
5
  *
6
6
  * Everything a bar or a pie chart would want too — what a series is, how an axis
7
7
  * is scaled and formatted, the theme leaf resolvers, the legend and plot-panel
8
- * branches — lives in `nodes/chart-kit/shared.ts` and is imported here. What's
8
+ * branches — lives in `../kit/shared.ts` and is imported here. What's
9
9
  * left below is what only a line chart has: points sorted along an x column,
10
10
  * a region clipped out of a polyline, and the `region` branch of the theme.
11
11
  *
12
12
  * Kept renderer-agnostic (no `Node` imports) so every part shares one
13
- * scale/format/palette/theme vocabulary, and so the studio's own inspector
14
- * mapping (`line-chart-props.ts`) can build a partial {@link ChartTheme} without
15
- * pulling the node classes in.
13
+ * scale/format/palette/theme vocabulary, and so a host's own inspector
14
+ * mapping can build a partial {@link ChartTheme} without
15
+ * pulling the components in.
16
16
  */
17
17
 
18
18
  import {
@@ -25,7 +25,7 @@ import {
25
25
  type FillResolved,
26
26
  type Stroke,
27
27
  type StrokeResolved,
28
- } from "@motionscript/core"
28
+ } from "@motionscript/sdk"
29
29
 
30
30
  import {
31
31
  CHART_PALETTE,
@@ -365,7 +365,7 @@ function lerpRegionConfig(
365
365
  }
366
366
 
367
367
  /**
368
- * {@link LineChart}'s `theme` @property mapper: merges the author's partial
368
+ * {@link LineChart}'s `theme` entry's resolve: merges the author's partial
369
369
  * {@link ChartTheme} onto `previous` (falling back to
370
370
  * {@link DEFAULT_CHART_THEME} on first resolution), fully resolving every leaf.
371
371
  */
@@ -384,7 +384,7 @@ export function resolveChartTheme(
384
384
  }
385
385
  }
386
386
 
387
- /** {@link LineChart}'s `theme` @property tween — leaf by leaf. */
387
+ /** {@link LineChart}'s `theme` entry's lerp — leaf by leaf. */
388
388
  export function lerpChartTheme(
389
389
  from: ChartConfig,
390
390
  to: ChartConfig,
@@ -454,6 +454,20 @@ export function resolveYScale(
454
454
  if (range) return range
455
455
  const [lo, hi] = yExtent(data, series)
456
456
  const segments = Math.max(1, Math.round(divisions))
457
- const step = niceStep((hi - lo) / segments || 1)
457
+ if (hi === lo) return constantScale(lo, segments)
458
+ const step = niceStep((hi - lo) / segments)
458
459
  return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step]
459
460
  }
461
+
462
+ /**
463
+ * The scale for data that never moves. A zero-width scale puts every tick on the
464
+ * same value and the line on the plot's floor, so it is widened to a few steps
465
+ * either side of the value (the step sized to its magnitude, so `5` gets
466
+ * `[3, 7]` and `5000` gets `[3000, 7000]`), or to `[0, 1]` for all zeros, as for
467
+ * no data at all.
468
+ */
469
+ function constantScale(value: number, segments: number): Range {
470
+ if (value === 0) return [0, 1]
471
+ const step = niceStep(Math.abs(value) / segments)
472
+ return [value - step, value + step]
473
+ }
@@ -26,7 +26,7 @@
26
26
  * and that is the one case {@link formatInstant} covers.
27
27
  */
28
28
 
29
- import type { DataRecord } from "@motionscript/core"
29
+ import type { DataRecord } from "@motionscript/sdk"
30
30
 
31
31
  import {
32
32
  formatMarker,
@@ -35,7 +35,7 @@ import {
35
35
  text,
36
36
  type Range,
37
37
  } from "../kit/shared"
38
- import { formatNumber } from "@motionscript/core/component"
38
+ import { formatNumber } from "@motionscript/sdk/component"
39
39
 
40
40
  /** How an x column's cells become positions along the axis. */
41
41
  export type XScaleKind = "numeric" | "time" | "ordinal"
@@ -304,15 +304,30 @@ function labelBySample(
304
304
  return i >= 0 ? captions[i] : fallback(value)
305
305
  }
306
306
 
307
+ /** Scales already resolved, by data array, then by field and pattern. */
308
+ const scales = new WeakMap<DataRecord[], Map<string, XScale>>()
309
+
307
310
  /**
308
311
  * How `field` positions the rows: the number it holds, the instant it names, or
309
312
  * failing both, the row's own place in the file.
310
313
  *
311
- * Resolved from the data on every read rather than cached on the node: it is
312
- * cheap (one pass to classify, one to position), and a cache keyed on a `data`
313
- * array that `buildScene` rebuilds on every edit would miss every time anyway.
314
+ * Kept per `data` array: a chart's bound props ask a dozen times a frame, and
315
+ * parsing every row's instant each time was most of a frame.
314
316
  */
315
317
  export function resolveXScale(
318
+ data: DataRecord[],
319
+ field: string,
320
+ pattern?: string
321
+ ): XScale {
322
+ let byKey = scales.get(data)
323
+ if (!byKey) scales.set(data, (byKey = new Map()))
324
+ const key = JSON.stringify([field, pattern ?? null])
325
+ let scale = byKey.get(key)
326
+ if (!scale) byKey.set(key, (scale = xScaleOf(data, field, pattern)))
327
+ return scale
328
+ }
329
+
330
+ function xScaleOf(
316
331
  data: DataRecord[],
317
332
  field: string,
318
333
  /**
package/src/nodes.ts CHANGED
@@ -6,15 +6,13 @@ import { PieChart } from "./pie-chart";
6
6
  * Every node type this package publishes.
7
7
  *
8
8
  * A host registers these by handing the array to an engine —
9
- * `new Engine(platform, { nodes: NODES })` — which reads each class's `@node()`
10
- * key. The decorator only *declares* that key: nothing is registered by the mere
11
- * act of importing a module, so a registry holds exactly what its owner asked
12
- * for and two engines in one process can differ about it.
9
+ * `new Engine(platform, { nodes: NODES })` — which reads each component's key.
10
+ * Defining a component only *declares* that key: nothing is registered by
11
+ * importing a module, so a registry holds exactly what its owner asked for.
13
12
  *
14
- * Listing class **values** is also what survives bundling. This package declares
15
- * `sideEffects: false`, which licenses a bundler to drop a module nothing
16
- * imports a value from, and a document names a node type by string — so
17
- * `import "./line-chart"` for its side effect is exactly what gets shaken out, where an
18
- * array of bindings is a data dependency that cannot be.
13
+ * Listing the component **values** is also what survives bundling: this package
14
+ * declares `sideEffects: false`, and a document names a node type by string, so
15
+ * an import kept only for its side effect is exactly what gets shaken out.
19
16
  */
20
- export const NODES = [LineChart, BarChart, PieChart];
17
+ // Typed by name, so the declaration names each component rather than spelling out its type through core.
18
+ export const NODES: (typeof LineChart | typeof BarChart | typeof PieChart)[] = [LineChart, BarChart, PieChart];
@@ -7,8 +7,8 @@
7
7
  * pie; it defaults to a donut, because the hole is the only place a chart has
8
8
  * to put its conclusion.
9
9
  */
10
- export { PieChart } from "./pie-chart"
11
- export type { PieChartProps } from "./pie-chart"
10
+ export { PieChart, isSliceSelected } from "./pie-chart"
11
+ export type { PieChartProps, PieChartValues } from "./pie-chart"
12
12
  export { PieRing } from "./pie-ring"
13
13
  export type { PieRingProps } from "./pie-ring"
14
14
  export { PieLegend } from "./pie-legend"