nmrium 0.51.0 → 0.53.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 (119) hide show
  1. package/lib/component/1d/LinesSeries.js +1 -1
  2. package/lib/component/1d/ranges/AssignmentLabel.d.ts +7 -0
  3. package/lib/component/1d/ranges/AssignmentLabel.js +10 -0
  4. package/lib/component/1d/ranges/Range.js +2 -1
  5. package/lib/component/EventsTrackers/KeysListenerTracker.js +3 -3
  6. package/lib/component/context/DispatchContext.d.ts +1 -1
  7. package/lib/component/elements/EditableColumn.js +3 -3
  8. package/lib/component/elements/Label.js +1 -1
  9. package/lib/component/header/ApodizationOptionsPanel.js +1 -1
  10. package/lib/component/header/AutoPeakPickingOptionPanel.js +1 -1
  11. package/lib/component/header/BaseLineCorrectionPanel.js +2 -2
  12. package/lib/component/header/Header.js +1 -1
  13. package/lib/component/header/PhaseCorrectionPanel.js +1 -1
  14. package/lib/component/header/PhaseCorrectionTwoDimensionsPanel.js +2 -2
  15. package/lib/component/header/RangesPickingOptionPanel.js +1 -1
  16. package/lib/component/header/ZeroFillingOptionsPanel.js +1 -1
  17. package/lib/component/header/Zones2DOptionPanel.js +6 -2
  18. package/lib/component/hooks/useActiveSpectrumRangesViewState.js +1 -0
  19. package/lib/component/hooks/useActiveSpectrumZonesViewState.js +1 -0
  20. package/lib/component/hooks/useToolsFunctions.d.ts +1 -1
  21. package/lib/component/hooks/useToolsFunctions.js +10 -4
  22. package/lib/component/main/NMRiumStateProvider.js +1 -1
  23. package/lib/component/modal/AboutPredictionModal.js +1 -1
  24. package/lib/component/modal/AboutSpectrumSimulationModal.js +1 -1
  25. package/lib/component/modal/EditPeakShapeModal.js +1 -1
  26. package/lib/component/modal/ImportPublicationStringModal.d.ts +5 -3
  27. package/lib/component/modal/ImportPublicationStringModal.js +7 -4
  28. package/lib/component/modal/LoadJCAMPModal.js +1 -1
  29. package/lib/component/modal/LogsHistoryModal.js +1 -1
  30. package/lib/component/modal/MultipletAnalysisModal.js +1 -1
  31. package/lib/component/modal/SaveAsModal.js +2 -2
  32. package/lib/component/modal/editZone/EditPathLengthFormik.js +2 -2
  33. package/lib/component/modal/editZone/EditZoneModal.js +1 -1
  34. package/lib/component/modal/metaImportation/MetaImportationModal.js +1 -1
  35. package/lib/component/modal/setting/GeneralSettings.js +2 -2
  36. package/lib/component/modal/setting/settings-tabs/GeneralTabContent.js +1 -1
  37. package/lib/component/modal/setting/settings-tabs/InfoBlockTabContent.js +1 -1
  38. package/lib/component/modal/setting/settings-tabs/OnLoadProcessingTabContent.js +1 -1
  39. package/lib/component/panels/IntegralsPanel/IntegralsPreferences.js +1 -1
  40. package/lib/component/panels/Panels.js +5 -5
  41. package/lib/component/panels/RangesPanel/RangesHeader.js +21 -7
  42. package/lib/component/panels/RangesPanel/RangesPanel.js +1 -1
  43. package/lib/component/panels/RangesPanel/RangesPreferences.js +9 -3
  44. package/lib/component/panels/RangesPanel/RangesTable.js +1 -1
  45. package/lib/component/panels/RangesPanel/RangesTableRow.js +2 -1
  46. package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentColumn.d.ts +7 -0
  47. package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentColumn.js +16 -0
  48. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.d.ts +5 -0
  49. package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectraPanelHeader.js +8 -8
  50. package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectraTable.js +1 -1
  51. package/lib/component/panels/SpectraPanel/SpectraTabs.d.ts +1 -0
  52. package/lib/component/panels/{SpectrumsPanel/SpectrumsTabs.js → SpectraPanel/SpectraTabs.js} +6 -6
  53. package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectrumListPanel.js +2 -2
  54. package/lib/component/panels/databasePanel/DatabasePreferences.js +1 -1
  55. package/lib/component/panels/header/SpectraAutomaticPickingButton.js +1 -1
  56. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +1 -1
  57. package/lib/component/panels/multipleAnalysisPanel/AnalysisChart.js +2 -2
  58. package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
  59. package/lib/component/panels/multipleAnalysisPanel/preferences/index.js +1 -1
  60. package/lib/component/panels/predictionPanel/PredictionOptionsPanel.js +2 -2
  61. package/lib/component/panels/predictionPanel/PredictionSimpleOptions.js +1 -1
  62. package/lib/component/panels/spectrumSimulation/SpectrumSimulation.js +8 -1
  63. package/lib/component/panels/spectrumSimulation/SpectrumSimulationPreferences.js +1 -1
  64. package/lib/component/panels/spectrumSimulation/SpectrumSimulationSimpleOptions.js +2 -2
  65. package/lib/component/panels/spectrumSimulation/SpinSystemTable.js +1 -1
  66. package/lib/component/reducer/IgnoreActions.js +1 -1
  67. package/lib/component/reducer/Reducer.d.ts +1 -0
  68. package/lib/component/reducer/Reducer.js +19 -16
  69. package/lib/component/reducer/actions/DomainActions.js +3 -3
  70. package/lib/component/reducer/actions/FiltersActions.js +337 -317
  71. package/lib/component/reducer/actions/LoadActions.js +1 -1
  72. package/lib/component/reducer/actions/PreferencesActions.js +2 -2
  73. package/lib/component/reducer/actions/RangesActions.d.ts +7 -2
  74. package/lib/component/reducer/actions/RangesActions.js +16 -2
  75. package/lib/component/reducer/actions/ToolsActions.d.ts +3 -3
  76. package/lib/component/reducer/actions/ToolsActions.js +21 -28
  77. package/lib/component/reducer/actions/ZonesActions.d.ts +2 -0
  78. package/lib/component/reducer/actions/ZonesActions.js +5 -1
  79. package/lib/component/reducer/preferences/panelsPreferencesDefaultValues.js +6 -4
  80. package/lib/component/toolbar/ToolBar.js +16 -16
  81. package/lib/component/toolbar/toolbarMenu.js +4 -4
  82. package/lib/component/utility/export.js +1 -1
  83. package/lib/constants.js +5 -5
  84. package/lib/data/data2d/Spectrum2D/getSlice.js +1 -1
  85. package/lib/data/data2d/Spectrum2D/zones/getDetectionZones.d.ts +1 -0
  86. package/lib/versionInfo.js +1 -1
  87. package/package.json +16 -15
  88. package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.d.ts +0 -5
  89. package/lib/component/panels/SpectrumsPanel/SpectrumsTabs.d.ts +0 -1
  90. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectraPreferences.d.ts +0 -0
  91. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectraPreferences.js +0 -0
  92. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectraTable.d.ts +0 -0
  93. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/SpectrumListPanel.d.ts +0 -0
  94. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/ColorIndicator.d.ts +0 -0
  95. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/ColorIndicator.js +0 -0
  96. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/RenderAsHTML.d.ts +0 -0
  97. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/RenderAsHTML.js +0 -0
  98. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/ShowHideSpectrumButton.d.ts +0 -0
  99. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/ShowHideSpectrumButton.js +0 -0
  100. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/SpectraColumnsManager.d.ts +0 -0
  101. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/SpectraColumnsManager.js +0 -0
  102. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/SpectrumName.d.ts +0 -0
  103. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/SpectrumName.js +0 -0
  104. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/PlotChart.d.ts +0 -0
  105. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/PlotChart.js +0 -0
  106. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum1DHistogram.d.ts +0 -0
  107. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum1DHistogram.js +0 -0
  108. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum1DSetting.d.ts +0 -0
  109. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum1DSetting.js +0 -0
  110. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum2DHistogram.d.ts +0 -0
  111. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum2DHistogram.js +0 -0
  112. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum2DSetting.d.ts +0 -0
  113. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/Spectrum2DSetting.js +0 -0
  114. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/SpectrumSetting.d.ts +0 -0
  115. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/SpectrumSetting.js +0 -0
  116. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/processSnapPlot.d.ts +0 -0
  117. /package/lib/component/panels/{SpectrumsPanel → SpectraPanel}/base/setting/processSnapPlot.js +0 -0
  118. /package/lib/component/reducer/actions/{SpectrumsActions.d.ts → SpectraActions.d.ts} +0 -0
  119. /package/lib/component/reducer/actions/{SpectrumsActions.js → SpectraActions.js} +0 -0
@@ -280,148 +280,155 @@ function updateView(draft, filterUpdateDomainRules) {
280
280
  }
281
281
  function disableLivePreview(draft, id) {
282
282
  const activeSpectrum = getActiveSpectrum(draft);
283
- if (activeSpectrum) {
284
- const index = activeSpectrum.index;
285
- const { data } = draft.tempData[index];
286
- draft.data[index].data = data;
287
- if (baselineCorrection.id !== id) {
288
- setDomain(draft);
289
- }
290
- // reset default options
291
- switch (id) {
292
- case apodization.id: {
293
- draft.toolOptions.data.apodizationOptions = defaultApodizationOptions;
294
- break;
295
- }
296
- default:
297
- break;
283
+ if (!activeSpectrum || !draft.tempData) {
284
+ return;
285
+ }
286
+ const index = activeSpectrum.index;
287
+ const { data } = draft.tempData[index];
288
+ draft.data[index].data = data;
289
+ if (baselineCorrection.id !== id) {
290
+ setDomain(draft);
291
+ }
292
+ // reset default options
293
+ switch (id) {
294
+ case apodization.id: {
295
+ draft.toolOptions.data.apodizationOptions = defaultApodizationOptions;
296
+ break;
298
297
  }
298
+ default:
299
+ break;
299
300
  }
300
301
  }
301
302
  //action
302
303
  function handleShiftSpectrumAlongXAxis(draft, action) {
304
+ const activeSpectrum = getActiveSpectrum(draft);
305
+ if (!activeSpectrum) {
306
+ return;
307
+ }
303
308
  //apply filter into the spectrum
304
309
  const { shift } = action.payload;
305
- const activeSpectrum = getActiveSpectrum(draft);
306
- if (activeSpectrum) {
307
- const activeFilterIndex = getActiveFilterIndex(draft);
308
- const index = activeSpectrum?.index;
309
- FiltersManager.applyFilter(draft.data[index], [
310
- { name: shiftX.id, value: { shift } },
311
- ]);
312
- if (activeFilterIndex !== -1) {
313
- rollbackSpectrumByFilter(draft, {
314
- searchBy: 'name',
315
- key: shiftX.id,
316
- triggerSource: 'Apply',
317
- });
318
- }
319
- else {
320
- updateView(draft, shiftX.DOMAIN_UPDATE_RULES);
321
- }
310
+ const activeFilterIndex = getActiveFilterIndex(draft);
311
+ const index = activeSpectrum?.index;
312
+ FiltersManager.applyFilter(draft.data[index], [
313
+ { name: shiftX.id, value: { shift } },
314
+ ]);
315
+ if (activeFilterIndex !== -1) {
316
+ rollbackSpectrumByFilter(draft, {
317
+ searchBy: 'name',
318
+ key: shiftX.id,
319
+ triggerSource: 'Apply',
320
+ });
321
+ }
322
+ else {
323
+ updateView(draft, shiftX.DOMAIN_UPDATE_RULES);
322
324
  }
323
325
  }
324
326
  //action
325
327
  function handleApplyZeroFillingFilter(draft, action) {
326
328
  const activeSpectrum = getActiveSpectrum(draft);
327
- if (activeSpectrum) {
328
- const activeFilterIndex = getActiveFilterIndex(draft);
329
- const index = activeSpectrum.index;
330
- const filters = [
331
- {
332
- name: zeroFilling.id,
333
- value: action.payload.options,
334
- },
335
- ];
336
- FiltersManager.applyFilter(draft.tempData[index], filters, {
337
- filterIndex: activeFilterIndex,
329
+ if (!activeSpectrum || !draft.tempData) {
330
+ return;
331
+ }
332
+ const activeFilterIndex = getActiveFilterIndex(draft);
333
+ const index = activeSpectrum.index;
334
+ const filters = [
335
+ {
336
+ name: zeroFilling.id,
337
+ value: action.payload.options,
338
+ },
339
+ ];
340
+ FiltersManager.applyFilter(draft.tempData[index], filters, {
341
+ filterIndex: activeFilterIndex,
342
+ });
343
+ draft.data[index] = draft.tempData[index];
344
+ if (activeFilterIndex !== -1) {
345
+ rollbackSpectrumByFilter(draft, {
346
+ searchBy: 'name',
347
+ key: zeroFilling.id,
348
+ triggerSource: 'Apply',
338
349
  });
339
- draft.data[index] = draft.tempData[index];
340
- if (activeFilterIndex !== -1) {
341
- rollbackSpectrumByFilter(draft, {
342
- searchBy: 'name',
343
- key: zeroFilling.id,
344
- triggerSource: 'Apply',
345
- });
346
- }
347
- else {
348
- updateView(draft, zeroFilling.DOMAIN_UPDATE_RULES);
349
- }
350
+ }
351
+ else {
352
+ updateView(draft, zeroFilling.DOMAIN_UPDATE_RULES);
350
353
  }
351
354
  }
352
355
  //action
353
356
  function handleCalculateZeroFillingFilter(draft, action) {
354
357
  const activeSpectrum = getActiveSpectrum(draft);
355
- if (activeSpectrum) {
356
- const { options, livePreview } = action.payload;
357
- if (livePreview) {
358
- const index = activeSpectrum.index;
359
- const { data: { x, re, im }, filters, info, } = draft.tempData[index];
360
- const _data = { data: { x, re, im }, filters, info };
361
- zeroFilling.apply(_data, options);
362
- const { im: newIm, re: newRe, x: newX } = _data.data;
363
- const datum = draft.data[index];
364
- datum.data.x = newX;
365
- datum.data.im = newIm;
366
- datum.data.re = newRe;
367
- draft.xDomain = [newX[0], newX.at(-1)];
368
- }
369
- else {
370
- disableLivePreview(draft, zeroFilling.name);
371
- }
358
+ if (!activeSpectrum || !draft.tempData) {
359
+ return;
360
+ }
361
+ const { options, livePreview } = action.payload;
362
+ if (livePreview) {
363
+ const index = activeSpectrum.index;
364
+ const { data: { x, re, im }, filters, info, } = draft.tempData[index];
365
+ const _data = { data: { x, re, im }, filters, info };
366
+ zeroFilling.apply(_data, options);
367
+ const { im: newIm, re: newRe, x: newX } = _data.data;
368
+ const datum = draft.data[index];
369
+ datum.data.x = newX;
370
+ datum.data.im = newIm;
371
+ datum.data.re = newRe;
372
+ draft.xDomain = [newX[0], newX.at(-1)];
373
+ }
374
+ else {
375
+ disableLivePreview(draft, zeroFilling.name);
372
376
  }
373
377
  }
374
378
  //action
375
379
  function handleCalculateApodizationFilter(draft, action) {
376
380
  const activeSpectrum = getActiveSpectrum(draft);
377
- if (activeSpectrum) {
378
- const index = activeSpectrum.index;
379
- const { livePreview, options } = action.payload;
380
- if (livePreview) {
381
- const { data: { x, re, im }, info, } = draft.tempData[index];
382
- const _data = { data: { x, re, im }, info };
383
- draft.toolOptions.data.apodizationOptions = options;
384
- apodization.apply(_data, options);
385
- const { im: newIm, re: newRe } = _data.data;
386
- const datum = draft.data[index];
387
- datum.data.im = newIm;
388
- datum.data.re = newRe;
389
- }
390
- else {
391
- disableLivePreview(draft, apodization.name);
392
- }
381
+ if (!activeSpectrum || !draft.tempData) {
382
+ return;
383
+ }
384
+ const index = activeSpectrum.index;
385
+ const { livePreview, options } = action.payload;
386
+ if (livePreview) {
387
+ const { data: { x, re, im }, info, } = draft.tempData[index];
388
+ const _data = { data: { x, re, im }, info };
389
+ draft.toolOptions.data.apodizationOptions = options;
390
+ apodization.apply(_data, options);
391
+ const { im: newIm, re: newRe } = _data.data;
392
+ const datum = draft.data[index];
393
+ datum.data.im = newIm;
394
+ datum.data.re = newRe;
395
+ }
396
+ else {
397
+ disableLivePreview(draft, apodization.name);
393
398
  }
394
399
  }
395
400
  //action
396
401
  function handleApplyApodizationFilter(draft, action) {
397
402
  const activeSpectrum = getActiveSpectrum(draft);
398
- if (activeSpectrum) {
399
- const index = activeSpectrum.index;
400
- const activeFilterIndex = getActiveFilterIndex(draft);
401
- FiltersManager.applyFilter(draft.tempData[index], [
402
- {
403
- name: apodization.id,
404
- value: action.payload.options,
405
- },
406
- ], { filterIndex: activeFilterIndex });
407
- draft.data[index] = draft.tempData[index];
408
- if (activeFilterIndex !== -1) {
409
- rollbackSpectrumByFilter(draft, {
410
- searchBy: 'name',
411
- key: apodization.id,
412
- triggerSource: 'Apply',
413
- });
414
- }
415
- else {
416
- updateView(draft, apodization.DOMAIN_UPDATE_RULES);
417
- }
403
+ if (!activeSpectrum || !draft.tempData) {
404
+ return;
405
+ }
406
+ const index = activeSpectrum.index;
407
+ const activeFilterIndex = getActiveFilterIndex(draft);
408
+ FiltersManager.applyFilter(draft.tempData[index], [
409
+ {
410
+ name: apodization.id,
411
+ value: action.payload.options,
412
+ },
413
+ ], { filterIndex: activeFilterIndex });
414
+ draft.data[index] = draft.tempData[index];
415
+ if (activeFilterIndex !== -1) {
416
+ rollbackSpectrumByFilter(draft, {
417
+ searchBy: 'name',
418
+ key: apodization.id,
419
+ triggerSource: 'Apply',
420
+ });
421
+ }
422
+ else {
423
+ updateView(draft, apodization.DOMAIN_UPDATE_RULES);
418
424
  }
419
425
  }
420
426
  //action
421
427
  function handleApplyFFTFilter(draft) {
422
428
  const activeSpectrum = getActiveSpectrum(draft);
423
- if (!activeSpectrum)
429
+ if (!activeSpectrum) {
424
430
  return;
431
+ }
425
432
  const { index } = activeSpectrum;
426
433
  const activeFilterIndex = getActiveFilterIndex(draft);
427
434
  //apply filter into the spectrum
@@ -446,8 +453,9 @@ function handleApplyFFTFilter(draft) {
446
453
  }
447
454
  function handleApplyFFtDimension1Filter(draft) {
448
455
  const activeSpectrum = getActiveSpectrum(draft);
449
- if (!activeSpectrum)
456
+ if (!activeSpectrum) {
450
457
  return;
458
+ }
451
459
  const { index } = activeSpectrum;
452
460
  const activeFilterIndex = getActiveFilterIndex(draft);
453
461
  //apply filter into the spectrum
@@ -472,8 +480,9 @@ function handleApplyFFtDimension1Filter(draft) {
472
480
  }
473
481
  function handleApplyFFtDimension2Filter(draft) {
474
482
  const activeSpectrum = getActiveSpectrum(draft);
475
- if (!activeSpectrum)
483
+ if (!activeSpectrum) {
476
484
  return;
485
+ }
477
486
  const { index } = activeSpectrum;
478
487
  const activeFilterIndex = getActiveFilterIndex(draft);
479
488
  //apply filter into the spectrum
@@ -499,60 +508,62 @@ function handleApplyFFtDimension2Filter(draft) {
499
508
  //action
500
509
  function handleApplyManualPhaseCorrectionFilter(draft, action) {
501
510
  const activeSpectrum = getActiveSpectrum(draft);
502
- if (activeSpectrum) {
503
- const { index } = activeSpectrum;
504
- const { ph0, ph1 } = action.payload;
505
- draft.data = draft.tempData;
506
- const activeFilterIndex = getActiveFilterIndex(draft);
507
- FiltersManager.applyFilter(draft.tempData[index], [
508
- {
509
- name: phaseCorrection.id,
510
- value: { ph0, ph1 },
511
- },
512
- ], { filterIndex: activeFilterIndex });
513
- draft.data[index] = draft.tempData[index];
514
- if (activeFilterIndex !== -1) {
515
- rollbackSpectrumByFilter(draft, {
516
- searchBy: 'name',
517
- key: phaseCorrection.id,
518
- triggerSource: 'Apply',
519
- });
520
- }
521
- else {
522
- updateView(draft, phaseCorrection.DOMAIN_UPDATE_RULES);
523
- }
511
+ if (!activeSpectrum || !draft.tempData) {
512
+ return;
513
+ }
514
+ const { index } = activeSpectrum;
515
+ const { ph0, ph1 } = action.payload;
516
+ draft.data = draft.tempData;
517
+ const activeFilterIndex = getActiveFilterIndex(draft);
518
+ FiltersManager.applyFilter(draft.tempData[index], [
519
+ {
520
+ name: phaseCorrection.id,
521
+ value: { ph0, ph1 },
522
+ },
523
+ ], { filterIndex: activeFilterIndex });
524
+ draft.data[index] = draft.tempData[index];
525
+ if (activeFilterIndex !== -1) {
526
+ rollbackSpectrumByFilter(draft, {
527
+ searchBy: 'name',
528
+ key: phaseCorrection.id,
529
+ triggerSource: 'Apply',
530
+ });
531
+ }
532
+ else {
533
+ updateView(draft, phaseCorrection.DOMAIN_UPDATE_RULES);
524
534
  }
525
535
  }
526
536
  //action
527
537
  function handleAddPhaseCorrectionTrace(draft, action) {
528
- const { x, y } = action.payload;
529
538
  const activeSpectrum = getActiveSpectrum(draft);
539
+ if (!activeSpectrum) {
540
+ return;
541
+ }
542
+ const { x, y } = action.payload;
530
543
  const { margin, width, height, xDomain, yDomain, mode, data: spectra, } = draft;
531
544
  const { activeTraces, traces, addTracesToBothDirections } = getTwoDimensionPhaseCorrectionOptions(draft);
532
- if (activeSpectrum?.id) {
533
- const spectrum = spectra[activeSpectrum.index];
534
- if (isSpectrum2D(spectrum)) {
535
- const scale2dX = get2DXScale({ margin, width, xDomain, mode });
536
- const scale2dY = get2DYScale({ margin, height, yDomain });
537
- const xPPM = scale2dX.invert(x);
538
- const yPPM = scale2dY.invert(y);
539
- if (addTracesToBothDirections) {
540
- for (const direction of Object.keys(traces)) {
541
- traces[direction].spectra.push({
542
- id: v4(),
543
- x: xPPM,
544
- y: yPPM,
545
- });
546
- }
547
- }
548
- else {
549
- activeTraces.spectra.push({
545
+ const spectrum = spectra[activeSpectrum.index];
546
+ if (isSpectrum2D(spectrum)) {
547
+ const scale2dX = get2DXScale({ margin, width, xDomain, mode });
548
+ const scale2dY = get2DYScale({ margin, height, yDomain });
549
+ const xPPM = scale2dX.invert(x);
550
+ const yPPM = scale2dY.invert(y);
551
+ if (addTracesToBothDirections) {
552
+ for (const direction of Object.keys(traces)) {
553
+ traces[direction].spectra.push({
550
554
  id: v4(),
551
555
  x: xPPM,
552
556
  y: yPPM,
553
557
  });
554
558
  }
555
559
  }
560
+ else {
561
+ activeTraces.spectra.push({
562
+ id: v4(),
563
+ x: xPPM,
564
+ y: yPPM,
565
+ });
566
+ }
556
567
  }
557
568
  }
558
569
  //action
@@ -576,123 +587,128 @@ function handleDeletePhaseCorrectionTrace(draft, action) {
576
587
  //action
577
588
  function handleCalculateManualPhaseCorrection(draft, action) {
578
589
  const activeSpectrum = getActiveSpectrum(draft);
579
- if (activeSpectrum) {
580
- const { index } = activeSpectrum;
581
- const { data: { x, re, im }, info, } = draft.tempData[index];
582
- const { ph0, ph1 } = action.payload;
583
- const _data = { data: { x, re, im }, info };
584
- phaseCorrection.apply(_data, { ph0, ph1 });
585
- const { im: newIm, re: newRe } = _data.data;
586
- const datum = draft.data[index];
587
- datum.data.im = newIm;
588
- datum.data.re = newRe;
590
+ if (!activeSpectrum || !draft.tempData) {
591
+ return;
589
592
  }
593
+ const { index } = activeSpectrum;
594
+ const { data: { x, re, im }, info, } = draft.tempData[index];
595
+ const { ph0, ph1 } = action.payload;
596
+ const _data = { data: { x, re, im }, info };
597
+ phaseCorrection.apply(_data, { ph0, ph1 });
598
+ const { im: newIm, re: newRe } = _data.data;
599
+ const datum = draft.data[index];
600
+ datum.data.im = newIm;
601
+ datum.data.re = newRe;
590
602
  }
591
603
  //action
592
604
  function handleApplyAbsoluteFilter(draft) {
593
605
  const activeSpectrum = getActiveSpectrum(draft);
594
- if (activeSpectrum) {
595
- const { index } = activeSpectrum;
596
- const activeFilterIndex = getActiveFilterIndex(draft);
597
- FiltersManager.applyFilter(draft.tempData[index], [
598
- {
599
- name: phaseCorrection.id,
600
- value: { absolute: true },
601
- },
602
- ], { filterIndex: activeFilterIndex });
603
- draft.data[index] = draft.tempData[index];
604
- if (activeFilterIndex !== -1) {
605
- rollbackSpectrumByFilter(draft, {
606
- searchBy: 'name',
607
- key: phaseCorrection.id,
608
- triggerSource: 'Apply',
609
- });
610
- }
611
- else {
612
- updateView(draft, phaseCorrection.DOMAIN_UPDATE_RULES);
613
- }
606
+ if (!activeSpectrum || !draft.tempData) {
607
+ return;
608
+ }
609
+ const { index } = activeSpectrum;
610
+ const activeFilterIndex = getActiveFilterIndex(draft);
611
+ FiltersManager.applyFilter(draft.tempData[index], [
612
+ {
613
+ name: phaseCorrection.id,
614
+ value: { absolute: true },
615
+ },
616
+ ], { filterIndex: activeFilterIndex });
617
+ draft.data[index] = draft.tempData[index];
618
+ if (activeFilterIndex !== -1) {
619
+ rollbackSpectrumByFilter(draft, {
620
+ searchBy: 'name',
621
+ key: phaseCorrection.id,
622
+ triggerSource: 'Apply',
623
+ });
624
+ }
625
+ else {
626
+ updateView(draft, phaseCorrection.DOMAIN_UPDATE_RULES);
614
627
  }
615
628
  }
616
629
  //action
617
630
  function handleApplyAutoPhaseCorrectionFilter(draft) {
618
631
  const activeSpectrum = getActiveSpectrum(draft);
619
- if (activeSpectrum) {
620
- const { index } = activeSpectrum;
621
- const activeFilterIndex = getActiveFilterIndex(draft);
622
- FiltersManager.applyFilter(draft.tempData[index], [
623
- {
624
- name: phaseCorrection.id,
625
- value: {},
626
- },
627
- ], { filterIndex: activeFilterIndex });
628
- draft.data[index] = draft.tempData[index];
629
- if (activeFilterIndex !== -1) {
630
- rollbackSpectrumByFilter(draft, {
631
- searchBy: 'name',
632
- key: phaseCorrection.id,
633
- triggerSource: 'Apply',
634
- });
635
- }
636
- else {
637
- updateView(draft, phaseCorrection.DOMAIN_UPDATE_RULES);
638
- }
632
+ if (!activeSpectrum || !draft.tempData) {
633
+ return;
634
+ }
635
+ const { index } = activeSpectrum;
636
+ const activeFilterIndex = getActiveFilterIndex(draft);
637
+ FiltersManager.applyFilter(draft.tempData[index], [
638
+ {
639
+ name: phaseCorrection.id,
640
+ value: {},
641
+ },
642
+ ], { filterIndex: activeFilterIndex });
643
+ draft.data[index] = draft.tempData[index];
644
+ if (activeFilterIndex !== -1) {
645
+ rollbackSpectrumByFilter(draft, {
646
+ searchBy: 'name',
647
+ key: phaseCorrection.id,
648
+ triggerSource: 'Apply',
649
+ });
650
+ }
651
+ else {
652
+ updateView(draft, phaseCorrection.DOMAIN_UPDATE_RULES);
639
653
  }
640
654
  }
641
655
  //action
642
656
  function handleBaseLineCorrectionFilter(draft, action) {
643
657
  const activeSpectrum = getActiveSpectrum(draft);
644
- if (activeSpectrum) {
645
- const { index } = activeSpectrum;
646
- const { zones } = draft.toolOptions.data.baselineCorrection;
647
- const { options } = action.payload;
648
- const activeFilterIndex = getActiveFilterIndex(draft);
649
- FiltersManager.applyFilter(draft.tempData[index], [
650
- {
651
- name: baselineCorrection.id,
652
- value: {
653
- ...options,
654
- zones,
655
- },
658
+ if (!activeSpectrum || !draft.tempData) {
659
+ return;
660
+ }
661
+ const { index } = activeSpectrum;
662
+ const { zones } = draft.toolOptions.data.baselineCorrection;
663
+ const { options } = action.payload;
664
+ const activeFilterIndex = getActiveFilterIndex(draft);
665
+ FiltersManager.applyFilter(draft.tempData[index], [
666
+ {
667
+ name: baselineCorrection.id,
668
+ value: {
669
+ ...options,
670
+ zones,
656
671
  },
657
- ], { filterIndex: activeFilterIndex });
658
- draft.data[index] = draft.tempData[index];
659
- if (activeFilterIndex !== -1) {
660
- rollbackSpectrumByFilter(draft, {
661
- searchBy: 'name',
662
- key: baselineCorrection.id,
663
- triggerSource: 'Apply',
664
- });
665
- }
666
- else {
667
- updateView(draft, baselineCorrection.DOMAIN_UPDATE_RULES);
668
- }
672
+ },
673
+ ], { filterIndex: activeFilterIndex });
674
+ draft.data[index] = draft.tempData[index];
675
+ if (activeFilterIndex !== -1) {
676
+ rollbackSpectrumByFilter(draft, {
677
+ searchBy: 'name',
678
+ key: baselineCorrection.id,
679
+ triggerSource: 'Apply',
680
+ });
681
+ }
682
+ else {
683
+ updateView(draft, baselineCorrection.DOMAIN_UPDATE_RULES);
669
684
  }
670
685
  }
671
686
  function calculateBaseLineCorrection(draft, baseLineOptions) {
672
687
  const activeSpectrum = getActiveSpectrum(draft);
673
- if (activeSpectrum) {
674
- const { index } = activeSpectrum;
675
- const { data: { x, re, im }, info, } = draft.tempData[index];
676
- // save the baseline options temporary
677
- draft.toolOptions.data.baselineCorrection = {
678
- ...draft.toolOptions.data.baselineCorrection,
679
- ...(baseLineOptions && baseLineOptions),
680
- };
681
- const { zones, options, livePreview } = current(draft).toolOptions.data.baselineCorrection;
682
- if (livePreview) {
683
- const _data = { data: { x, re, im }, info };
684
- baselineCorrection.apply(_data, {
685
- zones,
686
- ...options,
687
- });
688
- const { im: newIm, re: newRe } = _data.data;
689
- const datum = draft.data[index];
690
- datum.data.im = newIm;
691
- datum.data.re = newRe;
692
- }
693
- else {
694
- disableLivePreview(draft, baselineCorrection.id);
695
- }
688
+ if (!activeSpectrum || !draft.tempData) {
689
+ return;
690
+ }
691
+ const { index } = activeSpectrum;
692
+ const { data: { x, re, im }, info, } = draft.tempData[index];
693
+ // save the baseline options temporary
694
+ draft.toolOptions.data.baselineCorrection = {
695
+ ...draft.toolOptions.data.baselineCorrection,
696
+ ...(baseLineOptions && baseLineOptions),
697
+ };
698
+ const { zones, options, livePreview } = current(draft).toolOptions.data.baselineCorrection;
699
+ if (livePreview) {
700
+ const _data = { data: { x, re, im }, info };
701
+ baselineCorrection.apply(_data, {
702
+ zones,
703
+ ...options,
704
+ });
705
+ const { im: newIm, re: newRe } = _data.data;
706
+ const datum = draft.data[index];
707
+ datum.data.im = newIm;
708
+ datum.data.re = newRe;
709
+ }
710
+ else {
711
+ disableLivePreview(draft, baselineCorrection.id);
696
712
  }
697
713
  }
698
714
  //action
@@ -701,34 +717,36 @@ function handleCalculateBaseLineCorrection(draft, action) {
701
717
  }
702
718
  //action
703
719
  function handleEnableFilter(draft, action) {
704
- const { id: filterID, enabled } = action.payload;
705
720
  const activeSpectrum = getActiveSpectrum(draft);
706
- if (activeSpectrum) {
707
- //apply filter into the spectrum
708
- FiltersManager.enableFilter(draft.data[activeSpectrum.index], filterID, enabled);
709
- resetSelectedTool(draft);
710
- setDomain(draft);
711
- setMode(draft);
712
- const zoomHistory = zoomHistoryManager(draft.zoom.history, draft.view.spectra.activeTab);
713
- const zoomValue = zoomHistory.getLast();
714
- if (zoomValue) {
715
- draft.xDomain = zoomValue.xDomain;
716
- draft.yDomain = zoomValue.yDomain;
717
- }
721
+ if (!activeSpectrum) {
722
+ return;
723
+ }
724
+ const { id: filterID, enabled } = action.payload;
725
+ //apply filter into the spectrum
726
+ FiltersManager.enableFilter(draft.data[activeSpectrum.index], filterID, enabled);
727
+ resetSelectedTool(draft);
728
+ setDomain(draft);
729
+ setMode(draft);
730
+ const zoomHistory = zoomHistoryManager(draft.zoom.history, draft.view.spectra.activeTab);
731
+ const zoomValue = zoomHistory.getLast();
732
+ if (zoomValue) {
733
+ draft.xDomain = zoomValue.xDomain;
734
+ draft.yDomain = zoomValue.yDomain;
718
735
  }
719
736
  }
720
737
  //action
721
738
  function handleDeleteFilter(draft, action) {
722
- const filterID = action?.payload?.id;
723
739
  const activeSpectrum = getActiveSpectrum(draft);
724
- if (activeSpectrum) {
725
- //apply filter into the spectrum
726
- FiltersManager.deleteFilter(draft.data[activeSpectrum.index], filterID);
727
- draft.toolOptions.data.activeFilterID = null;
728
- resetSelectedTool(draft);
729
- setDomain(draft);
730
- setMode(draft);
740
+ if (!activeSpectrum) {
741
+ return;
731
742
  }
743
+ const filterID = action?.payload?.id;
744
+ //apply filter into the spectrum
745
+ FiltersManager.deleteFilter(draft.data[activeSpectrum.index], filterID);
746
+ draft.toolOptions.data.activeFilterID = null;
747
+ resetSelectedTool(draft);
748
+ setDomain(draft);
749
+ setMode(draft);
732
750
  }
733
751
  //action
734
752
  function handleDeleteSpectraFilter(draft, action) {
@@ -847,35 +865,36 @@ function handleSetOneDimensionPhaseCorrectionPivotPoint(draft, action) {
847
865
  }
848
866
  }
849
867
  function handleSetTwoDimensionPhaseCorrectionPivotPoint(draft, action) {
868
+ const activeSpectrum = getActiveSpectrum(draft);
869
+ if (!activeSpectrum) {
870
+ return;
871
+ }
850
872
  const { data: spectra, margin, width, height, yDomain, xDomain, mode, } = draft;
851
873
  const { x, y } = action.payload;
852
874
  const { activeTraces, activeTraceDirection } = getTwoDimensionPhaseCorrectionOptions(draft);
853
- const activeSpectrum = getActiveSpectrum(draft);
854
- if (activeSpectrum?.id) {
855
- switch (activeTraceDirection) {
856
- case 'horizontal':
857
- {
858
- const scale = get2DXScale({ margin, width, xDomain, mode });
859
- const pivotValue = scale.invert(x);
860
- const spectrum = spectra[activeSpectrum.index];
861
- const datum = getProjection(spectrum.data.rr, 0);
862
- const index = xFindClosestIndex(datum.x, pivotValue);
863
- activeTraces.pivot = { value: pivotValue, index };
864
- }
865
- break;
866
- case 'vertical':
867
- {
868
- const scale = get2DYScale({ margin, height, yDomain });
869
- const pivotValue = scale.invert(y);
870
- const spectrum = spectra[activeSpectrum.index];
871
- const datum = getProjection(spectrum.data.rr, 1);
872
- const index = xFindClosestIndex(datum.x, pivotValue);
873
- activeTraces.pivot = { value: pivotValue, index };
874
- }
875
- break;
876
- default:
877
- break;
878
- }
875
+ switch (activeTraceDirection) {
876
+ case 'horizontal':
877
+ {
878
+ const scale = get2DXScale({ margin, width, xDomain, mode });
879
+ const pivotValue = scale.invert(x);
880
+ const spectrum = spectra[activeSpectrum.index];
881
+ const datum = getProjection(spectrum.data.rr, 0);
882
+ const index = xFindClosestIndex(datum.x, pivotValue);
883
+ activeTraces.pivot = { value: pivotValue, index };
884
+ }
885
+ break;
886
+ case 'vertical':
887
+ {
888
+ const scale = get2DYScale({ margin, height, yDomain });
889
+ const pivotValue = scale.invert(y);
890
+ const spectrum = spectra[activeSpectrum.index];
891
+ const datum = getProjection(spectrum.data.rr, 1);
892
+ const index = xFindClosestIndex(datum.x, pivotValue);
893
+ activeTraces.pivot = { value: pivotValue, index };
894
+ }
895
+ break;
896
+ default:
897
+ break;
879
898
  }
880
899
  }
881
900
  //action
@@ -919,28 +938,29 @@ function getTwoDimensionsPhaseCorrectionOptions(draft) {
919
938
  //action
920
939
  function handleApplyManualTowDimensionsPhaseCorrectionFilter(draft) {
921
940
  const activeSpectrum = getActiveSpectrum(draft);
922
- if (activeSpectrum) {
923
- const { index } = activeSpectrum;
924
- draft.data = draft.tempData;
925
- const activeFilterIndex = getActiveFilterIndex(draft);
926
- const filterOptions = getTwoDimensionsPhaseCorrectionOptions(draft);
927
- FiltersManager.applyFilter(draft.tempData[index], [
928
- {
929
- name: phaseCorrectionTwoDimensions.id,
930
- value: filterOptions,
931
- },
932
- ], { filterIndex: activeFilterIndex });
933
- draft.data[index] = draft.tempData[index];
934
- if (activeFilterIndex !== -1) {
935
- rollbackSpectrumByFilter(draft, {
936
- searchBy: 'name',
937
- key: phaseCorrectionTwoDimensions.id,
938
- triggerSource: 'Apply',
939
- });
940
- }
941
- else {
942
- updateView(draft, phaseCorrectionTwoDimensions.DOMAIN_UPDATE_RULES);
943
- }
941
+ if (!activeSpectrum || !draft.tempData) {
942
+ return;
943
+ }
944
+ const { index } = activeSpectrum;
945
+ draft.data = draft.tempData;
946
+ const activeFilterIndex = getActiveFilterIndex(draft);
947
+ const filterOptions = getTwoDimensionsPhaseCorrectionOptions(draft);
948
+ FiltersManager.applyFilter(draft.tempData[index], [
949
+ {
950
+ name: phaseCorrectionTwoDimensions.id,
951
+ value: filterOptions,
952
+ },
953
+ ], { filterIndex: activeFilterIndex });
954
+ draft.data[index] = draft.tempData[index];
955
+ if (activeFilterIndex !== -1) {
956
+ rollbackSpectrumByFilter(draft, {
957
+ searchBy: 'name',
958
+ key: phaseCorrectionTwoDimensions.id,
959
+ triggerSource: 'Apply',
960
+ });
961
+ }
962
+ else {
963
+ updateView(draft, phaseCorrectionTwoDimensions.DOMAIN_UPDATE_RULES);
944
964
  }
945
965
  }
946
966
  export { handleShiftSpectrumAlongXAxis, handleApplyZeroFillingFilter, handleApplyApodizationFilter, handleApplyFFTFilter, handleApplyFFtDimension1Filter, handleApplyFFtDimension2Filter, handleApplyManualPhaseCorrectionFilter, handleApplyManualTowDimensionsPhaseCorrectionFilter, handleApplyAutoPhaseCorrectionFilter, handleApplyAbsoluteFilter, handleCalculateManualPhaseCorrection, calculateBaseLineCorrection, handleCalculateBaseLineCorrection, handleCalculateApodizationFilter, handleCalculateZeroFillingFilter, handleEnableFilter, handleDeleteFilter, handleDeleteSpectraFilter, handleBaseLineCorrectionFilter, handleSetFilterSnapshotHandler, handleAddExclusionZone, handleDeleteExclusionZone, handleSignalProcessingFilter, rollbackSpectrum, rollbackSpectrumByFilter, handleAddPhaseCorrectionTrace, handleChangePhaseCorrectionDirection, handleDeletePhaseCorrectionTrace, handleSetOneDimensionPhaseCorrectionPivotPoint, handleSetTwoDimensionPhaseCorrectionPivotPoint, handleCalculateManualTwoDimensionPhaseCorrection, handleToggleAddTracesToBothDirections, };