nmrium 0.32.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 (116) hide show
  1. package/lib/component/1d/Chart1D.js +1 -1
  2. package/lib/component/1d/{Integral.d.ts → integral/Integral.d.ts} +0 -0
  3. package/lib/component/1d/{Integral.js → integral/Integral.js} +2 -2
  4. package/lib/component/1d/integral/IntegralIndicator.d.ts +9 -0
  5. package/lib/component/1d/integral/IntegralIndicator.js +27 -0
  6. package/lib/component/1d/{IntegralResizable.d.ts → integral/IntegralResizable.d.ts} +0 -0
  7. package/lib/component/1d/integral/IntegralResizable.js +69 -0
  8. package/lib/component/1d/{IntegralsSeries.d.ts → integral/IntegralsSeries.d.ts} +0 -0
  9. package/lib/component/1d/{IntegralsSeries.js → integral/IntegralsSeries.js} +3 -3
  10. package/lib/component/1d/ranges/Range.js +27 -50
  11. package/lib/component/1d/utilities/scale.js +2 -2
  12. package/lib/component/2d/Contours.js +61 -42
  13. package/lib/component/NMRium.d.ts +1 -1
  14. package/lib/component/NMRium.js +1 -1
  15. package/lib/component/elements/formik/FormikColorPicker.d.ts +0 -1
  16. package/lib/component/elements/formik/FormikColorPicker.js +5 -8
  17. package/lib/component/elements/formik/FormikInput.d.ts +0 -1
  18. package/lib/component/elements/formik/FormikInput.js +8 -19
  19. package/lib/component/elements/formik/FormikOnChange.d.ts +1 -1
  20. package/lib/component/elements/formik/FormikOnChange.js +13 -10
  21. package/lib/component/elements/formik/FormikSlider.d.ts +2 -4
  22. package/lib/component/elements/formik/FormikSlider.js +8 -11
  23. package/lib/component/hooks/useExport.js +1 -1
  24. package/lib/component/modal/ExportAsMatrixModal.js +1 -1
  25. package/lib/component/modal/editRange/forms/components/SignalFormInfo.js +1 -1
  26. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +1 -1
  27. package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
  28. package/lib/component/panels/RangesPanel/RangesHeader.js +1 -1
  29. package/lib/component/panels/RangesPanel/RangesPanel.js +1 -1
  30. package/lib/component/panels/RangesPanel/RangesTableRow.js +1 -3
  31. package/lib/component/panels/SpectrumsPanel/SpectrumsTabs.js +1 -1
  32. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum1DSetting.d.ts +1 -1
  33. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum1DSetting.js +2 -1
  34. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum2DSetting.d.ts +1 -1
  35. package/lib/component/panels/SpectrumsPanel/base/setting/Spectrum2DSetting.js +2 -1
  36. package/lib/component/panels/extra/preferences/ColumnsHelper.js +5 -2
  37. package/lib/component/reducer/Reducer.d.ts +18 -12
  38. package/lib/component/reducer/Reducer.js +23 -9
  39. package/lib/component/reducer/actions/PreferencesActions.js +16 -35
  40. package/lib/component/reducer/actions/RangesActions.js +6 -4
  41. package/lib/component/reducer/actions/SpectrumsActions.js +10 -4
  42. package/lib/component/reducer/actions/ToolsActions.js +7 -22
  43. package/lib/component/reducer/core/Constants.js +1 -1
  44. package/lib/component/utility/FileUtility.d.ts +1 -8
  45. package/lib/component/utility/FileUtility.js +2 -17
  46. package/lib/component/utility/{Export.d.ts → export.d.ts} +0 -0
  47. package/lib/component/utility/{Export.js → export.js} +26 -49
  48. package/lib/component/utility/formatNumber.d.ts +6 -1
  49. package/lib/component/utility/formatNumber.js +4 -3
  50. package/lib/data/SpectraManager.d.ts +1 -2
  51. package/lib/data/SpectraManager.js +22 -55
  52. package/lib/data/data1d/filter1d/fft.js +21 -4
  53. package/lib/data/data2d/Spectrum2D/contours.d.ts +40 -0
  54. package/lib/data/data2d/Spectrum2D/contours.js +132 -0
  55. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js +2 -3
  56. package/lib/data/types/common/Source.d.ts +1 -0
  57. package/lib/data/types/data2d/Data2D.d.ts +2 -0
  58. package/lib/data/types/data2d/Datum2D.d.ts +0 -1
  59. package/lib/versionInfo.js +1 -1
  60. package/lib-cjs/component/1d/Chart1D.js +1 -1
  61. package/lib-cjs/component/1d/{Integral.js → integral/Integral.js} +2 -2
  62. package/lib-cjs/component/1d/integral/IntegralIndicator.js +31 -0
  63. package/lib-cjs/component/1d/integral/IntegralResizable.js +74 -0
  64. package/lib-cjs/component/1d/{IntegralsSeries.js → integral/IntegralsSeries.js} +3 -3
  65. package/lib-cjs/component/1d/ranges/Range.js +27 -50
  66. package/lib-cjs/component/1d/utilities/scale.js +2 -2
  67. package/lib-cjs/component/2d/Contours.js +60 -41
  68. package/lib-cjs/component/NMRium.js +2 -2
  69. package/lib-cjs/component/elements/formik/FormikColorPicker.js +4 -7
  70. package/lib-cjs/component/elements/formik/FormikInput.js +8 -19
  71. package/lib-cjs/component/elements/formik/FormikOnChange.js +13 -10
  72. package/lib-cjs/component/elements/formik/FormikSlider.js +7 -10
  73. package/lib-cjs/component/hooks/useExport.js +6 -6
  74. package/lib-cjs/component/modal/ExportAsMatrixModal.js +2 -2
  75. package/lib-cjs/component/modal/editRange/forms/components/SignalFormInfo.js +1 -1
  76. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +4 -4
  77. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +2 -2
  78. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +2 -2
  79. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +2 -2
  80. package/lib-cjs/component/panels/RangesPanel/RangesTableRow.js +1 -3
  81. package/lib-cjs/component/panels/SpectrumsPanel/SpectrumsTabs.js +2 -2
  82. package/lib-cjs/component/panels/SpectrumsPanel/base/setting/Spectrum1DSetting.js +2 -1
  83. package/lib-cjs/component/panels/SpectrumsPanel/base/setting/Spectrum2DSetting.js +2 -1
  84. package/lib-cjs/component/panels/extra/preferences/ColumnsHelper.js +5 -2
  85. package/lib-cjs/component/reducer/Reducer.js +22 -8
  86. package/lib-cjs/component/reducer/actions/PreferencesActions.js +16 -35
  87. package/lib-cjs/component/reducer/actions/RangesActions.js +6 -4
  88. package/lib-cjs/component/reducer/actions/SpectrumsActions.js +9 -3
  89. package/lib-cjs/component/reducer/actions/ToolsActions.js +7 -22
  90. package/lib-cjs/component/reducer/core/Constants.js +1 -1
  91. package/lib-cjs/component/utility/FileUtility.js +2 -18
  92. package/lib-cjs/component/utility/{Export.js → export.js} +50 -50
  93. package/lib-cjs/component/utility/formatNumber.js +4 -3
  94. package/lib-cjs/data/SpectraManager.js +23 -57
  95. package/lib-cjs/data/data1d/filter1d/fft.js +20 -3
  96. package/lib-cjs/data/data2d/Spectrum2D/contours.js +138 -0
  97. package/lib-cjs/data/data2d/Spectrum2D/initiateDatum2D.js +2 -3
  98. package/lib-cjs/versionInfo.js +1 -1
  99. package/package.json +6 -6
  100. package/lib/component/1d/IntegralResizable.js +0 -72
  101. package/lib/component/panels/RangesPanel/TableColumns/format.d.ts +0 -1
  102. package/lib/component/panels/RangesPanel/TableColumns/format.js +0 -8
  103. package/lib/data/data1d/Data1DManager.d.ts +0 -3
  104. package/lib/data/data1d/Data1DManager.js +0 -98
  105. package/lib/data/data2d/Data2DManager.d.ts +0 -3
  106. package/lib/data/data2d/Data2DManager.js +0 -34
  107. package/lib/data/types/data2d/Contour.d.ts +0 -4
  108. package/lib/data/types/data2d/Contour.js +0 -1
  109. package/lib/data/types/data2d/Contours.d.ts +0 -2
  110. package/lib/data/types/data2d/Contours.js +0 -1
  111. package/lib-cjs/component/1d/IntegralResizable.js +0 -77
  112. package/lib-cjs/component/panels/RangesPanel/TableColumns/format.js +0 -14
  113. package/lib-cjs/data/data1d/Data1DManager.js +0 -104
  114. package/lib-cjs/data/data2d/Data2DManager.js +0 -40
  115. package/lib-cjs/data/types/data2d/Contour.js +0 -2
  116. package/lib-cjs/data/types/data2d/Contours.js +0 -2
@@ -1,55 +1,31 @@
1
+ import * as clipboard from 'clipboard-polyfill';
1
2
  import { saveAs } from 'file-saver';
2
3
  import JSZip from 'jszip';
3
- function copyFormattedHtml(html) {
4
- // Create an iframe (isolated container) for the HTML
5
- let container = document.createElement('div');
6
- container.innerHTML = html;
7
- // Hide element
8
- container.style.position = 'fixed';
9
- container.style.pointerEvents = 'none';
10
- container.style.opacity = '0';
11
- // Detect all style sheets of the page
12
- let activeSheets = Array.prototype.slice
13
- .call(document.styleSheets)
14
- .filter((sheet) => {
15
- return !sheet.disabled;
16
- });
17
- // Mount the iframe to the DOM to make `contentWindow` available
18
- document.body.appendChild(container);
19
- // Copy to clipboard
20
- window.getSelection()?.removeAllRanges();
21
- let range = document.createRange();
22
- range.selectNode(container);
23
- window.getSelection()?.addRange(range);
24
- document.execCommand('copy');
25
- for (const active of activeSheets) {
26
- active.disabled = true;
27
- }
28
- document.execCommand('copy');
29
- for (const active of activeSheets) {
30
- active.disabled = false;
31
- }
32
- // Remove the iframe
33
- document.body.removeChild(container);
34
- }
35
4
  async function copyHTMLToClipboard(data) {
36
- try {
37
- copyFormattedHtml(data);
38
- return true;
39
- }
40
- catch (err) {
41
- return false;
42
- }
5
+ return copyToClipboard(data, 'text/html');
43
6
  }
44
7
  async function copyTextToClipboard(data) {
8
+ return copyToClipboard(data, 'text/plain');
9
+ }
10
+ async function copyToClipboard(data, type) {
45
11
  try {
46
- void navigator.clipboard.write([
47
- new ClipboardItem({
48
- 'text/plain': new Promise((resolve) => {
49
- resolve(new Blob([data], { type: 'text/plain' }));
12
+ if (typeof ClipboardItem !== 'undefined') {
13
+ void navigator.clipboard.write([
14
+ new ClipboardItem({
15
+ [type]: new Promise((resolve) => {
16
+ resolve(new Blob([data], { type }));
17
+ }),
50
18
  }),
51
- }),
52
- ]);
19
+ ]);
20
+ }
21
+ else {
22
+ //TODO when Firefox team implement ClipboardItem this code should be removed
23
+ // 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
24
+ const item = new clipboard.ClipboardItem({
25
+ [type]: new Blob([data], { type }),
26
+ });
27
+ await clipboard.write([item]);
28
+ }
53
29
  return true;
54
30
  }
55
31
  catch (err) {
@@ -145,7 +121,8 @@ function exportAsPng(rootRef, elementID, fileName = 'experiment') {
145
121
  console.log(e);
146
122
  }
147
123
  }
148
- function copyDataURLCliboard(image) {
124
+ // hack way to copy the image to the clipboard
125
+ function copyDataURLClipboardFireFox(image) {
149
126
  const img = document.createElement('img');
150
127
  img.src = image;
151
128
  img.style.position = 'fixed';
@@ -158,7 +135,7 @@ function copyDataURLCliboard(image) {
158
135
  document.execCommand('Copy');
159
136
  document.body.removeChild(img);
160
137
  }
161
- function copyBlobToCliboard(canvas) {
138
+ function copyBlobToClipboard(canvas) {
162
139
  canvas.toBlob((b) => {
163
140
  const clip = new ClipboardItem({
164
141
  [b.type]: b,
@@ -190,10 +167,10 @@ function copyPNGToClipboard(rootRef, elementID) {
190
167
  const png = canvas.toDataURL('image/png', 1);
191
168
  // @ts-expect-error write exists in some browsers
192
169
  if (navigator.clipboard.write) {
193
- copyBlobToCliboard(canvas);
170
+ copyBlobToClipboard(canvas);
194
171
  }
195
172
  else {
196
- copyDataURLCliboard(png);
173
+ copyDataURLClipboardFireFox(png);
197
174
  }
198
175
  URL.revokeObjectURL(png);
199
176
  };
@@ -1,3 +1,8 @@
1
- declare function formatNumber(value: any, format: any, prefix?: string, suffix?: string): any;
1
+ interface FormatOptions {
2
+ prefix?: string;
3
+ suffix?: string;
4
+ defaultFormat?: string;
5
+ }
6
+ declare function formatNumber(value: string | number, format: string | undefined, options?: FormatOptions): string;
2
7
  declare function getNumberOfDecimals(value: number | string): number;
3
8
  export { formatNumber, getNumberOfDecimals };
@@ -1,7 +1,8 @@
1
1
  import numeral from 'numeral';
2
- function formatNumber(value, format, prefix = '', suffix = '') {
3
- return (value || value === 0) && !isNaN(value)
4
- ? prefix + numeral(value).format(format) + suffix
2
+ function formatNumber(value, format, options = {}) {
3
+ const { prefix = '', suffix = '', defaultFormat = '0.00' } = options;
4
+ return typeof value === 'number' || !isNaN(value)
5
+ ? prefix + numeral(value).format(format || defaultFormat) + suffix
5
6
  : value;
6
7
  }
7
8
  function getNumberOfDecimals(value) {
@@ -6,8 +6,7 @@ export declare enum DataExportOptions {
6
6
  }
7
7
  export declare type DataExportOptionsType = keyof typeof DataExportOptions;
8
8
  export declare function addJcampFromURL(spectra: any, jcampURL: any, options: any, usedColors: any): Promise<void>;
9
- export declare function addJcamp(spectra: any, jcamp: any, options: any, usedColors: any): void;
10
- export declare function fromJSON(data?: any[], usedColors?: any): Promise<any[]>;
9
+ export declare function addJcamp(output: any, jcamp: any, options: any, usedColors: any): void;
11
10
  export declare function addJcamps(files: any, usedColors: any): never[];
12
11
  /**
13
12
  *
@@ -1,9 +1,6 @@
1
- import { CURRENT_EXPORT_VERSION } from 'nmr-load-save';
2
- import { fromJCAMP } from 'nmr-parser';
1
+ import { CURRENT_EXPORT_VERSION, processJcamp } from 'nmr-load-save';
3
2
  import { DISPLAYER_MODE } from '../component/reducer/core/Constants';
4
- import * as Data1DManager from './data1d/Data1DManager';
5
3
  import * as Datum1D from './data1d/Spectrum1D';
6
- import * as Data2DManager from './data2d/Data2DManager';
7
4
  import * as Datum2D from './data2d/Spectrum2D';
8
5
  import * as Molecule from './molecules/Molecule';
9
6
  export var DataExportOptions;
@@ -11,6 +8,15 @@ export var DataExportOptions;
11
8
  DataExportOptions["ROW_DATA"] = "ROW_DATA";
12
9
  DataExportOptions["DATA_SOURCE"] = "DATA_SOURCE";
13
10
  })(DataExportOptions || (DataExportOptions = {}));
11
+ function getData(datum, usedColors) {
12
+ const dimension = datum.info.dimension;
13
+ if (dimension === 1) {
14
+ return Datum1D.initiateDatum1D(datum, usedColors);
15
+ }
16
+ else if (dimension === 2) {
17
+ return Datum2D.initiateDatum2D(datum, usedColors);
18
+ }
19
+ }
14
20
  export function addJcampFromURL(spectra, jcampURL, options, usedColors) {
15
21
  return fetch(jcampURL)
16
22
  .then((response) => response.arrayBuffer())
@@ -18,65 +24,26 @@ export function addJcampFromURL(spectra, jcampURL, options, usedColors) {
18
24
  addJcamp(spectra, jcamp, options, usedColors);
19
25
  });
20
26
  }
21
- export function addJcamp(spectra, jcamp, options, usedColors) {
27
+ export function addJcamp(output, jcamp, options, usedColors) {
22
28
  options = options || {};
23
- const entries = fromJCAMP(jcamp, {
24
- noContour: true,
29
+ const name = options?.display?.name;
30
+ const { spectra: spectraIn } = processJcamp(jcamp, {
31
+ name,
32
+ noContours: true,
25
33
  xy: true,
26
34
  keepRecordsRegExp: /.*/,
27
35
  profiling: true,
28
36
  });
29
- if (entries.length === 0)
37
+ if (spectraIn.length === 0)
30
38
  return;
31
- // Should be improved when we have a more complex case
32
- for (let index = 0; index < entries.length; index++) {
33
- let entry = entries[index];
34
- const components = entry.dependentVariables?.[0]?.components;
35
- if (components && (components.length > 0 || components.z)) {
36
- addJcampSS(spectra, { index, entry }, options, usedColors);
37
- }
38
- }
39
- }
40
- function addJcampSS(spectra, jcampDatum, options, usedColors) {
41
- const source = options?.source || {};
42
- if (!('jcampSpectrumIndex' in source) ||
43
- source.jcampSpectrumIndex === jcampDatum.index) {
44
- const dimension = jcampDatum.entry.info.dimension;
45
- if (dimension === 1) {
46
- spectra.push(Data1DManager.fromParsedJcamp(jcampDatum.entry, options, usedColors, jcampDatum.index));
47
- }
48
- if (dimension === 2) {
49
- // console.log(options, jcampDatum.entry);
50
- spectra.push(Data2DManager.fromParsedJcamp(jcampDatum.entry, options, usedColors, jcampDatum.index));
51
- }
52
- }
53
- }
54
- function addData(spectra, datum, usedColors) {
55
- const dimension = datum.info.dimension;
56
- if (dimension === 1) {
57
- spectra.push(Datum1D.initiateDatum1D(datum, usedColors));
58
- }
59
- if (dimension === 2) {
60
- spectra.push(Datum2D.initiateDatum2D(datum, usedColors));
61
- }
62
- }
63
- export async function fromJSON(data = [], usedColors = {}) {
64
39
  const spectra = [];
65
- let promises = [];
66
- for (let datum of data) {
67
- const { jcamp, jcampURL } = datum?.source || {};
68
- if (jcamp != null) {
69
- addJcamp(spectra, jcamp, datum, usedColors);
70
- }
71
- else if (jcampURL != null) {
72
- promises.push(addJcampFromURL(spectra, jcampURL, datum, usedColors));
73
- }
74
- else {
75
- addData(spectra, datum, usedColors);
76
- }
40
+ for (let spectrum of spectraIn) {
41
+ const data = getData(spectrum, usedColors);
42
+ if (!data)
43
+ continue;
44
+ spectra.push(data);
77
45
  }
78
- await Promise.all(promises);
79
- return spectra;
46
+ output.push(...spectra);
80
47
  }
81
48
  export function addJcamps(files, usedColors) {
82
49
  const spectra = [];
@@ -1,4 +1,4 @@
1
- import { reimFFT, reimPhaseCorrection } from 'ml-spectra-processing';
1
+ import { reimFFT, reimPhaseCorrection, xMean } from 'ml-spectra-processing';
2
2
  import { padDataToNextPowerOfTwo } from './utils/padDataToNextPowerOfTwo';
3
3
  export const id = 'fft';
4
4
  export const name = 'FFT';
@@ -11,19 +11,22 @@ export function apply(datum1D) {
11
11
  throw new Error('fft not applicable on this data');
12
12
  }
13
13
  let digitalFilterApplied = datum1D.filters.some((e) => e.name === 'digitalFilter' && e.flag);
14
- const { data } = datum1D;
14
+ const data = datum1D.meta.AQ_mod === 1
15
+ ? removeDCOffset(datum1D, digitalFilterApplied)
16
+ : { ...datum1D.data };
15
17
  if (data.x.length !== data.re.length || data.x.length !== data.im.length) {
16
18
  throw new Error('The length of data should be equal');
17
19
  }
18
20
  else if (!isPowerOfTwo(datum1D.data.x.length)) {
19
21
  padDataToNextPowerOfTwo(datum1D, digitalFilterApplied);
20
22
  }
21
- Object.assign(datum1D.data, reimFFT(datum1D.data, { applyZeroShift: true }));
23
+ Object.assign(data, reimFFT(data, { applyZeroShift: true }));
22
24
  if (digitalFilterApplied) {
23
25
  let { digitalFilter = 0 } = datum1D.info;
24
26
  let ph1 = (digitalFilter - Math.floor(digitalFilter)) * Math.PI * 2;
25
- Object.assign(datum1D.data, reimPhaseCorrection(datum1D.data, 0, ph1));
27
+ Object.assign(data, reimPhaseCorrection(data, 0, ph1));
26
28
  }
29
+ Object.assign(datum1D.data, data);
27
30
  datum1D.data.x = generateXAxis(datum1D);
28
31
  datum1D.info = { ...datum1D.info, isFid: false, isFt: true };
29
32
  }
@@ -58,3 +61,17 @@ function generateXAxis(datum1D) {
58
61
  function isPowerOfTwo(n) {
59
62
  return n !== 0 && (n & (n - 1)) === 0;
60
63
  }
64
+ function removeDCOffset(datum1D, digitalFilterApplied) {
65
+ let { digitalFilter = 0 } = digitalFilterApplied ? datum1D.info : {};
66
+ const data = { ...datum1D.data };
67
+ const nbPoints = data.re.length;
68
+ const newRe = new Float64Array(data.re);
69
+ const newIm = new Float64Array(data.im);
70
+ const averageRe = xMean(data.re.slice((nbPoints * 0.75) >> 0, nbPoints - digitalFilter));
71
+ const averageIm = xMean(data.im.slice((nbPoints * 0.75) >> 0, nbPoints - digitalFilter));
72
+ for (let i = digitalFilterApplied ? 0 : digitalFilter; i < nbPoints - digitalFilter; i++) {
73
+ newRe[i] -= averageRe;
74
+ newIm[i] -= averageIm;
75
+ }
76
+ return { x: data.x, re: newRe, im: newIm };
77
+ }
@@ -0,0 +1,40 @@
1
+ import { Datum2D } from '../../types/data2d';
2
+ interface Level {
3
+ positive: number;
4
+ negative: number;
5
+ }
6
+ interface ContourItem {
7
+ contourLevels: [number, number];
8
+ numberOfLayers: number;
9
+ }
10
+ interface ContourOptions {
11
+ positive: ContourItem;
12
+ negative: ContourItem;
13
+ }
14
+ interface ContoursLevels {
15
+ [key: string]: Level;
16
+ }
17
+ declare const DEFAULT_CONTOURS_OPTIONS: {
18
+ positive: {
19
+ contourLevels: number[];
20
+ numberOfLayers: number;
21
+ };
22
+ negative: {
23
+ contourLevels: number[];
24
+ numberOfLayers: number;
25
+ };
26
+ };
27
+ declare type LevelSign = keyof Level;
28
+ interface ReturnContoursManager {
29
+ wheel: (value: number, shift: boolean) => Level;
30
+ getLevel: () => Level;
31
+ checkLevel: () => Level;
32
+ }
33
+ declare function getDefaultContoursLevel(options: ContourOptions): Level;
34
+ declare function contoursManager(spectrumID: string, state: ContoursLevels, options: ContourOptions): ReturnContoursManager;
35
+ declare function drawContours(level: number, datum: Datum2D, negative?: boolean): {
36
+ contours: any;
37
+ timeout: boolean;
38
+ };
39
+ export { drawContours, contoursManager, getDefaultContoursLevel, DEFAULT_CONTOURS_OPTIONS, };
40
+ export type { ContoursLevels, ReturnContoursManager, Level, LevelSign };
@@ -0,0 +1,132 @@
1
+ import { Conrec } from 'ml-conrec';
2
+ import { calculateSanPlot } from '../../utilities/calculateSanPlot';
3
+ const DEFAULT_CONTOURS_OPTIONS = {
4
+ positive: {
5
+ contourLevels: [0, 21],
6
+ numberOfLayers: 10,
7
+ },
8
+ negative: {
9
+ contourLevels: [0, 21],
10
+ numberOfLayers: 10,
11
+ },
12
+ };
13
+ const LEVEL_SIGNS = ['positive', 'negative'];
14
+ function getDefaultContoursLevel(options) {
15
+ const defaultLevel = { negative: 10, positive: 10 };
16
+ for (const sign of LEVEL_SIGNS) {
17
+ const [min, max] = options[sign].contourLevels;
18
+ defaultLevel[sign] = min + max / 2;
19
+ }
20
+ return defaultLevel;
21
+ }
22
+ function contoursManager(spectrumID, state, options) {
23
+ const spectraLevels = { ...state };
24
+ const contourOptions = { ...options };
25
+ if (!state || !state[spectrumID]) {
26
+ const defaultLevel = getDefaultContoursLevel(contourOptions);
27
+ spectraLevels[spectrumID] = defaultLevel;
28
+ }
29
+ const currentLevel = spectraLevels[spectrumID];
30
+ const wheel = (value, shiftKey) => prepareWheel(value, { shiftKey, contourOptions, currentLevel });
31
+ const getLevel = () => currentLevel;
32
+ const checkLevel = () => prepareCheckLevel(currentLevel, contourOptions);
33
+ return { wheel, getLevel, checkLevel };
34
+ }
35
+ function prepareWheel(value, options) {
36
+ let { shiftKey, currentLevel, contourOptions } = options;
37
+ const sign = Math.sign(value);
38
+ const positiveBoundary = contourOptions.positive.contourLevels;
39
+ const negativeBoundary = contourOptions.negative.contourLevels;
40
+ if (shiftKey) {
41
+ if ((currentLevel.positive === positiveBoundary[0] && sign === -1) ||
42
+ (currentLevel.positive >= positiveBoundary[1] && sign === 1)) {
43
+ return currentLevel;
44
+ }
45
+ currentLevel.positive += sign;
46
+ }
47
+ else {
48
+ if ((currentLevel.positive > positiveBoundary[0] && sign === -1) ||
49
+ (currentLevel.positive < positiveBoundary[1] && sign === 1)) {
50
+ currentLevel.positive += sign;
51
+ }
52
+ if ((currentLevel.negative > negativeBoundary[0] && sign === -1) ||
53
+ (currentLevel.negative < negativeBoundary[1] && sign === 1)) {
54
+ currentLevel.negative += sign;
55
+ }
56
+ }
57
+ return currentLevel;
58
+ }
59
+ function prepareCheckLevel(currentLevel, options) {
60
+ const level = { ...currentLevel };
61
+ for (const sign of LEVEL_SIGNS) {
62
+ const [min, max] = options[sign].contourLevels;
63
+ //check if the level is out of the boundary
64
+ if (level[sign] > max) {
65
+ level[sign] = max;
66
+ }
67
+ else if (level[sign] < min) {
68
+ level[sign] = min;
69
+ }
70
+ }
71
+ return level;
72
+ }
73
+ function getRange(min, max, length, exp) {
74
+ if (exp !== undefined) {
75
+ const factors = [];
76
+ factors[0] = 0;
77
+ for (let i = 1; i <= length; i++) {
78
+ factors[i] = factors[i - 1] + (exp - 1) / Math.pow(exp, i);
79
+ }
80
+ const lastFactor = factors[length];
81
+ const result = new Array(length);
82
+ for (let i = 0; i < length; i++) {
83
+ result[i] = (max - min) * (1 - factors[i + 1] / lastFactor) + min;
84
+ }
85
+ return result;
86
+ }
87
+ else {
88
+ const step = (max - min) / (length - 1);
89
+ return range(min, max + step / 2, step);
90
+ }
91
+ }
92
+ function range(from, to, step) {
93
+ const result = [];
94
+ for (let i = from; i < to; i += step) {
95
+ result.push(i);
96
+ }
97
+ return result;
98
+ }
99
+ function drawContours(level, datum, negative = false) {
100
+ const zoom = level / 2 + 1;
101
+ const { positive: { numberOfLayers: numberOfPositiveLayer }, negative: { numberOfLayers: numberOfNegativeLayer }, } = datum.display.contourOptions;
102
+ if (negative) {
103
+ return getContours(zoom, {
104
+ negative,
105
+ nbLevels: numberOfNegativeLayer,
106
+ data: datum.data,
107
+ });
108
+ }
109
+ return getContours(zoom, {
110
+ nbLevels: numberOfPositiveLayer,
111
+ data: datum.data,
112
+ });
113
+ }
114
+ function getContours(zoomLevel, options) {
115
+ const { negative = false, timeout = 2000, nbLevels, data } = options;
116
+ const xs = getRange(data.minX, data.maxX, data.z[0].length);
117
+ const ys = getRange(data.minY, data.maxY, data.z.length);
118
+ const conrec = new Conrec(data.z, { xs, ys, swapAxes: false });
119
+ const sanResult = calculateSanPlot('2D', data);
120
+ const median = sanResult.positive;
121
+ const max = Math.max(Math.abs(data.maxZ), Math.abs(data.minZ));
122
+ let _range = getRange(median * 1 * Math.pow(2, zoomLevel), max, nbLevels, 2);
123
+ if (negative) {
124
+ _range = _range.map((value) => -value);
125
+ }
126
+ return conrec.drawContour({
127
+ contourDrawer: 'basic',
128
+ levels: _range,
129
+ timeout,
130
+ });
131
+ }
132
+ export { drawContours, contoursManager, getDefaultContoursLevel, DEFAULT_CONTOURS_OPTIONS, };
@@ -1,7 +1,7 @@
1
1
  import { v4 } from '@lukeed/uuid';
2
2
  import * as FiltersManager from '../../FiltersManager';
3
3
  import { get2DColor } from '../../utilities/getColor';
4
- import Processing2D, { defaultContourOptions } from '../Processing2D';
4
+ import { DEFAULT_CONTOURS_OPTIONS } from './contours';
5
5
  export function initiateDatum2D(options, usedColors = {}) {
6
6
  const datum = {};
7
7
  datum.id = options.id || v4();
@@ -15,7 +15,7 @@ export function initiateDatum2D(options, usedColors = {}) {
15
15
  isPositiveVisible: true,
16
16
  isNegativeVisible: true,
17
17
  isVisible: true,
18
- contourOptions: defaultContourOptions,
18
+ contourOptions: DEFAULT_CONTOURS_OPTIONS,
19
19
  dimension: 2,
20
20
  ...options.display,
21
21
  };
@@ -40,7 +40,6 @@ export function initiateDatum2D(options, usedColors = {}) {
40
40
  datum.originalData = datum.data;
41
41
  datum.filters = Object.assign([], options.filters);
42
42
  datum.zones = { values: [], options: {}, ...options.zones };
43
- datum.processingController = new Processing2D(datum.data, datum.display.contourOptions);
44
43
  //reapply filters after load the original data
45
44
  FiltersManager.reapplyFilters(datum);
46
45
  return datum;
@@ -1,4 +1,5 @@
1
1
  export interface Source {
2
+ jcamp: string;
2
3
  jcampURL: string;
3
4
  jcampSpectrumIndex: number;
4
5
  file: File;
@@ -2,6 +2,8 @@ export interface Data2D {
2
2
  z: Array<Array<number>>;
3
3
  minX: number;
4
4
  minY: number;
5
+ minZ: number;
5
6
  maxX: number;
6
7
  maxY: number;
8
+ maxZ: number;
7
9
  }
@@ -15,5 +15,4 @@ export interface Datum2D {
15
15
  originalData?: Data2D;
16
16
  zones: Zones;
17
17
  filters: Array<Filter>;
18
- processingController: any;
19
18
  }
@@ -1 +1 @@
1
- export default { version: 'v0.32.0' };
1
+ export default { version: 'v0.33.0' };
@@ -7,10 +7,10 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const FloatMoleculeStructures_1 = __importDefault(require("../tool/FloatMoleculeStructures"));
8
8
  const ApodizationLine_1 = __importDefault(require("./ApodizationLine"));
9
9
  const ExclusionZonesAnnotations_1 = __importDefault(require("./ExclusionZonesAnnotations"));
10
- const IntegralsSeries_1 = __importDefault(require("./IntegralsSeries"));
11
10
  const LinesSeries_1 = __importDefault(require("./LinesSeries"));
12
11
  const XAxis_1 = __importDefault(require("./XAxis"));
13
12
  const DatabaseElements_1 = __importDefault(require("./database/DatabaseElements"));
13
+ const IntegralsSeries_1 = __importDefault(require("./integral/IntegralsSeries"));
14
14
  const JGraph_1 = __importDefault(require("./jCouplingGraph/JGraph"));
15
15
  const MultiAnalysisRanges_1 = __importDefault(require("./multiAnalysis/MultiAnalysisRanges"));
16
16
  const PeakAnnotations_1 = __importDefault(require("./peaks/PeakAnnotations"));
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
- const useIntegralPath_1 = __importDefault(require("../hooks/useIntegralPath"));
8
- const usePanelPreferences_1 = require("../hooks/usePanelPreferences");
7
+ const useIntegralPath_1 = __importDefault(require("../../hooks/useIntegralPath"));
8
+ const usePanelPreferences_1 = require("../../hooks/usePanelPreferences");
9
9
  const IntegralResizable_1 = __importDefault(require("./IntegralResizable"));
10
10
  function Integral({ integral, isActive, nucleus }) {
11
11
  const path = (0, useIntegralPath_1.default)(integral);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegralIndicator = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const ChartContext_1 = require("../../context/ChartContext");
6
+ const formatNumber_1 = require("../../utility/formatNumber");
7
+ const styles = {
8
+ text: {
9
+ fontSize: '11px',
10
+ textAnchor: 'middle',
11
+ dominantBaseline: 'middle',
12
+ writingMode: 'vertical-rl',
13
+ fill: 'black',
14
+ },
15
+ path: {
16
+ fill: 'none',
17
+ strokeWidth: '1px',
18
+ shapeRendering: 'crispEdges',
19
+ stroke: 'black',
20
+ },
21
+ };
22
+ function IntegralIndicator(props) {
23
+ const { value, width, format, opacity = 1 } = props;
24
+ const { height, margin } = (0, ChartContext_1.useChartData)();
25
+ const bottom = height - margin.bottom;
26
+ return ((0, jsx_runtime_1.jsxs)("g", { style: { transform: `translate(0,${bottom - 10}px) `, opacity }, children: [(0, jsx_runtime_1.jsx)("text", { style: {
27
+ ...styles.text,
28
+ transform: `translate(${width / 2}px,-12px) scale(-1)`,
29
+ }, children: value ? (0, formatNumber_1.formatNumber)(value, format) : '' }), (0, jsx_runtime_1.jsx)("path", { style: styles.path, d: `M0 0 L0 5 L${width} 5 L${width} 0 ` })] }));
30
+ }
31
+ exports.IntegralIndicator = IntegralIndicator;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
7
+ /** @jsxImportSource @emotion/react */
8
+ const react_1 = require("@emotion/react");
9
+ const ChartContext_1 = require("../../context/ChartContext");
10
+ const DispatchContext_1 = require("../../context/DispatchContext");
11
+ const GlobalContext_1 = require("../../context/GlobalContext");
12
+ const ScaleContext_1 = require("../../context/ScaleContext");
13
+ const Resizer_1 = __importDefault(require("../../elements/resizer/Resizer"));
14
+ const index_1 = require("../../highlight/index");
15
+ const Types_1 = require("../../reducer/types/Types");
16
+ const ToolTypes_1 = require("../../toolbar/ToolTypes");
17
+ const IntegralIndicator_1 = require("./IntegralIndicator");
18
+ const stylesOnHover = (0, react_1.css) `
19
+ pointer-events: bounding-box;
20
+ @-moz-document url-prefix() {
21
+ pointer-events: fill;
22
+ }
23
+ .highlight {
24
+ fill: transparent;
25
+ }
26
+ .target {
27
+ visibility: hidden;
28
+ }
29
+ `;
30
+ const stylesHighlighted = (0, react_1.css) `
31
+ pointer-events: bounding-box;
32
+
33
+ @-moz-document url-prefix() {
34
+ pointer-events: fill;
35
+ }
36
+ fill: #ff6f0057;
37
+
38
+ .target {
39
+ visibility: visible;
40
+ }
41
+ `;
42
+ function IntegralResizable({ integralData, integralFormat, }) {
43
+ const { height, margin, toolOptions: { selectedTool }, } = (0, ChartContext_1.useChartData)();
44
+ const { viewerRef } = (0, GlobalContext_1.useGlobal)();
45
+ const { scaleX } = (0, ScaleContext_1.useScaleChecked)();
46
+ const dispatch = (0, DispatchContext_1.useDispatch)();
47
+ const { id, integral } = integralData;
48
+ const highlight = (0, index_1.useHighlight)([id], {
49
+ type: index_1.HighlightEventSource.INTEGRAL,
50
+ extra: { id },
51
+ });
52
+ function handleOnStopResizing(position) {
53
+ dispatch({
54
+ type: Types_1.RESIZE_INTEGRAL,
55
+ payload: {
56
+ data: {
57
+ ...integralData,
58
+ from: scaleX().invert(position.x2),
59
+ to: scaleX().invert(position.x1),
60
+ },
61
+ },
62
+ });
63
+ }
64
+ const from = integralData.from ? scaleX()(integralData.from) : 0;
65
+ const to = integralData.to ? scaleX()(integralData.to) : 0;
66
+ const bottom = height - margin.bottom;
67
+ return ((0, jsx_runtime_1.jsx)("g", { onMouseEnter: () => highlight.show(), onMouseLeave: () => highlight.hide(), children: (0, jsx_runtime_1.jsx)(Resizer_1.default, { tag: "svg", initialPosition: { x1: to, x2: from }, onEnd: handleOnStopResizing, parentElement: viewerRef, disabled: selectedTool !== ToolTypes_1.options.integral.id, children: ({ x1, x2 }, isActive) => {
68
+ const width = x2 - x1;
69
+ return ((0, jsx_runtime_1.jsxs)("g", { css: highlight.isActive || isActive
70
+ ? stylesHighlighted
71
+ : stylesOnHover, children: [(0, jsx_runtime_1.jsx)("rect", { width: width, height: bottom, className: "highlight", "data-no-export": "true" }), (0, jsx_runtime_1.jsx)(IntegralIndicator_1.IntegralIndicator, { value: integral, format: integralFormat, width: width })] }));
72
+ } }, `${id}_${to}_${from}`) }));
73
+ }
74
+ exports.default = IntegralResizable;