@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,163 @@
1
+ /**
2
+ * `heatmap`: the annotated heatmap preset, a `chart` around a `cells` layer;
3
+ * with `cluster`, a clustermap whose dendrograms stand in the chart's margin.
4
+ * The nodes are made once and updated in place.
5
+ */
6
+ import type { ColorRampSpec, SceneNode } from "@sophistry/core";
7
+ import type { BandKey, Point } from "@sophistry/core/geometry";
8
+ import type { RampScaleName } from "../color-norm.js";
9
+ import type { Channel } from "../data/channels.js";
10
+ import type { ClusterLinkage, ClusterMetric } from "../math/cluster.js";
11
+ import type { KeyedTransitionProps, RevealProps } from "../props.js";
12
+ import type { TooltipSpec } from "../tooltip.js";
13
+ /**
14
+ * Props of {@link heatmap}.
15
+ *
16
+ * @category Charts
17
+ */
18
+ export interface HeatmapProps<T = unknown> extends KeyedTransitionProps<T>, RevealProps {
19
+ /** One cell per datum. */
20
+ data: readonly T[];
21
+ /** The cell's column: a category. */
22
+ x: Channel<T, BandKey>;
23
+ /** The cell's row: a category. */
24
+ y: Channel<T, BandKey>;
25
+ /** The number the cell's colour encodes. */
26
+ value: Channel<T, number>;
27
+ /**
28
+ * Column order; clustered columns are reordered. Defaults to the order first seen in `data`.
29
+ */
30
+ columns?: readonly BandKey[];
31
+ /**
32
+ * Row order, top to bottom; clustered rows are reordered. Defaults to the order first seen in
33
+ * `data`.
34
+ */
35
+ rows?: readonly BandKey[];
36
+ /**
37
+ * Cluster the rows, the columns, or both (`true`) by their values ({@link clusterRows}), laid
38
+ * out in dendrogram order so similar ones sit together. Missing cells are skipped.
39
+ * @default false
40
+ */
41
+ cluster?: boolean | "rows" | "columns";
42
+ /**
43
+ * How clusters are compared; see {@link ClusterLinkage}.
44
+ * @default "average"
45
+ */
46
+ linkage?: ClusterLinkage;
47
+ /**
48
+ * How rows (columns) are compared; see {@link ClusterMetric}.
49
+ * @default "euclidean"
50
+ */
51
+ metric?: ClusterMetric;
52
+ /**
53
+ * Draw each clustering's {@link dendrogram} in the margin: the rows' on the left (row names
54
+ * move right), the columns' above the grid. Defaults to true when clustering.
55
+ */
56
+ dendrogram?: boolean;
57
+ /**
58
+ * How far a dendrogram's root stands from its leaves.
59
+ * @default 0.8
60
+ */
61
+ dendrogramSize?: number;
62
+ /** Width of the plotting area. */
63
+ width: number;
64
+ /** Height of the plotting area. */
65
+ height: number;
66
+ /** Centre of the plotting area. Defaults to the origin. */
67
+ center?: Point;
68
+ /** Colormap name, CSS stops, or `(t) => colour`. Defaults to the theme's ramp. */
69
+ ramp?: ColorRampSpec;
70
+ /** Value at the bottom of the ramp. Defaults to the smallest value. */
71
+ rampMin?: number;
72
+ /** Value at the top of the ramp. Defaults to the largest value. */
73
+ rampMax?: number;
74
+ /**
75
+ * How values spread over the ramp (`"log"`, `"symlog"`, `"sqrt"`).
76
+ * @default "linear"
77
+ */
78
+ rampScale?: RampScaleName;
79
+ /** A diverging centre: this value takes the ramp's middle. */
80
+ rampMidpoint?: number;
81
+ /**
82
+ * Write each value in its cell: `true`, `false`, or a channel for your own text.
83
+ * @default true
84
+ */
85
+ labels?: boolean | Channel<T, string>;
86
+ /** Font size of the cell text. */
87
+ labelFontSize?: number;
88
+ /** Title above the chart. */
89
+ title?: string;
90
+ /**
91
+ * A colour bar beside the grid.
92
+ * @default false
93
+ */
94
+ colorbar?: boolean;
95
+ /** A title above the colour bar. */
96
+ colorbarLabel?: string;
97
+ /** Title for the columns, placed past the right end of the x axis. */
98
+ xLabel?: string;
99
+ /** Title for the rows, placed above the y axis. */
100
+ yLabel?: string;
101
+ /**
102
+ * Reveal, 0..1: names first, then the cells in reading order.
103
+ * @see https://sophistry.dev/guides/chart-animation/#reveals
104
+ */
105
+ progress?: number;
106
+ /**
107
+ * Fraction of the cells' reveal spent staggering, 0..0.95.
108
+ * @default 0.5
109
+ */
110
+ stagger?: number;
111
+ /** Hover tooltip: `true` for "column · row: value", or `(d, i) => string`. */
112
+ tooltip?: TooltipSpec<T>;
113
+ /** Paint order of the chart; the cells paint under its guides. */
114
+ zIndex?: number;
115
+ /** Set to false to hide the heatmap. */
116
+ visible?: boolean;
117
+ /** Placed inside the chart's coordinate context, after the cells. */
118
+ children?: readonly SceneNode[];
119
+ /**
120
+ * Each cell's identity across transitions. See {@link KeyedTransitionProps}. Defaults to its
121
+ * (column, row) pair.
122
+ */
123
+ key?: Channel<T, BandKey>;
124
+ /**
125
+ * The data to transition to, cells matched by `key`: colours blend, unmatched cells fade,
126
+ * fitted columns and rows blend. Throws together with `cluster`. See {@link
127
+ * KeyedTransitionProps}.
128
+ * @see https://sophistry.dev/guides/chart-animation/#data-transitions
129
+ */
130
+ to?: readonly T[];
131
+ }
132
+ /**
133
+ * An annotated heatmap: a value per (column, row) pair, coloured through a ramp and written in
134
+ * its cell in a colour that reads on it. With `cluster`, a clustermap with dendrograms in the
135
+ * margin. A preset over `chart` and {@link cells}; use those to add other marks.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import { heatmap } from "@sophistry/charts";
140
+ *
141
+ * const correlations = [
142
+ * { a: "x", b: "x", r: 1 },
143
+ * { a: "x", b: "y", r: -0.4 },
144
+ * { a: "y", b: "x", r: -0.4 },
145
+ * { a: "y", b: "y", r: 1 },
146
+ * ];
147
+ * heatmap.create({
148
+ * width: 6,
149
+ * height: 4,
150
+ * data: correlations,
151
+ * x: "a",
152
+ * y: "b",
153
+ * value: "r",
154
+ * ramp: "rdbu",
155
+ * rampMidpoint: 0,
156
+ * cluster: true,
157
+ * });
158
+ * ```
159
+ *
160
+ * @see https://sophistry.dev/reference/chart-catalogue/#heatmaps-and-contours
161
+ * @category Charts
162
+ */
163
+ export declare const heatmap: import("@sophistry/core").Definition<HeatmapProps<any>, import("@sophistry/core/internal").CompositeNode<HeatmapProps<any>>, keyof HeatmapProps<any>>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * `hexBin`: hexagonal binning, drawn as one path batch. The hexagons are
3
+ * regular in data units, so under unequal axis scales (or a log axis) their
4
+ * scene outlines differ in shape: a path batch (one outline per item) rather
5
+ * than polygon instances, which only scale uniformly.
6
+ */
7
+ import type { ColorRampSpec } from "@sophistry/core";
8
+ import type { Point } from "@sophistry/core/geometry";
9
+ import type { RampScaleProps } from "../color-norm.js";
10
+ import type { Channel } from "../data/channels.js";
11
+ /**
12
+ * Props of {@link hexBin}.
13
+ *
14
+ * @category Charts
15
+ */
16
+ export interface HexBinProps<T = unknown> {
17
+ /** One observation per datum; data with a non-finite `x` or `y` are dropped. */
18
+ data: readonly T[];
19
+ /** X position, in data units. */
20
+ x: Channel<T, number>;
21
+ /** Y position, in data units. */
22
+ y: Channel<T, number>;
23
+ /**
24
+ * Hex centre-to-corner distance in data units, on both axes (see {@link hexbin}). Required: no
25
+ * default fits every axis scale.
26
+ */
27
+ radius: number;
28
+ /**
29
+ * Low-to-high count ramp: a colormap name, CSS stops or function. Defaults to the theme's ramp.
30
+ */
31
+ ramp?: ColorRampSpec;
32
+ /**
33
+ * Fraction of the reveal spent staggering the cells in reading order, 0..0.95. Defaults to 0.5
34
+ * (0 above 2000 cells).
35
+ */
36
+ stagger?: number;
37
+ /**
38
+ * How counts spread over the ramp: `"log"` (from the emptiest drawn cell), `"sqrt"` or
39
+ * `"symlog"` (from 0).
40
+ * @default "linear"
41
+ */
42
+ rampScale?: RampScaleProps["rampScale"];
43
+ /**
44
+ * The count at the ramp's low end. Under `rampScale="log"`, give a value below the emptiest
45
+ * cell (say 0.5) to lift every drawn cell off the floor. Defaults to 0 (the emptiest drawn
46
+ * cell's count under `"log"`).
47
+ */
48
+ rampMin?: number;
49
+ /** The count at the ramp's high end. Defaults to the fullest cell's. */
50
+ rampMax?: number;
51
+ /** Hexagon outline. @default "none" */
52
+ stroke?: string;
53
+ /** Outline width. */
54
+ strokeWidth?: number;
55
+ /** Opacity 0..1. @default 1 */
56
+ opacity?: number;
57
+ /** Fill opacity 0..1, on top of `opacity`. @default 1 */
58
+ fillOpacity?: number;
59
+ /** Reveal 0..1: hexagons fade in in reading order, top row first. @default 1 */
60
+ progress?: number;
61
+ /** Paint order. Defaults to `UNDER_AXES_Z_INDEX` (above the grid, under the axes). */
62
+ zIndex?: number;
63
+ /** Set to false to hide the hexagons. */
64
+ visible?: boolean;
65
+ }
66
+ /**
67
+ * The six corners of a pointy-top hexagon in data space, matching the `hexbin()` grid.
68
+ *
69
+ * @internal
70
+ */
71
+ export declare function hexCorners(cx: number, cy: number, radius: number): Point[];
72
+ /**
73
+ * A hexagonal binning heatmap: points binned into a hex grid in data space, one filled hexagon
74
+ * per occupied cell coloured by its count. With unequal axis scales the hexagons stretch. Paints
75
+ * under the axes by default (`zIndex` `UNDER_AXES_Z_INDEX`). Inside a `chart` or `axes`; drawn
76
+ * as one path batch. See {@link hexbin} for the binning alone.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { chart, hexBin } from "@sophistry/charts";
81
+ *
82
+ * const points = Array.from({ length: 200 }, (_, i) => ({ x: Math.sin(i) * 3, y: Math.cos(i * 0.7) * 2 }));
83
+ * chart.create({
84
+ * width: 6,
85
+ * height: 4,
86
+ * children: [hexBin.create({ data: points, x: "x", y: "y", radius: 0.4, ramp: "magma" })],
87
+ * });
88
+ * ```
89
+ *
90
+ * @see https://sophistry.dev/reference/chart-catalogue/#heatmaps-and-contours
91
+ * @category Charts
92
+ */
93
+ export declare const hexBin: import("@sophistry/core").Definition<HexBinProps<any>, import("@sophistry/core/internal").CompositeNode<HexBinProps<any>>, keyof HexBinProps<any>>;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * `hist2d`: a 2D histogram, drawn as one instances node of `rect`s (see
3
+ * `cell-rects.ts`). Nonempty cells fade in in reading order.
4
+ */
5
+ import type { ColorRampSpec } from "@sophistry/core";
6
+ import type { Range } from "@sophistry/core/geometry";
7
+ import type { MarkTransition } from "../batch.js";
8
+ import type { RampScaleProps } from "../color-norm.js";
9
+ import type { Channel } from "../data/channels.js";
10
+ /**
11
+ * Props of {@link hist2d}.
12
+ *
13
+ * @category Charts
14
+ */
15
+ export interface Hist2DProps<T = unknown> {
16
+ /** One observation per datum; data with a non-finite `x` or `y` are dropped. */
17
+ data: readonly T[];
18
+ /** X position, in data units. */
19
+ x: Channel<T, number>;
20
+ /** Y position, in data units. */
21
+ y: Channel<T, number>;
22
+ /**
23
+ * Number of equal-width bins along x. Wins over an `xRange` step. Defaults to the count the
24
+ * step implies, else 10.
25
+ */
26
+ xBins?: number;
27
+ /**
28
+ * Number of equal-width bins along y. Wins over a `yRange` step. Defaults to the count the step
29
+ * implies, else 10.
30
+ */
31
+ yBins?: number;
32
+ /**
33
+ * `[min, max, step?]` spanned by the x bins, in data units; `step` is the bin width when
34
+ * `xBins` is not given. Defaults to the finite extent of the x values.
35
+ */
36
+ xRange?: Range;
37
+ /**
38
+ * `[min, max, step?]` spanned by the y bins, in data units; `step` is the bin width when
39
+ * `yBins` is not given. Defaults to the finite extent of the y values.
40
+ */
41
+ yRange?: Range;
42
+ /**
43
+ * Colour ramp (colormap name, CSS stops or function) sampled by each cell's count relative to
44
+ * the largest. Defaults to the theme's ramp (background to first series colour).
45
+ */
46
+ ramp?: ColorRampSpec;
47
+ /**
48
+ * Fraction of the reveal spent staggering the cells in reading order, 0..0.95. Defaults to 0.5
49
+ * (0 above 2000 cells).
50
+ */
51
+ stagger?: number;
52
+ /**
53
+ * How counts spread over the ramp: `"log"` (from the emptiest drawn cell), `"sqrt"` or
54
+ * `"symlog"` (from 0).
55
+ * @default "linear"
56
+ */
57
+ rampScale?: RampScaleProps["rampScale"];
58
+ /**
59
+ * The count at the ramp's low end. Under `rampScale="log"`, give a value below the emptiest
60
+ * cell (say 0.5) to lift every drawn cell off the floor. Defaults to 0 (the emptiest drawn
61
+ * cell's count under `"log"`).
62
+ */
63
+ rampMin?: number;
64
+ /** The count at the ramp's high end. Defaults to the fullest cell's. */
65
+ rampMax?: number;
66
+ /**
67
+ * How cells change colour when `data` changes: a tween or a spring; new
68
+ * cells fade in, emptied ones fade out. Omitted, changes are instant.
69
+ */
70
+ transition?: MarkTransition;
71
+ /** Cell outline. @default "none" */
72
+ stroke?: string;
73
+ /** Outline width. */
74
+ strokeWidth?: number;
75
+ /** Opacity 0..1. @default 1 */
76
+ opacity?: number;
77
+ /** Fill opacity 0..1, on top of `opacity`. @default 1 */
78
+ fillOpacity?: number;
79
+ /** Reveal 0..1: cells fade in in reading order, top row first. @default 1 */
80
+ progress?: number;
81
+ /** Paint order. Defaults to `UNDER_AXES_Z_INDEX` (above the grid, under the axes). */
82
+ zIndex?: number;
83
+ /** Set to false to hide the cells. */
84
+ visible?: boolean;
85
+ }
86
+ /**
87
+ * A 2D histogram: points bucketed into a grid of equal-width cells, each nonempty cell coloured
88
+ * by its count. Empty cells are not drawn. Paints under the axes by default (`zIndex`
89
+ * `UNDER_AXES_Z_INDEX`). Inside a `chart` or `axes`; drawn as one instances node of
90
+ * rectangles. See {@link histogram2d} for the binning alone.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { chart, hist2d } from "@sophistry/charts";
95
+ *
96
+ * const points = Array.from({ length: 200 }, (_, i) => ({ x: Math.sin(i) * 3, y: Math.cos(i * 0.7) * 2 }));
97
+ * chart.create({
98
+ * width: 6,
99
+ * height: 4,
100
+ * children: [hist2d.create({ data: points, x: "x", y: "y", xBins: 20, yBins: 12 })],
101
+ * });
102
+ * ```
103
+ *
104
+ * @see https://sophistry.dev/reference/chart-catalogue/#heatmaps-and-contours
105
+ * @category Charts
106
+ */
107
+ export declare const hist2d: import("@sophistry/core").Definition<Hist2DProps<any>, import("@sophistry/core/internal").CompositeNode<Hist2DProps<any>>, keyof Hist2DProps<any>>;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `imshow`: a 2D array as one image node. The colours go through a 256-step
3
+ * lookup table of the ramp (`raster.ts`), so a million cells are a million
4
+ * table reads and one bitmap the camera moves for free.
5
+ *
6
+ * The reading-order fade stays: while a staggered reveal runs, each pixel's
7
+ * alpha is its cell's share of the fade (the stagger drops to 0 above 2,000
8
+ * cells, so this only rewrites small images per frame). Under a non-linear
9
+ * axis, where an image would put cells in the wrong places, or with a cell
10
+ * `stroke`, the cells are drawn as one instances node of `rect`s instead.
11
+ */
12
+ import type { ColorRampSpec } from "@sophistry/core";
13
+ import type { Range } from "@sophistry/core/geometry";
14
+ import type { RampScaleProps } from "../color-norm.js";
15
+ /**
16
+ * Props of {@link imshow}.
17
+ *
18
+ * @category Charts
19
+ */
20
+ export interface ImshowProps extends RampScaleProps {
21
+ /** Rows × columns of values; ragged rows are tolerated. */
22
+ values: readonly (readonly number[])[];
23
+ /** `[min, max]` in data units the columns span. Defaults to `[0, ncols]`. */
24
+ xRange?: Range;
25
+ /** `[min, max]` in data units the rows span. Defaults to `[0, nrows]`. */
26
+ yRange?: Range;
27
+ /**
28
+ * Which edge row 0 sits on: `"upper"` (top) or `"lower"` (bottom).
29
+ * @default "upper"
30
+ */
31
+ rowOrigin?: "upper" | "lower";
32
+ /**
33
+ * Colour ramp sampled by each cell's value between `rampMin` and `rampMax`: CSS stops, a
34
+ * colormap name (`"viridis"`), or `(t) => colour`. Defaults to the theme's ramp (background to
35
+ * first series colour).
36
+ */
37
+ ramp?: ColorRampSpec;
38
+ /** Value at the bottom of the ramp. Defaults to the finite minimum of `values`. */
39
+ rampMin?: number;
40
+ /** Value at the top of the ramp. Defaults to the finite maximum of `values`. */
41
+ rampMax?: number;
42
+ /**
43
+ * Fraction of the reveal spent staggering the cells in reading order, 0..0.95. Defaults to 0.5
44
+ * (0 above 2000 cells).
45
+ */
46
+ stagger?: number;
47
+ /** Interpolate between pixels when magnified. @default false */
48
+ smoothing?: boolean;
49
+ /** Cell outline; given, the cells are drawn as rectangles rather than an image. */
50
+ stroke?: string;
51
+ /** Outline width. */
52
+ strokeWidth?: number;
53
+ /** Opacity 0..1. @default 1 */
54
+ opacity?: number;
55
+ /** Reveal 0..1: cells fade in in reading order, top row first. @default 1 */
56
+ progress?: number;
57
+ /** Paint order. Defaults to `UNDER_AXES_Z_INDEX` (above the grid, under the axes). */
58
+ zIndex?: number;
59
+ /** Set to false to hide the image. */
60
+ visible?: boolean;
61
+ }
62
+ /**
63
+ * A 2D array as an image: equal-sized cells over `xRange` × `yRange`, each finite value
64
+ * coloured on a ramp. Use {@link pcolormesh} for uneven cell coordinates. Paints under the
65
+ * axes by default (`zIndex` `UNDER_AXES_Z_INDEX`). Inside a `chart` or `axes`. Drawn as one
66
+ * image node (cells as rectangles under a non-linear axis or with a `stroke`). See
67
+ * {@link imshowCells}.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { chart, imshow } from "@sophistry/charts";
72
+ *
73
+ * chart.create({
74
+ * width: 6,
75
+ * height: 4,
76
+ * colorbar: true,
77
+ * children: [imshow.create({ values: [[0, 1, 2], [3, 4, 5]], ramp: "viridis" })],
78
+ * });
79
+ * ```
80
+ *
81
+ * @see https://sophistry.dev/reference/chart-catalogue/#heatmaps-and-contours
82
+ * @category Charts
83
+ */
84
+ export declare const imshow: import("@sophistry/core").Definition<ImshowProps, import("@sophistry/core/internal").CompositeNode<ImshowProps>, keyof ImshowProps>;
@@ -0,0 +1,26 @@
1
+ /** Family barrel: grids. Owned by its family; re-exported from the package entry. */
2
+ export type { BarbsProps } from "./barbs.js";
3
+ export { barbs } from "./barbs.js";
4
+ export type { CellsProps } from "./cells.js";
5
+ export { cells } from "./cells.js";
6
+ export type { ContourProps } from "./contour.js";
7
+ export { contour } from "./contour.js";
8
+ export type { ContourFProps } from "./contour-f.js";
9
+ export { contourF } from "./contour-f.js";
10
+ export type { DendrogramProps } from "./dendrogram.js";
11
+ export { dendrogram } from "./dendrogram.js";
12
+ export type { HeatmapProps } from "./heatmap.js";
13
+ export { heatmap } from "./heatmap.js";
14
+ export type { HexBinProps } from "./hex-bin.js";
15
+ export { hexBin } from "./hex-bin.js";
16
+ export type { Hist2DProps } from "./hist2d.js";
17
+ export { hist2d } from "./hist2d.js";
18
+ export type { ImshowProps } from "./imshow.js";
19
+ export { imshow } from "./imshow.js";
20
+ export type { PcolormeshProps } from "./pcolormesh.js";
21
+ export { pcolormesh } from "./pcolormesh.js";
22
+ export type { TriContourFProps, TriContourProps } from "./tri-contour.js";
23
+ export { triContour, triContourF } from "./tri-contour.js";
24
+ export type { TriChartBaseProps } from "./tri-shared.js";
25
+ export type { TripcolorProps } from "./tripcolor.js";
26
+ export { tripcolor } from "./tripcolor.js";
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `pcolormesh`: a coloured mesh over a rectilinear grid, drawn as one
3
+ * instances node of `rect`s (see `cell-rects.ts`). Cells fade in in reading
4
+ * order (`stagger`, dropped above 2,000 cells), through each item's opacity.
5
+ */
6
+ import type { ColorRampSpec } from "@sophistry/core";
7
+ import type { MarkTransition } from "../batch.js";
8
+ import type { RampScaleProps } from "../color-norm.js";
9
+ import type { PcolormeshCell } from "../math/pcolormesh.js";
10
+ import type { CellItem } from "./cell-rects.js";
11
+ import { cellBox } from "./cell-rects.js";
12
+ import type { RampCells } from "./ramp-cells.js";
13
+ /**
14
+ * Props of {@link pcolormesh}.
15
+ *
16
+ * @category Charts
17
+ */
18
+ export interface PcolormeshProps extends RampScaleProps {
19
+ /** `ncols` centres or `ncols + 1` edges of the columns, in data units. */
20
+ xs: readonly number[];
21
+ /** `nrows` centres or `nrows + 1` edges of the rows, in data units. */
22
+ ys: readonly number[];
23
+ /** Rows × columns of values; ragged rows are tolerated. */
24
+ values: readonly (readonly number[])[];
25
+ /**
26
+ * Colour ramp sampled by each cell's value between `rampMin` and `rampMax`: CSS stops, a
27
+ * colormap name, or `(t) => colour`. Defaults to the theme's ramp (background to first series
28
+ * colour).
29
+ */
30
+ ramp?: ColorRampSpec;
31
+ /** Value at the bottom of the ramp. Defaults to the finite minimum of `values`. */
32
+ rampMin?: number;
33
+ /** Value at the top of the ramp. Defaults to the finite maximum of `values`. */
34
+ rampMax?: number;
35
+ /**
36
+ * Fraction of the reveal spent staggering the cells in reading order, 0..0.95. Defaults to 0.5
37
+ * (0 above 2000 cells).
38
+ */
39
+ stagger?: number;
40
+ /**
41
+ * How cells change colour when `values` changes: a tween or a spring in the
42
+ * node's tween bank; new cells fade in, removed ones fade out. Omitted,
43
+ * changes are instant.
44
+ */
45
+ transition?: MarkTransition;
46
+ /** Cell outline. @default "none" */
47
+ stroke?: string;
48
+ /** Outline width. */
49
+ strokeWidth?: number;
50
+ /** Opacity 0..1. @default 1 */
51
+ opacity?: number;
52
+ /** Fill opacity 0..1, on top of `opacity`. @default 1 */
53
+ fillOpacity?: number;
54
+ /** Reveal 0..1: cells fade in in reading order, top row first. @default 1 */
55
+ progress?: number;
56
+ /** Paint order. Defaults to `UNDER_AXES_Z_INDEX` (above the grid, under the axes). */
57
+ zIndex?: number;
58
+ /** Set to false to hide the mesh. */
59
+ visible?: boolean;
60
+ }
61
+ /** Each drawn cell's box and colour, for one fit of the axes. */
62
+ export declare function placeGridCells(grid: RampCells<PcolormeshCell>, coords: Parameters<typeof cellBox>[0], bleed?: number): CellItem[];
63
+ /**
64
+ * The placed cells at this frame of the reveal: each with the layer's
65
+ * `opacity` and its share of the reveal as its `progress`.
66
+ */
67
+ export declare function revealCells(placed: readonly CellItem[], grid: Pick<RampCells<unknown>, "revealOf">, opacity: number | undefined): CellItem[];
68
+ /**
69
+ * A coloured mesh over a rectilinear grid: `xs`/`ys` are per-axis centres or edges (uneven
70
+ * spacing allowed), `values` the cell values, each finite cell coloured on a ramp. Throws if
71
+ * `xs` or `ys` has the wrong length. Paints under the axes by default (`zIndex`
72
+ * `UNDER_AXES_Z_INDEX`). Inside a `chart` or `axes`. Drawn as one instances node of
73
+ * rectangles. See {@link pcolormeshCells}.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { chart, pcolormesh } from "@sophistry/charts";
78
+ *
79
+ * chart.create({
80
+ * width: 6,
81
+ * height: 4,
82
+ * colorbar: true,
83
+ * children: [pcolormesh.create({ xs: [0, 1, 3], ys: [0, 2], values: [[1, 2]], ramp: "viridis" })],
84
+ * });
85
+ * ```
86
+ *
87
+ * @see https://sophistry.dev/reference/chart-catalogue/#heatmaps-and-contours
88
+ * @category Charts
89
+ */
90
+ export declare const pcolormesh: import("@sophistry/core").Definition<PcolormeshProps, import("@sophistry/core/internal").CompositeNode<PcolormeshProps>, keyof PcolormeshProps>;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The plumbing the gridded colour layers share (`imshow`, `pcolormesh`,
3
+ * `hist2d`, `hexBin`): a colormap and norm over the cells' values, the
4
+ * layer's report to its chart (with its colour-bar ramp), and the cells'
5
+ * reading-order fade. Internal to the charts.
6
+ *
7
+ * Each piece is a factory called once in `setup` that returns a function to
8
+ * call in every `update`. Each step sits
9
+ * behind a last-input cache, so a frame of a reveal recomputes the fade and
10
+ * nothing else, and the colormap and norm keep their identity (the chart
11
+ * compares reports by value, colormaps and scales by identity).
12
+ */
13
+ import type { ColorRampSpec, CoordinateSystem } from "@sophistry/core";
14
+ import type { Colormap, Theme } from "@sophistry/core/themes";
15
+ import type { ColorNorm, RampScaleOptions } from "../color-norm.js";
16
+ import type { ChartLayer } from "../context.js";
17
+ import type { ChartLayerExtent } from "../frame/types.js";
18
+ /** What {@link createRampCells}'s function takes on each update. */
19
+ export interface RampCellsSpec<C> {
20
+ layer: ChartLayer;
21
+ coords: CoordinateSystem;
22
+ theme: Theme;
23
+ ramp: ColorRampSpec | undefined;
24
+ /** Every cell, drawn or not; keep the same array while nothing changed. */
25
+ cells: readonly C[];
26
+ value: (cell: C) => number;
27
+ /** A cell's place for reading order (any point its row shares). */
28
+ at: (cell: C) => {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ norm: RampScaleOptions;
33
+ /** The values the norm's automatic range reads (same array while unchanged); defaults to every cell's value. */
34
+ domain?: readonly number[];
35
+ /** The layer's report, less `covers` and `ramp`. */
36
+ extent: Omit<ChartLayerExtent, "ramp" | "covers">;
37
+ stagger: number | undefined;
38
+ /** The layer's own `progress`, before the chart's data phase. */
39
+ progress: number | undefined;
40
+ }
41
+ /** What {@link createRampCells}'s function hands back. */
42
+ export interface RampCells<C> {
43
+ /** The cells to draw: those whose value has a place on the norm (finite; positive under `"log"`). */
44
+ cells: readonly C[];
45
+ /** A drawn cell's colour. */
46
+ fill(cell: C): string;
47
+ /** A value's place on the norm, 0..1 (non-finite when it has none). */
48
+ unitOf(value: number): number;
49
+ /** The ramp's colour at a place on the norm, 0..1. */
50
+ colorAt(unit: number): string;
51
+ /** The colormap, kept while the ramp and theme are. */
52
+ colormap: Colormap;
53
+ /** The norm, kept while the values and norm props are. */
54
+ norm: ColorNorm;
55
+ /** The layer's reveal, scaled by the chart's data phase (undefined outside a chart without `progress`). */
56
+ progress: number | undefined;
57
+ /** Whether the cells fade one after another (a stagger over more than one cell). */
58
+ staggered: boolean;
59
+ /** The `i`th drawn cell's reveal: its share of the reading-order fade when staggered. */
60
+ revealOf(i: number): number | undefined;
61
+ }
62
+ /**
63
+ * A gridded colour layer's cells, colours, report and fade. Call once, in
64
+ * `setup`; call the result in each `update` (it reports to the chart).
65
+ */
66
+ export declare function createRampCells<C>(): (spec: RampCellsSpec<C>) => RampCells<C>;