react-cheminfo 0.44.0 → 0.46.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/lib/chart/core/chartDomain.d.ts +16 -5
- package/lib/chart/core/chartDomain.d.ts.map +1 -1
- package/lib/chart/core/chartDomain.js.map +1 -1
- package/lib/chart/core/index.d.ts +1 -1
- package/lib/chart/core/index.d.ts.map +1 -1
- package/lib/chart/core/index.js +1 -1
- package/lib/chart/core/index.js.map +1 -1
- package/lib/chart/core/selectionGeometry.d.ts +4 -3
- package/lib/chart/core/selectionGeometry.d.ts.map +1 -1
- package/lib/chart/core/selectionGeometry.js +4 -3
- package/lib/chart/core/selectionGeometry.js.map +1 -1
- package/lib/chart/core/zoomDomain.d.ts +28 -3
- package/lib/chart/core/zoomDomain.d.ts.map +1 -1
- package/lib/chart/core/zoomDomain.js +67 -19
- package/lib/chart/core/zoomDomain.js.map +1 -1
- package/lib/chart/ui/SelectionRect.d.ts.map +1 -1
- package/lib/chart/ui/SelectionRect.js +1 -1
- package/lib/chart/ui/SelectionRect.js.map +1 -1
- 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/split/core/index.d.ts +3 -0
- package/lib/split/core/index.d.ts.map +1 -0
- package/lib/split/core/index.js +2 -0
- package/lib/split/core/index.js.map +1 -0
- package/lib/split/core/split.d.ts +52 -0
- package/lib/split/core/split.d.ts.map +1 -0
- package/lib/split/core/split.js +45 -0
- package/lib/split/core/split.js.map +1 -0
- package/lib/split/ui/SplitRow.d.ts +66 -0
- package/lib/split/ui/SplitRow.d.ts.map +1 -0
- package/lib/split/ui/SplitRow.js +99 -0
- package/lib/split/ui/SplitRow.js.map +1 -0
- package/lib/split/ui/index.d.ts +3 -0
- package/lib/split/ui/index.d.ts.map +1 -0
- package/lib/split/ui/index.js +2 -0
- package/lib/split/ui/index.js.map +1 -0
- 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/chart/core/chartDomain.ts +16 -5
- package/src/chart/core/index.ts +2 -0
- package/src/chart/core/selectionGeometry.ts +4 -3
- package/src/chart/core/zoomDomain.ts +74 -23
- package/src/chart/ui/SelectionRect.tsx +4 -0
- package/src/core.ts +1 -0
- package/src/split/core/index.ts +8 -0
- package/src/split/core/split.ts +67 -0
- package/src/split/ui/SplitRow.tsx +225 -0
- package/src/split/ui/index.ts +2 -0
- package/src/ui.ts +1 -0
- package/styles/chrome.css +18 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { SplitPane } from 'react-science/ui';
|
|
4
|
+
import { useResizeObserver } from "../../hooks/ui/useResizeObserver.js";
|
|
5
|
+
import { clampSplit } from "../core/split.js";
|
|
6
|
+
/**
|
|
7
|
+
* Two panes sharing a row, divided where the address says.
|
|
8
|
+
* @param props - See {@link SplitRowProps}.
|
|
9
|
+
* @returns The two panes with the splitter between them, the two stacked on a
|
|
10
|
+
* narrow screen, or whichever one a link left on the page, alone.
|
|
11
|
+
*/
|
|
12
|
+
export function SplitRow(props) {
|
|
13
|
+
const { ratio, defaultRatio, onRatio, start, end, min, max, stackBelow = STACK_BELOW, gutter = GUTTER, stackedGap = STACKED_GAP, } = props;
|
|
14
|
+
const row = useRef(null);
|
|
15
|
+
const [width, setWidth] = useState(windowWidth);
|
|
16
|
+
// The share under the pointer, which is not the one in the address: a drag
|
|
17
|
+
// reports every pixel it crosses, and the address is rewritten once, where
|
|
18
|
+
// the splitter is let go.
|
|
19
|
+
const [dragged, setDragged] = useState(null);
|
|
20
|
+
useResizeObserver(row, (size) => {
|
|
21
|
+
setWidth(size.width);
|
|
22
|
+
});
|
|
23
|
+
if (start === null && end === null)
|
|
24
|
+
return null;
|
|
25
|
+
const stacked = start === null || end === null || width < stackBelow;
|
|
26
|
+
const startPane = start === null ? null : (_jsx("div", { "data-testid": "split-start", style: stacked ? STACKED_PANE : paneStyle('start', gutter), children: start }));
|
|
27
|
+
const endPane = end === null ? null : (_jsx("div", { "data-testid": "split-end", style: stacked ? STACKED_PANE : paneStyle('end', gutter), children: end }));
|
|
28
|
+
if (stacked) {
|
|
29
|
+
return (_jsxs("div", { ref: row, style: { ...STACK, gap: stackedGap }, children: [startPane, endPane] }));
|
|
30
|
+
}
|
|
31
|
+
const share = clampSplit(dragged ?? ratio ?? defaultRatio, { min, max });
|
|
32
|
+
return (_jsx("div", { ref: row, className: "split-row", children: _jsxs(SplitPane, { direction: "horizontal", controlledSide: "start", size: `${share}%`,
|
|
33
|
+
// Held open, so the only layout a visitor can reach is one the address
|
|
34
|
+
// describes: left to itself a double click collapses a pane, and a link
|
|
35
|
+
// shared from there would open with the pane back. The double click is
|
|
36
|
+
// answered here instead, by returning to the page's own share.
|
|
37
|
+
open: true, onOpenChange: () => {
|
|
38
|
+
setDragged(null);
|
|
39
|
+
onRatio(null);
|
|
40
|
+
}, onSizeChange: (asked) => {
|
|
41
|
+
setDragged(shareOf(asked, share, { min, max }));
|
|
42
|
+
}, onResize: (asked) => {
|
|
43
|
+
const rested = shareOf(asked, share, { min, max });
|
|
44
|
+
setDragged(null);
|
|
45
|
+
onRatio(rested);
|
|
46
|
+
}, children: [startPane, endPane] }) }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The share a splitter asked for.
|
|
50
|
+
* @param asked - What it reported, a percentage because that is what it was
|
|
51
|
+
* given.
|
|
52
|
+
* @param current - The share in force, kept when the report is not a number.
|
|
53
|
+
* @param range - The range this row is divided in.
|
|
54
|
+
* @returns A whole percentage inside it.
|
|
55
|
+
*/
|
|
56
|
+
function shareOf(asked, current, range) {
|
|
57
|
+
const value = Number.parseFloat(asked);
|
|
58
|
+
return Number.isFinite(value) ? clampSplit(value, range) : current;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* How wide the window is, which is what the row is taken to be until it has
|
|
62
|
+
* been measured. Reading it rather than starting at zero is what keeps a wide
|
|
63
|
+
* page from laying itself out stacked and splitting a frame later, which would
|
|
64
|
+
* build both figures twice on every load.
|
|
65
|
+
* @returns The width in pixels, or the threshold itself where there is no
|
|
66
|
+
* window to read — a test, or a page rendered to a string — which is the
|
|
67
|
+
* narrowest a row is still split at.
|
|
68
|
+
*/
|
|
69
|
+
function windowWidth() {
|
|
70
|
+
const { innerWidth } = globalThis;
|
|
71
|
+
return typeof innerWidth === 'number' && innerWidth > 0
|
|
72
|
+
? innerWidth
|
|
73
|
+
: STACK_BELOW;
|
|
74
|
+
}
|
|
75
|
+
/** The narrowest row that is still split, in pixels. */
|
|
76
|
+
const STACK_BELOW = 860;
|
|
77
|
+
/** The gutter a pane keeps beside the splitter, in pixels. */
|
|
78
|
+
const GUTTER = 6;
|
|
79
|
+
/** The gap between the panes once they have stacked, in pixels. */
|
|
80
|
+
const STACKED_GAP = 16;
|
|
81
|
+
const STACK = {
|
|
82
|
+
display: 'flex',
|
|
83
|
+
flexDirection: 'column',
|
|
84
|
+
};
|
|
85
|
+
const STACKED_PANE = {
|
|
86
|
+
display: 'flex',
|
|
87
|
+
flexDirection: 'column',
|
|
88
|
+
minWidth: 0,
|
|
89
|
+
};
|
|
90
|
+
function paneStyle(side, gutter) {
|
|
91
|
+
return {
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flex: '1 1 0%',
|
|
94
|
+
flexDirection: 'column',
|
|
95
|
+
minWidth: 0,
|
|
96
|
+
[side === 'start' ? 'paddingRight' : 'paddingLeft']: gutter,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=SplitRow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SplitRow.js","sourceRoot":"","sources":["../../../src/split/ui/SplitRow.tsx"],"names":[],"mappings":";AAuBA,OAA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,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/split/ui/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/split/ui/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAgB,CAAC"}
|
package/lib/ui.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from './scatter/ui/index.ts';
|
|
|
30
30
|
export * from './scatter3d/ui/index.ts';
|
|
31
31
|
export * from './share/ui/index.ts';
|
|
32
32
|
export * from './shared/ui/index.ts';
|
|
33
|
+
export * from './split/ui/index.ts';
|
|
33
34
|
export type { ConformerTableProps } from './structure/ui/ConformerTable.tsx';
|
|
34
35
|
export { ConformerTable } from './structure/ui/ConformerTable.tsx';
|
|
35
36
|
export type { ConformerColumn } from './structure/ui/conformerColumns.ts';
|
package/lib/ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC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qB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AAKpC,YAAY,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,YAAY,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,oCAAoC,CAAC"}
|
package/lib/ui.js
CHANGED
|
@@ -30,6 +30,7 @@ export * from "./scatter/ui/index.js";
|
|
|
30
30
|
export * from "./scatter3d/ui/index.js";
|
|
31
31
|
export * from "./share/ui/index.js";
|
|
32
32
|
export * from "./shared/ui/index.js";
|
|
33
|
+
export * from "./split/ui/index.js";
|
|
33
34
|
export { ConformerTable } from "./structure/ui/ConformerTable.js";
|
|
34
35
|
export { CONFORMER_COLUMN_LABELS, PICKER_COLUMNS, RANKING_COLUMNS, } from "./structure/ui/conformerColumns.js";
|
|
35
36
|
//# sourceMappingURL=ui.js.map
|
package/lib/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAA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,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AAMpC,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAmC,CAAC;AAEnE,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,oCAAoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cheminfo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
|
|
6
6
|
"author": "Luc Patiny",
|
|
@@ -80,18 +80,29 @@ export const DEFAULT_Y_AXIS_RULES: Required<YAxisRules> = {
|
|
|
80
80
|
* between forty and sixty percent", so a drag narrows the horizontal axis and
|
|
81
81
|
* leaves the height alone unless it is released past the baseline.
|
|
82
82
|
*
|
|
83
|
+
* `dual` is the same reading gesture with a gate a reader can predict: a drag
|
|
84
|
+
* kept level narrows the horizontal axis alone, and one taken far enough up or
|
|
85
|
+
* down brings the height with it. It is what `xAxis` cannot be on a chart whose
|
|
86
|
+
* vertical axis has no baseline to cross — a titration curve climbing from pH 2
|
|
87
|
+
* to pH 12, a speciation diagram drawn over decades — where "has the pointer
|
|
88
|
+
* passed zero" is a question about the margin rather than about the data, and
|
|
89
|
+
* the answer to it is no for every drag made inside the plot. Here both windows
|
|
90
|
+
* are asked for where the curve is, and the preview changes shape as the
|
|
91
|
+
* threshold is crossed, so the rectangle is found by the hand that was already
|
|
92
|
+
* drawing one.
|
|
93
|
+
*
|
|
83
94
|
* `box` is the tool: while it is chosen, the rectangle dragged out is the window,
|
|
84
95
|
* both axes at once. It is a mode rather than a modifier because it is used in
|
|
85
96
|
* runs — a baseline being examined is examined several times over — and a
|
|
86
97
|
* modifier held down through each of them is a worse gesture than a tool pressed
|
|
87
98
|
* once.
|
|
88
99
|
*
|
|
89
|
-
* The
|
|
90
|
-
* nothing but zoom tools can say so in its own signature — which is
|
|
91
|
-
* `select`, the one drag that moves no axis, from reaching a chart
|
|
92
|
-
* handler for it.
|
|
100
|
+
* The three are named apart from the whole of `DragMode` so that a chart
|
|
101
|
+
* offering nothing but zoom tools can say so in its own signature — which is
|
|
102
|
+
* what stops `select`, the one drag that moves no axis, from reaching a chart
|
|
103
|
+
* with no handler for it.
|
|
93
104
|
*/
|
|
94
|
-
export type ZoomDragMode = 'xAxis' | 'box';
|
|
105
|
+
export type ZoomDragMode = 'xAxis' | 'dual' | 'box';
|
|
95
106
|
|
|
96
107
|
/**
|
|
97
108
|
* What a drag across the plot asks for.
|
package/src/chart/core/index.ts
CHANGED
|
@@ -169,7 +169,9 @@ export {
|
|
|
169
169
|
} from './viewTransform.ts';
|
|
170
170
|
export type { DragBox, ZoomSelection } from './zoomDomain.ts';
|
|
171
171
|
export {
|
|
172
|
+
DUAL_ZOOM_TRAVEL,
|
|
172
173
|
MINIMUM_DRAG,
|
|
174
|
+
draggedBeyondLevel,
|
|
173
175
|
releasedBeyondBaseline,
|
|
174
176
|
scaledYAxis,
|
|
175
177
|
zoomSelection,
|
|
@@ -34,9 +34,10 @@ export interface SelectionRectangle {
|
|
|
34
34
|
* A drag that takes the y axis with it is drawn at the height of the drag
|
|
35
35
|
* itself, and one that asks for the x axis alone spans the whole plot.
|
|
36
36
|
* That is the gesture announcing itself before the button is let go: the
|
|
37
|
-
* rectangle changing shape as the pointer crosses the baseline
|
|
38
|
-
*
|
|
39
|
-
* they can still act
|
|
37
|
+
* rectangle changing shape — as the pointer crosses the baseline, or as a
|
|
38
|
+
* `dual` drag leaves the level it started on — is the only warning a user gets
|
|
39
|
+
* that the release is about to move both axes, and it is one they can still act
|
|
40
|
+
* on.
|
|
40
41
|
*
|
|
41
42
|
* A drag too short to zoom draws nothing at all. Below `MINIMUM_DRAG` the
|
|
42
43
|
* release does nothing — most clicks made on a trackpad wobble by a pixel or two
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { clamp } from '../../format/core/clamp.ts';
|
|
12
12
|
|
|
13
|
-
import type { ChartDomain, ZoomRules } from './chartDomain.ts';
|
|
13
|
+
import type { ChartDomain, DragMode, ZoomRules } from './chartDomain.ts';
|
|
14
14
|
import { DEFAULT_Y_AXIS_RULES } from './chartDomain.ts';
|
|
15
15
|
import type { PlotRect } from './chartGeometry.ts';
|
|
16
16
|
import type { ChartScale } from './chartScale.ts';
|
|
@@ -30,6 +30,19 @@ import { chartPixel, chartValue } from './chartScale.ts';
|
|
|
30
30
|
*/
|
|
31
31
|
export const MINIMUM_DRAG = 4;
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* How far a `dual` drag has to travel vertically before it brings the y axis
|
|
35
|
+
* with it, in user units of the SVG.
|
|
36
|
+
*
|
|
37
|
+
* Far enough above `MINIMUM_DRAG` that no drag meant to stay level reaches it by
|
|
38
|
+
* the tremor of a hand or the slope of a trackpad swipe, and near enough that
|
|
39
|
+
* the rectangle a reader wants costs one gesture rather than a reach for the
|
|
40
|
+
* margin. The preview changes shape on the pixel it is crossed, so the number
|
|
41
|
+
* itself never has to be learnt: the first drag that crosses it teaches the
|
|
42
|
+
* gesture, and the first that recrosses it back shows the way out.
|
|
43
|
+
*/
|
|
44
|
+
export const DUAL_ZOOM_TRAVEL = 24;
|
|
45
|
+
|
|
33
46
|
/** The two corners of a drag, in the user units of the SVG. */
|
|
34
47
|
export interface DragBox {
|
|
35
48
|
/** Where the press landed, horizontally. */
|
|
@@ -58,9 +71,9 @@ export interface ZoomSelection extends DragBox {
|
|
|
58
71
|
* than by the rectangle itself — so what the preview promises and what letting
|
|
59
72
|
* go actually does are the same test rather than two that have to agree.
|
|
60
73
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
74
|
+
* Which answer a mode gives is `takesYAxis`'s business, so a `select` drag is
|
|
75
|
+
* always a band however far past the baseline it strays, and a `dual` drag
|
|
76
|
+
* becomes a rectangle the moment it has travelled `DUAL_ZOOM_TRAVEL`.
|
|
64
77
|
* @param drag - The drag being made, `null` when none is.
|
|
65
78
|
* @param yScale - The y axis as it is currently zoomed.
|
|
66
79
|
* @param rules - How the y axis behaves and what a drag means, defaulting to a
|
|
@@ -83,16 +96,26 @@ export function zoomSelection(
|
|
|
83
96
|
fromY: drag.fromY,
|
|
84
97
|
toX: drag.toX,
|
|
85
98
|
toY: drag.toY,
|
|
86
|
-
|
|
87
|
-
// the first pixel of the gesture rather than a full-height band that
|
|
88
|
-
// suddenly becomes one; a select drag never takes it at all.
|
|
89
|
-
zoomsYAxis:
|
|
90
|
-
mode === 'box' ||
|
|
91
|
-
(mode !== 'select' &&
|
|
92
|
-
releasedBeyondBaseline(drag.toY, yScale, baseline, pointsDown)),
|
|
99
|
+
zoomsYAxis: takesYAxis(drag, mode, yScale, baseline, pointsDown),
|
|
93
100
|
};
|
|
94
101
|
}
|
|
95
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Whether a drag has left the level it started on by enough to ask for the y
|
|
105
|
+
* axis as well.
|
|
106
|
+
*
|
|
107
|
+
* Measured as the hand made it, before any clamping to the plot: a drag that ran
|
|
108
|
+
* out over the tick labels travelled however far it travelled. Nothing is
|
|
109
|
+
* latched — the answer is read off the two corners and nothing else — so a
|
|
110
|
+
* reader who drifted down and came back up is promised a band again, and the
|
|
111
|
+
* preview says so while the button is still down.
|
|
112
|
+
* @param drag - The drag being made or released, in user units of the SVG.
|
|
113
|
+
* @returns Whether the height comes along.
|
|
114
|
+
*/
|
|
115
|
+
export function draggedBeyondLevel(drag: DragBox): boolean {
|
|
116
|
+
return Math.abs(drag.toY - drag.fromY) >= DUAL_ZOOM_TRAVEL;
|
|
117
|
+
}
|
|
118
|
+
|
|
96
119
|
/**
|
|
97
120
|
* Whether a drag let go here asks for the y axis as well.
|
|
98
121
|
*
|
|
@@ -178,24 +201,19 @@ export function zoomedDomain(
|
|
|
178
201
|
Math.min(firstX, secondX),
|
|
179
202
|
Math.max(firstX, secondX),
|
|
180
203
|
];
|
|
181
|
-
|
|
182
|
-
// go; the reading gesture takes the height only when it crossed the baseline.
|
|
183
|
-
if (
|
|
184
|
-
mode !== 'box' &&
|
|
185
|
-
!releasedBeyondBaseline(drag.toY, yScale, baseline, pointsDown)
|
|
186
|
-
) {
|
|
204
|
+
if (!takesYAxis(drag, mode, yScale, baseline, pointsDown)) {
|
|
187
205
|
return { x, y: current.y };
|
|
188
206
|
}
|
|
189
207
|
|
|
190
208
|
const fromY = chartValue(yScale, clamp(drag.fromY, plot.top, plot.bottom));
|
|
191
209
|
const toY = chartValue(yScale, clamp(drag.toY, plot.top, plot.bottom));
|
|
192
210
|
// Both ends, so a baseline the data runs *down* from — 100 percent
|
|
193
|
-
// transmittance — is kept as surely as one it stands on.
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
// drawn.
|
|
198
|
-
const holdBaseline = keepBaseline && mode
|
|
211
|
+
// transmittance — is kept as surely as one it stands on. Only the reading
|
|
212
|
+
// gesture holds a baseline: a rectangle dragged out deliberately, by the box
|
|
213
|
+
// tool or by a `dual` drag that left its level, is a promise about exactly
|
|
214
|
+
// that rectangle, and a viewer whose axis rules keep its baseline would
|
|
215
|
+
// otherwise see a taller window than the one drawn.
|
|
216
|
+
const holdBaseline = keepBaseline && mode === 'xAxis';
|
|
199
217
|
const bottom = holdBaseline
|
|
200
218
|
? Math.min(baseline, fromY, toY)
|
|
201
219
|
: Math.min(fromY, toY);
|
|
@@ -233,3 +251,36 @@ export function scaledYAxis(
|
|
|
233
251
|
];
|
|
234
252
|
return y[1] > y[0] ? { x: current.x, y } : current;
|
|
235
253
|
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Whether a drag brings the y axis with it, which is the one question the
|
|
257
|
+
* preview and the release must never answer differently.
|
|
258
|
+
*
|
|
259
|
+
* Asked once, here, rather than by each of them: a rectangle that promises a
|
|
260
|
+
* height the release then refuses teaches a reader that the chart is
|
|
261
|
+
* unreliable, and two copies of this test are how that comes about.
|
|
262
|
+
*
|
|
263
|
+
* The box tool takes the height always, so its preview is a rectangle from the
|
|
264
|
+
* first pixel of the gesture rather than a full-height band that suddenly
|
|
265
|
+
* becomes one. A `select` drag never takes it at all: its answer is two numbers
|
|
266
|
+
* on one axis, and a preview that grew into a rectangle would promise a height
|
|
267
|
+
* nobody is ever told about.
|
|
268
|
+
* @param drag - The drag being made or released, in user units of the SVG.
|
|
269
|
+
* @param mode - What a drag on this chart asks for.
|
|
270
|
+
* @param yScale - The y axis as it is currently zoomed.
|
|
271
|
+
* @param baseline - The value the reading gesture is judged against.
|
|
272
|
+
* @param pointsDown - Whether the data hangs below that baseline.
|
|
273
|
+
* @returns Whether the height comes along.
|
|
274
|
+
*/
|
|
275
|
+
function takesYAxis(
|
|
276
|
+
drag: DragBox,
|
|
277
|
+
mode: DragMode,
|
|
278
|
+
yScale: ChartScale,
|
|
279
|
+
baseline: number,
|
|
280
|
+
pointsDown: boolean,
|
|
281
|
+
): boolean {
|
|
282
|
+
if (mode === 'box') return true;
|
|
283
|
+
if (mode === 'select') return false;
|
|
284
|
+
if (mode === 'dual') return draggedBeyondLevel(drag);
|
|
285
|
+
return releasedBeyondBaseline(drag.toY, yScale, baseline, pointsDown);
|
|
286
|
+
}
|
|
@@ -36,6 +36,10 @@ export function SelectionRect(props: SelectionRectProps): ReactElement | null {
|
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
38
|
<rect
|
|
39
|
+
// Named, because the shape of this rectangle is the whole promise a drag
|
|
40
|
+
// makes — a band for the x axis alone, the drawn height for both — and
|
|
41
|
+
// the only way to check the promise is to measure it mid-drag.
|
|
42
|
+
data-testid="chart-selection"
|
|
39
43
|
x={rectangle.x}
|
|
40
44
|
y={rectangle.y}
|
|
41
45
|
width={rectangle.width}
|
package/src/core.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from './share/core/index.ts';
|
|
|
30
30
|
// The deck format and its navigation are framework-free, so a backend can read
|
|
31
31
|
// a manifest without loading React: `react-cheminfo/slides` is the player.
|
|
32
32
|
export * from './slides/core/index.ts';
|
|
33
|
+
export * from './split/core/index.ts';
|
|
33
34
|
export * from './state/core/index.ts';
|
|
34
35
|
// Framework-free molfile and editor-value helpers, so a worker can read a
|
|
35
36
|
// molfile without loading the editor that `react-cheminfo/structure` exports.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a row holding two figures is divided, and how that travels in a link.
|
|
3
|
+
*
|
|
4
|
+
* The share is the *first* pane's, as a whole percentage, because it is written
|
|
5
|
+
* into the address: `?split=35` is a number somebody can read off a link,
|
|
6
|
+
* retype into a slide and hand out. A link that names none opens the page at
|
|
7
|
+
* its own default, and nothing is written until a splitter has been dragged, so
|
|
8
|
+
* an ordinary link stays an ordinary link.
|
|
9
|
+
*
|
|
10
|
+
* One name across the family: a reader who has learned to widen the chart on
|
|
11
|
+
* one of our tools has learned it on all of them.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ShareParamCodec } from '../../share/core/params.ts';
|
|
15
|
+
import { integerParam } from '../../share/core/params.ts';
|
|
16
|
+
|
|
17
|
+
/** Query parameter a row's division is carried in, on every site. */
|
|
18
|
+
export const SPLIT_PARAM = 'split';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The narrowest either pane is left at. Under a fifth of the row neither side
|
|
22
|
+
* is read, and a drag that lands there is one nobody can undo without the
|
|
23
|
+
* splitter they have just squeezed out of sight.
|
|
24
|
+
*/
|
|
25
|
+
export const MIN_SPLIT = 20;
|
|
26
|
+
|
|
27
|
+
/** The widest the first pane goes, which is {@link MIN_SPLIT} from the other end. */
|
|
28
|
+
export const MAX_SPLIT = 100 - MIN_SPLIT;
|
|
29
|
+
|
|
30
|
+
/** The range a row may be divided in, where a page wants its own. */
|
|
31
|
+
export interface SplitRange {
|
|
32
|
+
/**
|
|
33
|
+
* The narrowest the first pane is left at.
|
|
34
|
+
* @default 20
|
|
35
|
+
*/
|
|
36
|
+
min?: number;
|
|
37
|
+
/**
|
|
38
|
+
* The widest the first pane is left at.
|
|
39
|
+
* @default 80
|
|
40
|
+
*/
|
|
41
|
+
max?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The share to keep, given one asked for by a drag or named by a link.
|
|
46
|
+
* @param value - The share asked for.
|
|
47
|
+
* @param range - The range this row is divided in.
|
|
48
|
+
* @returns A whole percentage inside it.
|
|
49
|
+
*/
|
|
50
|
+
export function clampSplit(value: number, range: SplitRange = {}): number {
|
|
51
|
+
const { min = MIN_SPLIT, max = MAX_SPLIT } = range;
|
|
52
|
+
return Math.min(max, Math.max(min, Math.round(value)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The codec a site reads `split=` with, for its share vocabulary or its route
|
|
57
|
+
* table. `null` is "the page's own share", which is what an absent parameter
|
|
58
|
+
* and an unreadable one both mean, and what writes no parameter at all.
|
|
59
|
+
* @param range - The range this row is divided in.
|
|
60
|
+
* @returns The codec.
|
|
61
|
+
*/
|
|
62
|
+
export function splitParam(
|
|
63
|
+
range: SplitRange = {},
|
|
64
|
+
): ShareParamCodec<number | null> {
|
|
65
|
+
const { min = MIN_SPLIT, max = MAX_SPLIT } = range;
|
|
66
|
+
return integerParam({ min, max, default: null });
|
|
67
|
+
}
|