nmrium 0.49.0 → 0.50.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +7 -7
  2. package/lib/component/1d/Chart1D.js +3 -1
  3. package/lib/component/1d/LinesSeries.js +1 -1
  4. package/lib/component/1d/SimilarityTree.d.ts +1 -0
  5. package/lib/component/1d/SimilarityTree.js +60 -0
  6. package/lib/component/1d/Viewer1D.js +9 -11
  7. package/lib/component/1d/multiplicityTree/MultiplicityTree.d.ts +1 -7
  8. package/lib/component/1d/multiplicityTree/MultiplicityTree.js +114 -125
  9. package/lib/component/1d/multiplicityTree/MultiplicityTrees.d.ts +1 -0
  10. package/lib/component/1d/multiplicityTree/MultiplicityTrees.js +23 -0
  11. package/lib/component/1d/multiplicityTree/generateTreeNodes.d.ts +18 -0
  12. package/lib/component/1d/multiplicityTree/generateTreeNodes.js +66 -0
  13. package/lib/component/1d/ranges/Range.d.ts +1 -1
  14. package/lib/component/1d/ranges/Range.js +8 -9
  15. package/lib/component/elements/CloseButton.d.ts +2 -10
  16. package/lib/component/elements/CloseButton.js +3 -20
  17. package/lib/component/elements/CounterLabel.d.ts +3 -3
  18. package/lib/component/elements/CounterLabel.js +3 -4
  19. package/lib/component/elements/PreferencesButton.d.ts +2 -4
  20. package/lib/component/elements/PreferencesButton.js +3 -3
  21. package/lib/component/elements/ReactTable/ReactTable.js +5 -2
  22. package/lib/component/elements/SaveButton.d.ts +2 -11
  23. package/lib/component/elements/SaveButton.js +4 -19
  24. package/lib/component/elements/ToolBarButton.d.ts +2 -0
  25. package/lib/component/elements/ToolBarButton.js +5 -0
  26. package/lib/component/elements/ToolbarPopoverItem.d.ts +11 -0
  27. package/lib/component/elements/ToolbarPopoverItem.js +10 -0
  28. package/lib/component/elements/popup/Modal/ConfirmDialog.d.ts +2 -1
  29. package/lib/component/elements/popup/Modal/ConfirmDialog.js +11 -8
  30. package/lib/component/hooks/useSaveSettings.js +3 -2
  31. package/lib/component/main/InnerNMRiumContents.js +1 -1
  32. package/lib/component/modal/AboutPredictionModal.js +4 -8
  33. package/lib/component/modal/AboutSpectrumSimulationModal.js +4 -8
  34. package/lib/component/modal/CopyClipboardModal.js +2 -2
  35. package/lib/component/modal/EditPeakShapeModal.js +2 -2
  36. package/lib/component/modal/ExportAsJcampModal.d.ts +1 -1
  37. package/lib/component/modal/ExportAsJcampModal.js +7 -3
  38. package/lib/component/modal/ImportPublicationStringModal.js +15 -11
  39. package/lib/component/modal/LoadJCAMPModal.js +12 -9
  40. package/lib/component/modal/LogsHistoryModal.d.ts +1 -1
  41. package/lib/component/modal/LogsHistoryModal.js +9 -4
  42. package/lib/component/modal/MoleculeStructureEditorModal.js +10 -3
  43. package/lib/component/modal/MultipletAnalysisModal.js +8 -8
  44. package/lib/component/modal/PredictSpectraModal.js +6 -5
  45. package/lib/component/modal/SaveAsModal.js +2 -2
  46. package/lib/component/modal/aboutUs/AboutUsModal.js +11 -26
  47. package/lib/component/modal/changeSum/ChangeSumModal.d.ts +4 -3
  48. package/lib/component/modal/changeSum/ChangeSumModal.js +10 -3
  49. package/lib/component/modal/changeSum/ChangeSumModalContents.d.ts +1 -3
  50. package/lib/component/modal/changeSum/ChangeSumModalContents.js +9 -6
  51. package/lib/component/modal/editRange/EditRangeModal.js +8 -6
  52. package/lib/component/modal/editRange/forms/components/AddSignalFormTab.js +1 -0
  53. package/lib/component/modal/editRange/forms/components/CouplingsTable.js +13 -10
  54. package/lib/component/modal/editRange/forms/components/SignalFormTab.js +1 -1
  55. package/lib/component/modal/editRange/forms/components/SignalsForm.js +1 -0
  56. package/lib/component/modal/editZone/EditZoneModal.js +3 -3
  57. package/lib/component/modal/metaImportation/MetaImportationModal.js +2 -2
  58. package/lib/component/modal/setting/GeneralSettings.js +17 -38
  59. package/lib/component/modal/setting/settings-tabs/OnLoadProcessingTabContent.js +2 -4
  60. package/lib/component/panels/AutomaticAssignment/AutomaticAssignment.js +16 -2
  61. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +22 -25
  62. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +16 -3
  63. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +5 -5
  64. package/lib/component/panels/PeaksPanel/PeaksPanel.js +43 -13
  65. package/lib/component/panels/RangesPanel/RangesHeader.d.ts +1 -1
  66. package/lib/component/panels/RangesPanel/RangesHeader.js +71 -34
  67. package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +46 -5
  68. package/lib/component/panels/SpectrumsPanel/SpectraTable.js +40 -9
  69. package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.js +2 -2
  70. package/lib/component/panels/SummaryPanel/SetMolecularFormulaModal.js +2 -2
  71. package/lib/component/panels/SummaryPanel/SetShiftTolerancesModal.js +2 -2
  72. package/lib/component/panels/SummaryPanel/SummaryPanel.js +30 -19
  73. package/lib/component/panels/ZonesPanel/ZonesPanel.js +28 -28
  74. package/lib/component/panels/databasePanel/DatabasePanel.js +6 -6
  75. package/lib/component/panels/databasePanel/DatabaseSearchOptions.d.ts +4 -6
  76. package/lib/component/panels/databasePanel/DatabaseSearchOptions.js +13 -14
  77. package/lib/component/panels/databasePanel/DatabaseStructureSearchModal.js +7 -8
  78. package/lib/component/panels/filtersPanel/FilterPanel.js +1 -1
  79. package/lib/component/panels/filtersPanel/FiltersTable.js +1 -1
  80. package/lib/component/panels/header/DefaultPanelHeader.d.ts +10 -6
  81. package/lib/component/panels/header/DefaultPanelHeader.js +30 -9
  82. package/lib/component/panels/header/PanelHeader.js +0 -1
  83. package/lib/component/panels/header/PreferencesHeader.d.ts +2 -4
  84. package/lib/component/panels/header/PreferencesHeader.js +9 -23
  85. package/lib/component/panels/header/SpectraAutomaticPickingButton.js +2 -2
  86. package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js +39 -10
  87. package/lib/component/panels/spectrumSimulation/SpectrumSimulation.js +5 -1
  88. package/lib/component/panels/spectrumSimulation/SpectrumSimulationSimpleOptions.js +3 -3
  89. package/lib/component/reducer/Reducer.js +3 -0
  90. package/lib/component/reducer/actions/DatabaseActions.d.ts +3 -2
  91. package/lib/component/reducer/actions/DatabaseActions.js +5 -1
  92. package/lib/component/reducer/actions/IntegralsActions.d.ts +1 -1
  93. package/lib/component/toolbar/ToolBar.js +237 -9
  94. package/lib/component/toolbar/toolbarMenu.d.ts +4 -0
  95. package/lib/component/toolbar/toolbarMenu.js +77 -0
  96. package/lib/component/utility/booleanToString.d.ts +6 -0
  97. package/lib/component/utility/booleanToString.js +4 -0
  98. package/lib/utils/clipboard/clipboardComponents.d.ts +2 -2
  99. package/lib/utils/clipboard/clipboardComponents.js +8 -3
  100. package/lib/versionInfo.js +1 -1
  101. package/package.json +17 -16
  102. package/lib/component/1d/multiplicityTree/LevelNode.d.ts +0 -8
  103. package/lib/component/1d/multiplicityTree/LevelNode.js +0 -8
  104. package/lib/component/1d/multiplicityTree/StringNode.d.ts +0 -11
  105. package/lib/component/1d/multiplicityTree/StringNode.js +0 -7
  106. package/lib/component/1d/multiplicityTree/TreeColors.d.ts +0 -1
  107. package/lib/component/1d/multiplicityTree/TreeColors.js +0 -1
  108. package/lib/component/1d/multiplicityTree/TreeNodes.d.ts +0 -21
  109. package/lib/component/1d/multiplicityTree/TreeNodes.js +0 -23
  110. package/lib/component/1d/multiplicityTree/buildTreeNode.d.ts +0 -11
  111. package/lib/component/1d/multiplicityTree/buildTreeNode.js +0 -57
  112. package/lib/component/elements/DeleteButton.d.ts +0 -8
  113. package/lib/component/elements/DeleteButton.js +0 -6
  114. package/lib/component/elements/DropdownMenu.d.ts +0 -9
  115. package/lib/component/elements/DropdownMenu.js +0 -7
  116. package/lib/component/panels/PeaksPanel/PeaksToggleActions.d.ts +0 -10
  117. package/lib/component/panels/PeaksPanel/PeaksToggleActions.js +0 -10
  118. package/lib/component/toolbar/BasicToolBar.d.ts +0 -1
  119. package/lib/component/toolbar/BasicToolBar.js +0 -165
  120. package/lib/component/toolbar/FunctionToolBar.d.ts +0 -3
  121. package/lib/component/toolbar/FunctionToolBar.js +0 -148
package/README.md CHANGED
@@ -92,13 +92,13 @@ npm start
92
92
 
93
93
  ## Funding
94
94
 
95
- | | |
96
- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
97
- | <img src="images/zakodium.svg" width="200"> | [Zakodium sàrl](https://www.zakodium.com) |
98
- | <img src="images/idnmr.png" height="80"> | [Initiative zur Verbesserung der NMR-Datenqualität (IDNMR)](https://idnmr.uni-koeln.de/) |
99
- | <img src="images/nfdi4chem.png" width="200"> | [NFDI4Chem Chemistry Consortium in the NFDI](https://www.nfdi4chem.de/) |
100
- | <img src="images/univalle.svg" height="100"> | [Universidad del Valle / Cali, Colombia](https://darmn.correounivalle.edu.co/) |
101
- | <img src="images/bigmap.jpg" height="100"> | [Union’s Horizon 2020 research and innovation programme under grant agreement No 957189](https://www.big-map.eu/European) |
95
+ | | |
96
+ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97
+ | <img src="images/zakodium.svg" width="200"> | [Zakodium sàrl](https://www.zakodium.com) |
98
+ | <img src="images/idnmr.png" height="80"> | [Initiative zur Verbesserung der NMR-Datenqualität (IDNMR)](https://idnmr.uni-koeln.de/) |
99
+ | <img src="images/nfdi4chem.png" width="200"> | [NFDI4Chem Chemistry Consortium in the NFDI](https://www.nfdi4chem.de/) |
100
+ | <img src="images/univalle.svg" height="100"> | [Universidad del Valle / Cali, Colombia](https://darmn.correounivalle.edu.co/) |
101
+ | <img src="images/bigmap.jpg" height="100"> | This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 957189. The project is part of BATTERY 2030+, the large-scale European research initiative for inventing the sustainable batteries of the future. |
102
102
 
103
103
  ## License
104
104
 
@@ -4,12 +4,14 @@ import { usePreferences } from '../context/PreferencesContext';
4
4
  import ApodizationLine from './ApodizationLine';
5
5
  import ExclusionZonesAnnotations from './ExclusionZonesAnnotations';
6
6
  import LinesSeries from './LinesSeries';
7
+ import SimilarityTree from './SimilarityTree';
7
8
  import SpectraTracker from './SpectraLegends';
8
9
  import XAxis from './XAxis';
9
10
  import DatabaseElements from './database/DatabaseElements';
10
11
  import IntegralsSeries from './integral/IntegralsSeries';
11
12
  import JGraph from './jCouplingGraph/JGraph';
12
13
  import MultiAnalysisRanges from './multiAnalysis/MultiAnalysisRanges';
14
+ import MultiplicityTrees from './multiplicityTree/MultiplicityTrees';
13
15
  import { PeakEditionProvider } from './peaks/PeakEditionManager';
14
16
  import Peaks from './peaks/Peaks';
15
17
  import PeaksShapes from './peaks/PeaksShapes';
@@ -20,6 +22,6 @@ function Chart1D({ mode, width, height, margin, displayerKey }) {
20
22
  const { current: { general: { spectraRendering }, }, } = usePreferences();
21
23
  const innerWidth = width - margin.left - margin.right;
22
24
  const innerHeight = height - margin.bottom;
23
- return (_jsx(PeakEditionProvider, { children: _jsxs("svg", { id: "nmrSVG", width: width, height: height, viewBox: `0 0 ${width} ${height}`, fontFamily: "Arial, Helvetica, sans-serif", shapeRendering: spectraRendering, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${displayerKey}clip-chart-1d`, children: _jsx("rect", { width: innerWidth, height: innerHeight, x: margin.left, y: "0" }) }) }), _jsx(LinesSeries, {}), _jsx(ApodizationLine, {}), _jsx(IntegralsSeries, {}), _jsx(Peaks, { peaksSource: "peaks" }), _jsx(RangesIntegrals, {}), _jsx(Peaks, { peaksSource: "ranges" }), _jsx(Ranges, {}), _jsx(JGraph, {}), _jsx(MultiAnalysisRanges, {}), _jsx(BaseLineZones, {}), _jsx(ExclusionZonesAnnotations, {}), _jsx(DatabaseElements, {}), _jsx(PeaksShapes, {}), _jsx(SpectraTracker, {}), _jsx(SpectrumInfoBlock, {}), _jsx("g", { className: "container", style: { pointerEvents: 'none' }, children: _jsx(XAxis, { showGrid: true, mode: mode }) })] }) }));
25
+ return (_jsx(PeakEditionProvider, { children: _jsxs("svg", { id: "nmrSVG", width: width, height: height, viewBox: `0 0 ${width} ${height}`, fontFamily: "Arial, Helvetica, sans-serif", shapeRendering: spectraRendering, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${displayerKey}clip-chart-1d`, children: _jsx("rect", { width: innerWidth, height: innerHeight, x: margin.left, y: "0" }) }) }), _jsx(LinesSeries, {}), _jsx(ApodizationLine, {}), _jsx(IntegralsSeries, {}), _jsx(Peaks, { peaksSource: "peaks" }), _jsx(RangesIntegrals, {}), _jsx(Peaks, { peaksSource: "ranges" }), _jsx(Ranges, {}), _jsx(MultiplicityTrees, {}), _jsx(JGraph, {}), _jsx(MultiAnalysisRanges, {}), _jsx(BaseLineZones, {}), _jsx(ExclusionZonesAnnotations, {}), _jsx(DatabaseElements, {}), _jsx(PeaksShapes, {}), _jsx(SpectraTracker, {}), _jsx(SpectrumInfoBlock, {}), _jsx(SimilarityTree, {}), _jsx("g", { className: "container", style: { pointerEvents: 'none' }, children: _jsx(XAxis, { showGrid: true, mode: mode }) })] }) }));
24
26
  }
25
27
  export default Chart1D;
@@ -29,6 +29,6 @@ function LinesSeries() {
29
29
  const { setActiveSpectrum } = useSetActiveSpectrumAction();
30
30
  return (_jsxs("g", { clipPath: `url(#${displayerKey}clip-chart-1d)`, className: "spectrums", children: [spectra.map((d, i) => (_jsxs("g", { children: [_jsx(Line, { display: d.display, id: d.id, data: get1DDataXY(d), index: i }), verticalAlign === 'stack' && (_jsx("rect", { css: style, y: innerHeight - shiftY * i - BOX_SIZE / 2, x: margin.left, width: `${innerWidth}px`, height: `${BOX_SIZE}px`, onClick: (e) => {
31
31
  setActiveSpectrum(e, d.id);
32
- } }))] }, d.id))), activeSpectra?.map((activeSpectrum) => (_jsx("use", { href: `#${activeSpectrum.id}` }, activeSpectrum.id)))] }));
32
+ }, "data-no-export": "true" }))] }, d.id))), activeSpectra?.map((activeSpectrum) => (_jsx("use", { href: `#${activeSpectrum.id}` }, activeSpectrum.id)))] }));
33
33
  }
34
34
  export default LinesSeries;
@@ -0,0 +1 @@
1
+ export default function SimilarityTree(): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createTree } from 'ml-tree-similarity';
3
+ import { Fragment } from 'react';
4
+ import { isSpectrum1D } from '../../data/data1d/Spectrum1D';
5
+ import { useChartData } from '../context/ChartContext';
6
+ import { useScaleChecked } from '../context/ScaleContext';
7
+ import { useFormatNumberByNucleus } from '../hooks/useFormatNumberByNucleus';
8
+ import useSpectrum from '../hooks/useSpectrum';
9
+ const circleSize = 3;
10
+ const marginTop = circleSize + 10;
11
+ const lineColor = 'black';
12
+ const textColor = 'black';
13
+ const textPadding = circleSize + 2;
14
+ const textSize = 10;
15
+ const maxTreeLevels = 25;
16
+ export default function SimilarityTree() {
17
+ const { height, view: { spectra: { activeTab, showSimilarityTree }, }, } = useChartData();
18
+ const spectrum = useSpectrum();
19
+ const format = useFormatNumberByNucleus(activeTab);
20
+ const { scaleX } = useScaleChecked();
21
+ const scaleY = (value) => (height * value) / maxTreeLevels;
22
+ const treeHeadLength = height / maxTreeLevels;
23
+ if (!spectrum || !showSimilarityTree || !isSpectrum1D(spectrum))
24
+ return null;
25
+ const { data: { x, re }, display: { color }, } = spectrum;
26
+ const tree = createTree({ x, y: re });
27
+ const data = mapTreeToArray(tree, 0);
28
+ const paths = [];
29
+ for (const { level, center, parentCenter, parentLevel } of data) {
30
+ if (parentCenter === undefined)
31
+ continue;
32
+ const startX = scaleX()(parentCenter);
33
+ const startY = scaleY(parentLevel);
34
+ const midY = startY + treeHeadLength / 2;
35
+ const endX = scaleX()(center);
36
+ const endY = scaleY(level);
37
+ const path = `M ${startX} ${startY} L ${startX} ${midY} L ${endX} ${midY} L${endX} ${endY}`;
38
+ paths.push(path);
39
+ }
40
+ return (_jsxs("g", { className: "similarity-tree", transform: `translate(0,${marginTop})`, children: [_jsx("path", { className: "tree-lines", d: paths.join(' '), fill: "none", stroke: lineColor }), ";", _jsx("g", { className: "tree-nodes", children: data.map(({ level, center }) => {
41
+ const x = scaleX()(center);
42
+ const y = scaleY(level);
43
+ return (_jsxs(Fragment, { children: [_jsx("circle", { cx: x, cy: y, r: circleSize, fill: color }), _jsx("text", { x: x + textPadding, y: y, textAnchor: "start", alignmentBaseline: "middle", fill: textColor, fontSize: textSize, children: format(center) })] }, `${level}${center}`));
44
+ }) })] }));
45
+ }
46
+ function mapTreeToArray(node, level, parentCenter = null, parentLevel = -1) {
47
+ if (!node)
48
+ return [];
49
+ const { center, sum } = node;
50
+ const result = [{ center, sum, level }];
51
+ for (const obj of result) {
52
+ if (parentCenter) {
53
+ obj.parentCenter = parentCenter;
54
+ obj.parentLevel = parentLevel;
55
+ }
56
+ }
57
+ const left = mapTreeToArray(node.left, level + 1, center, parentLevel + 1);
58
+ const right = mapTreeToArray(node.right, level + 1, center, parentLevel + 1);
59
+ return result.concat(left, right);
60
+ }
@@ -101,10 +101,6 @@ function Viewer1D({ emptyText = undefined }) {
101
101
  // when Alt key is active
102
102
  case primaryKeyIdentifier: {
103
103
  switch (selectedTool) {
104
- case options.zoom.id: {
105
- executeDefaultAction = true;
106
- break;
107
- }
108
104
  case options.integral.id:
109
105
  dispatch({
110
106
  type: 'ADD_INTEGRAL',
@@ -172,7 +168,7 @@ function Viewer1D({ emptyText = undefined }) {
172
168
  break;
173
169
  }
174
170
  default:
175
- propagateEvent();
171
+ executeDefaultAction = true;
176
172
  break;
177
173
  }
178
174
  break;
@@ -194,12 +190,14 @@ function Viewer1D({ emptyText = undefined }) {
194
190
  break;
195
191
  }
196
192
  }
197
- const isNotDistanceMeasurementTool = selectedTool !== 'zoom' ||
198
- (selectedTool === 'zoom' && !brushData.shiftKey);
199
- if (executeDefaultAction &&
200
- selectedTool != null &&
201
- isNotDistanceMeasurementTool) {
202
- dispatch({ type: 'BRUSH_END', payload: brushData });
193
+ const tools = new Set(['zoom', 'databaseRangesSelection']);
194
+ const enableDefaultBrush = !tools.has(selectedTool) ||
195
+ (tools.has(selectedTool) && !brushData.shiftKey);
196
+ if (executeDefaultAction && selectedTool != null) {
197
+ if (enableDefaultBrush) {
198
+ dispatch({ type: 'BRUSH_END', payload: brushData });
199
+ }
200
+ propagateEvent();
203
201
  }
204
202
  }
205
203
  }, [
@@ -1,12 +1,6 @@
1
1
  import { Range } from 'nmr-processing';
2
- import { CSSProperties } from 'react';
3
2
  interface MultiplicityTreeProps {
4
3
  range: Range;
5
- labelOptions?: {
6
- distance: number;
7
- fontSize: CSSProperties['fontSize'];
8
- };
9
- onUnlink: (index: number) => void;
10
4
  }
11
- export declare function MultiplicityTree(props: MultiplicityTreeProps): import("@emotion/react/jsx-runtime").JSX.Element | null;
5
+ export default function MultiplicityTree(props: MultiplicityTreeProps): import("@emotion/react/jsx-runtime").JSX.Element[] | null;
12
6
  export {};
@@ -1,19 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { css } from '@emotion/react';
4
- import { checkMultiplicity } from 'nmr-processing';
5
- import { useMemo } from 'react';
6
- import { useAssignment, } from '../../assignment/AssignmentsContext';
4
+ import { xFindClosestIndex } from 'ml-spectra-processing';
5
+ import { isSpectrum1D } from '../../../data/data1d/Spectrum1D';
6
+ import { useAssignment, useAssignmentData, } from '../../assignment/AssignmentsContext';
7
7
  import { useChartData } from '../../context/ChartContext';
8
+ import { useDispatch } from '../../context/DispatchContext';
8
9
  import { useScaleChecked } from '../../context/ScaleContext';
9
10
  import { HighlightEventSource, useHighlight } from '../../highlight';
10
11
  import useSpectrum from '../../hooks/useSpectrum';
11
- import { hasCouplingConstant } from '../../panels/extra/utilities/MultiplicityUtilities';
12
12
  import { AssignmentActionsButtons } from '../ranges/AssignmentActionsButtons';
13
- import LevelNode from './LevelNode';
14
- import StringNode from './StringNode';
15
- import TreeNodes from './TreeNodes';
16
- import createTreeNodes from './buildTreeNode';
13
+ import { generateTreeNodes } from './generateTreeNodes';
17
14
  const styles = {
18
15
  cursor: 'default',
19
16
  opacity: 0.6,
@@ -30,150 +27,142 @@ const cssStyle = css `
30
27
  }
31
28
  }
32
29
  `;
33
- const BOX_PADDING = 5;
34
- function extractID(assignment) {
35
- return [assignment.id].concat(assignment.assigned?.x || []);
30
+ const treeLevelsColors = ['red', 'green', 'blue', 'magenta'];
31
+ const marginBottom = 20;
32
+ const headTextMargin = 5;
33
+ const tailLengthScale = 60;
34
+ const boxPadding = 20;
35
+ export default function MultiplicityTree(props) {
36
+ const { range } = props;
37
+ const spectrum = useSpectrum();
38
+ const { scaleY } = useScaleChecked();
39
+ if (!spectrum || !isSpectrum1D(spectrum))
40
+ return null;
41
+ const { from, to } = range;
42
+ const maxY = getMaxY(spectrum, { from, to });
43
+ const startY = scaleY(spectrum.id)(maxY) - marginBottom;
44
+ const tree = generateTreeNodes(range, spectrum);
45
+ return tree.map((treeItem, signalIndex) => {
46
+ const { rangeKey, signalKey } = treeItem;
47
+ return (_jsx(Tree, { treeNodes: treeItem, startY: startY, signalIndex: signalIndex, range: range }, rangeKey + signalKey));
48
+ });
36
49
  }
37
- function InnerMultiplicityTree({ labelOptions, onUnlink, data, width: widthProp, index, }) {
38
- const { startX, signal, width, height, startY } = data;
50
+ function Tree(props) {
51
+ const { signalIndex, range, startY: originStartY, treeNodes: { multiplicity = '', nodes, min, max, signalKey, diaIDs }, } = props;
52
+ const { from, to } = range;
53
+ const { width } = useChartData();
39
54
  const { scaleX } = useScaleChecked();
40
- const showLabels = width / widthProp >= 0.1;
41
- labelOptions = labelOptions || {
42
- distance: 10,
43
- fontSize: 11,
44
- };
45
- const assignment = useAssignment(signal.id);
55
+ const dispatch = useDispatch();
56
+ const assignmentData = useAssignmentData();
57
+ const assignment = useAssignment(signalKey);
46
58
  const highlight = useHighlight(extractID(assignment), {
47
59
  type: HighlightEventSource.SIGNAL,
48
60
  });
61
+ let widthRatio = 0;
62
+ let treeWidth = 0;
63
+ if (nodes?.length > 1) {
64
+ treeWidth = scaleX()(min) - scaleX()(max);
65
+ widthRatio = treeWidth / width;
66
+ }
67
+ else {
68
+ treeWidth = 4;
69
+ widthRatio = (scaleX()(from) - scaleX()(to)) / width;
70
+ }
71
+ const tailLength = widthRatio * tailLengthScale;
72
+ const rationTextSize = widthRatio * 30;
73
+ let multiplicityTextSize = rationTextSize;
74
+ if (multiplicityTextSize < 10) {
75
+ multiplicityTextSize = 10;
76
+ }
77
+ const isMassive = ['m', 's'].includes(multiplicity);
78
+ const levelLength = isMassive ? tailLength : tailLength * 2;
79
+ const treeHeight = multiplicity.split('').length * levelLength + tailLength;
80
+ const startY = originStartY - treeHeight;
81
+ const [{ x: head }, ...otherNodes] = nodes;
82
+ const headX = scaleX()(head);
83
+ const paths = useTreePaths(otherNodes, {
84
+ isMassive,
85
+ levelLength,
86
+ tailLength,
87
+ startY,
88
+ });
89
+ if (!multiplicity)
90
+ return null;
49
91
  function assignHandler() {
50
92
  assignment.setActive('x');
51
93
  }
52
94
  function unAssignHandler() {
53
- onUnlink(index);
95
+ dispatch({
96
+ type: 'UNLINK_RANGE',
97
+ payload: {
98
+ range,
99
+ assignmentData,
100
+ signalIndex,
101
+ },
102
+ });
54
103
  }
55
104
  const isHighlighted = highlight.isActive || assignment.isActive;
105
+ const padding = boxPadding * widthRatio;
106
+ const x = scaleX()(max) - padding;
107
+ const y = startY - headTextMargin - multiplicityTextSize - padding;
108
+ const boxWidth = treeWidth + padding * 2;
109
+ const boxHeight = treeHeight + headTextMargin + multiplicityTextSize + padding * 2;
56
110
  return (_jsxs("g", { style: isHighlighted ? { ...styles, opacity: 1, strokeWidth: 1.5 } : styles, onMouseEnter: () => {
57
111
  assignment.show('x');
58
112
  highlight.show();
59
- },
60
- onMouseLeave: () => {
113
+ }, onMouseLeave: () => {
61
114
  assignment.hide();
62
115
  highlight.hide();
63
- }, pointerEvents: "bounding-box", ...(!assignment.isActive && { css: cssStyle }), children: [drawTree(data, { scaleX, labelOptions, showLabels }), _jsx("rect", { x: startX - BOX_PADDING, y: startY - BOX_PADDING, width: width + BOX_PADDING * 2, height: height + BOX_PADDING * 2, fill: isHighlighted ? '#ff6f0057' : 'transparent', "data-no-export": "true" }), _jsx(AssignmentActionsButtons, { className: "signal-target", isActive: !!(assignment.isActive || signal?.diaIDs), y: startY, x: scaleX()(signal.delta) - 30, onAssign: assignHandler, onUnAssign: unAssignHandler, borderRadius: 16 })] }));
116
+ }, pointerEvents: "bounding-box", ...(!assignment.isActive && { css: cssStyle }), children: [_jsx("rect", { x: x, y: y, width: boxWidth, height: boxHeight, fill: isHighlighted ? '#ff6f0057' : 'transparent', "data-no-export": "true" }), _jsxs("g", { className: "multiplicity-tree-head", children: [_jsx("text", { x: headX, y: startY - headTextMargin, textAnchor: "middle", fontSize: multiplicityTextSize, fill: "black", children: multiplicity }), _jsx("line", { x1: headX, x2: headX, y1: startY, y2: startY + tailLength, stroke: treeLevelsColors[0] })] }), _jsx("g", { className: "multiplicity-tree-lines", children: paths.map((path, level) => {
117
+ const levelColor = isMassive
118
+ ? 'blue'
119
+ : treeLevelsColors[level % treeLevelsColors.length];
120
+ return (_jsx("path", { d: path.join(' '), fill: "none", stroke: levelColor }, path.join(`%${level}`)));
121
+ }) }), _jsx("g", { className: "multiplicity-tree-ration-labels", children: !isMassive &&
122
+ otherNodes.map((node) => {
123
+ const { x, level, ratio } = node;
124
+ const x1 = scaleX()(x);
125
+ const y = levelLength * level + tailLength + tailLength / 2;
126
+ const levelColor = treeLevelsColors[level % treeLevelsColors.length];
127
+ return (_jsx("text", { x: x1, y: startY + y, textAnchor: "middle", alignmentBaseline: "middle", fontSize: rationTextSize, fill: levelColor, children: ratio }, JSON.stringify(node)));
128
+ }) }), _jsx(AssignmentActionsButtons, { className: "signal-target", isActive: !!(assignment.isActive ||
129
+ (Array.isArray(diaIDs) && diaIDs.length > 0)), y: startY - 16, x: headX - 30, onAssign: assignHandler, onUnAssign: unAssignHandler, borderRadius: 16 })] }));
64
130
  }
65
- export function MultiplicityTree(props) {
66
- const { width } = useChartData();
67
- const spectrum = useSpectrum(null);
68
- const { scaleX, scaleY } = useScaleChecked();
69
- const treeData = useMemo(() => spectrum
70
- ? getTree(props.range, spectrum, { scaleX, scaleY })
71
- : [], [props.range, scaleX, scaleY, spectrum]);
72
- if (!spectrum)
73
- return null;
74
- return (_jsx("g", { children: treeData?.map((data, index) => (_jsx(InnerMultiplicityTree, { index: index, data: data, width: width, ...props }, data.signal.id))) }));
75
- }
76
- function getTree(range, spectrum, scale) {
77
- const SHIFT_X = 30;
78
- const treeResult = [];
79
- const { signals = [], ...otherRangeProps } = range;
80
- for (const signal of signals) {
81
- const isMassive = !checkMultiplicity(signal.multiplicity, ['m']);
82
- const length = signal?.multiplicity?.length || 0;
83
- let width = 0;
84
- let height = 0;
85
- let levelHeight = 0;
86
- const nodes = [];
87
- let startX = 0;
88
- const { from, to } = range;
89
- if (signal.multiplicity) {
90
- const buildTreeNodesData = createTreeNodes(signal, spectrum);
91
- const jIndices = signal.multiplicity
92
- .split('')
93
- .map((_mult, i) => (hasCouplingConstant(_mult) ? i : undefined))
94
- .filter((i) => i !== undefined);
95
- const treeNodes = buildTreeNodesData(0, jIndices, [], signal.delta);
96
- if (treeNodes)
97
- nodes.push(...treeNodes);
131
+ function useTreePaths(otherNodes, options) {
132
+ const { tailLength, levelLength, startY, isMassive } = options;
133
+ const { scaleX } = useScaleChecked();
134
+ const paths = [];
135
+ for (const node of otherNodes) {
136
+ const { x, parentX = 0, level } = node;
137
+ const baseX = scaleX()(parentX);
138
+ const x1 = scaleX()(x);
139
+ let y = tailLength;
140
+ if (!isMassive) {
141
+ y = levelLength * level + tailLength;
98
142
  }
99
- // +2 because of multiplicity text and start level node before the actual tree starts
100
- // 2* for levels between nodes (edges)
101
- if (isMassive) {
102
- startX = scale.scaleX()(to);
103
- width = Math.abs(scale.scaleX()(from)) - Math.abs(startX);
104
- height = width / 3;
105
- levelHeight = height / (length + 2);
143
+ const path = `M ${baseX} ${startY + y} L ${x1} ${startY + y + (isMassive ? 0 : tailLength)} l 0 ${tailLength}`;
144
+ if (!paths?.[level]) {
145
+ paths[level] = [path];
106
146
  }
107
147
  else {
108
- const treeRange = getTreeRange(nodes, signal.delta);
109
- startX = scale.scaleX()(treeRange.to);
110
- width = Math.abs(scale.scaleX()(treeRange.from)) - Math.abs(startX);
111
- height = width / 2;
112
- if (signal.multiplicity !== 's') {
113
- levelHeight = height / (2 * length + 2);
114
- height = width / 2;
115
- }
116
- else {
117
- levelHeight = 3;
118
- height = levelHeight * 4;
119
- }
148
+ paths[level].push(path);
120
149
  }
121
- const startY = scale.scaleY(spectrum.id)(getStartY(spectrum, { from, to })) -
122
- height -
123
- SHIFT_X;
124
- treeResult.push({
125
- isMassive,
126
- startX,
127
- startY,
128
- width,
129
- height,
130
- levelHeight,
131
- nodes,
132
- signal,
133
- range: otherRangeProps,
134
- });
135
150
  }
136
- return treeResult;
151
+ return paths;
137
152
  }
138
- function getStartY(spectrum, options) {
139
- const { data: { x, re }, } = spectrum;
153
+ function getMaxY(spectrum, options) {
140
154
  const { from, to } = options;
155
+ const { data: { re, x }, } = spectrum;
156
+ const fromIndex = xFindClosestIndex(x, from);
157
+ const toIndex = xFindClosestIndex(x, to);
141
158
  let max = Number.NEGATIVE_INFINITY;
142
- for (const i in x) {
143
- if (x[i] >= from && x[i] <= to && re[i] > max) {
144
- max = re[i];
159
+ for (const value of re.slice(fromIndex, toIndex)) {
160
+ if (value > max) {
161
+ max = value;
145
162
  }
146
163
  }
147
164
  return max;
148
165
  }
149
- function getTreeRange(nodes, delta) {
150
- const range = { from: delta, to: delta };
151
- for (const node of nodes) {
152
- if (node._startX < range.from) {
153
- range.from = node._startX;
154
- }
155
- if (node._startX > range.to) {
156
- range.to = node._startX;
157
- }
158
- }
159
- return range;
160
- }
161
- function drawTree(treeData, { scaleX, labelOptions, showLabels }) {
162
- const { isMassive, signal, levelHeight, range, nodes, startY } = treeData;
163
- // const { levelHeight } = treeProps;
164
- // first tree level
165
- const firstLevelStartY = startY;
166
- let _startY = firstLevelStartY;
167
- // second tree level
168
- const secondLevelStartY = startY + levelHeight;
169
- _startY = secondLevelStartY;
170
- // third tree level
171
- _startY += levelHeight;
172
- if (isMassive) {
173
- const _rangeFrom = scaleX()(range.from);
174
- const _rangeTo = scaleX()(range.to);
175
- const pathData = `M ${_rangeFrom} ${_startY + levelHeight} ${_rangeFrom} ${_startY} ${scaleX()(signal.delta)} ${_startY} ${_rangeTo} ${_startY} ${_rangeTo} ${_startY + levelHeight}`;
176
- return (_jsxs("g", { children: [_jsx(StringNode, { signal: signal, startY: firstLevelStartY, levelHeight: levelHeight, fontSize: labelOptions.fontSize, showLabels: showLabels }), _jsx(LevelNode, { signal: signal, startY: secondLevelStartY, levelHeight: levelHeight }), _jsx("path", { d: pathData, stroke: "blue", fill: "none" })] }));
177
- }
178
- return (_jsxs("g", { children: [_jsx(StringNode, { signal: signal, startY: firstLevelStartY, levelHeight: levelHeight, fontSize: labelOptions.fontSize, showLabels: showLabels }), _jsx(LevelNode, { signal: signal, startY: secondLevelStartY, levelHeight: levelHeight }), _jsx(TreeNodes, { nodesData: nodes, signalID: nodes, showLabels: showLabels, startY: startY, labelOptions: labelOptions, levelHeight: levelHeight })] }));
166
+ function extractID(assignment) {
167
+ return [assignment.id].concat(assignment.assigned?.x || []);
179
168
  }
@@ -0,0 +1 @@
1
+ export default function MultiplicityTrees(): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { useChartData } from '../../context/ChartContext';
4
+ import { useActiveSpectrumRangesViewState } from '../../hooks/useActiveSpectrumRangesViewState';
5
+ import useSpectrum from '../../hooks/useSpectrum';
6
+ import MultiplicityTreeNode from './MultiplicityTree';
7
+ function MultiplicityTreesInner({ ranges, displayerKey, }) {
8
+ return (_jsx("g", { clipPath: `url(#${displayerKey}clip-chart-1d)`, children: ranges?.values?.map((range) => (_jsx(MultiplicityTreeNode, { range: range }, range.id))) }));
9
+ }
10
+ const MemoizedMultiplicityTrees = memo(MultiplicityTreesInner);
11
+ const emptyData = { ranges: {}, info: {}, display: {} };
12
+ export default function MultiplicityTrees() {
13
+ const { displayerKey } = useChartData();
14
+ const { showMultiplicityTrees } = useActiveSpectrumRangesViewState();
15
+ const spectrum = useSpectrum(emptyData);
16
+ if (!spectrum.ranges?.values ||
17
+ !spectrum.display.isVisible ||
18
+ spectrum.info?.isFid ||
19
+ !showMultiplicityTrees) {
20
+ return null;
21
+ }
22
+ return (_jsx(MemoizedMultiplicityTrees, { ranges: spectrum.ranges, displayerKey: displayerKey }));
23
+ }
@@ -0,0 +1,18 @@
1
+ import { Spectrum1D } from 'nmr-load-save';
2
+ import { Range } from 'nmr-processing';
3
+ export interface TreeNode {
4
+ x: number;
5
+ parentX?: number;
6
+ level: number;
7
+ ratio: number;
8
+ }
9
+ export interface TreeNodes {
10
+ rangeKey: string;
11
+ signalKey: string;
12
+ multiplicity?: string;
13
+ nodes: TreeNode[];
14
+ diaIDs?: string[];
15
+ min: number;
16
+ max: number;
17
+ }
18
+ export declare function generateTreeNodes(range: Range, spectrumData: Spectrum1D): TreeNodes[];
@@ -0,0 +1,66 @@
1
+ import lodashGet from 'lodash/get';
2
+ import { getMultiplicityNumber, getPascal, } from '../../panels/extra/utilities/MultiplicityUtilities';
3
+ export function generateTreeNodes(range, spectrumData) {
4
+ const frequency = lodashGet(spectrumData, 'info.originFrequency');
5
+ const result = [];
6
+ let nodes = [];
7
+ function generateNodes(startX, parentX, js, jsIndex, minMax) {
8
+ if (jsIndex >= js.length)
9
+ return;
10
+ const { multiplicity, coupling: couplingHz } = js[jsIndex];
11
+ const pascal = getPascal(getMultiplicityNumber(multiplicity), 0.5); // @TODO for now we use the default spin of 1 / 2 only
12
+ // convert to ppm
13
+ const coupling = couplingHz / frequency;
14
+ let x = pascal.length % 2 === 0
15
+ ? startX - (pascal.length / 2) * coupling + coupling / 2 // in case of even number of nodes
16
+ : startX - (pascal.length / 2 - 0.5) * coupling; // in case of odd number of nodes
17
+ for (const [k, ratio] of pascal.entries()) {
18
+ if (k > 0) {
19
+ x += coupling;
20
+ }
21
+ if (x < minMax.min) {
22
+ minMax.min = x;
23
+ }
24
+ if (x > minMax.max) {
25
+ minMax.max = x;
26
+ }
27
+ nodes.push({
28
+ x,
29
+ parentX,
30
+ ratio,
31
+ level: jsIndex,
32
+ });
33
+ generateNodes(x, x, js, jsIndex + 1, minMax);
34
+ }
35
+ }
36
+ const { signals, from, to, id: rangeKey } = range;
37
+ for (const signal of signals || []) {
38
+ nodes = [];
39
+ const { multiplicity, js, delta, id: signalKey, diaIDs } = signal;
40
+ const minMax = { min: delta, max: delta };
41
+ nodes.push({
42
+ x: delta,
43
+ level: 0,
44
+ ratio: 1,
45
+ });
46
+ if (!multiplicity)
47
+ continue;
48
+ if (multiplicity === 'm') {
49
+ nodes.push({ x: from, parentX: delta, level: 1, ratio: 1 }, { x: to, parentX: delta, level: 1, ratio: 1 });
50
+ minMax.min = from;
51
+ minMax.max = to;
52
+ }
53
+ else {
54
+ generateNodes(delta, delta, js, 0, minMax);
55
+ }
56
+ result.push({
57
+ rangeKey,
58
+ signalKey,
59
+ diaIDs,
60
+ multiplicity,
61
+ nodes,
62
+ ...minMax,
63
+ });
64
+ }
65
+ return result;
66
+ }
@@ -5,5 +5,5 @@ interface RangeProps {
5
5
  range: RangeType;
6
6
  relativeFormat: string;
7
7
  }
8
- declare function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, }: RangeProps): import("@emotion/react/jsx-runtime").JSX.Element;
8
+ declare function Range({ range, selectedTool, relativeFormat }: RangeProps): import("@emotion/react/jsx-runtime").JSX.Element;
9
9
  export default Range;
@@ -12,7 +12,6 @@ import { useActiveSpectrumRangesViewState } from '../../hooks/useActiveSpectrumR
12
12
  import { useResizerStatus } from '../../hooks/useResizerStatus';
13
13
  import { options } from '../../toolbar/ToolTypes';
14
14
  import { IntegralIndicator } from '../integral/IntegralIndicator';
15
- import { MultiplicityTree } from '../multiplicityTree/MultiplicityTree';
16
15
  import { useScaleX } from '../utilities/scale';
17
16
  import { AssignmentActionsButtons } from './AssignmentActionsButtons';
18
17
  import { Atoms } from './Atoms';
@@ -27,8 +26,8 @@ const style = css `
27
26
  }
28
27
  }
29
28
  `;
30
- function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, }) {
31
- const { id, integration, signals, diaIDs: rangeDiaIDs, from, to } = range;
29
+ function Range({ range, selectedTool, relativeFormat }) {
30
+ const { id, integration, signals, from, to, diaIDs: rangeDiaIDs } = range;
32
31
  const assignmentData = useAssignmentData();
33
32
  const assignmentRange = useAssignment(id);
34
33
  const highlightRange = useHighlight([assignmentRange.id].concat(assignmentRange.assigned?.x || []).concat(filterForIDsWithAssignment(assignmentData, signals.map((_signal) => _signal.id))), { type: HighlightEventSource.RANGE, extra: { id } });
@@ -56,6 +55,11 @@ function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, })
56
55
  assignmentRange.hide();
57
56
  highlightRange.hide();
58
57
  }
58
+ function assignHandler() {
59
+ if (!isBlockedByEditing) {
60
+ assignmentRange.setActive('x');
61
+ }
62
+ }
59
63
  function unAssignHandler(signalIndex = -1) {
60
64
  dispatch({
61
65
  type: 'UNLINK_RANGE',
@@ -66,11 +70,6 @@ function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, })
66
70
  },
67
71
  });
68
72
  }
69
- function assignHandler() {
70
- if (!isBlockedByEditing) {
71
- assignmentRange.setActive('x');
72
- }
73
- }
74
73
  const isNotSignal = !checkRangeKind(range);
75
74
  const isHighlighted = isBlockedByEditing || highlightRange.isActive || assignmentRange.isActive;
76
75
  const isAssigned = isRangeAssigned(range);
@@ -79,6 +78,6 @@ function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, })
79
78
  return (_jsxs("g", { "data-testid": "range", style: { outline: 'none' }, onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, ...(!assignmentRange.isActive && { css: style }), children: [_jsx(ResizerWithScale, { from: from, to: to, onEnd: handleOnStopResizing, disabled: !isResizingActive, children: ({ x1, x2 }, isActive) => {
80
79
  const width = x2 - x1;
81
80
  return (_jsxs("g", { children: [isAssigned && !isHighlighted && !isActive && (_jsx("rect", { width: width, height: "10px", fill: "#ffd700", opacity: "0.35", "data-no-export": "true" })), _jsx("rect", { width: width, height: "100%", fill: isHighlighted || isActive ? '#ff6f0057' : 'transparent', "data-no-export": "true" }), showIntegralsValues && (_jsx(IntegralIndicator, { value: integration, format: relativeFormat, width: width, opacity: isNotSignal ? 0.5 : 1 }))] }));
82
- } }), showMultiplicityTrees && (_jsx(MultiplicityTree, { range: range, onUnlink: unAssignHandler })), _jsx(Atoms, { range: range, x: startX }), _jsx(AssignmentActionsButtons, { isActive: !!(assignmentRange.isActive || rangeDiaIDs), x: startX, onAssign: assignHandler, onUnAssign: () => unAssignHandler() })] }, id));
81
+ } }), _jsx(Atoms, { range: range, x: startX }), _jsx(AssignmentActionsButtons, { isActive: !!(assignmentRange.isActive || rangeDiaIDs), x: startX, onAssign: assignHandler, onUnAssign: () => unAssignHandler() })] }, id));
83
82
  }
84
83
  export default Range;