react-cheminfo 0.132.0 → 0.134.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 +16 -0
- package/lib/drawing/captionEditor/CaptionEditor.d.ts +3 -3
- package/lib/drawing/captionEditor/CaptionEditor.d.ts.map +1 -1
- package/lib/drawing/captionEditor/CaptionEditor.js +8 -4
- package/lib/drawing/captionEditor/CaptionEditor.js.map +1 -1
- package/lib/drawing/captionEditor/CaptionToolbar.d.ts +4 -2
- package/lib/drawing/captionEditor/CaptionToolbar.d.ts.map +1 -1
- package/lib/drawing/captionEditor/CaptionToolbar.js +6 -4
- package/lib/drawing/captionEditor/CaptionToolbar.js.map +1 -1
- package/lib/drawing/captionEditor/index.d.ts +2 -0
- package/lib/drawing/captionEditor/index.d.ts.map +1 -1
- package/lib/drawing/captionEditor/index.js +1 -0
- package/lib/drawing/captionEditor/index.js.map +1 -1
- package/lib/drawing/captionEditor/toolbarInView.d.ts +40 -0
- package/lib/drawing/captionEditor/toolbarInView.d.ts.map +1 -0
- package/lib/drawing/captionEditor/toolbarInView.js +53 -0
- package/lib/drawing/captionEditor/toolbarInView.js.map +1 -0
- package/lib/drawing/core/camera.d.ts +2 -0
- package/lib/drawing/core/camera.d.ts.map +1 -1
- package/lib/drawing/core/camera.js +2 -0
- package/lib/drawing/core/camera.js.map +1 -1
- package/lib/drawing/core/index.d.ts +1 -1
- package/lib/drawing/core/index.d.ts.map +1 -1
- package/lib/drawing/core/index.js +1 -1
- package/lib/drawing/core/index.js.map +1 -1
- package/lib/drawing/render/index.d.ts +1 -1
- package/lib/drawing/render/index.d.ts.map +1 -1
- package/lib/drawing/render/index.js +1 -1
- package/lib/drawing/render/index.js.map +1 -1
- package/lib/drawing/render/pageGrid.d.ts +16 -0
- package/lib/drawing/render/pageGrid.d.ts.map +1 -1
- package/lib/drawing/render/pageGrid.js +28 -10
- package/lib/drawing/render/pageGrid.js.map +1 -1
- package/lib/drawing/ui/PageField.d.ts +29 -0
- package/lib/drawing/ui/PageField.d.ts.map +1 -0
- package/lib/drawing/ui/PageField.js +38 -0
- package/lib/drawing/ui/PageField.js.map +1 -0
- package/lib/drawing/ui/PageGrid.d.ts +20 -0
- package/lib/drawing/ui/PageGrid.d.ts.map +1 -0
- package/lib/drawing/ui/PageGrid.js +26 -0
- package/lib/drawing/ui/PageGrid.js.map +1 -0
- package/lib/drawing/ui/PageSideInput.d.ts +28 -0
- package/lib/drawing/ui/PageSideInput.d.ts.map +1 -0
- package/lib/drawing/ui/PageSideInput.js +47 -0
- package/lib/drawing/ui/PageSideInput.js.map +1 -0
- package/lib/drawing/ui/PageToolbar.d.ts +16 -0
- package/lib/drawing/ui/PageToolbar.d.ts.map +1 -0
- package/lib/drawing/ui/PageToolbar.js +16 -0
- package/lib/drawing/ui/PageToolbar.js.map +1 -0
- package/lib/drawing/ui/PrintSheets.d.ts +32 -0
- package/lib/drawing/ui/PrintSheets.d.ts.map +1 -0
- package/lib/drawing/ui/PrintSheets.js +17 -0
- package/lib/drawing/ui/PrintSheets.js.map +1 -0
- package/lib/drawing/ui/TextToolIcon.d.ts +19 -0
- package/lib/drawing/ui/TextToolIcon.d.ts.map +1 -0
- package/lib/drawing/ui/TextToolIcon.js +21 -0
- package/lib/drawing/ui/TextToolIcon.js.map +1 -0
- package/lib/drawing/ui/ZoomControl.d.ts +25 -0
- package/lib/drawing/ui/ZoomControl.d.ts.map +1 -0
- package/lib/drawing/ui/ZoomControl.js +27 -0
- package/lib/drawing/ui/ZoomControl.js.map +1 -0
- package/lib/drawing/ui/index.d.ts +10 -0
- package/lib/drawing/ui/index.d.ts.map +1 -1
- package/lib/drawing/ui/index.js +7 -0
- package/lib/drawing/ui/index.js.map +1 -1
- package/lib/guide/ui/EmptyGuide.d.ts +5 -2
- package/lib/guide/ui/EmptyGuide.d.ts.map +1 -1
- package/lib/guide/ui/EmptyGuide.js +8 -3
- package/lib/guide/ui/EmptyGuide.js.map +1 -1
- package/lib/guide/ui/GuideFigures.d.ts +6 -0
- package/lib/guide/ui/GuideFigures.d.ts.map +1 -1
- package/lib/guide/ui/GuideFigures.js +5 -5
- package/lib/guide/ui/GuideFigures.js.map +1 -1
- package/lib/host/core/index.d.ts +2 -0
- package/lib/host/core/index.d.ts.map +1 -1
- package/lib/host/core/index.js +1 -0
- package/lib/host/core/index.js.map +1 -1
- package/lib/host/core/kinds.d.ts +6 -1
- package/lib/host/core/kinds.d.ts.map +1 -1
- package/lib/host/core/kinds.js +4 -1
- package/lib/host/core/kinds.js.map +1 -1
- package/lib/host/core/recordKinds.d.ts +165 -0
- package/lib/host/core/recordKinds.d.ts.map +1 -0
- package/lib/host/core/recordKinds.js +68 -0
- package/lib/host/core/recordKinds.js.map +1 -0
- package/lib/mass/core/index.d.ts +1 -0
- package/lib/mass/core/index.d.ts.map +1 -1
- package/lib/mass/core/index.js +1 -0
- package/lib/mass/core/index.js.map +1 -1
- package/lib/mass/core/massDomain.d.ts.map +1 -1
- package/lib/mass/core/massDomain.js +9 -5
- package/lib/mass/core/massDomain.js.map +1 -1
- package/lib/mass/core/massSpectrum.d.ts +9 -0
- package/lib/mass/core/massSpectrum.d.ts.map +1 -1
- package/lib/mass/core/massSpectrum.js.map +1 -1
- package/lib/mass/core/verticalScale.d.ts +30 -0
- package/lib/mass/core/verticalScale.d.ts.map +1 -0
- package/lib/mass/core/verticalScale.js +40 -0
- package/lib/mass/core/verticalScale.js.map +1 -0
- package/lib/mass/ui/MassChart.d.ts.map +1 -1
- package/lib/mass/ui/MassChart.js +4 -38
- package/lib/mass/ui/MassChart.js.map +1 -1
- package/lib/mass/ui/massChartLayers.d.ts +31 -0
- package/lib/mass/ui/massChartLayers.d.ts.map +1 -0
- package/lib/mass/ui/massChartLayers.js +57 -0
- package/lib/mass/ui/massChartLayers.js.map +1 -0
- package/lib/structure/core/index.d.ts +1 -1
- package/lib/structure/core/index.d.ts.map +1 -1
- package/lib/structure/core/index.js.map +1 -1
- package/lib/structure/core/structurePicture.d.ts +32 -1
- package/lib/structure/core/structurePicture.d.ts.map +1 -1
- package/lib/structure/core/structurePicture.js +29 -2
- package/lib/structure/core/structurePicture.js.map +1 -1
- package/lib/structure/ui/StructureEditor.d.ts +2 -1
- package/lib/structure/ui/StructureEditor.d.ts.map +1 -1
- package/lib/structure/ui/StructureEditor.js +9 -3
- package/lib/structure/ui/StructureEditor.js.map +1 -1
- package/lib/structure/ui/StructureEditorGuide.d.ts +15 -0
- package/lib/structure/ui/StructureEditorGuide.d.ts.map +1 -0
- package/lib/structure/ui/StructureEditorGuide.js +26 -0
- package/lib/structure/ui/StructureEditorGuide.js.map +1 -0
- package/lib/structure/ui/structureEditorProps.d.ts +11 -1
- package/lib/structure/ui/structureEditorProps.d.ts.map +1 -1
- package/lib/structure/ui/useCanvasPress.d.ts +23 -0
- package/lib/structure/ui/useCanvasPress.d.ts.map +1 -0
- package/lib/structure/ui/useCanvasPress.js +53 -0
- package/lib/structure/ui/useCanvasPress.js.map +1 -0
- package/lib/xps/core/detectFormat.d.ts +6 -0
- package/lib/xps/core/detectFormat.d.ts.map +1 -1
- package/lib/xps/core/detectFormat.js +8 -0
- package/lib/xps/core/detectFormat.js.map +1 -1
- package/lib/xps/core/xpsEditorApi.d.ts +16 -0
- package/lib/xps/core/xpsEditorApi.d.ts.map +1 -1
- package/lib/xps/ui/XpsCanvas.d.ts +10 -1
- package/lib/xps/ui/XpsCanvas.d.ts.map +1 -1
- package/lib/xps/ui/XpsCanvas.js +14 -3
- package/lib/xps/ui/XpsCanvas.js.map +1 -1
- package/lib/xps/ui/XpsChart.d.ts.map +1 -1
- package/lib/xps/ui/XpsChart.js +12 -43
- package/lib/xps/ui/XpsChart.js.map +1 -1
- package/lib/xps/ui/XpsEditor.d.ts +8 -0
- package/lib/xps/ui/XpsEditor.d.ts.map +1 -1
- package/lib/xps/ui/XpsEditor.js +2 -2
- package/lib/xps/ui/XpsEditor.js.map +1 -1
- package/lib/xps/ui/XpsShell.d.ts +5 -0
- package/lib/xps/ui/XpsShell.d.ts.map +1 -1
- package/lib/xps/ui/XpsShell.js +18 -4
- package/lib/xps/ui/XpsShell.js.map +1 -1
- package/lib/xps/ui/dropEvents.d.ts +8 -1
- package/lib/xps/ui/dropEvents.d.ts.map +1 -1
- package/lib/xps/ui/dropEvents.js +15 -1
- package/lib/xps/ui/dropEvents.js.map +1 -1
- package/lib/xps/ui/useSpectrumDrop.d.ts +6 -0
- package/lib/xps/ui/useSpectrumDrop.d.ts.map +1 -1
- package/lib/xps/ui/useSpectrumDrop.js +1 -1
- package/lib/xps/ui/useSpectrumDrop.js.map +1 -1
- package/lib/xps/ui/useXpsEditorHandle.d.ts +4 -1
- package/lib/xps/ui/useXpsEditorHandle.d.ts.map +1 -1
- package/lib/xps/ui/useXpsEditorHandle.js +6 -2
- package/lib/xps/ui/useXpsEditorHandle.js.map +1 -1
- package/lib/xps/ui/useXpsReadout.d.ts +43 -0
- package/lib/xps/ui/useXpsReadout.d.ts.map +1 -0
- package/lib/xps/ui/useXpsReadout.js +59 -0
- package/lib/xps/ui/useXpsReadout.js.map +1 -0
- package/lib/xps/ui/xpsChartProps.d.ts +9 -0
- package/lib/xps/ui/xpsChartProps.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/drawing/captionEditor/CaptionEditor.tsx +8 -3
- package/src/drawing/captionEditor/CaptionToolbar.tsx +18 -2
- package/src/drawing/captionEditor/index.ts +2 -0
- package/src/drawing/captionEditor/toolbarInView.ts +73 -0
- package/src/drawing/core/camera.ts +3 -0
- package/src/drawing/core/index.ts +1 -0
- package/src/drawing/render/index.ts +2 -0
- package/src/drawing/render/pageGrid.ts +29 -11
- package/src/drawing/ui/PageField.tsx +104 -0
- package/src/drawing/ui/PageGrid.tsx +48 -0
- package/src/drawing/ui/PageSideInput.tsx +81 -0
- package/src/drawing/ui/PageToolbar.tsx +45 -0
- package/src/drawing/ui/PrintSheets.tsx +57 -0
- package/src/drawing/ui/TextToolIcon.tsx +48 -0
- package/src/drawing/ui/ZoomControl.tsx +112 -0
- package/src/drawing/ui/index.ts +10 -0
- package/src/guide/ui/EmptyGuide.tsx +20 -13
- package/src/guide/ui/GuideFigures.tsx +15 -4
- package/src/host/core/index.ts +7 -0
- package/src/host/core/kinds.ts +7 -2
- package/src/host/core/recordKinds.ts +144 -0
- package/src/mass/core/index.ts +1 -0
- package/src/mass/core/massDomain.ts +9 -3
- package/src/mass/core/massSpectrum.ts +9 -0
- package/src/mass/core/verticalScale.ts +48 -0
- package/src/mass/ui/MassChart.tsx +12 -43
- package/src/mass/ui/massChartLayers.ts +66 -0
- package/src/structure/core/index.ts +1 -0
- package/src/structure/core/structurePicture.ts +78 -4
- package/src/structure/ui/StructureEditor.tsx +13 -2
- package/src/structure/ui/StructureEditorGuide.tsx +35 -0
- package/src/structure/ui/structureEditorProps.ts +11 -1
- package/src/structure/ui/useCanvasPress.ts +69 -0
- package/src/xps/core/detectFormat.ts +9 -0
- package/src/xps/core/xpsEditorApi.ts +16 -0
- package/src/xps/ui/XpsCanvas.tsx +26 -3
- package/src/xps/ui/XpsChart.tsx +12 -56
- package/src/xps/ui/XpsEditor.tsx +10 -0
- package/src/xps/ui/XpsShell.tsx +37 -7
- package/src/xps/ui/dropEvents.ts +16 -1
- package/src/xps/ui/useSpectrumDrop.ts +7 -1
- package/src/xps/ui/useXpsEditorHandle.ts +12 -2
- package/src/xps/ui/useXpsReadout.ts +104 -0
- package/src/xps/ui/xpsChartProps.ts +9 -0
- package/styles/caption-editor.css +15 -1
- package/styles/chrome.css +130 -9
- package/styles/drawing.css +100 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The press that starts a stroke on the structure editor's canvas, which a
|
|
3
|
+
* site's guide makes way for.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { PointerEvent as ReactPointerEvent } from 'react';
|
|
7
|
+
import { useCallback, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { EDITOR_TOOLBAR_WIDTH } from '../core/editorToolbarGeometry.ts';
|
|
10
|
+
|
|
11
|
+
/** Whether a stroke is being drawn, and how to hear the press that starts one. */
|
|
12
|
+
export interface CanvasPress {
|
|
13
|
+
/** Whether the drawing area is held down, which the guide makes way for. */
|
|
14
|
+
pressed: boolean;
|
|
15
|
+
/** Put on the editor's box, in the capture phase. */
|
|
16
|
+
onPointerDownCapture: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hear a press on the drawing area, so the guide goes at the press that starts
|
|
21
|
+
* a stroke rather than once the stroke is reported.
|
|
22
|
+
*
|
|
23
|
+
* A press on the toolbar, on a corner button or on the guide's own buttons is
|
|
24
|
+
* not a stroke. The guide comes back after the release only when the editor
|
|
25
|
+
* has not reported a drawing by then.
|
|
26
|
+
* @returns See {@link CanvasPress}.
|
|
27
|
+
*/
|
|
28
|
+
export function useCanvasPress(): CanvasPress {
|
|
29
|
+
const [pressed, setPressed] = useState(false);
|
|
30
|
+
const onPointerDownCapture = useCallback(
|
|
31
|
+
(event: ReactPointerEvent<HTMLElement>) => {
|
|
32
|
+
if (!onDrawingArea(event)) return;
|
|
33
|
+
setPressed(true);
|
|
34
|
+
function release(): void {
|
|
35
|
+
globalThis.removeEventListener('pointerup', release, true);
|
|
36
|
+
globalThis.removeEventListener('pointercancel', release, true);
|
|
37
|
+
// Once the editor has handled the release too: a stroke that drew
|
|
38
|
+
// something is reported by then, and the guide does not flash back.
|
|
39
|
+
setTimeout(() => setPressed(false), 0);
|
|
40
|
+
}
|
|
41
|
+
// Heard on the way down, which no handler of the canvas can stop.
|
|
42
|
+
globalThis.addEventListener('pointerup', release, true);
|
|
43
|
+
globalThis.addEventListener('pointercancel', release, true);
|
|
44
|
+
},
|
|
45
|
+
[],
|
|
46
|
+
);
|
|
47
|
+
return { pressed, onPointerDownCapture };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether a press landed on the drawing area: on the editor's canvas, and to
|
|
52
|
+
* the right of its toolbar. Both live in the editor's shadow root, so the event
|
|
53
|
+
* names the element holding it.
|
|
54
|
+
* @param event - The press, heard on the editor's box.
|
|
55
|
+
* @returns Whether it starts a stroke.
|
|
56
|
+
*/
|
|
57
|
+
function onDrawingArea(event: ReactPointerEvent<HTMLElement>): boolean {
|
|
58
|
+
const { target, currentTarget, clientX } = event;
|
|
59
|
+
if (!(target instanceof Element) || target.closest(CANVAS) === null) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return clientX - currentTarget.getBoundingClientRect().left > TOOLBAR_EDGE;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The element the openchemlib editor is drawn in. */
|
|
66
|
+
const CANVAS = '[data-openchemlib-canvas-editor]';
|
|
67
|
+
|
|
68
|
+
/** The toolbar's right edge, inside the editor's one-pixel border. */
|
|
69
|
+
const TOOLBAR_EDGE = EDITOR_TOOLBAR_WIDTH + 1;
|
|
@@ -69,6 +69,15 @@ const EXTENSIONS = new Map<string, XpsFormat>([
|
|
|
69
69
|
['xy', 'text'],
|
|
70
70
|
]);
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The extensions the readers know, as a file picker's `accept`: what the
|
|
74
|
+
* picker offers first, while a file it does not name is still read by its
|
|
75
|
+
* content.
|
|
76
|
+
*/
|
|
77
|
+
export const XPS_FILE_ACCEPT = [...EXTENSIONS.keys()]
|
|
78
|
+
.map((extension) => `.${extension}`)
|
|
79
|
+
.join(',');
|
|
80
|
+
|
|
72
81
|
/** The one decoder the header is read through, kept rather than rebuilt. */
|
|
73
82
|
const DECODER = new TextDecoder();
|
|
74
83
|
|
|
@@ -59,6 +59,22 @@ export interface XpsEditorHandle {
|
|
|
59
59
|
setSpectra: (spectra: XpsSpectrum[]) => void;
|
|
60
60
|
/** Close every spectrum and start again from an empty chart. */
|
|
61
61
|
clear: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* Open the viewer's file picker; what is chosen is read as a drop is,
|
|
64
|
+
* joining what is open. A browser opens a picker only for a click, so call
|
|
65
|
+
* it from one — an "Import data…" button of a guide.
|
|
66
|
+
*/
|
|
67
|
+
openFiles: () => void;
|
|
68
|
+
/**
|
|
69
|
+
* Read the clipboard's text as a paste into the viewer is read, joining what
|
|
70
|
+
* is open; what cannot be read is said in the status bar, as for a paste.
|
|
71
|
+
* Call it from a click, which is when a browser lets a page read the
|
|
72
|
+
* clipboard.
|
|
73
|
+
* @returns Resolves once the text is handed to the reader, and rejects when
|
|
74
|
+
* the browser refuses to read the clipboard, so the caller can suggest the
|
|
75
|
+
* paste keys instead.
|
|
76
|
+
*/
|
|
77
|
+
paste: () => Promise<void>;
|
|
62
78
|
/**
|
|
63
79
|
* Frame a binding energy on the chart, keeping the counts axis where it was.
|
|
64
80
|
*
|
package/src/xps/ui/XpsCanvas.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
import { useCallback, useMemo } from 'react';
|
|
2
3
|
|
|
4
|
+
import { TOKEN } from '../../tokens/core/familyTokens.ts';
|
|
3
5
|
import { hasBindingAxis } from '../core/energyAxis.ts';
|
|
4
6
|
import { findSpectrum } from '../core/spectrumGroups.ts';
|
|
5
7
|
import { surveyLinesOf } from '../core/surveyElements.ts';
|
|
@@ -32,6 +34,13 @@ export interface XpsCanvasProps {
|
|
|
32
34
|
* @default false
|
|
33
35
|
*/
|
|
34
36
|
isReading?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* What the empty chart shows in place of its own invitation to drop a
|
|
39
|
+
* spectrum: the site's `<EmptyGuide>`, over the whole chart. Gone while a
|
|
40
|
+
* file is dragged over the chart or read, and once anything is open.
|
|
41
|
+
* @default undefined — the chart's own invitation
|
|
42
|
+
*/
|
|
43
|
+
guide?: ReactNode;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
/**
|
|
@@ -46,12 +55,13 @@ export interface XpsCanvasProps {
|
|
|
46
55
|
* The empty chart says what to do with it rather than showing an axis from 0 to
|
|
47
56
|
* 1 and leaving the question open: the two ways in are a file and a paste, and
|
|
48
57
|
* neither is discoverable from a blank plot. The invitation goes as soon as
|
|
49
|
-
* anything is open, since from then on the axes are the answer.
|
|
58
|
+
* anything is open, since from then on the axes are the answer. A site with a
|
|
59
|
+
* guide of its own passes it as `guide`, and it is drawn instead.
|
|
50
60
|
* @param props - Component props.
|
|
51
61
|
* @returns The canvas side of the split.
|
|
52
62
|
*/
|
|
53
63
|
export function XpsCanvas(props: XpsCanvasProps) {
|
|
54
|
-
const { isOver = false, isReading = false, chartId } = props;
|
|
64
|
+
const { isOver = false, isReading = false, chartId, guide } = props;
|
|
55
65
|
const { state } = useXpsEditorState();
|
|
56
66
|
const actions = useXpsActions();
|
|
57
67
|
const highlight = useXpsHighlight();
|
|
@@ -90,6 +100,7 @@ export function XpsCanvas(props: XpsCanvasProps) {
|
|
|
90
100
|
const { selectedId, openPanelIds, domain } = view;
|
|
91
101
|
const { instruments, instrumentId } = settings;
|
|
92
102
|
const quantifying = openPanelIds.includes('quantification');
|
|
103
|
+
const empty = spectra.length === 0 && !isReading;
|
|
93
104
|
const windows = useMemo(
|
|
94
105
|
() =>
|
|
95
106
|
quantifying
|
|
@@ -115,7 +126,10 @@ export function XpsCanvas(props: XpsCanvasProps) {
|
|
|
115
126
|
isOver={isOver}
|
|
116
127
|
isReading={isReading}
|
|
117
128
|
/>
|
|
118
|
-
{
|
|
129
|
+
{empty && guide !== undefined && !isOver ? (
|
|
130
|
+
<div style={guideStyle}>{guide}</div>
|
|
131
|
+
) : null}
|
|
132
|
+
{empty && guide === undefined ? (
|
|
119
133
|
<div style={inviteStyle}>
|
|
120
134
|
<div style={inviteTitleStyle}>Drop a spectrum here</div>
|
|
121
135
|
<div>
|
|
@@ -169,6 +183,15 @@ const inviteStyle = {
|
|
|
169
183
|
|
|
170
184
|
const inviteTitleStyle = { fontSize: 15, fontWeight: 600 } as const;
|
|
171
185
|
|
|
186
|
+
// Instead of the plot: faint figures over an empty frame of axes read as data
|
|
187
|
+
// drawn on it. The pointer goes through to the chart, which takes the drop.
|
|
188
|
+
const guideStyle = {
|
|
189
|
+
position: 'absolute',
|
|
190
|
+
inset: 0,
|
|
191
|
+
background: TOKEN.surface,
|
|
192
|
+
pointerEvents: 'none',
|
|
193
|
+
} as const;
|
|
194
|
+
|
|
172
195
|
/**
|
|
173
196
|
* The windows the selected survey is quantified over, for the chart to shade
|
|
174
197
|
* while the quantification panel is open.
|
package/src/xps/ui/XpsChart.tsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useId, useMemo, useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { MARGIN, plotRect } from '../../chart/core/chartGeometry.ts';
|
|
5
|
-
import { chartScale
|
|
6
|
-
import type { ChartPoint } from '../../chart/core/svgPoint.ts';
|
|
5
|
+
import { chartScale } from '../../chart/core/chartScale.ts';
|
|
7
6
|
import { Axes } from '../../chart/ui/Axes.tsx';
|
|
8
7
|
import { AxisGuide } from '../../chart/ui/AxisGuide.tsx';
|
|
9
8
|
import { SelectionRect } from '../../chart/ui/SelectionRect.tsx';
|
|
10
|
-
import { useChartPointer } from '../../chart/ui/useChartPointer.ts';
|
|
11
9
|
import { useChartSize } from '../../chart/ui/useChartSize.ts';
|
|
12
10
|
import {
|
|
13
11
|
axisEnergy,
|
|
@@ -17,17 +15,15 @@ import {
|
|
|
17
15
|
countsTitle,
|
|
18
16
|
isAxisReversed,
|
|
19
17
|
} from '../core/energyAxis.ts';
|
|
20
|
-
import type { NearestPeak } from '../core/nearestPeak.ts';
|
|
21
|
-
import { nearestPeakEnergy, sameNearestPeak } from '../core/nearestPeak.ts';
|
|
22
18
|
import { fullDomain } from '../core/xpsDomain.ts';
|
|
23
19
|
import { NO_HIGHLIGHT } from '../core/xpsHighlight.ts';
|
|
24
20
|
import type { XpsDomain } from '../core/xpsSpectrum.ts';
|
|
25
21
|
|
|
26
22
|
import { ChartData } from './ChartData.tsx';
|
|
27
23
|
import { DropOverlay } from './DropOverlay.tsx';
|
|
28
|
-
import type { XpsReadout } from './XpsPointerTracker.tsx';
|
|
29
24
|
import { XpsPointerTracker } from './XpsPointerTracker.tsx';
|
|
30
25
|
import { useXpsGestures } from './useXpsGestures.ts';
|
|
26
|
+
import { useXpsReadout } from './useXpsReadout.ts';
|
|
31
27
|
import type { XpsChartProps } from './xpsChartProps.ts';
|
|
32
28
|
|
|
33
29
|
/**
|
|
@@ -72,15 +68,14 @@ export function XpsChart(props: XpsChartProps): ReactNode {
|
|
|
72
68
|
windows,
|
|
73
69
|
isOver = false,
|
|
74
70
|
isReading = false,
|
|
71
|
+
size,
|
|
75
72
|
} = props;
|
|
76
73
|
|
|
77
74
|
const [containerRef, measured] = useChartSize<HTMLDivElement>();
|
|
78
75
|
const svgRef = useRef<SVGSVGElement | null>(null);
|
|
76
|
+
const { width, height } = size ?? measured;
|
|
79
77
|
|
|
80
|
-
const plot = useMemo(
|
|
81
|
-
() => plotRect({ width: measured.width, height: measured.height }),
|
|
82
|
-
[measured.width, measured.height],
|
|
83
|
-
);
|
|
78
|
+
const plot = useMemo(() => plotRect({ width, height }), [width, height]);
|
|
84
79
|
// Read back off the plot rather than off the measurement, so a chart briefly
|
|
85
80
|
// laid out at nothing still draws its axes inside a box that holds them.
|
|
86
81
|
const frameWidth = plot.right + MARGIN.right;
|
|
@@ -125,42 +120,14 @@ export function XpsChart(props: XpsChartProps): ReactNode {
|
|
|
125
120
|
onPickEnergy,
|
|
126
121
|
});
|
|
127
122
|
|
|
128
|
-
const
|
|
129
|
-
(point: ChartPoint): XpsReadout => ({
|
|
130
|
-
energy: chartValue(xScale, point.x),
|
|
131
|
-
counts: chartValue(yScale, point.y),
|
|
132
|
-
peak: nearestPeakEnergy(spectra, axis, xScale, point.x),
|
|
133
|
-
}),
|
|
134
|
-
[xScale, yScale, spectra, axis],
|
|
135
|
-
);
|
|
136
|
-
// Only a change of peak is reported, starting from none: the pointer coming
|
|
137
|
-
// onto the plot over no peak says nothing, so a guide a panel put on the
|
|
138
|
-
// chart stays until the pointer actually reaches a peak.
|
|
139
|
-
const reportedPeak = useRef<NearestPeak | null>(null);
|
|
140
|
-
const onReadout = useCallback(
|
|
141
|
-
(readout: XpsReadout | null) => {
|
|
142
|
-
const found = readout?.peak ?? null;
|
|
143
|
-
if (sameNearestPeak(reportedPeak.current, found)) return;
|
|
144
|
-
reportedPeak.current = found;
|
|
145
|
-
onHighlightChange?.(
|
|
146
|
-
found === null
|
|
147
|
-
? NO_HIGHLIGHT
|
|
148
|
-
: {
|
|
149
|
-
spectrumId: found.spectrumId,
|
|
150
|
-
peakId: found.peak.id,
|
|
151
|
-
componentId: null,
|
|
152
|
-
bindingEnergy: found.peak.bindingEnergy,
|
|
153
|
-
},
|
|
154
|
-
);
|
|
155
|
-
},
|
|
156
|
-
[onHighlightChange],
|
|
157
|
-
);
|
|
158
|
-
const pointer = useChartPointer<XpsReadout>({
|
|
123
|
+
const pointer = useXpsReadout({
|
|
159
124
|
svgRef,
|
|
160
125
|
plot,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
126
|
+
spectra,
|
|
127
|
+
axis,
|
|
128
|
+
xScale,
|
|
129
|
+
yScale,
|
|
130
|
+
onHighlightChange,
|
|
164
131
|
});
|
|
165
132
|
|
|
166
133
|
const guideEnergy =
|
|
@@ -235,17 +202,6 @@ export function XpsChart(props: XpsChartProps): ReactNode {
|
|
|
235
202
|
);
|
|
236
203
|
}
|
|
237
204
|
|
|
238
|
-
/**
|
|
239
|
-
* Whether two readings are about the same peak, which is all the rest of the
|
|
240
|
-
* viewer hears about: the energy under the crosshair changes on every pixel.
|
|
241
|
-
* @param current - The reading last reported.
|
|
242
|
-
* @param next - The reading now.
|
|
243
|
-
* @returns Whether nothing needs reporting.
|
|
244
|
-
*/
|
|
245
|
-
function samePeakReadout(current: XpsReadout, next: XpsReadout): boolean {
|
|
246
|
-
return sameNearestPeak(current.peak, next.peak);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
205
|
/**
|
|
250
206
|
* The room an energy label wants along the bottom, at its widest: `1200` or
|
|
251
207
|
* `284.8` with the space either side of it.
|
package/src/xps/ui/XpsEditor.tsx
CHANGED
|
@@ -81,6 +81,14 @@ export interface XpsEditorProps {
|
|
|
81
81
|
* @default undefined
|
|
82
82
|
*/
|
|
83
83
|
actions?: ReactNode;
|
|
84
|
+
/**
|
|
85
|
+
* What the empty chart shows in place of its own invitation to drop a
|
|
86
|
+
* spectrum: the site's `<EmptyGuide>`, whose "Import data…" and "Paste"
|
|
87
|
+
* buttons call the handle's `openFiles` and `paste`. Gone while a file is
|
|
88
|
+
* dragged over the chart or read, and once anything is open.
|
|
89
|
+
* @default undefined — the chart's own invitation
|
|
90
|
+
*/
|
|
91
|
+
guide?: ReactNode;
|
|
84
92
|
/**
|
|
85
93
|
* The handle a host drives the viewer through: take these spectra, frame this
|
|
86
94
|
* energy, tell me what is open.
|
|
@@ -123,6 +131,7 @@ export function XpsEditor(props: XpsEditorProps) {
|
|
|
123
131
|
defaultPanelIds,
|
|
124
132
|
panels = NO_PANELS,
|
|
125
133
|
actions,
|
|
134
|
+
guide,
|
|
126
135
|
ref,
|
|
127
136
|
storageKey,
|
|
128
137
|
} = props;
|
|
@@ -162,6 +171,7 @@ export function XpsEditor(props: XpsEditorProps) {
|
|
|
162
171
|
handle={ref}
|
|
163
172
|
panels={panels}
|
|
164
173
|
actions={actions}
|
|
174
|
+
guide={guide}
|
|
165
175
|
/>
|
|
166
176
|
</RootLayout>
|
|
167
177
|
</XpsHighlightProvider>
|
package/src/xps/ui/XpsShell.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ReactNode, Ref } from 'react';
|
|
2
|
-
import { useCallback, useId, useMemo, useState } from 'react';
|
|
1
|
+
import type { ChangeEvent, ReactNode, Ref } from 'react';
|
|
2
|
+
import { useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { sanitizeFileName } from '../../download/core/sanitizeFileName.ts';
|
|
5
5
|
import { useFigureDownload } from '../../download/ui/useFigureDownload.tsx';
|
|
6
6
|
import { FixedPanelRow } from '../../panel/ui/FixedPanelRow.tsx';
|
|
7
7
|
import { PanelRail } from '../../panel/ui/PanelRail.tsx';
|
|
8
|
+
import { XPS_FILE_ACCEPT } from '../core/detectFormat.ts';
|
|
8
9
|
import type { XpsEditorHandle } from '../core/xpsEditorApi.ts';
|
|
9
10
|
import type { XpsSpectrum } from '../core/xpsSpectrum.ts';
|
|
10
11
|
|
|
@@ -16,6 +17,7 @@ import { XpsHeader } from './XpsHeader.tsx';
|
|
|
16
17
|
import { XpsSettingsDialog } from './XpsSettingsDialog.tsx';
|
|
17
18
|
import { XpsSidePanel } from './XpsSidePanel.tsx';
|
|
18
19
|
import { XpsToolbar } from './XpsToolbar.tsx';
|
|
20
|
+
import { readClipboardText } from './dropEvents.ts';
|
|
19
21
|
import { useSpectrumDrop } from './useSpectrumDrop.ts';
|
|
20
22
|
import { useXpsCommandHandlers } from './useXpsCommandHandlers.ts';
|
|
21
23
|
import { useXpsEditorHandle } from './useXpsEditorHandle.ts';
|
|
@@ -40,6 +42,11 @@ export interface XpsShellProps {
|
|
|
40
42
|
* @default undefined
|
|
41
43
|
*/
|
|
42
44
|
actions?: ReactNode;
|
|
45
|
+
/**
|
|
46
|
+
* What the empty chart shows in place of its own invitation.
|
|
47
|
+
* @default undefined — the chart's own invitation
|
|
48
|
+
*/
|
|
49
|
+
guide?: ReactNode;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
@@ -53,15 +60,13 @@ export interface XpsShellProps {
|
|
|
53
60
|
* @returns The screen.
|
|
54
61
|
*/
|
|
55
62
|
export function XpsShell(props: XpsShellProps) {
|
|
56
|
-
const { pasteFromPage, handle, panels, actions: hostActions } = props;
|
|
63
|
+
const { pasteFromPage, handle, panels, actions: hostActions, guide } = props;
|
|
57
64
|
|
|
58
65
|
const { state } = useXpsEditorState();
|
|
59
66
|
const actions = useXpsActions();
|
|
60
67
|
const { spectra } = state.data;
|
|
61
68
|
const side = useXpsSide(panels);
|
|
62
69
|
|
|
63
|
-
useXpsEditorHandle(handle);
|
|
64
|
-
|
|
65
70
|
const [isAboutOpen, setIsAboutOpen] = useState(false);
|
|
66
71
|
const [isDocumentationOpen, setIsDocumentationOpen] = useState(false);
|
|
67
72
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
|
@@ -77,6 +82,15 @@ export function XpsShell(props: XpsShellProps) {
|
|
|
77
82
|
pasteFromPage,
|
|
78
83
|
});
|
|
79
84
|
|
|
85
|
+
// The ways in a guide's buttons reuse: the drop's own reader behind both.
|
|
86
|
+
const fileInput = useRef<HTMLInputElement>(null);
|
|
87
|
+
const openFiles = useCallback(() => fileInput.current?.click(), []);
|
|
88
|
+
const { read, readText, isOver, isReading } = drop;
|
|
89
|
+
const paste = useCallback(async () => {
|
|
90
|
+
readText(await readClipboardText());
|
|
91
|
+
}, [readText]);
|
|
92
|
+
useXpsEditorHandle(handle, { openFiles, paste });
|
|
93
|
+
|
|
80
94
|
// The root is held as state rather than in a ref because the keys are bound
|
|
81
95
|
// to it from an effect: a ref filled in during the commit would leave the
|
|
82
96
|
// effect with nothing to listen on for the first render, and no reason ever
|
|
@@ -130,8 +144,9 @@ export function XpsShell(props: XpsShellProps) {
|
|
|
130
144
|
view={
|
|
131
145
|
<XpsCanvas
|
|
132
146
|
chartId={chartId}
|
|
133
|
-
isOver={
|
|
134
|
-
isReading={
|
|
147
|
+
isOver={isOver}
|
|
148
|
+
isReading={isReading}
|
|
149
|
+
guide={guide}
|
|
135
150
|
/>
|
|
136
151
|
}
|
|
137
152
|
panels={<XpsSidePanel panels={panels} side={side} />}
|
|
@@ -147,6 +162,21 @@ export function XpsShell(props: XpsShellProps) {
|
|
|
147
162
|
/>
|
|
148
163
|
</div>
|
|
149
164
|
</div>
|
|
165
|
+
|
|
166
|
+
<input
|
|
167
|
+
ref={fileInput}
|
|
168
|
+
type="file"
|
|
169
|
+
multiple
|
|
170
|
+
hidden
|
|
171
|
+
accept={XPS_FILE_ACCEPT}
|
|
172
|
+
data-testid="xps-editor-file"
|
|
173
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
174
|
+
const chosen = [...(event.currentTarget.files ?? [])];
|
|
175
|
+
// Emptied so that choosing the same file again is still a change.
|
|
176
|
+
event.currentTarget.value = '';
|
|
177
|
+
read(chosen);
|
|
178
|
+
}}
|
|
179
|
+
/>
|
|
150
180
|
</div>
|
|
151
181
|
|
|
152
182
|
<XpsAboutDialog
|
package/src/xps/ui/dropEvents.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What a drag and a paste actually carry, and whether the viewer should take
|
|
2
|
+
* What a drag and a paste actually carry, and whether the viewer should take
|
|
3
|
+
* it — and, for a Paste button, what the clipboard holds.
|
|
3
4
|
*
|
|
4
5
|
* Kept apart from the hook because these are the decisions rather than the
|
|
5
6
|
* plumbing: a paste into the tolerance box is being typed, a drag of selected
|
|
@@ -50,3 +51,17 @@ export function takePaste(
|
|
|
50
51
|
event.preventDefault();
|
|
51
52
|
readText(text);
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The clipboard's text, for a Paste button: what a paste with the keys would
|
|
57
|
+
* have carried, read without one.
|
|
58
|
+
* @returns The text.
|
|
59
|
+
*/
|
|
60
|
+
export async function readClipboardText(): Promise<string> {
|
|
61
|
+
const clipboard = (globalThis.navigator as Partial<Navigator> | undefined)
|
|
62
|
+
?.clipboard;
|
|
63
|
+
if (clipboard === undefined) {
|
|
64
|
+
throw new Error('This browser lets no page read the clipboard.');
|
|
65
|
+
}
|
|
66
|
+
return clipboard.readText();
|
|
67
|
+
}
|
|
@@ -83,6 +83,12 @@ export interface SpectrumDrop {
|
|
|
83
83
|
* @param files - The files to read.
|
|
84
84
|
*/
|
|
85
85
|
read: (files: FileList | readonly File[]) => void;
|
|
86
|
+
/**
|
|
87
|
+
* Read text as a paste is read — two columns of numbers, a VAMAS or a JCAMP
|
|
88
|
+
* file as text. Stable for the life of the viewer.
|
|
89
|
+
* @param text - The text.
|
|
90
|
+
*/
|
|
91
|
+
readText: (text: string) => void;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
/** The `ref` to put on the viewer's root, and what that root is doing. */
|
|
@@ -238,5 +244,5 @@ export function useSpectrumDrop(
|
|
|
238
244
|
};
|
|
239
245
|
}, [pasteFromPage, read, readText]);
|
|
240
246
|
|
|
241
|
-
return [attach, { isOver, isReading, read }];
|
|
247
|
+
return [attach, { isOver, isReading, read, readText }];
|
|
242
248
|
}
|
|
@@ -23,11 +23,19 @@ import { ENERGY_WINDOW } from '../core/xpsEditorApi.ts';
|
|
|
23
23
|
|
|
24
24
|
import { useXpsActions, useXpsEditorState } from './xpsStateContext.ts';
|
|
25
25
|
|
|
26
|
+
/** The ways in the viewer's screen owns: its file picker and its paste. */
|
|
27
|
+
export type XpsEntryPoints = Pick<XpsEditorHandle, 'openFiles' | 'paste'>;
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* Fill in the handle a host drives the viewer through.
|
|
28
31
|
* @param handle - Where to put it, `undefined` when the host asked for none.
|
|
32
|
+
* @param entry - The file picker and the paste, stable for the viewer's life.
|
|
29
33
|
*/
|
|
30
|
-
export function useXpsEditorHandle(
|
|
34
|
+
export function useXpsEditorHandle(
|
|
35
|
+
handle: Ref<XpsEditorHandle> | undefined,
|
|
36
|
+
entry: XpsEntryPoints,
|
|
37
|
+
) {
|
|
38
|
+
const { openFiles, paste } = entry;
|
|
31
39
|
const { state } = useXpsEditorState();
|
|
32
40
|
const actions = useXpsActions();
|
|
33
41
|
|
|
@@ -48,6 +56,8 @@ export function useXpsEditorHandle(handle: Ref<XpsEditorHandle> | undefined) {
|
|
|
48
56
|
actions.addSpectra(spectra);
|
|
49
57
|
},
|
|
50
58
|
clear: actions.clear,
|
|
59
|
+
openFiles,
|
|
60
|
+
paste,
|
|
51
61
|
zoomToEnergy(bindingEnergy, options) {
|
|
52
62
|
const current = live.current;
|
|
53
63
|
const half = options?.halfWidth ?? ENERGY_WINDOW;
|
|
@@ -70,6 +80,6 @@ export function useXpsEditorHandle(handle: Ref<XpsEditorHandle> | undefined) {
|
|
|
70
80
|
},
|
|
71
81
|
getState: () => live.current,
|
|
72
82
|
}),
|
|
73
|
-
[actions],
|
|
83
|
+
[actions, openFiles, paste],
|
|
74
84
|
);
|
|
75
85
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the pointer reads off the XPS chart, and what of it the rest of the
|
|
3
|
+
* viewer hears: the crosshair follows every pixel, the viewer only the peak.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { RefObject } from 'react';
|
|
7
|
+
import { useCallback, useRef } from 'react';
|
|
8
|
+
|
|
9
|
+
import type { PlotRect } from '../../chart/core/chartGeometry.ts';
|
|
10
|
+
import type { ChartScale } from '../../chart/core/chartScale.ts';
|
|
11
|
+
import { chartValue } from '../../chart/core/chartScale.ts';
|
|
12
|
+
import type { ChartPoint } from '../../chart/core/svgPoint.ts';
|
|
13
|
+
import type { ChartPointer } from '../../chart/ui/useChartPointer.ts';
|
|
14
|
+
import { useChartPointer } from '../../chart/ui/useChartPointer.ts';
|
|
15
|
+
import type { NearestPeak } from '../core/nearestPeak.ts';
|
|
16
|
+
import { nearestPeakEnergy, sameNearestPeak } from '../core/nearestPeak.ts';
|
|
17
|
+
import type { XpsHighlight } from '../core/xpsHighlight.ts';
|
|
18
|
+
import { NO_HIGHLIGHT } from '../core/xpsHighlight.ts';
|
|
19
|
+
import type { EnergyAxis } from '../core/xpsSettings.ts';
|
|
20
|
+
import type { XpsSpectrum } from '../core/xpsSpectrum.ts';
|
|
21
|
+
|
|
22
|
+
import type { XpsReadout } from './XpsPointerTracker.tsx';
|
|
23
|
+
|
|
24
|
+
/** What {@link useXpsReadout} reads the pointer against. */
|
|
25
|
+
export interface XpsReadoutOptions {
|
|
26
|
+
/** The chart's SVG, which the pointer is heard on. */
|
|
27
|
+
svgRef: RefObject<SVGSVGElement | null>;
|
|
28
|
+
/** The plot, outside which the pointer reads nothing. */
|
|
29
|
+
plot: PlotRect;
|
|
30
|
+
/** The spectra drawn, whose peaks the pointer is nearest to. */
|
|
31
|
+
spectra: readonly XpsSpectrum[];
|
|
32
|
+
/** The energy axis the chart is drawn against. */
|
|
33
|
+
axis: EnergyAxis;
|
|
34
|
+
/** The energy scale on screen. */
|
|
35
|
+
xScale: ChartScale;
|
|
36
|
+
/** The counts scale on screen. */
|
|
37
|
+
yScale: ChartScale;
|
|
38
|
+
/**
|
|
39
|
+
* Told whenever the peak under the pointer changes.
|
|
40
|
+
* @default undefined
|
|
41
|
+
*/
|
|
42
|
+
onHighlightChange?: (highlight: XpsHighlight) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Follow the pointer over the chart, and tell the viewer which peak it is on.
|
|
47
|
+
*
|
|
48
|
+
* Only a change of peak is reported, starting from none: the pointer coming
|
|
49
|
+
* onto the plot over no peak says nothing, so a guide a panel put on the chart
|
|
50
|
+
* stays until the pointer actually reaches a peak.
|
|
51
|
+
* @param options - See {@link XpsReadoutOptions}.
|
|
52
|
+
* @returns Where the pointer is and what it reads.
|
|
53
|
+
*/
|
|
54
|
+
export function useXpsReadout(
|
|
55
|
+
options: XpsReadoutOptions,
|
|
56
|
+
): ChartPointer<XpsReadout> {
|
|
57
|
+
const { svgRef, plot, spectra, axis, xScale, yScale, onHighlightChange } =
|
|
58
|
+
options;
|
|
59
|
+
const read = useCallback(
|
|
60
|
+
(point: ChartPoint): XpsReadout => ({
|
|
61
|
+
energy: chartValue(xScale, point.x),
|
|
62
|
+
counts: chartValue(yScale, point.y),
|
|
63
|
+
peak: nearestPeakEnergy(spectra, axis, xScale, point.x),
|
|
64
|
+
}),
|
|
65
|
+
[xScale, yScale, spectra, axis],
|
|
66
|
+
);
|
|
67
|
+
const reportedPeak = useRef<NearestPeak | null>(null);
|
|
68
|
+
const onReadout = useCallback(
|
|
69
|
+
(readout: XpsReadout | null) => {
|
|
70
|
+
const found = readout?.peak ?? null;
|
|
71
|
+
if (sameNearestPeak(reportedPeak.current, found)) return;
|
|
72
|
+
reportedPeak.current = found;
|
|
73
|
+
onHighlightChange?.(
|
|
74
|
+
found === null
|
|
75
|
+
? NO_HIGHLIGHT
|
|
76
|
+
: {
|
|
77
|
+
spectrumId: found.spectrumId,
|
|
78
|
+
peakId: found.peak.id,
|
|
79
|
+
componentId: null,
|
|
80
|
+
bindingEnergy: found.peak.bindingEnergy,
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
[onHighlightChange],
|
|
85
|
+
);
|
|
86
|
+
return useChartPointer<XpsReadout>({
|
|
87
|
+
svgRef,
|
|
88
|
+
plot,
|
|
89
|
+
read,
|
|
90
|
+
sameReadout: samePeakReadout,
|
|
91
|
+
onReadout,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether two readings are about the same peak, which is all the rest of the
|
|
97
|
+
* viewer hears about: the energy under the crosshair changes on every pixel.
|
|
98
|
+
* @param current - The reading last reported.
|
|
99
|
+
* @param next - The reading now.
|
|
100
|
+
* @returns Whether nothing needs reporting.
|
|
101
|
+
*/
|
|
102
|
+
function samePeakReadout(current: XpsReadout, next: XpsReadout): boolean {
|
|
103
|
+
return sameNearestPeak(current.peak, next.peak);
|
|
104
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* test.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import type { ChartSize } from '../../chart/core/chartGeometry.ts';
|
|
15
16
|
import type { XpsHighlight } from '../core/xpsHighlight.ts';
|
|
16
17
|
import type { XpsDomain, XpsRegion, XpsSpectrum } from '../core/xpsSpectrum.ts';
|
|
17
18
|
import type { XpsSettings } from '../core/xpsState.ts';
|
|
@@ -66,6 +67,14 @@ export interface XpsChartProps {
|
|
|
66
67
|
* @default false
|
|
67
68
|
*/
|
|
68
69
|
isReading?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The size to draw at, in CSS pixels, instead of the box the chart is put in
|
|
72
|
+
* — for a chart drawn where nothing is laid out, as a figure written to a
|
|
73
|
+
* file by `renderToStaticMarkup`, which would otherwise come out at the
|
|
74
|
+
* smallest plot there is.
|
|
75
|
+
* @default undefined — the box the chart is put in, measured
|
|
76
|
+
*/
|
|
77
|
+
size?: ChartSize;
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
/** Windows shaded on the chart for one spectrum, beside the ones its file defines. */
|
|
@@ -92,10 +92,18 @@
|
|
|
92
92
|
font-family: inherit;
|
|
93
93
|
font-size: 13px;
|
|
94
94
|
gap: 4px;
|
|
95
|
-
|
|
95
|
+
/* Centred over its caption, then moved back inside the figure when the
|
|
96
|
+
caption sits near an edge (`useToolbarInView`). */
|
|
97
|
+
transform: translateX(calc(-50% + var(--caption-toolbar-shift, 0px)));
|
|
96
98
|
white-space: nowrap;
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
/* With no room above the caption, the bar goes under it. */
|
|
102
|
+
.caption-toolbar[data-below] {
|
|
103
|
+
top: calc(100% + 4px);
|
|
104
|
+
bottom: auto;
|
|
105
|
+
}
|
|
106
|
+
|
|
99
107
|
.caption-toolbar__size {
|
|
100
108
|
display: flex;
|
|
101
109
|
align-items: center;
|
|
@@ -109,3 +117,9 @@
|
|
|
109
117
|
.caption-toolbar__unit {
|
|
110
118
|
color: var(--text-muted);
|
|
111
119
|
}
|
|
120
|
+
|
|
121
|
+
/* The tick keeps the caption: it stands apart from the styles. */
|
|
122
|
+
.caption-toolbar__done {
|
|
123
|
+
padding-left: 4px;
|
|
124
|
+
border-left: 1px solid var(--border);
|
|
125
|
+
}
|