nmrium 0.31.0 → 0.33.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 (178) hide show
  1. package/lib/component/1d/Chart1D.js +1 -1
  2. package/lib/component/1d/FooterBanner.js +17 -10
  3. package/lib/component/1d/{Integral.d.ts → integral/Integral.d.ts} +0 -0
  4. package/lib/component/1d/{Integral.js → integral/Integral.js} +2 -2
  5. package/lib/component/1d/integral/IntegralIndicator.d.ts +9 -0
  6. package/lib/component/1d/integral/IntegralIndicator.js +27 -0
  7. package/lib/component/1d/{IntegralResizable.d.ts → integral/IntegralResizable.d.ts} +0 -0
  8. package/lib/component/1d/integral/IntegralResizable.js +69 -0
  9. package/lib/component/1d/{IntegralsSeries.d.ts → integral/IntegralsSeries.d.ts} +0 -0
  10. package/lib/component/1d/{IntegralsSeries.js → integral/IntegralsSeries.js} +3 -3
  11. package/lib/component/1d/ranges/Range.js +27 -50
  12. package/lib/component/1d/utilities/scale.js +2 -2
  13. package/lib/component/2d/Contours.js +61 -42
  14. package/lib/component/2d/Left1DChart.js +1 -1
  15. package/lib/component/2d/Top1DChart.js +1 -1
  16. package/lib/component/EventsTrackers/BrushTracker.js +30 -21
  17. package/lib/component/NMRium.d.ts +1 -1
  18. package/lib/component/NMRium.js +1 -1
  19. package/lib/component/SplitPaneWrapper.js +1 -1
  20. package/lib/component/elements/EditableColumn.d.ts +3 -1
  21. package/lib/component/elements/EditableColumn.js +18 -3
  22. package/lib/component/elements/formik/FormikColorPicker.d.ts +0 -1
  23. package/lib/component/elements/formik/FormikColorPicker.js +5 -8
  24. package/lib/component/elements/formik/FormikInput.d.ts +0 -1
  25. package/lib/component/elements/formik/FormikInput.js +8 -19
  26. package/lib/component/elements/formik/FormikOnChange.d.ts +1 -1
  27. package/lib/component/elements/formik/FormikOnChange.js +13 -10
  28. package/lib/component/elements/formik/FormikSlider.d.ts +2 -4
  29. package/lib/component/elements/formik/FormikSlider.js +8 -11
  30. package/lib/component/hooks/useActiveSpectrumStyleOptions.js +1 -1
  31. package/lib/component/hooks/useExport.js +1 -1
  32. package/lib/component/loader/DropZone.js +9 -1
  33. package/lib/component/modal/ExportAsMatrixModal.js +1 -1
  34. package/lib/component/modal/editRange/forms/components/SignalFormInfo.js +1 -1
  35. package/lib/component/modal/setting/GeneralTabContent.js +1 -1
  36. package/lib/component/panels/MoleculesPanel/MoleculeHeader.js +1 -1
  37. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +1 -1
  38. package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
  39. package/lib/component/panels/PeaksPanel/PeaksTable.js +1 -1
  40. package/lib/component/panels/RangesPanel/RangesHeader.js +1 -1
  41. package/lib/component/panels/RangesPanel/RangesPanel.js +1 -1
  42. package/lib/component/panels/RangesPanel/RangesTableRow.js +1 -3
  43. package/lib/component/panels/SpectrumsPanel/SpectrumsTabs.js +1 -1
  44. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum1DSetting.d.ts +1 -1
  45. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum1DSetting.js +2 -1
  46. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum2DSetting.d.ts +1 -1
  47. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum2DSetting.js +2 -1
  48. package/lib/component/panels/SpectrumsPanel/base/setting/processSnapPlot.js +3 -26
  49. package/lib/component/panels/extra/preferences/ColumnsHelper.js +5 -2
  50. package/lib/component/reducer/Reducer.d.ts +20 -59
  51. package/lib/component/reducer/Reducer.js +24 -10
  52. package/lib/component/reducer/actions/DomainActions.js +3 -2
  53. package/lib/component/reducer/actions/FiltersActions.js +12 -3
  54. package/lib/component/reducer/actions/IntegralsActions.js +6 -5
  55. package/lib/component/reducer/actions/PeaksActions.js +7 -6
  56. package/lib/component/reducer/actions/PreferencesActions.js +18 -36
  57. package/lib/component/reducer/actions/RangesActions.d.ts +1 -1
  58. package/lib/component/reducer/actions/RangesActions.js +20 -16
  59. package/lib/component/reducer/actions/SpectrumsActions.js +13 -6
  60. package/lib/component/reducer/actions/ToolsActions.d.ts +1 -1
  61. package/lib/component/reducer/actions/ToolsActions.js +15 -28
  62. package/lib/component/reducer/actions/ZonesActions.js +9 -8
  63. package/lib/component/reducer/core/Constants.js +1 -1
  64. package/lib/component/reducer/helper/getActiveSpectrum.d.ts +3 -0
  65. package/lib/component/reducer/helper/getActiveSpectrum.js +4 -0
  66. package/lib/component/reducer/preferences/preferencesReducer.d.ts +2 -2
  67. package/lib/component/toolbar/BasicToolBar.js +8 -7
  68. package/lib/component/utility/FileUtility.d.ts +1 -8
  69. package/lib/component/utility/FileUtility.js +2 -17
  70. package/lib/component/utility/{Export.d.ts → export.d.ts} +0 -0
  71. package/lib/component/utility/{Export.js → export.js} +27 -44
  72. package/lib/component/utility/formatNumber.d.ts +6 -1
  73. package/lib/component/utility/formatNumber.js +4 -3
  74. package/lib/component/workspaces/Workspace.d.ts +1 -1
  75. package/lib/component/workspaces/exercise.js +4 -4
  76. package/lib/component/workspaces/workspaceDefaultProperties.js +1 -1
  77. package/lib/data/Filters.d.ts +1 -2
  78. package/lib/data/Filters.js +1 -2
  79. package/lib/data/SpectraManager.d.ts +1 -2
  80. package/lib/data/SpectraManager.js +22 -55
  81. package/lib/data/data1d/filter1d/fft.js +21 -4
  82. package/lib/data/data1d/filter1d/phaseCorrection.js +11 -5
  83. package/lib/data/data2d/Processing2D.js +3 -2
  84. package/lib/data/data2d/Spectrum2D/contours.d.ts +40 -0
  85. package/lib/data/data2d/Spectrum2D/contours.js +132 -0
  86. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js +2 -3
  87. package/lib/data/types/common/Source.d.ts +1 -0
  88. package/lib/data/types/data2d/Data2D.d.ts +2 -0
  89. package/lib/data/types/data2d/Datum2D.d.ts +0 -1
  90. package/lib/data/utilities/calculateSanPlot.d.ts +8 -0
  91. package/lib/data/utilities/calculateSanPlot.js +31 -0
  92. package/lib/types/NMRiumGeneralPreferences.d.ts +2 -2
  93. package/lib/versionInfo.js +1 -1
  94. package/lib-cjs/component/1d/Chart1D.js +1 -1
  95. package/lib-cjs/component/1d/FooterBanner.js +16 -9
  96. package/lib-cjs/component/1d/{Integral.js → integral/Integral.js} +2 -2
  97. package/lib-cjs/component/1d/integral/IntegralIndicator.js +31 -0
  98. package/lib-cjs/component/1d/integral/IntegralResizable.js +74 -0
  99. package/lib-cjs/component/1d/{IntegralsSeries.js → integral/IntegralsSeries.js} +3 -3
  100. package/lib-cjs/component/1d/ranges/Range.js +27 -50
  101. package/lib-cjs/component/1d/utilities/scale.js +2 -2
  102. package/lib-cjs/component/2d/Contours.js +60 -41
  103. package/lib-cjs/component/2d/Left1DChart.js +1 -1
  104. package/lib-cjs/component/2d/Top1DChart.js +1 -1
  105. package/lib-cjs/component/EventsTrackers/BrushTracker.js +30 -21
  106. package/lib-cjs/component/NMRium.js +2 -2
  107. package/lib-cjs/component/SplitPaneWrapper.js +1 -1
  108. package/lib-cjs/component/elements/EditableColumn.js +18 -3
  109. package/lib-cjs/component/elements/formik/FormikColorPicker.js +4 -7
  110. package/lib-cjs/component/elements/formik/FormikInput.js +8 -19
  111. package/lib-cjs/component/elements/formik/FormikOnChange.js +13 -10
  112. package/lib-cjs/component/elements/formik/FormikSlider.js +7 -10
  113. package/lib-cjs/component/hooks/useActiveSpectrumStyleOptions.js +1 -1
  114. package/lib-cjs/component/hooks/useExport.js +6 -6
  115. package/lib-cjs/component/loader/DropZone.js +9 -1
  116. package/lib-cjs/component/modal/ExportAsMatrixModal.js +2 -2
  117. package/lib-cjs/component/modal/editRange/forms/components/SignalFormInfo.js +1 -1
  118. package/lib-cjs/component/modal/setting/GeneralTabContent.js +1 -1
  119. package/lib-cjs/component/panels/MoleculesPanel/MoleculeHeader.js +1 -1
  120. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +4 -4
  121. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +2 -2
  122. package/lib-cjs/component/panels/PeaksPanel/PeaksTable.js +1 -1
  123. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +2 -2
  124. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +2 -2
  125. package/lib-cjs/component/panels/RangesPanel/RangesTableRow.js +1 -3
  126. package/lib-cjs/component/panels/SpectrumsPanel/SpectrumsTabs.js +2 -2
  127. package/lib-cjs/component/panels/SpectrumsPanel/base/setting/Spectrum1DSetting.js +2 -1
  128. package/lib-cjs/component/panels/SpectrumsPanel/base/setting/Spectrum2DSetting.js +2 -1
  129. package/lib-cjs/component/panels/SpectrumsPanel/base/setting/processSnapPlot.js +2 -25
  130. package/lib-cjs/component/panels/extra/preferences/ColumnsHelper.js +5 -2
  131. package/lib-cjs/component/reducer/Reducer.js +23 -9
  132. package/lib-cjs/component/reducer/actions/DomainActions.js +3 -2
  133. package/lib-cjs/component/reducer/actions/FiltersActions.js +12 -3
  134. package/lib-cjs/component/reducer/actions/IntegralsActions.js +6 -5
  135. package/lib-cjs/component/reducer/actions/PeaksActions.js +7 -6
  136. package/lib-cjs/component/reducer/actions/PreferencesActions.js +18 -36
  137. package/lib-cjs/component/reducer/actions/RangesActions.js +20 -16
  138. package/lib-cjs/component/reducer/actions/SpectrumsActions.js +12 -5
  139. package/lib-cjs/component/reducer/actions/ToolsActions.js +15 -28
  140. package/lib-cjs/component/reducer/actions/ZonesActions.js +9 -8
  141. package/lib-cjs/component/reducer/core/Constants.js +1 -1
  142. package/lib-cjs/component/reducer/helper/getActiveSpectrum.js +8 -0
  143. package/lib-cjs/component/toolbar/BasicToolBar.js +7 -6
  144. package/lib-cjs/component/utility/FileUtility.js +2 -18
  145. package/lib-cjs/component/utility/{Export.js → export.js} +51 -45
  146. package/lib-cjs/component/utility/formatNumber.js +4 -3
  147. package/lib-cjs/component/workspaces/exercise.js +4 -4
  148. package/lib-cjs/component/workspaces/workspaceDefaultProperties.js +1 -1
  149. package/lib-cjs/data/Filters.js +1 -3
  150. package/lib-cjs/data/SpectraManager.js +23 -57
  151. package/lib-cjs/data/data1d/filter1d/fft.js +20 -3
  152. package/lib-cjs/data/data1d/filter1d/phaseCorrection.js +10 -4
  153. package/lib-cjs/data/data2d/Processing2D.js +3 -2
  154. package/lib-cjs/data/data2d/Spectrum2D/contours.js +138 -0
  155. package/lib-cjs/data/data2d/Spectrum2D/initiateDatum2D.js +2 -3
  156. package/lib-cjs/data/utilities/calculateSanPlot.js +35 -0
  157. package/lib-cjs/versionInfo.js +1 -1
  158. package/package.json +21 -20
  159. package/lib/component/1d/IntegralResizable.js +0 -72
  160. package/lib/component/panels/RangesPanel/TableColumns/format.d.ts +0 -1
  161. package/lib/component/panels/RangesPanel/TableColumns/format.js +0 -8
  162. package/lib/data/data1d/Data1DManager.d.ts +0 -3
  163. package/lib/data/data1d/Data1DManager.js +0 -98
  164. package/lib/data/data1d/filter1d/absolute.d.ts +0 -13
  165. package/lib/data/data1d/filter1d/absolute.js +0 -26
  166. package/lib/data/data2d/Data2DManager.d.ts +0 -3
  167. package/lib/data/data2d/Data2DManager.js +0 -34
  168. package/lib/data/types/data2d/Contour.d.ts +0 -4
  169. package/lib/data/types/data2d/Contour.js +0 -1
  170. package/lib/data/types/data2d/Contours.d.ts +0 -2
  171. package/lib/data/types/data2d/Contours.js +0 -1
  172. package/lib-cjs/component/1d/IntegralResizable.js +0 -77
  173. package/lib-cjs/component/panels/RangesPanel/TableColumns/format.js +0 -14
  174. package/lib-cjs/data/data1d/Data1DManager.js +0 -104
  175. package/lib-cjs/data/data1d/filter1d/absolute.js +0 -32
  176. package/lib-cjs/data/data2d/Data2DManager.js +0 -40
  177. package/lib-cjs/data/types/data2d/Contour.js +0 -2
  178. package/lib-cjs/data/types/data2d/Contours.js +0 -2
@@ -1,63 +1,68 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.getBlob = exports.exportAsMatrix = exports.exportAsMol = exports.copyHTMLToClipboard = exports.copyTextToClipboard = exports.copyPNGToClipboard = exports.exportAsPng = exports.exportAsNMRE = exports.exportAsJSON = exports.exportAsSVG = void 0;
30
+ const clipboard = __importStar(require("clipboard-polyfill"));
7
31
  const file_saver_1 = require("file-saver");
8
32
  const jszip_1 = __importDefault(require("jszip"));
9
- function copyFormattedHtml(html) {
10
- // Create an iframe (isolated container) for the HTML
11
- let container = document.createElement('div');
12
- container.innerHTML = html;
13
- // Hide element
14
- container.style.position = 'fixed';
15
- container.style.pointerEvents = 'none';
16
- container.style.opacity = '0';
17
- // Detect all style sheets of the page
18
- let activeSheets = Array.prototype.slice
19
- .call(document.styleSheets)
20
- .filter((sheet) => {
21
- return !sheet.disabled;
22
- });
23
- // Mount the iframe to the DOM to make `contentWindow` available
24
- document.body.appendChild(container);
25
- // Copy to clipboard
26
- window.getSelection()?.removeAllRanges();
27
- let range = document.createRange();
28
- range.selectNode(container);
29
- window.getSelection()?.addRange(range);
30
- document.execCommand('copy');
31
- for (const active of activeSheets) {
32
- active.disabled = true;
33
- }
34
- document.execCommand('copy');
35
- for (const active of activeSheets) {
36
- active.disabled = false;
37
- }
38
- // Remove the iframe
39
- document.body.removeChild(container);
40
- }
41
33
  async function copyHTMLToClipboard(data) {
42
- try {
43
- copyFormattedHtml(data);
44
- return true;
45
- }
46
- catch (err) {
47
- return false;
48
- }
34
+ return copyToClipboard(data, 'text/html');
49
35
  }
50
36
  exports.copyHTMLToClipboard = copyHTMLToClipboard;
51
37
  async function copyTextToClipboard(data) {
38
+ return copyToClipboard(data, 'text/plain');
39
+ }
40
+ exports.copyTextToClipboard = copyTextToClipboard;
41
+ async function copyToClipboard(data, type) {
52
42
  try {
53
- await navigator.clipboard.writeText(data);
43
+ if (typeof ClipboardItem !== 'undefined') {
44
+ void navigator.clipboard.write([
45
+ new ClipboardItem({
46
+ [type]: new Promise((resolve) => {
47
+ resolve(new Blob([data], { type }));
48
+ }),
49
+ }),
50
+ ]);
51
+ }
52
+ else {
53
+ //TODO when Firefox team implement ClipboardItem this code should be removed
54
+ // this library is used mainly to solve the problem of copy HTML to a clipboard in Firefox but we use it for both HTML and plain text
55
+ const item = new clipboard.ClipboardItem({
56
+ [type]: new Blob([data], { type }),
57
+ });
58
+ await clipboard.write([item]);
59
+ }
54
60
  return true;
55
61
  }
56
62
  catch (err) {
57
63
  return false;
58
64
  }
59
65
  }
60
- exports.copyTextToClipboard = copyTextToClipboard;
61
66
  /**
62
67
  * export the experiments result in JSON format
63
68
  * @param {*} data
@@ -153,7 +158,8 @@ function exportAsPng(rootRef, elementID, fileName = 'experiment') {
153
158
  }
154
159
  }
155
160
  exports.exportAsPng = exportAsPng;
156
- function copyDataURLCliboard(image) {
161
+ // hack way to copy the image to the clipboard
162
+ function copyDataURLClipboardFireFox(image) {
157
163
  const img = document.createElement('img');
158
164
  img.src = image;
159
165
  img.style.position = 'fixed';
@@ -166,7 +172,7 @@ function copyDataURLCliboard(image) {
166
172
  document.execCommand('Copy');
167
173
  document.body.removeChild(img);
168
174
  }
169
- function copyBlobToCliboard(canvas) {
175
+ function copyBlobToClipboard(canvas) {
170
176
  canvas.toBlob((b) => {
171
177
  const clip = new ClipboardItem({
172
178
  [b.type]: b,
@@ -198,10 +204,10 @@ function copyPNGToClipboard(rootRef, elementID) {
198
204
  const png = canvas.toDataURL('image/png', 1);
199
205
  // @ts-expect-error write exists in some browsers
200
206
  if (navigator.clipboard.write) {
201
- copyBlobToCliboard(canvas);
207
+ copyBlobToClipboard(canvas);
202
208
  }
203
209
  else {
204
- copyDataURLCliboard(png);
210
+ copyDataURLClipboardFireFox(png);
205
211
  }
206
212
  URL.revokeObjectURL(png);
207
213
  };
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getNumberOfDecimals = exports.formatNumber = void 0;
7
7
  const numeral_1 = __importDefault(require("numeral"));
8
- function formatNumber(value, format, prefix = '', suffix = '') {
9
- return (value || value === 0) && !isNaN(value)
10
- ? prefix + (0, numeral_1.default)(value).format(format) + suffix
8
+ function formatNumber(value, format, options = {}) {
9
+ const { prefix = '', suffix = '', defaultFormat = '0.00' } = options;
10
+ return typeof value === 'number' || !isNaN(value)
11
+ ? prefix + (0, numeral_1.default)(value).format(format || defaultFormat) + suffix
11
12
  : value;
12
13
  }
13
14
  exports.formatNumber = formatNumber;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.exercise = void 0;
4
4
  exports.exercise = {
5
- version: 1,
5
+ version: 2,
6
6
  label: 'Exercise',
7
7
  display: {
8
8
  general: {
@@ -13,17 +13,17 @@ exports.exercise = {
13
13
  integralsPanel: { display: true },
14
14
  },
15
15
  toolBarButtons: {
16
- peakPicking: true,
16
+ zoom: true,
17
+ zoomOut: true,
17
18
  apodization: true,
18
19
  zeroFilling: true,
19
20
  fastFourierTransform: true,
20
21
  phaseCorrection: true,
21
22
  baselineCorrection: true,
23
+ peakPicking: true,
22
24
  integral: true,
23
25
  spectraCenterAlignments: true,
24
26
  spectraStackAlignments: true,
25
- zoomOut: true,
26
- zoom: true,
27
27
  },
28
28
  },
29
29
  };
@@ -46,7 +46,7 @@ exports.workspaceDefaultProperties = {
46
46
  },
47
47
  },
48
48
  general: {
49
- dimmedSpectraTransparency: 0.1,
49
+ dimmedSpectraOpacity: 0.1,
50
50
  },
51
51
  formatting: {
52
52
  nuclei: {
@@ -23,9 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.shift2DY = exports.shift2DX = exports.exclusionZones = exports.pareto = exports.centerMean = exports.standardDeviation = exports.equallySpaced = exports.fromTo = exports.digitalFilter = exports.zeroFilling = exports.shiftX = exports.autoPhaseCorrection = exports.phaseCorrection = exports.fft = exports.apodization = exports.baselineCorrection = exports.absolute = void 0;
27
- const absolute = __importStar(require("./data1d/filter1d/absolute"));
28
- exports.absolute = absolute;
26
+ exports.shift2DY = exports.shift2DX = exports.exclusionZones = exports.pareto = exports.centerMean = exports.standardDeviation = exports.equallySpaced = exports.fromTo = exports.digitalFilter = exports.zeroFilling = exports.shiftX = exports.autoPhaseCorrection = exports.phaseCorrection = exports.fft = exports.apodization = exports.baselineCorrection = void 0;
29
27
  const apodization = __importStar(require("./data1d/filter1d/apodization"));
30
28
  exports.apodization = apodization;
31
29
  const autoPhaseCorrection = __importStar(require("./data1d/filter1d/autoPhaseCorrection"));
@@ -23,13 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.toJSON = exports.addJcamps = exports.fromJSON = exports.addJcamp = exports.addJcampFromURL = exports.DataExportOptions = void 0;
26
+ exports.toJSON = exports.addJcamps = exports.addJcamp = exports.addJcampFromURL = exports.DataExportOptions = void 0;
27
27
  const nmr_load_save_1 = require("nmr-load-save");
28
- const nmr_parser_1 = require("nmr-parser");
29
28
  const Constants_1 = require("../component/reducer/core/Constants");
30
- const Data1DManager = __importStar(require("./data1d/Data1DManager"));
31
29
  const Datum1D = __importStar(require("./data1d/Spectrum1D"));
32
- const Data2DManager = __importStar(require("./data2d/Data2DManager"));
33
30
  const Datum2D = __importStar(require("./data2d/Spectrum2D"));
34
31
  const Molecule = __importStar(require("./molecules/Molecule"));
35
32
  var DataExportOptions;
@@ -37,6 +34,15 @@ var DataExportOptions;
37
34
  DataExportOptions["ROW_DATA"] = "ROW_DATA";
38
35
  DataExportOptions["DATA_SOURCE"] = "DATA_SOURCE";
39
36
  })(DataExportOptions = exports.DataExportOptions || (exports.DataExportOptions = {}));
37
+ function getData(datum, usedColors) {
38
+ const dimension = datum.info.dimension;
39
+ if (dimension === 1) {
40
+ return Datum1D.initiateDatum1D(datum, usedColors);
41
+ }
42
+ else if (dimension === 2) {
43
+ return Datum2D.initiateDatum2D(datum, usedColors);
44
+ }
45
+ }
40
46
  function addJcampFromURL(spectra, jcampURL, options, usedColors) {
41
47
  return fetch(jcampURL)
42
48
  .then((response) => response.arrayBuffer())
@@ -45,68 +51,28 @@ function addJcampFromURL(spectra, jcampURL, options, usedColors) {
45
51
  });
46
52
  }
47
53
  exports.addJcampFromURL = addJcampFromURL;
48
- function addJcamp(spectra, jcamp, options, usedColors) {
54
+ function addJcamp(output, jcamp, options, usedColors) {
49
55
  options = options || {};
50
- const entries = (0, nmr_parser_1.fromJCAMP)(jcamp, {
51
- noContour: true,
56
+ const name = options?.display?.name;
57
+ const { spectra: spectraIn } = (0, nmr_load_save_1.processJcamp)(jcamp, {
58
+ name,
59
+ noContours: true,
52
60
  xy: true,
53
61
  keepRecordsRegExp: /.*/,
54
62
  profiling: true,
55
63
  });
56
- if (entries.length === 0)
64
+ if (spectraIn.length === 0)
57
65
  return;
58
- // Should be improved when we have a more complex case
59
- for (let index = 0; index < entries.length; index++) {
60
- let entry = entries[index];
61
- const components = entry.dependentVariables?.[0]?.components;
62
- if (components && (components.length > 0 || components.z)) {
63
- addJcampSS(spectra, { index, entry }, options, usedColors);
64
- }
65
- }
66
- }
67
- exports.addJcamp = addJcamp;
68
- function addJcampSS(spectra, jcampDatum, options, usedColors) {
69
- const source = options?.source || {};
70
- if (!('jcampSpectrumIndex' in source) ||
71
- source.jcampSpectrumIndex === jcampDatum.index) {
72
- const dimension = jcampDatum.entry.info.dimension;
73
- if (dimension === 1) {
74
- spectra.push(Data1DManager.fromParsedJcamp(jcampDatum.entry, options, usedColors, jcampDatum.index));
75
- }
76
- if (dimension === 2) {
77
- // console.log(options, jcampDatum.entry);
78
- spectra.push(Data2DManager.fromParsedJcamp(jcampDatum.entry, options, usedColors, jcampDatum.index));
79
- }
80
- }
81
- }
82
- function addData(spectra, datum, usedColors) {
83
- const dimension = datum.info.dimension;
84
- if (dimension === 1) {
85
- spectra.push(Datum1D.initiateDatum1D(datum, usedColors));
86
- }
87
- if (dimension === 2) {
88
- spectra.push(Datum2D.initiateDatum2D(datum, usedColors));
89
- }
90
- }
91
- async function fromJSON(data = [], usedColors = {}) {
92
66
  const spectra = [];
93
- let promises = [];
94
- for (let datum of data) {
95
- const { jcamp, jcampURL } = datum?.source || {};
96
- if (jcamp != null) {
97
- addJcamp(spectra, jcamp, datum, usedColors);
98
- }
99
- else if (jcampURL != null) {
100
- promises.push(addJcampFromURL(spectra, jcampURL, datum, usedColors));
101
- }
102
- else {
103
- addData(spectra, datum, usedColors);
104
- }
67
+ for (let spectrum of spectraIn) {
68
+ const data = getData(spectrum, usedColors);
69
+ if (!data)
70
+ continue;
71
+ spectra.push(data);
105
72
  }
106
- await Promise.all(promises);
107
- return spectra;
73
+ output.push(...spectra);
108
74
  }
109
- exports.fromJSON = fromJSON;
75
+ exports.addJcamp = addJcamp;
110
76
  function addJcamps(files, usedColors) {
111
77
  const spectra = [];
112
78
  for (const file of files) {
@@ -14,19 +14,22 @@ function apply(datum1D) {
14
14
  throw new Error('fft not applicable on this data');
15
15
  }
16
16
  let digitalFilterApplied = datum1D.filters.some((e) => e.name === 'digitalFilter' && e.flag);
17
- const { data } = datum1D;
17
+ const data = datum1D.meta.AQ_mod === 1
18
+ ? removeDCOffset(datum1D, digitalFilterApplied)
19
+ : { ...datum1D.data };
18
20
  if (data.x.length !== data.re.length || data.x.length !== data.im.length) {
19
21
  throw new Error('The length of data should be equal');
20
22
  }
21
23
  else if (!isPowerOfTwo(datum1D.data.x.length)) {
22
24
  (0, padDataToNextPowerOfTwo_1.padDataToNextPowerOfTwo)(datum1D, digitalFilterApplied);
23
25
  }
24
- Object.assign(datum1D.data, (0, ml_spectra_processing_1.reimFFT)(datum1D.data, { applyZeroShift: true }));
26
+ Object.assign(data, (0, ml_spectra_processing_1.reimFFT)(data, { applyZeroShift: true }));
25
27
  if (digitalFilterApplied) {
26
28
  let { digitalFilter = 0 } = datum1D.info;
27
29
  let ph1 = (digitalFilter - Math.floor(digitalFilter)) * Math.PI * 2;
28
- Object.assign(datum1D.data, (0, ml_spectra_processing_1.reimPhaseCorrection)(datum1D.data, 0, ph1));
30
+ Object.assign(data, (0, ml_spectra_processing_1.reimPhaseCorrection)(data, 0, ph1));
29
31
  }
32
+ Object.assign(datum1D.data, data);
30
33
  datum1D.data.x = generateXAxis(datum1D);
31
34
  datum1D.info = { ...datum1D.info, isFid: false, isFt: true };
32
35
  }
@@ -64,3 +67,17 @@ function generateXAxis(datum1D) {
64
67
  function isPowerOfTwo(n) {
65
68
  return n !== 0 && (n & (n - 1)) === 0;
66
69
  }
70
+ function removeDCOffset(datum1D, digitalFilterApplied) {
71
+ let { digitalFilter = 0 } = digitalFilterApplied ? datum1D.info : {};
72
+ const data = { ...datum1D.data };
73
+ const nbPoints = data.re.length;
74
+ const newRe = new Float64Array(data.re);
75
+ const newIm = new Float64Array(data.im);
76
+ const averageRe = (0, ml_spectra_processing_1.xMean)(data.re.slice((nbPoints * 0.75) >> 0, nbPoints - digitalFilter));
77
+ const averageIm = (0, ml_spectra_processing_1.xMean)(data.im.slice((nbPoints * 0.75) >> 0, nbPoints - digitalFilter));
78
+ for (let i = digitalFilterApplied ? 0 : digitalFilter; i < nbPoints - digitalFilter; i++) {
79
+ newRe[i] -= averageRe;
80
+ newIm[i] -= averageIm;
81
+ }
82
+ return { x: data.x, re: newRe, im: newIm };
83
+ }
@@ -15,10 +15,16 @@ function apply(datum1D, options = {}) {
15
15
  if (!isApplicable(datum1D)) {
16
16
  throw new Error('phaseCorrection not applicable on this data');
17
17
  }
18
- let { ph0, ph1 } = options;
19
- ph0 *= Math.PI / 180.0;
20
- ph1 *= Math.PI / 180.0;
21
- Object.assign(datum1D.data, (0, ml_spectra_processing_1.reimPhaseCorrection)(datum1D.data, ph0, ph1));
18
+ let { ph0, ph1, absolute } = options;
19
+ if (absolute) {
20
+ datum1D.data.re = (0, ml_spectra_processing_1.reimAbsolute)(datum1D.data);
21
+ datum1D.data.im = new Float64Array(0);
22
+ }
23
+ else {
24
+ ph0 *= Math.PI / 180.0;
25
+ ph1 *= Math.PI / 180.0;
26
+ Object.assign(datum1D.data, (0, ml_spectra_processing_1.reimPhaseCorrection)(datum1D.data, ph0, ph1));
27
+ }
22
28
  }
23
29
  exports.apply = apply;
24
30
  function isApplicable(datum1D) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultContourOptions = void 0;
4
4
  const ml_conrec_1 = require("ml-conrec");
5
- const ml_spectra_processing_1 = require("ml-spectra-processing");
5
+ const calculateSanPlot_1 = require("../utilities/calculateSanPlot");
6
6
  exports.defaultContourOptions = {
7
7
  positive: {
8
8
  contourLevels: [0, 21],
@@ -25,7 +25,8 @@ class Processing2D {
25
25
  const xs = getRange(minMax.minX, minMax.maxX, minMax.z[0].length);
26
26
  const ys = getRange(minMax.minY, minMax.maxY, minMax.z.length);
27
27
  this.conrec = new ml_conrec_1.Conrec(minMax.z, { xs, ys, swapAxes: false });
28
- this.median = (0, ml_spectra_processing_1.matrixAbsoluteMedian)(minMax.z);
28
+ const sanResult = (0, calculateSanPlot_1.calculateSanPlot)('2D', minMax);
29
+ this.median = sanResult.positive;
29
30
  this.minMax = minMax;
30
31
  }
31
32
  getLevel() {
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CONTOURS_OPTIONS = exports.getDefaultContoursLevel = exports.contoursManager = exports.drawContours = void 0;
4
+ const ml_conrec_1 = require("ml-conrec");
5
+ const calculateSanPlot_1 = require("../../utilities/calculateSanPlot");
6
+ const DEFAULT_CONTOURS_OPTIONS = {
7
+ positive: {
8
+ contourLevels: [0, 21],
9
+ numberOfLayers: 10,
10
+ },
11
+ negative: {
12
+ contourLevels: [0, 21],
13
+ numberOfLayers: 10,
14
+ },
15
+ };
16
+ exports.DEFAULT_CONTOURS_OPTIONS = DEFAULT_CONTOURS_OPTIONS;
17
+ const LEVEL_SIGNS = ['positive', 'negative'];
18
+ function getDefaultContoursLevel(options) {
19
+ const defaultLevel = { negative: 10, positive: 10 };
20
+ for (const sign of LEVEL_SIGNS) {
21
+ const [min, max] = options[sign].contourLevels;
22
+ defaultLevel[sign] = min + max / 2;
23
+ }
24
+ return defaultLevel;
25
+ }
26
+ exports.getDefaultContoursLevel = getDefaultContoursLevel;
27
+ function contoursManager(spectrumID, state, options) {
28
+ const spectraLevels = { ...state };
29
+ const contourOptions = { ...options };
30
+ if (!state || !state[spectrumID]) {
31
+ const defaultLevel = getDefaultContoursLevel(contourOptions);
32
+ spectraLevels[spectrumID] = defaultLevel;
33
+ }
34
+ const currentLevel = spectraLevels[spectrumID];
35
+ const wheel = (value, shiftKey) => prepareWheel(value, { shiftKey, contourOptions, currentLevel });
36
+ const getLevel = () => currentLevel;
37
+ const checkLevel = () => prepareCheckLevel(currentLevel, contourOptions);
38
+ return { wheel, getLevel, checkLevel };
39
+ }
40
+ exports.contoursManager = contoursManager;
41
+ function prepareWheel(value, options) {
42
+ let { shiftKey, currentLevel, contourOptions } = options;
43
+ const sign = Math.sign(value);
44
+ const positiveBoundary = contourOptions.positive.contourLevels;
45
+ const negativeBoundary = contourOptions.negative.contourLevels;
46
+ if (shiftKey) {
47
+ if ((currentLevel.positive === positiveBoundary[0] && sign === -1) ||
48
+ (currentLevel.positive >= positiveBoundary[1] && sign === 1)) {
49
+ return currentLevel;
50
+ }
51
+ currentLevel.positive += sign;
52
+ }
53
+ else {
54
+ if ((currentLevel.positive > positiveBoundary[0] && sign === -1) ||
55
+ (currentLevel.positive < positiveBoundary[1] && sign === 1)) {
56
+ currentLevel.positive += sign;
57
+ }
58
+ if ((currentLevel.negative > negativeBoundary[0] && sign === -1) ||
59
+ (currentLevel.negative < negativeBoundary[1] && sign === 1)) {
60
+ currentLevel.negative += sign;
61
+ }
62
+ }
63
+ return currentLevel;
64
+ }
65
+ function prepareCheckLevel(currentLevel, options) {
66
+ const level = { ...currentLevel };
67
+ for (const sign of LEVEL_SIGNS) {
68
+ const [min, max] = options[sign].contourLevels;
69
+ //check if the level is out of the boundary
70
+ if (level[sign] > max) {
71
+ level[sign] = max;
72
+ }
73
+ else if (level[sign] < min) {
74
+ level[sign] = min;
75
+ }
76
+ }
77
+ return level;
78
+ }
79
+ function getRange(min, max, length, exp) {
80
+ if (exp !== undefined) {
81
+ const factors = [];
82
+ factors[0] = 0;
83
+ for (let i = 1; i <= length; i++) {
84
+ factors[i] = factors[i - 1] + (exp - 1) / Math.pow(exp, i);
85
+ }
86
+ const lastFactor = factors[length];
87
+ const result = new Array(length);
88
+ for (let i = 0; i < length; i++) {
89
+ result[i] = (max - min) * (1 - factors[i + 1] / lastFactor) + min;
90
+ }
91
+ return result;
92
+ }
93
+ else {
94
+ const step = (max - min) / (length - 1);
95
+ return range(min, max + step / 2, step);
96
+ }
97
+ }
98
+ function range(from, to, step) {
99
+ const result = [];
100
+ for (let i = from; i < to; i += step) {
101
+ result.push(i);
102
+ }
103
+ return result;
104
+ }
105
+ function drawContours(level, datum, negative = false) {
106
+ const zoom = level / 2 + 1;
107
+ const { positive: { numberOfLayers: numberOfPositiveLayer }, negative: { numberOfLayers: numberOfNegativeLayer }, } = datum.display.contourOptions;
108
+ if (negative) {
109
+ return getContours(zoom, {
110
+ negative,
111
+ nbLevels: numberOfNegativeLayer,
112
+ data: datum.data,
113
+ });
114
+ }
115
+ return getContours(zoom, {
116
+ nbLevels: numberOfPositiveLayer,
117
+ data: datum.data,
118
+ });
119
+ }
120
+ exports.drawContours = drawContours;
121
+ function getContours(zoomLevel, options) {
122
+ const { negative = false, timeout = 2000, nbLevels, data } = options;
123
+ const xs = getRange(data.minX, data.maxX, data.z[0].length);
124
+ const ys = getRange(data.minY, data.maxY, data.z.length);
125
+ const conrec = new ml_conrec_1.Conrec(data.z, { xs, ys, swapAxes: false });
126
+ const sanResult = (0, calculateSanPlot_1.calculateSanPlot)('2D', data);
127
+ const median = sanResult.positive;
128
+ const max = Math.max(Math.abs(data.maxZ), Math.abs(data.minZ));
129
+ let _range = getRange(median * 1 * Math.pow(2, zoomLevel), max, nbLevels, 2);
130
+ if (negative) {
131
+ _range = _range.map((value) => -value);
132
+ }
133
+ return conrec.drawContour({
134
+ contourDrawer: 'basic',
135
+ levels: _range,
136
+ timeout,
137
+ });
138
+ }
@@ -27,7 +27,7 @@ exports.initiateDatum2D = void 0;
27
27
  const uuid_1 = require("@lukeed/uuid");
28
28
  const FiltersManager = __importStar(require("../../FiltersManager"));
29
29
  const getColor_1 = require("../../utilities/getColor");
30
- const Processing2D_1 = __importStar(require("../Processing2D"));
30
+ const contours_1 = require("./contours");
31
31
  function initiateDatum2D(options, usedColors = {}) {
32
32
  const datum = {};
33
33
  datum.id = options.id || (0, uuid_1.v4)();
@@ -41,7 +41,7 @@ function initiateDatum2D(options, usedColors = {}) {
41
41
  isPositiveVisible: true,
42
42
  isNegativeVisible: true,
43
43
  isVisible: true,
44
- contourOptions: Processing2D_1.defaultContourOptions,
44
+ contourOptions: contours_1.DEFAULT_CONTOURS_OPTIONS,
45
45
  dimension: 2,
46
46
  ...options.display,
47
47
  };
@@ -66,7 +66,6 @@ function initiateDatum2D(options, usedColors = {}) {
66
66
  datum.originalData = datum.data;
67
67
  datum.filters = Object.assign([], options.filters);
68
68
  datum.zones = { values: [], options: {}, ...options.zones };
69
- datum.processingController = new Processing2D_1.default(datum.data, datum.display.contourOptions);
70
69
  //reapply filters after load the original data
71
70
  FiltersManager.reapplyFilters(datum);
72
71
  return datum;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateSanPlot = void 0;
4
+ const ml_spectra_processing_1 = require("ml-spectra-processing");
5
+ function calculateSanPlot(dimension, data) {
6
+ const input = dimension === '1D'
7
+ ? prepare1DData(data)
8
+ : prepare2DData(data);
9
+ return (0, ml_spectra_processing_1.xNoiseSanPlot)(input);
10
+ }
11
+ exports.calculateSanPlot = calculateSanPlot;
12
+ function prepare1DData(data) {
13
+ const length = data.re.length;
14
+ const jump = Math.floor(length / 307200) || 1;
15
+ const array = new Float64Array((length / jump) >> 0);
16
+ let index = 0;
17
+ for (let i = 0; i < array.length; i += jump) {
18
+ array[index++] = data.re[i];
19
+ }
20
+ return array;
21
+ }
22
+ function prepare2DData(data) {
23
+ let cols = data.z[0].length;
24
+ let rows = data.z.length;
25
+ let jump = Math.floor((cols * rows) / 204800) || 1;
26
+ const array = new Float64Array(((cols * rows) / jump) >> 0);
27
+ let index = 0;
28
+ // console.log('jump', jump, cols * rows);
29
+ for (let r = 0; r < rows; r += 1) {
30
+ for (let c = 0; c < cols; c += jump) {
31
+ array[index++] = data.z[r][c];
32
+ }
33
+ }
34
+ return array;
35
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = { version: 'v0.31.0' };
3
+ exports.default = { version: 'v0.33.0' };