nmrium 0.30.0 → 0.31.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 (230) hide show
  1. package/lib/component/1d/ApodizationLine.js +3 -1
  2. package/lib/component/1d/FooterBanner.js +3 -1
  3. package/lib/component/1d/IntegralsSeries.js +3 -1
  4. package/lib/component/1d/LinesSeries.js +3 -1
  5. package/lib/component/1d/SpectraTracker.js +1 -1
  6. package/lib/component/1d/Viewer1D.js +3 -1
  7. package/lib/component/1d/jCouplingGraph/JGraph.js +5 -1
  8. package/lib/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
  9. package/lib/component/1d/multiplicityTree/MultiplicityTree.js +3 -1
  10. package/lib/component/1d/peaks/PeakAnnotations.js +3 -1
  11. package/lib/component/1d/peaks/PeaksShapes.js +4 -2
  12. package/lib/component/1d/peaks/usePeakShapesPath.js +7 -3
  13. package/lib/component/1d/ranges/Ranges.js +8 -2
  14. package/lib/component/1d/tool/PeakPointer.js +3 -1
  15. package/lib/component/1d/tool/XLabelPointer.js +3 -1
  16. package/lib/component/2d/Contours.js +3 -1
  17. package/lib/component/2d/FooterBanner.js +3 -1
  18. package/lib/component/2d/Viewer2D.js +4 -4
  19. package/lib/component/2d/XAxis.js +2 -2
  20. package/lib/component/2d/YAxis.js +2 -2
  21. package/lib/component/2d/tools/XYLabelPointer.js +3 -1
  22. package/lib/component/2d/tools/slicing/SlicingView.js +3 -1
  23. package/lib/component/2d/zones/IndicationLines.js +1 -1
  24. package/lib/component/2d/zones/Zones.js +14 -19
  25. package/lib/component/NMRium.d.ts +2 -0
  26. package/lib/component/NMRium.js +14 -3
  27. package/lib/component/elements/popup/Modal/Provider.d.ts +3 -3
  28. package/lib/component/elements/popup/Modal/Provider.js +8 -11
  29. package/lib/component/header/ZeroFillingOptionsPanel.js +3 -1
  30. package/lib/component/hooks/useActiveSpectrumStyleOptions.js +2 -2
  31. package/lib/component/hooks/useDatumWithSpectraStatistics.js +3 -1
  32. package/lib/component/hooks/useExport.d.ts +0 -1
  33. package/lib/component/hooks/useExport.js +1 -17
  34. package/lib/component/hooks/useIntegralPath.js +5 -2
  35. package/lib/component/hooks/useNucleus.js +4 -4
  36. package/lib/component/hooks/useSpectraPerNucleus.js +1 -1
  37. package/lib/component/hooks/useSpectrum.js +3 -1
  38. package/lib/component/loader/DropZone.js +7 -147
  39. package/lib/component/modal/changeSum/SelectMolecule.js +1 -1
  40. package/lib/component/modal/editRange/EditRangeModal.js +1 -1
  41. package/lib/component/modal/setting/ToolsTabContent.js +4 -0
  42. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +1 -1
  43. package/lib/component/panels/MoleculesPanel/MoleculePanel.js +1 -1
  44. package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
  45. package/lib/component/panels/PeaksPanel/PeaksPanel.js +1 -1
  46. package/lib/component/panels/RangesPanel/RangesHeader.d.ts +2 -1
  47. package/lib/component/panels/RangesPanel/RangesHeader.js +10 -9
  48. package/lib/component/panels/RangesPanel/RangesPanel.js +7 -3
  49. package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +3 -1
  50. package/lib/component/panels/SpectrumsPanel/SpectrumsTabs.js +3 -1
  51. package/lib/component/panels/SummaryPanel/SummaryPanel.js +1 -1
  52. package/lib/component/panels/SummaryPanel/utilities/useInView.js +3 -1
  53. package/lib/component/panels/ZonesPanel/ZonesPanel.js +19 -10
  54. package/lib/component/panels/databasePanel/DatabasePanel.js +1 -1
  55. package/lib/component/reducer/IgnoreActions.js +1 -0
  56. package/lib/component/reducer/Reducer.d.ts +108 -49
  57. package/lib/component/reducer/Reducer.js +45 -41
  58. package/lib/component/reducer/actions/DomainActions.d.ts +1 -1
  59. package/lib/component/reducer/actions/DomainActions.js +11 -9
  60. package/lib/component/reducer/actions/FiltersActions.d.ts +1 -1
  61. package/lib/component/reducer/actions/FiltersActions.js +218 -232
  62. package/lib/component/reducer/actions/IntegralsActions.js +13 -8
  63. package/lib/component/reducer/actions/LoadActions.d.ts +2 -5
  64. package/lib/component/reducer/actions/LoadActions.js +19 -34
  65. package/lib/component/reducer/actions/MoleculeActions.d.ts +2 -1
  66. package/lib/component/reducer/actions/MoleculeActions.js +22 -6
  67. package/lib/component/reducer/actions/PeaksActions.js +18 -12
  68. package/lib/component/reducer/actions/PreferencesActions.js +8 -10
  69. package/lib/component/reducer/actions/RangesActions.d.ts +3 -3
  70. package/lib/component/reducer/actions/RangesActions.js +85 -27
  71. package/lib/component/reducer/actions/SpectraAnalysisAction.js +5 -5
  72. package/lib/component/reducer/actions/SpectrumsActions.js +13 -10
  73. package/lib/component/reducer/actions/ToolsActions.js +38 -23
  74. package/lib/component/reducer/actions/ZonesActions.d.ts +4 -1
  75. package/lib/component/reducer/actions/ZonesActions.js +68 -17
  76. package/lib/component/reducer/helper/Zoom1DManager.js +2 -1
  77. package/lib/component/reducer/helper/getActiveSpectrumOrFail.d.ts +3 -0
  78. package/lib/component/reducer/helper/getActiveSpectrumOrFail.js +6 -0
  79. package/lib/component/reducer/helper/getSpectrum.js +3 -2
  80. package/lib/component/reducer/helper/getStrongestPeak.js +2 -1
  81. package/lib/component/reducer/types/Types.d.ts +5 -0
  82. package/lib/component/reducer/types/Types.js +5 -0
  83. package/lib/component/tool/FloatMoleculeStructures/DraggableStructure.d.ts +6 -0
  84. package/lib/component/tool/FloatMoleculeStructures/DraggableStructure.js +10 -3
  85. package/lib/component/tool/FloatMoleculeStructures/index.js +14 -8
  86. package/lib/component/toolbar/BasicToolBar.js +4 -6
  87. package/lib/component/toolbar/FunctionToolBar.js +3 -1
  88. package/lib/component/utility/assert.d.ts +1 -0
  89. package/lib/component/utility/assert.js +5 -0
  90. package/lib/component/workspaces/exercise.js +6 -0
  91. package/lib/data/SpectraManager.d.ts +0 -4
  92. package/lib/data/SpectraManager.js +2 -87
  93. package/lib/data/data1d/Spectrum1D/peaks/autoPeakPicking.js +1 -0
  94. package/lib/data/data1d/Spectrum1D/ranges/autoRangesDetection.js +1 -0
  95. package/lib/data/data1d/filter1d/fft.js +11 -0
  96. package/lib/data/data1d/filter1d/utils/padDataToNextPowerOfTwo.d.ts +2 -0
  97. package/lib/data/data1d/filter1d/utils/padDataToNextPowerOfTwo.js +35 -0
  98. package/lib/data/data2d/Spectrum2D/zones/getDetectionZones.d.ts +1 -1
  99. package/lib/data/molecules/Molecule.d.ts +5 -0
  100. package/lib/versionInfo.js +1 -1
  101. package/lib-cjs/component/1d/ApodizationLine.js +3 -1
  102. package/lib-cjs/component/1d/FooterBanner.js +3 -1
  103. package/lib-cjs/component/1d/IntegralsSeries.js +3 -1
  104. package/lib-cjs/component/1d/LinesSeries.js +3 -1
  105. package/lib-cjs/component/1d/SpectraTracker.js +1 -1
  106. package/lib-cjs/component/1d/Viewer1D.js +3 -1
  107. package/lib-cjs/component/1d/jCouplingGraph/JGraph.js +5 -1
  108. package/lib-cjs/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
  109. package/lib-cjs/component/1d/multiplicityTree/MultiplicityTree.js +3 -1
  110. package/lib-cjs/component/1d/peaks/PeakAnnotations.js +3 -1
  111. package/lib-cjs/component/1d/peaks/PeaksShapes.js +4 -2
  112. package/lib-cjs/component/1d/peaks/usePeakShapesPath.js +7 -3
  113. package/lib-cjs/component/1d/ranges/Ranges.js +7 -1
  114. package/lib-cjs/component/1d/tool/PeakPointer.js +3 -1
  115. package/lib-cjs/component/1d/tool/XLabelPointer.js +3 -1
  116. package/lib-cjs/component/2d/Contours.js +3 -1
  117. package/lib-cjs/component/2d/FooterBanner.js +3 -1
  118. package/lib-cjs/component/2d/Viewer2D.js +4 -4
  119. package/lib-cjs/component/2d/XAxis.js +2 -2
  120. package/lib-cjs/component/2d/YAxis.js +2 -2
  121. package/lib-cjs/component/2d/tools/XYLabelPointer.js +3 -1
  122. package/lib-cjs/component/2d/tools/slicing/SlicingView.js +3 -1
  123. package/lib-cjs/component/2d/zones/IndicationLines.js +1 -1
  124. package/lib-cjs/component/2d/zones/Zones.js +13 -18
  125. package/lib-cjs/component/NMRium.js +14 -3
  126. package/lib-cjs/component/elements/popup/Modal/Provider.js +8 -11
  127. package/lib-cjs/component/header/ZeroFillingOptionsPanel.js +3 -1
  128. package/lib-cjs/component/hooks/useActiveSpectrumStyleOptions.js +2 -2
  129. package/lib-cjs/component/hooks/useDatumWithSpectraStatistics.js +3 -1
  130. package/lib-cjs/component/hooks/useExport.js +0 -16
  131. package/lib-cjs/component/hooks/useIntegralPath.js +5 -2
  132. package/lib-cjs/component/hooks/useNucleus.js +4 -4
  133. package/lib-cjs/component/hooks/useSpectraPerNucleus.js +1 -1
  134. package/lib-cjs/component/hooks/useSpectrum.js +3 -1
  135. package/lib-cjs/component/loader/DropZone.js +6 -149
  136. package/lib-cjs/component/modal/changeSum/SelectMolecule.js +1 -1
  137. package/lib-cjs/component/modal/editRange/EditRangeModal.js +1 -1
  138. package/lib-cjs/component/modal/setting/ToolsTabContent.js +4 -0
  139. package/lib-cjs/component/panels/IntegralsPanel/IntegralPanel.js +1 -1
  140. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanel.js +1 -1
  141. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
  142. package/lib-cjs/component/panels/PeaksPanel/PeaksPanel.js +1 -1
  143. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +10 -9
  144. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +7 -3
  145. package/lib-cjs/component/panels/SpectrumsPanel/SpectraPanelHeader.js +3 -1
  146. package/lib-cjs/component/panels/SpectrumsPanel/SpectrumsTabs.js +3 -1
  147. package/lib-cjs/component/panels/SummaryPanel/SummaryPanel.js +1 -1
  148. package/lib-cjs/component/panels/SummaryPanel/utilities/useInView.js +3 -1
  149. package/lib-cjs/component/panels/ZonesPanel/ZonesPanel.js +18 -9
  150. package/lib-cjs/component/panels/databasePanel/DatabasePanel.js +1 -1
  151. package/lib-cjs/component/reducer/IgnoreActions.js +1 -0
  152. package/lib-cjs/component/reducer/Reducer.js +48 -43
  153. package/lib-cjs/component/reducer/actions/DomainActions.js +11 -9
  154. package/lib-cjs/component/reducer/actions/FiltersActions.js +219 -233
  155. package/lib-cjs/component/reducer/actions/IntegralsActions.js +13 -8
  156. package/lib-cjs/component/reducer/actions/LoadActions.js +18 -36
  157. package/lib-cjs/component/reducer/actions/MoleculeActions.js +23 -6
  158. package/lib-cjs/component/reducer/actions/PeaksActions.js +18 -12
  159. package/lib-cjs/component/reducer/actions/PreferencesActions.js +8 -10
  160. package/lib-cjs/component/reducer/actions/RangesActions.js +85 -27
  161. package/lib-cjs/component/reducer/actions/SpectraAnalysisAction.js +5 -5
  162. package/lib-cjs/component/reducer/actions/SpectrumsActions.js +13 -10
  163. package/lib-cjs/component/reducer/actions/ToolsActions.js +38 -23
  164. package/lib-cjs/component/reducer/actions/ZonesActions.js +71 -17
  165. package/lib-cjs/component/reducer/helper/Zoom1DManager.js +2 -1
  166. package/lib-cjs/component/reducer/helper/getActiveSpectrumOrFail.js +10 -0
  167. package/lib-cjs/component/reducer/helper/getSpectrum.js +3 -2
  168. package/lib-cjs/component/reducer/helper/getStrongestPeak.js +2 -1
  169. package/lib-cjs/component/reducer/types/Types.js +8 -3
  170. package/lib-cjs/component/tool/FloatMoleculeStructures/DraggableStructure.js +10 -3
  171. package/lib-cjs/component/tool/FloatMoleculeStructures/index.js +14 -8
  172. package/lib-cjs/component/toolbar/BasicToolBar.js +4 -6
  173. package/lib-cjs/component/toolbar/FunctionToolBar.js +3 -1
  174. package/lib-cjs/component/utility/assert.js +9 -0
  175. package/lib-cjs/component/workspaces/exercise.js +6 -0
  176. package/lib-cjs/data/SpectraManager.js +3 -92
  177. package/lib-cjs/data/data1d/Spectrum1D/peaks/autoPeakPicking.js +1 -0
  178. package/lib-cjs/data/data1d/Spectrum1D/ranges/autoRangesDetection.js +1 -0
  179. package/lib-cjs/data/data1d/filter1d/fft.js +11 -0
  180. package/lib-cjs/data/data1d/filter1d/utils/padDataToNextPowerOfTwo.js +39 -0
  181. package/lib-cjs/versionInfo.js +1 -1
  182. package/package.json +22 -22
  183. package/lib/component/utility/nmredataToNmrium.d.ts +0 -4
  184. package/lib/component/utility/nmredataToNmrium.js +0 -66
  185. package/lib/component/utility/nmriumToNmredata.d.ts +0 -2
  186. package/lib/component/utility/nmriumToNmredata.js +0 -80
  187. package/lib/component/utility/util/nmredata/addRanges.d.ts +0 -1
  188. package/lib/component/utility/util/nmredata/addRanges.js +0 -52
  189. package/lib/component/utility/util/nmredata/addSource.d.ts +0 -6
  190. package/lib/component/utility/util/nmredata/addSource.js +0 -54
  191. package/lib/component/utility/util/nmredata/addZones.d.ts +0 -1
  192. package/lib/component/utility/util/nmredata/addZones.js +0 -41
  193. package/lib/component/utility/util/nmredata/flat2DSignals.d.ts +0 -1
  194. package/lib/component/utility/util/nmredata/flat2DSignals.js +0 -7
  195. package/lib/component/utility/util/nmredata/get1DSignals.d.ts +0 -10
  196. package/lib/component/utility/util/nmredata/get1DSignals.js +0 -96
  197. package/lib/component/utility/util/nmredata/get2DSignals.d.ts +0 -8
  198. package/lib/component/utility/util/nmredata/get2DSignals.js +0 -59
  199. package/lib/component/utility/util/nmredata/getCouplingObserved.d.ts +0 -1
  200. package/lib/component/utility/util/nmredata/getCouplingObserved.js +0 -11
  201. package/lib/component/utility/util/nmredata/getLabels.d.ts +0 -9
  202. package/lib/component/utility/util/nmredata/getLabels.js +0 -66
  203. package/lib/component/utility/util/nmredata/getToFix.d.ts +0 -1
  204. package/lib/component/utility/util/nmredata/getToFix.js +0 -19
  205. package/lib/data/migration/MigrationManager.d.ts +0 -2
  206. package/lib/data/migration/MigrationManager.js +0 -19
  207. package/lib/data/migration/changeKeys.d.ts +0 -1
  208. package/lib/data/migration/changeKeys.js +0 -9
  209. package/lib/data/migration/migrateToVersion1.d.ts +0 -11
  210. package/lib/data/migration/migrateToVersion1.js +0 -32
  211. package/lib/data/migration/migrateToVersion2.d.ts +0 -1
  212. package/lib/data/migration/migrateToVersion2.js +0 -111
  213. package/lib/data/migration/migrateToVersion3.d.ts +0 -1
  214. package/lib/data/migration/migrateToVersion3.js +0 -55
  215. package/lib-cjs/component/utility/nmredataToNmrium.js +0 -73
  216. package/lib-cjs/component/utility/nmriumToNmredata.js +0 -87
  217. package/lib-cjs/component/utility/util/nmredata/addRanges.js +0 -56
  218. package/lib-cjs/component/utility/util/nmredata/addSource.js +0 -61
  219. package/lib-cjs/component/utility/util/nmredata/addZones.js +0 -45
  220. package/lib-cjs/component/utility/util/nmredata/flat2DSignals.js +0 -11
  221. package/lib-cjs/component/utility/util/nmredata/get1DSignals.js +0 -100
  222. package/lib-cjs/component/utility/util/nmredata/get2DSignals.js +0 -63
  223. package/lib-cjs/component/utility/util/nmredata/getCouplingObserved.js +0 -15
  224. package/lib-cjs/component/utility/util/nmredata/getLabels.js +0 -70
  225. package/lib-cjs/component/utility/util/nmredata/getToFix.js +0 -23
  226. package/lib-cjs/data/migration/MigrationManager.js +0 -26
  227. package/lib-cjs/data/migration/changeKeys.js +0 -13
  228. package/lib-cjs/data/migration/migrateToVersion1.js +0 -35
  229. package/lib-cjs/data/migration/migrateToVersion2.js +0 -114
  230. package/lib-cjs/data/migration/migrateToVersion3.js +0 -58
@@ -13,6 +13,7 @@ import { options } from '../../toolbar/ToolTypes';
13
13
  import { getSpectraByNucleus } from '../../utility/getSpectraByNucleus';
14
14
  import nucleusToString from '../../utility/nucleusToString';
15
15
  import zoomHistoryManager from '../helper/ZoomHistoryManager';
16
+ import { getActiveSpectrumOrFail } from '../helper/getActiveSpectrumOrFail';
16
17
  import getRange from '../helper/getRange';
17
18
  import { getStrongestPeak } from '../helper/getStrongestPeak';
18
19
  import { setDomain, setMode } from './DomainActions';
@@ -20,202 +21,189 @@ import { changeSpectrumVerticalAlignment } from './PreferencesActions';
20
21
  import { resetSelectedTool } from './ToolsActions';
21
22
  function shiftSpectrumAlongXAxis(draft, shiftValue) {
22
23
  //apply filter into the spectrum
23
- if (draft.activeSpectrum?.id) {
24
- const index = draft.activeSpectrum?.index;
25
- FiltersManager.applyFilter(draft.data[index], [
26
- { name: Filters.shiftX.id, options: shiftValue },
27
- ]);
28
- updateXShift(draft.data[index]);
29
- resetSelectedTool(draft);
30
- setDomain(draft);
31
- }
24
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
25
+ const index = activeSpectrum?.index;
26
+ FiltersManager.applyFilter(draft.data[index], [
27
+ { name: Filters.shiftX.id, options: shiftValue },
28
+ ]);
29
+ updateXShift(draft.data[index]);
30
+ resetSelectedTool(draft);
31
+ setDomain(draft);
32
32
  }
33
33
  function applyZeroFillingFilter(draft, action) {
34
- if (draft.activeSpectrum?.id) {
35
- const index = draft.activeSpectrum.index;
36
- const { size } = action.payload;
37
- const filters = [
38
- {
39
- name: Filters.zeroFilling.id,
40
- options: size,
41
- },
42
- ];
43
- FiltersManager.applyFilter(draft.data[index], filters);
44
- resetSelectedTool(draft);
45
- setDomain(draft);
46
- setMode(draft);
47
- }
34
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
35
+ const index = activeSpectrum.index;
36
+ const { size } = action.payload;
37
+ const filters = [
38
+ {
39
+ name: Filters.zeroFilling.id,
40
+ options: size,
41
+ },
42
+ ];
43
+ FiltersManager.applyFilter(draft.data[index], filters);
44
+ resetSelectedTool(draft);
45
+ setDomain(draft);
46
+ setMode(draft);
48
47
  }
49
48
  function calculateApodizationFilter(draft, action) {
50
- if (draft.activeSpectrum) {
51
- const index = draft.activeSpectrum.index;
52
- const options = action.payload;
53
- const { data: { x, re, im }, info, } = draft.data[index];
54
- let _data = { data: { x, re, im }, info };
55
- draft.toolOptions.data.apodizationOptions = options;
56
- apodization(_data, options);
57
- const { im: newIm, re: newRe } = _data.data;
58
- draft.tempData[index].data.im = newIm;
59
- draft.tempData[index].data.re = newRe;
60
- }
49
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
50
+ const index = activeSpectrum.index;
51
+ const options = action.payload;
52
+ const { data: { x, re, im }, info, } = draft.data[index];
53
+ let _data = { data: { x, re, im }, info };
54
+ draft.toolOptions.data.apodizationOptions = options;
55
+ apodization(_data, options);
56
+ const { im: newIm, re: newRe } = _data.data;
57
+ draft.tempData[index].data.im = newIm;
58
+ draft.tempData[index].data.re = newRe;
61
59
  }
62
60
  function applyApodizationFilter(draft, action) {
63
- if (draft.activeSpectrum?.id) {
64
- const index = draft.activeSpectrum.index;
65
- const options = action.payload;
66
- const filters = [
67
- {
68
- name: Filters.apodization.id,
69
- options,
70
- },
71
- ];
72
- FiltersManager.applyFilter(draft.data[index], filters);
73
- resetSelectedTool(draft);
74
- setDomain(draft);
75
- setMode(draft);
76
- }
61
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
62
+ const index = activeSpectrum.index;
63
+ const options = action.payload;
64
+ const filters = [
65
+ {
66
+ name: Filters.apodization.id,
67
+ options,
68
+ },
69
+ ];
70
+ FiltersManager.applyFilter(draft.data[index], filters);
71
+ resetSelectedTool(draft);
72
+ setDomain(draft);
73
+ setMode(draft);
77
74
  }
78
75
  function calculateZeroFillingFilter(draft, action) {
79
- if (draft.activeSpectrum) {
80
- const index = draft.activeSpectrum.index;
81
- const { size } = action.payload;
82
- const { data: { x, re, im }, filters, info, } = draft.data[index];
83
- let _data = { data: { x, re, im }, filters, info };
84
- zeroFilling(_data, size);
85
- const { im: newIm, re: newRe, x: newX } = _data.data;
86
- draft.tempData[index].data.x = newX;
87
- draft.tempData[index].data.im = newIm;
88
- draft.tempData[index].data.re = newRe;
89
- draft.xDomain = [newX[0], newX[newX.length - 1]];
90
- }
76
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
77
+ const index = activeSpectrum.index;
78
+ const { size } = action.payload;
79
+ const { data: { x, re, im }, filters, info, } = draft.data[index];
80
+ let _data = { data: { x, re, im }, filters, info };
81
+ zeroFilling(_data, size);
82
+ const { im: newIm, re: newRe, x: newX } = _data.data;
83
+ draft.tempData[index].data.x = newX;
84
+ draft.tempData[index].data.im = newIm;
85
+ draft.tempData[index].data.re = newRe;
86
+ draft.xDomain = [newX[0], newX[newX.length - 1]];
91
87
  }
92
88
  function applyFFTFilter(draft) {
93
- if (draft.activeSpectrum?.id) {
94
- const { index } = draft.activeSpectrum;
95
- //apply filter into the spectrum
96
- FiltersManager.applyFilter(draft.data[index], [
97
- { name: Filters.fft.id, options: {} },
98
- ]);
99
- resetSelectedTool(draft);
100
- changeSpectrumVerticalAlignment(draft, { align: 'bottom' });
101
- setDomain(draft, { yDomain: { isChanged: true } });
102
- setMode(draft);
103
- }
89
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
90
+ const { index } = activeSpectrum;
91
+ //apply filter into the spectrum
92
+ FiltersManager.applyFilter(draft.data[index], [
93
+ { name: Filters.fft.id, options: {} },
94
+ ]);
95
+ resetSelectedTool(draft);
96
+ changeSpectrumVerticalAlignment(draft, { align: 'bottom' });
97
+ setDomain(draft, { yDomain: { isChanged: true } });
98
+ setMode(draft);
104
99
  }
105
100
  function applyManualPhaseCorrectionFilter(draft, filterOptions) {
106
- if (draft.activeSpectrum?.id) {
107
- const { index } = draft.activeSpectrum;
108
- const { ph0, ph1 } = filterOptions;
109
- FiltersManager.applyFilter(draft.data[index], [
110
- { name: Filters.phaseCorrection.id, options: { ph0, ph1 } },
111
- ]);
112
- resetSelectedTool(draft);
113
- draft.tempData = null;
114
- setDomain(draft);
115
- }
101
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
102
+ const { index } = activeSpectrum;
103
+ const { ph0, ph1 } = filterOptions;
104
+ FiltersManager.applyFilter(draft.data[index], [
105
+ { name: Filters.phaseCorrection.id, options: { ph0, ph1 } },
106
+ ]);
107
+ resetSelectedTool(draft);
108
+ draft.tempData = null;
109
+ setDomain(draft);
116
110
  }
117
111
  function applyAbsoluteFilter(draft) {
118
- if (draft.activeSpectrum?.id) {
119
- const { index } = draft.activeSpectrum;
120
- FiltersManager.applyFilter(draft.data[index], [
121
- { name: Filters.absolute.id, options: {} },
122
- ]);
123
- resetSelectedTool(draft);
124
- draft.tempData = null;
125
- setDomain(draft);
126
- }
112
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
113
+ const { index } = activeSpectrum;
114
+ FiltersManager.applyFilter(draft.data[index], [
115
+ { name: Filters.absolute.id, options: {} },
116
+ ]);
117
+ resetSelectedTool(draft);
118
+ draft.tempData = null;
119
+ setDomain(draft);
127
120
  }
128
121
  function applyAutoPhaseCorrectionFilter(draft) {
129
- if (draft.activeSpectrum?.id) {
130
- const { index } = draft.activeSpectrum;
131
- const { ph0, ph1 } = autoPhaseCorrection(draft.data[index]);
132
- FiltersManager.applyFilter(draft.data[index], [
133
- { name: Filters.phaseCorrection.id, options: { ph0, ph1 } },
134
- ]);
135
- resetSelectedTool(draft);
136
- draft.tempData = null;
137
- setDomain(draft);
138
- }
122
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
123
+ const { index } = activeSpectrum;
124
+ const { ph0, ph1 } = autoPhaseCorrection(draft.data[index]);
125
+ FiltersManager.applyFilter(draft.data[index], [
126
+ { name: Filters.phaseCorrection.id, options: { ph0, ph1 } },
127
+ ]);
128
+ resetSelectedTool(draft);
129
+ draft.tempData = null;
130
+ setDomain(draft);
139
131
  }
140
132
  function calculateBaseLineCorrection(draft, action) {
141
- if (draft.activeSpectrum) {
142
- const { index } = draft.activeSpectrum;
143
- const { data: { x, re, im }, info, } = draft.data[index];
144
- // save the baseline options temporary
145
- draft.toolOptions.data.baselineCorrection = {
146
- ...draft.toolOptions.data.baselineCorrection,
147
- ...(action?.options ? { options: action.options } : {}),
148
- };
149
- const { zones, options } = draft.toolOptions.data.baselineCorrection;
150
- const { livePreview, ...filterOptions } = options;
151
- if (livePreview) {
152
- let _data = { data: { x, re, im }, info };
153
- baselineCorrection(_data, {
154
- zones,
155
- ...filterOptions,
156
- });
157
- const { im: newIm, re: newRe } = _data.data;
158
- draft.tempData[index].data.im = newIm;
159
- draft.tempData[index].data.re = newRe;
160
- }
161
- }
162
- }
163
- function calculateManualPhaseCorrection(draft, filterOptions) {
164
- if (draft.activeSpectrum) {
165
- const { index } = draft.activeSpectrum;
166
- const { data: { x, re, im }, info, } = draft.data[index];
167
- const { ph0, ph1 } = filterOptions;
133
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
134
+ const { index } = activeSpectrum;
135
+ const { data: { x, re, im }, info, } = draft.data[index];
136
+ // save the baseline options temporary
137
+ draft.toolOptions.data.baselineCorrection = {
138
+ ...draft.toolOptions.data.baselineCorrection,
139
+ ...(action?.options ? { options: action.options } : {}),
140
+ };
141
+ const { zones, options } = draft.toolOptions.data.baselineCorrection;
142
+ const { livePreview, ...filterOptions } = options;
143
+ if (livePreview) {
168
144
  let _data = { data: { x, re, im }, info };
169
- phaseCorrection(_data, { ph0, ph1 });
145
+ baselineCorrection(_data, {
146
+ zones,
147
+ ...filterOptions,
148
+ });
170
149
  const { im: newIm, re: newRe } = _data.data;
171
150
  draft.tempData[index].data.im = newIm;
172
151
  draft.tempData[index].data.re = newRe;
173
152
  }
174
153
  }
154
+ function calculateManualPhaseCorrection(draft, filterOptions) {
155
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
156
+ const { index } = activeSpectrum;
157
+ const { data: { x, re, im }, info, } = draft.data[index];
158
+ const { ph0, ph1 } = filterOptions;
159
+ let _data = { data: { x, re, im }, info };
160
+ phaseCorrection(_data, { ph0, ph1 });
161
+ const { im: newIm, re: newRe } = _data.data;
162
+ draft.tempData[index].data.im = newIm;
163
+ draft.tempData[index].data.re = newRe;
164
+ }
175
165
  function enableFilter(draft, filterID, checked) {
176
- if (draft.activeSpectrum?.id) {
177
- const { index } = draft.activeSpectrum;
178
- //apply filter into the spectrum
179
- FiltersManager.enableFilter(draft.data[index], filterID, checked);
180
- if (draft.data[index].info?.dimension === 1) {
181
- updateXShift(draft.data[index]);
182
- }
183
- else if (draft.data[index].info?.dimension === 2) {
184
- update2dShift(draft.data[index]);
185
- }
186
- resetSelectedTool(draft);
187
- setDomain(draft);
188
- setMode(draft);
189
- const zoomHistory = zoomHistoryManager(draft.zoom.history, draft.activeTab);
190
- const zoomValue = zoomHistory.getLast();
191
- if (zoomValue) {
192
- draft.xDomain = zoomValue.xDomain;
193
- draft.yDomain = zoomValue.yDomain;
194
- }
166
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
167
+ const { index } = activeSpectrum;
168
+ //apply filter into the spectrum
169
+ FiltersManager.enableFilter(draft.data[index], filterID, checked);
170
+ if (draft.data[index].info?.dimension === 1) {
171
+ updateXShift(draft.data[index]);
172
+ }
173
+ else if (draft.data[index].info?.dimension === 2) {
174
+ update2dShift(draft.data[index]);
175
+ }
176
+ resetSelectedTool(draft);
177
+ setDomain(draft);
178
+ setMode(draft);
179
+ const zoomHistory = zoomHistoryManager(draft.zoom.history, draft.view.spectra.activeTab);
180
+ const zoomValue = zoomHistory.getLast();
181
+ if (zoomValue) {
182
+ draft.xDomain = zoomValue.xDomain;
183
+ draft.yDomain = zoomValue.yDomain;
195
184
  }
196
185
  }
197
186
  function deleteFilter(draft, actions) {
198
187
  const filterID = actions.payload.id;
199
- if (draft.activeSpectrum?.id) {
200
- const { index } = draft.activeSpectrum;
201
- //apply filter into the spectrum
202
- FiltersManager.deleteFilter(draft.data[index], filterID);
203
- if (draft.data[index].info?.dimension === 1) {
204
- updateXShift(draft.data[index]);
205
- }
206
- else if (draft.data[index].info?.dimension === 2) {
207
- update2dShift(draft.data[index]);
208
- }
209
- resetSelectedTool(draft);
210
- setDomain(draft);
211
- setMode(draft);
188
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
189
+ const { index } = activeSpectrum;
190
+ //apply filter into the spectrum
191
+ FiltersManager.deleteFilter(draft.data[index], filterID);
192
+ if (draft.data[index].info?.dimension === 1) {
193
+ updateXShift(draft.data[index]);
212
194
  }
195
+ else if (draft.data[index].info?.dimension === 2) {
196
+ update2dShift(draft.data[index]);
197
+ }
198
+ resetSelectedTool(draft);
199
+ setDomain(draft);
200
+ setMode(draft);
213
201
  }
214
202
  function deleteSpectraFilter(draft, actions) {
215
203
  const filterType = actions.payload.filterType;
216
- if (draft.activeTab) {
204
+ if (draft.view.spectra.activeTab) {
217
205
  for (const datum of draft.data) {
218
- if (nucleusToString(datum?.info?.nucleus) === draft.activeTab) {
206
+ if (nucleusToString(datum?.info?.nucleus) === draft.view.spectra.activeTab) {
219
207
  const filtersResult = datum.filters?.filter((filter) => filter.name === filterType) || [];
220
208
  filtersResult.forEach((filter) => {
221
209
  FiltersManager.deleteFilter(datum, filter.id);
@@ -234,24 +222,23 @@ function deleteSpectraFilter(draft, actions) {
234
222
  }
235
223
  }
236
224
  function handleBaseLineCorrectionFilter(draft, action) {
237
- if (draft.activeSpectrum?.id) {
238
- const { index } = draft.activeSpectrum;
239
- const { zones } = draft.toolOptions.data.baselineCorrection;
240
- const { livePreview, ...options } = action.options;
241
- FiltersManager.applyFilter(draft.data[index], [
242
- {
243
- name: Filters.baselineCorrection.id,
244
- options: {
245
- zones,
246
- ...options,
247
- },
225
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
226
+ const { index } = activeSpectrum;
227
+ const { zones } = draft.toolOptions.data.baselineCorrection;
228
+ const { livePreview, ...options } = action.options;
229
+ FiltersManager.applyFilter(draft.data[index], [
230
+ {
231
+ name: Filters.baselineCorrection.id,
232
+ options: {
233
+ zones,
234
+ ...options,
248
235
  },
249
- ]);
250
- const xDomainSnapshot = draft.xDomain.slice();
251
- resetSelectedTool(draft);
252
- setDomain(draft);
253
- draft.xDomain = xDomainSnapshot;
254
- }
236
+ },
237
+ ]);
238
+ const xDomainSnapshot = draft.xDomain.slice();
239
+ resetSelectedTool(draft);
240
+ setDomain(draft);
241
+ draft.xDomain = xDomainSnapshot;
255
242
  }
256
243
  /**
257
244
  * reset spectrum data for specific point of time (Filter)
@@ -266,48 +253,46 @@ function resetSpectrumByFilter(draft, options) {
266
253
  const { updateDomain = true, rollback = false, searchBy = 'id', applyFilter = false, // the filter that we rollback and return the affect data for the selected spectrum
267
254
  filterId, } = options || {};
268
255
  let currentDatum = null;
269
- const currentActiveSpectrum = draft.activeSpectrum;
270
- if (currentActiveSpectrum?.id) {
271
- const index = currentActiveSpectrum.index;
272
- const datum = draft.data[index];
273
- if (filterId && draft.toolOptions.data.activeFilterID !== filterId) {
274
- const filterIndex = datum.filters.findIndex((f) => f[searchBy] === filterId);
275
- let filters = [];
276
- if (filterIndex !== -1) {
277
- filters = datum.filters.slice(0, rollback ? filterIndex : filterIndex + 1);
278
- if (filters.length >= 1) {
279
- draft.toolOptions.data.activeFilterID =
280
- datum.filters[rollback ? filterIndex - 1 : filterIndex]?.id;
281
- }
282
- else {
283
- draft.toolOptions.data.activeFilterID = null;
284
- }
285
- FiltersManager.reapplyFilters(datum, filters);
286
- if (applyFilter) {
287
- const { name, value: options } = datum.filters[filterIndex];
288
- const newDatum = current(draft).data[index];
289
- if (newDatum.info?.dimension === 1) {
290
- FiltersManager.applyFilter(newDatum, [{ name, options }]);
291
- }
292
- currentDatum = { datum: newDatum, index };
256
+ const currentActiveSpectrum = getActiveSpectrumOrFail(draft);
257
+ const index = currentActiveSpectrum.index;
258
+ const datum = draft.data[index];
259
+ if (filterId && draft.toolOptions.data.activeFilterID !== filterId) {
260
+ const filterIndex = datum.filters.findIndex((f) => f[searchBy] === filterId);
261
+ let filters = [];
262
+ if (filterIndex !== -1) {
263
+ filters = datum.filters.slice(0, rollback ? filterIndex : filterIndex + 1);
264
+ if (filters.length >= 1) {
265
+ draft.toolOptions.data.activeFilterID =
266
+ datum.filters[rollback ? filterIndex - 1 : filterIndex]?.id;
267
+ }
268
+ else {
269
+ draft.toolOptions.data.activeFilterID = null;
270
+ }
271
+ FiltersManager.reapplyFilters(datum, filters);
272
+ if (applyFilter) {
273
+ const { name, value: options } = datum.filters[filterIndex];
274
+ const newDatum = current(draft).data[index];
275
+ if (newDatum.info?.dimension === 1) {
276
+ FiltersManager.applyFilter(newDatum, [{ name, options }]);
293
277
  }
278
+ currentDatum = { datum: newDatum, index };
294
279
  }
295
280
  }
296
- else {
297
- //close filter snapshot mode and replay all enabled filters
298
- draft.toolOptions.data.activeFilterID = null;
299
- FiltersManager.reapplyFilters(datum);
300
- }
301
- if (datum.info?.dimension === 1) {
302
- updateXShift(datum);
303
- }
304
- else if (datum.info?.dimension === 2) {
305
- update2dShift(datum);
306
- }
307
- if (updateDomain) {
308
- setDomain(draft);
309
- setMode(draft);
310
- }
281
+ }
282
+ else {
283
+ //close filter snapshot mode and replay all enabled filters
284
+ draft.toolOptions.data.activeFilterID = null;
285
+ FiltersManager.reapplyFilters(datum);
286
+ }
287
+ if (datum.info?.dimension === 1) {
288
+ updateXShift(datum);
289
+ }
290
+ else if (datum.info?.dimension === 2) {
291
+ update2dShift(datum);
292
+ }
293
+ if (updateDomain) {
294
+ setDomain(draft);
295
+ setMode(draft);
311
296
  }
312
297
  if (applyFilter) {
313
298
  return currentDatum;
@@ -318,7 +303,7 @@ function filterSnapshotHandler(draft, action) {
318
303
  resetSpectrumByFilter(draft, { filterId });
319
304
  }
320
305
  function handleMultipleSpectraFilter(draft, action) {
321
- const spectra = getSpectraByNucleus(draft.activeTab, draft.data);
306
+ const spectra = getSpectraByNucleus(draft.view.spectra.activeTab, draft.data);
322
307
  if (spectra && spectra.length > 0 && Array.isArray(action.payload)) {
323
308
  const exclusions = spectra[0].filters.find((f) => f.name === Filters.exclusionZones.id)
324
309
  ?.value || [];
@@ -341,12 +326,14 @@ function handleAddExclusionZone(draft, action) {
341
326
  const { from: startX, to: endX } = action.payload;
342
327
  const range = getRange(draft, { startX, endX });
343
328
  let spectra;
344
- if (draft.activeSpectrum?.id) {
345
- const index = draft.activeSpectrum?.index;
329
+ // todo: refactor this
330
+ const activeSpectrum = draft.view.spectra.activeSpectra[draft.view.spectra.activeTab];
331
+ if (activeSpectrum?.id) {
332
+ const index = activeSpectrum?.index;
346
333
  spectra = [draft.data[index]];
347
334
  }
348
335
  else {
349
- spectra = getSpectraByNucleus(draft.activeTab, draft.data);
336
+ spectra = getSpectraByNucleus(draft.view.spectra.activeTab, draft.data);
350
337
  }
351
338
  for (const spectrum of spectra) {
352
339
  FiltersManager.applyFilter(spectrum, [
@@ -382,7 +369,7 @@ function handleDeleteExclusionZone(draft, action) {
382
369
  }
383
370
  else {
384
371
  // remove all exclusive zone that have the same range in all spectra
385
- const data = getSpectraByNucleus(draft.activeTab, draft.data);
372
+ const data = getSpectraByNucleus(draft.view.spectra.activeTab, draft.data);
386
373
  for (const datum of data) {
387
374
  for (const filter of datum.filters) {
388
375
  if (filter.name === Filters.exclusionZones.id) {
@@ -409,7 +396,8 @@ function checkFilterHasTempData(selectedToolId) {
409
396
  ].includes(selectedToolId);
410
397
  }
411
398
  function setFilterChanges(draft, selectedFilterID) {
412
- const activeSpectrumId = draft.activeSpectrum?.id;
399
+ const activeSpectrum = getActiveSpectrumOrFail(draft);
400
+ const activeSpectrumId = activeSpectrum.id;
413
401
  // If the user selects the filter from the filters list or selects its tool and has a record in the filter list for preview and edit
414
402
  if (checkFilterHasTempData(selectedFilterID)) {
415
403
  //return back the spectra data to point of time before applying a specific filter
@@ -441,14 +429,12 @@ function setFilterChanges(draft, selectedFilterID) {
441
429
  break;
442
430
  }
443
431
  case options.baselineCorrection.id: {
444
- if (draft.activeSpectrum?.id) {
445
- const baselineCorrectionFilter = current(draft).data[draft.activeSpectrum.index].filters.find((filter) => filter.name === options.baselineCorrection.id);
446
- if (baselineCorrectionFilter) {
447
- draft.toolOptions.data.baselineCorrection.zones =
448
- baselineCorrectionFilter
449
- ? baselineCorrectionFilter.value.zones
450
- : [];
451
- }
432
+ const baselineCorrectionFilter = current(draft).data[activeSpectrum.index].filters.find((filter) => filter.name === options.baselineCorrection.id);
433
+ if (baselineCorrectionFilter) {
434
+ draft.toolOptions.data.baselineCorrection.zones =
435
+ baselineCorrectionFilter
436
+ ? baselineCorrectionFilter.value.zones
437
+ : [];
452
438
  }
453
439
  break;
454
440
  }
@@ -6,7 +6,8 @@ import { initSumOptions, setSumOptions, } from '../../../data/data1d/Spectrum1D/
6
6
  import getRange from '../helper/getRange';
7
7
  import { setIntegralsYDomain } from './DomainActions';
8
8
  function handleChangeIntegralSum(draft, options) {
9
- const { data, activeSpectrum, activeTab: nucleus } = draft;
9
+ const { data, view: { spectra: { activeTab: nucleus }, }, } = draft;
10
+ const activeSpectrum = draft.view.spectra.activeSpectra[draft.view.spectra.activeTab];
10
11
  if (activeSpectrum?.id) {
11
12
  const { index } = activeSpectrum;
12
13
  const datum = data[index];
@@ -16,7 +17,8 @@ function handleChangeIntegralSum(draft, options) {
16
17
  }
17
18
  function addIntegral(draft, action) {
18
19
  const { startX, endX } = action;
19
- const { data, molecules, activeTab: nucleus, activeSpectrum } = draft;
20
+ const { data, molecules, view: { spectra: { activeTab: nucleus }, }, } = draft;
21
+ const activeSpectrum = draft.view.spectra.activeSpectra[draft.view.spectra.activeTab];
20
22
  const [from, to] = getRange(draft, { startX, endX });
21
23
  if (activeSpectrum?.id) {
22
24
  const datum = data[activeSpectrum.index];
@@ -41,9 +43,10 @@ function addIntegral(draft, action) {
41
43
  }
42
44
  }
43
45
  function deleteIntegral(draft, action) {
44
- if (draft.activeSpectrum) {
46
+ const activeSpectrum = draft.view.spectra.activeSpectra[draft.view.spectra.activeTab];
47
+ if (activeSpectrum) {
45
48
  const state = original(draft);
46
- const { index } = draft.activeSpectrum;
49
+ const { index } = activeSpectrum;
47
50
  const { integralID } = action;
48
51
  const datum = draft.data[index];
49
52
  if (integralID == null) {
@@ -57,10 +60,11 @@ function deleteIntegral(draft, action) {
57
60
  }
58
61
  }
59
62
  function changeIntegral(draft, action) {
63
+ const activeSpectrum = draft.view.spectra.activeSpectra[draft.view.spectra.activeTab];
60
64
  const state = original(draft);
61
65
  const integral = action.payload.data;
62
- if (draft.activeSpectrum?.id) {
63
- const { index } = draft.activeSpectrum;
66
+ if (activeSpectrum?.id) {
67
+ const { index } = activeSpectrum;
64
68
  const originalDatum = state.data[index];
65
69
  const datum = draft.data[index];
66
70
  const { x, re } = originalDatum.data;
@@ -77,9 +81,10 @@ function changeIntegral(draft, action) {
77
81
  }
78
82
  }
79
83
  function handleChangeIntegralsRelativeValue(draft, action) {
84
+ const activeSpectrum = draft.view.spectra.activeSpectra[draft.view.spectra.activeTab];
80
85
  const data = action.payload.data;
81
- if (draft.activeSpectrum?.id) {
82
- const { index } = draft.activeSpectrum;
86
+ if (activeSpectrum?.id) {
87
+ const { index } = activeSpectrum;
83
88
  changeIntegralsRelative(draft.data[index], data);
84
89
  }
85
90
  }
@@ -2,10 +2,7 @@ import { Draft } from 'immer';
2
2
  import { State } from '../Reducer';
3
3
  declare function setIsLoading(draft: Draft<State>, isLoading: boolean): void;
4
4
  declare function initiate(draft: Draft<State>, action: any): State;
5
- declare function loadJDFFile(draft: Draft<State>, actions: any): void;
6
5
  declare function loadJcampFile(draft: Draft<State>, actions: any): void;
7
6
  declare function handleLoadJsonFile(draft: Draft<State>, action: any): State;
8
- declare function handleLoadMOLFile(draft: Draft<State>, actions: any): void;
9
- declare function handleLoadZIPFile(draft: Draft<State>, action: any): void;
10
- declare function handleLoadNmredata(draft: Draft<State>, action: any): State;
11
- export { setIsLoading, initiate, loadJcampFile, loadJDFFile, handleLoadJsonFile, handleLoadNmredata, handleLoadMOLFile, handleLoadZIPFile, };
7
+ declare function loadDropFiles(draft: Draft<State>, actions: any): void;
8
+ export { setIsLoading, initiate, loadJcampFile, loadDropFiles, handleLoadJsonFile, };