react-cheminfo 0.131.0 → 0.133.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 +29 -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/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/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +4 -0
- package/lib/locales/en.json +4 -0
- package/lib/locales/es.json +4 -0
- package/lib/locales/fr.json +4 -0
- package/lib/locales/it.json +4 -0
- package/lib/log/core/index.d.ts +4 -0
- package/lib/log/core/index.d.ts.map +1 -0
- package/lib/log/core/index.js +3 -0
- package/lib/log/core/index.js.map +1 -0
- package/lib/log/core/logGroups.d.ts +87 -0
- package/lib/log/core/logGroups.d.ts.map +1 -0
- package/lib/log/core/logGroups.js +85 -0
- package/lib/log/core/logGroups.js.map +1 -0
- package/lib/log/core/logLines.d.ts +19 -0
- package/lib/log/core/logLines.d.ts.map +1 -0
- package/lib/log/core/logLines.js +36 -0
- package/lib/log/core/logLines.js.map +1 -0
- package/lib/log/ui/LogBadge.d.ts +39 -0
- package/lib/log/ui/LogBadge.d.ts.map +1 -0
- package/lib/log/ui/LogBadge.js +28 -0
- package/lib/log/ui/LogBadge.js.map +1 -0
- package/lib/log/ui/LogCallouts.d.ts +55 -0
- package/lib/log/ui/LogCallouts.d.ts.map +1 -0
- package/lib/log/ui/LogCallouts.js +38 -0
- package/lib/log/ui/LogCallouts.js.map +1 -0
- package/lib/log/ui/index.d.ts +7 -0
- package/lib/log/ui/index.d.ts.map +1 -0
- package/lib/log/ui/index.js +5 -0
- package/lib/log/ui/index.js.map +1 -0
- package/lib/log/ui/logIcon.d.ts +9 -0
- package/lib/log/ui/logIcon.d.ts.map +1 -0
- package/lib/log/ui/logIcon.js +17 -0
- package/lib/log/ui/logIcon.js.map +1 -0
- package/lib/log/ui/useLogEntries.d.ts +15 -0
- package/lib/log/ui/useLogEntries.d.ts.map +1 -0
- package/lib/log/ui/useLogEntries.js +47 -0
- package/lib/log/ui/useLogEntries.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/conformerMinimise.d.ts +13 -4
- package/lib/structure/core/conformerMinimise.d.ts.map +1 -1
- package/lib/structure/core/conformerMinimise.js +23 -6
- package/lib/structure/core/conformerMinimise.js.map +1 -1
- package/lib/structure/core/conformerRefine.d.ts +2 -2
- package/lib/structure/core/conformerRefine.d.ts.map +1 -1
- package/lib/structure/core/conformerRefine.js +23 -7
- package/lib/structure/core/conformerRefine.js.map +1 -1
- package/lib/structure/core/conformers.d.ts +8 -3
- package/lib/structure/core/conformers.d.ts.map +1 -1
- package/lib/structure/core/conformers.js +10 -7
- package/lib/structure/core/conformers.js.map +1 -1
- package/lib/structure/core/geometryRelaxer.d.ts +10 -3
- package/lib/structure/core/geometryRelaxer.d.ts.map +1 -1
- 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/relaxerLogLines.d.ts +16 -0
- package/lib/structure/core/relaxerLogLines.d.ts.map +1 -0
- package/lib/structure/core/relaxerLogLines.js +33 -0
- package/lib/structure/core/relaxerLogLines.js.map +1 -0
- 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/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/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/lib/xtb/core/taggedLogger.d.ts +11 -0
- package/lib/xtb/core/taggedLogger.d.ts.map +1 -0
- package/lib/xtb/core/taggedLogger.js +31 -0
- package/lib/xtb/core/taggedLogger.js.map +1 -0
- package/lib/xtb/core/xtbRelaxer.d.ts.map +1 -1
- package/lib/xtb/core/xtbRelaxer.js +13 -5
- package/lib/xtb/core/xtbRelaxer.js.map +1 -1
- package/package.json +4 -3
- package/src/core.ts +1 -0
- 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/locales/de.json +4 -0
- package/src/locales/en.json +4 -0
- package/src/locales/es.json +4 -0
- package/src/locales/fr.json +4 -0
- package/src/locales/it.json +4 -0
- package/src/log/core/index.ts +9 -0
- package/src/log/core/logGroups.ts +159 -0
- package/src/log/core/logLines.ts +44 -0
- package/src/log/ui/LogBadge.tsx +89 -0
- package/src/log/ui/LogCallouts.tsx +103 -0
- package/src/log/ui/index.ts +6 -0
- package/src/log/ui/logIcon.ts +21 -0
- package/src/log/ui/useLogEntries.ts +57 -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/conformerMinimise.ts +34 -8
- package/src/structure/core/conformerRefine.ts +29 -13
- package/src/structure/core/conformers.ts +23 -12
- package/src/structure/core/geometryRelaxer.ts +11 -3
- package/src/structure/core/index.ts +1 -0
- package/src/structure/core/relaxerLogLines.ts +39 -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/ui.ts +1 -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/src/xtb/core/taggedLogger.ts +35 -0
- package/src/xtb/core/xtbRelaxer.ts +15 -5
- package/styles/caption-editor.css +15 -1
- package/styles/chrome.css +164 -9
- package/styles/drawing.css +100 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** A level a log entry carries, as fifo-logger and pino label it. */
|
|
2
|
+
export type LogLevelLabel =
|
|
3
|
+
'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
4
|
+
|
|
5
|
+
/** How a message reads on the page, in Blueprint's intents. */
|
|
6
|
+
export type LogIntent = 'danger' | 'warning' | 'primary' | 'none';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* One logged message, as the page reads it. A fifo-logger `LogEntry` is one;
|
|
10
|
+
* so is a plain object a site writes for a caveat that is always true, or one
|
|
11
|
+
* read back from a saved file.
|
|
12
|
+
*
|
|
13
|
+
* Two keys of `meta` are shown: a string `title` heads the message, and a
|
|
14
|
+
* string `source` — a file, a line, the third conformer — labels where it
|
|
15
|
+
* comes from, so the message itself never has to name it.
|
|
16
|
+
*/
|
|
17
|
+
export interface LogLine {
|
|
18
|
+
/** The level it was logged at; `silent` entries are never shown. */
|
|
19
|
+
levelLabel: LogLevelLabel | 'silent';
|
|
20
|
+
/** The message. */
|
|
21
|
+
message: string;
|
|
22
|
+
/**
|
|
23
|
+
* What was logged with it.
|
|
24
|
+
* @default undefined
|
|
25
|
+
*/
|
|
26
|
+
meta?: Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* The error that was logged, whose own message is shown.
|
|
29
|
+
* @default undefined
|
|
30
|
+
*/
|
|
31
|
+
error?: Error;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One message as the page shows it: every entry that said it, once. */
|
|
35
|
+
export interface LogGroup {
|
|
36
|
+
/** The same for the same level, source, title and text. */
|
|
37
|
+
key: string;
|
|
38
|
+
/** The level it was logged at. */
|
|
39
|
+
level: LogLevelLabel;
|
|
40
|
+
/**
|
|
41
|
+
* Where it comes from, from a string `source` in the meta.
|
|
42
|
+
* @default undefined
|
|
43
|
+
*/
|
|
44
|
+
source?: string;
|
|
45
|
+
/**
|
|
46
|
+
* A heading for the message, from a string `title` in the meta.
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
title?: string;
|
|
50
|
+
/** The message, or the logged error's own message. */
|
|
51
|
+
text: string;
|
|
52
|
+
/** How many entries said it. */
|
|
53
|
+
count: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Which entries {@link groupLogEntries} keeps. */
|
|
57
|
+
export interface LogGroupOptions {
|
|
58
|
+
/**
|
|
59
|
+
* The least serious level shown. Debug and trace are for a developer, so
|
|
60
|
+
* they stay out of the page unless asked for.
|
|
61
|
+
* @default 'info'
|
|
62
|
+
*/
|
|
63
|
+
minLevel?: LogLevelLabel;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The messages a page shows for some log entries: the same message said twice
|
|
68
|
+
* once, with its count, and the most serious first. Within one level the
|
|
69
|
+
* messages keep the order they were first said in, which is the order the
|
|
70
|
+
* work happened in.
|
|
71
|
+
*
|
|
72
|
+
* Entries from several loggers can be passed together, so what a run reported
|
|
73
|
+
* and what a model always says about its results read as one list.
|
|
74
|
+
* @param lines - What one or more loggers collected.
|
|
75
|
+
* @param options - See {@link LogGroupOptions}.
|
|
76
|
+
* @returns The messages to show, worst first.
|
|
77
|
+
*/
|
|
78
|
+
export function groupLogEntries(
|
|
79
|
+
lines: readonly LogLine[],
|
|
80
|
+
options: LogGroupOptions = {},
|
|
81
|
+
): LogGroup[] {
|
|
82
|
+
const minimum = SEVERITY[options.minLevel ?? 'info'];
|
|
83
|
+
const groups = new Map<string, LogGroup>();
|
|
84
|
+
for (const line of lines) {
|
|
85
|
+
const level = line.levelLabel;
|
|
86
|
+
if (level === 'silent' || SEVERITY[level] < minimum) continue;
|
|
87
|
+
const source = metaString(line, 'source');
|
|
88
|
+
const title = metaString(line, 'title');
|
|
89
|
+
const text = line.error?.message ?? line.message;
|
|
90
|
+
const key = [level, source ?? '', title ?? '', text].join('\u0000');
|
|
91
|
+
const group = groups.get(key);
|
|
92
|
+
if (group === undefined) {
|
|
93
|
+
groups.set(key, {
|
|
94
|
+
key,
|
|
95
|
+
level,
|
|
96
|
+
...(source === undefined ? {} : { source }),
|
|
97
|
+
...(title === undefined ? {} : { title }),
|
|
98
|
+
text,
|
|
99
|
+
count: 1,
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
group.count++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return [...groups.values()].toSorted(
|
|
106
|
+
(first, second) => SEVERITY[second.level] - SEVERITY[first.level],
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The most serious level among some messages: the one a single indicator
|
|
112
|
+
* standing for all of them is drawn in.
|
|
113
|
+
* @param groups - Messages from {@link groupLogEntries}.
|
|
114
|
+
* @returns The worst level, or `null` when there is no message.
|
|
115
|
+
*/
|
|
116
|
+
export function worstLogLevel(
|
|
117
|
+
groups: readonly LogGroup[],
|
|
118
|
+
): LogLevelLabel | null {
|
|
119
|
+
let worst: LogLevelLabel | null = null;
|
|
120
|
+
for (const group of groups) {
|
|
121
|
+
if (worst === null || SEVERITY[group.level] > SEVERITY[worst]) {
|
|
122
|
+
worst = group.level;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return worst;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The intent a message of this level is drawn in: an error in red, a warning
|
|
130
|
+
* in amber, context in the primary blue.
|
|
131
|
+
* @param level - The level it was logged at.
|
|
132
|
+
* @returns A Blueprint intent.
|
|
133
|
+
*/
|
|
134
|
+
export function logIntent(level: LogLevelLabel): LogIntent {
|
|
135
|
+
return INTENTS[level];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const SEVERITY: Record<LogLevelLabel, number> = {
|
|
139
|
+
trace: 10,
|
|
140
|
+
debug: 20,
|
|
141
|
+
info: 30,
|
|
142
|
+
warn: 40,
|
|
143
|
+
error: 50,
|
|
144
|
+
fatal: 60,
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const INTENTS: Record<LogLevelLabel, LogIntent> = {
|
|
148
|
+
trace: 'none',
|
|
149
|
+
debug: 'none',
|
|
150
|
+
info: 'primary',
|
|
151
|
+
warn: 'warning',
|
|
152
|
+
error: 'danger',
|
|
153
|
+
fatal: 'danger',
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
function metaString(line: LogLine, key: string): string | undefined {
|
|
157
|
+
const value = line.meta?.[key];
|
|
158
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
159
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { LogGroupOptions, LogLine } from './logGroups.ts';
|
|
2
|
+
import { groupLogEntries } from './logGroups.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Log entries as plain data, to keep with a result, save in a file or post
|
|
6
|
+
* across a worker: a logged error becomes its message, and nothing else of a
|
|
7
|
+
* fifo-logger entry — its id, time and logger uuids — is kept.
|
|
8
|
+
* @param lines - What a logger collected.
|
|
9
|
+
* @returns The same messages, as plain objects in the same order.
|
|
10
|
+
*/
|
|
11
|
+
export function plainLogLines(lines: readonly LogLine[]): LogLine[] {
|
|
12
|
+
const plain: LogLine[] = [];
|
|
13
|
+
for (const line of lines) {
|
|
14
|
+
plain.push({
|
|
15
|
+
levelLabel: line.levelLabel,
|
|
16
|
+
message: line.error?.message ?? line.message,
|
|
17
|
+
...(line.meta === undefined ? {} : { meta: line.meta }),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return plain;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The messages as sentences, for an answer that carries text rather than a
|
|
25
|
+
* page: an MCP tool, a host's reply, a status line. Each message comes once,
|
|
26
|
+
* the worst first, prefixed by where it comes from and led by its title.
|
|
27
|
+
* @param lines - What one or more loggers collected.
|
|
28
|
+
* @param options - See {@link LogGroupOptions}.
|
|
29
|
+
* @returns One sentence per distinct message.
|
|
30
|
+
*/
|
|
31
|
+
export function logMessages(
|
|
32
|
+
lines: readonly LogLine[],
|
|
33
|
+
options: LogGroupOptions = {},
|
|
34
|
+
): string[] {
|
|
35
|
+
const messages: string[] = [];
|
|
36
|
+
for (const group of groupLogEntries(lines, options)) {
|
|
37
|
+
const text =
|
|
38
|
+
group.title === undefined ? group.text : `${group.title}. ${group.text}`;
|
|
39
|
+
messages.push(
|
|
40
|
+
group.source === undefined ? text : `${group.source}: ${text}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return messages;
|
|
44
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { PopoverNextProps } from '@blueprintjs/core';
|
|
2
|
+
import { Button, PopoverNext } from '@blueprintjs/core';
|
|
3
|
+
import type { ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
6
|
+
import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
|
|
7
|
+
import type { LogLevelLabel, LogLine } from '../core/logGroups.ts';
|
|
8
|
+
import {
|
|
9
|
+
groupLogEntries,
|
|
10
|
+
logIntent,
|
|
11
|
+
worstLogLevel,
|
|
12
|
+
} from '../core/logGroups.ts';
|
|
13
|
+
|
|
14
|
+
import { LogGroupList } from './LogCallouts.tsx';
|
|
15
|
+
import { logIcon } from './logIcon.ts';
|
|
16
|
+
|
|
17
|
+
/** Props of {@link LogBadge}. */
|
|
18
|
+
export interface LogBadgeProps {
|
|
19
|
+
/** What one or more loggers collected, in the order they logged it. */
|
|
20
|
+
entries: readonly LogLine[];
|
|
21
|
+
/**
|
|
22
|
+
* The least serious level shown.
|
|
23
|
+
* @default 'info'
|
|
24
|
+
*/
|
|
25
|
+
minLevel?: LogLevelLabel;
|
|
26
|
+
/**
|
|
27
|
+
* How many messages the popover shows before the rest are counted instead.
|
|
28
|
+
* @default every message
|
|
29
|
+
*/
|
|
30
|
+
limit?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Which side the messages open on.
|
|
33
|
+
* @default 'bottom-start'
|
|
34
|
+
*/
|
|
35
|
+
placement?: PopoverNextProps['placement'];
|
|
36
|
+
/**
|
|
37
|
+
* Class names added to the button.
|
|
38
|
+
* @default undefined
|
|
39
|
+
*/
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One small button standing for every message a logger collected about what
|
|
45
|
+
* sits beside it, drawn in the colour of the most serious and counting them,
|
|
46
|
+
* which opens them all as callouts on hover. The messages stay one pointer
|
|
47
|
+
* away from the chart or the result they qualify instead of pushing it down
|
|
48
|
+
* the page.
|
|
49
|
+
* @param props - See {@link LogBadgeProps}.
|
|
50
|
+
* @returns The button, or nothing when there is no message to show.
|
|
51
|
+
*/
|
|
52
|
+
export function LogBadge(props: LogBadgeProps): ReactElement | null {
|
|
53
|
+
const {
|
|
54
|
+
entries,
|
|
55
|
+
minLevel,
|
|
56
|
+
limit,
|
|
57
|
+
placement = 'bottom-start',
|
|
58
|
+
className,
|
|
59
|
+
} = props;
|
|
60
|
+
const t = useChromeT();
|
|
61
|
+
const groups = groupLogEntries(entries, { minLevel });
|
|
62
|
+
const worst = worstLogLevel(groups);
|
|
63
|
+
if (worst === null) return null;
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<PopoverNext
|
|
67
|
+
interactionKind="hover"
|
|
68
|
+
hoverOpenDelay={150}
|
|
69
|
+
placement={placement}
|
|
70
|
+
popoverClassName="log-badge__popover"
|
|
71
|
+
content={<LogGroupList groups={groups} limit={limit} />}
|
|
72
|
+
>
|
|
73
|
+
<Button
|
|
74
|
+
variant="minimal"
|
|
75
|
+
size="small"
|
|
76
|
+
intent={logIntent(worst)}
|
|
77
|
+
icon={logIcon(worst)}
|
|
78
|
+
className={joinClassNames('log-badge', 'no-print', className)}
|
|
79
|
+
aria-label={
|
|
80
|
+
groups.length === 1
|
|
81
|
+
? t('log.badge.one')
|
|
82
|
+
: t('log.badge.other', { count: groups.length })
|
|
83
|
+
}
|
|
84
|
+
>
|
|
85
|
+
{groups.length > 1 ? groups.length : undefined}
|
|
86
|
+
</Button>
|
|
87
|
+
</PopoverNext>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Callout } from '@blueprintjs/core';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
5
|
+
import { InlineText } from '../../pedagogy/ui/InlineText.tsx';
|
|
6
|
+
import { joinClassNames } from '../../shared/ui/joinClassNames.ts';
|
|
7
|
+
import type { LogGroup, LogLevelLabel, LogLine } from '../core/logGroups.ts';
|
|
8
|
+
import { groupLogEntries, logIntent } from '../core/logGroups.ts';
|
|
9
|
+
|
|
10
|
+
import { logIcon } from './logIcon.ts';
|
|
11
|
+
|
|
12
|
+
/** Props of {@link LogCallouts}. */
|
|
13
|
+
export interface LogCalloutsProps {
|
|
14
|
+
/** What one or more loggers collected, in the order they logged it. */
|
|
15
|
+
entries: readonly LogLine[];
|
|
16
|
+
/**
|
|
17
|
+
* The least serious level shown.
|
|
18
|
+
* @default 'info'
|
|
19
|
+
*/
|
|
20
|
+
minLevel?: LogLevelLabel;
|
|
21
|
+
/**
|
|
22
|
+
* How many messages are shown before the rest are counted instead.
|
|
23
|
+
* @default every message
|
|
24
|
+
*/
|
|
25
|
+
limit?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Class names added to the list.
|
|
28
|
+
* @default undefined
|
|
29
|
+
*/
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* What a logger collected, as callouts in the page: one per distinct message,
|
|
35
|
+
* the most serious first, each in the colour and with the icon of its level.
|
|
36
|
+
*
|
|
37
|
+
* A message is authored prose — `` `code` ``, `{{CO2}}`, `**strong**`. A string
|
|
38
|
+
* `title` in its meta heads it and a string `source` labels where it comes
|
|
39
|
+
* from. A message said several times is shown once, with how many times.
|
|
40
|
+
* @param props - See {@link LogCalloutsProps}.
|
|
41
|
+
* @returns The callouts, or nothing when there is no message to show.
|
|
42
|
+
*/
|
|
43
|
+
export function LogCallouts(props: LogCalloutsProps): ReactElement | null {
|
|
44
|
+
const { entries, minLevel, limit, className } = props;
|
|
45
|
+
const groups = groupLogEntries(entries, { minLevel });
|
|
46
|
+
if (groups.length === 0) return null;
|
|
47
|
+
return <LogGroupList groups={groups} limit={limit} className={className} />;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Props of {@link LogGroupList}. */
|
|
51
|
+
export interface LogGroupListProps {
|
|
52
|
+
/** The messages, as {@link groupLogEntries} ordered them. */
|
|
53
|
+
groups: readonly LogGroup[];
|
|
54
|
+
/**
|
|
55
|
+
* How many messages are shown before the rest are counted instead.
|
|
56
|
+
* @default every message
|
|
57
|
+
*/
|
|
58
|
+
limit?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Class names added to the list.
|
|
61
|
+
* @default undefined
|
|
62
|
+
*/
|
|
63
|
+
className?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Messages already grouped, as callouts.
|
|
68
|
+
* @param props - See {@link LogGroupListProps}.
|
|
69
|
+
* @returns The callouts.
|
|
70
|
+
*/
|
|
71
|
+
export function LogGroupList(props: LogGroupListProps): ReactElement {
|
|
72
|
+
const { groups, limit = groups.length, className } = props;
|
|
73
|
+
const t = useChromeT();
|
|
74
|
+
const hidden = Math.max(0, groups.length - limit);
|
|
75
|
+
return (
|
|
76
|
+
<div className={joinClassNames('log-callouts', className)}>
|
|
77
|
+
{groups.slice(0, limit).map((group) => (
|
|
78
|
+
<Callout
|
|
79
|
+
key={group.key}
|
|
80
|
+
compact
|
|
81
|
+
intent={logIntent(group.level)}
|
|
82
|
+
icon={logIcon(group.level)}
|
|
83
|
+
title={group.title}
|
|
84
|
+
>
|
|
85
|
+
{group.source !== undefined && (
|
|
86
|
+
<span className="log-callouts__source">{group.source}</span>
|
|
87
|
+
)}
|
|
88
|
+
<InlineText text={group.text} />
|
|
89
|
+
{group.count > 1 && (
|
|
90
|
+
<span className="log-callouts__count">×{group.count}</span>
|
|
91
|
+
)}
|
|
92
|
+
</Callout>
|
|
93
|
+
))}
|
|
94
|
+
{hidden > 0 && (
|
|
95
|
+
<span className="log-callouts__more">
|
|
96
|
+
{hidden === 1
|
|
97
|
+
? t('log.more.one')
|
|
98
|
+
: t('log.more.other', { count: hidden })}
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { LogBadgeProps } from './LogBadge.tsx';
|
|
2
|
+
export { LogBadge } from './LogBadge.tsx';
|
|
3
|
+
export type { LogCalloutsProps, LogGroupListProps } from './LogCallouts.tsx';
|
|
4
|
+
export { LogCallouts, LogGroupList } from './LogCallouts.tsx';
|
|
5
|
+
export { logIcon } from './logIcon.ts';
|
|
6
|
+
export { useLogEntries } from './useLogEntries.ts';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IconName } from '@blueprintjs/core';
|
|
2
|
+
|
|
3
|
+
import type { LogLevelLabel } from '../core/logGroups.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The icon a message of this level is shown with.
|
|
7
|
+
* @param level - The level it was logged at.
|
|
8
|
+
* @returns A Blueprint icon name.
|
|
9
|
+
*/
|
|
10
|
+
export function logIcon(level: LogLevelLabel): IconName {
|
|
11
|
+
return ICONS[level];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ICONS: Record<LogLevelLabel, IconName> = {
|
|
15
|
+
trace: 'console',
|
|
16
|
+
debug: 'console',
|
|
17
|
+
info: 'info-sign',
|
|
18
|
+
warn: 'warning-sign',
|
|
19
|
+
error: 'error',
|
|
20
|
+
fatal: 'error',
|
|
21
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { FifoLogger, LogEntry } from 'fifo-logger';
|
|
2
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What a logger holds, kept up to date as it logs: a page shows the messages
|
|
6
|
+
* of a long run while it is still running, and the list redraws only when
|
|
7
|
+
* something was logged.
|
|
8
|
+
*
|
|
9
|
+
* The logger is named, never read from a context: each result keeps a logger
|
|
10
|
+
* of its own, so a new run replaces its own messages and leaves the others'.
|
|
11
|
+
* react-science's `useFifoLogs` is for the one page-wide logger its
|
|
12
|
+
* `FifoLoggerProvider` holds.
|
|
13
|
+
* @param logger - The logger to read, or nothing while there is none.
|
|
14
|
+
* @returns Its entries, the same array until it logs again.
|
|
15
|
+
*/
|
|
16
|
+
export function useLogEntries(
|
|
17
|
+
logger: FifoLogger | null | undefined,
|
|
18
|
+
): readonly LogEntry[] {
|
|
19
|
+
const subscribe = useCallback(
|
|
20
|
+
(onChange: () => void) => {
|
|
21
|
+
if (logger == null) return noSubscription;
|
|
22
|
+
const listener = () => {
|
|
23
|
+
snapshots.delete(logger);
|
|
24
|
+
onChange();
|
|
25
|
+
};
|
|
26
|
+
logger.addEventListener('change', listener);
|
|
27
|
+
return () => {
|
|
28
|
+
logger.removeEventListener('change', listener);
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
[logger],
|
|
32
|
+
);
|
|
33
|
+
const read = useCallback(() => snapshotOf(logger), [logger]);
|
|
34
|
+
return useSyncExternalStore(subscribe, read, read);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// One array per logger until it logs again: `getLogs` builds a new one on every
|
|
38
|
+
// call, and a store has to answer the same value while nothing changed.
|
|
39
|
+
const snapshots = new WeakMap<FifoLogger, readonly LogEntry[]>();
|
|
40
|
+
|
|
41
|
+
const NO_ENTRIES: readonly LogEntry[] = [];
|
|
42
|
+
|
|
43
|
+
function snapshotOf(
|
|
44
|
+
logger: FifoLogger | null | undefined,
|
|
45
|
+
): readonly LogEntry[] {
|
|
46
|
+
if (logger == null) return NO_ENTRIES;
|
|
47
|
+
let entries = snapshots.get(logger);
|
|
48
|
+
if (entries === undefined) {
|
|
49
|
+
entries = logger.getLogs({ includeChildren: true });
|
|
50
|
+
snapshots.set(logger, entries);
|
|
51
|
+
}
|
|
52
|
+
return entries;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function noSubscription(): void {
|
|
56
|
+
// Nothing was subscribed to.
|
|
57
|
+
}
|
package/src/mass/core/index.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { xMaxValue } from 'ml-spectra-processing';
|
|
12
12
|
|
|
13
13
|
import type { MassDomain, MassSpectrum, MassTrace } from './massSpectrum.ts';
|
|
14
|
+
import { verticalScaleOf } from './verticalScale.ts';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* How much air is left either side of the outermost peak, as a fraction.
|
|
@@ -191,10 +192,13 @@ function traceExtent(
|
|
|
191
192
|
let extent: TraceExtent | null = null;
|
|
192
193
|
for (const spectrum of spectra) {
|
|
193
194
|
if (!includeExcluded && spectrum.excludeFromDomain) continue;
|
|
195
|
+
const scale = verticalScaleOf(spectrum);
|
|
194
196
|
if (spectrum.showProfile && spectrum.profile !== null) {
|
|
195
|
-
extent = widen(extent, spectrum.profile);
|
|
197
|
+
extent = widen(extent, spectrum.profile, scale);
|
|
198
|
+
}
|
|
199
|
+
if (spectrum.showCentroid) {
|
|
200
|
+
extent = widen(extent, spectrum.centroid, scale);
|
|
196
201
|
}
|
|
197
|
-
if (spectrum.showCentroid) extent = widen(extent, spectrum.centroid);
|
|
198
202
|
}
|
|
199
203
|
return extent;
|
|
200
204
|
}
|
|
@@ -207,17 +211,19 @@ function traceExtent(
|
|
|
207
211
|
* hundred thousand points of a profile to learn what index zero already says.
|
|
208
212
|
* @param extent - What has been covered so far, `null` for nothing.
|
|
209
213
|
* @param trace - The trace to cover as well.
|
|
214
|
+
* @param scale - How many times taller than measured it is drawn.
|
|
210
215
|
* @returns The grown extent, unchanged when the trace holds no point.
|
|
211
216
|
*/
|
|
212
217
|
function widen(
|
|
213
218
|
extent: TraceExtent | null,
|
|
214
219
|
trace: MassTrace,
|
|
220
|
+
scale: number,
|
|
215
221
|
): TraceExtent | null {
|
|
216
222
|
const { x, y } = trace;
|
|
217
223
|
if (x.length === 0 || y.length === 0) return extent;
|
|
218
224
|
const first = x[0] as number;
|
|
219
225
|
const last = x.at(-1) as number;
|
|
220
|
-
const tallest = xMaxValue(y);
|
|
226
|
+
const tallest = xMaxValue(y) * scale;
|
|
221
227
|
if (extent === null) {
|
|
222
228
|
return { xMinimum: first, xMaximum: last, yMaximum: tallest };
|
|
223
229
|
}
|
|
@@ -180,6 +180,15 @@ export interface MassSpectrum {
|
|
|
180
180
|
* @default false
|
|
181
181
|
*/
|
|
182
182
|
excludeFromDomain?: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* How many times taller than measured the spectrum is drawn, so one spectrum
|
|
185
|
+
* can be brought up against another while the axis stays shared. It scales
|
|
186
|
+
* about the baseline, the fit covers the heights as drawn, and the labels
|
|
187
|
+
* still write the measured intensities. A value that is not a positive
|
|
188
|
+
* number draws it as measured.
|
|
189
|
+
* @default 1
|
|
190
|
+
*/
|
|
191
|
+
verticalScale?: number;
|
|
183
192
|
/**
|
|
184
193
|
* How finely the spectrum resolves masses, as it was decided when it was read.
|
|
185
194
|
*
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drawing one spectrum taller or shorter than the others on a shared axis.
|
|
3
|
+
*
|
|
4
|
+
* The axis stays the measurement's, so a spectrum scaled up is a picture of
|
|
5
|
+
* the measurement and not a new one: every number written on the chart — the
|
|
6
|
+
* labels, the peak under the pointer — is still read off the measured trace.
|
|
7
|
+
* Only where a sample is drawn moves.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ChartScale } from '../../chart/core/chartScale.ts';
|
|
11
|
+
|
|
12
|
+
import type { MassSpectrum } from './massSpectrum.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* How many times taller than measured a spectrum is drawn.
|
|
16
|
+
* @param spectrum - The spectrum.
|
|
17
|
+
* @returns Its `verticalScale`, `1` when that is not a positive finite number.
|
|
18
|
+
*/
|
|
19
|
+
export function verticalScaleOf(spectrum: MassSpectrum): number {
|
|
20
|
+
const { verticalScale } = spectrum;
|
|
21
|
+
return verticalScale !== undefined &&
|
|
22
|
+
Number.isFinite(verticalScale) &&
|
|
23
|
+
verticalScale > 0
|
|
24
|
+
? verticalScale
|
|
25
|
+
: 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The intensity axis one spectrum is drawn against: the chart's, stretched by
|
|
30
|
+
* the spectrum's own scale about the baseline, so zero stays where every stick
|
|
31
|
+
* stands.
|
|
32
|
+
*
|
|
33
|
+
* A spectrum drawn as measured gets the chart's scale itself back rather than
|
|
34
|
+
* an equal copy, because the traces memoise their paths on the scale's
|
|
35
|
+
* identity and a copy per render would rebuild every path on every render.
|
|
36
|
+
* @param yScale - The chart's intensity axis.
|
|
37
|
+
* @param spectrum - The spectrum.
|
|
38
|
+
* @returns The axis to draw it against.
|
|
39
|
+
*/
|
|
40
|
+
export function spectrumYScale(
|
|
41
|
+
yScale: ChartScale,
|
|
42
|
+
spectrum: MassSpectrum,
|
|
43
|
+
): ChartScale {
|
|
44
|
+
const scale = verticalScaleOf(spectrum);
|
|
45
|
+
return scale === 1
|
|
46
|
+
? yScale
|
|
47
|
+
: { offset: yScale.offset, factor: yScale.factor * scale };
|
|
48
|
+
}
|