@sophistry/charts 0.0.0-stage → 0.1.0

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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/dist/3d/bar-chart3d.d.ts +55 -0
  4. package/dist/3d/definitions.d.ts +37 -0
  5. package/dist/3d/definitions.js +14 -0
  6. package/dist/3d/forward.d.ts +64 -0
  7. package/dist/3d/index.d.ts +30 -0
  8. package/dist/3d/index.js +1 -0
  9. package/dist/3d/quiver3d.d.ts +52 -0
  10. package/dist/3d/scatter3d.d.ts +44 -0
  11. package/dist/3d/stem3d.d.ts +45 -0
  12. package/dist/3d/surface-grid3d.d.ts +33 -0
  13. package/dist/3d/tri-surface3d.d.ts +45 -0
  14. package/dist/3d/voxels3d.d.ts +25 -0
  15. package/dist/3d/wireframe3d.d.ts +30 -0
  16. package/dist/band.d.ts +20 -0
  17. package/dist/bars/bar-chart.d.ts +143 -0
  18. package/dist/bars/bar-labels.d.ts +116 -0
  19. package/dist/bars/bars.d.ts +223 -0
  20. package/dist/bars/bullet.d.ts +157 -0
  21. package/dist/bars/candlestick.d.ts +97 -0
  22. package/dist/bars/funnel.d.ts +90 -0
  23. package/dist/bars/histogram.d.ts +108 -0
  24. package/dist/bars/index.d.ts +22 -0
  25. package/dist/bars/race.d.ts +28 -0
  26. package/dist/bars/rules.d.ts +121 -0
  27. package/dist/bars/shared.d.ts +41 -0
  28. package/dist/bars/transforms.d.ts +249 -0
  29. package/dist/bars/waterfall.d.ts +106 -0
  30. package/dist/batch.d.ts +142 -0
  31. package/dist/channels-_Xf-p6Lx.js +56 -0
  32. package/dist/chart.d.ts +87 -0
  33. package/dist/color-norm.d.ts +90 -0
  34. package/dist/context.d.ts +111 -0
  35. package/dist/curves/density.d.ts +125 -0
  36. package/dist/curves/ecdf.d.ts +72 -0
  37. package/dist/curves/fill-between.d.ts +100 -0
  38. package/dist/curves/index.d.ts +15 -0
  39. package/dist/curves/line-plot.d.ts +104 -0
  40. package/dist/curves/regression.d.ts +124 -0
  41. package/dist/curves/shared.d.ts +52 -0
  42. package/dist/curves/stack-plot.d.ts +140 -0
  43. package/dist/curves/stairs.d.ts +170 -0
  44. package/dist/data/channels.d.ts +170 -0
  45. package/dist/end-space.d.ts +81 -0
  46. package/dist/entries/definitions.d.ts +20 -0
  47. package/dist/entries/definitions.js +6 -0
  48. package/dist/frame/band-axis.d.ts +42 -0
  49. package/dist/frame/coords.d.ts +111 -0
  50. package/dist/frame/fit.d.ts +170 -0
  51. package/dist/frame/format.d.ts +40 -0
  52. package/dist/frame/guide-metrics.d.ts +36 -0
  53. package/dist/frame/guides.d.ts +67 -0
  54. package/dist/frame/keys.d.ts +96 -0
  55. package/dist/frame/layout.d.ts +145 -0
  56. package/dist/frame/registry.d.ts +31 -0
  57. package/dist/frame/reports.d.ts +53 -0
  58. package/dist/frame/secondary-axes.d.ts +73 -0
  59. package/dist/frame/secondary.d.ts +56 -0
  60. package/dist/frame/tooltip-overlay.d.ts +64 -0
  61. package/dist/frame/types.d.ts +658 -0
  62. package/dist/grids/barbs.d.ts +51 -0
  63. package/dist/grids/cell-rects.d.ts +37 -0
  64. package/dist/grids/cells.d.ts +130 -0
  65. package/dist/grids/contour-f.d.ts +80 -0
  66. package/dist/grids/contour-shared.d.ts +53 -0
  67. package/dist/grids/contour.d.ts +84 -0
  68. package/dist/grids/dendrogram.d.ts +104 -0
  69. package/dist/grids/heatmap.d.ts +163 -0
  70. package/dist/grids/hex-bin.d.ts +93 -0
  71. package/dist/grids/hist2d.d.ts +107 -0
  72. package/dist/grids/imshow.d.ts +84 -0
  73. package/dist/grids/index.d.ts +26 -0
  74. package/dist/grids/pcolormesh.d.ts +90 -0
  75. package/dist/grids/ramp-cells.d.ts +66 -0
  76. package/dist/grids/tri-contour.d.ts +120 -0
  77. package/dist/grids/tri-shared.d.ts +61 -0
  78. package/dist/grids/tripcolor.d.ts +73 -0
  79. package/dist/guides/colorbar.d.ts +110 -0
  80. package/dist/guides/index.d.ts +11 -0
  81. package/dist/guides/legend.d.ts +118 -0
  82. package/dist/guides/nodes.d.ts +13 -0
  83. package/dist/guides/size-legend.d.ts +233 -0
  84. package/dist/hierarchy/breadcrumbs.d.ts +133 -0
  85. package/dist/hierarchy/circle-pack.d.ts +72 -0
  86. package/dist/hierarchy/drill.d.ts +245 -0
  87. package/dist/hierarchy/frame.d.ts +67 -0
  88. package/dist/hierarchy/icicle.d.ts +76 -0
  89. package/dist/hierarchy/index.d.ts +20 -0
  90. package/dist/hierarchy/labels.d.ts +24 -0
  91. package/dist/hierarchy/mosaic.d.ts +130 -0
  92. package/dist/hierarchy/own-tooltip.d.ts +12 -0
  93. package/dist/hierarchy/props.d.ts +13 -0
  94. package/dist/hierarchy/sankey.d.ts +132 -0
  95. package/dist/hierarchy/shared.d.ts +247 -0
  96. package/dist/hierarchy/sunburst.d.ts +74 -0
  97. package/dist/hierarchy/tree.d.ts +124 -0
  98. package/dist/hierarchy/treemap.d.ts +76 -0
  99. package/dist/index.d.ts +29 -0
  100. package/dist/index.js +5 -0
  101. package/dist/item-tooltip.d.ts +33 -0
  102. package/dist/join.d.ts +223 -0
  103. package/dist/math/3d/bar3d.d.ts +27 -0
  104. package/dist/math/3d/quiver3d.d.ts +26 -0
  105. package/dist/math/3d/scatter3d.d.ts +15 -0
  106. package/dist/math/3d/stem3d.d.ts +22 -0
  107. package/dist/math/3d/surfaceGrid3d.d.ts +33 -0
  108. package/dist/math/3d/trisurface.d.ts +11 -0
  109. package/dist/math/3d/voxels.d.ts +17 -0
  110. package/dist/math/aggregate.d.ts +68 -0
  111. package/dist/math/bar.d.ts +31 -0
  112. package/dist/math/barLabels.d.ts +83 -0
  113. package/dist/math/barbs.d.ts +36 -0
  114. package/dist/math/boxplot.d.ts +36 -0
  115. package/dist/math/breadcrumbs.d.ts +128 -0
  116. package/dist/math/bubble.d.ts +38 -0
  117. package/dist/math/bullet.d.ts +110 -0
  118. package/dist/math/chord.d.ts +103 -0
  119. package/dist/math/cluster.d.ts +88 -0
  120. package/dist/math/contour.d.ts +48 -0
  121. package/dist/math/contourf.d.ts +50 -0
  122. package/dist/math/dodge.d.ts +36 -0
  123. package/dist/math/ecdf.d.ts +41 -0
  124. package/dist/math/errorbar.d.ts +27 -0
  125. package/dist/math/eventplot.d.ts +26 -0
  126. package/dist/math/facet.d.ts +90 -0
  127. package/dist/math/fillBetween.d.ts +28 -0
  128. package/dist/math/gauge.d.ts +71 -0
  129. package/dist/math/hexbin.d.ts +20 -0
  130. package/dist/math/hierarchy.d.ts +179 -0
  131. package/dist/math/hierarchyJoin.d.ts +59 -0
  132. package/dist/math/histogram.d.ts +36 -0
  133. package/dist/math/histogram2d.d.ts +44 -0
  134. package/dist/math/imshow.d.ts +26 -0
  135. package/dist/math/index.d.ts +139 -0
  136. package/dist/math/index.js +3 -0
  137. package/dist/math/jitter.d.ts +16 -0
  138. package/dist/math/join.d.ts +135 -0
  139. package/dist/math/keyframes.d.ts +127 -0
  140. package/dist/math/legend.d.ts +120 -0
  141. package/dist/math/line.d.ts +53 -0
  142. package/dist/math/morph.d.ts +81 -0
  143. package/dist/math/mosaic.d.ts +119 -0
  144. package/dist/math/ordinal.d.ts +79 -0
  145. package/dist/math/parallel.d.ts +38 -0
  146. package/dist/math/pcolormesh.d.ts +22 -0
  147. package/dist/math/pie.d.ts +105 -0
  148. package/dist/math/polarArea.d.ts +34 -0
  149. package/dist/math/radar.d.ts +110 -0
  150. package/dist/math/range.d.ts +98 -0
  151. package/dist/math/regression.d.ts +109 -0
  152. package/dist/math/reveal.d.ts +63 -0
  153. package/dist/math/sankey.d.ts +154 -0
  154. package/dist/math/scatter.d.ts +14 -0
  155. package/dist/math/shared/binning.d.ts +23 -0
  156. package/dist/math/shared/gridCells.d.ts +41 -0
  157. package/dist/math/shared/gridExtent.d.ts +5 -0
  158. package/dist/math/shared/pairs.d.ts +2 -0
  159. package/dist/math/shared/polar.d.ts +23 -0
  160. package/dist/math/stack.d.ts +69 -0
  161. package/dist/math/stackplot.d.ts +35 -0
  162. package/dist/math/stairs.d.ts +17 -0
  163. package/dist/math/stem.d.ts +21 -0
  164. package/dist/math/symbol.d.ts +25 -0
  165. package/dist/math/tree.d.ts +117 -0
  166. package/dist/math/tricontour.d.ts +76 -0
  167. package/dist/math/violin.d.ts +99 -0
  168. package/dist/math/waffle.d.ts +48 -0
  169. package/dist/math/waterfall.d.ts +28 -0
  170. package/dist/math-CSHNpGej.js +3648 -0
  171. package/dist/mix.d.ts +24 -0
  172. package/dist/multiview/brush.d.ts +165 -0
  173. package/dist/multiview/chart-group.d.ts +265 -0
  174. package/dist/multiview/chart-link.d.ts +188 -0
  175. package/dist/multiview/chart-zoom.d.ts +144 -0
  176. package/dist/multiview/facet.d.ts +238 -0
  177. package/dist/multiview/group-guides.d.ts +99 -0
  178. package/dist/multiview/index.d.ts +17 -0
  179. package/dist/multiview/joint-plot.d.ts +114 -0
  180. package/dist/multiview/pair-plot.d.ts +153 -0
  181. package/dist/multiview/panels.d.ts +22 -0
  182. package/dist/multiview/parallel-coordinates.d.ts +109 -0
  183. package/dist/points/event-plot.d.ts +67 -0
  184. package/dist/points/index.d.ts +19 -0
  185. package/dist/points/labels.d.ts +70 -0
  186. package/dist/points/links.d.ts +123 -0
  187. package/dist/points/rects.d.ts +80 -0
  188. package/dist/points/rug.d.ts +72 -0
  189. package/dist/points/scatter.d.ts +169 -0
  190. package/dist/points/segment-marks.d.ts +39 -0
  191. package/dist/points/shared.d.ts +34 -0
  192. package/dist/points/stem.d.ts +75 -0
  193. package/dist/points/strip.d.ts +145 -0
  194. package/dist/points/symbol-marker.d.ts +33 -0
  195. package/dist/points/ticks.d.ts +102 -0
  196. package/dist/props.d.ts +126 -0
  197. package/dist/radial/chord.d.ts +148 -0
  198. package/dist/radial/gauge.d.ts +126 -0
  199. package/dist/radial/index.d.ts +15 -0
  200. package/dist/radial/pie-chart.d.ts +143 -0
  201. package/dist/radial/polar-area-chart.d.ts +135 -0
  202. package/dist/radial/radar-chart.d.ts +176 -0
  203. package/dist/radial/radial-bar-chart.d.ts +116 -0
  204. package/dist/radial/shared.d.ts +78 -0
  205. package/dist/radial/waffle.d.ts +130 -0
  206. package/dist/raster.d.ts +43 -0
  207. package/dist/series.d.ts +71 -0
  208. package/dist/src-CwGo1bes.js +19221 -0
  209. package/dist/stagger.d.ts +54 -0
  210. package/dist/statistics/box-plot.d.ts +151 -0
  211. package/dist/statistics/error-bar.d.ts +148 -0
  212. package/dist/statistics/groups.d.ts +140 -0
  213. package/dist/statistics/index.d.ts +7 -0
  214. package/dist/statistics/violin-plot.d.ts +143 -0
  215. package/dist/text-width.d.ts +9 -0
  216. package/dist/tooltip.d.ts +276 -0
  217. package/dist/util.d.ts +33 -0
  218. package/dist/voxels-9lJ2TZS4.js +235 -0
  219. package/dist/wireframe3d-D157GZAq.js +345 -0
  220. package/package.json +86 -3
@@ -0,0 +1,124 @@
1
+ /**
2
+ * `regression`: a fitted trend (least squares or LOESS) with its confidence
3
+ * band, one per `series`, drawn as one path batch (per fit a closed band
4
+ * item, then an open line item) in a group whose clip the reveal sweeps.
5
+ */
6
+ import type { ColorInput } from "@sophistry/core/color";
7
+ import type { BandKey } from "@sophistry/core/geometry";
8
+ import type { Channel, PositionValue } from "../data/channels.js";
9
+ import type { SeriesTransitionProps } from "../props.js";
10
+ /**
11
+ * Props of {@link regressionPlot}: `x` and `y` default to the index and the
12
+ * datum when `data` is `number[]`; name them otherwise.
13
+ *
14
+ * @category Charts
15
+ */
16
+ export interface RegressionProps<T = unknown> extends SeriesTransitionProps<T> {
17
+ /** The points the fit is through: one per datum. */
18
+ data: readonly T[];
19
+ /**
20
+ * Predictor, in data units (a `Date` reads as epoch ms). Defaults to the index when `data` is
21
+ * `number[]`; required otherwise.
22
+ */
23
+ x?: Channel<T, PositionValue>;
24
+ /**
25
+ * Response, in data units. Defaults to the datum when `data` is `number[]`; required otherwise.
26
+ * Pairs with a non-finite member are dropped.
27
+ */
28
+ y?: Channel<T, number>;
29
+ /**
30
+ * The fit: `"linear"`, `"poly"` (a polynomial of `degree`) or `"loess"` (a local smooth over
31
+ * `bandwidth` of the points).
32
+ * @default "linear"
33
+ */
34
+ method?: "linear" | "poly" | "loess";
35
+ /**
36
+ * Polynomial degree for `method="poly"`.
37
+ * @default 2
38
+ */
39
+ degree?: number;
40
+ /**
41
+ * Fraction of the points each local fit uses, for `method="loess"`.
42
+ * @default 0.3
43
+ */
44
+ bandwidth?: number;
45
+ /**
46
+ * Make a `method="loess"` smooth robust to outliers: `true` for 2 re-weighting passes, or a
47
+ * number of passes.
48
+ * @default false
49
+ */
50
+ robust?: boolean | number;
51
+ /**
52
+ * Confidence level of the band around the fit, 0..1 (0 for no band): the fitted mean's t-band
53
+ * for least squares, the standard-error band for LOESS (see {@link loessBand}).
54
+ * @default 0.95
55
+ */
56
+ level?: number;
57
+ /**
58
+ * How many x positions the fit is drawn through.
59
+ * @default 50
60
+ */
61
+ samples?: number;
62
+ /**
63
+ * The category of each datum: one fit per category, coloured through the chart's shared colour
64
+ * scale and legend. `color` wins.
65
+ */
66
+ series?: Channel<T, BandKey>;
67
+ /**
68
+ * Line and band colour. Defaults to the `series` colour, else the theme's first series colour.
69
+ */
70
+ color?: ColorInput;
71
+ /**
72
+ * Band fill opacity, 0..1.
73
+ * @default 0.2
74
+ */
75
+ bandOpacity?: number;
76
+ /** Line width. */
77
+ strokeWidth?: number;
78
+ /** Opacity 0..1. @default 1 */
79
+ opacity?: number;
80
+ /**
81
+ * Reveal, 0..1: the line and its band sweep in left to right together.
82
+ * @default 1
83
+ * @see https://sophistry.dev/guides/chart-animation/#reveals
84
+ */
85
+ progress?: number;
86
+ /**
87
+ * The data to transition to, fits matched by `series`: shared fits morph with their bands, new
88
+ * ones sweep in, leaving ones fade out. See {@link SeriesTransitionProps}.
89
+ * @see https://sophistry.dev/guides/chart-animation/#data-transitions
90
+ */
91
+ to?: readonly T[];
92
+ /** Paint order. */
93
+ zIndex?: number;
94
+ /** Set to false to hide the fits. */
95
+ visible?: boolean;
96
+ }
97
+ /**
98
+ * A fitted trend with its confidence band over the data's x extent: least
99
+ * squares (a line or polynomial) or a LOESS smooth. Draw it over a
100
+ * `scatter` of the same data. See the `regression` and `loessBand` maths for
101
+ * the fits alone.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { chart, regressionPlot, scatter } from "@sophistry/charts";
106
+ *
107
+ * const rows = [1, 2, 3, 4, 5, 6, 7, 8].map((x) => ({ x, y: Math.sqrt(x) + Math.sin(x) / 4 }));
108
+ * chart.create({
109
+ * width: 8,
110
+ * height: 4,
111
+ * children: [
112
+ * scatter.create({ data: rows, x: "x", y: "y" }),
113
+ * regressionPlot.create({ data: rows, x: "x", y: "y", method: "loess" }),
114
+ * ],
115
+ * });
116
+ * ```
117
+ *
118
+ * Exported as `regressionPlot` (definition name `"Regression"`): the
119
+ * package entry already exports the `regression` fit from its maths.
120
+ *
121
+ * @see https://sophistry.dev/reference/chart-catalogue/#lines-scatter-and-error-bars
122
+ * @category Charts
123
+ */
124
+ export declare const regressionPlot: import("@sophistry/core").Definition<RegressionProps<any>, import("@sophistry/core/internal").CompositeNode<RegressionProps<any>>, keyof RegressionProps<any>>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * What the line and area marks (`linePlot`, `stackPlot`, `fillBetween`,
3
+ * `stairs`, `ecdf`, `density`, `regression`) share: the one path batch each
4
+ * draws through (with the clip a sweep reveal needs), stable items so an
5
+ * outline that did not move is prepared once, and group colours across a
6
+ * keyed transition. Internal.
7
+ *
8
+ * Every curve mark draws one shape per group (a `series` category, or the
9
+ * one `WHOLE` group), and those shapes have outlines of their own, so the
10
+ * mark is one core `pathBatch` node: an item per line, band or region, each
11
+ * with its own stroke or fill and opacity. A `reveal="length"` draw hands
12
+ * each item its `progress` (the stroke traced along
13
+ * the outline, a closed outline's fill coming up with it), over the whole
14
+ * outline; the batch keeps an outline's arrays while only that changes, so
15
+ * the renderer measures their arc length once.
16
+ */
17
+ import type { Bindable, PathBatchItem, PathBatchItemsProps, PathBatchNode, SceneNode } from "@sophistry/core";
18
+ import type { Bounds } from "@sophistry/core/geometry";
19
+ import type { ChartLayer } from "../context.js";
20
+ import type { GroupJoin } from "../join.js";
21
+ import type { GroupKey, SeriesState } from "../series.js";
22
+ /**
23
+ * A group's colour from the series scale, across a keyed transition: while
24
+ * one runs, over both ends' categories (`data`'s first), so a category keeps
25
+ * its colour. Undefined for {@link WHOLE}, or when an explicit colour wins.
26
+ */
27
+ export declare function groupColors(layer: ChartLayer, series: SeriesState, join: GroupJoin): (key: GroupKey) => string | undefined;
28
+ /**
29
+ * The one path batch of a curve mark, inside a group whose clip a sweep
30
+ * reveal moves. Call once, in `setup`.
31
+ */
32
+ export interface CurveBatch {
33
+ /** The node to return from the mark: the group holding the batch. */
34
+ readonly node: SceneNode;
35
+ /** The batch itself. */
36
+ readonly batch: PathBatchNode<PathBatchItemsProps>;
37
+ /**
38
+ * Writes one update's items (`[slot key, item]` pairs, in paint order),
39
+ * shared props and clip. An item equal to the one its slot held last time
40
+ * is handed over as that same object, one whose outline alone is equal
41
+ * (its `progress` or a paint changed) around the same outline arrays, and
42
+ * an unchanged list as the same array, so the batch re-prepares only
43
+ * outlines that moved.
44
+ */
45
+ update(items: readonly (readonly [unknown, PathBatchItem])[], shared: Bindable<Omit<PathBatchItemsProps, "items">>, clip?: Bounds | undefined): void;
46
+ /** The items as last written. */
47
+ readonly items: readonly PathBatchItem[];
48
+ }
49
+ /** Makes a mark's {@link CurveBatch}. */
50
+ export declare function createCurveBatch(): CurveBatch;
51
+ /** A group's slot key in a batch with more than one item per group (`"fill"`, `"line"`). */
52
+ export declare function slotOf(key: GroupKey, part: string): string;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * `stackPlot`: a stacked area chart, drawn as one path batch (a closed item
3
+ * per band) in a group whose clip the `"x"` reveal sweeps; `reveal="length"`
4
+ * traces each band's outline (the item's `progress`), its fill coming up
5
+ * with it.
6
+ *
7
+ * Across a keyed transition each end is stacked on its own, a band one end
8
+ * lacks stands with no thickness on its seam, and the update morphs each
9
+ * band's bounds together, so adjacent bands stay touching on every frame.
10
+ */
11
+ import type { PaintSpec } from "@sophistry/core";
12
+ import type { ColorInput } from "@sophistry/core/color";
13
+ import type { BandKey, CurveKind } from "@sophistry/core/geometry";
14
+ import type { Channel, PositionValue } from "../data/channels.js";
15
+ import type { JoinStaging } from "../math/join.js";
16
+ import type { StackOffset, StackOrder } from "../math/stack.js";
17
+ import type { StackReveal, TransitionProps } from "../props.js";
18
+ /**
19
+ * Props of {@link stackPlot}: `x` defaults to the index when `data` is
20
+ * `number[]`; name it otherwise.
21
+ *
22
+ * @category Charts
23
+ */
24
+ export interface StackPlotProps<T = unknown> extends TransitionProps<T> {
25
+ /**
26
+ * Wide format (`y` a list): one row per x position. Long format (`y` one channel, with a
27
+ * `series`): one row per band per x position.
28
+ */
29
+ data: readonly T[];
30
+ /**
31
+ * X position, in data units (a `Date` reads as epoch ms). Defaults to the index when `data` is
32
+ * `number[]`; required otherwise.
33
+ */
34
+ x?: Channel<T, PositionValue>;
35
+ /**
36
+ * One channel per band, stacked in the order given (`y: ["north", "south"]`); or one channel,
37
+ * for long-format `data`, with `series` naming each row's band. Non-finite heights count as 0.
38
+ */
39
+ y: readonly Channel<T, number>[] | Channel<T, number>;
40
+ /**
41
+ * Which series each band is, colouring bands through the chart's shared colour scale and
42
+ * legend: with a list of `y` channels, one name per channel; with one `y` channel, a channel
43
+ * naming each row's band (rows missing at an x count as 0).
44
+ */
45
+ series?: readonly BandKey[] | Channel<T, BandKey>;
46
+ /**
47
+ * Colours cycled across bands by index. Defaults to the `series` colours, else the theme's
48
+ * categorical colours.
49
+ */
50
+ colors?: readonly ColorInput[];
51
+ /**
52
+ * Data-space y the first band stacks on, under the `"zero"` offset. Defaults to the axis
53
+ * baseline.
54
+ */
55
+ baseline?: number;
56
+ /**
57
+ * Where each x's stack is placed: `"zero"` on the baseline, `"normalize"` as shares of the
58
+ * total, `"center"` centred on zero, `"wiggle"` a streamgraph (needs ascending, evenly spaced
59
+ * x). See {@link StackOffset}.
60
+ * @default "zero"
61
+ */
62
+ offset?: StackOffset;
63
+ /**
64
+ * Which band sits at the bottom: `"appearance"`, `"reverse"`, `"sum"` (largest on top),
65
+ * `"insideOut"` (streamgraph order), or band indices bottom to top. Colours stay with their
66
+ * band.
67
+ * @default "appearance"
68
+ */
69
+ order?: StackOrder;
70
+ /**
71
+ * How `progress` reveals the stack: `"grow"` every band's height from the baseline together,
72
+ * `"x"` left to right behind one front, `"length"` each band's outline by arc length.
73
+ * @default "grow"
74
+ * @see https://sophistry.dev/guides/chart-animation/#reveals
75
+ */
76
+ reveal?: StackReveal;
77
+ /**
78
+ * How band edges run between rows: `"linear"` or any {@link CurveKind} (`"monotone"` for a
79
+ * smooth stack). Adjacent bands still share their edge exactly.
80
+ * @default "linear"
81
+ */
82
+ curve?: CurveKind;
83
+ /**
84
+ * The data to transition to, bands matched by `series` (long format) or place in `y` (wide):
85
+ * each end is stacked on its own and shared bands morph between them, so every frame is a
86
+ * stack. Leaving bands shrink away, new ones grow in.
87
+ * @see https://sophistry.dev/guides/chart-animation/#data-transitions
88
+ */
89
+ to?: readonly T[];
90
+ /**
91
+ * How the transition spends `blend`.
92
+ * @default "staged"
93
+ */
94
+ staging?: JoinStaging;
95
+ /**
96
+ * With `to`: fraction of the enter stage spent staggering arriving bands, bottom up, 0..0.95.
97
+ * @default 0
98
+ */
99
+ enterStagger?: number;
100
+ /** Band fill opacity 0..1. @default 0.85 */
101
+ fillOpacity?: number;
102
+ /** Band outline. @default "none" */
103
+ stroke?: PaintSpec;
104
+ /** Outline width. */
105
+ strokeWidth?: number;
106
+ /** Opacity 0..1. @default 1 */
107
+ opacity?: number;
108
+ /** Reveal 0..1 (see `reveal`). @default 1 */
109
+ progress?: number;
110
+ /** Paint order (the bands paint under the axes of that order). */
111
+ zIndex?: number;
112
+ /** Set to false to hide the bands. */
113
+ visible?: boolean;
114
+ }
115
+ /**
116
+ * A stacked area chart: bands stacked atop a shared baseline, each shaded in
117
+ * its own colour. Use `offset` for 100% areas or streamgraphs. Inside a
118
+ * `chart` (or any `axes` whose y range covers the stacked total). See
119
+ * {@link stackedBands} for the stacking alone.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { chart, stackPlot } from "@sophistry/charts";
124
+ *
125
+ * const rows = [
126
+ * { year: 2022, north: 3, south: 2 },
127
+ * { year: 2023, north: 4, south: 3 },
128
+ * { year: 2024, north: 5, south: 3 },
129
+ * ];
130
+ * chart.create({
131
+ * width: 8,
132
+ * height: 4,
133
+ * children: [stackPlot.create({ data: rows, x: "year", y: ["north", "south"], series: ["North", "South"] })],
134
+ * });
135
+ * ```
136
+ *
137
+ * @see https://sophistry.dev/reference/chart-catalogue/#stacked-areas
138
+ * @category Charts
139
+ */
140
+ export declare const stackPlot: import("@sophistry/core").Definition<StackPlotProps<any>, import("@sophistry/core/internal").CompositeNode<StackPlotProps<any>>, keyof StackPlotProps<any>>;
@@ -0,0 +1,170 @@
1
+ /**
2
+ * `stairs`: a step function held flat across each `[edges[i], edges[i + 1]]`
3
+ * interval, one open line per `series`, drawn as one path batch. Also the
4
+ * step-line drawing `ecdf` shares ({@link stepLineItems}): lines kept by
5
+ * group, coloured by the series scale unless `stroke` is set, revealed along
6
+ * x behind one front (or by arc length), and morphed as step functions
7
+ * across a keyed transition.
8
+ */
9
+ import type { CoordinateSystem, PaintSpec, SceneNode } from "@sophistry/core";
10
+ import type { BandKey, Point } from "@sophistry/core/geometry";
11
+ import type { Channel } from "../data/channels.js";
12
+ import type { ChartFrame } from "../frame/types.js";
13
+ import type { GroupJoin } from "../join.js";
14
+ import type { StepFunction } from "../math/morph.js";
15
+ import type { CurveReveal, SeriesTransitionProps } from "../props.js";
16
+ import type { GroupKey } from "../series.js";
17
+ import type { CurveBatch } from "./shared.js";
18
+ /**
19
+ * The stroke props every step line takes (`stairs`, `ecdf`).
20
+ *
21
+ * @category Charts
22
+ */
23
+ export interface StepLineStyleProps {
24
+ /** Line colour (or gradient) for every line. Defaults to the `series` colour, else the theme's foreground. */
25
+ stroke?: PaintSpec;
26
+ /** Line width. Defaults to the theme's stroke width. */
27
+ strokeWidth?: number;
28
+ /** Dash pattern, in scene units. Solid when omitted. */
29
+ dash?: number[];
30
+ /** Offset into `dash`. @default 0 */
31
+ dashOffset?: number;
32
+ /** How line ends are capped. @default "round" */
33
+ lineCap?: CanvasLineCap;
34
+ /** How corners are joined. @default "round" */
35
+ lineJoin?: CanvasLineJoin;
36
+ /** Opacity 0..1. @default 1 */
37
+ opacity?: number;
38
+ /** Reveal 0..1 (see `reveal`). @default 1 */
39
+ progress?: number;
40
+ /** Paint order. */
41
+ zIndex?: number;
42
+ /** Set to false to hide the lines. */
43
+ visible?: boolean;
44
+ }
45
+ /**
46
+ * Props of {@link stairs}: `value` defaults to the datum when `data` is
47
+ * `number[]`; name it otherwise.
48
+ *
49
+ * @category Charts
50
+ */
51
+ export interface StairsProps<T = unknown> extends SeriesTransitionProps<T>, StepLineStyleProps {
52
+ /** One step per datum. */
53
+ data: readonly T[];
54
+ /**
55
+ * Height of each step, in data units, held across `[edges[i], edges[i + 1]]`. Defaults to the
56
+ * datum when `data` is `number[]`; required otherwise.
57
+ */
58
+ value?: Channel<T, number>;
59
+ /**
60
+ * Step boundaries in data units, ascending, exactly one more than `data` (else throws). With a
61
+ * `series`, shared by every category. Defaults to `0..data.length`.
62
+ */
63
+ edges?: readonly number[];
64
+ /**
65
+ * The category of each datum: one step line per category, coloured through the chart's shared
66
+ * colour scale and legend. `stroke` wins.
67
+ */
68
+ series?: Channel<T, BandKey>;
69
+ /**
70
+ * How `progress` reveals the steps: `"x"` left to right at a constant rate, or `"length"` by
71
+ * arc length.
72
+ * @default "x"
73
+ * @see https://sophistry.dev/guides/chart-animation/#reveals
74
+ */
75
+ reveal?: CurveReveal;
76
+ /**
77
+ * The data to transition to, lines matched by `series`: shared lines morph and stay step
78
+ * functions every frame, new ones sweep in, leaving ones fade out. See {@link
79
+ * SeriesTransitionProps}.
80
+ * @see https://sophistry.dev/guides/chart-animation/#data-transitions
81
+ */
82
+ to?: readonly T[];
83
+ }
84
+ /** The descriptor entries of {@link StepLineStyleProps}. */
85
+ export declare const stepLineStyleDescriptor: {
86
+ readonly stroke: {
87
+ readonly invalidates: 64;
88
+ };
89
+ readonly strokeWidth: {
90
+ readonly invalidates: 64;
91
+ };
92
+ readonly dash: {
93
+ readonly invalidates: 64;
94
+ };
95
+ readonly dashOffset: {
96
+ readonly invalidates: 64;
97
+ };
98
+ readonly lineCap: {
99
+ readonly invalidates: 64;
100
+ };
101
+ readonly lineJoin: {
102
+ readonly invalidates: 64;
103
+ };
104
+ readonly opacity: {
105
+ readonly invalidates: 64;
106
+ };
107
+ readonly progress: {
108
+ readonly default: 1;
109
+ readonly invalidates: 64;
110
+ };
111
+ readonly zIndex: {
112
+ readonly invalidates: 64;
113
+ };
114
+ readonly visible: {
115
+ readonly invalidates: 64;
116
+ };
117
+ };
118
+ /** What a step-line drawing keeps between updates. */
119
+ export interface StepLines {
120
+ scene: (deps: readonly unknown[], make: () => Map<GroupKey, Point[][]>) => Map<GroupKey, Point[][]>;
121
+ lines: CurveBatch;
122
+ }
123
+ /** Makes a {@link StepLines}. Call once, in `setup`. */
124
+ export declare function createStepLines(): StepLines;
125
+ /**
126
+ * Draws one step line per group (what `stairs` and `ecdf` share): each
127
+ * group's line in scene units on this frame (morphed as a step function on
128
+ * the update stage, entering ones swept in, leaving ones faded), cut at one
129
+ * front along x (or by arc length), as path batch items.
130
+ *
131
+ * @internal
132
+ */
133
+ export declare function drawStepLines(own: StepLines, spec: {
134
+ props: StepLineStyleProps;
135
+ theme: {
136
+ palette: {
137
+ foreground: string;
138
+ };
139
+ };
140
+ frame: ChartFrame | null;
141
+ coords: CoordinateSystem;
142
+ /** `data`'s step functions, per group. */
143
+ steps: Map<GroupKey, StepFunction>;
144
+ /** `to`'s, while a transition runs. */
145
+ to: Map<GroupKey, StepFunction> | undefined;
146
+ join: GroupJoin;
147
+ colorOf: (key: GroupKey) => string | undefined;
148
+ progress: number | undefined;
149
+ alongX: boolean;
150
+ }): SceneNode[];
151
+ /**
152
+ * A step function held flat across each `[edges[i], edges[i + 1]]` interval,
153
+ * drawn as one open line: a histogram's outline without the fill. Inside a
154
+ * `chart` or `axes`. See {@link stairsPolyline} for the geometry alone.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { chart, stairs } from "@sophistry/charts";
159
+ *
160
+ * chart.create({
161
+ * width: 8,
162
+ * height: 4,
163
+ * children: [stairs.create({ data: [3, 5, 2, 6], edges: [0, 1, 2, 4, 5] })],
164
+ * });
165
+ * ```
166
+ *
167
+ * @see https://sophistry.dev/reference/chart-catalogue/#histograms
168
+ * @category Charts
169
+ */
170
+ export declare const stairs: import("@sophistry/core").Definition<StairsProps<any>, import("@sophistry/core/internal").CompositeNode<StairsProps<any>>, keyof StairsProps<any>>;
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Data channels: how a chart reads one field out of each datum. A channel
3
+ * is a key of the datum (`x="year"`, type-checked against `T`) or a function
4
+ * `(d, i) => value`. Singular props are channels, plural ones (`xs`,
5
+ * `colors`, `edges`) literal arrays. With `number[]` data the main numeric
6
+ * channel defaults to the datum itself. Colour is a constant or a function,
7
+ * never a key; colour by a field with `series`. Dates in positional
8
+ * channels are read as epoch milliseconds.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ import type { ContextKey } from "@sophistry/core";
13
+ import type { ColorInput } from "@sophistry/core/color";
14
+ import type { TemporalValue, TimeZone } from "@sophistry/core/geometry";
15
+ /**
16
+ * A channel function: reads one value from a datum and its index.
17
+ *
18
+ * @category Channels
19
+ */
20
+ export type ChannelFn<T, V> = (datum: T, index: number) => V;
21
+ /**
22
+ * The keys of `T` whose values suit a `V`-valued channel (`V`, `null` or `undefined`).
23
+ *
24
+ * @category Channels
25
+ */
26
+ export type ChannelKey<T, V> = [T] extends [object] ? {
27
+ [K in keyof T & string]-?: T[K] extends V | null | undefined ? K : never;
28
+ }[keyof T & string] : never;
29
+ /**
30
+ * Where a chart finds a `V` in each `T`: a key of `T` whose value is a `V`,
31
+ * or a function `(d, i) => V`.
32
+ *
33
+ * @see https://sophistry.dev/guides/charts/#data-and-channels
34
+ * @category Channels
35
+ */
36
+ export type Channel<T, V> = ChannelKey<T, V> | ChannelFn<T, V>;
37
+ /**
38
+ * A position on a continuous axis, as positional channels (`x`, `y`, `x1`,
39
+ * …) accept it: a number, a `Date`, or a Temporal value (`Instant`,
40
+ * `ZonedDateTime`, `PlainDate`, `PlainDateTime`).
41
+ *
42
+ * @see https://sophistry.dev/guides/charts/#dates-and-time-zones
43
+ * @category Channels
44
+ */
45
+ export type PositionValue = number | Date | TemporalValue;
46
+ /**
47
+ * What a channel of `V`s reads once resolved: dates become epoch
48
+ * milliseconds, anything else is as given.
49
+ *
50
+ * @category Channels
51
+ */
52
+ export type ChannelRead<V> = V extends Date | TemporalValue ? number : V;
53
+ /**
54
+ * A number: one constant for every datum, or a per-datum {@link Channel}.
55
+ *
56
+ * @category Channels
57
+ */
58
+ export type Quantity<T> = number | Channel<T, number>;
59
+ /**
60
+ * A colour: one constant (a CSS string or a `Color` such as `BLUE`) or
61
+ * `(d, i) => colour`. No key form: a string is always a colour.
62
+ *
63
+ * @category Channels
64
+ */
65
+ export type ColorChannel<T> = ColorInput | ChannelFn<T, ColorInput>;
66
+ /**
67
+ * Placeholder type of a required channel prop; see {@link RequiredUnless}.
68
+ * Its name is what a "missing property" error shows.
69
+ *
70
+ * @category Channels
71
+ */
72
+ export interface RequiredChannel<T, V> {
73
+ /** @internal */
74
+ readonly __channel?: [T, V];
75
+ }
76
+ /**
77
+ * Makes the channel prop `K` required unless `T` is already a `V` (then the
78
+ * channel defaults to the datum itself; nullish members of `T` don't
79
+ * count). Intersect it with a props interface declaring `K` as an optional
80
+ * {@link Channel}; `T` stays inferred from `data`.
81
+ *
82
+ * @category Channels
83
+ */
84
+ export type RequiredUnless<T, V, K extends string> = [NonNullable<T>] extends [
85
+ V
86
+ ] ? unknown : {
87
+ [P in K]-?: RequiredChannel<T, V>;
88
+ };
89
+ /** The identity channel, the default for `number[]` data. */
90
+ export declare const identity: <T, V>(datum: T) => V;
91
+ /** Position of a datum: the default `x` channel for `number[]` data. */
92
+ export declare const indexOf: (_datum: unknown, index: number) => number;
93
+ /**
94
+ * Turns a {@link Channel} into a plain function: a key reads that property,
95
+ * a function is called as is. Dates come back as epoch milliseconds (plain
96
+ * Temporal dates in the axis's `timeZone`, else UTC); read through a
97
+ * positional channel under a `<Chart>`, they also make that axis a time
98
+ * axis. An omitted channel resolves to `fallback`, or `undefined`.
99
+ *
100
+ * A mark passes the {@link DateSink} it read from {@link dateSinkContext}.
101
+ *
102
+ * @param fallback - Used when `channel` is `undefined`.
103
+ * @param name - Prop name for the error message.
104
+ * @param sink - Where a positional channel notes dates (the enclosing chart's).
105
+ * @throws {TypeError} If `channel` is neither a function nor a string or symbol key.
106
+ * @category Channels
107
+ */
108
+ export declare function resolveChannel<T, V>(channel: Channel<T, V>, fallback?: undefined, name?: string, sink?: DateSink | null): ChannelFn<T, ChannelRead<V>>;
109
+ export declare function resolveChannel<T, V>(channel: Channel<T, V> | undefined, fallback: ChannelFn<T, V>, name?: string, sink?: DateSink | null): ChannelFn<T, ChannelRead<V>>;
110
+ export declare function resolveChannel<T, V>(channel: Channel<T, V> | undefined, fallback?: undefined, name?: string, sink?: DateSink | null): ChannelFn<T, ChannelRead<V>> | undefined;
111
+ /** An axis a channel's dates can be noted on: a chart's own, or a secondary one. */
112
+ export type DateAxis = "x" | "y" | "x2" | "y2";
113
+ /**
114
+ * Where positional channels note that they read dates, so `<Chart>` can
115
+ * infer a `"utc"` scale; also gives the zone an axis reads plain Temporal
116
+ * dates in.
117
+ *
118
+ * @category Extending
119
+ */
120
+ export interface DateSink {
121
+ note(axis: DateAxis): void;
122
+ /** The zone `axis` names, if any, else `"UTC"`. */
123
+ timeZone(axis: DateAxis): TimeZone;
124
+ }
125
+ /**
126
+ * Provided by `chart` (and redirected by `secondaryX`/`secondaryY`); outside
127
+ * one (3D charts, transforms) it is null. Marks read it with
128
+ * `ctx.context(dateSinkContext)` and pass it to {@link resolveChannel}.
129
+ *
130
+ * @category Extending
131
+ */
132
+ export declare const dateSinkContext: ContextKey<DateSink | null>;
133
+ /**
134
+ * A {@link Quantity} as a function: a constant ignores the datum. An omitted
135
+ * quantity resolves to `fallback`, or `undefined`.
136
+ *
137
+ * @category Channels
138
+ */
139
+ export declare function resolveQuantity<T>(quantity: Quantity<T>): ChannelFn<T, number>;
140
+ export declare function resolveQuantity<T>(quantity: Quantity<T> | undefined, fallback: ChannelFn<T, number>): ChannelFn<T, number>;
141
+ export declare function resolveQuantity<T>(quantity: Quantity<T> | undefined): ChannelFn<T, number> | undefined;
142
+ /**
143
+ * Reads a channel across `data`.
144
+ *
145
+ * @param name - Prop name for the error message.
146
+ * @returns One value per datum, in order (dates as epoch milliseconds).
147
+ * @category Channels
148
+ */
149
+ export declare function channelValues<T, V>(data: readonly T[], channel: Channel<T, V> | undefined, fallback?: ChannelFn<T, V>, name?: string, sink?: DateSink | null): (ChannelRead<V> | undefined)[];
150
+ /**
151
+ * {@link channelValues} for a numeric channel: non-numbers become `NaN`
152
+ * (which charts skip), dates epoch milliseconds.
153
+ *
154
+ * @category Channels
155
+ */
156
+ export declare function numberValues<T, V extends PositionValue = PositionValue>(data: readonly T[], channel: Channel<T, V> | undefined, fallback?: ChannelFn<T, NoInfer<V>>, name?: string, sink?: DateSink | null): number[];
157
+ /**
158
+ * A {@link ColorChannel} as a function, or `undefined` when omitted.
159
+ *
160
+ * @category Channels
161
+ */
162
+ export declare function resolveColor<T>(color: ColorChannel<T> | undefined): ChannelFn<T, string> | undefined;
163
+ /**
164
+ * Colour of datum `i`: the per-datum `color` if given, else the `colors`
165
+ * palette cycled by index, else `fallback`.
166
+ *
167
+ * @param fallback - Used when the palette is empty.
168
+ * @category Channels
169
+ */
170
+ export declare function colorResolver<T>(color: ColorChannel<T> | undefined, palette: readonly ColorInput[], fallback: ColorInput): ChannelFn<T, string>;