nmrium 0.48.0 → 0.50.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.
Files changed (154) hide show
  1. package/lib/component/1d/Chart1D.js +3 -1
  2. package/lib/component/1d/LinesSeries.js +1 -1
  3. package/lib/component/1d/SimilarityTree.d.ts +1 -0
  4. package/lib/component/1d/SimilarityTree.js +60 -0
  5. package/lib/component/1d/SpectraLegends.js +1 -1
  6. package/lib/component/1d/Viewer1D.js +142 -124
  7. package/lib/component/1d/jCouplingGraph/JsCoupling.js +1 -1
  8. package/lib/component/1d/multiplicityTree/MultiplicityTree.d.ts +1 -7
  9. package/lib/component/1d/multiplicityTree/MultiplicityTree.js +114 -125
  10. package/lib/component/1d/multiplicityTree/MultiplicityTrees.d.ts +1 -0
  11. package/lib/component/1d/multiplicityTree/MultiplicityTrees.js +23 -0
  12. package/lib/component/1d/multiplicityTree/generateTreeNodes.d.ts +18 -0
  13. package/lib/component/1d/multiplicityTree/generateTreeNodes.js +66 -0
  14. package/lib/component/1d/ranges/Atoms.d.ts +7 -0
  15. package/lib/component/1d/ranges/Atoms.js +43 -0
  16. package/lib/component/1d/ranges/Range.d.ts +1 -1
  17. package/lib/component/1d/ranges/Range.js +10 -9
  18. package/lib/component/1d/tool/BaseLine.d.ts +2 -0
  19. package/lib/component/1d/tool/BaseLine.js +26 -0
  20. package/lib/component/1d/tool/BaseLineZones.js +18 -3
  21. package/lib/component/2d/Chart2D.js +6 -4
  22. package/lib/component/2d/Viewer2D.js +35 -26
  23. package/lib/component/context/KeyModifierContext.d.ts +13 -2
  24. package/lib/component/context/KeyModifierContext.js +35 -4
  25. package/lib/component/context/LoggerContext.d.ts +9 -0
  26. package/lib/component/context/LoggerContext.js +21 -7
  27. package/lib/component/context/PreferencesContext.d.ts +1 -108
  28. package/lib/component/context/TopicMoleculeContext.d.ts +8 -0
  29. package/lib/component/context/TopicMoleculeContext.js +30 -0
  30. package/lib/component/elements/CloseButton.d.ts +2 -10
  31. package/lib/component/elements/CloseButton.js +3 -20
  32. package/lib/component/elements/CounterLabel.js +0 -1
  33. package/lib/component/elements/DeleteButton.d.ts +5 -7
  34. package/lib/component/elements/DeleteButton.js +7 -5
  35. package/lib/component/elements/FilterButton.d.ts +6 -0
  36. package/lib/component/elements/FilterButton.js +8 -0
  37. package/lib/component/elements/Input.js +4 -1
  38. package/lib/component/elements/PreferencesButton.d.ts +2 -4
  39. package/lib/component/elements/PreferencesButton.js +5 -3
  40. package/lib/component/elements/ReactTable/ReactTable.js +5 -2
  41. package/lib/component/elements/ResizerWithScale.js +19 -2
  42. package/lib/component/elements/SVGGroup.js +2 -2
  43. package/lib/component/elements/SaveButton.d.ts +2 -11
  44. package/lib/component/elements/SaveButton.js +4 -19
  45. package/lib/component/elements/ToolBarButton.d.ts +9 -0
  46. package/lib/component/elements/ToolBarButton.js +14 -0
  47. package/lib/component/elements/formik/FormikTextarea.js +8 -9
  48. package/lib/component/elements/linearAxis/LinearVerticalAxis.js +1 -1
  49. package/lib/component/elements/popup/Modal/ConfirmDialog.d.ts +2 -1
  50. package/lib/component/elements/popup/Modal/ConfirmDialog.js +11 -8
  51. package/lib/component/elements/resizer/SVGResizer.js +1 -1
  52. package/lib/component/header/BaseLineCorrectionPanel.js +3 -2
  53. package/lib/component/header/Header.js +2 -2
  54. package/lib/component/hooks/useCheckToolsVisibility.js +1 -1
  55. package/lib/component/hooks/useSaveSettings.js +3 -2
  56. package/lib/component/hooks/useToolsFunctions.js +4 -2
  57. package/lib/component/main/InnerNMRium.js +2 -1
  58. package/lib/component/main/InnerNMRiumContents.js +1 -1
  59. package/lib/component/modal/AboutPredictionModal.js +4 -8
  60. package/lib/component/modal/AboutSpectrumSimulationModal.js +4 -8
  61. package/lib/component/modal/CopyClipboardModal.js +1 -1
  62. package/lib/component/modal/EditPeakShapeModal.js +2 -2
  63. package/lib/component/modal/ExportAsJcampModal.d.ts +1 -1
  64. package/lib/component/modal/ExportAsJcampModal.js +8 -4
  65. package/lib/component/modal/ImportPublicationStringModal.d.ts +2 -1
  66. package/lib/component/modal/ImportPublicationStringModal.js +80 -32
  67. package/lib/component/modal/LoadJCAMPModal.js +12 -9
  68. package/lib/component/modal/LogsHistoryModal.d.ts +1 -1
  69. package/lib/component/modal/LogsHistoryModal.js +9 -4
  70. package/lib/component/modal/MoleculeStructureEditorModal.js +10 -3
  71. package/lib/component/modal/MultipletAnalysisModal.js +8 -8
  72. package/lib/component/modal/PredictSpectraModal.js +6 -5
  73. package/lib/component/modal/SaveAsModal.js +2 -2
  74. package/lib/component/modal/aboutUs/AboutUsModal.js +11 -26
  75. package/lib/component/modal/changeSum/ChangeSumModal.d.ts +4 -3
  76. package/lib/component/modal/changeSum/ChangeSumModal.js +10 -3
  77. package/lib/component/modal/changeSum/ChangeSumModalContents.d.ts +1 -3
  78. package/lib/component/modal/changeSum/ChangeSumModalContents.js +9 -6
  79. package/lib/component/modal/editRange/EditRangeModal.js +8 -6
  80. package/lib/component/modal/editRange/forms/components/AddSignalFormTab.js +1 -0
  81. package/lib/component/modal/editRange/forms/components/CouplingsTable.js +13 -10
  82. package/lib/component/modal/editRange/forms/components/SignalFormTab.js +1 -1
  83. package/lib/component/modal/editRange/forms/components/SignalsForm.js +1 -0
  84. package/lib/component/modal/editZone/EditZoneModal.js +3 -3
  85. package/lib/component/modal/metaImportation/MetaImportationModal.js +1 -1
  86. package/lib/component/modal/setting/GeneralSettings.js +17 -38
  87. package/lib/component/modal/setting/settings-tabs/GeneralTabContent.js +9 -11
  88. package/lib/component/modal/setting/settings-tabs/OnLoadProcessingTabContent.js +2 -4
  89. package/lib/component/panels/AutomaticAssignment/AutomaticAssignment.js +2 -2
  90. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +6 -23
  91. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +3 -3
  92. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +6 -4
  93. package/lib/component/panels/PeaksPanel/PeaksPanel.js +7 -8
  94. package/lib/component/panels/PeaksPanel/PeaksToggleActions.d.ts +8 -6
  95. package/lib/component/panels/PeaksPanel/PeaksToggleActions.js +3 -6
  96. package/lib/component/panels/RangesPanel/RangesHeader.d.ts +1 -1
  97. package/lib/component/panels/RangesPanel/RangesHeader.js +8 -31
  98. package/lib/component/panels/RangesPanel/RangesTable.js +1 -1
  99. package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +2 -2
  100. package/lib/component/panels/SpectrumsPanel/SpectraPreferences.js +39 -5
  101. package/lib/component/panels/SpectrumsPanel/SpectraTable.js +42 -11
  102. package/lib/component/panels/SpectrumsPanel/SpectrumListPanel.js +4 -2
  103. package/lib/component/panels/SpectrumsPanel/base/SpectraColumnsManager.js +19 -16
  104. package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.js +1 -1
  105. package/lib/component/panels/SummaryPanel/SetMolecularFormulaModal.js +1 -1
  106. package/lib/component/panels/SummaryPanel/SetShiftTolerancesModal.js +1 -1
  107. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -3
  108. package/lib/component/panels/ZonesPanel/ZonesPanel.js +2 -26
  109. package/lib/component/panels/databasePanel/DatabasePanel.js +6 -6
  110. package/lib/component/panels/databasePanel/DatabaseSearchOptions.d.ts +4 -6
  111. package/lib/component/panels/databasePanel/DatabaseSearchOptions.js +12 -13
  112. package/lib/component/panels/databasePanel/DatabaseStructureSearchModal.js +7 -8
  113. package/lib/component/panels/filtersPanel/FiltersTable.js +1 -1
  114. package/lib/component/panels/header/DefaultPanelHeader.js +9 -4
  115. package/lib/component/panels/header/PanelHeader.js +0 -1
  116. package/lib/component/panels/header/PreferencesHeader.d.ts +2 -4
  117. package/lib/component/panels/header/PreferencesHeader.js +9 -23
  118. package/lib/component/panels/header/SpectraAutomaticPickingButton.js +2 -2
  119. package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -9
  120. package/lib/component/panels/spectrumSimulation/SpectrumSimulationSimpleOptions.js +3 -3
  121. package/lib/component/reducer/Reducer.js +5 -0
  122. package/lib/component/reducer/actions/DatabaseActions.d.ts +3 -2
  123. package/lib/component/reducer/actions/DatabaseActions.js +5 -1
  124. package/lib/component/reducer/actions/FiltersActions.d.ts +3 -4
  125. package/lib/component/reducer/actions/FiltersActions.js +92 -55
  126. package/lib/component/reducer/actions/LoadActions.js +10 -8
  127. package/lib/component/reducer/actions/SpectrumsActions.d.ts +8 -1
  128. package/lib/component/reducer/actions/SpectrumsActions.js +3 -3
  129. package/lib/component/reducer/actions/ToolsActions.d.ts +8 -5
  130. package/lib/component/reducer/actions/ToolsActions.js +51 -44
  131. package/lib/component/toolbar/BasicToolBar.js +11 -29
  132. package/lib/component/utility/export.js +3 -0
  133. package/lib/component/workspaces/exercise.js +1 -0
  134. package/lib/component/workspaces/prediction.js +1 -16
  135. package/lib/component/workspaces/simulation.js +1 -2
  136. package/lib/component/workspaces/workspaceDefaultProperties.js +4 -3
  137. package/lib/data/data1d/Spectrum1D/index.d.ts +0 -1
  138. package/lib/data/data1d/Spectrum1D/index.js +0 -1
  139. package/lib/utils/clipboard/clipboardComponents.d.ts +2 -2
  140. package/lib/utils/clipboard/clipboardComponents.js +8 -3
  141. package/lib/versionInfo.js +1 -1
  142. package/package.json +25 -23
  143. package/lib/component/1d/multiplicityTree/LevelNode.d.ts +0 -8
  144. package/lib/component/1d/multiplicityTree/LevelNode.js +0 -8
  145. package/lib/component/1d/multiplicityTree/StringNode.d.ts +0 -11
  146. package/lib/component/1d/multiplicityTree/StringNode.js +0 -7
  147. package/lib/component/1d/multiplicityTree/TreeColors.d.ts +0 -1
  148. package/lib/component/1d/multiplicityTree/TreeColors.js +0 -1
  149. package/lib/component/1d/multiplicityTree/TreeNodes.d.ts +0 -21
  150. package/lib/component/1d/multiplicityTree/TreeNodes.js +0 -23
  151. package/lib/component/1d/multiplicityTree/buildTreeNode.d.ts +0 -11
  152. package/lib/component/1d/multiplicityTree/buildTreeNode.js +0 -57
  153. package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.d.ts +0 -2
  154. package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.js +0 -6
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ import { Range } from 'nmr-processing';
2
+ interface AtomsProps {
3
+ range: Range;
4
+ x: number;
5
+ }
6
+ export declare function Atoms(props: AtomsProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useChartData } from '../../context/ChartContext';
3
+ import { useTopicMolecule } from '../../context/TopicMoleculeContext';
4
+ const fontSize = 12;
5
+ const lineHeight = fontSize * 1.1;
6
+ const marginTop = 55;
7
+ function getDiaIds(range) {
8
+ const { diaIDs = [], signals } = range;
9
+ const ids = diaIDs.slice();
10
+ for (const signal of signals) {
11
+ if (signal?.diaIDs) {
12
+ ids.push(...signal.diaIDs);
13
+ }
14
+ }
15
+ return ids;
16
+ }
17
+ function useAtoms(range) {
18
+ const topicMolecule = useTopicMolecule();
19
+ const diaIDs = getDiaIds(range);
20
+ const atomsList = [];
21
+ for (const [id, topicMoleculeObject] of Object.entries(topicMolecule)) {
22
+ const atoms = [];
23
+ const diaIDsObject = topicMoleculeObject.getDiaIDsObject();
24
+ for (const id of diaIDs) {
25
+ const existingAtoms = diaIDsObject[id]?.existingAtoms;
26
+ if (existingAtoms?.length > 0) {
27
+ atoms.push(...existingAtoms);
28
+ }
29
+ }
30
+ if (atoms.length > 0) {
31
+ atomsList.push({ id, atoms: [...new Set(atoms.sort((a, b) => a - b))] });
32
+ }
33
+ }
34
+ return atomsList;
35
+ }
36
+ export function Atoms(props) {
37
+ const { range, x } = props;
38
+ const { view: { molecules }, } = useChartData();
39
+ const atomsList = useAtoms(range).filter((atomsList) => molecules?.[atomsList.id]?.showAtomNumber);
40
+ return (_jsx("g", { transform: `translate(${x},${marginTop})`, children: atomsList.map((row, rowIndex) => (
41
+ // eslint-disable-next-line react/no-array-index-key
42
+ _jsx("g", { transform: `translate(${rowIndex * lineHeight}, 0)`, children: row.atoms.map((item, colIndex) => (_jsx("text", { x: 0, y: colIndex * lineHeight, fontSize: fontSize, fill: "black", children: item }, colIndex))) }, rowIndex))) }));
43
+ }
@@ -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,9 +12,9 @@ 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';
17
+ import { Atoms } from './Atoms';
18
18
  const style = css `
19
19
  .target {
20
20
  visibility: hidden;
@@ -26,8 +26,8 @@ const style = css `
26
26
  }
27
27
  }
28
28
  `;
29
- function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, }) {
30
- const { id, integration, signals, diaIDs, from, to } = range;
29
+ function Range({ range, selectedTool, relativeFormat }) {
30
+ const { id, integration, signals, from, to, diaIDs: rangeDiaIDs } = range;
31
31
  const assignmentData = useAssignmentData();
32
32
  const assignmentRange = useAssignment(id);
33
33
  const highlightRange = useHighlight([assignmentRange.id].concat(assignmentRange.assigned?.x || []).concat(filterForIDsWithAssignment(assignmentData, signals.map((_signal) => _signal.id))), { type: HighlightEventSource.RANGE, extra: { id } });
@@ -55,6 +55,11 @@ function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, })
55
55
  assignmentRange.hide();
56
56
  highlightRange.hide();
57
57
  }
58
+ function assignHandler() {
59
+ if (!isBlockedByEditing) {
60
+ assignmentRange.setActive('x');
61
+ }
62
+ }
58
63
  function unAssignHandler(signalIndex = -1) {
59
64
  dispatch({
60
65
  type: 'UNLINK_RANGE',
@@ -65,18 +70,14 @@ function Range({ range, showMultiplicityTrees, selectedTool, relativeFormat, })
65
70
  },
66
71
  });
67
72
  }
68
- function assignHandler() {
69
- if (!isBlockedByEditing) {
70
- assignmentRange.setActive('x');
71
- }
72
- }
73
73
  const isNotSignal = !checkRangeKind(range);
74
74
  const isHighlighted = isBlockedByEditing || highlightRange.isActive || assignmentRange.isActive;
75
75
  const isAssigned = isRangeAssigned(range);
76
76
  const isResizingActive = useResizerStatus('rangePicking');
77
+ const startX = scaleX()(from) - 16;
77
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) => {
78
79
  const width = x2 - x1;
79
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 }))] }));
80
- } }), showMultiplicityTrees && (_jsx(MultiplicityTree, { range: range, onUnlink: unAssignHandler })), _jsx(AssignmentActionsButtons, { isActive: !!(assignmentRange.isActive || diaIDs), x: scaleX()(from) - 16, 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));
81
82
  }
82
83
  export default Range;
@@ -0,0 +1,2 @@
1
+ declare function BaseLine(): import("react/jsx-runtime").JSX.Element | null;
2
+ export default BaseLine;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useChartData } from '../../context/ChartContext';
3
+ import { useScaleChecked } from '../../context/ScaleContext';
4
+ import { options } from '../../toolbar/ToolTypes';
5
+ const styles = {
6
+ transformOrigin: 'top left',
7
+ position: 'absolute',
8
+ top: '0px',
9
+ left: '0px',
10
+ height: 1,
11
+ backgroundColor: 'yellow',
12
+ };
13
+ function BaseLine() {
14
+ const { width, margin: { left, right }, toolOptions: { selectedTool }, } = useChartData();
15
+ const { scaleY } = useScaleChecked();
16
+ const innerWidth = width - left - right;
17
+ if (![options.phaseCorrection.id, options.baselineCorrection.id].includes(selectedTool)) {
18
+ return null;
19
+ }
20
+ return (_jsx("div", { style: {
21
+ ...styles,
22
+ transform: `translate(${left}px, ${scaleY()(0)}px)`,
23
+ width: innerWidth,
24
+ } }));
25
+ }
26
+ export default BaseLine;
@@ -1,7 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useChartData } from '../../context/ChartContext';
3
+ import { useDispatch } from '../../context/DispatchContext';
3
4
  import { useScaleChecked } from '../../context/ScaleContext';
5
+ import { ResizerWithScale } from '../../elements/ResizerWithScale';
4
6
  import { useHighlight } from '../../highlight';
7
+ import { useResizerStatus } from '../../hooks/useResizerStatus';
5
8
  function BaseLineZones() {
6
9
  const { toolOptions: { selectedTool, data: { baselineCorrection }, }, } = useChartData();
7
10
  const baseLineZones = baselineCorrection.zones;
@@ -14,8 +17,20 @@ function BaseLineZone(props) {
14
17
  const { from, to, id } = props;
15
18
  const { onHover, isActive, defaultActiveStyle: { backgroundColor: activeFill }, } = useHighlight([id], { type: 'BASELINE_ZONE', extra: { id } });
16
19
  const { scaleX } = useScaleChecked();
17
- const x = scaleX()(to);
18
- const width = scaleX()(from) - scaleX()(to);
19
- return (_jsx("g", { transform: `translate(${x},0)`, ...onHover, children: _jsx("rect", { x: "0", width: width, height: "100%", style: { backgroundColor: 'red' }, fill: isActive ? activeFill : '#b8b8b857' }) }));
20
+ const dispatch = useDispatch();
21
+ function handleOnStopResizing(position) {
22
+ dispatch({
23
+ type: 'RESIZE_BASE_LINE_ZONE',
24
+ payload: {
25
+ id,
26
+ from: scaleX().invert(position.x2),
27
+ to: scaleX().invert(position.x1),
28
+ },
29
+ });
30
+ }
31
+ const isResizingActive = useResizerStatus('baselineCorrection');
32
+ return (_jsx("g", { ...onHover, className: "base-line-zones", children: _jsx(ResizerWithScale, { from: from, to: to, onEnd: handleOnStopResizing, disabled: !isResizingActive, children: ({ x1, x2 }, isResizeActive) => {
33
+ return (_jsx("rect", { width: Math.abs(x2 - x1), height: "100%", fill: isActive && !isResizeActive ? activeFill : '#b8b8b857' }));
34
+ } }) }));
20
35
  }
21
36
  export default BaseLineZones;
@@ -9,12 +9,14 @@ import { FidContainer } from './fid/FidContainer';
9
9
  import { FTContainer } from './ft/FTContainer';
10
10
  import IndicationLines from './zones/IndicationLines';
11
11
  import Zones from './zones/Zones';
12
- function chart2DInner({ spectra, width, height, margin, displayerKey, SpectraRendering, }) {
13
- return (_jsxs("svg", { viewBox: `0 0 ${width} ${height}`, width: width, height: height, id: "nmrSVG", shapeRendering: SpectraRendering, style: { position: 'absolute' }, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${displayerKey}clip-chart-2d`, children: _jsx("rect", { width: width - margin.left - margin.right, height: height - margin.top - margin.bottom, x: margin.left, y: margin.top }) }) }), _jsx("rect", { width: width - margin.left - margin.right, height: height - margin.top - margin.bottom, x: margin.left, y: margin.top, stroke: "black", strokeWidth: "1", fill: "transparent" }), _jsx(FTContainer, { spectra: spectra }), _jsx(FidContainer, {}), _jsx(Zones, {}), _jsx(IndicationLines, { axis: "X", show: true }), _jsx(IndicationLines, { axis: "Y", show: true }), _jsx(SpectrumInfoBlock, {}), _jsxs("g", { className: "container", style: { pointerEvents: 'none' }, children: [_jsx(XAxis, {}), _jsx(YAxis, {})] })] }));
12
+ function chart2DInner({ spectra, width, height, margin, displayerKey, spectraRendering, }) {
13
+ return (_jsxs("svg", { id: "nmrSVG", viewBox: `0 0 ${width} ${height}`, width: width, height: height, fontFamily: "Arial, Helvetica, sans-serif", shapeRendering: spectraRendering, style: {
14
+ position: 'absolute',
15
+ }, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${displayerKey}clip-chart-2d`, children: _jsx("rect", { width: width - margin.left - margin.right, height: height - margin.top - margin.bottom, x: margin.left, y: margin.top }) }) }), _jsx("rect", { width: width - margin.left - margin.right, height: height - margin.top - margin.bottom, x: margin.left, y: margin.top, stroke: "black", strokeWidth: "1", fill: "transparent" }), _jsx(FTContainer, { spectra: spectra }), _jsx(FidContainer, {}), _jsx(Zones, {}), _jsx(IndicationLines, { axis: "X", show: true }), _jsx(IndicationLines, { axis: "Y", show: true }), _jsx(SpectrumInfoBlock, {}), _jsxs("g", { className: "container", style: { pointerEvents: 'none' }, children: [_jsx(XAxis, {}), _jsx(YAxis, {})] })] }));
14
16
  }
15
17
  const MemoizedChart2D = memo(chart2DInner);
16
18
  export default function Chart2D({ spectra }) {
17
19
  const { width, height, margin, displayerKey } = useChartData();
18
- const { current: { general: { SpectraRendering }, }, } = usePreferences();
19
- return (_jsx(MemoizedChart2D, { spectra, width, height, margin, displayerKey, SpectraRendering }));
20
+ const { current: { general: { spectraRendering }, }, } = usePreferences();
21
+ return (_jsx(MemoizedChart2D, { spectra, width, height, margin, displayerKey, spectraRendering }));
20
22
  }