@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.
- package/CHANGELOG.md +105 -0
- package/NOTICE +49 -0
- package/README.md +99 -0
- package/dist/bar-chart/bar-chart.d.ts +133 -228
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +386 -565
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +35 -41
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +93 -115
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +50 -70
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +155 -210
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -2
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +7 -7
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +7 -7
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
- package/dist/browser/chunks/chunk-TJNHLQGV.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +4 -3
- package/dist/engine.d.ts +10 -8
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +10 -8
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +44 -0
- package/dist/kit/cartesian.d.ts.map +1 -0
- package/dist/kit/cartesian.js +59 -0
- package/dist/kit/cartesian.js.map +1 -0
- package/dist/kit/chart-border.d.ts +10 -11
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +15 -32
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -21
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +33 -90
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +123 -85
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +137 -186
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +17 -0
- package/dist/kit/entries.d.ts.map +1 -0
- package/dist/kit/entries.js +19 -0
- package/dist/kit/entries.js.map +1 -0
- package/dist/kit/motion.d.ts +48 -0
- package/dist/kit/motion.d.ts.map +1 -0
- package/dist/kit/motion.js +63 -0
- package/dist/kit/motion.js.map +1 -0
- package/dist/kit/paints.d.ts +10 -0
- package/dist/kit/paints.d.ts.map +1 -0
- package/dist/kit/paints.js +12 -0
- package/dist/kit/paints.js.map +1 -0
- package/dist/kit/shared.d.ts +61 -10
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +108 -13
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +48 -61
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +97 -132
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +60 -77
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +100 -121
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +32 -33
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +31 -65
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +58 -64
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +94 -123
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +3 -3
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +2 -2
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +156 -303
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +410 -638
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +7 -7
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +23 -8
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +4 -11
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +16 -5
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -2
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +108 -126
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +202 -271
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +84 -31
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +93 -107
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +160 -122
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +333 -361
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +12 -6
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +14 -8
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +7 -4
- package/src/bar-chart/bar-chart.ts +424 -686
- package/src/bar-chart/category-axis.ts +96 -111
- package/src/bar-chart/chart-bars.ts +178 -201
- package/src/bar-chart/index.ts +2 -2
- package/src/bar-chart/shared.ts +7 -7
- package/src/engine.ts +10 -8
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +23 -34
- package/src/kit/chart-canvas.ts +45 -80
- package/src/kit/chart-legend.ts +185 -206
- package/src/kit/entries.ts +20 -0
- package/src/kit/motion.ts +90 -0
- package/src/kit/paints.ts +15 -0
- package/src/kit/shared.ts +120 -13
- package/src/kit/vertical-axis.ts +111 -141
- package/src/line-chart/chart-line.ts +103 -155
- package/src/line-chart/chart-region.ts +36 -81
- package/src/line-chart/horizontal-axis.ts +102 -153
- package/src/line-chart/index.ts +3 -3
- package/src/line-chart/line-chart.ts +463 -759
- package/src/line-chart/shared.ts +22 -8
- package/src/line-chart/x-scale.ts +20 -5
- package/src/nodes.ts +8 -10
- package/src/pie-chart/index.ts +2 -2
- package/src/pie-chart/pie-chart.ts +225 -303
- package/src/pie-chart/pie-legend.ts +125 -115
- package/src/pie-chart/pie-ring.ts +388 -443
- package/src/pie-chart/shared.ts +14 -8
- package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
- package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
package/src/line-chart/shared.ts
CHANGED
|
@@ -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
|
|
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
|
|
14
|
-
* mapping
|
|
15
|
-
* pulling the
|
|
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/
|
|
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`
|
|
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`
|
|
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
|
-
|
|
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/
|
|
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/
|
|
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
|
-
*
|
|
312
|
-
*
|
|
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
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
15
|
-
* `sideEffects: false`,
|
|
16
|
-
*
|
|
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
|
-
|
|
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];
|
package/src/pie-chart/index.ts
CHANGED
|
@@ -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"
|