@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,98 @@
1
+ /** Axis ranging for data plotted from raw values rather than a function. */
2
+ import type { Range, ScaleName, TimeZone } from "@sophistry/core/geometry";
3
+ /** @category Math */
4
+ export interface AutoRangeOptions {
5
+ /** Roughly how many ticks the rounded range should offer. @default 5 */
6
+ targetTicks?: number;
7
+ }
8
+ /**
9
+ * Rounds a data span out to a whole number of nice steps, always including
10
+ * zero (an axis starting at 90 exaggerates differences). For charts whose
11
+ * caller gave no explicit range.
12
+ *
13
+ * @param values - The data the axis must cover; non-finite entries are ignored.
14
+ * @returns `[min, max, step]` containing 0; `[0, 1, 1]` when there is no spread.
15
+ * @category Math & helpers
16
+ */
17
+ export declare function autoRange(values: readonly number[], options?: AutoRangeOptions): Range;
18
+ /**
19
+ * Options for {@link fitRange}.
20
+ *
21
+ * @category Math & helpers
22
+ */
23
+ export interface FitRangeOptions {
24
+ /**
25
+ * The scale the range is for, which decides what "round" means: a 1-2-5
26
+ * step for linear, sqrt and symlog, whole decades for log, calendar units
27
+ * for time and utc.
28
+ * @default "linear"
29
+ */
30
+ type?: ScaleName;
31
+ /**
32
+ * Stretch the range to include zero, for marks whose length encodes value
33
+ * (bars, areas, histograms). Ignored by log and time scales.
34
+ * @default false
35
+ */
36
+ zero?: boolean;
37
+ /**
38
+ * Round the ends out to tick values. `false` keeps the data's ends;
39
+ * `"tight"` rounds an end out only when the next tick is within a quarter
40
+ * step of the data (weeks 0–11 fit `[0, 11]`, not `[0, 15]`).
41
+ * @default true
42
+ */
43
+ nice?: boolean | "tight";
44
+ /** Roughly how many ticks the rounded range should offer. @default 5 */
45
+ targetTicks?: number;
46
+ /** Log base, when `type` is `"log"`. @default 10 */
47
+ base?: number;
48
+ /**
49
+ * The zone whose calendar a time range rounds to: an IANA name, `"UTC"` or
50
+ * `"local"`. Omitted, `"utc"` rounds in UTC and `"time"` in local time.
51
+ */
52
+ timeZone?: TimeZone;
53
+ /**
54
+ * Pad the data's extent by this fraction of its span on each side before
55
+ * rounding; a side pinned at zero by `zero` stays there. Ignored by log.
56
+ * @default 0
57
+ */
58
+ margin?: number;
59
+ }
60
+ /**
61
+ * The range an axis should span to show `values`: their extent, stretched to
62
+ * zero if asked, rounded out to ticks for the scale type. This is how
63
+ * `<Chart>` fits its axes. Non-finite values (and non-positive ones on a
64
+ * log scale) are ignored; one value or none still gets a usable span.
65
+ *
66
+ * @returns `[min, max, step]` on a nice linear-family range, `[min, max]` otherwise.
67
+ * @category Math & helpers
68
+ */
69
+ export declare function fitRange(values: readonly number[], options?: FitRangeOptions): Range;
70
+ /**
71
+ * Options for {@link alignedRange}.
72
+ *
73
+ * @category Math & helpers
74
+ */
75
+ export interface AlignedRangeOptions {
76
+ /** Keep zero in range (bars, areas). @default false */
77
+ zero?: boolean;
78
+ /**
79
+ * Pad the data's extent by this fraction of its span first, as {@link FitRangeOptions.margin}.
80
+ * @default 0
81
+ */
82
+ margin?: number;
83
+ /** The two axes run opposite ways (one is reversed). @default false */
84
+ opposite?: boolean;
85
+ }
86
+ /**
87
+ * A secondary axis range whose ticks fall exactly where the primary's do,
88
+ * so one grid serves both: the same number of tick intervals, with the
89
+ * smallest nice step (1, 2, 2.5 or 5 × 10ⁿ) that covers `values`. Linear
90
+ * axes only.
91
+ *
92
+ * @param primary - The primary axis's range, `[min, max, step?]` (either order).
93
+ * @param primaryTicks - The primary's major tick values, evenly spaced (at least two).
94
+ * @param values - The data the secondary axis must show.
95
+ * @returns `[min, max, step]` ascending, or undefined when the primary has fewer than two ticks.
96
+ * @category Math & helpers
97
+ */
98
+ export declare function alignedRange(primary: Range, primaryTicks: readonly number[], values: readonly number[], options?: AlignedRangeOptions): Range | undefined;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Regression and intervals: least-squares polynomial fits with a confidence
3
+ * band for the fitted mean, LOESS smoothing (optionally robust, with a band),
4
+ * and the t-based confidence interval of a sample mean.
5
+ */
6
+ /** @category Math */
7
+ export interface RegressionPoint {
8
+ x: number;
9
+ /** The fitted value. */
10
+ y: number;
11
+ /** Lower end of the confidence band for the fitted mean (`y` when there is no band). */
12
+ low: number;
13
+ /** Upper end of the band. */
14
+ high: number;
15
+ }
16
+ /** @category Math */
17
+ export interface RegressionOptions {
18
+ /** Polynomial degree: 1 is a straight line, 2 a parabola, ... @default 1 */
19
+ degree?: number;
20
+ /** Confidence level of the band around the fitted mean, 0..1; 0 draws no band. @default 0.95 */
21
+ level?: number;
22
+ /** How many evenly spaced x positions to evaluate the fit at. @default 50 */
23
+ samples?: number;
24
+ /** The x span to evaluate over. Defaults to the data's x extent. */
25
+ domain?: [number, number];
26
+ }
27
+ /**
28
+ * A least-squares polynomial fit of `ys` on `xs`, with the confidence band
29
+ * of the fitted mean `ŷ ± t(level, n − p) · s · √(x₀ᵀ (XᵀX)⁻¹ x₀)`. Pairs
30
+ * with a non-finite member are dropped; with no more points than
31
+ * coefficients the result is `[]`.
32
+ *
33
+ * @param ys - Responses, paired with `xs` by index.
34
+ * @returns Points ascending in x.
35
+ * @category Math & helpers
36
+ */
37
+ export declare function regression(xs: readonly number[], ys: readonly number[], options?: RegressionOptions): RegressionPoint[];
38
+ /** @category Math */
39
+ export interface LoessOptions {
40
+ /** Fraction of the points each local fit uses, 0..1. @default 0.3 */
41
+ bandwidth?: number;
42
+ /** How many evenly spaced x positions to evaluate at. @default 50 */
43
+ samples?: number;
44
+ /**
45
+ * Robustness iterations: each re-weights points by their residual (bisquare)
46
+ * and refits, so outliers stop pulling the smooth; 2 is the usual choice.
47
+ * @default 0
48
+ */
49
+ iterations?: number;
50
+ }
51
+ /** @category Math */
52
+ export interface LoessBandOptions extends LoessOptions {
53
+ /** Confidence level of the band around the smooth, 0..1; 0 draws no band. @default 0.95 */
54
+ level?: number;
55
+ }
56
+ /**
57
+ * LOESS: a locally weighted linear fit at each sample over the nearest
58
+ * `bandwidth` fraction of the points (tricube weights), optionally robust to
59
+ * outliers. {@link loessBand} adds a confidence band.
60
+ *
61
+ * @param ys - Responses, paired with `xs` by index; non-finite pairs dropped.
62
+ * @returns Points ascending in x across the data's extent; `[]` with fewer than 2 points.
63
+ * @category Math & helpers
64
+ */
65
+ export declare function loess(xs: readonly number[], ys: readonly number[], options?: LoessOptions): {
66
+ x: number;
67
+ y: number;
68
+ }[];
69
+ /**
70
+ * {@link loess} with a confidence band for the smooth:
71
+ * `ŷ ± t(level, δ₁) · σ̂ · ‖l(x₀)‖`, with `σ̂² = RSS / δ₁` and
72
+ * `δ₁ = tr((I − L)ᵀ(I − L))` over the smoother matrix `L`. Robustness
73
+ * weights are folded in, so ignored outliers don't widen the band.
74
+ *
75
+ * @param ys - Responses, paired with `xs` by index; non-finite pairs dropped.
76
+ * @returns Points ascending in x across the data's extent; `[]` with fewer
77
+ * than 2 points. With 3 points or fewer, or an interpolating smoother, no
78
+ * band (`low === high === y`).
79
+ * @category Math & helpers
80
+ */
81
+ export declare function loessBand(xs: readonly number[], ys: readonly number[], options?: LoessBandOptions): RegressionPoint[];
82
+ /** @category Math */
83
+ export interface MeanInterval {
84
+ mean: number;
85
+ low: number;
86
+ high: number;
87
+ /** How many finite values the interval is over. */
88
+ n: number;
89
+ }
90
+ /**
91
+ * The mean of `values` with an interval: `"ci"` the t-based confidence
92
+ * interval at `level`, `"se"` ± one standard error, `"sd"` ± one sample
93
+ * standard deviation. Non-finite values are dropped; with none every field
94
+ * is `NaN` and `n` is 0.
95
+ *
96
+ * @param interval - Defaults to `"ci"`.
97
+ * @param level - Confidence level for `"ci"`, 0..1. Defaults to 0.95.
98
+ * @category Math & helpers
99
+ */
100
+ export declare function meanInterval(values: readonly number[], interval?: "ci" | "se" | "sd", level?: number): MeanInterval;
101
+ /**
102
+ * The `p` quantile of Student's t distribution with `df` degrees of
103
+ * freedom: exact for 1 and 2, a Cornish–Fisher expansion (within ~0.1%)
104
+ * above.
105
+ *
106
+ * @returns The quantile; `NaN` outside the domain.
107
+ * @category Math & helpers
108
+ */
109
+ export declare function studentT(p: number, df: number): number;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Reveals that follow the independent variable: geometry cut off at an x
3
+ * that sweeps left to right at a constant rate as `progress` runs 0 → 1, so
4
+ * reveal progress reads as progress along x. Works on points in scene units.
5
+ */
6
+ import type { Bounds, Point } from "@sophistry/core/geometry";
7
+ /**
8
+ * The `[min, max]` x of every point in `polylines`, or undefined when there
9
+ * are none (or none finite).
10
+ *
11
+ * @category Math & helpers
12
+ */
13
+ export declare function xExtent(polylines: readonly (readonly Point[])[]): [number, number] | undefined;
14
+ /**
15
+ * The parts of an open polyline at or left of `cutoff`; a line doubling back
16
+ * over the cut comes out in several pieces.
17
+ *
18
+ * @returns The kept pieces; pieces of fewer than two points are dropped.
19
+ * @category Math & helpers
20
+ */
21
+ export declare function clipPolylineToX(points: readonly Point[], cutoff: number): Point[][];
22
+ /**
23
+ * A closed ring cut to the half-plane `x <= cutoff`, so a filled area
24
+ * reveals with a straight front. A ring given closed comes back closed.
25
+ *
26
+ * @returns The cut ring, or `[]` when nothing is left of the cut.
27
+ * @category Math & helpers
28
+ */
29
+ export declare function clipRingToX(ring: readonly Point[], cutoff: number): Point[];
30
+ /**
31
+ * Where the cut stands at `progress`: linear across `extent`. Ease the
32
+ * track driving `progress` for an eased reveal.
33
+ *
34
+ * @category Math & helpers
35
+ */
36
+ export declare function revealCutoff(progress: number, extent: readonly [number, number]): number;
37
+ /**
38
+ * Open polylines revealed left to right over their joint x extent, all cut
39
+ * at the same x so lines drawn together advance together.
40
+ *
41
+ * @param progress - 0..1.
42
+ * @category Math & helpers
43
+ */
44
+ export declare function revealPolylinesAlongX(polylines: readonly (readonly Point[])[], progress: number): Point[][];
45
+ /**
46
+ * Closed rings (filled areas) revealed left to right over their joint x extent.
47
+ *
48
+ * @param progress - 0..1.
49
+ * @returns The visible rings; a ring entirely right of the cut is dropped.
50
+ * @category Math & helpers
51
+ */
52
+ export declare function revealRingsAlongX(rings: readonly (readonly Point[])[], progress: number): Point[][];
53
+ /**
54
+ * The clip box revealing filled regions left to right: everything left of
55
+ * the reached x, with room around so only the front cuts. Unlike a cut, it
56
+ * leaves the geometry whole (no stroked edge along the front).
57
+ *
58
+ * @param polylines - The geometry being revealed, in scene units.
59
+ * @param progress - 0..1.
60
+ * @returns A box for `<Group clip>`, or undefined at `progress >= 1` or with no geometry.
61
+ * @category Math & helpers
62
+ */
63
+ export declare function revealClipAlongX(polylines: readonly (readonly Point[])[], progress: number): Bounds | undefined;
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Sankey layout: nodes in columns, links as ribbons as wide as their value.
3
+ * Coordinates are in a `[0, width] × [0, height]` box with **y pointing
4
+ * down**: `y0` is a node's top edge. A y-up renderer maps `y` to `top - y`.
5
+ */
6
+ import type { Point } from "@sophistry/core/geometry";
7
+ /**
8
+ * A node id: whatever the links name their endpoints with.
9
+ *
10
+ * @category Math & helpers
11
+ */
12
+ export type SankeyId = string | number;
13
+ /**
14
+ * One link of the input graph.
15
+ *
16
+ * @category Math & helpers
17
+ */
18
+ export interface SankeyLinkInput {
19
+ source: SankeyId;
20
+ target: SankeyId;
21
+ /** The flow's size; non-finite and negative values count as 0. */
22
+ value: number;
23
+ }
24
+ /**
25
+ * How nodes are assigned to columns: `"justify"` by longest path from a
26
+ * source with sinks in the last column; `"left"` by longest path from a
27
+ * source; `"right"` by longest path to a sink; `"center"` like `"left"` but
28
+ * each source one column before its nearest target.
29
+ *
30
+ * @category Math & helpers
31
+ */
32
+ export type SankeyAlign = "justify" | "left" | "right" | "center";
33
+ /**
34
+ * Options for {@link sankeyLayout}.
35
+ *
36
+ * @category Math & helpers
37
+ */
38
+ export interface SankeyOptions {
39
+ /**
40
+ * Node ids in stacking and colour order; ids named only by links are appended. Defaults to the
41
+ * link endpoints in first-seen order.
42
+ */
43
+ nodes?: readonly SankeyId[];
44
+ /** Width of the layout box. @default 1 */
45
+ width?: number;
46
+ /** Height of the layout box. @default 1 */
47
+ height?: number;
48
+ /** Width of each node bar. Defaults to 2.4% of `width`. */
49
+ nodeWidth?: number;
50
+ /**
51
+ * Vertical gap between nodes in a column, shrunk if a tall column can't fit it. Defaults to 8%
52
+ * of `height`.
53
+ */
54
+ nodePadding?: number;
55
+ /** Column assignment; see {@link SankeyAlign}. @default "justify" */
56
+ align?: SankeyAlign;
57
+ /** Relaxation passes pulling connected nodes level; 0 keeps the initial stacking. @default 6 */
58
+ iterations?: number;
59
+ }
60
+ /**
61
+ * One laid-out node. `y0 < y1` (y points down).
62
+ *
63
+ * @category Math & helpers
64
+ */
65
+ export interface SankeyNode {
66
+ id: SankeyId;
67
+ /** Position in the node order (first-seen, or `options.nodes`). */
68
+ index: number;
69
+ /** `max(Σ incoming, Σ outgoing)`. */
70
+ value: number;
71
+ /** The column the node is drawn in, after `align`; 0 is the leftmost. */
72
+ depth: number;
73
+ x0: number;
74
+ x1: number;
75
+ y0: number;
76
+ y1: number;
77
+ }
78
+ /**
79
+ * One laid-out link. `y0`/`y1` are the ribbon's centreline at its source and
80
+ * target ends; its edges are `width / 2` either side.
81
+ *
82
+ * @category Math & helpers
83
+ */
84
+ export interface SankeyLink {
85
+ /** Index of the source node in {@link SankeyLayout.nodes}. */
86
+ source: number;
87
+ /** Index of the target node in {@link SankeyLayout.nodes}. */
88
+ target: number;
89
+ /** The value used (non-finite and negative inputs read as 0). */
90
+ value: number;
91
+ /** Centreline y where the link leaves its source. */
92
+ y0: number;
93
+ /** Centreline y where the link enters its target. */
94
+ y1: number;
95
+ /** `value × ky`: the ribbon's thickness. */
96
+ width: number;
97
+ /** Position of the link in the input. */
98
+ index: number;
99
+ }
100
+ /**
101
+ * The result of {@link sankeyLayout}.
102
+ *
103
+ * @category Math & helpers
104
+ */
105
+ export interface SankeyLayout {
106
+ nodes: SankeyNode[];
107
+ /** In input order. */
108
+ links: SankeyLink[];
109
+ /** Number of columns. */
110
+ columns: number;
111
+ /** The vertical scale: layout units per unit of value. */
112
+ ky: number;
113
+ }
114
+ /**
115
+ * Lays out a Sankey diagram: each node gets a column and a height
116
+ * proportional to its value (`max(Σ in, Σ out)`), each link its attachment
117
+ * points. Relaxation passes pull nodes toward their neighbours, and links are
118
+ * ordered at each node so ribbons don't cross there. Deterministic.
119
+ *
120
+ * @returns Nodes and links in a `[0, width] × [0, height]` box, y down.
121
+ * @throws {Error} If the graph has a cycle (a self-loop included).
122
+ * @throws {Error} If `options.nodes` is given and a link names an id not in it.
123
+ * @category Math & helpers
124
+ */
125
+ export declare function sankeyLayout(links: readonly SankeyLinkInput[], options?: SankeyOptions): SankeyLayout;
126
+ /**
127
+ * Options for {@link sankeyRibbon}.
128
+ *
129
+ * @category Math & helpers
130
+ */
131
+ export interface SankeyRibbonOptions {
132
+ /** Points sampled along each edge. @default 24 */
133
+ samples?: number;
134
+ /**
135
+ * How much of the ribbon to keep from the source end, 0..1, for a
136
+ * left-to-right reveal; the cut is vertical.
137
+ * @default 1
138
+ */
139
+ t?: number;
140
+ }
141
+ /**
142
+ * The outline of one link's ribbon as an open polygon: a cubic Bézier with
143
+ * horizontal end tangents along the top edge, the same curve `width` lower
144
+ * traced back. Coordinates are in the inputs' space.
145
+ *
146
+ * @param x0 - Where the ribbon leaves its source (the source node's `x1`).
147
+ * @param y0 - Centreline y at the source end (the link's `y0`).
148
+ * @param x1 - Where the ribbon enters its target (the target node's `x0`).
149
+ * @param y1 - Centreline y at the target end (the link's `y1`).
150
+ * @param width - The ribbon's thickness (the link's `width`).
151
+ * @returns `2 × samples` points, top edge forward then bottom edge back; empty when `t` is 0.
152
+ * @category Math & helpers
153
+ */
154
+ export declare function sankeyRibbon(x0: number, y0: number, x1: number, y1: number, width: number, options?: SankeyRibbonOptions): Point[];
@@ -0,0 +1,14 @@
1
+ /** `scatter(x, y)` — one marker per finite `(x, y)` pair. */
2
+ /** @category Math */
3
+ export interface ScatterPoint {
4
+ /** Index into the input `xs`/`ys`, keeping `sizes`/`colors` aligned past dropped pairs. */
5
+ index: number;
6
+ x: number;
7
+ y: number;
8
+ }
9
+ /**
10
+ * The finite `(x, y)` pairs, paired by index, each keeping its index.
11
+ *
12
+ * @category Math & helpers
13
+ */
14
+ export declare function scatterPoints(xs: readonly number[], ys: readonly number[]): ScatterPoint[];
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Equal-width bin math shared by `histogramBins` (1D) and `histogram2d` (2D):
3
+ * both bin a continuous range into `n` buckets with the same right-inclusive
4
+ * last bin and the same degenerate-range widening.
5
+ */
6
+ /**
7
+ * How many bins to use and where the last edge lands: an explicit `count`
8
+ * wins; else a positive `step` is the bin width (`max` extended to a whole
9
+ * step, with float tolerance so `[0, 0.3, 0.1]` is 3 bins); else
10
+ * `fallbackCount` bins span `[min, max]`.
11
+ *
12
+ * @returns The bin count and the (possibly extended) upper bound.
13
+ */
14
+ export declare function resolveBinning(min: number, max: number, count: number | undefined, step: number | undefined, fallbackCount: number): {
15
+ n: number;
16
+ max: number;
17
+ };
18
+ /** Widens a degenerate `[min, max]` (`min === max`) symmetrically to a small nonzero span. */
19
+ export declare function widenDegenerate(min: number, max: number): [number, number];
20
+ /** Bin index for `value` within `[min, max]` split into `bins` equal buckets, the last bin right-inclusive. */
21
+ export declare function binIndex(value: number, min: number, max: number, bins: number): number;
22
+ /** `n + 1` evenly spaced edges from `min` to `max`, split into `n` bins. */
23
+ export declare function binEdges(min: number, max: number, n: number): number[];
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Grid-cell assembly shared by `imshow` and `pcolormesh`: a value grid laid
3
+ * onto data-space rectangles from a caller-supplied `rectFor`, ragged rows
4
+ * tolerated, `min`/`max` over finite values (`[0, 1]` when none).
5
+ */
6
+ /**
7
+ * One grid cell: its `(row, column)` and its data-space rectangle.
8
+ *
9
+ * @category Math & helpers
10
+ */
11
+ export interface GridCell {
12
+ row: number;
13
+ column: number;
14
+ x0: number;
15
+ x1: number;
16
+ y0: number;
17
+ y1: number;
18
+ value: number;
19
+ }
20
+ /**
21
+ * The full gridded result.
22
+ *
23
+ * @category Math & helpers
24
+ */
25
+ export interface GridResult {
26
+ cells: GridCell[];
27
+ /** Smallest finite value in the grid, or 0 if there were none. */
28
+ min: number;
29
+ /** Largest finite value in the grid, or 1 if there were none. */
30
+ max: number;
31
+ nrows: number;
32
+ ncols: number;
33
+ }
34
+ /** Longest row length across `Z` (ragged rows have fewer cells). */
35
+ export declare function gridNcols(Z: readonly (readonly number[])[]): number;
36
+ /** One `GridCell` per entry of `Z`, positioned by `rectFor(row, col)`, and the finite `min`/`max` (`[0, 1]` when none). */
37
+ export declare function buildGridCells(Z: readonly (readonly number[])[], rectFor: (row: number, col: number) => Pick<GridCell, "x0" | "x1" | "y0" | "y1">): {
38
+ cells: GridCell[];
39
+ min: number;
40
+ max: number;
41
+ };
@@ -0,0 +1,5 @@
1
+ /** Level resolution shared by contour lines and filled contours: explicit values, or a count spaced over the data's finite extent. */
2
+ /** Smallest/largest finite value in a 2D grid, or `null` if it has none. */
3
+ export declare function dataExtent(z: readonly (readonly number[])[]): [number, number] | null;
4
+ /** Resolves `levels` (explicit values as is, or a count spaced by `evenFn`) against `z`'s extent; `[]` for a constant or all-non-finite field. */
5
+ export declare function resolveLevels(levels: readonly number[] | number, z: readonly (readonly number[])[], evenFn: (min: number, max: number, count: number) => number[]): number[];
@@ -0,0 +1,2 @@
1
+ /** Number of index-aligned pairs two parallel arrays offer, `Math.min(xs.length, ys.length)`; the longer tail is dropped. */
2
+ export declare function pairCount(xs: readonly unknown[], ys: readonly unknown[]): number;
@@ -0,0 +1,23 @@
1
+ /** The `startAngle`/`clockwise` sweep options shared by the polar charts. */
2
+ export { TAU } from "@sophistry/core/internal";
3
+ /** @category Math */
4
+ export interface PolarSweepOptions {
5
+ /**
6
+ * Radians from +x (counter-clockwise, y up) where the first slice, wedge or axis begins. The
7
+ * default is 12 o'clock.
8
+ * @default Math.PI / 2
9
+ */
10
+ startAngle?: number;
11
+ /** Sweep direction. @default true */
12
+ clockwise?: boolean;
13
+ }
14
+ export interface ResolvedPolarSweep {
15
+ startAngle: number;
16
+ /** `-1` for clockwise, `1` for counter-clockwise — multiply into an angular step. */
17
+ direction: 1 | -1;
18
+ }
19
+ /**
20
+ * Resolves `{ startAngle, clockwise }` to `{ startAngle, direction }`, filling
21
+ * in the shared defaults (12 o'clock, clockwise).
22
+ */
23
+ export declare function resolvePolarSweep(options: PolarSweepOptions | undefined): ResolvedPolarSweep;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Stacking: values sharing a position laid end to end as segments (stacked
3
+ * bars and areas, streamgraphs, normalized and diverging stacks). Input is
4
+ * one column per position, each a list of `{ series, value }` items stacked
5
+ * in series order, then placed by the {@link StackOffset}.
6
+ */
7
+ /**
8
+ * How a stack is placed: `"zero"` on the baseline; `"normalize"` each
9
+ * column scaled to 0..1; `"center"` each column centred on zero;
10
+ * `"wiggle"` shifted to minimise slope change between columns (a
11
+ * streamgraph), centred overall.
12
+ *
13
+ * @category Math & helpers
14
+ */
15
+ export type StackOffset = "zero" | "normalize" | "center" | "wiggle";
16
+ /**
17
+ * Which series sits at the bottom: `"appearance"` (given or first-seen
18
+ * order), `"reverse"`, `"sum"` (largest on top), `"insideOut"` (the
19
+ * streamgraph order: earliest peaks in the middle), or an array of series
20
+ * indices bottom to top (unlisted series follow).
21
+ *
22
+ * @category Math & helpers
23
+ */
24
+ export type StackOrder = "appearance" | "reverse" | "sum" | "insideOut" | readonly number[];
25
+ /** @category Math */
26
+ export interface StackColumnsOptions {
27
+ /** @default "zero" */
28
+ offset?: StackOffset;
29
+ /** @default "appearance" */
30
+ order?: StackOrder;
31
+ /**
32
+ * Stack negatives down from the baseline and positives up, as two stacks.
33
+ * Off, values accumulate in one running total, so a negative dips back down.
34
+ * @default true
35
+ */
36
+ diverging?: boolean;
37
+ /** Where the stack starts under `"zero"`; other offsets ignore it. @default 0 */
38
+ baseline?: number;
39
+ }
40
+ /** @category Math */
41
+ export interface StackItem {
42
+ /** The item's series, 0-based; several items of one series in a column stack one after another. */
43
+ series: number;
44
+ /** Its value; a non-finite value takes no room. */
45
+ value: number;
46
+ }
47
+ /** @category Math */
48
+ export interface StackColumnsResult {
49
+ /** `[y1, y2]` per item, parallel to the input: segment start (towards the baseline) and end; `[NaN, NaN]` when non-finite. */
50
+ spans: [number, number][][];
51
+ /** Series indices, bottom of the stack to top. */
52
+ order: number[];
53
+ }
54
+ /**
55
+ * Stacks every column's items in series order, then places each column by
56
+ * `offset`.
57
+ *
58
+ * @param columns - One item list per position, in axis order (only `"wiggle"` reads the order).
59
+ * @param seriesCount - How many series there are; items name theirs by index.
60
+ * @category Math & helpers
61
+ */
62
+ export declare function stackColumns(columns: readonly (readonly StackItem[])[], seriesCount: number, options?: StackColumnsOptions): StackColumnsResult;
63
+ /**
64
+ * Series indices bottom to top for `order`; see {@link StackOrder}.
65
+ *
66
+ * @returns Every series index once, bottom of the stack first.
67
+ * @category Math & helpers
68
+ */
69
+ export declare function stackOrder(columns: readonly (readonly StackItem[])[], seriesCount: number, order: StackOrder): number[];
@@ -0,0 +1,35 @@
1
+ /** Stacked areas: parallel series stacked on a shared baseline, each band the region between consecutive running totals. */
2
+ import type { Point } from "@sophistry/core/geometry";
3
+ import type { StackOffset, StackOrder } from "./stack.js";
4
+ /** @category Math */
5
+ export interface StackedBand {
6
+ /** The running total *below* this series, per `x` — the band's lower edge. */
7
+ bottom: number[];
8
+ /** `bottom + series`, per `x` — the band's upper edge. */
9
+ top: number[];
10
+ /** `top`/`bottom` mapped through `fillBetweenRings`, in data coordinates. */
11
+ rings: Point[][];
12
+ }
13
+ /** @category Math */
14
+ export interface StackPlotOptions {
15
+ /** The running total the first series stacks atop, under the `"zero"` offset. @default 0 */
16
+ baseline?: number;
17
+ /** Where each x's stack is placed; see {@link StackOffset}. @default "zero" */
18
+ offset?: StackOffset;
19
+ /**
20
+ * Which series sits at the bottom; see {@link StackOrder}. Bands are still
21
+ * returned in the order given.
22
+ * @default "appearance"
23
+ */
24
+ order?: StackOrder;
25
+ }
26
+ /**
27
+ * Stacks `series` (each parallel to `xs`) on `baseline`; band `i`'s `rings`
28
+ * shade the slice that series adds. Other offsets then rescale or shift each
29
+ * x's stack; `"wiggle"` treats `xs` as evenly spaced.
30
+ *
31
+ * @param series - One array per band; missing or non-finite entries count as 0, negatives subtract.
32
+ * @returns One {@link StackedBand} per series, in the order given.
33
+ * @category Math & helpers
34
+ */
35
+ export declare function stackedBands(xs: readonly number[], series: readonly (readonly number[])[], options?: StackPlotOptions): StackedBand[];
@@ -0,0 +1,17 @@
1
+ /** Stairs: a step function held constant across each `[edges[i], edges[i+1]]`. */
2
+ import type { Point } from "@sophistry/core/geometry";
3
+ /**
4
+ * The step-function polyline.
5
+ *
6
+ * @category Math & helpers
7
+ */
8
+ export type StairsPolyline = Point[];
9
+ /**
10
+ * The step-function polyline for `values` held over `edges`.
11
+ *
12
+ * @param edges - Step boundaries, one more than `values`; defaults to `0..values.length`.
13
+ * @returns The polyline in data coordinates, two points per value.
14
+ * @throws If `edges` is given and its length is not `values.length + 1`.
15
+ * @category Math & helpers
16
+ */
17
+ export declare function stairsPolyline(values: readonly number[], edges?: readonly number[]): StairsPolyline;