nmrium 0.54.0 → 0.56.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 (142) hide show
  1. package/lib/component/1d/Chart1D.js +3 -1
  2. package/lib/component/1d/Viewer1D.js +36 -11
  3. package/lib/component/1d/XAxis.js +1 -1
  4. package/lib/component/1d/integral/IntegralsSeries.js +2 -2
  5. package/lib/component/1d/integral/Integration.d.ts +3 -1
  6. package/lib/component/1d/integral/Integration.js +3 -2
  7. package/lib/component/1d/matrix/Boxplot.d.ts +6 -0
  8. package/lib/component/1d/matrix/Boxplot.js +97 -0
  9. package/lib/component/1d/matrix/Stocsy.d.ts +5 -0
  10. package/lib/component/1d/matrix/Stocsy.js +101 -0
  11. package/lib/component/1d/matrix/useMatrix.d.ts +29 -0
  12. package/lib/component/1d/matrix/useMatrix.js +93 -0
  13. package/lib/component/1d/peaks/PeakEditionManager.js +5 -3
  14. package/lib/component/1d/ranges/AssignmentActionsButtons.d.ts +1 -0
  15. package/lib/component/1d/ranges/AssignmentActionsButtons.js +3 -3
  16. package/lib/component/1d/ranges/AssignmentLabel.d.ts +1 -1
  17. package/lib/component/1d/ranges/AssignmentLabel.js +31 -4
  18. package/lib/component/1d/ranges/Atoms.js +4 -5
  19. package/lib/component/1d/ranges/Range.js +48 -6
  20. package/lib/component/1d/ranges/Ranges.js +2 -1
  21. package/lib/component/1d/ranges/RangesIntegrals.js +11 -4
  22. package/lib/component/1d/utilities/scale.d.ts +2 -1
  23. package/lib/component/1d/utilities/scale.js +6 -1
  24. package/lib/component/1d-2d/FieldEdition.d.ts +13 -0
  25. package/lib/component/1d-2d/FieldEdition.js +42 -0
  26. package/lib/component/2d/Chart2D.js +5 -3
  27. package/lib/component/2d/zones/Zone.js +18 -2
  28. package/lib/component/2d/zones/ZonesAssignmentsLabels.d.ts +7 -0
  29. package/lib/component/2d/zones/ZonesAssignmentsLabels.js +286 -0
  30. package/lib/component/EventsTrackers/KeysListenerTracker.js +14 -1
  31. package/lib/component/context/PrepareExportContext.d.ts +21 -0
  32. package/lib/component/context/PrepareExportContext.js +124 -0
  33. package/lib/component/context/ShareDataContext.d.ts +10 -0
  34. package/lib/component/context/ShareDataContext.js +22 -0
  35. package/lib/component/elements/ActionsButtonsPopover.d.ts +10 -0
  36. package/lib/component/elements/ActionsButtonsPopover.js +22 -0
  37. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +7 -5
  38. package/lib/component/elements/ReactTable/ReactTable.d.ts +2 -2
  39. package/lib/component/elements/SVGButton.d.ts +14 -0
  40. package/lib/component/elements/SVGButton.js +6 -0
  41. package/lib/component/elements/SVGGroup.js +15 -13
  42. package/lib/component/elements/SVGText.d.ts +8 -0
  43. package/lib/component/elements/SVGText.js +24 -0
  44. package/lib/component/elements/draggable/SVGDraggable.d.ts +2 -2
  45. package/lib/component/elements/formik/FormikInput.d.ts +2 -1
  46. package/lib/component/elements/formik/FormikInput.js +4 -3
  47. package/lib/component/header/Header.js +7 -10
  48. package/lib/component/hooks/useActiveSpectrumZonesViewState.js +1 -0
  49. package/lib/component/hooks/useCheckPointsNumberInWindowArea.d.ts +1 -1
  50. package/lib/component/hooks/useExport.d.ts +1 -1
  51. package/lib/component/hooks/useExport.js +4 -4
  52. package/lib/component/hooks/useFormatNumberByNucleus.d.ts +1 -1
  53. package/lib/component/hooks/useFormatNumberByNucleus.js +8 -7
  54. package/lib/component/hooks/useIntegralPath.d.ts +2 -0
  55. package/lib/component/hooks/useIntegralPath.js +3 -1
  56. package/lib/component/hooks/usePanelPreferences.d.ts +2 -3
  57. package/lib/component/hooks/usePanelPreferences.js +4 -3
  58. package/lib/component/hooks/useSaveSettings.js +7 -14
  59. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +10 -0
  60. package/lib/component/hooks/useToggleSpectraVisibility.js +41 -0
  61. package/lib/component/hooks/useTriggerNewAssignmentLabel.d.ts +4 -0
  62. package/lib/component/hooks/useTriggerNewAssignmentLabel.js +8 -0
  63. package/lib/component/hooks/useWorkspaceAction.d.ts +7 -0
  64. package/lib/component/hooks/useWorkspaceAction.js +89 -0
  65. package/lib/component/loader/DropZone.js +0 -3
  66. package/lib/component/main/InnerNMRium.js +3 -1
  67. package/lib/component/main/InnerNMRiumContents.js +14 -2
  68. package/lib/component/main/NMRiumStateProvider.js +4 -2
  69. package/lib/component/modal/editRange/forms/components/DeltaInput.js +3 -3
  70. package/lib/component/modal/editRange/forms/components/NewSignalTab.js +17 -12
  71. package/lib/component/modal/editRange/forms/components/signal-tabs/SignalJCouplingsTable.js +30 -13
  72. package/lib/component/modal/editRange/forms/components/signal-tabs/SignalPeaksTable.js +26 -16
  73. package/lib/component/modal/setting/GeneralSettings.js +7 -21
  74. package/lib/component/modal/setting/WorkspaceItem.js +1 -1
  75. package/lib/component/modal/setting/settings-tabs/NucleiTabContent.d.ts +2 -0
  76. package/lib/component/modal/setting/settings-tabs/NucleiTabContent.js +99 -0
  77. package/lib/component/modal/setting/settingsValidation.js +36 -40
  78. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.d.ts +2 -2
  79. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +121 -36
  80. package/lib/component/panels/Panels.js +1 -1
  81. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +4 -27
  82. package/lib/component/panels/SpectraPanel/SpectraPreferences.js +13 -1
  83. package/lib/component/panels/SpectraPanel/base/setting/PlotChart.js +1 -1
  84. package/lib/component/panels/SpectraPanel/base/setting/Spectrum2DHistogram.js +1 -1
  85. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentLabelColumn.d.ts +6 -0
  86. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentLabelColumn.js +16 -0
  87. package/lib/component/panels/ZonesPanel/ZonesPanel.js +18 -2
  88. package/lib/component/panels/ZonesPanel/ZonesPreferences.js +15 -9
  89. package/lib/component/panels/ZonesPanel/ZonesTable.js +2 -2
  90. package/lib/component/panels/ZonesPanel/ZonesTableRow.js +3 -2
  91. package/lib/component/panels/databasePanel/DatabaseTable.js +2 -2
  92. package/lib/component/panels/multipleAnalysisPanel/preferences/index.js +1 -1
  93. package/lib/component/reducer/IgnoreActions.js +1 -0
  94. package/lib/component/reducer/Reducer.d.ts +6 -0
  95. package/lib/component/reducer/Reducer.js +6 -0
  96. package/lib/component/reducer/actions/DomainActions.d.ts +12 -4
  97. package/lib/component/reducer/actions/DomainActions.js +35 -5
  98. package/lib/component/reducer/actions/FiltersActions.js +2 -2
  99. package/lib/component/reducer/actions/LoadActions.js +5 -2
  100. package/lib/component/reducer/actions/RangesActions.js +12 -6
  101. package/lib/component/reducer/actions/SpectraActions.d.ts +1 -0
  102. package/lib/component/reducer/actions/SpectraActions.js +7 -2
  103. package/lib/component/reducer/actions/ZonesActions.d.ts +15 -2
  104. package/lib/component/reducer/actions/ZonesActions.js +47 -13
  105. package/lib/component/reducer/helper/setRangesViewProperty.d.ts +1 -0
  106. package/lib/component/reducer/helper/setRangesViewProperty.js +11 -11
  107. package/lib/component/reducer/preferences/actions/addWorkspace.js +4 -23
  108. package/lib/component/reducer/preferences/actions/analyzeSpectra.js +4 -4
  109. package/lib/component/reducer/preferences/actions/initPreferences.js +2 -4
  110. package/lib/component/reducer/preferences/actions/matrixGeneration.d.ts +47 -2
  111. package/lib/component/reducer/preferences/actions/matrixGeneration.js +63 -26
  112. package/lib/component/reducer/preferences/actions/removeWorkspace.js +0 -5
  113. package/lib/component/reducer/preferences/actions/setActiveWorkspace.js +0 -4
  114. package/lib/component/reducer/preferences/actions/setPanelsPreferences.js +1 -1
  115. package/lib/component/reducer/preferences/actions/setPreferences.js +2 -16
  116. package/lib/component/reducer/preferences/panelsPreferencesDefaultValues.d.ts +5 -2
  117. package/lib/component/reducer/preferences/panelsPreferencesDefaultValues.js +17 -1
  118. package/lib/component/reducer/preferences/preferencesReducer.d.ts +9 -25
  119. package/lib/component/reducer/preferences/preferencesReducer.js +28 -19
  120. package/lib/component/toolbar/ToolBar.js +23 -20
  121. package/lib/component/utility/PathBuilder.d.ts +1 -0
  122. package/lib/component/utility/PathBuilder.js +8 -1
  123. package/lib/component/utility/PreferencesHelper.js +5 -4
  124. package/lib/component/utility/export.js +4 -0
  125. package/lib/component/workspaces/assignment.js +0 -1
  126. package/lib/component/workspaces/basic.js +0 -1
  127. package/lib/component/workspaces/embedded.js +0 -1
  128. package/lib/component/workspaces/exercise.js +26 -29
  129. package/lib/component/workspaces/prediction.js +171 -174
  130. package/lib/component/workspaces/process1D.js +0 -1
  131. package/lib/component/workspaces/simulation.js +35 -38
  132. package/lib/component/workspaces/workspaceDefaultProperties.js +9 -11
  133. package/lib/data/types/common/DeepPartial.d.ts +3 -0
  134. package/lib/data/types/common/DeepPartial.js +1 -0
  135. package/lib/versionInfo.js +1 -1
  136. package/package.json +39 -39
  137. package/lib/component/elements/CustomToolTip.d.ts +0 -8
  138. package/lib/component/elements/CustomToolTip.js +0 -107
  139. package/lib/component/modal/setting/settings-tabs/FormattingTabContent.d.ts +0 -2
  140. package/lib/component/modal/setting/settings-tabs/FormattingTabContent.js +0 -80
  141. package/lib/component/reducer/preferences/utilities/mapNucleiFormatting.d.ts +0 -2
  142. package/lib/component/reducer/preferences/utilities/mapNucleiFormatting.js +0 -10
@@ -10,6 +10,8 @@ import XAxis from './XAxis';
10
10
  import DatabaseElements from './database/DatabaseElements';
11
11
  import IntegralsSeries from './integral/IntegralsSeries';
12
12
  import JGraph from './jCouplingGraph/JGraph';
13
+ import { Boxplot } from './matrix/Boxplot';
14
+ import { Stocsy } from './matrix/Stocsy';
13
15
  import MultiAnalysisRanges from './multiAnalysis/MultiAnalysisRanges';
14
16
  import MultiplicityTrees from './multiplicityTree/MultiplicityTrees';
15
17
  import { PeakEditionProvider } from './peaks/PeakEditionManager';
@@ -22,6 +24,6 @@ function Chart1D({ mode, width, height, margin, displayerKey }) {
22
24
  const { current: { general: { spectraRendering }, }, } = usePreferences();
23
25
  const innerWidth = width - margin.left - margin.right;
24
26
  const innerHeight = height - margin.bottom;
25
- return (_jsx(PeakEditionProvider, { children: _jsxs("svg", { id: "nmrSVG", width: width, height: height, viewBox: `0 0 ${width} ${height}`, fontFamily: "Arial, Helvetica, sans-serif", shapeRendering: spectraRendering, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${displayerKey}clip-chart-1d`, children: _jsx("rect", { width: innerWidth, height: innerHeight, x: margin.left, y: "0" }) }) }), _jsx(LinesSeries, {}), _jsx(ApodizationLine, {}), _jsx(IntegralsSeries, {}), _jsx(Peaks, { peaksSource: "peaks" }), _jsx(RangesIntegrals, {}), _jsx(Ranges, {}), _jsx(Peaks, { peaksSource: "ranges" }), _jsx(MultiplicityTrees, {}), _jsx(JGraph, {}), _jsx(MultiAnalysisRanges, {}), _jsx(BaseLineZones, {}), _jsx(ExclusionZonesAnnotations, {}), _jsx(DatabaseElements, {}), _jsx(PeaksShapes, {}), _jsx(SpectraTracker, {}), _jsx(SpectrumInfoBlock, {}), _jsx(SimilarityTree, {}), _jsx("g", { className: "container", style: { pointerEvents: 'none' }, children: _jsx(XAxis, { showGrid: true, mode: mode }) })] }) }));
27
+ return (_jsx(PeakEditionProvider, { children: _jsxs("svg", { id: "nmrSVG", width: width, height: height, viewBox: `0 0 ${width} ${height}`, fontFamily: "Arial, Helvetica, sans-serif", shapeRendering: spectraRendering, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${displayerKey}clip-chart-1d`, children: _jsx("rect", { width: innerWidth, height: innerHeight, x: margin.left, y: "0" }) }) }), _jsx(LinesSeries, {}), _jsx(ApodizationLine, {}), _jsx(IntegralsSeries, {}), _jsx(Peaks, { peaksSource: "peaks" }), _jsx(RangesIntegrals, {}), _jsx(Ranges, {}), _jsx(Peaks, { peaksSource: "ranges" }), _jsx(MultiplicityTrees, {}), _jsx(JGraph, {}), _jsx(MultiAnalysisRanges, {}), _jsx(BaseLineZones, {}), _jsx(ExclusionZonesAnnotations, {}), _jsx(DatabaseElements, {}), _jsx(PeaksShapes, {}), _jsx(Stocsy, {}), _jsx(Boxplot, {}), _jsx(SpectraTracker, {}), _jsx(SpectrumInfoBlock, {}), _jsx(SimilarityTree, {}), _jsx("g", { className: "container", style: { pointerEvents: 'none' }, children: _jsx(XAxis, { showGrid: true, mode: mode }) })] }) }));
26
28
  }
27
29
  export default Chart1D;
@@ -16,6 +16,7 @@ import { useLogger } from '../context/LoggerContext';
16
16
  import { usePreferences } from '../context/PreferencesContext';
17
17
  import { ScaleProvider } from '../context/ScaleContext';
18
18
  import { useActiveSpectrum } from '../hooks/useActiveSpectrum';
19
+ import { usePanelPreferences } from '../hooks/usePanelPreferences';
19
20
  import useSpectrum from '../hooks/useSpectrum';
20
21
  import { useVerticalAlign } from '../hooks/useVerticalAlign';
21
22
  import Spinner from '../loader/Spinner';
@@ -41,6 +42,7 @@ function Viewer1D({ emptyText = undefined }) {
41
42
  const spectrum = useSpectrum();
42
43
  const dispatch = useDispatch();
43
44
  const { dispatch: dispatchPreferences } = usePreferences();
45
+ const { showBoxPlot, showStocsy } = usePanelPreferences('matrixGeneration', activeTab);
44
46
  const { logger } = useLogger();
45
47
  const [scaleState, dispatchScale] = useReducer(scaleReducer, scaleInitialState);
46
48
  useEffect(() => {
@@ -238,8 +240,27 @@ function Viewer1D({ emptyText = undefined }) {
238
240
  });
239
241
  }, [dispatch]);
240
242
  const handleZoom = useCallback((options) => {
241
- dispatch({ type: 'SET_ZOOM', payload: { options } });
242
- }, [dispatch]);
243
+ if ((showBoxPlot || showStocsy) &&
244
+ options.altKey &&
245
+ (selectedTool === 'zoom' ||
246
+ selectedTool === 'matrixGenerationExclusionZones')) {
247
+ //change the matrix generation vertical scale
248
+ dispatchPreferences({
249
+ type: 'CHANGE_MATRIX_GENERATION_SCALE',
250
+ payload: { nucleus: activeTab, zoomOptions: options },
251
+ });
252
+ }
253
+ else {
254
+ dispatch({ type: 'SET_ZOOM', payload: { options } });
255
+ }
256
+ }, [
257
+ activeTab,
258
+ dispatch,
259
+ dispatchPreferences,
260
+ selectedTool,
261
+ showBoxPlot,
262
+ showStocsy,
263
+ ]);
243
264
  const mouseClick = useCallback((event) => {
244
265
  if (!scaleState.scaleX)
245
266
  return;
@@ -252,19 +273,19 @@ function Viewer1D({ emptyText = undefined }) {
252
273
  switch (keyModifiers) {
253
274
  case primaryKeyIdentifier: {
254
275
  switch (selectedTool) {
255
- case options.peakPicking.id:
276
+ case 'peakPicking':
256
277
  dispatch({
257
278
  type: 'ADD_PEAK',
258
279
  payload: event,
259
280
  });
260
281
  break;
261
- case options.integral.id:
282
+ case 'integral':
262
283
  dispatch({
263
284
  type: 'CUT_INTEGRAL',
264
285
  payload: { cutValue: xPPM },
265
286
  });
266
287
  break;
267
- case options.rangePicking.id: {
288
+ case 'rangePicking': {
268
289
  if (!spectrum)
269
290
  break;
270
291
  if (isSpectrum1D(spectrum)) {
@@ -276,12 +297,13 @@ function Viewer1D({ emptyText = undefined }) {
276
297
  }
277
298
  break;
278
299
  }
279
- case options.phaseCorrection.id:
280
- dispatch({
281
- type: 'SET_ONE_DIMENSION_PIVOT_POINT',
282
- payload: {
283
- value: event.x,
284
- },
300
+ case 'zoom':
301
+ case 'matrixGenerationExclusionZones':
302
+ if (!showStocsy || !event.shiftKey)
303
+ break;
304
+ dispatchPreferences({
305
+ type: 'CHANGE_MATRIX_GENERATION_STOCSY_CHEMICAL_SHIFT',
306
+ payload: { nucleus: activeTab, chemicalShift: xPPM },
285
307
  });
286
308
  break;
287
309
  default:
@@ -293,11 +315,14 @@ function Viewer1D({ emptyText = undefined }) {
293
315
  break;
294
316
  }
295
317
  }, [
318
+ activeTab,
296
319
  dispatch,
320
+ dispatchPreferences,
297
321
  getModifiersKey,
298
322
  primaryKeyIdentifier,
299
323
  scaleState,
300
324
  selectedTool,
325
+ showStocsy,
301
326
  spectrum,
302
327
  ]);
303
328
  return (_jsxs(ScaleProvider, { value: scaleState, children: [_jsx(ResponsiveChart, { children: ({ height, width }) => (_jsx(ViewerResponsiveWrapper, { height: height, width: width, children: _jsxs("div", { style: { height: '100%', position: 'relative' }, children: [_jsx(Spinner, { isLoading: isLoading, emptyText: emptyText }), scaleState.scaleX &&
@@ -54,7 +54,7 @@ function XAxis(props) {
54
54
  .tickFormat(() => '');
55
55
  // @ts-expect-error This line of code is actually well typed ...
56
56
  d3.select(refAxis.current).call(xAxis);
57
- // @ts-expect-error ditto
57
+ // @ts-expect-error This line of code is actually well typed ...
58
58
  d3.select(refGrid.current).call(grid);
59
59
  }, [height, margin.bottom, margin.top, scaleX, show, xDomain]);
60
60
  if (!width || !height || !scaleX) {
@@ -5,11 +5,11 @@ import useSpectrum from '../../hooks/useSpectrum';
5
5
  import { Integration } from './Integration';
6
6
  const emptyData = { integrals: {}, info: {}, display: {} };
7
7
  export default function IntegralsSeries() {
8
- const { displayerKey, view: { spectra: { activeTab: nucleus }, }, } = useChartData();
8
+ const { displayerKey, view: { spectra: { activeTab: nucleus }, }, xDomain: [from, to], } = useChartData();
9
9
  const integrals = useIntegrals();
10
10
  if (!integrals)
11
11
  return null;
12
- return (_jsx("g", { clipPath: `url(#${displayerKey}clip-chart-1d)`, className: "integrals", children: integrals.values.map((integral) => (_jsx(Integration, { nucleus: nucleus, integral: integral, max: integrals.max }, integral.id))) }));
12
+ return (_jsx("g", { clipPath: `url(#${displayerKey}clip-chart-1d)`, className: "integrals", children: integrals.values.map((integral) => (_jsx(Integration, { nucleus: nucleus, integral: integral, max: integrals.max, from, to }, integral.id))) }));
13
13
  }
14
14
  function useIntegrals() {
15
15
  const spectrum = useSpectrum(emptyData);
@@ -3,6 +3,8 @@ interface IntegralProps {
3
3
  integral: IntegralData;
4
4
  nucleus: string;
5
5
  max: number;
6
+ from: number;
7
+ to: number;
6
8
  }
7
- export declare function Integration({ integral, nucleus, max }: IntegralProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function Integration(props: IntegralProps): import("react/jsx-runtime").JSX.Element;
8
10
  export {};
@@ -3,10 +3,11 @@ import { useActiveSpectrumIntegralsViewState } from '../../hooks/useActiveSpectr
3
3
  import useIntegralPath from '../../hooks/useIntegralPath';
4
4
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
5
5
  import IntegralResizable from './IntegralResizable';
6
- export function Integration({ integral, nucleus, max }) {
6
+ export function Integration(props) {
7
+ const { integral, nucleus, max, from, to } = props;
7
8
  const { x, y } = integral;
8
9
  const { scaleRatio } = useActiveSpectrumIntegralsViewState();
9
- const path = useIntegralPath({ x, y, max, scaleRatio });
10
+ const path = useIntegralPath({ x, y, max, scaleRatio, from, to });
10
11
  const { showIntegralsValues } = useActiveSpectrumIntegralsViewState();
11
12
  const integralPreferences = usePanelPreferences('integrals', nucleus);
12
13
  return (_jsxs("g", { children: [_jsx("path", { className: "line", stroke: integralPreferences.color, strokeWidth: integralPreferences.strokeWidth, fill: "none", d: path }), showIntegralsValues && (_jsx(IntegralResizable, { integralData: integral, integralFormat: integralPreferences.relative.format }))] }));
@@ -0,0 +1,6 @@
1
+ interface InnerBoxplotProps {
2
+ scaleRatio: number;
3
+ }
4
+ export declare function Boxplot(): import("react/jsx-runtime").JSX.Element | null | undefined;
5
+ export declare function InnerBoxplot(props: InnerBoxplotProps): import("react/jsx-runtime").JSX.Element | null;
6
+ export {};
@@ -0,0 +1,97 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { extent } from 'd3';
3
+ import { xFindClosestIndex } from 'ml-spectra-processing';
4
+ import { matrixToBoxPlot } from 'nmr-processing';
5
+ import { useMemo } from 'react';
6
+ import { useChartData } from '../../context/ChartContext';
7
+ import { useScaleChecked } from '../../context/ScaleContext';
8
+ import { usePanelPreferences } from '../../hooks/usePanelPreferences';
9
+ import { PathBuilder } from '../../utility/PathBuilder';
10
+ import { getYScaleWithRation } from '../utilities/scale';
11
+ import { sliceArrayForDomain, useMatrix } from './useMatrix';
12
+ function useYScale(scaleRatio, yDomain) {
13
+ const { margin, height } = useChartData();
14
+ return getYScaleWithRation({
15
+ height,
16
+ yDomain,
17
+ scaleRatio,
18
+ margin,
19
+ });
20
+ }
21
+ function usePath(pathPoints, scaleRatio, yDomain) {
22
+ const { scaleX } = useScaleChecked();
23
+ const scaleY = useYScale(scaleRatio, yDomain);
24
+ const pathBuilder = new PathBuilder();
25
+ const xScaler = scaleX();
26
+ pathBuilder.moveTo(xScaler(pathPoints.x[0]), scaleY(pathPoints.y[0]));
27
+ for (let i = 1; i < pathPoints.x.length; i++) {
28
+ pathBuilder.lineTo(xScaler(pathPoints.x[i]), scaleY(pathPoints.y[i]));
29
+ }
30
+ return pathBuilder.toString();
31
+ }
32
+ function useAreaPath(pathPoints, scaleRatio, yDomain) {
33
+ const { scaleX } = useScaleChecked();
34
+ const scaleY = useYScale(scaleRatio, yDomain);
35
+ const pathBuilder = new PathBuilder();
36
+ const pathBuilder2 = new PathBuilder();
37
+ const xScaler = scaleX();
38
+ pathBuilder.moveTo(xScaler(pathPoints.x[0]), scaleY(pathPoints.y1[0]));
39
+ for (let i = 1; i < pathPoints.x.length; i++) {
40
+ pathBuilder.lineTo(xScaler(pathPoints.x[i]), scaleY(pathPoints.y1[i]));
41
+ }
42
+ for (let i = pathPoints.x.length - 1; i >= 0; i--) {
43
+ pathBuilder2.lineTo(xScaler(pathPoints.x[i]), scaleY(pathPoints.y2[i]));
44
+ }
45
+ return pathBuilder.concatPath(pathBuilder2);
46
+ }
47
+ function useBoxPlot() {
48
+ const matrix = useMatrix();
49
+ const { xDomain: [from, to], } = useChartData();
50
+ return useMemo(() => {
51
+ if (!matrix)
52
+ return null;
53
+ const { x, matrixY } = matrix;
54
+ const { max, min, median, q1, q3 } = matrixToBoxPlot(matrixY);
55
+ const fromIndex = xFindClosestIndex(x, from);
56
+ const toIndex = xFindClosestIndex(x, to);
57
+ const yDomain = extent(median);
58
+ return {
59
+ x: sliceArrayForDomain(x, { fromIndex, toIndex }),
60
+ max: sliceArrayForDomain(max, { fromIndex, toIndex }),
61
+ min: sliceArrayForDomain(min, { fromIndex, toIndex }),
62
+ median: sliceArrayForDomain(median, { fromIndex, toIndex }),
63
+ q1: sliceArrayForDomain(q1, { fromIndex, toIndex }),
64
+ q3: sliceArrayForDomain(q3, { fromIndex, toIndex }),
65
+ yDomain,
66
+ };
67
+ }, [from, matrix, to]);
68
+ }
69
+ export function Boxplot() {
70
+ const { view: { spectra: { activeTab }, }, } = useChartData();
71
+ const options = usePanelPreferences('matrixGeneration', activeTab);
72
+ if (!options)
73
+ return;
74
+ const { scaleRatio, showBoxPlot } = options;
75
+ if (!showBoxPlot)
76
+ return null;
77
+ return _jsx(InnerBoxplot, { scaleRatio: scaleRatio });
78
+ }
79
+ export function InnerBoxplot(props) {
80
+ const { scaleRatio } = props;
81
+ const data = useBoxPlot();
82
+ const { displayerKey } = useChartData();
83
+ if (!data)
84
+ return null;
85
+ const { x, max, min, median, q1, q3, yDomain } = data;
86
+ return (_jsxs("g", { clipPath: `url(#${displayerKey}clip-chart-1d)`, children: [_jsx(RenderAreaPath, { x: x, y1: max, y2: min, color: "black", scaleRatio: scaleRatio, yDomain: yDomain }), _jsx(RenderAreaPath, { x: x, y1: q3, y2: q1, color: "black", scaleRatio: scaleRatio, yDomain: yDomain }), _jsx(RenderPath, { x: x, y: median, color: "black", scaleRatio: scaleRatio, yDomain: yDomain })] }));
87
+ }
88
+ function RenderAreaPath(props) {
89
+ const { x, y1, y2, scaleRatio, color, yDomain } = props;
90
+ const areaPath = useAreaPath({ x, y1, y2 }, scaleRatio, yDomain);
91
+ return _jsx("path", { d: areaPath, fill: color, opacity: 0.2 });
92
+ }
93
+ function RenderPath(props) {
94
+ const { x, y, scaleRatio, color, yDomain } = props;
95
+ const areaPath = usePath({ x, y }, scaleRatio, yDomain);
96
+ return _jsx("path", { d: areaPath, fill: "transparent", stroke: color });
97
+ }
@@ -0,0 +1,5 @@
1
+ export declare function Stocsy(): import("react/jsx-runtime").JSX.Element | null | undefined;
2
+ export declare function InnerStocsy({ scaleRatio, chemicalShift }: {
3
+ scaleRatio: any;
4
+ chemicalShift: any;
5
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { extent } from 'd3';
3
+ import { xFindClosestIndex } from 'ml-spectra-processing';
4
+ import { matrixToStocsy } from 'nmr-processing';
5
+ import { useMemo } from 'react';
6
+ import { useChartData } from '../../context/ChartContext';
7
+ import { useScaleChecked } from '../../context/ScaleContext';
8
+ import { usePanelPreferences } from '../../hooks/usePanelPreferences';
9
+ import { PathBuilder } from '../../utility/PathBuilder';
10
+ import { getYScaleWithRation } from '../utilities/scale';
11
+ import { sliceArrayForDomain, groupPointsByColor, useMatrix, } from './useMatrix';
12
+ function useStocsy(chemicalShift) {
13
+ const matrix = useMatrix();
14
+ return useMemo(() => {
15
+ if (!matrix)
16
+ return null;
17
+ const { x, matrixY } = matrix;
18
+ const cIndex = xFindClosestIndex(x, chemicalShift ?? x[0]);
19
+ const { color, y } = matrixToStocsy(matrixY, cIndex);
20
+ const yDomain = extent(y);
21
+ return {
22
+ color,
23
+ y,
24
+ yDomain,
25
+ x,
26
+ };
27
+ }, [chemicalShift, matrix]);
28
+ }
29
+ function useSliceStocsyData(options) {
30
+ const { xDomain: [from, to], } = useChartData();
31
+ return useMemo(() => {
32
+ if (!options)
33
+ return null;
34
+ const { color, y, x } = options;
35
+ const fromIndex = xFindClosestIndex(x, from);
36
+ const toIndex = xFindClosestIndex(x, to);
37
+ return {
38
+ x: sliceArrayForDomain(x, { fromIndex, toIndex }),
39
+ y: sliceArrayForDomain(y, { fromIndex, toIndex }),
40
+ color: sliceArrayForDomain(color, { fromIndex, toIndex }),
41
+ };
42
+ }, [from, options, to]);
43
+ }
44
+ export function Stocsy() {
45
+ const { view: { spectra: { activeTab }, }, } = useChartData();
46
+ const options = usePanelPreferences('matrixGeneration', activeTab);
47
+ if (!options)
48
+ return;
49
+ const { scaleRatio, showStocsy, chemicalShift } = options;
50
+ if (!showStocsy)
51
+ return null;
52
+ return _jsx(InnerStocsy, { scaleRatio: scaleRatio, chemicalShift: chemicalShift });
53
+ }
54
+ export function InnerStocsy({ scaleRatio, chemicalShift }) {
55
+ const stocsyData = useStocsy(chemicalShift);
56
+ const data = useSliceStocsyData(stocsyData);
57
+ const { displayerKey } = useChartData();
58
+ if (!data || !stocsyData)
59
+ return null;
60
+ const { yDomain } = stocsyData;
61
+ const { x, y, color } = data;
62
+ return (_jsxs("g", { clipPath: `url(#${displayerKey}clip-chart-1d)`, children: [_jsx(StocsyIndexPoint, { chemicalShift: chemicalShift }), _jsx(RenderStocsyAsSVG, { x: x, y: y, color: color, scaleRatio: scaleRatio, yDomain: yDomain })] }));
63
+ }
64
+ function useYScale(scaleRatio, yDomain) {
65
+ const { margin, height } = useChartData();
66
+ return getYScaleWithRation({
67
+ height,
68
+ yDomain,
69
+ scaleRatio,
70
+ margin,
71
+ });
72
+ }
73
+ function StocsyIndexPoint(props) {
74
+ const { chemicalShift } = props;
75
+ const { scaleX } = useScaleChecked();
76
+ const { xDomain: [from, to], } = useChartData();
77
+ if (!chemicalShift || chemicalShift < from || chemicalShift > to)
78
+ return null;
79
+ const xPixel = scaleX()(chemicalShift);
80
+ return (_jsx("g", { transform: `translate(${xPixel} 0)`, children: _jsx("line", { x1: -0.5, y1: 0, x2: -0.5, y2: "100%", stroke: "red", strokeDasharray: "5 2" }) }));
81
+ }
82
+ function RenderStocsyAsSVG(props) {
83
+ const { x, y, color, scaleRatio, yDomain } = props;
84
+ const scaleY = useYScale(scaleRatio, yDomain);
85
+ const { scaleX } = useScaleChecked();
86
+ const colorGroups = groupPointsByColor({ x, y, color });
87
+ const xScaler = scaleX();
88
+ return Object.keys(colorGroups).map((color) => {
89
+ const points = colorGroups[color];
90
+ const pathBuilder = new PathBuilder();
91
+ pathBuilder.moveTo(xScaler(points[0].x), scaleY(points[0].y));
92
+ for (let i = 1; i < points.length; i++) {
93
+ const point = points[i];
94
+ pathBuilder.lineTo(xScaler(points[i].x), scaleY(points[i].y));
95
+ if (point.endPath && i < points.length - 1) {
96
+ pathBuilder.moveTo(xScaler(points[i + 1].x), scaleY(points[i + 1].y));
97
+ }
98
+ }
99
+ return (_jsx("path", { d: pathBuilder.toString(), stroke: color, fill: "transparent" }, color));
100
+ });
101
+ }
@@ -0,0 +1,29 @@
1
+ import { NumberArray } from 'cheminfo-types';
2
+ /**
3
+ * This method will slice the array from the fromIndex to the toIndex and add the first and last element of the original array
4
+ * if needed
5
+ * It will also add one extra point at the beginning or the end if the fromIndex or toIndex is not the first or the last point of the array
6
+ *
7
+ * @param array
8
+ * @param options
9
+ * @returns
10
+ */
11
+ export declare function sliceArrayForDomain<T extends string[] | NumberArray>(array: T, options: {
12
+ fromIndex: number;
13
+ toIndex: number;
14
+ }): T;
15
+ export declare function useMatrix(): {
16
+ x: Float64Array | never[];
17
+ matrixY: Float64Array[];
18
+ } | null;
19
+ interface InterpolateColorsPointsOptions {
20
+ x: Float64Array | number[];
21
+ y: number[];
22
+ color: string[];
23
+ }
24
+ export declare function groupPointsByColor(data: InterpolateColorsPointsOptions): Record<string, {
25
+ x: number;
26
+ y: number;
27
+ endPath: boolean;
28
+ }[]>;
29
+ export {};
@@ -0,0 +1,93 @@
1
+ import { Filters } from 'nmr-processing';
2
+ import { useMemo } from 'react';
3
+ import { isSpectrum1D } from '../../../data/data1d/Spectrum1D';
4
+ import { useChartData } from '../../context/ChartContext';
5
+ import useSpectraByActiveNucleus from '../../hooks/useSpectraPerNucleus';
6
+ const { signalProcessing } = Filters;
7
+ /**
8
+ * This method will slice the array from the fromIndex to the toIndex and add the first and last element of the original array
9
+ * if needed
10
+ * It will also add one extra point at the beginning or the end if the fromIndex or toIndex is not the first or the last point of the array
11
+ *
12
+ * @param array
13
+ * @param options
14
+ * @returns
15
+ */
16
+ export function sliceArrayForDomain(array, options) {
17
+ let { fromIndex, toIndex } = options;
18
+ if (fromIndex > 0)
19
+ fromIndex--;
20
+ if (toIndex < array.length)
21
+ toIndex++;
22
+ // because slice does not include the last index we need to add one
23
+ if (toIndex < array.length)
24
+ toIndex++;
25
+ if (fromIndex > 0 || toIndex < array.length) {
26
+ return array.slice(fromIndex, toIndex);
27
+ }
28
+ return array;
29
+ }
30
+ function getX(spectra) {
31
+ const spectrum = spectra?.[0];
32
+ if (!spectrum || !isSpectrum1D(spectrum))
33
+ return [];
34
+ return spectrum.data.x;
35
+ }
36
+ export function useMatrix() {
37
+ const { displayerMode } = useChartData();
38
+ const spectra = useSpectraByActiveNucleus();
39
+ return useMemo(() => {
40
+ if (displayerMode !== '1D')
41
+ return null;
42
+ const matrixY = [];
43
+ for (let i = 0; i < spectra.length; i++) {
44
+ const spectrum = spectra[i];
45
+ const filter = spectrum.filters.find((filter) => filter.name === signalProcessing.id);
46
+ if (isSpectrum1D(spectrum) && filter?.flag) {
47
+ matrixY[i] = spectrum.data.re;
48
+ }
49
+ }
50
+ if (matrixY.length === 0)
51
+ return null;
52
+ return {
53
+ x: getX(spectra) || [],
54
+ matrixY,
55
+ };
56
+ }, [displayerMode, spectra]);
57
+ }
58
+ export function groupPointsByColor(data) {
59
+ const groups = {};
60
+ for (let i = 0; i < data.color.length - 1; i++) {
61
+ const color = data.color[i];
62
+ const x1 = data.x[i];
63
+ const y1 = data.y[i];
64
+ const nextColor = data.color[i + 1];
65
+ const x2 = data.x[i + 1];
66
+ const y2 = data.y[i + 1];
67
+ // add the original point
68
+ if (!groups[color])
69
+ groups[color] = [];
70
+ groups[color].push({ x: x1, y: y1, endPath: false });
71
+ // If the next point has a different color, add a segment with that color
72
+ if (color !== nextColor) {
73
+ // add the interpolated point
74
+ const interpolatedX = (x1 + x2) / 2;
75
+ const interpolatedY = (y1 + y2) / 2;
76
+ groups[color].push({ x: interpolatedX, y: interpolatedY, endPath: true });
77
+ if (!groups[nextColor])
78
+ groups[nextColor] = [];
79
+ groups[nextColor].push({
80
+ x: interpolatedX,
81
+ y: interpolatedY,
82
+ endPath: false,
83
+ });
84
+ }
85
+ }
86
+ // Add the last original point
87
+ const lastIndex = data.x.length - 1;
88
+ const lastColor = data.color[lastIndex];
89
+ const lastX = data.x[lastIndex];
90
+ const lastY = data.y[lastIndex];
91
+ groups[lastColor].push({ x: lastX, y: lastY, endPath: true });
92
+ return groups;
93
+ }
@@ -12,7 +12,9 @@ const validationSchema = Yup.object({
12
12
  });
13
13
  const InputDimension = { height: 28, width: 100 };
14
14
  const peaksEditionContext = {
15
- onEdit: () => { },
15
+ onEdit: () => {
16
+ // Empty default.
17
+ },
16
18
  };
17
19
  const PeaksEditionContext = createContext(peaksEditionContext);
18
20
  function usePeaksEditionManager() {
@@ -59,9 +61,9 @@ export function PeakEditionProvider({ children }) {
59
61
  setPeak(null);
60
62
  }
61
63
  }, []);
62
- const editiionManagerState = useMemo(() => ({ onEdit: handleOnEdit, id: peak?.id }), [peak?.id, handleOnEdit]);
64
+ const editionManagerState = useMemo(() => ({ onEdit: handleOnEdit, id: peak?.id }), [peak?.id, handleOnEdit]);
63
65
  const { x, y } = getPosition();
64
- return (_jsx(PeaksEditionContext.Provider, { value: editiionManagerState, children: _jsxs("div", { onClick: () => setPeak(null), onContextMenu: () => setPeak(null), style: { position: 'relative' }, children: [peak && (_jsx("div", { style: {
66
+ return (_jsx(PeaksEditionContext.Provider, { value: editionManagerState, children: _jsxs("div", { onClick: () => setPeak(null), onContextMenu: () => setPeak(null), style: { position: 'relative' }, children: [peak && (_jsx("div", { style: {
65
67
  position: 'absolute',
66
68
  display: 'block',
67
69
  transform: `translate(${x}px,${y}px)`,
@@ -6,5 +6,6 @@ export interface AssignmentActionsButtonsProps extends Omit<ButtonProps, 'childr
6
6
  className?: string;
7
7
  onAssign: ButtonProps['onClick'];
8
8
  onUnAssign: ButtonProps['onClick'];
9
+ onAddAssignmentLabel?: ButtonProps['onClick'];
9
10
  }
10
11
  export declare function AssignmentActionsButtons(props: AssignmentActionsButtonsProps): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FaLink, FaMinus } from 'react-icons/fa';
2
+ import { LuLink, LuUnlink } from 'react-icons/lu';
3
3
  import Button from '../../elements/Button';
4
4
  const styles = {
5
5
  button: { width: '16px', height: '16px', padding: 0 },
6
6
  icon: { fontSize: 9, margin: 'auto' },
7
7
  };
8
8
  export function AssignmentActionsButtons(props) {
9
- const { isActive, onAssign, onUnAssign, x = 0, y = 5, className = 'target', ...otherProps } = props;
10
- return (_jsxs("foreignObject", { width: "16px", height: "34px", x: x, y: y, className: className, "data-no-export": "true", children: [_jsx(Button, { theme: "success", style: styles.button, onClick: onAssign, ...otherProps, children: _jsx(FaLink, { style: styles.icon }) }), isActive && (_jsx(Button, { theme: "danger", style: { ...styles.button, marginTop: '2px' }, onClick: onUnAssign, ...otherProps, children: _jsx(FaMinus, { style: styles.icon }) }))] }));
9
+ const { isActive, onAssign, onUnAssign, onAddAssignmentLabel, x = 0, y = 5, className = 'target', ...otherProps } = props;
10
+ return (_jsxs("foreignObject", { width: "16px", height: "52px", x: x - 16, y: y, className: className, "data-no-export": "true", children: [_jsx(Button, { theme: "success", style: styles.button, onClick: onAssign, ...otherProps, children: _jsx(LuLink, { style: styles.icon }) }), isActive && (_jsx(Button, { theme: "danger", style: { ...styles.button, marginTop: '2px' }, onClick: onUnAssign, ...otherProps, children: _jsx(LuUnlink, { style: styles.icon }) }))] }));
11
11
  }
@@ -1,7 +1,7 @@
1
1
  import { Range } from 'nmr-processing';
2
2
  interface AssignmentLabelProps {
3
3
  range: Range;
4
- x: number;
4
+ width: number;
5
5
  }
6
6
  export declare function AssignmentLabel(props: AssignmentLabelProps): import("react/jsx-runtime").JSX.Element | null;
7
7
  export {};
@@ -1,10 +1,37 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useRef } from 'react';
3
+ import { FieldEdition } from '../../1d-2d/FieldEdition';
4
+ import { useChartData } from '../../context/ChartContext';
5
+ import { useDispatch } from '../../context/DispatchContext';
2
6
  import { useActiveSpectrumRangesViewState } from '../../hooks/useActiveSpectrumRangesViewState';
3
- const marginTop = 55;
7
+ import { useTriggerNewAssignmentLabel } from '../../hooks/useTriggerNewAssignmentLabel';
8
+ const marginTop = 15;
4
9
  export function AssignmentLabel(props) {
5
- const { range, x } = props;
10
+ const { range, width } = props;
11
+ const { id, assignment } = range;
6
12
  const { showAssignmentsLabels } = useActiveSpectrumRangesViewState();
7
- if (!range.assignment || !showAssignmentsLabels)
13
+ const dispatch = useDispatch();
14
+ const textRef = useRef(null);
15
+ const { margin } = useChartData();
16
+ const { isNewAssignment, dismissNewLabel } = useTriggerNewAssignmentLabel(id);
17
+ if ((!range.assignment || !showAssignmentsLabels) && !isNewAssignment) {
8
18
  return null;
9
- return (_jsx("text", { x: x - 5, y: marginTop, fontSize: "12px", fill: "black", textAnchor: "end", children: range.assignment }));
19
+ }
20
+ function handleChange(value) {
21
+ dismissNewLabel();
22
+ dispatch({
23
+ type: 'CHANGE_RANGE_ASSIGNMENT_LABEL',
24
+ payload: {
25
+ value,
26
+ rangeID: id,
27
+ },
28
+ });
29
+ }
30
+ return (_jsx("g", { transform: `translate(${width / 2} ${margin?.top + marginTop})`, children: _jsx(FieldEdition, { onChange: handleChange, inputType: "text", value: assignment || '', PopoverProps: {
31
+ position: 'bottom',
32
+ targetTagName: 'g',
33
+ ...(isNewAssignment
34
+ ? { isOpen: true, onClose: () => dismissNewLabel() }
35
+ : {}),
36
+ }, children: _jsx("text", { ref: textRef, textAnchor: "middle", fill: "black", style: { cursor: 'hand' }, width: width, children: assignment }) }) }));
10
37
  }
@@ -1,9 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useChartData } from '../../context/ChartContext';
3
3
  import { useTopicMolecule } from '../../context/TopicMoleculeContext';
4
+ import { SVGGroup } from '../../elements/SVGGroup';
5
+ import { SVGText } from '../../elements/SVGText';
4
6
  const fontSize = 12;
5
- const lineHeight = fontSize * 1.1;
6
- const marginTop = 55;
7
+ const marginTop = 45;
7
8
  function getDiaIds(range) {
8
9
  const { diaIDs = [], signals } = range;
9
10
  const ids = diaIDs.slice();
@@ -37,7 +38,5 @@ export function Atoms(props) {
37
38
  const { range, x } = props;
38
39
  const { view: { molecules }, } = useChartData();
39
40
  const atomsList = useAtoms(range).filter((atomsList) => molecules?.[atomsList.id]?.showAtomNumber);
40
- return (_jsx("g", { transform: `translate(${x},${marginTop})`, children: atomsList.map((row, rowIndex) => (
41
- // eslint-disable-next-line react/no-array-index-key
42
- _jsx("g", { transform: `translate(${rowIndex * lineHeight}, 0)`, children: row.atoms.map((item, colIndex) => (_jsx("text", { x: 0, y: colIndex * lineHeight, fontSize: fontSize, fill: "black", children: item }, colIndex))) }, rowIndex))) }));
41
+ return (_jsx(SVGGroup, { direction: "column", transform: `translate(${x},${marginTop})`, space: 5, children: atomsList.map((row) => (_jsx(SVGText, { x: 0, fontSize: fontSize, borderRadius: 5, padding: 2, rectProps: { fill: 'white', stroke: 'black', strokeWidth: 0.5 }, children: row.atoms.join(',') }, range.id + row.atoms.join(',')))) }));
43
42
  }