react-cheminfo 0.14.0 → 0.16.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 (207) hide show
  1. package/README.md +175 -21
  2. package/lib/about/core/about.d.ts +13 -7
  3. package/lib/about/core/about.d.ts.map +1 -1
  4. package/lib/about/core/about.js +4 -2
  5. package/lib/about/core/about.js.map +1 -1
  6. package/lib/about/ui/AboutBuild.d.ts +20 -0
  7. package/lib/about/ui/AboutBuild.d.ts.map +1 -0
  8. package/lib/about/ui/AboutBuild.js +38 -0
  9. package/lib/about/ui/AboutBuild.js.map +1 -0
  10. package/lib/about/ui/AboutPage.d.ts +7 -0
  11. package/lib/about/ui/AboutPage.d.ts.map +1 -1
  12. package/lib/about/ui/AboutPage.js +5 -2
  13. package/lib/about/ui/AboutPage.js.map +1 -1
  14. package/lib/about/ui/index.d.ts +2 -0
  15. package/lib/about/ui/index.d.ts.map +1 -1
  16. package/lib/about/ui/index.js +1 -0
  17. package/lib/about/ui/index.js.map +1 -1
  18. package/lib/build/core/buildInfo.d.ts +39 -0
  19. package/lib/build/core/buildInfo.d.ts.map +1 -0
  20. package/lib/build/core/buildInfo.js +20 -0
  21. package/lib/build/core/buildInfo.js.map +1 -0
  22. package/lib/build/core/current.d.ts +12 -0
  23. package/lib/build/core/current.d.ts.map +1 -0
  24. package/lib/build/core/current.js +11 -0
  25. package/lib/build/core/current.js.map +1 -0
  26. package/lib/build/core/index.d.ts +3 -0
  27. package/lib/build/core/index.d.ts.map +1 -0
  28. package/lib/build/core/index.js +2 -0
  29. package/lib/build/core/index.js.map +1 -0
  30. package/lib/build/vite/buildInfo.d.ts +57 -0
  31. package/lib/build/vite/buildInfo.d.ts.map +1 -0
  32. package/lib/build/vite/buildInfo.js +151 -0
  33. package/lib/build/vite/buildInfo.js.map +1 -0
  34. package/lib/build/vite/gitHead.d.ts +29 -0
  35. package/lib/build/vite/gitHead.d.ts.map +1 -0
  36. package/lib/build/vite/gitHead.js +102 -0
  37. package/lib/build/vite/gitHead.js.map +1 -0
  38. package/lib/build/vite/index.d.ts +4 -0
  39. package/lib/build/vite/index.d.ts.map +1 -0
  40. package/lib/build/vite/index.js +3 -0
  41. package/lib/build/vite/index.js.map +1 -0
  42. package/lib/build-info.d.ts +3 -0
  43. package/lib/build-info.d.ts.map +1 -0
  44. package/lib/build-info.js +2 -0
  45. package/lib/build-info.js.map +1 -0
  46. package/lib/core.d.ts +2 -0
  47. package/lib/core.d.ts.map +1 -1
  48. package/lib/core.js +2 -0
  49. package/lib/core.js.map +1 -1
  50. package/lib/credits/core/credits.d.ts +35 -0
  51. package/lib/credits/core/credits.d.ts.map +1 -1
  52. package/lib/credits/core/credits.js +41 -0
  53. package/lib/credits/core/credits.js.map +1 -1
  54. package/lib/ecosystem/core/sites.d.ts.map +1 -1
  55. package/lib/ecosystem/core/sites.js +40 -0
  56. package/lib/ecosystem/core/sites.js.map +1 -1
  57. package/lib/ecosystem/core/types.d.ts +1 -1
  58. package/lib/ecosystem/core/types.d.ts.map +1 -1
  59. package/lib/ecosystem/ui/Wordmark.d.ts +14 -3
  60. package/lib/ecosystem/ui/Wordmark.d.ts.map +1 -1
  61. package/lib/ecosystem/ui/Wordmark.js +8 -4
  62. package/lib/ecosystem/ui/Wordmark.js.map +1 -1
  63. package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
  64. package/lib/ecosystem/ui/glyphs.js +11 -0
  65. package/lib/ecosystem/ui/glyphs.js.map +1 -1
  66. package/lib/parallel/core/index.d.ts +27 -0
  67. package/lib/parallel/core/index.d.ts.map +1 -0
  68. package/lib/parallel/core/index.js +20 -0
  69. package/lib/parallel/core/index.js.map +1 -0
  70. package/lib/parallel/core/parallelAxes.d.ts +103 -0
  71. package/lib/parallel/core/parallelAxes.d.ts.map +1 -0
  72. package/lib/parallel/core/parallelAxes.js +146 -0
  73. package/lib/parallel/core/parallelAxes.js.map +1 -0
  74. package/lib/parallel/core/parallelBrush.d.ts +79 -0
  75. package/lib/parallel/core/parallelBrush.d.ts.map +1 -0
  76. package/lib/parallel/core/parallelBrush.js +99 -0
  77. package/lib/parallel/core/parallelBrush.js.map +1 -0
  78. package/lib/parallel/core/parallelExtent.d.ts +28 -0
  79. package/lib/parallel/core/parallelExtent.d.ts.map +1 -0
  80. package/lib/parallel/core/parallelExtent.js +47 -0
  81. package/lib/parallel/core/parallelExtent.js.map +1 -0
  82. package/lib/parallel/core/parallelFilter.d.ts +36 -0
  83. package/lib/parallel/core/parallelFilter.d.ts.map +1 -0
  84. package/lib/parallel/core/parallelFilter.js +74 -0
  85. package/lib/parallel/core/parallelFilter.js.map +1 -0
  86. package/lib/parallel/core/parallelHit.d.ts +47 -0
  87. package/lib/parallel/core/parallelHit.d.ts.map +1 -0
  88. package/lib/parallel/core/parallelHit.js +81 -0
  89. package/lib/parallel/core/parallelHit.js.map +1 -0
  90. package/lib/parallel/core/parallelPaint.d.ts +104 -0
  91. package/lib/parallel/core/parallelPaint.d.ts.map +1 -0
  92. package/lib/parallel/core/parallelPaint.js +160 -0
  93. package/lib/parallel/core/parallelPaint.js.map +1 -0
  94. package/lib/parallel/core/parallelPalette.d.ts +31 -0
  95. package/lib/parallel/core/parallelPalette.d.ts.map +1 -0
  96. package/lib/parallel/core/parallelPalette.js +68 -0
  97. package/lib/parallel/core/parallelPalette.js.map +1 -0
  98. package/lib/parallel/core/parallelTicks.d.ts +34 -0
  99. package/lib/parallel/core/parallelTicks.d.ts.map +1 -0
  100. package/lib/parallel/core/parallelTicks.js +116 -0
  101. package/lib/parallel/core/parallelTicks.js.map +1 -0
  102. package/lib/parallel/core/parallelTypes.d.ts +129 -0
  103. package/lib/parallel/core/parallelTypes.d.ts.map +1 -0
  104. package/lib/parallel/core/parallelTypes.js +29 -0
  105. package/lib/parallel/core/parallelTypes.js.map +1 -0
  106. package/lib/parallel/ui/ParallelAxesLayer.d.ts +28 -0
  107. package/lib/parallel/ui/ParallelAxesLayer.d.ts.map +1 -0
  108. package/lib/parallel/ui/ParallelAxesLayer.js +29 -0
  109. package/lib/parallel/ui/ParallelAxesLayer.js.map +1 -0
  110. package/lib/parallel/ui/ParallelCoordinates.d.ts +21 -0
  111. package/lib/parallel/ui/ParallelCoordinates.d.ts.map +1 -0
  112. package/lib/parallel/ui/ParallelCoordinates.js +109 -0
  113. package/lib/parallel/ui/ParallelCoordinates.js.map +1 -0
  114. package/lib/parallel/ui/ParallelLabels.d.ts +26 -0
  115. package/lib/parallel/ui/ParallelLabels.d.ts.map +1 -0
  116. package/lib/parallel/ui/ParallelLabels.js +25 -0
  117. package/lib/parallel/ui/ParallelLabels.js.map +1 -0
  118. package/lib/parallel/ui/ParallelTooltip.d.ts +26 -0
  119. package/lib/parallel/ui/ParallelTooltip.d.ts.map +1 -0
  120. package/lib/parallel/ui/ParallelTooltip.js +30 -0
  121. package/lib/parallel/ui/ParallelTooltip.js.map +1 -0
  122. package/lib/parallel/ui/index.d.ts +25 -0
  123. package/lib/parallel/ui/index.d.ts.map +1 -0
  124. package/lib/parallel/ui/index.js +18 -0
  125. package/lib/parallel/ui/index.js.map +1 -0
  126. package/lib/parallel/ui/parallelCoordinatesProps.d.ts +185 -0
  127. package/lib/parallel/ui/parallelCoordinatesProps.d.ts.map +1 -0
  128. package/lib/parallel/ui/parallelCoordinatesProps.js +11 -0
  129. package/lib/parallel/ui/parallelCoordinatesProps.js.map +1 -0
  130. package/lib/parallel/ui/parallelGestureModel.d.ts +52 -0
  131. package/lib/parallel/ui/parallelGestureModel.d.ts.map +1 -0
  132. package/lib/parallel/ui/parallelGestureModel.js +80 -0
  133. package/lib/parallel/ui/parallelGestureModel.js.map +1 -0
  134. package/lib/parallel/ui/parallelInk.d.ts +76 -0
  135. package/lib/parallel/ui/parallelInk.d.ts.map +1 -0
  136. package/lib/parallel/ui/parallelInk.js +113 -0
  137. package/lib/parallel/ui/parallelInk.js.map +1 -0
  138. package/lib/parallel/ui/parallelPlotModel.d.ts +55 -0
  139. package/lib/parallel/ui/parallelPlotModel.d.ts.map +1 -0
  140. package/lib/parallel/ui/parallelPlotModel.js +113 -0
  141. package/lib/parallel/ui/parallelPlotModel.js.map +1 -0
  142. package/lib/parallel/ui/parallelStyles.d.ts +83 -0
  143. package/lib/parallel/ui/parallelStyles.d.ts.map +1 -0
  144. package/lib/parallel/ui/parallelStyles.js +131 -0
  145. package/lib/parallel/ui/parallelStyles.js.map +1 -0
  146. package/lib/parallel/ui/useParallelCanvas.d.ts +49 -0
  147. package/lib/parallel/ui/useParallelCanvas.d.ts.map +1 -0
  148. package/lib/parallel/ui/useParallelCanvas.js +58 -0
  149. package/lib/parallel/ui/useParallelCanvas.js.map +1 -0
  150. package/lib/parallel/ui/useParallelGesture.d.ts +67 -0
  151. package/lib/parallel/ui/useParallelGesture.d.ts.map +1 -0
  152. package/lib/parallel/ui/useParallelGesture.js +139 -0
  153. package/lib/parallel/ui/useParallelGesture.js.map +1 -0
  154. package/lib/structure/ui/useToolbarFloor.d.ts.map +1 -1
  155. package/lib/structure/ui/useToolbarFloor.js +29 -22
  156. package/lib/structure/ui/useToolbarFloor.js.map +1 -1
  157. package/lib/ui.d.ts +1 -0
  158. package/lib/ui.d.ts.map +1 -1
  159. package/lib/ui.js +1 -0
  160. package/lib/ui.js.map +1 -1
  161. package/lib/vite.d.ts +1 -0
  162. package/lib/vite.d.ts.map +1 -1
  163. package/lib/vite.js +1 -0
  164. package/lib/vite.js.map +1 -1
  165. package/package.json +2 -1
  166. package/src/about/core/about.ts +18 -9
  167. package/src/about/ui/AboutBuild.tsx +83 -0
  168. package/src/about/ui/AboutPage.tsx +15 -7
  169. package/src/about/ui/index.ts +2 -0
  170. package/src/build/core/buildInfo.ts +48 -0
  171. package/src/build/core/current.ts +12 -0
  172. package/src/build/core/index.ts +2 -0
  173. package/src/build/vite/buildInfo.ts +178 -0
  174. package/src/build/vite/gitHead.ts +114 -0
  175. package/src/build/vite/index.ts +8 -0
  176. package/src/build-info.ts +2 -0
  177. package/src/core.ts +2 -0
  178. package/src/credits/core/credits.ts +42 -0
  179. package/src/ecosystem/core/sites.ts +40 -0
  180. package/src/ecosystem/core/types.ts +4 -1
  181. package/src/ecosystem/ui/Wordmark.tsx +22 -7
  182. package/src/ecosystem/ui/glyphs.tsx +46 -0
  183. package/src/parallel/core/index.ts +80 -0
  184. package/src/parallel/core/parallelAxes.ts +207 -0
  185. package/src/parallel/core/parallelBrush.ts +145 -0
  186. package/src/parallel/core/parallelExtent.ts +56 -0
  187. package/src/parallel/core/parallelFilter.ts +94 -0
  188. package/src/parallel/core/parallelHit.ts +106 -0
  189. package/src/parallel/core/parallelPaint.ts +231 -0
  190. package/src/parallel/core/parallelPalette.ts +80 -0
  191. package/src/parallel/core/parallelTicks.ts +164 -0
  192. package/src/parallel/core/parallelTypes.ts +147 -0
  193. package/src/parallel/ui/ParallelAxesLayer.tsx +123 -0
  194. package/src/parallel/ui/ParallelCoordinates.tsx +233 -0
  195. package/src/parallel/ui/ParallelLabels.tsx +56 -0
  196. package/src/parallel/ui/ParallelTooltip.tsx +55 -0
  197. package/src/parallel/ui/index.ts +50 -0
  198. package/src/parallel/ui/parallelCoordinatesProps.ts +199 -0
  199. package/src/parallel/ui/parallelGestureModel.ts +109 -0
  200. package/src/parallel/ui/parallelInk.ts +182 -0
  201. package/src/parallel/ui/parallelPlotModel.ts +130 -0
  202. package/src/parallel/ui/parallelStyles.ts +146 -0
  203. package/src/parallel/ui/useParallelCanvas.ts +104 -0
  204. package/src/parallel/ui/useParallelGesture.ts +227 -0
  205. package/src/structure/ui/useToolbarFloor.ts +27 -22
  206. package/src/ui.ts +1 -0
  207. package/src/vite.ts +1 -0
@@ -0,0 +1,147 @@
1
+ /**
2
+ * What a parallel-coordinates figure is asked to draw: one axis per column,
3
+ * the intervals the reader brushed on them, and the quantity the lines are
4
+ * coloured by.
5
+ *
6
+ * The figure itself is index-based — every axis hands over its column as an
7
+ * `ArrayLike<number>` read in place — so a repaint costs an indexed read per
8
+ * value rather than a call. {@link parallelAxisOf} is the one place a row type
9
+ * is named, and it is run once per data change rather than once per repaint.
10
+ */
11
+
12
+ import type { ColorScale } from '../../color/core/interpolate.ts';
13
+
14
+ /** How a value is placed along an axis. */
15
+ export type ParallelAxisScale = 'linear' | 'log';
16
+
17
+ /** One labelled graduation a caller writes itself. */
18
+ export interface ParallelTick {
19
+ /** Where it sits, in the axis's own units. */
20
+ value: number;
21
+ /** What is written beside it. */
22
+ label: string;
23
+ }
24
+
25
+ /** One vertical axis of a parallel-coordinates figure, and the column it draws. */
26
+ export interface ParallelAxis {
27
+ /**
28
+ * A stable key, which is how a brushed range is reported and how a caller
29
+ * names the axis the colour is read from. Never an index: axes are added and
30
+ * reordered, and a range keyed on a position outlives the axis it belonged
31
+ * to.
32
+ */
33
+ id: string;
34
+ /** What it is called, written over the axis. */
35
+ label: string;
36
+ /**
37
+ * Every row's value, in the figure's row order. Read in place — nothing is
38
+ * copied — so a `Float64Array` is the cheapest thing to pass.
39
+ */
40
+ values: ArrayLike<number>;
41
+ /**
42
+ * The two ends of the axis, low first. Left out, they are the column's own
43
+ * smallest and largest finite value, and a column with no spread at all is
44
+ * opened by half a unit on each side so that it still draws.
45
+ * @default undefined — the column's own range
46
+ */
47
+ domain?: readonly [number, number];
48
+ /**
49
+ * How values are placed between the ends. `log` needs a domain whose low end
50
+ * is above zero; a value at or below zero is pinned to the low end.
51
+ * @default 'linear'
52
+ */
53
+ scale?: ParallelAxisScale;
54
+ /**
55
+ * How a tick is written. Left out, the ticks carry as many decimals as the
56
+ * spacing needs.
57
+ * @default undefined
58
+ */
59
+ format?: (value: number) => string;
60
+ /**
61
+ * The graduations, written out by the caller — what a coded quantity needs,
62
+ * where `0`, `1`, `2` should read `none`, `low`, `high`.
63
+ * @default undefined — the figure graduates the axis itself
64
+ */
65
+ ticks?: readonly ParallelTick[];
66
+ /**
67
+ * Roughly how many graduations to aim for, when the figure picks them.
68
+ * @default 5
69
+ */
70
+ tickCount?: number;
71
+ /**
72
+ * Whether the ends are rounded outward to whole tick steps. Off, so the axis
73
+ * ends exactly on the data — a reader comparing two molecules on a drug
74
+ * score must see the best one touch the top of its axis, not float below a
75
+ * round number nothing reached.
76
+ * @default false
77
+ */
78
+ nice?: boolean;
79
+ /**
80
+ * The unit written after the axis name, e.g. `g/mol`.
81
+ * @default '' — nothing is written
82
+ */
83
+ unit?: string;
84
+ }
85
+
86
+ /** An interval kept on one axis, in that axis's own units, low first. */
87
+ export type ParallelRange = readonly [number, number];
88
+
89
+ /** Which rows a set of brushes keeps, keyed by axis id. */
90
+ export type ParallelRanges = Readonly<Record<string, ParallelRange | null>>;
91
+
92
+ /** How the lines are coloured. */
93
+ export interface ParallelColorBy {
94
+ /** The quantity read for each row, in the figure's row order. */
95
+ values: ArrayLike<number>;
96
+ /**
97
+ * The value at the low end of the ramp.
98
+ * @default the smallest finite value
99
+ */
100
+ min?: number;
101
+ /**
102
+ * The value at its high end.
103
+ * @default the largest finite value
104
+ */
105
+ max?: number;
106
+ /**
107
+ * The ramp, as the registry hands it over or as a plain list of colours.
108
+ * @default viridis — `resolveColorScale(DEFAULT_COLOR_SCALE_ID).scale`
109
+ */
110
+ scale?: ColorScale | readonly string[];
111
+ /**
112
+ * Whether the quantity is read on a base-10 logarithmic ramp.
113
+ * @default false
114
+ */
115
+ logarithmic?: boolean;
116
+ }
117
+
118
+ /** An axis described by the field to read off each row, rather than by its column. */
119
+ export type ParallelAxisSource<Row> = Omit<ParallelAxis, 'values'> & {
120
+ /**
121
+ * The value this axis reads off one row. Called once per row per data
122
+ * change, never per repaint.
123
+ */
124
+ readonly value: (row: Row) => number;
125
+ };
126
+
127
+ /**
128
+ * One axis built by reading a field off each row.
129
+ *
130
+ * The one place a row type is named: the figure itself reads numbers out of a
131
+ * typed array, so a repaint costs an indexed read rather than a call per
132
+ * value. Call it inside a `useMemo` keyed on the rows.
133
+ * @param rows - The rows, in the order the figure will index them.
134
+ * @param axis - The axis, with the field to read instead of its values.
135
+ * @returns The axis, with its values filled in.
136
+ */
137
+ export function parallelAxisOf<Row>(
138
+ rows: readonly Row[],
139
+ axis: ParallelAxisSource<Row>,
140
+ ): ParallelAxis {
141
+ const { value, ...rest } = axis;
142
+ const values = new Float64Array(rows.length);
143
+ for (let row = 0; row < rows.length; row++) {
144
+ values[row] = value(rows[row] as Row);
145
+ }
146
+ return { ...rest, values };
147
+ }
@@ -0,0 +1,123 @@
1
+ import type { ReactElement } from 'react';
2
+
3
+ import type { ParallelAxisLayout } from '../core/parallelAxes.ts';
4
+ import { PARALLEL_MARGIN, parallelValueToY } from '../core/parallelAxes.ts';
5
+ import type { ParallelBand } from '../core/parallelBrush.ts';
6
+ import { PARALLEL_BRUSH_HALF_WIDTH } from '../core/parallelBrush.ts';
7
+
8
+ import {
9
+ PARALLEL_HANDLE_HEIGHT,
10
+ PARALLEL_TICK_LABEL_INSET,
11
+ PARALLEL_TICK_LABEL_STYLE,
12
+ PARALLEL_TICK_LENGTH,
13
+ parallelBandStyle,
14
+ parallelHandleStyle,
15
+ } from './parallelStyles.ts';
16
+
17
+ /** What {@link ParallelAxesLayer} draws. */
18
+ export interface ParallelAxesLayerProps {
19
+ /** The axes, from left to right, already placed and graduated. */
20
+ layouts: readonly ParallelAxisLayout[];
21
+ /** Height of the drawing area, in pixels. */
22
+ innerHeight: number;
23
+ /** The band each axis carries right now, the one being dragged included. */
24
+ bands: ReadonlyMap<string, ParallelBand>;
25
+ /** The ink the axes, their ticks and their labels are drawn in. */
26
+ axisInk: string;
27
+ /** The ink a band is filled and outlined in. */
28
+ bandInk: string;
29
+ }
30
+
31
+ /**
32
+ * The axes, their graduations and the intervals brushed on them.
33
+ *
34
+ * Every axis carries a `data-parallel-brush` rectangle over the strip a press
35
+ * on it reaches, which nothing points at: one surface over the whole figure
36
+ * takes every event, so the rectangle exists to be found — by a test driving
37
+ * a drag, and by a reader's eye, which is the same thing.
38
+ * @param props - See {@link ParallelAxesLayerProps}.
39
+ * @returns The axes.
40
+ */
41
+ export function ParallelAxesLayer(props: ParallelAxesLayerProps): ReactElement {
42
+ const { layouts, innerHeight, bands, axisInk, bandInk } = props;
43
+ const stroke = { stroke: axisInk };
44
+
45
+ return (
46
+ <g
47
+ transform={`translate(${PARALLEL_MARGIN.left},${PARALLEL_MARGIN.top})`}
48
+ style={{ fill: axisInk }}
49
+ textAnchor="middle"
50
+ >
51
+ {layouts.map((layout) => {
52
+ const band = bands.get(layout.id) ?? null;
53
+ return (
54
+ <g
55
+ key={layout.id}
56
+ className="parallel-axis"
57
+ data-parallel-axis={layout.id}
58
+ transform={`translate(${layout.x},0)`}
59
+ >
60
+ <line y2={innerHeight} style={stroke} />
61
+ {layout.ticks.map((tick) => (
62
+ <g
63
+ key={tick.value}
64
+ transform={`translate(0,${parallelValueToY(tick.value, layout)})`}
65
+ >
66
+ <line x1={-PARALLEL_TICK_LENGTH} style={stroke} />
67
+ <text
68
+ x={-PARALLEL_TICK_LABEL_INSET}
69
+ dy="0.32em"
70
+ textAnchor="end"
71
+ style={PARALLEL_TICK_LABEL_STYLE}
72
+ >
73
+ {tick.label}
74
+ </text>
75
+ </g>
76
+ ))}
77
+ <rect
78
+ data-parallel-brush={layout.id}
79
+ x={-PARALLEL_BRUSH_HALF_WIDTH}
80
+ y={0}
81
+ width={PARALLEL_BRUSH_HALF_WIDTH * 2}
82
+ height={Math.max(0, innerHeight)}
83
+ fill="transparent"
84
+ pointerEvents="none"
85
+ />
86
+ {band === null ? null : <BrushBand band={band} ink={bandInk} />}
87
+ </g>
88
+ );
89
+ })}
90
+ </g>
91
+ );
92
+ }
93
+
94
+ function BrushBand(props: { band: ParallelBand; ink: string }): ReactElement {
95
+ const { band, ink } = props;
96
+ const height = Math.max(0, band.bottom - band.top);
97
+ const width = PARALLEL_BRUSH_HALF_WIDTH * 2;
98
+ return (
99
+ <g className="parallel-axis-band" pointerEvents="none">
100
+ <rect
101
+ x={-PARALLEL_BRUSH_HALF_WIDTH}
102
+ y={band.top}
103
+ width={width}
104
+ height={height}
105
+ style={parallelBandStyle(ink)}
106
+ />
107
+ <rect
108
+ x={-PARALLEL_BRUSH_HALF_WIDTH}
109
+ y={band.top - PARALLEL_HANDLE_HEIGHT / 2}
110
+ width={width}
111
+ height={PARALLEL_HANDLE_HEIGHT}
112
+ style={parallelHandleStyle(ink)}
113
+ />
114
+ <rect
115
+ x={-PARALLEL_BRUSH_HALF_WIDTH}
116
+ y={band.bottom - PARALLEL_HANDLE_HEIGHT / 2}
117
+ width={width}
118
+ height={PARALLEL_HANDLE_HEIGHT}
119
+ style={parallelHandleStyle(ink)}
120
+ />
121
+ </g>
122
+ );
123
+ }
@@ -0,0 +1,233 @@
1
+ import type { ReactElement } from 'react';
2
+ import { useMemo, useState } from 'react';
3
+
4
+ import { OverlayLayer } from '../../overlay/ui/OverlayLayer.tsx';
5
+ import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
6
+ import { PARALLEL_MARGIN, parallelAxisLayouts } from '../core/parallelAxes.ts';
7
+ import { parallelIncludedMask } from '../core/parallelFilter.ts';
8
+ import {
9
+ parallelColorSteps,
10
+ parallelPalette,
11
+ } from '../core/parallelPalette.ts';
12
+ import type {
13
+ ParallelAxis,
14
+ ParallelRange,
15
+ ParallelRanges,
16
+ } from '../core/parallelTypes.ts';
17
+
18
+ import { ParallelAxesLayer } from './ParallelAxesLayer.tsx';
19
+ import { ParallelLabels } from './ParallelLabels.tsx';
20
+ import { ParallelTooltip } from './ParallelTooltip.tsx';
21
+ import type { ParallelCoordinatesProps } from './parallelCoordinatesProps.ts';
22
+ import { useParallelInk } from './parallelInk.ts';
23
+ import {
24
+ parallelColorOf,
25
+ parallelFigureLabel,
26
+ parallelHighlightsOf,
27
+ parallelIsBrushed,
28
+ parallelRowCount,
29
+ } from './parallelPlotModel.ts';
30
+ import {
31
+ PARALLEL_SVG_STYLE,
32
+ parallelCanvasStyle,
33
+ parallelFigureStyle,
34
+ } from './parallelStyles.ts';
35
+ import { useParallelCanvas } from './useParallelCanvas.ts';
36
+ import { useParallelGesture } from './useParallelGesture.ts';
37
+
38
+ /** Height the figure takes when the caller names none. */
39
+ const DEFAULT_HEIGHT = 320;
40
+
41
+ /** The smallest drawing area the figure will lay out, in pixels. */
42
+ const SMALLEST_SIDE = 10;
43
+
44
+ /** No axis is brushed, shared so an uncontrolled figure never rebuilds it. */
45
+ const NO_RANGES: ParallelRanges = Object.freeze({});
46
+
47
+ /**
48
+ * One vertical axis per column, one line per row, and a brush on every axis.
49
+ *
50
+ * It is told nothing about what the rows are: a library of molecules, a set of
51
+ * runs and a table of measurements all arrive as one `ArrayLike<number>` per
52
+ * axis, read in place. The lines are painted into a canvas because ten
53
+ * thousand of them are not ten thousand elements; everything the reader points
54
+ * at, brushes or reads is SVG and HTML over the top.
55
+ *
56
+ * The brush reports on release, never while the band is being dragged, so a
57
+ * table filtering on the same intervals re-renders once per gesture. What it
58
+ * keeps is `parallelIncludedMask`, which that table should filter with — two
59
+ * definitions of "kept" is how a figure and the list under it come to disagree.
60
+ * @param props - See {@link ParallelCoordinatesProps}.
61
+ * @returns The figure, or what the caller asked to show in its place when
62
+ * there is nothing to draw.
63
+ */
64
+ export function ParallelCoordinates(
65
+ props: ParallelCoordinatesProps,
66
+ ): ReactElement {
67
+ const { axes, width, height = DEFAULT_HEIGHT, empty, overlay } = props;
68
+ const { selected, renderTooltip, renderAxisLabel } = props;
69
+ const { className, testId, ink: inkProp, label: given } = props;
70
+ const { ranges: ownedRanges, defaultRanges, included: givenMask } = props;
71
+ const { color: givenColor, colorAxis, onRangeChange: report } = props;
72
+ const { onRangePreview, hovered, onHoverChange, onRowClick } = props;
73
+ const count = parallelRowCount(axes, props.count);
74
+ const innerWidth = Math.max(
75
+ width - PARALLEL_MARGIN.left - PARALLEL_MARGIN.right,
76
+ SMALLEST_SIDE,
77
+ );
78
+ const innerHeight = Math.max(
79
+ height - PARALLEL_MARGIN.top - PARALLEL_MARGIN.bottom,
80
+ SMALLEST_SIDE,
81
+ );
82
+
83
+ const [ownRanges, setOwnRanges] = useState<ParallelRanges>(
84
+ defaultRanges ?? NO_RANGES,
85
+ );
86
+ const ranges = ownedRanges ?? ownRanges;
87
+
88
+ const layouts = useMemo(
89
+ () => parallelAxisLayouts(axes, count, innerWidth, innerHeight),
90
+ [axes, count, innerWidth, innerHeight],
91
+ );
92
+ const values = useMemo(() => columnsOf(axes), [axes]);
93
+ const { ink, ref: figure } = useParallelInk(inkProp);
94
+ const color = useMemo(
95
+ () => parallelColorOf(givenColor, colorAxis, axes),
96
+ [givenColor, colorAxis, axes],
97
+ );
98
+ const steps = useMemo(
99
+ () => (color === undefined ? null : parallelColorSteps(color, count)),
100
+ [color, count],
101
+ );
102
+ const palette = useMemo(
103
+ () => (color === undefined ? [] : parallelPalette(color.scale)),
104
+ [color],
105
+ );
106
+ const included = useMemo(() => {
107
+ if (givenMask !== undefined) return givenMask;
108
+ if (!parallelIsBrushed(axes, ranges)) return null;
109
+ return parallelIncludedMask(axes, ranges, count);
110
+ }, [givenMask, axes, ranges, count]);
111
+
112
+ function commitRange(axisId: string, range: ParallelRange | null): void {
113
+ if (ownedRanges === undefined) {
114
+ setOwnRanges((previous) => ({ ...previous, [axisId]: range }));
115
+ }
116
+ report?.(axisId, range);
117
+ }
118
+
119
+ const gesture = useParallelGesture({
120
+ layouts,
121
+ values,
122
+ count,
123
+ innerHeight,
124
+ included,
125
+ ranges,
126
+ onRangeChange: commitRange,
127
+ onRangePreview,
128
+ hovered,
129
+ onHoverChange,
130
+ onRowClick,
131
+ });
132
+
133
+ const highlights = useMemo(
134
+ () =>
135
+ parallelHighlightsOf(selected, gesture.hovered, ink.selection, ink.hover),
136
+ [selected, gesture.hovered, ink.selection, ink.hover],
137
+ );
138
+ const { lines: lineCanvas, marks: markCanvas } = useParallelCanvas({
139
+ width,
140
+ height,
141
+ layouts,
142
+ values,
143
+ count,
144
+ included,
145
+ steps,
146
+ palette,
147
+ highlights,
148
+ ink,
149
+ });
150
+
151
+ const label = given ?? parallelFigureLabel(axes, count);
152
+ const canvasStyle = parallelCanvasStyle(height);
153
+ const hover =
154
+ gesture.pointer === null || gesture.hovered < 0
155
+ ? null
156
+ : { index: gesture.hovered, ...gesture.pointer };
157
+
158
+ return (
159
+ <div
160
+ ref={figure}
161
+ className={joinClassNames('parallel-coordinates', className)}
162
+ style={parallelFigureStyle(height)}
163
+ data-testid={testId}
164
+ >
165
+ {count === 0 || layouts.length === 0 ? (
166
+ empty
167
+ ) : (
168
+ <>
169
+ <canvas
170
+ ref={lineCanvas}
171
+ className="parallel-coordinates-canvas"
172
+ style={canvasStyle}
173
+ />
174
+ <canvas
175
+ ref={markCanvas}
176
+ className="parallel-coordinates-canvas"
177
+ style={canvasStyle}
178
+ />
179
+ <svg
180
+ width={Math.max(0, width)}
181
+ height={Math.max(0, height)}
182
+ style={PARALLEL_SVG_STYLE}
183
+ role="img"
184
+ aria-label={label}
185
+ >
186
+ <ParallelAxesLayer
187
+ layouts={layouts}
188
+ innerHeight={innerHeight}
189
+ bands={gesture.bands}
190
+ axisInk={ink.axis}
191
+ bandInk={ink.selection}
192
+ />
193
+ <rect
194
+ x={0}
195
+ y={0}
196
+ width={Math.max(0, width)}
197
+ height={Math.max(0, height)}
198
+ fill="transparent"
199
+ onClick={gesture.onClick}
200
+ {...gesture.surface}
201
+ />
202
+ </svg>
203
+ <ParallelLabels
204
+ axes={axes}
205
+ layouts={layouts}
206
+ render={renderAxisLabel}
207
+ />
208
+ {hover === null || renderTooltip === undefined ? null : (
209
+ <ParallelTooltip
210
+ x={hover.x}
211
+ y={hover.y}
212
+ boxWidth={width}
213
+ boxHeight={height}
214
+ >
215
+ {renderTooltip(hover)}
216
+ </ParallelTooltip>
217
+ )}
218
+ </>
219
+ )}
220
+ {overlay === undefined ? null : (
221
+ <OverlayLayer width={width} busy={gesture.brushing}>
222
+ {overlay}
223
+ </OverlayLayer>
224
+ )}
225
+ </div>
226
+ );
227
+ }
228
+
229
+ function columnsOf(axes: readonly ParallelAxis[]): Array<ArrayLike<number>> {
230
+ const columns: Array<ArrayLike<number>> = [];
231
+ for (const axis of axes) columns.push(axis.values);
232
+ return columns;
233
+ }
@@ -0,0 +1,56 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+
3
+ import type { ParallelAxisLayout } from '../core/parallelAxes.ts';
4
+ import { PARALLEL_MARGIN } from '../core/parallelAxes.ts';
5
+ import type { ParallelAxis } from '../core/parallelTypes.ts';
6
+
7
+ import { PARALLEL_LABELS_STYLE, parallelLabelStyle } from './parallelStyles.ts';
8
+
9
+ /** What {@link ParallelLabels} writes. */
10
+ export interface ParallelLabelsProps {
11
+ /** The axes as the caller described them, for a caller's own renderer. */
12
+ axes: readonly ParallelAxis[];
13
+ /** The same axes, placed, so each name sits over its own axis. */
14
+ layouts: readonly ParallelAxisLayout[];
15
+ /**
16
+ * How a name is written. Left out, it is the label and the unit after it.
17
+ * @default undefined
18
+ */
19
+ render?: ((axis: ParallelAxis, index: number) => ReactNode) | undefined;
20
+ }
21
+
22
+ /**
23
+ * The axis names, as HTML over the figure.
24
+ *
25
+ * HTML rather than SVG text so that a name can carry a tooltip explaining what
26
+ * the axis measures. The layer lets every pointer event through and only the
27
+ * names themselves take it back, so a brush started under a name still starts.
28
+ * @param props - See {@link ParallelLabelsProps}.
29
+ * @returns The names.
30
+ */
31
+ export function ParallelLabels(props: ParallelLabelsProps): ReactElement {
32
+ const { axes, layouts, render } = props;
33
+
34
+ return (
35
+ <div className="parallel-coordinates-labels" style={PARALLEL_LABELS_STYLE}>
36
+ {layouts.map((layout, index) => {
37
+ const axis = axes[index];
38
+ return (
39
+ <div
40
+ key={layout.id}
41
+ className="parallel-axis-label"
42
+ style={parallelLabelStyle(PARALLEL_MARGIN.left + layout.x)}
43
+ >
44
+ {axis !== undefined && render !== undefined
45
+ ? render(axis, index)
46
+ : defaultLabel(layout)}
47
+ </div>
48
+ );
49
+ })}
50
+ </div>
51
+ );
52
+ }
53
+
54
+ function defaultLabel(layout: ParallelAxisLayout): string {
55
+ return layout.unit === '' ? layout.label : `${layout.label} (${layout.unit})`;
56
+ }
@@ -0,0 +1,55 @@
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import { useRef } from 'react';
3
+
4
+ import { useContainerSize } from '../../hooks/ui/useContainerSize.ts';
5
+ import { placeOverlayCard } from '../../overlay/core/placeOverlayCard.ts';
6
+
7
+ import { parallelTooltipStyle } from './parallelStyles.ts';
8
+
9
+ /** What {@link ParallelTooltip} shows, and where. */
10
+ export interface ParallelTooltipProps {
11
+ /** Where the pointer is, in pixels from the figure's left edge. */
12
+ x: number;
13
+ /** Where it is, in pixels from its top edge. */
14
+ y: number;
15
+ /** Width of the figure, so the card is flipped rather than clipped. */
16
+ boxWidth: number;
17
+ /** Its height. */
18
+ boxHeight: number;
19
+ /** What the card says, written by the caller. */
20
+ children: ReactNode;
21
+ }
22
+
23
+ /**
24
+ * The card over the row under the pointer.
25
+ *
26
+ * It measures itself and flips rather than being clipped, because a card that
27
+ * runs off the bottom right of a figure is exactly where a reader points last
28
+ * — and it never takes the pointer, so moving towards it never dismisses it by
29
+ * moving off the line underneath.
30
+ * @param props - See {@link ParallelTooltipProps}.
31
+ * @returns The card.
32
+ */
33
+ export function ParallelTooltip(props: ParallelTooltipProps): ReactElement {
34
+ const { x, y, boxWidth, boxHeight, children } = props;
35
+ const card = useRef<HTMLDivElement>(null);
36
+ const size = useContainerSize(card);
37
+ const placed = placeOverlayCard({
38
+ pointerX: x,
39
+ pointerY: y,
40
+ cardWidth: size.width,
41
+ cardHeight: size.height,
42
+ boxWidth,
43
+ boxHeight,
44
+ });
45
+
46
+ return (
47
+ <div
48
+ ref={card}
49
+ className="parallel-coordinates-tooltip"
50
+ style={parallelTooltipStyle(placed.left, placed.top)}
51
+ >
52
+ {children}
53
+ </div>
54
+ );
55
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * A parallel-coordinates figure the reader can interrogate: brush any axis to
3
+ * keep an interval of it, rest on a line for what is known about that row, and
4
+ * colour every line by whichever column answers the question being asked.
5
+ *
6
+ * Nothing here knows what the rows are. The same figure draws a library of
7
+ * molecules, a set of experimental runs and a table of measurements, which is
8
+ * why it is its own domain rather than part of the first viewer to want one.
9
+ */
10
+
11
+ export { ParallelAxesLayer } from './ParallelAxesLayer.tsx';
12
+ export type { ParallelAxesLayerProps } from './ParallelAxesLayer.tsx';
13
+ export { ParallelCoordinates } from './ParallelCoordinates.tsx';
14
+ export type {
15
+ ParallelCoordinatesProps,
16
+ ParallelHover,
17
+ ParallelInk,
18
+ } from './parallelCoordinatesProps.ts';
19
+ export type {
20
+ ParallelInkBinding,
21
+ ParallelInkValues,
22
+ ParallelTokenInk,
23
+ } from './parallelInk.ts';
24
+ export {
25
+ parallelInkFrom,
26
+ readParallelInk,
27
+ readParallelTokens,
28
+ useParallelInk,
29
+ } from './parallelInk.ts';
30
+ export { ParallelLabels } from './ParallelLabels.tsx';
31
+ export type { ParallelLabelsProps } from './ParallelLabels.tsx';
32
+ export {
33
+ parallelColorOf,
34
+ parallelFigureLabel,
35
+ parallelHighlightsOf,
36
+ parallelIsBrushed,
37
+ parallelRowCount,
38
+ } from './parallelPlotModel.ts';
39
+ export { ParallelTooltip } from './ParallelTooltip.tsx';
40
+ export type { ParallelTooltipProps } from './ParallelTooltip.tsx';
41
+ export type {
42
+ ParallelCanvasOptions,
43
+ ParallelCanvases,
44
+ } from './useParallelCanvas.ts';
45
+ export { useParallelCanvas } from './useParallelCanvas.ts';
46
+ export type {
47
+ ParallelGesture,
48
+ ParallelGestureOptions,
49
+ } from './useParallelGesture.ts';
50
+ export { useParallelGesture } from './useParallelGesture.ts';