@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.
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/3d/bar-chart3d.d.ts +55 -0
- package/dist/3d/definitions.d.ts +37 -0
- package/dist/3d/definitions.js +14 -0
- package/dist/3d/forward.d.ts +64 -0
- package/dist/3d/index.d.ts +30 -0
- package/dist/3d/index.js +1 -0
- package/dist/3d/quiver3d.d.ts +52 -0
- package/dist/3d/scatter3d.d.ts +44 -0
- package/dist/3d/stem3d.d.ts +45 -0
- package/dist/3d/surface-grid3d.d.ts +33 -0
- package/dist/3d/tri-surface3d.d.ts +45 -0
- package/dist/3d/voxels3d.d.ts +25 -0
- package/dist/3d/wireframe3d.d.ts +30 -0
- package/dist/band.d.ts +20 -0
- package/dist/bars/bar-chart.d.ts +143 -0
- package/dist/bars/bar-labels.d.ts +116 -0
- package/dist/bars/bars.d.ts +223 -0
- package/dist/bars/bullet.d.ts +157 -0
- package/dist/bars/candlestick.d.ts +97 -0
- package/dist/bars/funnel.d.ts +90 -0
- package/dist/bars/histogram.d.ts +108 -0
- package/dist/bars/index.d.ts +22 -0
- package/dist/bars/race.d.ts +28 -0
- package/dist/bars/rules.d.ts +121 -0
- package/dist/bars/shared.d.ts +41 -0
- package/dist/bars/transforms.d.ts +249 -0
- package/dist/bars/waterfall.d.ts +106 -0
- package/dist/batch.d.ts +142 -0
- package/dist/channels-_Xf-p6Lx.js +56 -0
- package/dist/chart.d.ts +87 -0
- package/dist/color-norm.d.ts +90 -0
- package/dist/context.d.ts +111 -0
- package/dist/curves/density.d.ts +125 -0
- package/dist/curves/ecdf.d.ts +72 -0
- package/dist/curves/fill-between.d.ts +100 -0
- package/dist/curves/index.d.ts +15 -0
- package/dist/curves/line-plot.d.ts +104 -0
- package/dist/curves/regression.d.ts +124 -0
- package/dist/curves/shared.d.ts +52 -0
- package/dist/curves/stack-plot.d.ts +140 -0
- package/dist/curves/stairs.d.ts +170 -0
- package/dist/data/channels.d.ts +170 -0
- package/dist/end-space.d.ts +81 -0
- package/dist/entries/definitions.d.ts +20 -0
- package/dist/entries/definitions.js +6 -0
- package/dist/frame/band-axis.d.ts +42 -0
- package/dist/frame/coords.d.ts +111 -0
- package/dist/frame/fit.d.ts +170 -0
- package/dist/frame/format.d.ts +40 -0
- package/dist/frame/guide-metrics.d.ts +36 -0
- package/dist/frame/guides.d.ts +67 -0
- package/dist/frame/keys.d.ts +96 -0
- package/dist/frame/layout.d.ts +145 -0
- package/dist/frame/registry.d.ts +31 -0
- package/dist/frame/reports.d.ts +53 -0
- package/dist/frame/secondary-axes.d.ts +73 -0
- package/dist/frame/secondary.d.ts +56 -0
- package/dist/frame/tooltip-overlay.d.ts +64 -0
- package/dist/frame/types.d.ts +658 -0
- package/dist/grids/barbs.d.ts +51 -0
- package/dist/grids/cell-rects.d.ts +37 -0
- package/dist/grids/cells.d.ts +130 -0
- package/dist/grids/contour-f.d.ts +80 -0
- package/dist/grids/contour-shared.d.ts +53 -0
- package/dist/grids/contour.d.ts +84 -0
- package/dist/grids/dendrogram.d.ts +104 -0
- package/dist/grids/heatmap.d.ts +163 -0
- package/dist/grids/hex-bin.d.ts +93 -0
- package/dist/grids/hist2d.d.ts +107 -0
- package/dist/grids/imshow.d.ts +84 -0
- package/dist/grids/index.d.ts +26 -0
- package/dist/grids/pcolormesh.d.ts +90 -0
- package/dist/grids/ramp-cells.d.ts +66 -0
- package/dist/grids/tri-contour.d.ts +120 -0
- package/dist/grids/tri-shared.d.ts +61 -0
- package/dist/grids/tripcolor.d.ts +73 -0
- package/dist/guides/colorbar.d.ts +110 -0
- package/dist/guides/index.d.ts +11 -0
- package/dist/guides/legend.d.ts +118 -0
- package/dist/guides/nodes.d.ts +13 -0
- package/dist/guides/size-legend.d.ts +233 -0
- package/dist/hierarchy/breadcrumbs.d.ts +133 -0
- package/dist/hierarchy/circle-pack.d.ts +72 -0
- package/dist/hierarchy/drill.d.ts +245 -0
- package/dist/hierarchy/frame.d.ts +67 -0
- package/dist/hierarchy/icicle.d.ts +76 -0
- package/dist/hierarchy/index.d.ts +20 -0
- package/dist/hierarchy/labels.d.ts +24 -0
- package/dist/hierarchy/mosaic.d.ts +130 -0
- package/dist/hierarchy/own-tooltip.d.ts +12 -0
- package/dist/hierarchy/props.d.ts +13 -0
- package/dist/hierarchy/sankey.d.ts +132 -0
- package/dist/hierarchy/shared.d.ts +247 -0
- package/dist/hierarchy/sunburst.d.ts +74 -0
- package/dist/hierarchy/tree.d.ts +124 -0
- package/dist/hierarchy/treemap.d.ts +76 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +5 -0
- package/dist/item-tooltip.d.ts +33 -0
- package/dist/join.d.ts +223 -0
- package/dist/math/3d/bar3d.d.ts +27 -0
- package/dist/math/3d/quiver3d.d.ts +26 -0
- package/dist/math/3d/scatter3d.d.ts +15 -0
- package/dist/math/3d/stem3d.d.ts +22 -0
- package/dist/math/3d/surfaceGrid3d.d.ts +33 -0
- package/dist/math/3d/trisurface.d.ts +11 -0
- package/dist/math/3d/voxels.d.ts +17 -0
- package/dist/math/aggregate.d.ts +68 -0
- package/dist/math/bar.d.ts +31 -0
- package/dist/math/barLabels.d.ts +83 -0
- package/dist/math/barbs.d.ts +36 -0
- package/dist/math/boxplot.d.ts +36 -0
- package/dist/math/breadcrumbs.d.ts +128 -0
- package/dist/math/bubble.d.ts +38 -0
- package/dist/math/bullet.d.ts +110 -0
- package/dist/math/chord.d.ts +103 -0
- package/dist/math/cluster.d.ts +88 -0
- package/dist/math/contour.d.ts +48 -0
- package/dist/math/contourf.d.ts +50 -0
- package/dist/math/dodge.d.ts +36 -0
- package/dist/math/ecdf.d.ts +41 -0
- package/dist/math/errorbar.d.ts +27 -0
- package/dist/math/eventplot.d.ts +26 -0
- package/dist/math/facet.d.ts +90 -0
- package/dist/math/fillBetween.d.ts +28 -0
- package/dist/math/gauge.d.ts +71 -0
- package/dist/math/hexbin.d.ts +20 -0
- package/dist/math/hierarchy.d.ts +179 -0
- package/dist/math/hierarchyJoin.d.ts +59 -0
- package/dist/math/histogram.d.ts +36 -0
- package/dist/math/histogram2d.d.ts +44 -0
- package/dist/math/imshow.d.ts +26 -0
- package/dist/math/index.d.ts +139 -0
- package/dist/math/index.js +3 -0
- package/dist/math/jitter.d.ts +16 -0
- package/dist/math/join.d.ts +135 -0
- package/dist/math/keyframes.d.ts +127 -0
- package/dist/math/legend.d.ts +120 -0
- package/dist/math/line.d.ts +53 -0
- package/dist/math/morph.d.ts +81 -0
- package/dist/math/mosaic.d.ts +119 -0
- package/dist/math/ordinal.d.ts +79 -0
- package/dist/math/parallel.d.ts +38 -0
- package/dist/math/pcolormesh.d.ts +22 -0
- package/dist/math/pie.d.ts +105 -0
- package/dist/math/polarArea.d.ts +34 -0
- package/dist/math/radar.d.ts +110 -0
- package/dist/math/range.d.ts +98 -0
- package/dist/math/regression.d.ts +109 -0
- package/dist/math/reveal.d.ts +63 -0
- package/dist/math/sankey.d.ts +154 -0
- package/dist/math/scatter.d.ts +14 -0
- package/dist/math/shared/binning.d.ts +23 -0
- package/dist/math/shared/gridCells.d.ts +41 -0
- package/dist/math/shared/gridExtent.d.ts +5 -0
- package/dist/math/shared/pairs.d.ts +2 -0
- package/dist/math/shared/polar.d.ts +23 -0
- package/dist/math/stack.d.ts +69 -0
- package/dist/math/stackplot.d.ts +35 -0
- package/dist/math/stairs.d.ts +17 -0
- package/dist/math/stem.d.ts +21 -0
- package/dist/math/symbol.d.ts +25 -0
- package/dist/math/tree.d.ts +117 -0
- package/dist/math/tricontour.d.ts +76 -0
- package/dist/math/violin.d.ts +99 -0
- package/dist/math/waffle.d.ts +48 -0
- package/dist/math/waterfall.d.ts +28 -0
- package/dist/math-CSHNpGej.js +3648 -0
- package/dist/mix.d.ts +24 -0
- package/dist/multiview/brush.d.ts +165 -0
- package/dist/multiview/chart-group.d.ts +265 -0
- package/dist/multiview/chart-link.d.ts +188 -0
- package/dist/multiview/chart-zoom.d.ts +144 -0
- package/dist/multiview/facet.d.ts +238 -0
- package/dist/multiview/group-guides.d.ts +99 -0
- package/dist/multiview/index.d.ts +17 -0
- package/dist/multiview/joint-plot.d.ts +114 -0
- package/dist/multiview/pair-plot.d.ts +153 -0
- package/dist/multiview/panels.d.ts +22 -0
- package/dist/multiview/parallel-coordinates.d.ts +109 -0
- package/dist/points/event-plot.d.ts +67 -0
- package/dist/points/index.d.ts +19 -0
- package/dist/points/labels.d.ts +70 -0
- package/dist/points/links.d.ts +123 -0
- package/dist/points/rects.d.ts +80 -0
- package/dist/points/rug.d.ts +72 -0
- package/dist/points/scatter.d.ts +169 -0
- package/dist/points/segment-marks.d.ts +39 -0
- package/dist/points/shared.d.ts +34 -0
- package/dist/points/stem.d.ts +75 -0
- package/dist/points/strip.d.ts +145 -0
- package/dist/points/symbol-marker.d.ts +33 -0
- package/dist/points/ticks.d.ts +102 -0
- package/dist/props.d.ts +126 -0
- package/dist/radial/chord.d.ts +148 -0
- package/dist/radial/gauge.d.ts +126 -0
- package/dist/radial/index.d.ts +15 -0
- package/dist/radial/pie-chart.d.ts +143 -0
- package/dist/radial/polar-area-chart.d.ts +135 -0
- package/dist/radial/radar-chart.d.ts +176 -0
- package/dist/radial/radial-bar-chart.d.ts +116 -0
- package/dist/radial/shared.d.ts +78 -0
- package/dist/radial/waffle.d.ts +130 -0
- package/dist/raster.d.ts +43 -0
- package/dist/series.d.ts +71 -0
- package/dist/src-CwGo1bes.js +19221 -0
- package/dist/stagger.d.ts +54 -0
- package/dist/statistics/box-plot.d.ts +151 -0
- package/dist/statistics/error-bar.d.ts +148 -0
- package/dist/statistics/groups.d.ts +140 -0
- package/dist/statistics/index.d.ts +7 -0
- package/dist/statistics/violin-plot.d.ts +143 -0
- package/dist/text-width.d.ts +9 -0
- package/dist/tooltip.d.ts +276 -0
- package/dist/util.d.ts +33 -0
- package/dist/voxels-9lJ2TZS4.js +235 -0
- package/dist/wireframe3d-D157GZAq.js +345 -0
- package/package.json +86 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Event plot: a raster of vertical tick marks, one row per sequence (e.g. spike trains). */
|
|
2
|
+
import type { Point } from "@sophistry/core/geometry";
|
|
3
|
+
/** @category Math */
|
|
4
|
+
export interface EventRow {
|
|
5
|
+
/** Index into the original `rows` — which band this row's ticks belong to. */
|
|
6
|
+
row: number;
|
|
7
|
+
/** One `[from, to]` drop-line pair per finite event time in this row. */
|
|
8
|
+
ticks: [Point, Point][];
|
|
9
|
+
}
|
|
10
|
+
/** @category Math */
|
|
11
|
+
export interface EventPlotOptions {
|
|
12
|
+
/** Data-space spacing between successive rows' y. @default 1 */
|
|
13
|
+
lineOffset?: number;
|
|
14
|
+
/** Data-space height of each tick, centred on its row's y. @default 0.8 */
|
|
15
|
+
lineLength?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One vertical tick per finite event time, grouped by row: row `i` sits at
|
|
19
|
+
* `y = i * lineOffset`, each tick at `x = t`, `lineLength` tall. Empty rows
|
|
20
|
+
* are kept.
|
|
21
|
+
*
|
|
22
|
+
* @param rows - One array of event positions (x) per row.
|
|
23
|
+
* @returns One {@link EventRow} per input row, in order.
|
|
24
|
+
* @category Math & helpers
|
|
25
|
+
*/
|
|
26
|
+
export declare function eventPlotRows(rows: readonly (readonly number[])[], options?: EventPlotOptions): EventRow[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small multiples: which panel goes where, how big each is, and how a
|
|
3
|
+
* grid of panels reveals. Pure functions behind `<Facet>`, `<PairPlot>` and
|
|
4
|
+
* `<JointPlot>`.
|
|
5
|
+
*/
|
|
6
|
+
import type { BandKey, Bounds, Point } from "@sophistry/core/geometry";
|
|
7
|
+
/** One panel's place in a facet grid. */
|
|
8
|
+
export interface FacetSlot {
|
|
9
|
+
/** Reading-order index (row-major). */
|
|
10
|
+
index: number;
|
|
11
|
+
/** Grid row, from the top. */
|
|
12
|
+
row: number;
|
|
13
|
+
/** Grid column, from the left. */
|
|
14
|
+
column: number;
|
|
15
|
+
/** The panel's `row` category, when faceting by rows. */
|
|
16
|
+
rowKey?: BandKey;
|
|
17
|
+
/** The panel's `column` category, when faceting by columns. */
|
|
18
|
+
columnKey?: BandKey;
|
|
19
|
+
}
|
|
20
|
+
/** The grid {@link facetSlots} lays out. */
|
|
21
|
+
export interface FacetSlots {
|
|
22
|
+
slots: FacetSlot[];
|
|
23
|
+
rows: number;
|
|
24
|
+
columns: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Where each panel of a facet grid goes: with both key lists a full grid;
|
|
28
|
+
* with one, a single row (`columnKeys`) or column (`rowKeys`) wrapped after
|
|
29
|
+
* `wrap` panels; with neither, one panel.
|
|
30
|
+
*
|
|
31
|
+
* @param wrap - Panels per line when faceting by one variable.
|
|
32
|
+
*/
|
|
33
|
+
export declare function facetSlots(rowKeys: readonly BandKey[], columnKeys: readonly BandKey[], wrap?: number): FacetSlots;
|
|
34
|
+
/** Whether no panel sits directly below (or above, `"top"`) a slot: it is on the grid's outer edge there. */
|
|
35
|
+
export declare function outerEdge(slot: FacetSlot, slots: readonly FacetSlot[], side: "top" | "bottom" | "left" | "right"): boolean;
|
|
36
|
+
/** Room around a grid or panel, per side, in scene units. */
|
|
37
|
+
export interface SideRoom {
|
|
38
|
+
left: number;
|
|
39
|
+
right: number;
|
|
40
|
+
top: number;
|
|
41
|
+
bottom: number;
|
|
42
|
+
}
|
|
43
|
+
/** Options for {@link facetGrid}. */
|
|
44
|
+
export interface FacetGridOptions {
|
|
45
|
+
rows: number;
|
|
46
|
+
columns: number;
|
|
47
|
+
/** The whole footprint's width, in scene units. */
|
|
48
|
+
width: number;
|
|
49
|
+
/** The whole footprint's height. */
|
|
50
|
+
height: number;
|
|
51
|
+
/** The footprint's centre. Defaults to the origin. */
|
|
52
|
+
center?: Point;
|
|
53
|
+
/** Space between neighbouring panels' plotting areas, across a column gap. */
|
|
54
|
+
gapX: number;
|
|
55
|
+
/** Space between neighbouring panels' plotting areas, across a row gap. */
|
|
56
|
+
gapY: number;
|
|
57
|
+
/** Room kept free around the grid of plots, inside the footprint. */
|
|
58
|
+
outer?: Partial<SideRoom>;
|
|
59
|
+
/** Relative column widths. Defaults to equal. */
|
|
60
|
+
widthRatios?: readonly number[];
|
|
61
|
+
/** Relative row heights, top to bottom. Defaults to equal. */
|
|
62
|
+
heightRatios?: readonly number[];
|
|
63
|
+
}
|
|
64
|
+
/** One cell of a {@link facetGrid}: the plotting area of a panel. */
|
|
65
|
+
export interface FacetCell {
|
|
66
|
+
center: Point;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
/** What {@link facetGrid} returns. */
|
|
71
|
+
export interface FacetGrid {
|
|
72
|
+
/** `cells[row][column]`, rows from the top. */
|
|
73
|
+
cells: FacetCell[][];
|
|
74
|
+
/** The box around every plotting area (the grid without its outer room). */
|
|
75
|
+
plots: Bounds;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Lays out a grid of plotting areas inside a footprint: outer room first,
|
|
79
|
+
* then the gaps, the rest shared between columns and rows by ratio. Each
|
|
80
|
+
* plot keeps at least a tenth of a unit.
|
|
81
|
+
*/
|
|
82
|
+
export declare function facetGrid(options: FacetGridOptions): FacetGrid;
|
|
83
|
+
/**
|
|
84
|
+
* A panel's reveal from the grid's: every panel's frame half at once, then
|
|
85
|
+
* the data half staggered across panels in reading order.
|
|
86
|
+
*
|
|
87
|
+
* @param stagger - Fraction of the data half spent staggering, 0..0.95.
|
|
88
|
+
* @param frameEnd - Where a panel's frame half ends. Defaults to 0.5.
|
|
89
|
+
*/
|
|
90
|
+
export declare function panelProgress(progress: number, index: number, count: number, stagger?: number, frameEnd?: number): number;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** The region between two series over shared `x` values: a confidence band or min/max envelope. */
|
|
2
|
+
import type { CurveKind, CurvePath, Point } from "@sophistry/core/geometry";
|
|
3
|
+
/**
|
|
4
|
+
* One ring per continuous run, returned closed (first point repeated), as
|
|
5
|
+
* the reveal walks it back to its start.
|
|
6
|
+
*
|
|
7
|
+
* @category Math & helpers
|
|
8
|
+
*/
|
|
9
|
+
export type FillBetweenRings = Point[][];
|
|
10
|
+
/**
|
|
11
|
+
* One closed ring per continuous run of `(x, y1, y2)`, split wherever a value
|
|
12
|
+
* is non-finite, so a gap shades as two regions.
|
|
13
|
+
*
|
|
14
|
+
* @param y1 - One boundary, parallel to `xs`.
|
|
15
|
+
* @param y2 - The other boundary, parallel to `xs`.
|
|
16
|
+
* @returns Closed rings, one per run of at least 2 finite points.
|
|
17
|
+
* @category Math & helpers
|
|
18
|
+
*/
|
|
19
|
+
export declare function fillBetweenRings(xs: readonly number[], y1: readonly number[], y2: readonly number[]): FillBetweenRings;
|
|
20
|
+
/**
|
|
21
|
+
* One of {@link fillBetweenRings}' rings (in any units) as a closed curve,
|
|
22
|
+
* each boundary curved on its own so a boundary shared by adjacent bands is
|
|
23
|
+
* the same curve in both. A ring of another shape is closed straight.
|
|
24
|
+
*
|
|
25
|
+
* @param ring - `n` upper points, `n` lower points reversed, the first repeated.
|
|
26
|
+
* @category Math & helpers
|
|
27
|
+
*/
|
|
28
|
+
export declare function fillBetweenCurve(ring: readonly Point[], curve: CurveKind): CurvePath;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gauge geometry: where a value sits on a gauge's arc, and how threshold
|
|
3
|
+
* bands divide it. Angles are radians from +x, counter-clockwise positive;
|
|
4
|
+
* a gauge reads clockwise, so its default `endAngle` is less than its
|
|
5
|
+
* `startAngle`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The default gauge start, 210° from +x: with {@link GAUGE_END_ANGLE}, a 240°
|
|
9
|
+
* arc opening downward, symmetric about 12 o'clock.
|
|
10
|
+
*
|
|
11
|
+
* @category Math & helpers
|
|
12
|
+
*/
|
|
13
|
+
export declare const GAUGE_START_ANGLE: number;
|
|
14
|
+
/**
|
|
15
|
+
* The default gauge end: 120° clockwise of 12 o'clock (−30° from +x).
|
|
16
|
+
*
|
|
17
|
+
* @category Math & helpers
|
|
18
|
+
*/
|
|
19
|
+
export declare const GAUGE_END_ANGLE: number;
|
|
20
|
+
/**
|
|
21
|
+
* Where `value` sits between `min` and `max`, clamped to 0..1. A non-finite
|
|
22
|
+
* value, or `max <= min`, reads as 0.
|
|
23
|
+
*
|
|
24
|
+
* @category Math & helpers
|
|
25
|
+
*/
|
|
26
|
+
export declare function gaugeFraction(value: number, min: number, max: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* The angle at `fraction` (not clamped) of the way along a gauge's arc.
|
|
29
|
+
*
|
|
30
|
+
* @param startAngle - Defaults to {@link GAUGE_START_ANGLE}.
|
|
31
|
+
* @param endAngle - Defaults to {@link GAUGE_END_ANGLE}.
|
|
32
|
+
* @category Math & helpers
|
|
33
|
+
*/
|
|
34
|
+
export declare function gaugeAngle(fraction: number, startAngle?: number, endAngle?: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* One resolved threshold band of a gauge.
|
|
37
|
+
*
|
|
38
|
+
* @category Math & helpers
|
|
39
|
+
*/
|
|
40
|
+
export interface GaugeBandSpan {
|
|
41
|
+
/** Position in the input `bands` array. */
|
|
42
|
+
index: number;
|
|
43
|
+
/** Where the band starts, in data units (the previous band's end, or `min`). */
|
|
44
|
+
from: number;
|
|
45
|
+
/** Where the band ends, in data units, clamped to `[min, max]`. */
|
|
46
|
+
to: number;
|
|
47
|
+
/** `from` as a fraction of the arc, 0..1. */
|
|
48
|
+
startFraction: number;
|
|
49
|
+
/** `to` as a fraction of the arc, 0..1. */
|
|
50
|
+
endFraction: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolves threshold bands, each given by where it ends, into arc spans:
|
|
54
|
+
* band `i` runs from band `i - 1`'s end (or `min`) to its `to`, clamped to
|
|
55
|
+
* `[min, max]`; `to: Infinity` runs to the end. Out-of-order bands keep zero
|
|
56
|
+
* width so `index` stays aligned.
|
|
57
|
+
*
|
|
58
|
+
* @returns One {@link GaugeBandSpan} per band, or `[]` when `max <= min`.
|
|
59
|
+
* @category Math & helpers
|
|
60
|
+
*/
|
|
61
|
+
export declare function gaugeBands(bands: readonly {
|
|
62
|
+
readonly to: number;
|
|
63
|
+
}[], min: number, max: number): GaugeBandSpan[];
|
|
64
|
+
/**
|
|
65
|
+
* Which band `value` falls in: the first non-empty band ending at or past
|
|
66
|
+
* it, so a value on a threshold belongs to the band it closes.
|
|
67
|
+
*
|
|
68
|
+
* @returns The band's `index`, or -1 when none reaches the value or it is not finite.
|
|
69
|
+
* @category Math & helpers
|
|
70
|
+
*/
|
|
71
|
+
export declare function gaugeBandIndex(value: number, spans: readonly GaugeBandSpan[]): number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Hexagonal binning: finite `(x, y)` pairs counted into a pointy-top hex grid. */
|
|
2
|
+
import type { Point } from "@sophistry/core/geometry";
|
|
3
|
+
/**
|
|
4
|
+
* One occupied hex: its centre in data units, and how many points landed in it.
|
|
5
|
+
*
|
|
6
|
+
* @category Math & helpers
|
|
7
|
+
*/
|
|
8
|
+
export interface HexBinCell {
|
|
9
|
+
center: Point;
|
|
10
|
+
count: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Bins finite `(x, y)` pairs (paired by index) into a pointy-top hex grid of
|
|
14
|
+
* the given `radius`, in data units.
|
|
15
|
+
*
|
|
16
|
+
* @param radius - Centre-to-corner distance of each hexagon, in data units; must be positive.
|
|
17
|
+
* @returns One {@link HexBinCell} per occupied hexagon, in no particular order.
|
|
18
|
+
* @category Math & helpers
|
|
19
|
+
*/
|
|
20
|
+
export declare function hexbin(xs: readonly number[], ys: readonly number[], radius: number): HexBinCell[];
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hierarchy layouts (treemap, partition, circle packing) over a nested tree
|
|
3
|
+
* of plain objects, flattened to plain nodes in pre-order. Coordinates are
|
|
4
|
+
* in the layout's own box with **y pointing down**: `[0, width] × [0,
|
|
5
|
+
* height]` for rectangles, `[0, size]²` for circles.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* How a hierarchy layout reads the tree. Accessors get the datum and its
|
|
9
|
+
* pre-order index in the input tree (root 0).
|
|
10
|
+
*
|
|
11
|
+
* @category Math & helpers
|
|
12
|
+
*/
|
|
13
|
+
export interface HierarchyOptions<T> {
|
|
14
|
+
/**
|
|
15
|
+
* A node's children; anything but a non-empty array makes it a leaf. Defaults to the datum's
|
|
16
|
+
* `children` property.
|
|
17
|
+
*/
|
|
18
|
+
children?: (datum: T, index: number) => readonly T[] | null | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* A leaf's size; negative and non-finite values count as 0. A parent is the
|
|
21
|
+
* sum of its leaves. Defaults to the datum itself when a number, else 0.
|
|
22
|
+
*/
|
|
23
|
+
value?: (datum: T, index: number) => number;
|
|
24
|
+
/** A node's name, used for `path`. @default "" */
|
|
25
|
+
label?: (datum: T, index: number) => string;
|
|
26
|
+
/** Order siblings by descending value; `false` keeps data order. @default true */
|
|
27
|
+
sort?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One laid-out node, common to every hierarchy layout.
|
|
31
|
+
*
|
|
32
|
+
* @category Math & helpers
|
|
33
|
+
*/
|
|
34
|
+
export interface HierarchyNodeInfo<T> {
|
|
35
|
+
/** The input object. */
|
|
36
|
+
datum: T;
|
|
37
|
+
/** Pre-order position in the input tree: the `i` channel functions get. */
|
|
38
|
+
index: number;
|
|
39
|
+
/** 0 for the root, +1 per generation. */
|
|
40
|
+
depth: number;
|
|
41
|
+
/** Longest distance to a leaf below: 0 for a leaf. */
|
|
42
|
+
height: number;
|
|
43
|
+
/** Whether the node has no children. */
|
|
44
|
+
leaf: boolean;
|
|
45
|
+
/** The node's label. */
|
|
46
|
+
label: string;
|
|
47
|
+
/** Labels from the root down to this node, inclusive. */
|
|
48
|
+
path: string[];
|
|
49
|
+
/** The leaf's value, or the sum of a parent's leaves; always > 0. */
|
|
50
|
+
value: number;
|
|
51
|
+
/**
|
|
52
|
+
* Position of the node's top-level ancestor among the root's children, in
|
|
53
|
+
* input order (unaffected by `sort`); -1 for the root. Charts colour by it.
|
|
54
|
+
*/
|
|
55
|
+
branch: number;
|
|
56
|
+
/** Position of the parent in the returned array, -1 for the root. */
|
|
57
|
+
parent: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A laid-out rectangle, in the layout box with y pointing down.
|
|
61
|
+
*
|
|
62
|
+
* @category Math & helpers
|
|
63
|
+
*/
|
|
64
|
+
export interface HierarchyRect<T> extends HierarchyNodeInfo<T> {
|
|
65
|
+
x0: number;
|
|
66
|
+
y0: number;
|
|
67
|
+
x1: number;
|
|
68
|
+
y1: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A laid-out circle, in the layout box with y pointing down.
|
|
72
|
+
*
|
|
73
|
+
* @category Math & helpers
|
|
74
|
+
*/
|
|
75
|
+
export interface HierarchyCircle<T> extends HierarchyNodeInfo<T> {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
r: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Treemap tiling: `"squarify"` (near-square tiles), `"resquarify"` (keeps its
|
|
82
|
+
* rows when values change, for animating), `"binary"`, `"slice"` (stacked
|
|
83
|
+
* vertically), `"dice"` (side by side), `"sliceDice"` (alternating by depth).
|
|
84
|
+
*
|
|
85
|
+
* @category Math & helpers
|
|
86
|
+
*/
|
|
87
|
+
export type TreemapTile = "squarify" | "binary" | "slice" | "dice" | "sliceDice" | "resquarify";
|
|
88
|
+
/** @category Math */
|
|
89
|
+
export interface TreemapOptions<T> extends HierarchyOptions<T> {
|
|
90
|
+
/** Width of the layout box. @default 1 */
|
|
91
|
+
width?: number;
|
|
92
|
+
/** Height of the layout box. @default 1 */
|
|
93
|
+
height?: number;
|
|
94
|
+
/** Tiling method. @default "squarify" */
|
|
95
|
+
tile?: TreemapTile;
|
|
96
|
+
/** Gap between siblings, and between a parent's edge and its children. @default 0 */
|
|
97
|
+
padding?: number;
|
|
98
|
+
/** Gap at the top of every parent below the root, room for its name. Defaults to `padding`. */
|
|
99
|
+
paddingTop?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Lay every parent out in these rows (from {@link treemapRows} of another
|
|
102
|
+
* tree) instead of tiling afresh, so tiles keep their neighbours across a
|
|
103
|
+
* transition. Children no row lists are squarified into what is left.
|
|
104
|
+
*/
|
|
105
|
+
keepRows?: TreemapRows;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* One row of a squarified parent: its children's labels in order, and
|
|
109
|
+
* whether it runs across the parent (`dice`) or down it.
|
|
110
|
+
*
|
|
111
|
+
* @category Math & helpers
|
|
112
|
+
*/
|
|
113
|
+
export interface TreemapRow {
|
|
114
|
+
dice: boolean;
|
|
115
|
+
labels: readonly string[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The rows squarify chose for every parent, keyed by the parent's
|
|
119
|
+
* JSON-encoded label path. See {@link treemapRows}.
|
|
120
|
+
*
|
|
121
|
+
* @category Math & helpers
|
|
122
|
+
*/
|
|
123
|
+
export type TreemapRows = ReadonlyMap<string, readonly TreemapRow[]>;
|
|
124
|
+
/** @category Math */
|
|
125
|
+
export interface PartitionOptions<T> extends HierarchyOptions<T> {
|
|
126
|
+
/** Extent of the breadth axis (siblings side by side). @default 1 */
|
|
127
|
+
width?: number;
|
|
128
|
+
/** Extent of the depth axis (one equal band per level). @default 1 */
|
|
129
|
+
height?: number;
|
|
130
|
+
}
|
|
131
|
+
/** @category Math */
|
|
132
|
+
export interface PackOptions<T> extends HierarchyOptions<T> {
|
|
133
|
+
/** Side of the square box; the root circle's diameter. @default 1 */
|
|
134
|
+
size?: number;
|
|
135
|
+
/** Gap between sibling circles and their parent's rim. @default 0 */
|
|
136
|
+
padding?: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A treemap: each node a rectangle with area proportional to its value,
|
|
140
|
+
* nested in its parent's; squarified by default.
|
|
141
|
+
*
|
|
142
|
+
* @returns Every node with a positive value in pre-order, or `[]` when the
|
|
143
|
+
* total is 0 or the box is empty.
|
|
144
|
+
* @throws {Error} If the tree contains a cycle.
|
|
145
|
+
* @category Math & helpers
|
|
146
|
+
*/
|
|
147
|
+
export declare function treemapLayout<T>(root: T, options?: TreemapOptions<T>): HierarchyRect<T>[];
|
|
148
|
+
/**
|
|
149
|
+
* The rows squarify lays a tree's parents out in, for
|
|
150
|
+
* {@link TreemapOptions.keepRows}: lay another tree out in the same rows so
|
|
151
|
+
* its tiles keep their neighbours. Takes {@link treemapLayout}'s options
|
|
152
|
+
* (`tile` is ignored).
|
|
153
|
+
*
|
|
154
|
+
* @returns Every parent's rows, children by label; empty for an empty box.
|
|
155
|
+
* @throws {Error} If the tree contains a cycle.
|
|
156
|
+
* @category Math & helpers
|
|
157
|
+
*/
|
|
158
|
+
export declare function treemapRows<T>(root: T, options?: TreemapOptions<T>): TreemapRows;
|
|
159
|
+
/**
|
|
160
|
+
* A partition (icicle / sunburst) layout: one equal band per depth along
|
|
161
|
+
* `y` (root at 0); along `x` each node spans its children, sized by value.
|
|
162
|
+
* Use `width = 1` for a sunburst's turn fraction.
|
|
163
|
+
*
|
|
164
|
+
* @returns Every node with a positive value in pre-order, or `[]` when the
|
|
165
|
+
* total is 0 or the box is empty.
|
|
166
|
+
* @throws {Error} If the tree contains a cycle.
|
|
167
|
+
* @category Math & helpers
|
|
168
|
+
*/
|
|
169
|
+
export declare function partitionLayout<T>(root: T, options?: PartitionOptions<T>): HierarchyRect<T>[];
|
|
170
|
+
/**
|
|
171
|
+
* Circle packing: leaves are circles with area proportional to value,
|
|
172
|
+
* packed inside their parent's enclosing circle.
|
|
173
|
+
*
|
|
174
|
+
* @returns Every node with a positive value in pre-order, or `[]` when the
|
|
175
|
+
* total is 0 or the size is not positive.
|
|
176
|
+
* @throws {Error} If the tree contains a cycle.
|
|
177
|
+
* @category Math & helpers
|
|
178
|
+
*/
|
|
179
|
+
export declare function packLayout<T>(root: T, options?: PackOptions<T>): HierarchyCircle<T>[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyed transitions between two hierarchy layouts, matched by path of
|
|
3
|
+
* names: one layout of the union tree at blend `t`, staged exit, then
|
|
4
|
+
* update (matched nodes move), then enter. Pure in `t`, so it scrubs.
|
|
5
|
+
*/
|
|
6
|
+
import type { HierarchyNodeInfo } from "./hierarchy.js";
|
|
7
|
+
import type { JoinStaging } from "./join.js";
|
|
8
|
+
/**
|
|
9
|
+
* Where a node of a joined layout came from, and how present it is.
|
|
10
|
+
*
|
|
11
|
+
* @category Math & helpers
|
|
12
|
+
*/
|
|
13
|
+
export interface HierarchyJoinInfo {
|
|
14
|
+
/** 0..1: fading out (exit), whole (both ends), or fading in (enter). */
|
|
15
|
+
presence: number;
|
|
16
|
+
/** The node's position in the `from` layout, or -1 when it enters. */
|
|
17
|
+
fromAt: number;
|
|
18
|
+
/** The node's position in the `to` layout, or -1 when it exits. */
|
|
19
|
+
toAt: number;
|
|
20
|
+
/** How far the update stage has got, 0..1 (for blending colours). */
|
|
21
|
+
update: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options for {@link hierarchyJoin}.
|
|
25
|
+
*
|
|
26
|
+
* @category Math & helpers
|
|
27
|
+
*/
|
|
28
|
+
export interface HierarchyJoinOptions<N> {
|
|
29
|
+
/** The blend, 0..1: 0 is `from`'s layout, 1 is `to`'s. */
|
|
30
|
+
blend: number;
|
|
31
|
+
/** `"staged"`: exit, then update, then enter; `"together"`: all at once, linearly. @default "staged" */
|
|
32
|
+
staging?: JoinStaging;
|
|
33
|
+
/** The numeric fields that place a node (`["x0", "x1", "y0", "y1"]` or `["x", "y", "r"]`). */
|
|
34
|
+
fields: readonly (keyof N & string)[];
|
|
35
|
+
/**
|
|
36
|
+
* Fraction of the enter stage spent staggering entering nodes, 0..0.95, in
|
|
37
|
+
* `to`'s pre-order (parents before children).
|
|
38
|
+
* @default 0
|
|
39
|
+
*/
|
|
40
|
+
enterStagger?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Each node's identity in a layout: its path of names, repeated sibling names
|
|
44
|
+
* told apart by occurrence. The root's key is always `""`.
|
|
45
|
+
*
|
|
46
|
+
* @category Math & helpers
|
|
47
|
+
*/
|
|
48
|
+
export declare function hierarchyKeys<T>(nodes: readonly HierarchyNodeInfo<T>[]): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Two layouts of one kind (same layout function and options) joined at
|
|
51
|
+
* blend `t` into one layout of the union tree, in pre-order. Matched nodes
|
|
52
|
+
* move on the update stage (`fields` and `value` blended); nodes only in
|
|
53
|
+
* `from` fade out in place; nodes only in `to` fade in at their new place.
|
|
54
|
+
*
|
|
55
|
+
* @param from - The layout at `blend = 0`.
|
|
56
|
+
* @param to - The layout at `blend = 1`.
|
|
57
|
+
* @category Math & helpers
|
|
58
|
+
*/
|
|
59
|
+
export declare function hierarchyJoin<T, N extends HierarchyNodeInfo<T>>(from: readonly N[], to: readonly N[], options: HierarchyJoinOptions<N>): (N & HierarchyJoinInfo)[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Histogram binning: equal-width buckets over a value range, counted. */
|
|
2
|
+
import type { Range } from "@sophistry/core/geometry";
|
|
3
|
+
/** @category Math */
|
|
4
|
+
export interface HistogramBins {
|
|
5
|
+
/** `binCount + 1` bin boundaries, ascending. Bin `i` covers `[edges[i], edges[i + 1])`. */
|
|
6
|
+
edges: number[];
|
|
7
|
+
/** One count per bin, parallel to the gaps between `edges`. */
|
|
8
|
+
counts: number[];
|
|
9
|
+
}
|
|
10
|
+
/** @category Math */
|
|
11
|
+
export interface HistogramOptions {
|
|
12
|
+
/**
|
|
13
|
+
* How many equal-width buckets to split `range` into; wins over a `range` step. Defaults to the
|
|
14
|
+
* count implied by the `range` step, else 10.
|
|
15
|
+
*/
|
|
16
|
+
binCount?: number;
|
|
17
|
+
/**
|
|
18
|
+
* `[min, max, step?]`. Without `binCount`, `step` is the bin width (the last
|
|
19
|
+
* edge extends to a whole step). Defaults to the finite extent of `values`.
|
|
20
|
+
*/
|
|
21
|
+
range?: Range;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `HistogramOptions.binCount`'s default.
|
|
25
|
+
*
|
|
26
|
+
* @category Math & helpers
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_BIN_COUNT = 10;
|
|
29
|
+
/**
|
|
30
|
+
* Bins `values` into equal-width buckets across `range`. Non-finite values
|
|
31
|
+
* are dropped; the last bin is right-inclusive so the maximum lands in it.
|
|
32
|
+
*
|
|
33
|
+
* @returns `edges` (`binCount + 1` boundaries) and `counts` (one per bin).
|
|
34
|
+
* @category Math & helpers
|
|
35
|
+
*/
|
|
36
|
+
export declare function histogramBins(values: readonly number[], options?: HistogramOptions): HistogramBins;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** 2D histogram: finite `(x, y)` pairs counted into a grid of equal-width cells. */
|
|
2
|
+
import type { Range } from "@sophistry/core/geometry";
|
|
3
|
+
/** @category Math */
|
|
4
|
+
export interface Histogram2D {
|
|
5
|
+
/** `xBins + 1` x bin boundaries, ascending. */
|
|
6
|
+
xEdges: number[];
|
|
7
|
+
/** `yBins + 1` y bin boundaries, ascending. */
|
|
8
|
+
yEdges: number[];
|
|
9
|
+
/** `counts[row = yBin][col = xBin]`. */
|
|
10
|
+
counts: number[][];
|
|
11
|
+
/** Largest cell value, or 0 if there were no finite pairs. */
|
|
12
|
+
maxCount: number;
|
|
13
|
+
}
|
|
14
|
+
/** @category Math */
|
|
15
|
+
export interface Histogram2DOptions {
|
|
16
|
+
/**
|
|
17
|
+
* How many equal-width columns to split `xRange` into; wins over an `xRange` step. Defaults to
|
|
18
|
+
* the step's count, else 10.
|
|
19
|
+
*/
|
|
20
|
+
xBins?: number;
|
|
21
|
+
/**
|
|
22
|
+
* How many equal-width rows to split `yRange` into; wins over a `yRange` step. Defaults to the
|
|
23
|
+
* step's count, else 10.
|
|
24
|
+
*/
|
|
25
|
+
yBins?: number;
|
|
26
|
+
/**
|
|
27
|
+
* `[min, max, step?]`; `step` is the bin width unless `xBins` is given. Defaults to the finite
|
|
28
|
+
* extent of `xs`.
|
|
29
|
+
*/
|
|
30
|
+
xRange?: Range;
|
|
31
|
+
/**
|
|
32
|
+
* `[min, max, step?]`; `step` is the bin height unless `yBins` is given. Defaults to the finite
|
|
33
|
+
* extent of `ys`.
|
|
34
|
+
*/
|
|
35
|
+
yRange?: Range;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Bins `(x, y)` pairs (paired by index; dropped unless both are finite)
|
|
39
|
+
* into an `xBins × yBins` grid over `xRange` and `yRange`.
|
|
40
|
+
*
|
|
41
|
+
* @returns Both axes' edges, the `counts[row][col]` grid and the largest count.
|
|
42
|
+
* @category Math & helpers
|
|
43
|
+
*/
|
|
44
|
+
export declare function histogram2d(xs: readonly number[], ys: readonly number[], options?: Histogram2DOptions): Histogram2D;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Image-from-array cells: `Z` (rows × cols) laid onto equal-sized cells spanning a rectangular `extent`. */
|
|
2
|
+
import { type GridCell, type GridResult } from "./shared/gridCells.js";
|
|
3
|
+
/** @category Math */
|
|
4
|
+
export type ImshowCell = GridCell;
|
|
5
|
+
/** @category Math */
|
|
6
|
+
export type ImshowResult = GridResult;
|
|
7
|
+
/** @category Math */
|
|
8
|
+
export interface ImshowOptions {
|
|
9
|
+
/** `[xMin, xMax, yMin, yMax]`. Defaults to `[0, ncols, 0, nrows]`. */
|
|
10
|
+
extent?: [number, number, number, number];
|
|
11
|
+
/**
|
|
12
|
+
* `"upper"` puts row 0 at the top of `extent`; `"lower"` at the bottom, like
|
|
13
|
+
* ordinary cartesian data.
|
|
14
|
+
* @default "upper"
|
|
15
|
+
*/
|
|
16
|
+
origin?: "upper" | "lower";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Lays `Z` onto `ncols × nrows` equal cells spanning `extent` (`ncols` the
|
|
20
|
+
* longest row; ragged rows tolerated). Non-finite values pass through;
|
|
21
|
+
* `min`/`max` cover finite values only (`[0, 1]` when none).
|
|
22
|
+
*
|
|
23
|
+
* @param Z - Samples as `Z[row][col]`.
|
|
24
|
+
* @category Math & helpers
|
|
25
|
+
*/
|
|
26
|
+
export declare function imshowCells(Z: readonly (readonly number[])[], options?: ImshowOptions): ImshowResult;
|