nmrium 0.25.0 → 0.26.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/multiplicityTree/MultiplicityTree.js +5 -5
- package/lib/component/1d/ranges/Range.js +6 -5
- package/lib/component/2d/zones/Signal.js +8 -8
- package/lib/component/2d/zones/Zone.js +3 -3
- package/lib/component/EventsTrackers/KeysListenerTracker.js +1 -1
- package/lib/component/assignment/AssignmentsContext.d.ts +35 -0
- package/lib/component/assignment/AssignmentsContext.js +83 -0
- package/lib/component/assignment/AssignmentsReducer.d.ts +32 -0
- package/lib/component/assignment/AssignmentsReducer.js +39 -0
- package/lib/component/assignment/actions/initAssignment.d.ts +5 -0
- package/lib/component/assignment/actions/initAssignment.js +62 -0
- package/lib/component/assignment/actions/removeAssignment.d.ts +16 -0
- package/lib/component/assignment/actions/removeAssignment.js +24 -0
- package/lib/component/assignment/actions/setActiveAssignment.d.ts +10 -0
- package/lib/component/assignment/actions/setActiveAssignment.js +8 -0
- package/lib/component/assignment/actions/toggleAssignment.d.ts +7 -0
- package/lib/component/assignment/actions/toggleAssignment.js +44 -0
- package/lib/component/assignment/index.d.ts +0 -18
- package/lib/component/assignment/index.js +12 -266
- package/lib/component/assignment/utilities/filterForIDsWithAssignment.d.ts +2 -0
- package/lib/component/assignment/utilities/filterForIDsWithAssignment.js +3 -0
- package/lib/component/elements/Button.js +2 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.d.ts +5 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +38 -10
- package/lib/component/elements/ReactTable/ReactTable.d.ts +3 -1
- package/lib/component/elements/ReactTable/ReactTable.js +7 -2
- package/lib/component/elements/ReactTable/Style.d.ts +1 -3
- package/lib/component/elements/ReactTable/Style.js +1 -7
- package/lib/component/header/BaseLineCorrectionPanel.js +1 -1
- package/lib/component/modal/setting/FormattingTabContent.js +17 -11
- package/lib/component/modal/setting/GeneralSettings.js +2 -1
- package/lib/component/modal/setting/settingsValidation.d.ts +8 -0
- package/lib/component/modal/setting/settingsValidation.js +40 -0
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignment.js +6 -4
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignmentTable.d.ts +4 -3
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignmentTable.js +13 -6
- package/lib/component/panels/AutomaticAssignment/useAutoAssignments.d.ts +10 -0
- package/lib/component/panels/AutomaticAssignment/useAutoAssignments.js +60 -0
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +1 -1
- package/lib/component/panels/MoleculesPanel/Utilities.d.ts +20 -11
- package/lib/component/panels/MoleculesPanel/Utilities.js +50 -68
- package/lib/component/panels/MoleculesPanel/useAtomAssignment.d.ts +2 -2
- package/lib/component/panels/MoleculesPanel/useAtomAssignment.js +55 -60
- package/lib/component/panels/RangesPanel/RangesHeader.js +2 -2
- package/lib/component/panels/RangesPanel/RangesPanel.js +1 -1
- package/lib/component/panels/RangesPanel/RangesTableRow.js +12 -11
- package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.d.ts +16 -9
- package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.js +2 -2
- package/lib/component/panels/RangesPanel/TableColumns/SignalAssignmentsColumn.d.ts +2 -3
- package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +1 -1
- package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +5 -18
- package/lib/component/panels/SummaryPanel/SummaryPanel.js +1 -1
- package/lib/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +1 -1
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.d.ts +5 -7
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.js +2 -2
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.d.ts +4 -8
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.js +1 -1
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.d.ts +5 -9
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.js +4 -4
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumns.d.ts +4 -8
- package/lib/component/panels/ZonesPanel/ZonesPanel.js +1 -1
- package/lib/component/panels/ZonesPanel/ZonesTableRow.d.ts +2 -1
- package/lib/component/panels/ZonesPanel/ZonesTableRow.js +20 -20
- package/lib/component/panels/header/SpectraAutomaticPickingButton.d.ts +2 -0
- package/lib/component/panels/header/SpectraAutomaticPickingButton.js +30 -0
- package/lib/component/reducer/Reducer.d.ts +2 -0
- package/lib/component/reducer/Reducer.js +4 -1
- package/lib/component/reducer/actions/AssignmentsActions.d.ts +9 -0
- package/lib/component/reducer/actions/AssignmentsActions.js +18 -0
- package/lib/component/reducer/actions/LoadActions.d.ts +1 -1
- package/lib/component/reducer/actions/LoadActions.js +10 -5
- package/lib/component/reducer/preferencesReducer.d.ts +1 -8
- package/lib/component/reducer/preferencesReducer.js +10 -13
- package/lib/component/reducer/types/Types.d.ts +1 -0
- package/lib/component/reducer/types/Types.js +1 -0
- package/lib/component/utility/FormatNumber.js +1 -1
- package/lib/component/workspaces/Workspace.d.ts +2 -4
- package/lib/component/workspaces/basic.js +8 -9
- package/lib/data/SpectraManager.js +23 -15
- package/lib/data/data1d/Data1DManager.d.ts +1 -1
- package/lib/data/data1d/Data1DManager.js +2 -1
- package/lib/data/data1d/Spectrum1D/toJSON.d.ts +2 -0
- package/lib/data/data1d/Spectrum1D/toJSON.js +1 -0
- package/lib/data/data1d/database.d.ts +1 -2
- package/lib/data/data1d/database.js +1 -1
- package/lib/data/data1d/filter1d/exclusionZones.d.ts +1 -4
- package/lib/data/data2d/Data2DManager.d.ts +1 -1
- package/lib/data/data2d/Data2DManager.js +2 -1
- package/lib/data/data2d/Spectrum2D/toJSON.d.ts +2 -0
- package/lib/data/data2d/Spectrum2D/toJSON.js +1 -0
- package/lib/data/types/common/Source.d.ts +1 -0
- package/lib/data/types/data2d/Signal2DAxisData.d.ts +1 -1
- package/lib/versionInfo.js +1 -1
- package/lib-cjs/component/1d/multiplicityTree/MultiplicityTree.js +6 -6
- package/lib-cjs/component/1d/ranges/Range.js +8 -7
- package/lib-cjs/component/2d/zones/Signal.js +9 -9
- package/lib-cjs/component/2d/zones/Zone.js +4 -4
- package/lib-cjs/component/EventsTrackers/KeysListenerTracker.js +2 -2
- package/lib-cjs/component/assignment/AssignmentsContext.js +88 -0
- package/lib-cjs/component/assignment/AssignmentsReducer.js +45 -0
- package/lib-cjs/component/assignment/actions/initAssignment.js +65 -0
- package/lib-cjs/component/assignment/actions/removeAssignment.js +29 -0
- package/lib-cjs/component/assignment/actions/setActiveAssignment.js +11 -0
- package/lib-cjs/component/assignment/actions/toggleAssignment.js +47 -0
- package/lib-cjs/component/assignment/index.js +15 -269
- package/lib-cjs/component/assignment/utilities/filterForIDsWithAssignment.js +7 -0
- package/lib-cjs/component/elements/Button.js +2 -1
- package/lib-cjs/component/elements/ReactTable/Elements/ReactTableRow.js +42 -14
- package/lib-cjs/component/elements/ReactTable/ReactTable.js +7 -2
- package/lib-cjs/component/elements/ReactTable/Style.js +1 -9
- package/lib-cjs/component/header/BaseLineCorrectionPanel.js +1 -1
- package/lib-cjs/component/modal/setting/FormattingTabContent.js +17 -11
- package/lib-cjs/component/modal/setting/GeneralSettings.js +2 -1
- package/lib-cjs/component/modal/setting/settingsValidation.js +66 -0
- package/lib-cjs/component/panels/AutomaticAssignment/AutomaticAssignment.js +6 -4
- package/lib-cjs/component/panels/AutomaticAssignment/AutomaticAssignmentTable.js +13 -6
- package/lib-cjs/component/panels/AutomaticAssignment/useAutoAssignments.js +67 -0
- package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +2 -2
- package/lib-cjs/component/panels/MoleculesPanel/Utilities.js +50 -68
- package/lib-cjs/component/panels/MoleculesPanel/useAtomAssignment.js +55 -60
- package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +3 -3
- package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +2 -2
- package/lib-cjs/component/panels/RangesPanel/RangesTableRow.js +15 -14
- package/lib-cjs/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.js +2 -2
- package/lib-cjs/component/panels/RangesPanel/hooks/useEditRangeModal.js +2 -2
- package/lib-cjs/component/panels/SpectrumsPanel/SpectraPanelHeader.js +3 -16
- package/lib-cjs/component/panels/SummaryPanel/SummaryPanel.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.js +1 -1
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.js +4 -4
- package/lib-cjs/component/panels/ZonesPanel/ZonesPanel.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/ZonesTableRow.js +21 -21
- package/lib-cjs/component/panels/header/SpectraAutomaticPickingButton.js +37 -0
- package/lib-cjs/component/reducer/Reducer.js +4 -1
- package/lib-cjs/component/reducer/actions/AssignmentsActions.js +21 -0
- package/lib-cjs/component/reducer/actions/LoadActions.js +9 -4
- package/lib-cjs/component/reducer/preferencesReducer.js +10 -13
- package/lib-cjs/component/reducer/types/Types.js +2 -1
- package/lib-cjs/component/utility/FormatNumber.js +1 -1
- package/lib-cjs/component/workspaces/basic.js +8 -9
- package/lib-cjs/data/SpectraManager.js +23 -15
- package/lib-cjs/data/data1d/Data1DManager.js +2 -1
- package/lib-cjs/data/data1d/Spectrum1D/toJSON.js +1 -0
- package/lib-cjs/data/data2d/Data2DManager.js +2 -1
- package/lib-cjs/data/data2d/Spectrum2D/toJSON.js +1 -0
- package/lib-cjs/versionInfo.js +1 -1
- package/package.json +19 -19
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { SvgNmrAssignment } from 'cheminfo-font';
|
|
3
3
|
import { useCallback, useMemo, memo } from 'react';
|
|
4
|
+
import { useDispatch } from '../../context/DispatchContext';
|
|
4
5
|
import ReactTable from '../../elements/ReactTable/ReactTable';
|
|
6
|
+
import { SET_AUTOMATIC_ASSIGNMENTS } from '../../reducer/types/Types';
|
|
5
7
|
import NoTableData from '../extra/placeholder/NoTableData';
|
|
6
|
-
function
|
|
8
|
+
function AutomaticAssignmentTable({ data }) {
|
|
9
|
+
const dispatch = useDispatch();
|
|
7
10
|
const assignHandler = useCallback((e, row) => {
|
|
8
11
|
e.preventDefault();
|
|
9
12
|
e.stopPropagation();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const assignments = row.original.assignment;
|
|
14
|
+
dispatch({
|
|
15
|
+
type: SET_AUTOMATIC_ASSIGNMENTS,
|
|
16
|
+
payload: { assignments },
|
|
17
|
+
});
|
|
18
|
+
}, [dispatch]);
|
|
13
19
|
const COLUMNS = useMemo(() => [
|
|
14
20
|
{
|
|
15
21
|
index: 1,
|
|
@@ -20,6 +26,7 @@ function PeaksTable({ data }) {
|
|
|
20
26
|
{
|
|
21
27
|
index: 2,
|
|
22
28
|
Header: 'Score',
|
|
29
|
+
accessor: 'score',
|
|
23
30
|
},
|
|
24
31
|
{
|
|
25
32
|
index: 3,
|
|
@@ -33,6 +40,6 @@ function PeaksTable({ data }) {
|
|
|
33
40
|
Cell: ({ row }) => (_jsx("button", { type: "button", className: "assign-button", onClick: (e) => assignHandler(e, row), children: _jsx(SvgNmrAssignment, {}) })),
|
|
34
41
|
},
|
|
35
42
|
], [assignHandler]);
|
|
36
|
-
return data && data.length > 0 ? (_jsx(ReactTable, { data: data, columns: COLUMNS })) : (_jsx(NoTableData, {}));
|
|
43
|
+
return data && data.length > 0 ? (_jsx(ReactTable, { data: data, columns: COLUMNS, onClick: assignHandler, highlightActiveRow: true })) : (_jsx(NoTableData, {}));
|
|
37
44
|
}
|
|
38
|
-
export default memo(
|
|
45
|
+
export default memo(AutomaticAssignmentTable);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SpectraData1D, SpectraData2D } from 'nmr-processing';
|
|
2
|
+
export interface AutoAssignmentsData {
|
|
3
|
+
score: number;
|
|
4
|
+
assignment: (SpectraData1D | SpectraData2D)[];
|
|
5
|
+
}
|
|
6
|
+
export declare function useAutoAssignments(): {
|
|
7
|
+
getAssignments: () => void;
|
|
8
|
+
assignments: AutoAssignmentsData[];
|
|
9
|
+
restAssignments: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getAssignments as getAssignmentsData, } from 'nmr-processing';
|
|
2
|
+
import OCL from 'openchemlib/full';
|
|
3
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { useChartData } from '../../context/ChartContext';
|
|
5
|
+
import { useDispatch } from '../../context/DispatchContext';
|
|
6
|
+
import { useAlert } from '../../elements/popup/Alert';
|
|
7
|
+
import { SET_AUTOMATIC_ASSIGNMENTS } from '../../reducer/types/Types';
|
|
8
|
+
function mapSpectra(data) {
|
|
9
|
+
return data.reduce((acc, spectrum) => {
|
|
10
|
+
const { id, info } = spectrum;
|
|
11
|
+
const dimension = spectrum.info.dimension;
|
|
12
|
+
if (dimension === 1) {
|
|
13
|
+
const ranges = spectrum.ranges.values;
|
|
14
|
+
acc.push({ id, info, ranges });
|
|
15
|
+
}
|
|
16
|
+
else if (dimension === 2) {
|
|
17
|
+
const zones = spectrum.zones.values;
|
|
18
|
+
acc.push({ id, info, zones });
|
|
19
|
+
}
|
|
20
|
+
return acc;
|
|
21
|
+
}, []);
|
|
22
|
+
}
|
|
23
|
+
export function useAutoAssignments() {
|
|
24
|
+
const dispatch = useDispatch();
|
|
25
|
+
const { data, molecules } = useChartData();
|
|
26
|
+
const originData = useRef();
|
|
27
|
+
const alert = useAlert();
|
|
28
|
+
const [assignments, setAssignments] = useState([]);
|
|
29
|
+
const restAssignments = useCallback(() => {
|
|
30
|
+
dispatch({
|
|
31
|
+
type: SET_AUTOMATIC_ASSIGNMENTS,
|
|
32
|
+
payload: { assignments: originData.current },
|
|
33
|
+
});
|
|
34
|
+
}, [dispatch]);
|
|
35
|
+
const getAssignments = useCallback(() => {
|
|
36
|
+
void (async () => {
|
|
37
|
+
const hideLoading = await alert.showLoading('Auto Assignments');
|
|
38
|
+
const molecule = OCL.Molecule.fromMolfile(molecules[0]?.molfile || '');
|
|
39
|
+
const spectra = mapSpectra(data);
|
|
40
|
+
if (!originData.current) {
|
|
41
|
+
originData.current = spectra;
|
|
42
|
+
}
|
|
43
|
+
const result = await getAssignmentsData({
|
|
44
|
+
spectra,
|
|
45
|
+
molecule,
|
|
46
|
+
}, { minScore: 0 });
|
|
47
|
+
dispatch({
|
|
48
|
+
type: SET_AUTOMATIC_ASSIGNMENTS,
|
|
49
|
+
payload: { assignments: result[0].assignment },
|
|
50
|
+
});
|
|
51
|
+
hideLoading();
|
|
52
|
+
setAssignments(result);
|
|
53
|
+
})();
|
|
54
|
+
}, [alert, data, dispatch, molecules]);
|
|
55
|
+
return useMemo(() => ({
|
|
56
|
+
getAssignments,
|
|
57
|
+
assignments,
|
|
58
|
+
restAssignments,
|
|
59
|
+
}), [assignments, getAssignments, restAssignments]);
|
|
60
|
+
}
|
|
@@ -4,7 +4,7 @@ import { css } from '@emotion/react';
|
|
|
4
4
|
import { SvgNmrFt } from 'cheminfo-font';
|
|
5
5
|
import { useCallback } from 'react';
|
|
6
6
|
import { FaCopy, FaDownload, FaFileExport, FaFileImage, FaPaste, FaPlus, FaRegTrashAlt, } from 'react-icons/fa';
|
|
7
|
-
import { useAssignmentData } from '../../assignment';
|
|
7
|
+
import { useAssignmentData } from '../../assignment/AssignmentsContext';
|
|
8
8
|
import { useDispatch } from '../../context/DispatchContext';
|
|
9
9
|
import { useGlobal } from '../../context/GlobalContext';
|
|
10
10
|
import ButtonToolTip from '../../elements/ButtonToolTip';
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Range } from '../../../data/types/data1d';
|
|
2
|
+
import { Zone } from '../../../data/types/data2d';
|
|
3
|
+
import { AssignmentContext, Axis } from '../../assignment/AssignmentsContext';
|
|
4
|
+
interface Atom {
|
|
5
|
+
oclID: string;
|
|
6
|
+
atomLabel: string;
|
|
6
7
|
nbAtoms: number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
nbHydrogens: number;
|
|
9
|
+
hydrogenOCLIDs: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface AtomData {
|
|
12
|
+
oclIDs: string[];
|
|
13
|
+
nbAtoms: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function extractFromAtom(atom: Atom, activeTab: string, axis?: Axis | null): AtomData;
|
|
16
|
+
export declare function findDatumAndSignalIndex(data: (Range | Zone)[], id: string): {
|
|
17
|
+
datum: Range | Zone | undefined;
|
|
10
18
|
signalIndex: any;
|
|
11
19
|
};
|
|
12
|
-
export declare function getHighlightsOnHover(
|
|
13
|
-
export declare function getCurrentDiaIDsToHighlight(assignmentData:
|
|
14
|
-
export declare function toggleDiaIDs(
|
|
20
|
+
export declare function getHighlightsOnHover(assignments: AssignmentContext, oclIDs: any, data: any): string[];
|
|
21
|
+
export declare function getCurrentDiaIDsToHighlight(assignmentData: AssignmentContext): string[];
|
|
22
|
+
export declare function toggleDiaIDs(diaIDs: string[], atomInformation: AtomData): (number | string[])[];
|
|
23
|
+
export {};
|
|
@@ -1,110 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function getElements(activeTab) {
|
|
2
|
+
const nuclei = activeTab.split(',');
|
|
3
|
+
return nuclei.map((nucleus) => nucleus.replace(/[0-9]/g, ''));
|
|
4
|
+
}
|
|
5
|
+
export function extractFromAtom(atom, activeTab, axis) {
|
|
6
|
+
const elements = getElements(activeTab);
|
|
3
7
|
if (elements.length > 0 && Object.keys(atom).length > 0) {
|
|
4
|
-
const dim =
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
const dim = axis === 'x' ? 0 : axis === 'y' ? 1 : null;
|
|
9
|
+
switch (dim !== null && elements[dim]) {
|
|
10
|
+
case atom.atomLabel: {
|
|
7
11
|
// take always oclID if atom type is same as element of activeTab)
|
|
8
12
|
return { oclIDs: [atom.oclID], nbAtoms: atom.nbAtoms };
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
case 'H': {
|
|
11
15
|
// if we are in proton spectrum and use then the IDs of attached hydrogens of an atom
|
|
12
16
|
return {
|
|
13
17
|
oclIDs: atom.hydrogenOCLIDs,
|
|
14
18
|
nbAtoms: atom.nbAtoms * atom.nbHydrogens,
|
|
15
19
|
};
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
21
|
+
default:
|
|
22
|
+
return {
|
|
23
|
+
oclIDs: [atom.oclID].concat(atom.hydrogenOCLIDs),
|
|
24
|
+
nbAtoms: atom.nbAtoms + atom.nbAtoms * atom.nbHydrogens,
|
|
25
|
+
};
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
return { oclIDs: [], nbAtoms: 0 };
|
|
26
29
|
}
|
|
27
|
-
export function findDatumAndSignalIndex(
|
|
30
|
+
export function findDatumAndSignalIndex(data, id) {
|
|
28
31
|
// if datum could be found then the id is on range/zone level
|
|
29
|
-
let datum =
|
|
32
|
+
let datum = data.find((_datum) => _datum.id === id);
|
|
30
33
|
let signalIndex;
|
|
31
34
|
if (!datum) {
|
|
32
35
|
// figure out the datum via id
|
|
33
|
-
for (const
|
|
34
|
-
signalIndex =
|
|
36
|
+
for (const record of data) {
|
|
37
|
+
signalIndex = record.signals.findIndex((signal) => signal.id === id);
|
|
35
38
|
if (signalIndex >= 0) {
|
|
36
|
-
datum =
|
|
39
|
+
datum = record;
|
|
37
40
|
break;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
return { datum, signalIndex };
|
|
42
45
|
}
|
|
43
|
-
export function getHighlightsOnHover(
|
|
46
|
+
export function getHighlightsOnHover(assignments, oclIDs, data) {
|
|
44
47
|
// set all IDs to highlight when hovering over an atom from assignment data
|
|
45
48
|
let highlights = [];
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
datum = result.datum;
|
|
60
|
-
signalIndex = result.signalIndex;
|
|
61
|
-
stop = true;
|
|
62
|
-
}
|
|
63
|
-
if (datum) {
|
|
64
|
-
highlights.push(datum.id);
|
|
65
|
-
if (signalIndex !== undefined) {
|
|
66
|
-
highlights.push(datum.signals[signalIndex].id);
|
|
49
|
+
const assignmentsByKey = assignments.data.assignments;
|
|
50
|
+
for (const key in assignmentsByKey) {
|
|
51
|
+
const assignments = assignmentsByKey[key];
|
|
52
|
+
for (const axis in assignments) {
|
|
53
|
+
if (assignments[axis]?.some((oclKey) => oclIDs.includes(oclKey))) {
|
|
54
|
+
highlights = highlights.concat(assignments[axis]);
|
|
55
|
+
const { datum, signalIndex } = findDatumAndSignalIndex(data, key);
|
|
56
|
+
if (datum) {
|
|
57
|
+
highlights.push(datum.id);
|
|
58
|
+
if (signalIndex !== undefined) {
|
|
59
|
+
highlights.push(datum.signals[signalIndex].id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
if (stop) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
64
|
}
|
|
73
65
|
return highlights;
|
|
74
66
|
}
|
|
75
|
-
export function getCurrentDiaIDsToHighlight(assignmentData
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
: displayerMode === DISPLAYER_MODE.DM_2D
|
|
86
|
-
? axisOnHover
|
|
87
|
-
? axisOnHover === 'x'
|
|
88
|
-
? assignmentOnHover.x || []
|
|
89
|
-
: axisOnHover === 'y'
|
|
90
|
-
? assignmentOnHover.y || []
|
|
91
|
-
: (assignmentOnHover.x || []).concat(assignmentOnHover.y || [])
|
|
92
|
-
: (assignmentOnHover.x || []).concat(assignmentOnHover.y || [])
|
|
93
|
-
: []
|
|
94
|
-
: [];
|
|
67
|
+
export function getCurrentDiaIDsToHighlight(assignmentData) {
|
|
68
|
+
const { highlighted, assignments } = assignmentData.data;
|
|
69
|
+
const assignment = highlighted ? assignments[highlighted.id] : null;
|
|
70
|
+
const axisHover = highlighted ? highlighted.axis : null;
|
|
71
|
+
if (axisHover && assignment && assignment[axisHover]) {
|
|
72
|
+
return assignment[axisHover];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return (assignment?.x || []).concat(assignment?.y || []);
|
|
76
|
+
}
|
|
95
77
|
}
|
|
96
|
-
export function toggleDiaIDs(
|
|
97
|
-
let
|
|
78
|
+
export function toggleDiaIDs(diaIDs, atomInformation) {
|
|
79
|
+
let _diaIDs = diaIDs ? diaIDs.slice() : [];
|
|
98
80
|
const { nbAtoms, oclIDs } = atomInformation;
|
|
99
81
|
let tempNbAtoms = nbAtoms;
|
|
100
82
|
oclIDs.forEach((_oclID) => {
|
|
101
|
-
if (
|
|
83
|
+
if (_diaIDs.includes(_oclID)) {
|
|
102
84
|
tempNbAtoms *= -1;
|
|
103
|
-
|
|
85
|
+
_diaIDs = _diaIDs.filter((_id) => _id !== _oclID);
|
|
104
86
|
}
|
|
105
87
|
else {
|
|
106
|
-
|
|
88
|
+
_diaIDs.push(_oclID);
|
|
107
89
|
}
|
|
108
90
|
});
|
|
109
|
-
return [
|
|
91
|
+
return [_diaIDs, tempNbAtoms];
|
|
110
92
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default function useAtomAssignment({ displayerMode, activeTab, zones, ranges, }: {
|
|
1
|
+
export default function useAtomAssignment({ displayerMode, activeTab: nucleus, zones, ranges, }: {
|
|
2
2
|
displayerMode: any;
|
|
3
3
|
activeTab: any;
|
|
4
4
|
zones: any;
|
|
@@ -6,6 +6,6 @@ export default function useAtomAssignment({ displayerMode, activeTab, zones, ran
|
|
|
6
6
|
}): {
|
|
7
7
|
handleOnAtomHover: (atom: any) => void;
|
|
8
8
|
handleOnClickAtom: (atom: any, event: any) => void;
|
|
9
|
-
currentDiaIDsToHighlight:
|
|
9
|
+
currentDiaIDsToHighlight: string[];
|
|
10
10
|
assignedDiaIDsMerged: any[];
|
|
11
11
|
};
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { ConcatenationString } from '../../../data/utilities/Concatenation';
|
|
3
3
|
import checkModifierKeyActivated from '../../../data/utilities/checkModifierKeyActivated';
|
|
4
|
-
import {
|
|
4
|
+
import { useAssignment, useAssignmentData, } from '../../assignment/AssignmentsContext';
|
|
5
|
+
import { filterForIDsWithAssignment } from '../../assignment/utilities/filterForIDsWithAssignment';
|
|
5
6
|
import { useDispatch } from '../../context/DispatchContext';
|
|
6
7
|
import { useAlert } from '../../elements/popup/Alert';
|
|
7
8
|
import { HighlightedSource, useHighlightData } from '../../highlight';
|
|
8
9
|
import { DISPLAYER_MODE } from '../../reducer/core/Constants';
|
|
9
10
|
import { SET_DIAID_RANGE, SET_DIAID_ZONE } from '../../reducer/types/Types';
|
|
10
11
|
import { extractFromAtom, findDatumAndSignalIndex, getCurrentDiaIDsToHighlight, getHighlightsOnHover, toggleDiaIDs, } from './Utilities';
|
|
11
|
-
export default function useAtomAssignment({ displayerMode, activeTab, zones, ranges, }) {
|
|
12
|
+
export default function useAtomAssignment({ displayerMode, activeTab: nucleus, zones, ranges, }) {
|
|
12
13
|
const alert = useAlert();
|
|
13
14
|
const dispatch = useDispatch();
|
|
14
15
|
const highlightData = useHighlightData();
|
|
15
|
-
const
|
|
16
|
-
const activeAssignment = useAssignment(
|
|
17
|
-
?
|
|
16
|
+
const assignments = useAssignmentData();
|
|
17
|
+
const activeAssignment = useAssignment(assignments.data.activated
|
|
18
|
+
? assignments.data.activated.id
|
|
18
19
|
: ConcatenationString);
|
|
19
20
|
const [onAtomHoverHighlights, setOnAtomHoverHighlights] = useState([]);
|
|
20
21
|
const [onAtomHoverAction, setOnAtomHoverAction] = useState(null);
|
|
21
|
-
const [elements, setElements] = useState([]);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (activeTab) {
|
|
24
|
-
const split = activeTab.split(',');
|
|
25
|
-
if (split.length === 1) {
|
|
26
|
-
setElements([activeTab.replace(/[0-9]/g, '')]);
|
|
27
|
-
}
|
|
28
|
-
else if (split.length === 2) {
|
|
29
|
-
setElements(split.map((nucleus) => nucleus.replace(/[0-9]/g, '')));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}, [activeTab]);
|
|
33
22
|
useEffect(() => {
|
|
34
23
|
if (onAtomHoverAction) {
|
|
35
24
|
if (onAtomHoverAction === 'show') {
|
|
@@ -63,23 +52,24 @@ export default function useAtomAssignment({ displayerMode, activeTab, zones, ran
|
|
|
63
52
|
}, [displayerMode, ranges, zones]);
|
|
64
53
|
const assignedDiaIDs = useMemo(() => {
|
|
65
54
|
const assignedDiaID = { x: [], y: [] };
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
const assignment = assignments.data.assignments;
|
|
56
|
+
for (let id in assignment) {
|
|
57
|
+
if (assignment[id].x) {
|
|
58
|
+
assignedDiaID.x.push(...assignment[id].x);
|
|
69
59
|
}
|
|
70
|
-
if (
|
|
71
|
-
assignedDiaID.y.push(...
|
|
60
|
+
if (assignment[id].y) {
|
|
61
|
+
assignedDiaID.y.push(...assignment[id].y);
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
64
|
// with its structure it's prepared for showing assigned IDs per axis
|
|
75
65
|
return assignedDiaID;
|
|
76
|
-
}, [
|
|
66
|
+
}, [assignments.data]);
|
|
77
67
|
// used for atom highlighting for now, until we would like to highlight atoms per axis separately
|
|
78
68
|
const assignedDiaIDsMerged = useMemo(() => assignedDiaIDs.x.concat(assignedDiaIDs.y), [assignedDiaIDs.x, assignedDiaIDs.y]);
|
|
79
69
|
const currentDiaIDsToHighlight = useMemo(() => {
|
|
80
70
|
let highlights = [];
|
|
81
71
|
highlightData.highlight.highlighted.forEach((highlightID) => {
|
|
82
|
-
const temp =
|
|
72
|
+
const temp = assignments.data.assignments[highlightID];
|
|
83
73
|
if (temp) {
|
|
84
74
|
const { datum } = findDatumAndSignalIndex(data, highlightID);
|
|
85
75
|
const type = highlightData.highlight.sourceData?.type;
|
|
@@ -87,56 +77,51 @@ export default function useAtomAssignment({ displayerMode, activeTab, zones, ran
|
|
|
87
77
|
(type === HighlightedSource.ZONE || type === HighlightedSource.RANGE)) {
|
|
88
78
|
// we are on range/zone level only, so add the belonging signal IDs to highlight too
|
|
89
79
|
highlights = highlights.concat(datum.signals
|
|
90
|
-
.map((signal) => filterForIDsWithAssignment(
|
|
91
|
-
0
|
|
80
|
+
.map((signal) => filterForIDsWithAssignment(assignments, [signal.id]).length > 0
|
|
92
81
|
? signal.diaIDs
|
|
93
82
|
: [])
|
|
94
83
|
.flat());
|
|
95
84
|
}
|
|
96
85
|
}
|
|
97
86
|
});
|
|
98
|
-
return getCurrentDiaIDsToHighlight(
|
|
99
|
-
}, [
|
|
87
|
+
return getCurrentDiaIDsToHighlight(assignments).concat(highlights);
|
|
88
|
+
}, [
|
|
89
|
+
assignments,
|
|
90
|
+
data,
|
|
91
|
+
highlightData.highlight.highlighted,
|
|
92
|
+
highlightData.highlight.sourceData?.type,
|
|
93
|
+
]);
|
|
100
94
|
const toggleAssignment = useCallback((diaID, atomInformation) => {
|
|
101
95
|
// a previous version of the code prevented to assign many time the same atom
|
|
102
96
|
// see revision cc13abc18f77b6787b923e3c4edaef51750d9e90
|
|
103
97
|
return toggleDiaIDs(diaID, atomInformation);
|
|
104
98
|
}, []);
|
|
105
99
|
const handleOnClickAtom = useCallback((atom, event) => {
|
|
106
|
-
if (!checkModifierKeyActivated(event)) {
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
if (!checkModifierKeyActivated(event) && activeAssignment.activated) {
|
|
101
|
+
const { axis, id } = activeAssignment.activated;
|
|
102
|
+
if (id && axis) {
|
|
103
|
+
const atomInformation = extractFromAtom(atom, nucleus, axis);
|
|
109
104
|
if (atomInformation.nbAtoms > 0) {
|
|
110
105
|
// save assignment in assignment hook
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
const dimension = displayerMode === DISPLAYER_MODE.DM_1D ? '1D' : '2D';
|
|
107
|
+
activeAssignment.toggle(atomInformation.oclIDs, dimension);
|
|
108
|
+
// console.log(activeAssignment);
|
|
114
109
|
// save assignment (diaIDs) in range/zone data
|
|
115
110
|
const { datum, signalIndex } = findDatumAndSignalIndex(data, activeAssignment.id);
|
|
116
111
|
if (datum) {
|
|
117
112
|
// determine the level of setting the diaIDs array (range vs. signal level) and save there
|
|
118
|
-
let
|
|
119
|
-
let nbAtoms = 0;
|
|
113
|
+
// let nbAtoms = 0;
|
|
120
114
|
// on range/zone level
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
[_diaID, nbAtoms] = toggleAssignment(datum[activeAssignment.activeAxis].diaIDs || [], atomInformation);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (datum.signals?.[signalIndex]) {
|
|
130
|
-
// on signal level
|
|
131
|
-
if (displayerMode === DISPLAYER_MODE.DM_1D) {
|
|
132
|
-
[_diaID, nbAtoms] = toggleAssignment(datum.signals[signalIndex].diaIDs || [], atomInformation);
|
|
115
|
+
if (displayerMode === DISPLAYER_MODE.DM_1D) {
|
|
116
|
+
const range = datum;
|
|
117
|
+
let _diaIDs = [];
|
|
118
|
+
if (signalIndex === undefined) {
|
|
119
|
+
_diaIDs = range?.diaIDs || [];
|
|
133
120
|
}
|
|
134
|
-
else
|
|
135
|
-
|
|
136
|
-
.diaIDs || [], atomInformation);
|
|
121
|
+
else {
|
|
122
|
+
_diaIDs = range?.signals[signalIndex]?.diaIDs || [];
|
|
137
123
|
}
|
|
138
|
-
|
|
139
|
-
if (displayerMode === DISPLAYER_MODE.DM_1D) {
|
|
124
|
+
const [_diaID, nbAtoms] = toggleAssignment(_diaIDs, atomInformation);
|
|
140
125
|
dispatch({
|
|
141
126
|
type: SET_DIAID_RANGE,
|
|
142
127
|
payload: {
|
|
@@ -147,20 +132,29 @@ export default function useAtomAssignment({ displayerMode, activeTab, zones, ran
|
|
|
147
132
|
},
|
|
148
133
|
});
|
|
149
134
|
}
|
|
150
|
-
else
|
|
135
|
+
else {
|
|
136
|
+
const zone = datum;
|
|
137
|
+
let _diaIDs = [];
|
|
138
|
+
if (signalIndex === undefined) {
|
|
139
|
+
_diaIDs = zone[axis]?.diaIDs || [];
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
_diaIDs = zone?.signals[signalIndex][axis]?.diaIDs || [];
|
|
143
|
+
}
|
|
144
|
+
const [_diaID, nbAtoms] = toggleAssignment(_diaIDs, atomInformation);
|
|
151
145
|
dispatch({
|
|
152
146
|
type: SET_DIAID_ZONE,
|
|
153
147
|
payload: {
|
|
154
148
|
nbAtoms,
|
|
155
149
|
zoneData: datum,
|
|
156
150
|
diaIDs: _diaID,
|
|
157
|
-
axis:
|
|
151
|
+
axis: axis,
|
|
158
152
|
signalIndex,
|
|
159
153
|
},
|
|
160
154
|
});
|
|
161
155
|
}
|
|
162
156
|
}
|
|
163
|
-
activeAssignment.
|
|
157
|
+
activeAssignment.setActive(axis);
|
|
164
158
|
}
|
|
165
159
|
else {
|
|
166
160
|
alert.info('Not assigned! Different atom type or no attached hydrogens found!');
|
|
@@ -173,15 +167,15 @@ export default function useAtomAssignment({ displayerMode, activeTab, zones, ran
|
|
|
173
167
|
data,
|
|
174
168
|
dispatch,
|
|
175
169
|
displayerMode,
|
|
176
|
-
|
|
170
|
+
nucleus,
|
|
177
171
|
toggleAssignment,
|
|
178
172
|
]);
|
|
179
173
|
const handleOnAtomHover = useCallback((atom) => {
|
|
180
|
-
const oclIDs = extractFromAtom(atom,
|
|
174
|
+
const { oclIDs } = extractFromAtom(atom, nucleus);
|
|
181
175
|
// on enter the atom
|
|
182
176
|
if (oclIDs.length > 0) {
|
|
183
177
|
// set all IDs to highlight when hovering over an atom from assignment data
|
|
184
|
-
const highlights = getHighlightsOnHover(
|
|
178
|
+
const highlights = getHighlightsOnHover(assignments, oclIDs, data);
|
|
185
179
|
setOnAtomHoverHighlights(highlights);
|
|
186
180
|
setOnAtomHoverAction('show');
|
|
187
181
|
}
|
|
@@ -189,7 +183,8 @@ export default function useAtomAssignment({ displayerMode, activeTab, zones, ran
|
|
|
189
183
|
// on leave the atom
|
|
190
184
|
setOnAtomHoverAction('hide');
|
|
191
185
|
}
|
|
192
|
-
|
|
186
|
+
// }
|
|
187
|
+
}, [assignments, data, nucleus]);
|
|
193
188
|
return {
|
|
194
189
|
handleOnAtomHover,
|
|
195
190
|
handleOnClickAtom,
|
|
@@ -7,7 +7,7 @@ import { rangesToACS } from 'nmr-processing';
|
|
|
7
7
|
import { useCallback } from 'react';
|
|
8
8
|
import { FaFileExport, FaUnlink, FaSitemap, FaChartBar } from 'react-icons/fa';
|
|
9
9
|
import { ImLink } from 'react-icons/im';
|
|
10
|
-
import { useAssignmentData } from '../../assignment';
|
|
10
|
+
import { useAssignmentData } from '../../assignment/AssignmentsContext';
|
|
11
11
|
import { useDispatch } from '../../context/DispatchContext';
|
|
12
12
|
import { usePreferences } from '../../context/PreferencesContext';
|
|
13
13
|
import Button from '../../elements/ButtonToolTip';
|
|
@@ -102,7 +102,7 @@ function RangesHeader({ ranges, info, onUnlink, onFilterActivated, onSettingClic
|
|
|
102
102
|
}, [alert]);
|
|
103
103
|
const saveAsHTMLHandler = useCallback(() => {
|
|
104
104
|
const { originFrequency: observedFrequency, nucleus } = info;
|
|
105
|
-
const format = lodashGet(preferences.current, `formatting.
|
|
105
|
+
const format = lodashGet(preferences.current, `formatting.nuclei[${nucleus.toLowerCase()}]`, '0.0');
|
|
106
106
|
const nbDecimalDelta = getNumberOfDecimals(format.ppm);
|
|
107
107
|
const nbDecimalJ = getNumberOfDecimals(format.hz);
|
|
108
108
|
const result = rangesToACS(ranges.values, {
|
|
@@ -4,7 +4,7 @@ import { css } from '@emotion/react';
|
|
|
4
4
|
import lodashGet from 'lodash/get';
|
|
5
5
|
import { xGetFromToIndex } from 'ml-spectra-processing';
|
|
6
6
|
import { useCallback, useMemo, memo, useState, useRef } from 'react';
|
|
7
|
-
import { useAssignmentData } from '../../assignment';
|
|
7
|
+
import { useAssignmentData } from '../../assignment/AssignmentsContext';
|
|
8
8
|
import { useChartData } from '../../context/ChartContext';
|
|
9
9
|
import { useDispatch } from '../../context/DispatchContext';
|
|
10
10
|
import { usePreferences } from '../../context/PreferencesContext';
|