react-cheminfo 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -0
- package/lib/core.d.ts +1 -0
- package/lib/core.d.ts.map +1 -1
- package/lib/core.js +1 -0
- package/lib/core.js.map +1 -1
- package/lib/credits/core/credits.d.ts +17 -0
- package/lib/credits/core/credits.d.ts.map +1 -1
- package/lib/credits/core/credits.js +20 -0
- package/lib/credits/core/credits.js.map +1 -1
- package/lib/ecosystem/core/sites.d.ts.map +1 -1
- package/lib/ecosystem/core/sites.js +40 -0
- package/lib/ecosystem/core/sites.js.map +1 -1
- package/lib/ecosystem/core/types.d.ts +1 -1
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +11 -0
- package/lib/ecosystem/ui/glyphs.js.map +1 -1
- package/lib/parallel/core/index.d.ts +29 -0
- package/lib/parallel/core/index.d.ts.map +1 -0
- package/lib/parallel/core/index.js +22 -0
- package/lib/parallel/core/index.js.map +1 -0
- package/lib/parallel/core/parallelAxes.d.ts +103 -0
- package/lib/parallel/core/parallelAxes.d.ts.map +1 -0
- package/lib/parallel/core/parallelAxes.js +146 -0
- package/lib/parallel/core/parallelAxes.js.map +1 -0
- package/lib/parallel/core/parallelBrush.d.ts +100 -0
- package/lib/parallel/core/parallelBrush.d.ts.map +1 -0
- package/lib/parallel/core/parallelBrush.js +149 -0
- package/lib/parallel/core/parallelBrush.js.map +1 -0
- package/lib/parallel/core/parallelExtent.d.ts +28 -0
- package/lib/parallel/core/parallelExtent.d.ts.map +1 -0
- package/lib/parallel/core/parallelExtent.js +47 -0
- package/lib/parallel/core/parallelExtent.js.map +1 -0
- package/lib/parallel/core/parallelFilter.d.ts +49 -0
- package/lib/parallel/core/parallelFilter.d.ts.map +1 -0
- package/lib/parallel/core/parallelFilter.js +107 -0
- package/lib/parallel/core/parallelFilter.js.map +1 -0
- package/lib/parallel/core/parallelHit.d.ts +47 -0
- package/lib/parallel/core/parallelHit.d.ts.map +1 -0
- package/lib/parallel/core/parallelHit.js +81 -0
- package/lib/parallel/core/parallelHit.js.map +1 -0
- package/lib/parallel/core/parallelOrder.d.ts +36 -0
- package/lib/parallel/core/parallelOrder.d.ts.map +1 -0
- package/lib/parallel/core/parallelOrder.js +65 -0
- package/lib/parallel/core/parallelOrder.js.map +1 -0
- package/lib/parallel/core/parallelPaint.d.ts +108 -0
- package/lib/parallel/core/parallelPaint.d.ts.map +1 -0
- package/lib/parallel/core/parallelPaint.js +169 -0
- package/lib/parallel/core/parallelPaint.js.map +1 -0
- package/lib/parallel/core/parallelPalette.d.ts +40 -0
- package/lib/parallel/core/parallelPalette.d.ts.map +1 -0
- package/lib/parallel/core/parallelPalette.js +81 -0
- package/lib/parallel/core/parallelPalette.js.map +1 -0
- package/lib/parallel/core/parallelSelection.d.ts +43 -0
- package/lib/parallel/core/parallelSelection.d.ts.map +1 -0
- package/lib/parallel/core/parallelSelection.js +87 -0
- package/lib/parallel/core/parallelSelection.js.map +1 -0
- package/lib/parallel/core/parallelTicks.d.ts +34 -0
- package/lib/parallel/core/parallelTicks.d.ts.map +1 -0
- package/lib/parallel/core/parallelTicks.js +119 -0
- package/lib/parallel/core/parallelTicks.js.map +1 -0
- package/lib/parallel/core/parallelTypes.d.ts +140 -0
- package/lib/parallel/core/parallelTypes.d.ts.map +1 -0
- package/lib/parallel/core/parallelTypes.js +29 -0
- package/lib/parallel/core/parallelTypes.js.map +1 -0
- package/lib/parallel/ui/ParallelAxesLayer.d.ts +28 -0
- package/lib/parallel/ui/ParallelAxesLayer.d.ts.map +1 -0
- package/lib/parallel/ui/ParallelAxesLayer.js +29 -0
- package/lib/parallel/ui/ParallelAxesLayer.js.map +1 -0
- package/lib/parallel/ui/ParallelCoordinates.d.ts +21 -0
- package/lib/parallel/ui/ParallelCoordinates.d.ts.map +1 -0
- package/lib/parallel/ui/ParallelCoordinates.js +114 -0
- package/lib/parallel/ui/ParallelCoordinates.js.map +1 -0
- package/lib/parallel/ui/ParallelLabels.d.ts +32 -0
- package/lib/parallel/ui/ParallelLabels.d.ts.map +1 -0
- package/lib/parallel/ui/ParallelLabels.js +37 -0
- package/lib/parallel/ui/ParallelLabels.js.map +1 -0
- package/lib/parallel/ui/ParallelTooltip.d.ts +26 -0
- package/lib/parallel/ui/ParallelTooltip.d.ts.map +1 -0
- package/lib/parallel/ui/ParallelTooltip.js +30 -0
- package/lib/parallel/ui/ParallelTooltip.js.map +1 -0
- package/lib/parallel/ui/index.d.ts +29 -0
- package/lib/parallel/ui/index.d.ts.map +1 -0
- package/lib/parallel/ui/index.js +20 -0
- package/lib/parallel/ui/index.js.map +1 -0
- package/lib/parallel/ui/parallelCoordinatesProps.d.ts +203 -0
- package/lib/parallel/ui/parallelCoordinatesProps.d.ts.map +1 -0
- package/lib/parallel/ui/parallelCoordinatesProps.js +11 -0
- package/lib/parallel/ui/parallelCoordinatesProps.js.map +1 -0
- package/lib/parallel/ui/parallelGestureModel.d.ts +83 -0
- package/lib/parallel/ui/parallelGestureModel.d.ts.map +1 -0
- package/lib/parallel/ui/parallelGestureModel.js +110 -0
- package/lib/parallel/ui/parallelGestureModel.js.map +1 -0
- package/lib/parallel/ui/parallelInk.d.ts +76 -0
- package/lib/parallel/ui/parallelInk.d.ts.map +1 -0
- package/lib/parallel/ui/parallelInk.js +113 -0
- package/lib/parallel/ui/parallelInk.js.map +1 -0
- package/lib/parallel/ui/parallelPlotModel.d.ts +55 -0
- package/lib/parallel/ui/parallelPlotModel.d.ts.map +1 -0
- package/lib/parallel/ui/parallelPlotModel.js +113 -0
- package/lib/parallel/ui/parallelPlotModel.js.map +1 -0
- package/lib/parallel/ui/parallelStyles.d.ts +106 -0
- package/lib/parallel/ui/parallelStyles.d.ts.map +1 -0
- package/lib/parallel/ui/parallelStyles.js +153 -0
- package/lib/parallel/ui/parallelStyles.js.map +1 -0
- package/lib/parallel/ui/useParallelAxisDrag.d.ts +60 -0
- package/lib/parallel/ui/useParallelAxisDrag.d.ts.map +1 -0
- package/lib/parallel/ui/useParallelAxisDrag.js +96 -0
- package/lib/parallel/ui/useParallelAxisDrag.js.map +1 -0
- package/lib/parallel/ui/useParallelCanvas.d.ts +49 -0
- package/lib/parallel/ui/useParallelCanvas.d.ts.map +1 -0
- package/lib/parallel/ui/useParallelCanvas.js +58 -0
- package/lib/parallel/ui/useParallelCanvas.js.map +1 -0
- package/lib/parallel/ui/useParallelGesture.d.ts +72 -0
- package/lib/parallel/ui/useParallelGesture.d.ts.map +1 -0
- package/lib/parallel/ui/useParallelGesture.js +164 -0
- package/lib/parallel/ui/useParallelGesture.js.map +1 -0
- package/lib/structure/ui/useToolbarFloor.d.ts.map +1 -1
- package/lib/structure/ui/useToolbarFloor.js +29 -22
- package/lib/structure/ui/useToolbarFloor.js.map +1 -1
- package/lib/ui.d.ts +1 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +1 -0
- package/lib/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/core.ts +1 -0
- package/src/credits/core/credits.ts +21 -0
- package/src/ecosystem/core/sites.ts +40 -0
- package/src/ecosystem/core/types.ts +4 -1
- package/src/ecosystem/ui/glyphs.tsx +46 -0
- package/src/parallel/core/index.ts +96 -0
- package/src/parallel/core/parallelAxes.ts +207 -0
- package/src/parallel/core/parallelBrush.ts +211 -0
- package/src/parallel/core/parallelExtent.ts +56 -0
- package/src/parallel/core/parallelFilter.ts +131 -0
- package/src/parallel/core/parallelHit.ts +106 -0
- package/src/parallel/core/parallelOrder.ts +73 -0
- package/src/parallel/core/parallelPaint.ts +242 -0
- package/src/parallel/core/parallelPalette.ts +93 -0
- package/src/parallel/core/parallelSelection.ts +99 -0
- package/src/parallel/core/parallelTicks.ts +168 -0
- package/src/parallel/core/parallelTypes.ts +159 -0
- package/src/parallel/ui/ParallelAxesLayer.tsx +129 -0
- package/src/parallel/ui/ParallelCoordinates.tsx +252 -0
- package/src/parallel/ui/ParallelLabels.tsx +77 -0
- package/src/parallel/ui/ParallelTooltip.tsx +55 -0
- package/src/parallel/ui/index.ts +65 -0
- package/src/parallel/ui/parallelCoordinatesProps.ts +217 -0
- package/src/parallel/ui/parallelGestureModel.ts +159 -0
- package/src/parallel/ui/parallelInk.ts +182 -0
- package/src/parallel/ui/parallelPlotModel.ts +130 -0
- package/src/parallel/ui/parallelStyles.ts +188 -0
- package/src/parallel/ui/useParallelAxisDrag.ts +147 -0
- package/src/parallel/ui/useParallelCanvas.ts +104 -0
- package/src/parallel/ui/useParallelGesture.ts +260 -0
- package/src/structure/ui/useToolbarFloor.ts +27 -22
- package/src/ui.ts +1 -0
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
import type { ParallelAxisDrag } from './useParallelAxisDrag.ts';
|
|
9
|
+
|
|
10
|
+
/** What {@link ParallelLabels} writes. */
|
|
11
|
+
export interface ParallelLabelsProps {
|
|
12
|
+
/** The axes as the caller described them, for a caller's own renderer. */
|
|
13
|
+
axes: readonly ParallelAxis[];
|
|
14
|
+
/** The same axes, placed, so each name sits over its own axis. */
|
|
15
|
+
layouts: readonly ParallelAxisLayout[];
|
|
16
|
+
/**
|
|
17
|
+
* How a name is written. Left out, it is the label and the unit after it.
|
|
18
|
+
* @default undefined
|
|
19
|
+
*/
|
|
20
|
+
render?: ((axis: ParallelAxis, index: number) => ReactNode) | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The gesture that moves an axis by its name.
|
|
23
|
+
* @default undefined — the axes are fixed
|
|
24
|
+
*/
|
|
25
|
+
drag?: ParallelAxisDrag | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The axis names, as HTML over the figure.
|
|
30
|
+
*
|
|
31
|
+
* HTML rather than SVG text so that a name can carry a tooltip explaining what
|
|
32
|
+
* the axis measures. The layer lets every pointer event through and only the
|
|
33
|
+
* names themselves take it back, so a brush started under a name still starts.
|
|
34
|
+
* @param props - See {@link ParallelLabelsProps}.
|
|
35
|
+
* @returns The names.
|
|
36
|
+
*/
|
|
37
|
+
export function ParallelLabels(props: ParallelLabelsProps): ReactElement {
|
|
38
|
+
const { axes, layouts, render, drag } = props;
|
|
39
|
+
const draggable = drag?.enabled ?? false;
|
|
40
|
+
const active = drag?.active ?? null;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="parallel-coordinates-labels" style={PARALLEL_LABELS_STYLE}>
|
|
44
|
+
{layouts.map((layout, index) => {
|
|
45
|
+
const axis = axes[index];
|
|
46
|
+
const moving = active !== null && active.from === index;
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
key={layout.id}
|
|
50
|
+
className="parallel-axis-label"
|
|
51
|
+
data-parallel-label={layout.id}
|
|
52
|
+
style={parallelLabelStyle({
|
|
53
|
+
left: PARALLEL_MARGIN.left + layout.x,
|
|
54
|
+
draggable,
|
|
55
|
+
dx: moving ? active.dx : null,
|
|
56
|
+
})}
|
|
57
|
+
{...drag?.propsFor(index)}
|
|
58
|
+
{...(draggable
|
|
59
|
+
? {
|
|
60
|
+
role: 'button',
|
|
61
|
+
'aria-label': `${layout.label}: move this axis with the left and right arrow keys`,
|
|
62
|
+
}
|
|
63
|
+
: null)}
|
|
64
|
+
>
|
|
65
|
+
{axis !== undefined && render !== undefined
|
|
66
|
+
? render(axis, index)
|
|
67
|
+
: defaultLabel(layout)}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
})}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function defaultLabel(layout: ParallelAxisLayout): string {
|
|
76
|
+
return layout.unit === '' ? layout.label : `${layout.label} (${layout.unit})`;
|
|
77
|
+
}
|
|
@@ -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,65 @@
|
|
|
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 type { ParallelCommit, ParallelDraft } from './parallelGestureModel.ts';
|
|
33
|
+
export {
|
|
34
|
+
parallelAxisById,
|
|
35
|
+
parallelAxisNear,
|
|
36
|
+
parallelBandsOf,
|
|
37
|
+
parallelCommitOf,
|
|
38
|
+
parallelPointOf,
|
|
39
|
+
} from './parallelGestureModel.ts';
|
|
40
|
+
export {
|
|
41
|
+
parallelColorOf,
|
|
42
|
+
parallelFigureLabel,
|
|
43
|
+
parallelHighlightsOf,
|
|
44
|
+
parallelIsBrushed,
|
|
45
|
+
parallelRowCount,
|
|
46
|
+
} from './parallelPlotModel.ts';
|
|
47
|
+
export { ParallelTooltip } from './ParallelTooltip.tsx';
|
|
48
|
+
export type { ParallelTooltipProps } from './ParallelTooltip.tsx';
|
|
49
|
+
export type {
|
|
50
|
+
ParallelCanvasOptions,
|
|
51
|
+
ParallelCanvases,
|
|
52
|
+
} from './useParallelCanvas.ts';
|
|
53
|
+
export { useParallelCanvas } from './useParallelCanvas.ts';
|
|
54
|
+
export type {
|
|
55
|
+
ParallelAxisDrag,
|
|
56
|
+
ParallelAxisDragOptions,
|
|
57
|
+
ParallelAxisDragState,
|
|
58
|
+
ParallelAxisHandleProps,
|
|
59
|
+
} from './useParallelAxisDrag.ts';
|
|
60
|
+
export { useParallelAxisDrag } from './useParallelAxisDrag.ts';
|
|
61
|
+
export type {
|
|
62
|
+
ParallelGesture,
|
|
63
|
+
ParallelGestureOptions,
|
|
64
|
+
} from './useParallelGesture.ts';
|
|
65
|
+
export { useParallelGesture } from './useParallelGesture.ts';
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a caller hands a `ParallelCoordinates`.
|
|
3
|
+
*
|
|
4
|
+
* The types the figure is *told* about — an axis, an interval, a colour ramp —
|
|
5
|
+
* live in `parallel/core`, because the same words describe the mask a table
|
|
6
|
+
* beside the figure filters on and the layout the painter reads. What is left
|
|
7
|
+
* here is what only a React component has: the render props, the inks a canvas
|
|
8
|
+
* cannot read off a stylesheet, and the controlled pairs.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { ReactNode } from 'react';
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
ParallelAxis,
|
|
15
|
+
ParallelColorBy,
|
|
16
|
+
ParallelRange,
|
|
17
|
+
ParallelRanges,
|
|
18
|
+
} from '../core/parallelTypes.ts';
|
|
19
|
+
|
|
20
|
+
/** What the pointer is over, and where. */
|
|
21
|
+
export interface ParallelHover {
|
|
22
|
+
/** The row, as an index into the axes' value arrays. */
|
|
23
|
+
index: number;
|
|
24
|
+
/** Where the pointer is, in pixels from the figure's left edge. */
|
|
25
|
+
x: number;
|
|
26
|
+
/** Where it is, in pixels from its top edge. */
|
|
27
|
+
y: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The colours a canvas is painted with, which cannot read a custom property. */
|
|
31
|
+
export interface ParallelInk {
|
|
32
|
+
/**
|
|
33
|
+
* The rows a brush left out, drawn under the rest.
|
|
34
|
+
* @default a light grey the dense mass can only converge on
|
|
35
|
+
*/
|
|
36
|
+
excluded?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The rows nothing is colouring, when no quantity was given.
|
|
39
|
+
* @default the value of `--text-muted` on the figure
|
|
40
|
+
*/
|
|
41
|
+
line?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The row under the pointer.
|
|
44
|
+
* @default the value of `--text` on the figure
|
|
45
|
+
*/
|
|
46
|
+
hover?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The rows singled out elsewhere — picked in a table, pinned by the reader.
|
|
49
|
+
* @default the value of `--accent` on the figure
|
|
50
|
+
*/
|
|
51
|
+
selection?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The halo a singled-out line is drawn over, so it reads against the mass.
|
|
54
|
+
* @default the value of `--surface`, at 85%
|
|
55
|
+
*/
|
|
56
|
+
halo?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The axis lines, their ticks and their labels.
|
|
59
|
+
* @default the value of `--text-muted`
|
|
60
|
+
*/
|
|
61
|
+
axis?: string;
|
|
62
|
+
/**
|
|
63
|
+
* How strongly a kept line is drawn. Turn it down for a dense library.
|
|
64
|
+
* @default 0.35
|
|
65
|
+
*/
|
|
66
|
+
includedAlpha?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** What `ParallelCoordinates` needs. */
|
|
70
|
+
export interface ParallelCoordinatesProps {
|
|
71
|
+
/** The axes, from left to right. Fewer than two draws no lines. */
|
|
72
|
+
axes: readonly ParallelAxis[];
|
|
73
|
+
/**
|
|
74
|
+
* How many rows to draw.
|
|
75
|
+
* @default the shortest axis's value count
|
|
76
|
+
*/
|
|
77
|
+
count?: number;
|
|
78
|
+
/** Total width, in pixels, normally from `useContainerSize`. */
|
|
79
|
+
width: number;
|
|
80
|
+
/**
|
|
81
|
+
* Total height, axis names and tick labels included.
|
|
82
|
+
* @default 320
|
|
83
|
+
*/
|
|
84
|
+
height?: number;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* What each axis keeps, keyed by axis id: one interval, several, or `null`.
|
|
88
|
+
* Present, the caller owns the brushes — which is what lets a table beside
|
|
89
|
+
* the figure filter on the same ranges. The band being dragged stays inside
|
|
90
|
+
* the component either way, so a controlled parent is never asked to
|
|
91
|
+
* re-render sixty times a second.
|
|
92
|
+
* @default undefined — the figure keeps its own
|
|
93
|
+
*/
|
|
94
|
+
ranges?: ParallelRanges;
|
|
95
|
+
/**
|
|
96
|
+
* The intervals in force before the reader touches anything.
|
|
97
|
+
* @default undefined — no axis is brushed
|
|
98
|
+
*/
|
|
99
|
+
defaultRanges?: ParallelRanges;
|
|
100
|
+
/**
|
|
101
|
+
* Whether one axis may keep several intervals at once — the light molecules
|
|
102
|
+
* and the heavy ones, with nothing in between. A reader brushes a second
|
|
103
|
+
* interval by dragging on a bare part of an axis that already carries one,
|
|
104
|
+
* and takes one away by clicking it.
|
|
105
|
+
* @default false — a new brush replaces the one the axis carried
|
|
106
|
+
*/
|
|
107
|
+
several?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Called when a brush is released, with every interval that axis now keeps —
|
|
110
|
+
* empty when the reader cleared it, and never while a band is being dragged.
|
|
111
|
+
* @default undefined
|
|
112
|
+
*/
|
|
113
|
+
onRangeChange?: (axisId: string, ranges: readonly ParallelRange[]) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Called on every frame a band grows, for a caption saying what letting go
|
|
116
|
+
* would keep. Nothing else should be wired to it.
|
|
117
|
+
* @default undefined
|
|
118
|
+
*/
|
|
119
|
+
onRangePreview?: (axisId: string, ranges: readonly ParallelRange[]) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Which rows the brushes keep, one entry per row, a zero meaning excluded.
|
|
122
|
+
* Left out, it is worked out from the ranges with `parallelIncludedMask`,
|
|
123
|
+
* which is exported so a table beside the figure filters on the same answer
|
|
124
|
+
* rather than on a second definition of "kept".
|
|
125
|
+
* @default undefined — worked out from the ranges
|
|
126
|
+
*/
|
|
127
|
+
included?: Uint8Array;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The row under the pointer, or `-1`. Present, the caller owns it, which is
|
|
131
|
+
* what lets a table hovered elsewhere light up its line here.
|
|
132
|
+
* @default undefined — the figure keeps its own
|
|
133
|
+
*/
|
|
134
|
+
hovered?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Called with the row under the pointer, or `-1`, whenever that changes.
|
|
137
|
+
* @default undefined
|
|
138
|
+
*/
|
|
139
|
+
onHoverChange?: (index: number) => void;
|
|
140
|
+
/**
|
|
141
|
+
* The rows singled out elsewhere, drawn over the mass in the selection ink.
|
|
142
|
+
* A row that is also the hovered one is drawn once, in the hover ink.
|
|
143
|
+
* @default undefined — nothing is singled out
|
|
144
|
+
*/
|
|
145
|
+
selected?: readonly number[];
|
|
146
|
+
/**
|
|
147
|
+
* Called when a line is clicked, with the row, or `-1` for empty ground.
|
|
148
|
+
* @default undefined — the lines are not clickable
|
|
149
|
+
*/
|
|
150
|
+
onRowClick?: (index: number) => void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The quantity the lines are coloured by.
|
|
154
|
+
* @default undefined — every line takes one ink
|
|
155
|
+
*/
|
|
156
|
+
color?: ParallelColorBy;
|
|
157
|
+
/**
|
|
158
|
+
* The id of the axis the lines are coloured by, for the common case where it
|
|
159
|
+
* is one of the axes already drawn. Ignored when `color` is given.
|
|
160
|
+
* @default undefined
|
|
161
|
+
*/
|
|
162
|
+
colorAxis?: string;
|
|
163
|
+
/**
|
|
164
|
+
* The canvas colours, merged over the ones read off the figure's own tokens.
|
|
165
|
+
* @default {}
|
|
166
|
+
*/
|
|
167
|
+
ink?: ParallelInk;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The card shown over the row under the pointer. It is placed by the figure,
|
|
171
|
+
* flipped rather than clipped at either edge, so a caller writes only what
|
|
172
|
+
* it says.
|
|
173
|
+
* @default undefined — no card is shown
|
|
174
|
+
*/
|
|
175
|
+
renderTooltip?: (hover: ParallelHover) => ReactNode;
|
|
176
|
+
/**
|
|
177
|
+
* How an axis is named. The default writes the label and its unit; a caller
|
|
178
|
+
* wraps it to hang a help tooltip off the name.
|
|
179
|
+
* @default the axis label, and its unit after it
|
|
180
|
+
*/
|
|
181
|
+
renderAxisLabel?: (axis: ParallelAxis, index: number) => ReactNode;
|
|
182
|
+
/**
|
|
183
|
+
* Called with the axis ids in the order the reader dragged them into.
|
|
184
|
+
* Present, every axis name becomes a handle: drag it, or focus it and press
|
|
185
|
+
* the left and right arrow keys. Two columns only show their relationship
|
|
186
|
+
* when they stand next to each other, so this is how a reader asks a
|
|
187
|
+
* different question of the same figure.
|
|
188
|
+
* @default undefined — the axes stand in the order the caller gave them
|
|
189
|
+
*/
|
|
190
|
+
onAxisOrder?: (ids: readonly string[]) => void;
|
|
191
|
+
/**
|
|
192
|
+
* What is shown in place of the figure when there is nothing to draw.
|
|
193
|
+
* @default undefined — an empty figure of the given height
|
|
194
|
+
*/
|
|
195
|
+
empty?: ReactNode;
|
|
196
|
+
/**
|
|
197
|
+
* What floats over the figure — a legend, a colour scale key, a caption.
|
|
198
|
+
* @default undefined
|
|
199
|
+
*/
|
|
200
|
+
overlay?: ReactNode;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* What a screen reader is told the figure shows.
|
|
204
|
+
* @default a sentence naming the axes and the row count
|
|
205
|
+
*/
|
|
206
|
+
label?: string;
|
|
207
|
+
/**
|
|
208
|
+
* A class for the figure's outermost element, for a site placing it.
|
|
209
|
+
* @default undefined
|
|
210
|
+
*/
|
|
211
|
+
className?: string;
|
|
212
|
+
/**
|
|
213
|
+
* Value of the `data-testid` attribute of the wrapper.
|
|
214
|
+
* @default undefined
|
|
215
|
+
*/
|
|
216
|
+
testId?: string;
|
|
217
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The questions the gesture asks that need neither React nor state: where a
|
|
3
|
+
* press landed, which axis it reached, and which band each axis should be
|
|
4
|
+
* drawn with once the one being dragged is taken into account.
|
|
5
|
+
*
|
|
6
|
+
* Kept out of the hook the way `lassoGesture.ts` is kept out of its own — each
|
|
7
|
+
* of these has exactly one answer, and none of them needs a render to be read.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { SurfaceEvent } from '../../scatter/ui/lassoGesture.ts';
|
|
11
|
+
import { surfacePosition } from '../../scatter/ui/lassoGesture.ts';
|
|
12
|
+
import type { ParallelAxisLayout } from '../core/parallelAxes.ts';
|
|
13
|
+
import { PARALLEL_MARGIN } from '../core/parallelAxes.ts';
|
|
14
|
+
import type { ParallelBand } from '../core/parallelBrush.ts';
|
|
15
|
+
import {
|
|
16
|
+
PARALLEL_BRUSH_HALF_WIDTH,
|
|
17
|
+
parallelBandOf,
|
|
18
|
+
parallelIsBand,
|
|
19
|
+
parallelRangeOf,
|
|
20
|
+
} from '../core/parallelBrush.ts';
|
|
21
|
+
import {
|
|
22
|
+
parallelRangeList,
|
|
23
|
+
parallelWriteRange,
|
|
24
|
+
} from '../core/parallelSelection.ts';
|
|
25
|
+
import type { ParallelRange, ParallelRanges } from '../core/parallelTypes.ts';
|
|
26
|
+
|
|
27
|
+
/** A band being dragged, before the interval it keeps is reported. */
|
|
28
|
+
export interface ParallelDraft {
|
|
29
|
+
/** The axis it is on. */
|
|
30
|
+
axis: string;
|
|
31
|
+
/** Which of that axis's bands it is, or `-1` when it is a new one. */
|
|
32
|
+
index: number;
|
|
33
|
+
/** Where it stands this frame. */
|
|
34
|
+
band: ParallelBand;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Where an event landed, relative to the top left of the drawing area.
|
|
39
|
+
* @param event - The event, for where on the surface it happened.
|
|
40
|
+
* @returns The position, in pixels from the corner of the drawing area.
|
|
41
|
+
*/
|
|
42
|
+
export function parallelPointOf(event: SurfaceEvent): {
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
} {
|
|
46
|
+
const position = surfacePosition(event, 0, 0);
|
|
47
|
+
return {
|
|
48
|
+
x: position.x - PARALLEL_MARGIN.left,
|
|
49
|
+
y: position.y - PARALLEL_MARGIN.top,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Which axis a press at that horizontal position took hold of.
|
|
55
|
+
* @param x - Pixels from the left of the drawing area.
|
|
56
|
+
* @param axes - The axes, from left to right.
|
|
57
|
+
* @returns The axis's index, or `-1` when the press landed between two of them.
|
|
58
|
+
*/
|
|
59
|
+
export function parallelAxisNear(
|
|
60
|
+
x: number,
|
|
61
|
+
axes: readonly ParallelAxisLayout[],
|
|
62
|
+
): number {
|
|
63
|
+
let nearest = -1;
|
|
64
|
+
let nearestDistance = PARALLEL_BRUSH_HALF_WIDTH;
|
|
65
|
+
for (let index = 0; index < axes.length; index++) {
|
|
66
|
+
const axis = axes[index];
|
|
67
|
+
if (axis === undefined) continue;
|
|
68
|
+
const distance = Math.abs(x - axis.x);
|
|
69
|
+
if (distance <= nearestDistance) {
|
|
70
|
+
nearestDistance = distance;
|
|
71
|
+
nearest = index;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return nearest;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* One axis, by the id a range is keyed on.
|
|
79
|
+
* @param axes - The axes, from left to right.
|
|
80
|
+
* @param axisId - The id to find.
|
|
81
|
+
* @returns The axis, or `undefined` when it is no longer drawn.
|
|
82
|
+
*/
|
|
83
|
+
export function parallelAxisById(
|
|
84
|
+
axes: readonly ParallelAxisLayout[],
|
|
85
|
+
axisId: string,
|
|
86
|
+
): ParallelAxisLayout | undefined {
|
|
87
|
+
for (const axis of axes) {
|
|
88
|
+
if (axis.id === axisId) return axis;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The bands to draw on each axis: the one being dragged where there is one,
|
|
95
|
+
* and the intervals in force everywhere else.
|
|
96
|
+
* @param axes - The axes, from left to right.
|
|
97
|
+
* @param ranges - What each axis keeps: one interval, several, or none.
|
|
98
|
+
* @param draft - The band being dragged, or `null` when nothing is.
|
|
99
|
+
* @returns The bands, keyed by axis id; an axis with none is left out. The
|
|
100
|
+
* band being dragged replaces the interval it came from rather than being
|
|
101
|
+
* drawn beside it, so an interval never appears twice mid-gesture.
|
|
102
|
+
*/
|
|
103
|
+
export function parallelBandsOf(
|
|
104
|
+
axes: readonly ParallelAxisLayout[],
|
|
105
|
+
ranges: ParallelRanges,
|
|
106
|
+
draft: ParallelDraft | null,
|
|
107
|
+
): ReadonlyMap<string, ParallelBand[]> {
|
|
108
|
+
const drawn = new Map<string, ParallelBand[]>();
|
|
109
|
+
for (const axis of axes) {
|
|
110
|
+
const list = parallelRangeList(ranges[axis.id]);
|
|
111
|
+
const dragging = draft !== null && draft.axis === axis.id;
|
|
112
|
+
const bands: ParallelBand[] = [];
|
|
113
|
+
for (let index = 0; index < list.length; index++) {
|
|
114
|
+
if (dragging && index === draft.index) continue;
|
|
115
|
+
bands.push(parallelBandOf(list[index] as ParallelRange, axis));
|
|
116
|
+
}
|
|
117
|
+
if (dragging) bands.push(draft.band);
|
|
118
|
+
if (bands.length > 0) drawn.set(axis.id, bands);
|
|
119
|
+
}
|
|
120
|
+
return drawn;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** What a released band does to the intervals its axis already kept. */
|
|
124
|
+
export interface ParallelCommit {
|
|
125
|
+
/** The intervals in force on that axis. */
|
|
126
|
+
list: readonly ParallelRange[];
|
|
127
|
+
/** Which of them the drag took hold of, or `-1` when it began a new one. */
|
|
128
|
+
index: number;
|
|
129
|
+
/** The band as the pointer left it. */
|
|
130
|
+
band: ParallelBand;
|
|
131
|
+
/** The axis it is on, to read the band back into its own units. */
|
|
132
|
+
layout: ParallelAxisLayout;
|
|
133
|
+
/** Whether the press took an interval and let it go without moving it. */
|
|
134
|
+
still: boolean;
|
|
135
|
+
/** Whether the axis may keep more than one interval. */
|
|
136
|
+
several: boolean;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The intervals an axis keeps once a band has been let go.
|
|
141
|
+
*
|
|
142
|
+
* A press that keeps nothing is a click, and a click says "take this away":
|
|
143
|
+
* the interval under the pointer when it landed on one, and every interval on
|
|
144
|
+
* the axis when it landed on bare axis. That is the only way to be rid of one
|
|
145
|
+
* interval on an axis carrying four, and it is the gesture that already
|
|
146
|
+
* cleared an axis before it could carry more than one.
|
|
147
|
+
* @param commit - See {@link ParallelCommit}.
|
|
148
|
+
* @returns The intervals, sorted and disjoint.
|
|
149
|
+
*/
|
|
150
|
+
export function parallelCommitOf(commit: ParallelCommit): ParallelRange[] {
|
|
151
|
+
const { list, index, band, layout, still, several } = commit;
|
|
152
|
+
if (still) return parallelWriteRange(list, index, null);
|
|
153
|
+
if (!parallelIsBand(band)) {
|
|
154
|
+
return index === -1 ? [] : parallelWriteRange(list, index, null);
|
|
155
|
+
}
|
|
156
|
+
const range = parallelRangeOf(band, layout);
|
|
157
|
+
if (!several && index === -1) return [range];
|
|
158
|
+
return parallelWriteRange(list, index, range);
|
|
159
|
+
}
|