@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,233 @@
1
+ /**
2
+ * `sizeLegend`: a key to a size encoding, a hollow reference circle per
3
+ * value; `sizeKeyStack`: a frame's stack of them, one per size scale; and
4
+ * the measurements a frame lays them out with.
5
+ *
6
+ * A value's nodes are kept for as long as either end of a transition shows
7
+ * the value, and hidden with `visible: false` when they are not shown.
8
+ * Each end is measured once per change of its scale, values, title or font,
9
+ * not as `progress` or a transition's stages move.
10
+ */
11
+ import type { Point } from "@sophistry/core/geometry";
12
+ import type { SizeScale } from "../frame/types.js";
13
+ /**
14
+ * A size key's keyed transition: the far end's scale and values, and how far each stage has
15
+ * got. `chart` passes one while a keyed transition runs.
16
+ *
17
+ * @see https://sophistry.dev/guides/chart-animation/#data-transitions
18
+ * @category Charts
19
+ */
20
+ export interface SizeLegendTransition {
21
+ /** The scale at the end. */
22
+ to: SizeScale;
23
+ /** The values the end shows. Defaults to `values`, else the end's own round values. */
24
+ values?: readonly number[];
25
+ /** Progress of the exit stage, 0..1. */
26
+ exit: number;
27
+ /** Progress of the update stage, 0..1. */
28
+ update: number;
29
+ /** Progress of the enter stage, 0..1. */
30
+ enter: number;
31
+ }
32
+ /**
33
+ * Props for {@link sizeLegend}.
34
+ *
35
+ * @category Charts
36
+ */
37
+ export interface SizeLegendProps {
38
+ /** The size scale the key explains. */
39
+ scale: SizeScale;
40
+ /**
41
+ * The values to draw circles for, in order. Defaults to up to three round values of the scale.
42
+ */
43
+ values?: readonly number[];
44
+ /** How a value is written. Defaults to the axes' formatting. */
45
+ format?: (value: number) => string;
46
+ /** The key's top-left corner, in scene units. */
47
+ at: Point;
48
+ /**
49
+ * `"column"`: one circle per row. `"row"`: side by side, wrapping at `maxWidth`.
50
+ * @default "column"
51
+ */
52
+ direction?: "column" | "row";
53
+ /** With `direction: "row"`: wrap before an entry that would run past this width. */
54
+ maxWidth?: number;
55
+ /** A title line above the circles. */
56
+ title?: string;
57
+ /**
58
+ * Font size of the labels.
59
+ * @default 0.28
60
+ */
61
+ fontSize?: number;
62
+ /**
63
+ * Reveal, 0..1: the circles fade in one after another.
64
+ * @default 1
65
+ */
66
+ progress?: number;
67
+ /** A keyed data transition in progress; see {@link SizeLegendTransition}. */
68
+ transition?: SizeLegendTransition;
69
+ /** Paint order; higher draws later. */
70
+ zIndex?: number;
71
+ /** Set to `false` to hide the key. */
72
+ visible?: boolean;
73
+ }
74
+ /** Measurement options shared by {@link sizeLegend} and the frames that place one. */
75
+ export interface SizeLegendMetrics {
76
+ direction?: "column" | "row";
77
+ maxWidth?: number;
78
+ title?: string;
79
+ fontSize?: number;
80
+ format?: (value: number) => string;
81
+ fontFamily: string;
82
+ }
83
+ /**
84
+ * A key to a size encoding: a hollow reference circle per value, with the value beside it,
85
+ * drawn through the same square-root scale as the marks. `chart` draws one automatically for
86
+ * layers sized by value (`scatter`'s `size`); use this directly for charts without a frame.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { sizeLegend } from "@sophistry/charts";
91
+ *
92
+ * sizeLegend.create({
93
+ * at: { x: 3, y: 2 },
94
+ * scale: { maxValue: 100, range: [0, 0.5] },
95
+ * values: [25, 100],
96
+ * title: "Population",
97
+ * });
98
+ * ```
99
+ *
100
+ * @see https://sophistry.dev/guides/charts/#series-and-legends
101
+ * @category Charts
102
+ */
103
+ export declare const sizeLegend: import("@sophistry/core").Definition<SizeLegendProps, import("@sophistry/core/internal").CompositeNode<SizeLegendProps>, keyof SizeLegendProps>;
104
+ /**
105
+ * One key of a frame's stack of size keys: the scale its sized layers draw on at each end of a
106
+ * keyed transition, and the first such layer's channel name.
107
+ *
108
+ * @internal
109
+ */
110
+ export interface SizeKey {
111
+ maxValue: number;
112
+ to?: number;
113
+ range: readonly [number, number];
114
+ label?: string;
115
+ }
116
+ /**
117
+ * A key's laid-out size, and how far it is there at all (0 at an end without one).
118
+ *
119
+ * @internal
120
+ */
121
+ export interface SizeKeyExtent {
122
+ width: number;
123
+ height: number;
124
+ presence: number;
125
+ }
126
+ /**
127
+ * A stack of size keys at each end of a keyed transition: the stack's size and each key's
128
+ * place in it.
129
+ *
130
+ * @internal
131
+ */
132
+ export interface SizeKeysEnds {
133
+ from: SizeKeyExtent;
134
+ to: SizeKeyExtent | undefined;
135
+ /** Each key's top-left corner from the stack's: `x` to the right, `y` down. */
136
+ offsets: {
137
+ from: readonly Point[];
138
+ to: readonly Point[] | undefined;
139
+ };
140
+ }
141
+ /**
142
+ * Each key of a stack measured at each end, before the stack is flowed ({@link flowSizeKeys}).
143
+ *
144
+ * @internal
145
+ */
146
+ export interface SizeKeyMeasures {
147
+ from: readonly SizeKeyExtent[];
148
+ to: readonly SizeKeyExtent[] | undefined;
149
+ }
150
+ /**
151
+ * How a stack of keys flows into columns: a key that would run past `maxHeight` starts a new
152
+ * column `gap` to the right.
153
+ *
154
+ * @internal
155
+ */
156
+ interface SizeKeyColumns {
157
+ maxHeight: number;
158
+ gap: number;
159
+ }
160
+ /**
161
+ * Measures each key of a stack at each end (presence 0 where an end sizes nothing). Undefined
162
+ * without keys. Separate from {@link flowSizeKeys} so a re-flow doesn't re-measure text.
163
+ *
164
+ * @internal
165
+ */
166
+ export declare function measureSizeKeyExtents(keys: readonly SizeKey[], options: Omit<SizeLegendMetrics, "title"> & {
167
+ title?: string;
168
+ values?: readonly number[];
169
+ }): SizeKeyMeasures | undefined;
170
+ /**
171
+ * Flows a stack's measured keys at each end: one under another `gap` apart, starting a new
172
+ * column when one would run past `columns.maxHeight`. A key absent at an end takes no room.
173
+ *
174
+ * @internal
175
+ */
176
+ export declare function flowSizeKeys(measures: SizeKeyMeasures | undefined, gap: number, columns?: SizeKeyColumns): SizeKeysEnds | undefined;
177
+ /**
178
+ * Measures a stack of size keys and flows it ({@link measureSizeKeyExtents},
179
+ * {@link flowSizeKeys}). Undefined without keys.
180
+ *
181
+ * @internal
182
+ */
183
+ export declare function measureSizeKeys(keys: readonly SizeKey[], options: Omit<SizeLegendMetrics, "title"> & {
184
+ title?: string;
185
+ values?: readonly number[];
186
+ }, gap: number, columns?: SizeKeyColumns): SizeKeysEnds | undefined;
187
+ /** Two stacks' measured keys with the same sizes, end by end. */
188
+ export declare function sameSizeKeyMeasures(a: SizeKeyMeasures | undefined, b: SizeKeyMeasures | undefined): boolean;
189
+ /** Two measured stacks of size keys with the same sizes and places. */
190
+ export declare function sameSizeKeysEnds(a: SizeKeysEnds | undefined, b: SizeKeysEnds | undefined): boolean;
191
+ /**
192
+ * Each key's place in the stack now: its own end's, or while a key rescales, both ends'
193
+ * blended by the update progress `u`.
194
+ *
195
+ * @internal
196
+ */
197
+ export declare function sizeKeyOffsets(ends: SizeKeysEnds | undefined, u: number): readonly Point[];
198
+ /** Two lists of key places, compared by value. */
199
+ export declare function sameOffsets(a: readonly Point[] | undefined, b: readonly Point[] | undefined): boolean;
200
+ /** The stages a stack of keys transitions on: exit, update and enter progress, as `SizeLegendTransition` takes them. */
201
+ export type SizeKeyStages = Pick<SizeLegendTransition, "exit" | "update" | "enter">;
202
+ /**
203
+ * Props for {@link sizeKeyStack}.
204
+ *
205
+ * @internal
206
+ */
207
+ export interface SizeKeyStackProps {
208
+ keys: readonly SizeKey[];
209
+ /** Each key's top-left corner from `at`: `x` to the right, `y` down. */
210
+ offsets: readonly Point[];
211
+ /** The stack's top-left corner. */
212
+ at: Point;
213
+ /** A title for the first key (see `sizeKeyTitle`). */
214
+ title?: string;
215
+ values?: readonly number[];
216
+ format?: (value: number) => string;
217
+ direction: "column" | "row";
218
+ maxWidth?: number;
219
+ fontSize?: number;
220
+ progress?: number;
221
+ /** The keyed transition's stages, while one runs. */
222
+ stages?: SizeKeyStages;
223
+ zIndex?: number;
224
+ visible?: boolean;
225
+ }
226
+ /**
227
+ * A frame's size keys, one {@link sizeLegend} per key at its place in the stack, each blending to
228
+ * its far end's scale while `stages` is given. Keys are kept by position in the stack.
229
+ *
230
+ * @internal
231
+ */
232
+ export declare const sizeKeyStack: import("@sophistry/core").Definition<SizeKeyStackProps, import("@sophistry/core/internal").CompositeNode<SizeKeyStackProps>, keyof SizeKeyStackProps>;
233
+ export {};
@@ -0,0 +1,133 @@
1
+ /**
2
+ * `breadcrumbs`: a trail of names for a drill-down, and the trail a zoomable
3
+ * hierarchy chart draws for its own `breadcrumbs` prop.
4
+ *
5
+ * A trail is a handful of words, each its own tap target and tab stop, so
6
+ * every crumb, separator and the back control stay `label` nodes (keyed by
7
+ * the crumb's path, so a crumb cross-fading through a zoom keeps its node).
8
+ */
9
+ import type { SceneNode } from "@sophistry/core";
10
+ import type { Point } from "@sophistry/core/geometry";
11
+ import type { HierarchyPathSpec } from "../math/breadcrumbs.js";
12
+ import type { HierarchyNodeInfo } from "../math/hierarchy.js";
13
+ import type { HierarchyBreadcrumbOptions, HierarchyDrill } from "./drill.js";
14
+ import type { ResolvedFocus } from "./shared.js";
15
+ /** @category Charts */
16
+ export interface BreadcrumbsProps {
17
+ /**
18
+ * The trail: names below the root (`[]` is the root alone), or a `{ from, to, t }` transition
19
+ * such as {@link createDrillDown}'s `focus`, so the crumbs follow a zoom.
20
+ */
21
+ path: HierarchyPathSpec;
22
+ /**
23
+ * The root crumb's text.
24
+ * @default "All"
25
+ */
26
+ root?: string;
27
+ /**
28
+ * Anchor x.
29
+ * @default 0
30
+ */
31
+ x?: number;
32
+ /**
33
+ * Anchor y (the text's vertical middle).
34
+ * @default 0
35
+ */
36
+ y?: number;
37
+ /**
38
+ * Where the anchor is on the trail.
39
+ * @default "left"
40
+ */
41
+ align?: "left" | "center" | "right";
42
+ /**
43
+ * Font size.
44
+ * @default 0.24
45
+ */
46
+ fontSize?: number;
47
+ /**
48
+ * Drawn between crumbs.
49
+ * @default "›"
50
+ */
51
+ separator?: string;
52
+ /**
53
+ * The widest the trail may be: a deeper path collapses its middle into one `…` crumb (tap it to
54
+ * climb), keeping the root and as many last crumbs as fit. Omitted, the trail never collapses.
55
+ */
56
+ maxWidth?: number;
57
+ /**
58
+ * The collapsed crumbs' text.
59
+ * @default "…"
60
+ */
61
+ ellipsis?: string;
62
+ /**
63
+ * A back control before the root crumb: `true` for `"←"`, or its text. With `onSelect`, tapping
64
+ * it asks for the parent of the node in focus; it fades out at the root. Defaults to none.
65
+ */
66
+ back?: boolean | string;
67
+ /** The last crumb's colour (the node in focus). Defaults to the theme foreground. */
68
+ color?: string;
69
+ /** The other crumbs' colour, marking them as tappable. Defaults to the theme accent. */
70
+ linkColor?: string;
71
+ /**
72
+ * Called with a crumb's path when an earlier crumb is tapped (or Enter is pressed on it).
73
+ * Without it the crumbs are not interactive.
74
+ */
75
+ onSelect?: (path: string[]) => void;
76
+ /**
77
+ * Reveal, 0..1: the trail fades in.
78
+ * @default 1
79
+ */
80
+ progress?: number;
81
+ /** Paint order; higher draws later. */
82
+ zIndex?: number;
83
+ /**
84
+ * Set to `false` to hide the trail.
85
+ * @default true
86
+ */
87
+ visible?: boolean;
88
+ }
89
+ /**
90
+ * A breadcrumb trail for a drill-down: the root's name, then each name on the path to the node
91
+ * in focus. Tap (or Enter on) an earlier crumb to go back up; Escape asks for the parent. Give
92
+ * it the same `path` as a hierarchy chart's `focus` and it scrubs with the zoom. The hierarchy
93
+ * charts draw one themselves with their `breadcrumbs` prop.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { createScene } from "@sophistry/core";
98
+ * import { breadcrumbs, createDrillDown } from "@sophistry/charts";
99
+ *
100
+ * const scene = createScene({ host: document.querySelector("#figure")!, units: 10 });
101
+ * const zoom = createDrillDown({ clock: scene.clock });
102
+ * breadcrumbs.create({ path: zoom.focus, root: "repo", x: -4, y: 2.4, onSelect: (path) => void zoom.zoomTo(path) });
103
+ * ```
104
+ *
105
+ * @see https://sophistry.dev/reference/chart-catalogue/#hierarchies
106
+ * @category Charts
107
+ */
108
+ export declare const breadcrumbs: import("@sophistry/core").Definition<BreadcrumbsProps, import("@sophistry/core/internal").CompositeNode<BreadcrumbsProps>, keyof BreadcrumbsProps>;
109
+ /** Where a chart's trail goes and how wide it may grow. @internal */
110
+ export interface ChartBreadcrumbsFrame<T> {
111
+ options: boolean | HierarchyBreadcrumbOptions | undefined;
112
+ nodes: readonly HierarchyNodeInfo<T>[];
113
+ resolved: ResolvedFocus;
114
+ drill: HierarchyDrill<T>;
115
+ /** The chart's top-left corner, in scene units. */
116
+ corner: Point;
117
+ /** The chart's width: how wide the trail may grow by default. */
118
+ width: number;
119
+ /** The chart's label font size. */
120
+ labelFontSize: number;
121
+ progress?: number;
122
+ zIndex?: number;
123
+ visible?: boolean;
124
+ }
125
+ /**
126
+ * The trail a zoomable hierarchy chart draws for its `breadcrumbs` prop: its
127
+ * focus as names, just above the chart's top-left unless placed, collapsing
128
+ * past the chart's width. Call once, in `setup`; the result hands back the
129
+ * trail's node (made the first time it is asked for), or null for none.
130
+ *
131
+ * @internal
132
+ */
133
+ export declare function createChartBreadcrumbs<T>(): (frame: ChartBreadcrumbsFrame<T>) => SceneNode | null;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `circlePack`: every leaf a disc, packed inside its parent's circle.
3
+ *
4
+ * Every circle is one `circle` instance of one instances node, keyed by the
5
+ * node's path of names, with its own fill, fill opacity and stroke (groups
6
+ * are tinted and outlined, leaves filled); per-node picking, tooltips and
7
+ * drilling go through `event.item`. Circles grow from their centres
8
+ * (radius). While zoomed, the node and the leaf names sit in
9
+ * a `group` clipped to the root's disc. Names are `label` nodes, one per
10
+ * leaf whose name fits.
11
+ */
12
+ import type { Point } from "@sophistry/core/geometry";
13
+ import type { RequiredUnless } from "../data/channels.js";
14
+ import type { HierarchyDrillProps } from "./drill.js";
15
+ import type { HierarchyChartBaseProps, HierarchyFocusSpec, HierarchyTransitionProps } from "./shared.js";
16
+ /** @category Charts */
17
+ export interface CirclePackBaseProps<T> extends HierarchyChartBaseProps<T>, HierarchyTransitionProps<T>, HierarchyDrillProps<T> {
18
+ /** Centre of the chart. Defaults to the origin. */
19
+ center?: Point;
20
+ /**
21
+ * Radius of the root circle.
22
+ * @default 1
23
+ */
24
+ radius?: number;
25
+ /**
26
+ * Gap between sibling circles and their parent's rim.
27
+ * @default 0.03
28
+ */
29
+ padding?: number;
30
+ /**
31
+ * Draw the root's circle.
32
+ * @default true
33
+ */
34
+ root?: boolean;
35
+ /**
36
+ * Zoom into a node: its circle grows to fill the root's while the rest fades away along a
37
+ * smooth zoom path. A path of names below the root (`["a"]`), a predicate, or `{ from, to, t }`
38
+ * for a scrubbable transition. Given, the chart is controlled: taps only call `onFocusChange`.
39
+ * Defaults to the root.
40
+ */
41
+ focus?: HierarchyFocusSpec<T>;
42
+ }
43
+ /**
44
+ * Props of {@link circlePack}: `value` is required unless the tree's nodes are numbers.
45
+ *
46
+ * @category Charts
47
+ */
48
+ export type CirclePackProps<T> = CirclePackBaseProps<T> & RequiredUnless<T, number, "value">;
49
+ /**
50
+ * Circle packing: every leaf a disc with area proportional to its value, packed inside its
51
+ * parent's circle. Draws in scene units; circles grow from their centres, parents first.
52
+ * Supports drill-down `focus` and keyed transitions. The circles are one instances node
53
+ * (`event.item` picks a circle). See {@link packLayout} for the layout alone.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { circlePack } from "@sophistry/charts";
58
+ *
59
+ * const files = {
60
+ * name: "repo",
61
+ * children: [
62
+ * { name: "src", children: [{ name: "index.ts", size: 12 }, { name: "chart.ts", size: 30 }] },
63
+ * { name: "README.md", size: 4 },
64
+ * ],
65
+ * };
66
+ * circlePack.create({ data: files, value: "size", label: "name", radius: 2, drill: true });
67
+ * ```
68
+ *
69
+ * @see https://sophistry.dev/reference/chart-catalogue/#hierarchies
70
+ * @category Charts
71
+ */
72
+ export declare const circlePack: import("@sophistry/core").Definition<CirclePackBaseProps<any>, import("@sophistry/core/internal").CompositeNode<CirclePackBaseProps<any>>, keyof CirclePackBaseProps<any>>;
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Tap-to-drill for the zoomable hierarchy charts (`treemap`, `icicle`,
3
+ * `sunburst`, `circlePack`, `tree`): {@link createDrillDown}, which turns
4
+ * "zoom to this node" into a tweened, scrubbable `{ from, to, t }` focus,
5
+ * plus the drill props the charts share and the interaction a chart's
6
+ * batched node carries.
7
+ *
8
+ * The drill-down is plain tracks (`focus` and `path` are `Readable`s a chart
9
+ * prop binds to) and its zoom runs on a clock it is given. A chart without
10
+ * a controlled `focus` keeps one of its own on its scene's clock.
11
+ *
12
+ * A chart's nodes are one batched node, so the chart is one tab stop whose
13
+ * nodes the arrow keys walk (the accessibility layer's item list): Enter or
14
+ * Space taps the current node (drilling as a tap does), Escape zooms out one
15
+ * level (`aria-keyshortcuts="Escape"`). The item list walks every drawn node.
16
+ */
17
+ import type { Clock, CompositeContext, Easing, KeyboardBehaviour, PlayResult, Readable, ReducedMotion, ScenePointerEvent, Track } from "@sophistry/core";
18
+ import type { Point } from "@sophistry/core/geometry";
19
+ import type { HierarchyPathSpec } from "../math/breadcrumbs.js";
20
+ import type { HierarchyNodeInfo } from "../math/hierarchy.js";
21
+ import type { TooltipSpec, TooltipState } from "../tooltip.js";
22
+ import type { HierarchyFocusSpec, ResolvedFocus } from "./shared.js";
23
+ /**
24
+ * How a drill-down zoom animates.
25
+ *
26
+ * @category Charts
27
+ */
28
+ export interface DrillOptions {
29
+ /** Length of the zoom, in seconds. @default 0.75 */
30
+ duration?: number;
31
+ /** Easing of the zoom. @default "smooth" */
32
+ easing?: Easing;
33
+ }
34
+ /**
35
+ * Options for {@link createDrillDown}.
36
+ *
37
+ * @category Charts
38
+ */
39
+ export interface DrillDownOptions extends DrillOptions {
40
+ /** The path in focus at first. Defaults to the root. @default [] */
41
+ initial?: readonly string[];
42
+ /**
43
+ * The clock the zoom's tween runs on: pass the scene's (`scene.clock`) so
44
+ * it pauses and steps with it. @default defaultClock
45
+ */
46
+ clock?: Clock;
47
+ /**
48
+ * Whether the zoom reduces motion (jumps to its end): `"auto"` defers to
49
+ * the clock, a `Readable` answers live (a scene's own setting).
50
+ * @default "auto"
51
+ */
52
+ reducedMotion?: ReducedMotion | Readable<boolean>;
53
+ /** Called just before a reduced-motion zoom jumps to its end. */
54
+ onReducedJump?: () => void;
55
+ }
56
+ /**
57
+ * A drill-down's state: where it is going and the tween getting it there.
58
+ * Returned by {@link createDrillDown}.
59
+ *
60
+ * @category Charts
61
+ */
62
+ export interface DrillDown {
63
+ /**
64
+ * The focus to hand to a chart (and to {@link breadcrumbs}): a transition
65
+ * from the view when the last zoom started to {@link DrillDown.path}. A
66
+ * `Readable`: pass it as the chart's `focus` prop and the chart follows.
67
+ */
68
+ readonly focus: Readable<HierarchyPathSpec>;
69
+ /** Where the drill-down is (or is going): names below the root. */
70
+ readonly path: Readable<readonly string[]>;
71
+ /** The last zoom's 0..1 track; set or scrub it to replay that zoom. */
72
+ readonly t: Track<number>;
73
+ /**
74
+ * Zooms to the node at `path` from the view on screen now, interrupting any
75
+ * running zoom. Resolves `"done"`, or `"aborted"` if replaced; a no-op when
76
+ * already there. Hand it straight to a chart's `onFocusChange` or a trail's
77
+ * `onSelect`.
78
+ */
79
+ zoomTo(path: readonly string[]): Promise<PlayResult>;
80
+ /** Zooms out one level, to the parent of {@link DrillDown.path}. */
81
+ zoomOut(): Promise<PlayResult>;
82
+ }
83
+ /**
84
+ * Animated, scrubbable drill-down for a zoomable hierarchy chart. Pass
85
+ * `focus` to the chart (and to {@link breadcrumbs}), and `zoomTo` to the
86
+ * chart's `onFocusChange`; every frame is a pure function of the track `t`.
87
+ * Give it the scene's clock so the zoom runs with the scene.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { createScene } from "@sophistry/core";
92
+ * import { createDrillDown, treemap } from "@sophistry/charts";
93
+ *
94
+ * const scene = createScene({ host: document.querySelector("#figure")!, units: 10 });
95
+ * const files = {
96
+ * name: "repo",
97
+ * children: [
98
+ * { name: "src", children: [{ name: "index.ts", size: 12 }, { name: "chart.ts", size: 30 }] },
99
+ * { name: "README.md", size: 4 },
100
+ * ],
101
+ * };
102
+ * const zoom = createDrillDown({ clock: scene.clock });
103
+ * scene.add(
104
+ * treemap.create({
105
+ * data: files,
106
+ * value: "size",
107
+ * label: "name",
108
+ * width: 8,
109
+ * height: 4,
110
+ * focus: zoom.focus,
111
+ * onFocusChange: (path) => void zoom.zoomTo(path),
112
+ * }),
113
+ * );
114
+ * ```
115
+ *
116
+ * @see https://sophistry.dev/reference/chart-catalogue/#hierarchies
117
+ * @category Charts
118
+ */
119
+ export declare function createDrillDown(options?: DrillDownOptions): DrillDown;
120
+ /**
121
+ * A breadcrumb trail drawn by a zoomable hierarchy chart itself (its
122
+ * `breadcrumbs` prop), by default just above the chart's top-left corner.
123
+ *
124
+ * @category Charts
125
+ */
126
+ export interface HierarchyBreadcrumbOptions {
127
+ /** The root crumb's text. Defaults to the root's `label`, else `"All"`. */
128
+ root?: string;
129
+ /** Where the trail starts (its left end, vertically centred). */
130
+ at?: Point;
131
+ /** Font size. Defaults to the chart's label size + 0.04. */
132
+ fontSize?: number;
133
+ /**
134
+ * The widest the trail may be before its middle collapses into `…`;
135
+ * `false` never collapses. Defaults to the chart's width.
136
+ */
137
+ maxWidth?: number | false;
138
+ /**
139
+ * A back control before the trail (`true` for `"←"`, or its text) that zooms
140
+ * out one level.
141
+ * @default false
142
+ */
143
+ back?: boolean | string;
144
+ }
145
+ /**
146
+ * Tap-to-drill props shared by `treemap`, `icicle`, `sunburst`, `circlePack`
147
+ * and `tree`. Uncontrolled (`drill`, no `focus`), the chart keeps its own
148
+ * focus and tweens to tapped nodes; controlled (`focus` + `onFocusChange`),
149
+ * a tap only calls `onFocusChange`. A tap on the focused node zooms out,
150
+ * on a parent zooms in, on a leaf zooms to its parent; Enter and Space tap
151
+ * the node the arrow keys are on, Escape zooms out. Focus is by name path,
152
+ * so keep sibling labels unique.
153
+ *
154
+ * @see https://sophistry.dev/reference/chart-catalogue/#hierarchies
155
+ * @category Charts
156
+ */
157
+ export interface HierarchyDrillProps<T> {
158
+ /**
159
+ * Tap or Enter on a node to zoom to it: `true`, or the zoom's timing.
160
+ * Defaults to true when `onFocusChange` is given, else false.
161
+ */
162
+ drill?: boolean | DrillOptions;
163
+ /** Called when a tap or breadcrumb asks to zoom, with the path below the root and that node's datum. */
164
+ onFocusChange?: (path: string[], datum: NoInfer<T>) => void;
165
+ /** The uncontrolled focus at first: a path of names below the root. Defaults to the root. */
166
+ defaultFocus?: readonly string[];
167
+ /** Draw a breadcrumb trail of the focus path above the chart; tap a crumb to zoom out to it. */
168
+ breadcrumbs?: boolean | HierarchyBreadcrumbOptions;
169
+ }
170
+ /** The drill prop keys every zoomable hierarchy chart declares. */
171
+ export declare const DRILL_PROP_KEYS: readonly ["drill", "onFocusChange", "defaultFocus", "breadcrumbs", "focus"];
172
+ /** A chart's drill-down state on one update: the focus to draw and how to ask for a new one. @internal */
173
+ export interface HierarchyDrill<T> {
174
+ /** The focus to draw. */
175
+ focus: HierarchyFocusSpec<T> | undefined;
176
+ /** Whether taps drill. */
177
+ enabled: boolean;
178
+ /** Whether asking to zoom does anything (uncontrolled, or someone listens). */
179
+ canSelect: boolean;
180
+ /** Asks to zoom to the node at `position` of the current layout. */
181
+ select(position: number): void;
182
+ /** Asks to zoom to a path. */
183
+ selectPath(path: readonly string[]): void;
184
+ }
185
+ /** The props {@link createHierarchyDrill} reads. */
186
+ type DrillChartProps<T> = HierarchyDrillProps<T> & {
187
+ focus?: HierarchyFocusSpec<T>;
188
+ };
189
+ /**
190
+ * A chart's drill-down: its `focus`, `drill`, `onFocusChange` and
191
+ * `defaultFocus` props resolved, with the uncontrolled focus kept on the
192
+ * scene's clock. The chart reruns its `update` while its own zoom runs.
193
+ * Call once, in `setup`; call the result in every update.
194
+ *
195
+ * @internal
196
+ */
197
+ export declare function createHierarchyDrill<T, P extends DrillChartProps<T>>(ctx: CompositeContext<P>): (props: DrillChartProps<T>, nodes: readonly HierarchyNodeInfo<T>[]) => HierarchyDrill<T>;
198
+ /** What a chart's node interaction reads on each event: the latest update's state. @internal */
199
+ export interface NodeInteractionState<T> {
200
+ /** The chart's tooltip. */
201
+ tooltip: TooltipState;
202
+ /** The chart's `tooltip` prop. */
203
+ spec: TooltipSpec<T> | undefined;
204
+ /** The whole layout. */
205
+ nodes: readonly HierarchyNodeInfo<T>[];
206
+ /** The node the zoom is heading for. */
207
+ target: number;
208
+ /** The resolved focus: no tooltip opens while it moves. */
209
+ resolved: ResolvedFocus;
210
+ drill: HierarchyDrill<T>;
211
+ /** A batched item's position in the whole layout, or undefined. */
212
+ positionOf(item: number): number | undefined;
213
+ /** Where a batched item's tooltip points, in scene units. */
214
+ atOf(item: number): Point | undefined;
215
+ }
216
+ /** The interaction props a hierarchy chart's batched node carries. @internal */
217
+ export interface NodeInteractionProps {
218
+ label?: string;
219
+ itemLabel?: (item: number) => string | undefined;
220
+ onEnter?: (event: ScenePointerEvent) => void;
221
+ onLeave?: (event: ScenePointerEvent) => void;
222
+ onTap?: (event: ScenePointerEvent) => void;
223
+ keyboard?: KeyboardBehaviour;
224
+ cursor?: string;
225
+ }
226
+ /** A chart's node interaction: see {@link createNodeInteraction}. @internal */
227
+ export interface NodeInteraction {
228
+ /**
229
+ * The props to spread into the batched node's shared props (empty when
230
+ * neither drilling nor tooltips are on), naming the node `name`.
231
+ */
232
+ props(name: string): NodeInteractionProps;
233
+ /** Taps the node at layout `position` (its tooltip pointing at `at`), as a tap on its item does. */
234
+ tapNode(position: number, at: Point): void;
235
+ }
236
+ /**
237
+ * The interaction of a hierarchy chart's batched node (tooltip, drilling
238
+ * tap, Escape, cursor, each node's accessible name), made once so the
239
+ * handlers' identities hold across updates. `stateOf` hands back the latest
240
+ * update's state. Call once, in `setup`.
241
+ *
242
+ * @internal
243
+ */
244
+ export declare function createNodeInteraction<T>(stateOf: () => NodeInteractionState<T>): NodeInteraction;
245
+ export {};