nmrium 0.47.0 → 0.49.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.
- package/lib/component/1d/Chart1D.js +1 -1
- package/lib/component/1d/Line.js +1 -1
- package/lib/component/1d/LinesSeries.d.ts +1 -1
- package/lib/component/1d/LinesSeries.js +24 -3
- package/lib/component/1d/SpectraLegends.js +1 -1
- package/lib/component/1d/Viewer1D.js +144 -124
- package/lib/component/1d/jCouplingGraph/JsCoupling.js +1 -1
- package/lib/component/1d/peaks/Peaks.js +5 -4
- package/lib/component/1d/ranges/Atoms.d.ts +7 -0
- package/lib/component/1d/ranges/Atoms.js +43 -0
- package/lib/component/1d/ranges/Range.js +4 -2
- package/lib/component/1d/tool/BaseLine.d.ts +2 -0
- package/lib/component/1d/tool/BaseLine.js +26 -0
- package/lib/component/1d/tool/BaseLineZones.js +18 -3
- package/lib/component/1d/utilities/scale.d.ts +1 -0
- package/lib/component/1d/utilities/scale.js +2 -1
- package/lib/component/2d/Chart2D.js +6 -4
- package/lib/component/2d/Viewer2D.js +35 -26
- package/lib/component/context/KeyModifierContext.d.ts +14 -3
- package/lib/component/context/KeyModifierContext.js +35 -4
- package/lib/component/context/LoggerContext.d.ts +9 -0
- package/lib/component/context/LoggerContext.js +21 -7
- package/lib/component/context/PreferencesContext.d.ts +1 -108
- package/lib/component/context/TopicMoleculeContext.d.ts +8 -0
- package/lib/component/context/TopicMoleculeContext.js +30 -0
- package/lib/component/elements/Input.js +4 -1
- package/lib/component/elements/ResizerWithScale.js +19 -2
- package/lib/component/elements/SVGGroup.js +2 -2
- package/lib/component/elements/formik/FormikTextarea.js +8 -9
- package/lib/component/elements/linearAxis/LinearVerticalAxis.js +1 -1
- package/lib/component/elements/resizer/SVGResizer.js +1 -1
- package/lib/component/header/BaseLineCorrectionPanel.js +3 -2
- package/lib/component/header/Header.js +2 -2
- package/lib/component/hooks/useCheckToolsVisibility.js +1 -1
- package/lib/component/hooks/useExport.js +2 -2
- package/lib/component/hooks/useSetActiveSpectrumAction.d.ts +3 -0
- package/lib/component/hooks/useSetActiveSpectrumAction.js +16 -0
- package/lib/component/hooks/useToolsFunctions.js +4 -2
- package/lib/component/hooks/useVerticalAlign.d.ts +1 -1
- package/lib/component/main/InnerNMRium.js +3 -2
- package/lib/component/modal/ExportAsJcampModal.js +1 -1
- package/lib/component/modal/ImportPublicationStringModal.d.ts +2 -1
- package/lib/component/modal/ImportPublicationStringModal.js +76 -32
- package/lib/component/modal/editRange/forms/validation/EditRangeValidation.js +2 -4
- package/lib/component/modal/setting/settings-tabs/GeneralTabContent.js +9 -11
- package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +2 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts +2 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +6 -5
- package/lib/component/panels/RangesPanel/RangesTable.js +1 -1
- package/lib/component/panels/SpectrumsPanel/SpectraPreferences.js +39 -5
- package/lib/component/panels/SpectrumsPanel/SpectraTable.js +28 -40
- package/lib/component/panels/SpectrumsPanel/SpectrumListPanel.js +4 -2
- package/lib/component/panels/SpectrumsPanel/SpectrumsTabs.js +3 -9
- package/lib/component/panels/SpectrumsPanel/base/RenderAsHTML.d.ts +7 -0
- package/lib/component/panels/SpectrumsPanel/base/RenderAsHTML.js +21 -0
- package/lib/component/panels/SpectrumsPanel/base/SpectraColumnsManager.js +19 -16
- package/lib/component/panels/SpectrumsPanel/base/SpectrumName.js +0 -1
- package/lib/component/panels/databasePanel/DatabasePanel.js +6 -1
- package/lib/component/panels/multipleAnalysisPanel/AnalysisChart.js +1 -1
- package/lib/component/panels/predictionPanel/PredictionPanel.js +3 -1
- package/lib/component/panels/spectrumSimulation/SpectrumSimulation.js +15 -4
- package/lib/component/reducer/Reducer.js +2 -0
- package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
- package/lib/component/reducer/actions/DomainActions.js +2 -2
- package/lib/component/reducer/actions/FiltersActions.d.ts +3 -4
- package/lib/component/reducer/actions/FiltersActions.js +93 -57
- package/lib/component/reducer/actions/LoadActions.js +10 -8
- package/lib/component/reducer/actions/SpectrumsActions.d.ts +8 -1
- package/lib/component/reducer/actions/SpectrumsActions.js +8 -4
- package/lib/component/reducer/actions/ToolsActions.d.ts +8 -5
- package/lib/component/reducer/actions/ToolsActions.js +51 -44
- package/lib/component/reducer/helper/getVerticalAlign.d.ts +1 -1
- package/lib/component/reducer/preferences/panelsPreferencesDefaultValues.js +0 -4
- package/lib/component/toolbar/BasicToolBar.js +11 -29
- package/lib/component/utility/export.d.ts +3 -2
- package/lib/component/utility/export.js +45 -26
- package/lib/component/workspaces/exercise.js +1 -0
- package/lib/component/workspaces/prediction.js +1 -16
- package/lib/component/workspaces/simulation.js +1 -2
- package/lib/component/workspaces/workspaceDefaultProperties.js +4 -3
- package/lib/data/data1d/Spectrum1D/index.d.ts +0 -1
- package/lib/data/data1d/Spectrum1D/index.js +0 -1
- package/lib/data/data1d/multipleSpectraAnalysis.js +27 -40
- package/lib/data/data2d/Spectrum2D/getMissingProjection.js +10 -1
- package/lib/versionInfo.js +1 -1
- package/package.json +31 -30
- package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.d.ts +0 -2
- package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.js +0 -6
|
@@ -4,10 +4,10 @@ import { css } from '@emotion/react';
|
|
|
4
4
|
import { useState, useMemo, memo, useCallback } from 'react';
|
|
5
5
|
import { useChartData } from '../../context/ChartContext';
|
|
6
6
|
import { useDispatch } from '../../context/DispatchContext';
|
|
7
|
-
import { getModifiers } from '../../context/KeyModifierContext';
|
|
8
7
|
import IsotopesViewer from '../../elements/IsotopesViewer';
|
|
9
8
|
import Tab from '../../elements/Tab/Tab';
|
|
10
9
|
import Tabs from '../../elements/Tab/Tabs';
|
|
10
|
+
import { useSetActiveSpectrumAction } from '../../hooks/useSetActiveSpectrumAction';
|
|
11
11
|
import groupByInfoKey from '../../utility/GroupByInfoKey';
|
|
12
12
|
import { SpectraTable } from './SpectraTable';
|
|
13
13
|
import SpectrumSetting from './base/setting/SpectrumSetting';
|
|
@@ -22,6 +22,7 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
22
22
|
const groupByNucleus = groupByInfoKey('nucleus');
|
|
23
23
|
return groupByNucleus(data, true);
|
|
24
24
|
}, [data]);
|
|
25
|
+
const { setActiveSpectrum } = useSetActiveSpectrumAction();
|
|
25
26
|
function onTabChangeHandler(tab) {
|
|
26
27
|
dispatch({ type: 'SET_ACTIVE_TAB', payload: { tab: tab.tabid } });
|
|
27
28
|
}
|
|
@@ -44,14 +45,7 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
44
45
|
});
|
|
45
46
|
}, [dispatch]);
|
|
46
47
|
function handleChangeActiveSpectrum(e, spectrum) {
|
|
47
|
-
|
|
48
|
-
const { ctrlKey, shiftKey } = getModifiers(e);
|
|
49
|
-
const modifier = `shift[${shiftKey ? 'true' : 'false'}]_ctrl[${ctrlKey ? 'true' : 'false'}]`;
|
|
50
|
-
dispatch({
|
|
51
|
-
type: 'CHANGE_ACTIVE_SPECTRUM',
|
|
52
|
-
payload: { modifier, id: spectrum.id },
|
|
53
|
-
});
|
|
54
|
-
}, 0);
|
|
48
|
+
setActiveSpectrum(e, spectrum.id);
|
|
55
49
|
}
|
|
56
50
|
function mouseLeaveHandler() {
|
|
57
51
|
setIsSettingModalDisplayed(false);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import lodashGet from 'lodash/get';
|
|
3
|
+
function formatValueAsHTML(value) {
|
|
4
|
+
if (value) {
|
|
5
|
+
value = value.replaceAll(/(?<value>\d+)/g, '<sub>$<value></sub>');
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function RenderAsHTML(props) {
|
|
10
|
+
const { data, jpath } = props;
|
|
11
|
+
const value = lodashGet(data, jpath);
|
|
12
|
+
if (!value) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return (_jsx("div", {
|
|
16
|
+
// style={styles.info}
|
|
17
|
+
// eslint-disable-next-line react/no-danger
|
|
18
|
+
dangerouslySetInnerHTML: {
|
|
19
|
+
__html: formatValueAsHTML(value),
|
|
20
|
+
} }));
|
|
21
|
+
}
|
|
@@ -6,14 +6,18 @@ import Button from '../../../elements/Button';
|
|
|
6
6
|
import { CheckBoxCell } from '../../../elements/CheckBoxCell';
|
|
7
7
|
import ReactTable from '../../../elements/ReactTable/ReactTable';
|
|
8
8
|
import FormikInput from '../../../elements/formik/FormikInput';
|
|
9
|
-
const style = {
|
|
10
|
-
width: '100%',
|
|
11
|
-
fontSize: '1.1em',
|
|
12
|
-
textAlign: 'left',
|
|
13
|
-
padding: '0.1em 0.1em',
|
|
14
|
-
};
|
|
15
9
|
const inputStyle = {
|
|
16
|
-
|
|
10
|
+
input: {
|
|
11
|
+
width: '100%',
|
|
12
|
+
fontSize: '1.1em',
|
|
13
|
+
textAlign: 'left',
|
|
14
|
+
backgroundColor: 'transparent',
|
|
15
|
+
},
|
|
16
|
+
inputWrapper: {
|
|
17
|
+
padding: '0.25rem 0.5rem',
|
|
18
|
+
borderRadius: 0,
|
|
19
|
+
borderColor: 'white',
|
|
20
|
+
},
|
|
17
21
|
};
|
|
18
22
|
export function SpectraColumnsManager({ nucleus, onAdd, onDelete, datalist, mapOnChangeValue, mapValue, }) {
|
|
19
23
|
const { values: nucleiPreferences } = useFormikContext();
|
|
@@ -25,24 +29,23 @@ export function SpectraColumnsManager({ nucleus, onAdd, onDelete, datalist, mapO
|
|
|
25
29
|
},
|
|
26
30
|
{
|
|
27
31
|
Header: 'Label',
|
|
32
|
+
style: { padding: 0 },
|
|
28
33
|
Cell: ({ row }) => {
|
|
29
|
-
return (_jsx(FormikInput, { name: `nuclei.${nucleus}.columns.${row.index}.label`, style:
|
|
30
|
-
input: { ...style, ...inputStyle },
|
|
31
|
-
inputWrapper: { border: 'none' },
|
|
32
|
-
} }));
|
|
34
|
+
return (_jsx(FormikInput, { name: `nuclei.${nucleus}.columns.${row.index}.label`, style: inputStyle }));
|
|
33
35
|
},
|
|
34
36
|
},
|
|
35
37
|
{
|
|
36
38
|
Header: 'Column',
|
|
39
|
+
style: { padding: 0 },
|
|
37
40
|
Cell: ({ row }) => {
|
|
38
41
|
const column = row.original;
|
|
39
42
|
if (column?.name) {
|
|
40
|
-
return (_jsx("span", { style:
|
|
43
|
+
return (_jsx("span", { style: {
|
|
44
|
+
...inputStyle.input,
|
|
45
|
+
padding: '0.25rem 0.5rem',
|
|
46
|
+
}, children: column?.jpath?.join('.') || column.description }));
|
|
41
47
|
}
|
|
42
|
-
return (_jsx(FormikInput, { name: `nuclei.${nucleus}.columns.${row.index}.jpath`, style:
|
|
43
|
-
input: { ...style, ...inputStyle },
|
|
44
|
-
inputWrapper: { border: 'none' },
|
|
45
|
-
}, datalist: datalist, mapOnChangeValue: mapOnChangeValue, mapValue: mapValue }));
|
|
48
|
+
return (_jsx(FormikInput, { name: `nuclei.${nucleus}.columns.${row.index}.jpath`, style: inputStyle, datalist: datalist, mapOnChangeValue: mapOnChangeValue, mapValue: mapValue }));
|
|
46
49
|
},
|
|
47
50
|
},
|
|
48
51
|
{
|
|
@@ -31,7 +31,12 @@ const emptyKeywords = {
|
|
|
31
31
|
searchKeywords: '',
|
|
32
32
|
};
|
|
33
33
|
function mapKeywordsToArray(searchKeywords, solvent) {
|
|
34
|
-
const values = searchKeywords
|
|
34
|
+
const values = searchKeywords
|
|
35
|
+
? searchKeywords
|
|
36
|
+
.trim()
|
|
37
|
+
.split(' ')
|
|
38
|
+
.filter((value) => value !== '')
|
|
39
|
+
: [];
|
|
35
40
|
if (solvent !== '-1') {
|
|
36
41
|
values.unshift(`solvent:${solvent}`);
|
|
37
42
|
}
|
|
@@ -93,7 +93,7 @@ export default function AnalysisChart(props) {
|
|
|
93
93
|
}
|
|
94
94
|
function handleCopy() {
|
|
95
95
|
if (chartParentRef.current) {
|
|
96
|
-
copyPNGToClipboard(chartParentRef.current, svgId, css({ text: { fill: 'black' } }));
|
|
96
|
+
void copyPNGToClipboard(chartParentRef.current, svgId, css({ text: { fill: 'black' } }));
|
|
97
97
|
alert.success('Chart copied to clipboard');
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -107,7 +107,9 @@ export default function PredictionPanel() {
|
|
|
107
107
|
setFlipStatus(false);
|
|
108
108
|
}
|
|
109
109
|
const isPredictedBefore = !!(molecules[currentIndex]?.id && predictions[molecules[currentIndex].id]);
|
|
110
|
-
return (_jsxs("div", { css: tablePanelStyle, children: [isFlipped && (_jsxs(_Fragment, { children: [_jsx(PreferencesHeader, { onSave: saveSettingHandler, onClose: settingsPanelHandler }), _jsx("div", { className: "inner-container", children: _jsx(PredictionPreferences, { ref: settingRef }) })] })), !isFlipped && (_jsxs(_Fragment, { children: [_jsx(MoleculePanelHeader, { currentIndex: currentIndex, moleculesView: moleculesView, molecules: molecules, renderSource: "predictionPanel", onClickPreferences: settingsPanelHandler, onOpenMoleculeEditor: () => openMoleculeEditor(),
|
|
110
|
+
return (_jsxs("div", { css: tablePanelStyle, children: [isFlipped && (_jsxs(_Fragment, { children: [_jsx(PreferencesHeader, { onSave: saveSettingHandler, onClose: settingsPanelHandler }), _jsx("div", { className: "inner-container", children: _jsx(PredictionPreferences, { ref: settingRef }) })] })), !isFlipped && (_jsxs(_Fragment, { children: [_jsx(MoleculePanelHeader, { currentIndex: currentIndex, moleculesView: moleculesView, molecules: molecules, renderSource: "predictionPanel", onClickPreferences: settingsPanelHandler, onOpenMoleculeEditor: () => openMoleculeEditor(), onClickPastMolecule: () => {
|
|
111
|
+
refreshSlider.current = true;
|
|
112
|
+
}, children: _jsx(PredictionSimpleOptions, {}) }), _jsxs("div", { style: styles.flexColumnContainer, children: [_jsx("div", { style: { flex: 1 }, children: _jsx(ResponsiveChart, { children: ({ height, width }) => {
|
|
111
113
|
return (_jsx(NextPrev, { onChange: (slideIndex) => {
|
|
112
114
|
setCurrentIndex(slideIndex);
|
|
113
115
|
setMolfile(molecules[slideIndex].molfile);
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/reac
|
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
4
|
import { Formik } from 'formik';
|
|
5
5
|
import { useCallback, useState, useRef, useMemo } from 'react';
|
|
6
|
+
import * as Yup from 'yup';
|
|
6
7
|
import { defaultSimulationOptions, } from '../../../data/data1d/spectrumSimulation';
|
|
7
8
|
import { useDispatch } from '../../context/DispatchContext';
|
|
8
9
|
import Button from '../../elements/Button';
|
|
@@ -14,6 +15,14 @@ import PreferencesHeader from '../header/PreferencesHeader';
|
|
|
14
15
|
import SpectrumSimulationPreferences from './SpectrumSimulationPreferences';
|
|
15
16
|
import SpectrumSimulationSimpleOptions from './SpectrumSimulationSimpleOptions';
|
|
16
17
|
import { SpinSystemTable } from './SpinSystemTable';
|
|
18
|
+
const validationSchema = Yup.object({
|
|
19
|
+
data: Yup.array().of(Yup.array().of(Yup.lazy((value) => {
|
|
20
|
+
if (value === null) {
|
|
21
|
+
return Yup.mixed().nullable();
|
|
22
|
+
}
|
|
23
|
+
return Yup.number().required();
|
|
24
|
+
}))),
|
|
25
|
+
});
|
|
17
26
|
export default function SpectrumSimulation() {
|
|
18
27
|
const dispatch = useDispatch();
|
|
19
28
|
const [isFlipped, setFlipStatus] = useState(false);
|
|
@@ -51,10 +60,12 @@ export default function SpectrumSimulation() {
|
|
|
51
60
|
return rows;
|
|
52
61
|
}, [spinSystem]);
|
|
53
62
|
function simulateHandler(values, keepSpectrum = false) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
if (validationSchema.isValidSync(values)) {
|
|
64
|
+
dispatch({
|
|
65
|
+
type: 'SIMULATE_SPECTRUM',
|
|
66
|
+
payload: { ...values, spinSystem: spinSystemRef.current, keepSpectrum },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
function addSpectrumHandler() {
|
|
60
71
|
const values = formRef.current?.values;
|
|
@@ -289,6 +289,8 @@ function innerSpectrumReducer(draft, action) {
|
|
|
289
289
|
return ToolsActions.handleAddBaseLineZone(draft, action);
|
|
290
290
|
case 'DELETE_BASE_LINE_ZONE':
|
|
291
291
|
return ToolsActions.handleDeleteBaseLineZone(draft, action);
|
|
292
|
+
case 'RESIZE_BASE_LINE_ZONE':
|
|
293
|
+
return ToolsActions.handleResizeBaseLineZone(draft, action);
|
|
292
294
|
case 'SET_2D_LEVEL':
|
|
293
295
|
return ToolsActions.levelChangeHandler(draft, action);
|
|
294
296
|
case 'ADD_MOLECULE':
|
|
@@ -13,8 +13,8 @@ type MoveXAxisAction = ActionType<'MOVE', {
|
|
|
13
13
|
}>;
|
|
14
14
|
export type DomainActions = SetXDomainAction | SetYDomainAction | MoveXAxisAction;
|
|
15
15
|
declare function getDomain(draft: Draft<State>): {
|
|
16
|
-
xDomain: [number, number] | [undefined, undefined];
|
|
17
|
-
yDomain: [number, number] | [undefined, undefined];
|
|
16
|
+
xDomain: [number, number] | never[] | [undefined, undefined];
|
|
17
|
+
yDomain: [number, number] | never[] | [undefined, undefined];
|
|
18
18
|
yDomains: Record<string, number[]>;
|
|
19
19
|
xDomains: Record<string, number[]>;
|
|
20
20
|
};
|
|
@@ -47,8 +47,8 @@ function getDomain(draft) {
|
|
|
47
47
|
reportError(error);
|
|
48
48
|
}
|
|
49
49
|
return {
|
|
50
|
-
xDomain: extent(xArray),
|
|
51
|
-
yDomain: extent(yArray),
|
|
50
|
+
xDomain: xArray?.length > 0 ? extent(xArray) : [],
|
|
51
|
+
yDomain: yArray?.length > 0 ? extent(yArray) : [],
|
|
52
52
|
yDomains,
|
|
53
53
|
xDomains,
|
|
54
54
|
};
|
|
@@ -82,7 +82,7 @@ type SetTwoDimensionPhaseCorrectionPivotPoint = ActionType<'SET_TWO_DIMENSION_PI
|
|
|
82
82
|
y: number;
|
|
83
83
|
}>;
|
|
84
84
|
export type FiltersActions = ShiftSpectrumAlongXAxisAction | ApodizationFilterAction | ApodizationFilterLiveAction | ZeroFillingFilterAction | ZeroFillingFilterLiveAction | ManualPhaseCorrectionFilterAction | BaselineCorrectionFilterAction | BaselineCorrectionFilterLiveAction | EnableFilterAction | DeleteFilterAction | DeleteSpectraFilterAction | SetFilterSnapshotAction | AddExclusionZoneAction | DeleteExclusionZoneAction | ApplySignalProcessingAction | AddPhaseCorrectionTraceAction | ChangePhaseCorrectionDirectionAction | DeletePhaseCorrectionTrace | SetOneDimensionPhaseCorrectionPivotPoint | SetTwoDimensionPhaseCorrectionPivotPoint | ActionType<'APPLY_FFT_FILTER' | 'APPLY_FFT_DIMENSION_1_FILTER' | 'APPLY_FFT_DIMENSION_2_FILTER' | 'APPLY_AUTO_PHASE_CORRECTION_FILTER' | 'APPLY_ABSOLUTE_FILTER'>;
|
|
85
|
-
interface RollbackSpectrumByFilterOptions {
|
|
85
|
+
export interface RollbackSpectrumByFilterOptions {
|
|
86
86
|
applyFilter?: boolean;
|
|
87
87
|
reset?: boolean;
|
|
88
88
|
searchBy?: 'id' | 'name';
|
|
@@ -91,9 +91,8 @@ interface RollbackSpectrumByFilterOptions {
|
|
|
91
91
|
triggerSource?: 'Apply' | 'none';
|
|
92
92
|
}
|
|
93
93
|
declare function rollbackSpectrumByFilter(draft: Draft<State>, options?: RollbackSpectrumByFilterOptions): void;
|
|
94
|
-
interface RollbackSpectrumOptions {
|
|
95
|
-
|
|
96
|
-
filterKey: string;
|
|
94
|
+
export interface RollbackSpectrumOptions {
|
|
95
|
+
filterKey?: string;
|
|
97
96
|
reset?: boolean;
|
|
98
97
|
}
|
|
99
98
|
declare function rollbackSpectrum(draft: Draft<State>, options: RollbackSpectrumOptions): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { v4 } from '@lukeed/uuid';
|
|
2
2
|
import { current } from 'immer';
|
|
3
3
|
import { xFindClosestIndex } from 'ml-spectra-processing';
|
|
4
|
-
import { Filters, FiltersManager, } from 'nmr-processing';
|
|
4
|
+
import { Filters, FiltersManager, getBaselineZones, } from 'nmr-processing';
|
|
5
5
|
import { defaultApodizationOptions } from '../../../data/constants/DefaultApodizationOptions';
|
|
6
6
|
import { getSlice, isSpectrum2D } from '../../../data/data2d/Spectrum2D';
|
|
7
7
|
import { getProjection } from '../../../data/data2d/Spectrum2D/getMissingProjection';
|
|
@@ -20,12 +20,32 @@ import { setDomain, setMode } from './DomainActions';
|
|
|
20
20
|
import { changeSpectrumVerticalAlignment } from './PreferencesActions';
|
|
21
21
|
import { activateTool, resetSelectedTool } from './ToolsActions';
|
|
22
22
|
const { fft, fftDimension1, fftDimension2, apodization, baselineCorrection, phaseCorrection, zeroFilling, shiftX, shift2DX, shift2DY, exclusionZones, signalProcessing, } = Filters;
|
|
23
|
-
function getFilterUpdateDomainRules(filterName) {
|
|
24
|
-
return (Filters[filterName]?.DOMAIN_UPDATE_RULES ||
|
|
23
|
+
function getFilterUpdateDomainRules(filterName, defaultRule) {
|
|
24
|
+
return (Filters[filterName]?.DOMAIN_UPDATE_RULES ||
|
|
25
|
+
defaultRule || {
|
|
25
26
|
updateXDomain: false,
|
|
26
27
|
updateYDomain: false,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
30
|
+
function getFilterDomain(datum, options) {
|
|
31
|
+
const { startIndex, lastIndex } = options;
|
|
32
|
+
const updateDomainOptions = {
|
|
33
|
+
updateXDomain: false,
|
|
34
|
+
updateYDomain: false,
|
|
35
|
+
};
|
|
36
|
+
if (datum?.filters?.length === 0)
|
|
37
|
+
return updateDomainOptions;
|
|
38
|
+
for (let i = startIndex; i <= lastIndex; i++) {
|
|
39
|
+
const { updateXDomain, updateYDomain } = getFilterUpdateDomainRules(datum.filters[i].name);
|
|
40
|
+
if (!updateDomainOptions.updateXDomain) {
|
|
41
|
+
updateDomainOptions.updateXDomain = updateXDomain;
|
|
42
|
+
}
|
|
43
|
+
if (!updateDomainOptions.updateYDomain) {
|
|
44
|
+
updateDomainOptions.updateYDomain = updateYDomain;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return updateDomainOptions;
|
|
48
|
+
}
|
|
29
49
|
function rollbackSpectrumByFilter(draft, options) {
|
|
30
50
|
const { applyFilter = true, searchBy = 'id', reset = false, key, activeSpectrum, triggerSource = 'none', } = options || {};
|
|
31
51
|
const currentActiveSpectrum = activeSpectrum || getActiveSpectrum(draft);
|
|
@@ -40,47 +60,53 @@ function rollbackSpectrumByFilter(draft, options) {
|
|
|
40
60
|
const datum = draft.data[index];
|
|
41
61
|
previousIsFid = datum.info.isFid;
|
|
42
62
|
const filterIndex = datum.filters.findIndex((f) => f[searchBy] === key);
|
|
43
|
-
const activeFilterId = draft.toolOptions.data.activeFilterID;
|
|
44
63
|
if (filterIndex !== -1 && !reset) {
|
|
45
|
-
const
|
|
64
|
+
const { activeFilterID } = draft.toolOptions.data;
|
|
65
|
+
const activeFilterIndex = activeFilterID
|
|
66
|
+
? datum.filters.findIndex((f) => f.id === activeFilterID)
|
|
67
|
+
: datum.filters.length - 1;
|
|
46
68
|
//set active filter
|
|
47
|
-
draft.toolOptions.data.activeFilterID =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
FiltersManager.reapplyFilters(datum, filters);
|
|
57
|
-
}
|
|
69
|
+
draft.toolOptions.data.activeFilterID =
|
|
70
|
+
datum.filters?.[filterIndex]?.id || null;
|
|
71
|
+
const filters = datum.filters.slice(0, filterIndex || 1);
|
|
72
|
+
updateDomainOptions = getFilterDomain(datum, {
|
|
73
|
+
startIndex: Math.min(activeFilterIndex, filterIndex),
|
|
74
|
+
lastIndex: Math.max(activeFilterIndex, filterIndex),
|
|
75
|
+
});
|
|
76
|
+
FiltersManager.reapplyFilters(datum, filters);
|
|
58
77
|
draft.tempData = current(draft).data;
|
|
59
78
|
// apply the current Filters
|
|
60
79
|
if (applyFilter) {
|
|
61
|
-
|
|
80
|
+
const { name, value } = datum.filters[filterIndex];
|
|
81
|
+
Filters[name].apply(datum, value);
|
|
62
82
|
}
|
|
63
83
|
currentIsFid = datum.info.isFid;
|
|
64
84
|
//if we still point to the same filter then close the filter options panel and reset the selected tool to default one (zoom tool)
|
|
65
|
-
if (
|
|
85
|
+
if (activeFilterID === datum.filters[filterIndex].id &&
|
|
66
86
|
triggerSource === 'Apply') {
|
|
67
87
|
draft.toolOptions.selectedOptionPanel = null;
|
|
68
88
|
draft.toolOptions.selectedTool = 'zoom';
|
|
69
89
|
}
|
|
70
90
|
}
|
|
71
|
-
|
|
91
|
+
if (filterIndex === -1 || reset) {
|
|
92
|
+
if (draft.tempData) {
|
|
93
|
+
FiltersManager.reapplyFilters(datum);
|
|
94
|
+
}
|
|
72
95
|
//if the filter is not exists, create a clone of the current data
|
|
73
96
|
draft.tempData = current(draft).data;
|
|
74
97
|
}
|
|
75
98
|
// re-implement all filters and rest all view property that related to filters
|
|
76
99
|
if (reset) {
|
|
100
|
+
draft.toolOptions.data.activeFilterID = null;
|
|
77
101
|
draft.tempData = null;
|
|
78
|
-
|
|
79
|
-
|
|
102
|
+
if (datum.filters.length > 0 && filterIndex !== -1) {
|
|
103
|
+
updateDomainOptions = getFilterDomain(datum, {
|
|
104
|
+
startIndex: filterIndex,
|
|
105
|
+
lastIndex: datum.filters.length - 1,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
80
108
|
const { toolOptions: { data }, } = getInitialState();
|
|
81
109
|
draft.toolOptions.data = data;
|
|
82
|
-
draft.toolOptions.selectedOptionPanel = null;
|
|
83
|
-
draft.toolOptions.selectedTool = 'zoom';
|
|
84
110
|
currentIsFid = datum.info.isFid;
|
|
85
111
|
}
|
|
86
112
|
}
|
|
@@ -91,28 +117,51 @@ function rollbackSpectrumByFilter(draft, options) {
|
|
|
91
117
|
}
|
|
92
118
|
}
|
|
93
119
|
function rollbackSpectrum(draft, options) {
|
|
94
|
-
const { filterKey, reset = false
|
|
120
|
+
const { filterKey, reset = false } = options;
|
|
95
121
|
//return back the spectra data to point of time before applying a specific filter
|
|
96
|
-
const applyFilter =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
const applyFilter = !filterKey
|
|
123
|
+
? true
|
|
124
|
+
: [
|
|
125
|
+
phaseCorrection.id,
|
|
126
|
+
fft.id,
|
|
127
|
+
shiftX.id,
|
|
128
|
+
shift2DX.id,
|
|
129
|
+
shift2DY.id,
|
|
130
|
+
signalProcessing.id,
|
|
131
|
+
].includes(filterKey);
|
|
132
|
+
beforeRollback(draft, filterKey);
|
|
104
133
|
rollbackSpectrumByFilter(draft, {
|
|
105
134
|
searchBy: 'name',
|
|
106
135
|
key: filterKey,
|
|
107
136
|
applyFilter,
|
|
108
137
|
reset,
|
|
109
138
|
});
|
|
110
|
-
|
|
111
|
-
updateFilterOptionsInView(draft, filterKey);
|
|
112
|
-
}
|
|
139
|
+
afterRollback(draft, filterKey);
|
|
113
140
|
}
|
|
114
|
-
function
|
|
141
|
+
function beforeRollback(draft, filterKey) {
|
|
115
142
|
const activeSpectrum = getActiveSpectrum(draft);
|
|
143
|
+
switch (filterKey) {
|
|
144
|
+
case baselineCorrection.id: {
|
|
145
|
+
if (activeSpectrum) {
|
|
146
|
+
const datum = current(draft).data[activeSpectrum.index];
|
|
147
|
+
const baselineCorrectionFilter = datum.filters.find((filter) => filter.name === Tools.baselineCorrection.id);
|
|
148
|
+
if (!baselineCorrectionFilter ||
|
|
149
|
+
(baselineCorrectionFilter &&
|
|
150
|
+
baselineCorrectionFilter.value.zones?.length === 0)) {
|
|
151
|
+
draft.toolOptions.data.baselineCorrection.zones = getBaselineZones(datum.data);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
draft.toolOptions.data.baselineCorrection.zones =
|
|
155
|
+
baselineCorrectionFilter.value.zones;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
default:
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function afterRollback(draft, filterKey) {
|
|
116
165
|
switch (filterKey) {
|
|
117
166
|
case phaseCorrection.id: {
|
|
118
167
|
// look for the strongest peak to set it as a pivot
|
|
@@ -123,18 +172,6 @@ function updateFilterOptionsInView(draft, filterKey) {
|
|
|
123
172
|
draft.toolOptions.data.pivot = { value: xValue, index };
|
|
124
173
|
break;
|
|
125
174
|
}
|
|
126
|
-
case baselineCorrection.id: {
|
|
127
|
-
if (activeSpectrum) {
|
|
128
|
-
const baselineCorrectionFilter = current(draft).data[activeSpectrum.index].filters.find((filter) => filter.name === Tools.baselineCorrection.id);
|
|
129
|
-
if (baselineCorrectionFilter) {
|
|
130
|
-
draft.toolOptions.data.baselineCorrection.zones =
|
|
131
|
-
baselineCorrectionFilter
|
|
132
|
-
? baselineCorrectionFilter.value.zones
|
|
133
|
-
: [];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
175
|
case apodization.id: {
|
|
139
176
|
draft.toolOptions.data.apodizationOptions = defaultApodizationOptions;
|
|
140
177
|
break;
|
|
@@ -170,16 +207,17 @@ function disableLivePreview(draft, id) {
|
|
|
170
207
|
const index = activeSpectrum.index;
|
|
171
208
|
const { data } = draft.tempData[index];
|
|
172
209
|
draft.data[index].data = data;
|
|
173
|
-
|
|
210
|
+
if (baselineCorrection.id !== id) {
|
|
211
|
+
setDomain(draft);
|
|
212
|
+
}
|
|
174
213
|
// reset default options
|
|
175
214
|
switch (id) {
|
|
176
|
-
case apodization.
|
|
215
|
+
case apodization.id: {
|
|
177
216
|
draft.toolOptions.data.apodizationOptions = defaultApodizationOptions;
|
|
178
217
|
break;
|
|
179
218
|
}
|
|
180
|
-
default:
|
|
181
|
-
|
|
182
|
-
}
|
|
219
|
+
default:
|
|
220
|
+
break;
|
|
183
221
|
}
|
|
184
222
|
}
|
|
185
223
|
}
|
|
@@ -526,7 +564,7 @@ function calculateBaseLineCorrection(draft, baseLineOptions) {
|
|
|
526
564
|
...draft.toolOptions.data.baselineCorrection,
|
|
527
565
|
...(baseLineOptions && baseLineOptions),
|
|
528
566
|
};
|
|
529
|
-
const { zones, options, livePreview } = draft.toolOptions.data.baselineCorrection;
|
|
567
|
+
const { zones, options, livePreview } = current(draft).toolOptions.data.baselineCorrection;
|
|
530
568
|
if (livePreview) {
|
|
531
569
|
const _data = { data: { x, re, im }, info };
|
|
532
570
|
baselineCorrection.apply(_data, {
|
|
@@ -603,7 +641,6 @@ function handleSetFilterSnapshotHandler(draft, action) {
|
|
|
603
641
|
activateTool(draft, { toolId: filterKey, reset });
|
|
604
642
|
}
|
|
605
643
|
else {
|
|
606
|
-
resetSelectedTool(draft);
|
|
607
644
|
rollbackSpectrum(draft, { filterKey, reset });
|
|
608
645
|
}
|
|
609
646
|
}
|
|
@@ -612,7 +649,6 @@ function handleSignalProcessingFilter(draft, action) {
|
|
|
612
649
|
const { data, view } = draft;
|
|
613
650
|
const nucleus = view.spectra.activeTab;
|
|
614
651
|
const value = action.payload.options;
|
|
615
|
-
const activeFilterIndex = getActiveFilterIndex(draft);
|
|
616
652
|
const spectra = getSpectraByNucleus(nucleus, data);
|
|
617
653
|
for (const spectrum of spectra) {
|
|
618
654
|
FiltersManager.applyFilter(spectrum, [
|
|
@@ -620,7 +656,7 @@ function handleSignalProcessingFilter(draft, action) {
|
|
|
620
656
|
name: signalProcessing.id,
|
|
621
657
|
value,
|
|
622
658
|
},
|
|
623
|
-
], {
|
|
659
|
+
], { forceReapply: true });
|
|
624
660
|
}
|
|
625
661
|
const { updateXDomain, updateYDomain } = signalProcessing.DOMAIN_UPDATE_RULES;
|
|
626
662
|
setDomain(draft, { updateXDomain, updateYDomain });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { produce } from 'immer';
|
|
1
2
|
import lodashMerge from 'lodash/merge';
|
|
2
3
|
import lodashMergeWith from 'lodash/mergeWith';
|
|
3
4
|
import { buildCorrelationData } from 'nmr-correlation';
|
|
@@ -113,14 +114,15 @@ function initData(draft, action, options = {}) {
|
|
|
113
114
|
const viewState = view;
|
|
114
115
|
if (data?.spectra?.length || forceInitialize) {
|
|
115
116
|
const state = getInitialState();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
return produce(state, (initialDraft) => {
|
|
118
|
+
setData(initialDraft, action.payload);
|
|
119
|
+
setActiveTab(initialDraft, { tab: viewState?.spectra?.activeTab || '' });
|
|
120
|
+
initialDraft.width = draft.width;
|
|
121
|
+
initialDraft.height = draft.height;
|
|
122
|
+
setPreferences(initialDraft, viewState);
|
|
123
|
+
initialDraft.isLoading = false;
|
|
124
|
+
initialDraft.actionType = action.type;
|
|
125
|
+
});
|
|
124
126
|
}
|
|
125
127
|
else {
|
|
126
128
|
if (view) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Draft } from 'immer';
|
|
2
2
|
import { Spectrum, Display1D, Display2D } from 'nmr-load-save';
|
|
3
|
+
import { NMRRange } from 'nmr-processing';
|
|
3
4
|
import { SpectrumSimulationOptions } from '../../../data/data1d/spectrumSimulation';
|
|
4
5
|
import { Nuclei, Nucleus } from '../../../data/types/common/Nucleus';
|
|
5
6
|
import { State } from '../Reducer';
|
|
@@ -33,7 +34,13 @@ type AlignSpectraAction = ActionType<'ALIGN_SPECTRA', {
|
|
|
33
34
|
targetX: number;
|
|
34
35
|
}>;
|
|
35
36
|
type GenerateSpectrumFromPublicationStringAction = ActionType<'GENERATE_SPECTRUM_FROM_PUBLICATION_STRING', {
|
|
36
|
-
|
|
37
|
+
ranges: NMRRange[];
|
|
38
|
+
info: {
|
|
39
|
+
nucleus: string;
|
|
40
|
+
solvent: string;
|
|
41
|
+
frequency: number;
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
|
37
44
|
}>;
|
|
38
45
|
type ImportSpectraMetaInfoAction = ActionType<'IMPORT_SPECTRA_META_INFO', {
|
|
39
46
|
spectraMeta: Record<string, Record<string, any>>;
|
|
@@ -3,7 +3,7 @@ import lodashGet from 'lodash/get';
|
|
|
3
3
|
import omitBy from 'lodash/omitBy';
|
|
4
4
|
import lodashSet from 'lodash/set';
|
|
5
5
|
import { Filters, FiltersManager } from 'nmr-processing';
|
|
6
|
-
import {
|
|
6
|
+
import { getReferenceShift, isSpectrum1D, get1DColor, initiateDatum1D, generateSpectrumFromRanges, } from '../../../data/data1d/Spectrum1D';
|
|
7
7
|
import { simulateSpectrum, } from '../../../data/data1d/spectrumSimulation';
|
|
8
8
|
import { getMissingProjection, isSpectrum2D, get2DColor, } from '../../../data/data2d/Spectrum2D';
|
|
9
9
|
import { contoursManager } from '../../../data/data2d/Spectrum2D/contours';
|
|
@@ -79,13 +79,17 @@ function setSpectraMetaInfo(draft, spectraMetaInfo) {
|
|
|
79
79
|
//action
|
|
80
80
|
function handleChangeSpectrumVisibilityById(draft, action) {
|
|
81
81
|
const { id, key } = action.payload;
|
|
82
|
-
const
|
|
82
|
+
const { xDomain, data } = draft;
|
|
83
|
+
const spectrum = data.find((d) => d.id === id);
|
|
83
84
|
if (spectrum) {
|
|
84
85
|
spectrum.display[key] = !spectrum.display[key];
|
|
85
86
|
if (spectrum.info.dimension === 2) {
|
|
86
87
|
spectrum.display.isVisible = checkIsVisible2D(spectrum);
|
|
87
88
|
}
|
|
88
89
|
}
|
|
90
|
+
if (xDomain?.length === 0) {
|
|
91
|
+
setDomain(draft);
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
94
|
//action
|
|
91
95
|
function handleChangeSpectraVisibilityByNucleus(draft, action) {
|
|
@@ -296,8 +300,8 @@ function handleAlignSpectraHandler(draft, action) {
|
|
|
296
300
|
}
|
|
297
301
|
//action
|
|
298
302
|
function handleGenerateSpectrumFromPublicationStringHandler(draft, action) {
|
|
299
|
-
const
|
|
300
|
-
const spectrum =
|
|
303
|
+
const { ranges, info } = action.payload;
|
|
304
|
+
const spectrum = generateSpectrumFromRanges(ranges, info, draft.usedColors);
|
|
301
305
|
if (spectrum) {
|
|
302
306
|
draft.data.push(spectrum);
|
|
303
307
|
setActiveTab(draft);
|