@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,67 @@
1
+ /**
2
+ * The steps every zoomable hierarchy chart (`treemap`, `icicle`, `sunburst`,
3
+ * `circlePack`, `tree`) takes on an update before drawing: lay out (both
4
+ * ends of a keyed transition, joined at `blend`), key, colour, resolve the
5
+ * drill-down and the zoom window, close a tooltip the view moved away from.
6
+ * Each step is cached on its inputs (see `shared.ts`), so a `progress` frame
7
+ * re-lays out nothing and a zoom scrub only moves the window.
8
+ *
9
+ * Internal to the family.
10
+ */
11
+ import type { CompositeContext, SceneNode } from "@sophistry/core";
12
+ import type { Point } from "@sophistry/core/geometry";
13
+ import type { Theme } from "@sophistry/core/themes";
14
+ import type { HierarchyNodeInfo } from "../math/hierarchy.js";
15
+ import type { TooltipState } from "../tooltip.js";
16
+ import type { ChartBreadcrumbsFrame } from "./breadcrumbs.js";
17
+ import type { HierarchyDrill, HierarchyDrillProps, NodeInteractionProps } from "./drill.js";
18
+ import type { HierarchyChartBaseProps, HierarchyEnds, HierarchyFocusSpec, HierarchyTransitionProps, HierarchyView, HierarchyZoom, Joined } from "./shared.js";
19
+ /** The props the shared steps read. */
20
+ export type ZoomableChartProps<T> = HierarchyChartBaseProps<T> & HierarchyTransitionProps<T> & HierarchyDrillProps<T> & {
21
+ focus?: HierarchyFocusSpec<T>;
22
+ };
23
+ /** One update's shared state of a hierarchy chart. @internal */
24
+ export interface HierarchyChartFrame<T, N extends HierarchyNodeInfo<T>> {
25
+ ends: HierarchyEnds<N>;
26
+ /** The layout drawn: `data`'s, or both ends joined at `blend`. */
27
+ layout: readonly Joined<N>[];
28
+ /** Each node's identity (its path of names): the instance key of its mark. */
29
+ keys: readonly string[];
30
+ /** Each node's fill. */
31
+ fills: readonly string[];
32
+ drill: HierarchyDrill<T>;
33
+ zoom: HierarchyZoom;
34
+ /** The chart's tooltip: the enclosing chart's, else its own. */
35
+ tooltip: TooltipState;
36
+ /** Whether nodes take part in interaction (taps, tooltips, the item list). */
37
+ interactive: boolean;
38
+ }
39
+ /** How a chart turns its layout into the windows its zoom moves between. */
40
+ export interface HierarchyViewOptions<N> {
41
+ /** The window showing the subtree of the node at `position`. */
42
+ viewOf: (layout: readonly Joined<N>[], position: number) => HierarchyView;
43
+ /** How two windows blend. @default linear */
44
+ blend?: (a: HierarchyView, b: HierarchyView, t: number) => HierarchyView;
45
+ }
46
+ /** A hierarchy chart's shared machinery. See {@link createHierarchyChart}. @internal */
47
+ export interface HierarchyChart<T, N extends HierarchyNodeInfo<T>> {
48
+ /** Runs the shared steps for this update. */
49
+ frame(props: ZoomableChartProps<T>, theme: Theme, layoutOf: (data: T, end: "from" | "to") => N[], deps: readonly unknown[], view: HierarchyViewOptions<N>): HierarchyChartFrame<T, N>;
50
+ /**
51
+ * The batched node's interaction props for this update, named `name`;
52
+ * `positionOf` and `atOf` map a batched item to its node and tooltip anchor.
53
+ */
54
+ interaction(name: string, positionOf: (item: number) => number | undefined, atOf: (item: number) => Point | undefined): NodeInteractionProps;
55
+ /** Taps the node at layout `position`, as a tap on its item does (for a node's name). */
56
+ tapNode(position: number, at: Point): void;
57
+ /** The chart's own trail, or null for none. */
58
+ breadcrumbs(frame: Omit<ChartBreadcrumbsFrame<T>, "nodes" | "resolved" | "drill">): SceneNode | null;
59
+ }
60
+ /**
61
+ * A hierarchy chart's shared machinery: its layout cache, keys, fills,
62
+ * drill-down, zoom, tooltip and trail. Call once, in `setup`.
63
+ *
64
+ * @param fields - The numeric fields that place a node (for the keyed join).
65
+ * @internal
66
+ */
67
+ export declare function createHierarchyChart<T, N extends HierarchyNodeInfo<T>, P extends ZoomableChartProps<T>>(ctx: CompositeContext<P>, fields: readonly (keyof N & string)[]): HierarchyChart<T, N>;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `icicle`: the partition layout as rectangles, one band per depth.
3
+ *
4
+ * Every band is one `rect` instance of one instances node, keyed by the
5
+ * node's path of names; per-node picking, tooltips and drilling go through
6
+ * `event.item`. The level-by-level reveal grows each rectangle from its
7
+ * parent side (geometry). Names are `label` nodes, one per
8
+ * rectangle whose name fits.
9
+ */
10
+ import type { Point } from "@sophistry/core/geometry";
11
+ import type { RequiredUnless } from "../data/channels.js";
12
+ import type { HierarchyDrillProps } from "./drill.js";
13
+ import type { HierarchyChartBaseProps, HierarchyFocusSpec, HierarchyTransitionProps } from "./shared.js";
14
+ /** @category Charts */
15
+ export interface IcicleBaseProps<T> extends HierarchyChartBaseProps<T>, HierarchyTransitionProps<T>, HierarchyDrillProps<T> {
16
+ /** Width of the whole chart. */
17
+ width: number;
18
+ /** Height of the whole chart. */
19
+ height: number;
20
+ /** Centre of the chart. Defaults to the origin. */
21
+ center?: Point;
22
+ /**
23
+ * `"horizontal"`: the root is a column at the left, depth increasing to the right.
24
+ * `"vertical"`: the root is a row at the top, depth increasing downward.
25
+ * @default "horizontal"
26
+ */
27
+ orientation?: "horizontal" | "vertical";
28
+ /**
29
+ * Draw the root's band; `false` gives its room to the other levels.
30
+ * @default true
31
+ */
32
+ root?: boolean;
33
+ /**
34
+ * Gap left around each rectangle.
35
+ * @default 0.01
36
+ */
37
+ inset?: number;
38
+ /**
39
+ * Zoom into a node: it spans the whole breadth, its descendants fill the depth after it, and
40
+ * the rest fades away. A path of names below the root (`["a"]`), a predicate, or `{ from, to, t
41
+ * }` for a scrubbable transition. Given, the chart is controlled: taps only call
42
+ * `onFocusChange`. Defaults to the root.
43
+ */
44
+ focus?: HierarchyFocusSpec<T>;
45
+ }
46
+ /**
47
+ * Props of {@link icicle}: `value` is required unless the tree's nodes are numbers.
48
+ *
49
+ * @category Charts
50
+ */
51
+ export type IcicleProps<T> = IcicleBaseProps<T> & RequiredUnless<T, number, "value">;
52
+ /**
53
+ * An icicle chart: the partition layout as rectangles, one band per depth, each node spanning
54
+ * exactly its children, sized by value. Lays itself out in a `width × height` box; reveals one
55
+ * depth at a time from the root. Supports drill-down `focus` and keyed transitions. The
56
+ * rectangles are one instances node (`event.item` picks a node). See {@link partitionLayout} for
57
+ * the layout alone.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { icicle } from "@sophistry/charts";
62
+ *
63
+ * const files = {
64
+ * name: "repo",
65
+ * children: [
66
+ * { name: "src", children: [{ name: "index.ts", size: 12 }, { name: "chart.ts", size: 30 }] },
67
+ * { name: "README.md", size: 4 },
68
+ * ],
69
+ * };
70
+ * icicle.create({ data: files, value: "size", label: "name", width: 8, height: 4, orientation: "vertical" });
71
+ * ```
72
+ *
73
+ * @see https://sophistry.dev/reference/chart-catalogue/#hierarchies
74
+ * @category Charts
75
+ */
76
+ export declare const icicle: import("@sophistry/core").Definition<IcicleBaseProps<any>, import("@sophistry/core/internal").CompositeNode<IcicleBaseProps<any>>, keyof IcicleBaseProps<any>>;
@@ -0,0 +1,20 @@
1
+ /** Family barrel: hierarchy. Owned by its family; re-exported from the package entry. */
2
+ export type { BreadcrumbsProps } from "./breadcrumbs.js";
3
+ export { breadcrumbs } from "./breadcrumbs.js";
4
+ export type { CirclePackBaseProps, CirclePackProps } from "./circle-pack.js";
5
+ export { circlePack } from "./circle-pack.js";
6
+ export type { DrillDown, DrillDownOptions, DrillOptions, HierarchyBreadcrumbOptions, HierarchyDrillProps, } from "./drill.js";
7
+ export { createDrillDown } from "./drill.js";
8
+ export type { IcicleBaseProps, IcicleProps } from "./icicle.js";
9
+ export { icicle } from "./icicle.js";
10
+ export type { MosaicProps } from "./mosaic.js";
11
+ export { mosaic } from "./mosaic.js";
12
+ export type { SankeyBaseProps, SankeyProps } from "./sankey.js";
13
+ export { sankey } from "./sankey.js";
14
+ export type { HierarchyChartBaseProps, HierarchyFocus, HierarchyFocusSpec, HierarchyTransitionProps, HierarchyView, } from "./shared.js";
15
+ export type { SunburstBaseProps, SunburstProps } from "./sunburst.js";
16
+ export { sunburst } from "./sunburst.js";
17
+ export type { TreeProps } from "./tree.js";
18
+ export { tree } from "./tree.js";
19
+ export type { TreemapBaseProps, TreemapProps } from "./treemap.js";
20
+ export { treemap } from "./treemap.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Node names of the hierarchy, flow and mosaic charts: one `label` node per
3
+ * name drawn, keyed by its node (so a name moving through a transition
4
+ * keeps its node), and a text-width cache so fitting names on every frame
5
+ * of a reveal or zoom measures each string once. Internal to the family.
6
+ */
7
+ import type { CompositeContext, LabelProps, SceneNode } from "@sophistry/core";
8
+ import type { Theme } from "@sophistry/core/themes";
9
+ /** One label of a keyed list: its key and the label's props. */
10
+ export interface KeyedLabel {
11
+ key: unknown;
12
+ props: LabelProps;
13
+ }
14
+ /**
15
+ * Keyed `label` nodes for one list (`slot`): a node per key, created once
16
+ * and updated in place, disposed when its key leaves.
17
+ */
18
+ export declare function labelList<P>(ctx: CompositeContext<P>, slot: string, labels: readonly KeyedLabel[]): SceneNode[];
19
+ /**
20
+ * A text-width cache for one chart: `(text, fontSize, theme, weight?)` is
21
+ * `textWidth` at the theme's font, measured once per string and size.
22
+ * Call once, in `setup`.
23
+ */
24
+ export declare function createLabelMeasure(): (text: string, fontSize: number, theme: Theme, fontWeight?: number) => number;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * `mosaic`: a Marimekko chart, columns as wide as their share of the whole,
3
+ * split into segments as tall as each row's share within the column.
4
+ *
5
+ * Every segment is one `rect` instance of one instances node, keyed by its
6
+ * (column, row) pair; per-segment picking and tooltips go through
7
+ * `event.item`. Columns grow from the bottom edge (geometry).
8
+ * Segment and column names are `label` nodes, one per name that fits.
9
+ */
10
+ import type { ColorInput } from "@sophistry/core/color";
11
+ import type { Point } from "@sophistry/core/geometry";
12
+ import type { Channel, ColorChannel } from "../data/channels.js";
13
+ import type { MosaicKey } from "../math/mosaic.js";
14
+ import type { TooltipSpec } from "../tooltip.js";
15
+ /**
16
+ * Props of {@link mosaic}.
17
+ *
18
+ * @category Charts
19
+ */
20
+ export interface MosaicProps<T> {
21
+ /** Long-form table: one datum per (column, row, value); duplicate pairs sum. */
22
+ data: readonly T[];
23
+ /** The column category. Data with no category are skipped. */
24
+ x: Channel<T, MosaicKey>;
25
+ /** The segment (row) category. Data with no category are skipped. */
26
+ y: Channel<T, MosaicKey>;
27
+ /**
28
+ * The amount; negative and non-finite values count as 0. Omitted, every datum counts 1 (a
29
+ * contingency table of counts).
30
+ */
31
+ value?: Channel<T, number>;
32
+ /** Column order, left to right; unlisted categories follow. Defaults to first-seen order. */
33
+ columns?: readonly MosaicKey[];
34
+ /** Segment order, bottom to top; unlisted categories follow. Defaults to first-seen order. */
35
+ rows?: readonly MosaicKey[];
36
+ /** Width of the mosaic. */
37
+ width: number;
38
+ /** Height of the mosaic (column names hang below it). */
39
+ height: number;
40
+ /** Centre of the mosaic. Defaults to the origin. */
41
+ center?: Point;
42
+ /**
43
+ * Gap between columns, and between segments in a column.
44
+ * @default 0.04
45
+ */
46
+ padding?: number;
47
+ /**
48
+ * One colour for every segment, or `(d, i) => colour` called with the segment's first datum
49
+ * (returning nothing falls back to `colors`). Wins over `colors`.
50
+ */
51
+ color?: ColorChannel<T>;
52
+ /**
53
+ * Colours cycled across the row categories, so a row has one colour in every column. Defaults
54
+ * to the theme's categorical colours.
55
+ */
56
+ colors?: readonly ColorInput[];
57
+ /**
58
+ * Fill opacity of the segments, 0..1.
59
+ * @default 1
60
+ */
61
+ fillOpacity?: number;
62
+ /**
63
+ * Write each row's name inside its segment where it fits.
64
+ * @default true
65
+ */
66
+ labels?: boolean;
67
+ /**
68
+ * Write each column's name under it where it fits.
69
+ * @default true
70
+ */
71
+ columnLabels?: boolean;
72
+ /**
73
+ * Write each column's share of the total under its name.
74
+ * @default false
75
+ */
76
+ shares?: boolean;
77
+ /**
78
+ * Label font size.
79
+ * @default 0.2
80
+ */
81
+ labelFontSize?: number;
82
+ /**
83
+ * Reveal, 0..1: column names fade in first, then the columns grow left to right from the
84
+ * bottom, segment names fading in as they go.
85
+ * @default 1
86
+ * @see https://sophistry.dev/guides/chart-animation/#reveals
87
+ */
88
+ progress?: number;
89
+ /**
90
+ * Fraction of the columns' reveal spent staggering column after column, 0..0.95.
91
+ * @default 0.5
92
+ */
93
+ stagger?: number;
94
+ /**
95
+ * Hover tooltip on a segment: `true` for "column · row: value (pct% of column)", or `(d, i) =>
96
+ * string` called with its first datum.
97
+ */
98
+ tooltip?: TooltipSpec<T>;
99
+ /** Paint order; labels draw at `zIndex + 1`. */
100
+ zIndex?: number;
101
+ /**
102
+ * Set to `false` to hide the chart.
103
+ * @default true
104
+ */
105
+ visible?: boolean;
106
+ }
107
+ /**
108
+ * A mosaic (Marimekko) chart: columns whose widths are their share of the whole, split into
109
+ * segments whose heights are each row's share within the column, so every rectangle's area is
110
+ * its value. `data` is long-form, one datum per (column, row, value). Lays itself out in a
111
+ * `width × height` box; needs no `chart`. The segments are one instances node (`event.item`
112
+ * picks one). See {@link mosaicLayout} for the layout alone.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * import { mosaic } from "@sophistry/charts";
117
+ *
118
+ * const sales = [
119
+ * { region: "north", product: "tea", units: 30 },
120
+ * { region: "north", product: "coffee", units: 50 },
121
+ * { region: "south", product: "tea", units: 45 },
122
+ * { region: "south", product: "coffee", units: 15 },
123
+ * ];
124
+ * mosaic.create({ data: sales, x: "region", y: "product", value: "units", width: 8, height: 4, shares: true });
125
+ * ```
126
+ *
127
+ * @see https://sophistry.dev/reference/chart-catalogue/#gauges-bullets-waffles-mosaics-and-radial-bars
128
+ * @category Charts
129
+ */
130
+ export declare const mosaic: import("@sophistry/core").Definition<MosaicProps<any>, import("@sophistry/core/internal").CompositeNode<MosaicProps<any>>, keyof MosaicProps<any>>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The tooltip a standalone hierarchy, flow or mosaic chart shows through:
3
+ * the enclosing chart's, else its own. Internal to the family.
4
+ *
5
+ * Outside a chart the state is kept (handlers, accessible names, the item
6
+ * walked by the keys) but no panel is drawn yet: the overlay is the chart
7
+ * frame's (`frame/tooltip-overlay.ts`).
8
+ */
9
+ import type { CompositeContext } from "@sophistry/core";
10
+ import type { TooltipState } from "../tooltip.js";
11
+ /** Call once, in `setup`; read the result in each `update`. */
12
+ export declare function createOwnTooltip(): <P>(ctx: CompositeContext<P>) => TooltipState;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The props descriptor the zoomable hierarchy charts share: every base,
3
+ * transition and drill prop reruns `update`, plus each chart's own. Internal
4
+ * to the family.
5
+ */
6
+ import type { PropsDescriptor } from "@sophistry/core";
7
+ /**
8
+ * A hierarchy chart's props descriptor: the shared keys and `own`, each
9
+ * rerunning `update` when written (`progress` defaults to 1).
10
+ *
11
+ * @internal
12
+ */
13
+ export declare function hierarchyPropsDescriptor<P extends object>(own: readonly (keyof P & string)[]): PropsDescriptor<P>;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * `sankey`: quantities flowing between stages.
3
+ *
4
+ * The flows are one path batch: each ribbon a closed ring with its own fill
5
+ * (its source's, target's or own colour), the fill opacity shared; per-flow
6
+ * picking and tooltips go through `event.item`. The node bars are `rect`
7
+ * instances of one instances node, keyed by node id. The left-to-right draw
8
+ * of a flow cuts its ring (`sankeyRibbon`'s `t`). Node names
9
+ * are `label` nodes placed beside their bars: outside the diagram for the first and last
10
+ * columns, right of the bar (with a halo over the flows) for the others.
11
+ */
12
+ import type { ColorInput } from "@sophistry/core/color";
13
+ import type { Point } from "@sophistry/core/geometry";
14
+ import type { Channel, ColorChannel, RequiredUnless } from "../data/channels.js";
15
+ import type { SankeyAlign, SankeyId } from "../math/sankey.js";
16
+ import type { TooltipSpec } from "../tooltip.js";
17
+ /** @category Charts */
18
+ export interface SankeyBaseProps<L, N> {
19
+ /** The flows: one ribbon per datum. */
20
+ data: readonly L[];
21
+ /** The node a flow leaves. */
22
+ source: Channel<L, SankeyId>;
23
+ /** The node a flow enters. */
24
+ target: Channel<L, SankeyId>;
25
+ /** The flow's size; non-finite and negative values draw nothing. */
26
+ value: Channel<L, number>;
27
+ /**
28
+ * The nodes, in the order they are stacked and coloured. Every id a link names must be here
29
+ * (else throws). Defaults to the links' endpoints in first-seen order.
30
+ */
31
+ nodes?: readonly N[];
32
+ /**
33
+ * A node's id, matched against `source`/`target`. Defaults to the datum itself, when `nodes` is
34
+ * `(string | number)[]`.
35
+ */
36
+ nodeId?: Channel<N, SankeyId>;
37
+ /** The text beside a node. Defaults to its id. */
38
+ nodeLabel?: Channel<N, string>;
39
+ /** Width of the diagram, nodes included; labels may overhang it. */
40
+ width: number;
41
+ /** Height of the diagram. */
42
+ height: number;
43
+ /** Centre of the diagram. Defaults to the origin. */
44
+ center?: Point;
45
+ /**
46
+ * Width of each node bar.
47
+ * @default 0.2
48
+ */
49
+ nodeWidth?: number;
50
+ /**
51
+ * Gap between nodes in a column.
52
+ * @default 0.2
53
+ */
54
+ nodePadding?: number;
55
+ /**
56
+ * How nodes are assigned to columns; see {@link SankeyAlign}.
57
+ * @default "justify"
58
+ */
59
+ align?: SankeyAlign;
60
+ /**
61
+ * Relaxation passes of the layout.
62
+ * @default 6
63
+ */
64
+ iterations?: number;
65
+ /** Node colours, cycled by node order. Defaults to the theme's categorical colours. */
66
+ colors?: readonly ColorInput[];
67
+ /**
68
+ * A flow's colour: its `"source"` node's, its `"target"` node's, or a colour channel of its
69
+ * own.
70
+ * @default "source"
71
+ */
72
+ linkColor?: "source" | "target" | ColorChannel<L>;
73
+ /**
74
+ * Fill opacity of the flows, 0..1.
75
+ * @default 0.35
76
+ */
77
+ linkOpacity?: number;
78
+ /**
79
+ * Draw node labels.
80
+ * @default true
81
+ */
82
+ labels?: boolean;
83
+ /**
84
+ * Font size of node labels.
85
+ * @default 0.24
86
+ */
87
+ labelFontSize?: number;
88
+ /**
89
+ * Reveal, 0..1: nodes appear column by column, then the flows draw left to right.
90
+ * @default 1
91
+ * @see https://sophistry.dev/guides/chart-animation/#reveals
92
+ */
93
+ progress?: number;
94
+ /**
95
+ * Hover tooltip: `true` shows "A → B: value" on a flow and "name: value" on a node; a function
96
+ * replaces the flow text.
97
+ */
98
+ tooltip?: TooltipSpec<L>;
99
+ /** Paint order of the flows; nodes paint above them. */
100
+ zIndex?: number;
101
+ visible?: boolean;
102
+ }
103
+ /**
104
+ * Props of {@link sankey}: `nodeId` is required when `nodes` holds records.
105
+ *
106
+ * @category Charts
107
+ */
108
+ export type SankeyProps<L, N = SankeyId> = SankeyBaseProps<L, N> & RequiredUnless<N, SankeyId, "nodeId">;
109
+ /**
110
+ * A Sankey diagram: quantities flowing between stages, each flow a ribbon as thick as its
111
+ * value, each node a bar as tall as what passes through it. Lays itself out in a
112
+ * `width × height` box; needs no `chart`. A cycle in the links throws. The flows are one path
113
+ * batch and the bars one instances node (`event.item` picks one). See {@link sankeyLayout} and
114
+ * {@link sankeyRibbon} for the geometry alone.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { sankey } from "@sophistry/charts";
119
+ *
120
+ * const flows = [
121
+ * { from: "coal", to: "electricity", twh: 40 },
122
+ * { from: "wind", to: "electricity", twh: 25 },
123
+ * { from: "electricity", to: "homes", twh: 35 },
124
+ * { from: "electricity", to: "industry", twh: 30 },
125
+ * ];
126
+ * sankey.create({ data: flows, source: "from", target: "to", value: "twh", width: 8, height: 4, tooltip: true });
127
+ * ```
128
+ *
129
+ * @see https://sophistry.dev/reference/chart-catalogue/#flows
130
+ * @category Charts
131
+ */
132
+ export declare const sankey: import("@sophistry/core").Definition<SankeyBaseProps<any, any>, import("@sophistry/core/internal").CompositeNode<SankeyBaseProps<any, any>>, keyof SankeyBaseProps<any, any>>;