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
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
2
2
|
/** @jsxImportSource @emotion/react */
|
|
3
3
|
import lodashGet from 'lodash/get';
|
|
4
4
|
import { useMemo, useState, useEffect } from 'react';
|
|
5
|
-
import { useAssignment } from '../../assignment';
|
|
5
|
+
import { useAssignment } from '../../assignment/AssignmentsContext';
|
|
6
6
|
import { useChartData } from '../../context/ChartContext';
|
|
7
7
|
import { useScaleChecked } from '../../context/ScaleContext';
|
|
8
8
|
import { HighlightedSource, useHighlight } from '../../highlight';
|
|
@@ -18,7 +18,7 @@ const styles = {
|
|
|
18
18
|
strokeWidth: 1,
|
|
19
19
|
};
|
|
20
20
|
function extractID(assignment) {
|
|
21
|
-
return [assignment.id].concat(assignment.assigned
|
|
21
|
+
return [assignment.id].concat(assignment.assigned?.x || []);
|
|
22
22
|
}
|
|
23
23
|
function MultiplicityTree({ rangeFrom, rangeTo, signal, labelOptions = {
|
|
24
24
|
distance: 10,
|
|
@@ -169,11 +169,11 @@ function MultiplicityTree({ rangeFrom, rangeTo, signal, labelOptions = {
|
|
|
169
169
|
? { ...styles, opacity: 1, strokeWidth: 1.5 }
|
|
170
170
|
: styles, ...{
|
|
171
171
|
onMouseEnter: () => {
|
|
172
|
-
assignment.
|
|
172
|
+
assignment.show('x');
|
|
173
173
|
highlight.show();
|
|
174
174
|
},
|
|
175
175
|
onMouseLeave: () => {
|
|
176
|
-
assignment.
|
|
176
|
+
assignment.hide();
|
|
177
177
|
highlight.hide();
|
|
178
178
|
},
|
|
179
179
|
}, ...{
|
|
@@ -184,7 +184,7 @@ function MultiplicityTree({ rangeFrom, rangeTo, signal, labelOptions = {
|
|
|
184
184
|
: (e) => {
|
|
185
185
|
if (e.shiftKey) {
|
|
186
186
|
e.stopPropagation();
|
|
187
|
-
assignment.
|
|
187
|
+
assignment.setActive('x');
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
}, children: multiplicityTree }));
|
|
@@ -3,7 +3,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
4
|
import { useCallback, useState, useEffect } from 'react';
|
|
5
5
|
import { checkRangeKind } from '../../../data/utilities/RangeUtilities';
|
|
6
|
-
import {
|
|
6
|
+
import { useAssignment, useAssignmentData, } from '../../assignment/AssignmentsContext';
|
|
7
|
+
import { filterForIDsWithAssignment } from '../../assignment/utilities/filterForIDsWithAssignment';
|
|
7
8
|
import { useDispatch } from '../../context/DispatchContext';
|
|
8
9
|
import { useScaleChecked } from '../../context/ScaleContext';
|
|
9
10
|
import Resizer from '../../elements/resizer/Resizer';
|
|
@@ -44,7 +45,7 @@ function Range({ rangeData, showMultiplicityTrees, selectedTool, startEditMode,
|
|
|
44
45
|
const { id, from, to, integration, signals } = rangeData;
|
|
45
46
|
const assignmentData = useAssignmentData();
|
|
46
47
|
const assignmentRange = useAssignment(id);
|
|
47
|
-
const highlightRange = useHighlight([assignmentRange.id].concat(assignmentRange.assigned
|
|
48
|
+
const highlightRange = useHighlight([assignmentRange.id].concat(assignmentRange.assigned?.x || []).concat(filterForIDsWithAssignment(assignmentData, signals.map((_signal) => _signal.id))), { type: HighlightedSource.RANGE, extra: { id } });
|
|
48
49
|
const { scaleX } = useScaleChecked();
|
|
49
50
|
const dispatch = useDispatch();
|
|
50
51
|
const [reduceOpacity, setReduceOpacity] = useState(false);
|
|
@@ -71,18 +72,18 @@ function Range({ rangeData, showMultiplicityTrees, selectedTool, startEditMode,
|
|
|
71
72
|
});
|
|
72
73
|
}, [dispatch, rangeData, scaleX]);
|
|
73
74
|
const mouseEnterHandler = useCallback(() => {
|
|
74
|
-
assignmentRange.
|
|
75
|
+
assignmentRange.show('x');
|
|
75
76
|
highlightRange.show();
|
|
76
77
|
}, [assignmentRange, highlightRange]);
|
|
77
78
|
const mouseLeaveHandler = useCallback(() => {
|
|
78
|
-
assignmentRange.
|
|
79
|
+
assignmentRange.hide();
|
|
79
80
|
highlightRange.hide();
|
|
80
81
|
}, [assignmentRange, highlightRange]);
|
|
81
82
|
const assignHandler = useCallback((e) => {
|
|
82
83
|
if (selectedTool === options.rangesPicking.id &&
|
|
83
84
|
e.shiftKey &&
|
|
84
85
|
!isBlockedByEditing) {
|
|
85
|
-
assignmentRange.
|
|
86
|
+
assignmentRange.setActive('x');
|
|
86
87
|
}
|
|
87
88
|
}, [assignmentRange, isBlockedByEditing, selectedTool]);
|
|
88
89
|
return (_jsxs("g", { "data-test-id": "range", style: { outline: 'none' }, css: isBlockedByEditing ||
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
2
2
|
/** @jsxImportSource @emotion/react */
|
|
3
3
|
import { memo, useState, useEffect, useCallback } from 'react';
|
|
4
4
|
import { buildID } from '../../../data/utilities/Concatenation';
|
|
5
|
-
import { useAssignment } from '../../assignment';
|
|
5
|
+
import { useAssignment } from '../../assignment/AssignmentsContext';
|
|
6
6
|
import { useChartData } from '../../context/ChartContext';
|
|
7
7
|
import { useHighlightData, useHighlight } from '../../highlight';
|
|
8
8
|
import { get2DXScale, get2DYScale } from '../utilities/scale';
|
|
@@ -34,13 +34,13 @@ const Signal = memo(({ signal, isVisible }) => {
|
|
|
34
34
|
]);
|
|
35
35
|
if (!signal)
|
|
36
36
|
return null;
|
|
37
|
-
return (_jsxs("g", { className: "zone-signal", onMouseEnter: () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
return (_jsxs("g", { className: "zone-signal", children: [isVisible.signals && (_jsxs("g", { children: [_jsx(SignalCrosshair, { signal: signal }), _jsx("circle", { onMouseEnter: () => {
|
|
38
|
+
assignment.show();
|
|
39
|
+
highlight.show();
|
|
40
|
+
}, onMouseLeave: () => {
|
|
41
|
+
assignment.hide();
|
|
42
|
+
highlight.hide();
|
|
43
|
+
}, cx: scaleX(signal.x.delta || 0), cy: scaleY(signal.y.delta || 0), r: isHighlighted ? 6 : 4, fill: isHighlighted ? 'green' : 'darkgreen' }, signal.id)] })), _jsx("g", { className: "zone-signal-peak", style: { pointerEvents: 'none' }, children: isVisible.peaks &&
|
|
44
44
|
signal.peaks &&
|
|
45
45
|
signal.peaks.map((peak, i) => (_jsx("circle", { cx: scaleX(peak.x), cy: scaleY(peak.y), r: 2, fill: "black" }, `${signal.id + i}`))) })] }));
|
|
46
46
|
});
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
4
|
import { useState, useEffect } from 'react';
|
|
5
5
|
import { checkZoneKind } from '../../../data/utilities/ZoneUtilities';
|
|
6
|
-
import { useAssignment } from '../../assignment';
|
|
6
|
+
import { useAssignment } from '../../assignment/AssignmentsContext';
|
|
7
7
|
import { useChartData } from '../../context/ChartContext';
|
|
8
8
|
import { HighlightedSource, useHighlight } from '../../highlight';
|
|
9
9
|
import { get2DXScale, get2DYScale } from '../utilities/scale';
|
|
@@ -54,10 +54,10 @@ const Zone = ({ zoneData, isVisible }) => {
|
|
|
54
54
|
return (_jsxs("g", { css: highlightZone.isActive || assignmentZone.isActive
|
|
55
55
|
? stylesHighlighted
|
|
56
56
|
: stylesOnHover, onMouseEnter: () => {
|
|
57
|
-
assignmentZone.
|
|
57
|
+
assignmentZone.show();
|
|
58
58
|
highlightZone.show();
|
|
59
59
|
}, onMouseLeave: () => {
|
|
60
|
-
assignmentZone.
|
|
60
|
+
assignmentZone.hide();
|
|
61
61
|
highlightZone.hide();
|
|
62
62
|
}, children: [isVisible.zones && (_jsx("g", { transform: `translate(${scaleX(x2)},${scaleY(y1)})`, children: _jsx("rect", { x: "0", width: scaleX(x1) - scaleX(x2), height: scaleY(y2) - scaleY(y1), className: "Integral-area", fill: "#0000000f", stroke: reduceOpacity ? '#343a40' : 'darkgreen', strokeWidth: reduceOpacity ? '0' : '1' }) })), signals.map((_signal, i) => (_jsx(Signal, { signal: _signal, isVisible: isVisible }, `${id + i}`)))] }, id));
|
|
63
63
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
2
|
import checkModifierKeyActivated from '../../data/utilities/checkModifierKeyActivated';
|
|
3
|
-
import { useAssignmentData } from '../assignment';
|
|
3
|
+
import { useAssignmentData } from '../assignment/AssignmentsContext';
|
|
4
4
|
import { useChartData } from '../context/ChartContext';
|
|
5
5
|
import { useDispatch } from '../context/DispatchContext';
|
|
6
6
|
import { useLoader } from '../context/LoaderContext';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AssignmentsActions } from './AssignmentsReducer';
|
|
3
|
+
export declare type Axis = 'x' | 'y';
|
|
4
|
+
export declare type Assignment = Record<Axis, string[]>;
|
|
5
|
+
export declare type Assignments = Record<string, Assignment>;
|
|
6
|
+
export declare type AssignmentDimension = '1D' | '2D';
|
|
7
|
+
export interface AssignmentAction {
|
|
8
|
+
id: string;
|
|
9
|
+
axis: Axis | null;
|
|
10
|
+
}
|
|
11
|
+
export interface AssignmentState {
|
|
12
|
+
assignments: Assignments;
|
|
13
|
+
activated: AssignmentAction | null;
|
|
14
|
+
highlighted: AssignmentAction | null;
|
|
15
|
+
}
|
|
16
|
+
export interface AssignmentContext {
|
|
17
|
+
data: AssignmentState;
|
|
18
|
+
dispatch: (action: AssignmentsActions) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface AssignmentsData extends Pick<AssignmentState, 'activated' | 'highlighted'> {
|
|
21
|
+
id: string;
|
|
22
|
+
isActive: boolean;
|
|
23
|
+
isOver: boolean;
|
|
24
|
+
assigned: Record<Axis, string[]>;
|
|
25
|
+
removeAll: (axis: Axis) => void;
|
|
26
|
+
toggle: (atomIDs: string[], dimension: AssignmentDimension) => void;
|
|
27
|
+
setActive: (axis: Axis) => void;
|
|
28
|
+
show: (axis?: Axis) => void;
|
|
29
|
+
hide: () => void;
|
|
30
|
+
}
|
|
31
|
+
export declare const assignmentState: AssignmentState;
|
|
32
|
+
export declare const assignmentContext: import("react").Context<AssignmentContext>;
|
|
33
|
+
export declare const AssignmentProvider: import("react").Provider<AssignmentContext>;
|
|
34
|
+
export declare function useAssignmentData(): AssignmentContext;
|
|
35
|
+
export declare function useAssignment(key: any): AssignmentsData;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useMemo } from 'react';
|
|
2
|
+
export const assignmentState = {
|
|
3
|
+
assignments: {},
|
|
4
|
+
activated: null,
|
|
5
|
+
highlighted: null,
|
|
6
|
+
};
|
|
7
|
+
export const assignmentContext = createContext({
|
|
8
|
+
data: assignmentState,
|
|
9
|
+
dispatch: () => null,
|
|
10
|
+
});
|
|
11
|
+
export const AssignmentProvider = assignmentContext.Provider;
|
|
12
|
+
export function useAssignmentData() {
|
|
13
|
+
const context = useContext(assignmentContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error('Assignment context was not found');
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
}
|
|
19
|
+
// key can be signal id,range id or zone id
|
|
20
|
+
export function useAssignment(key) {
|
|
21
|
+
const { data: { activated, highlighted, assignments }, dispatch, } = useAssignmentData();
|
|
22
|
+
if ((typeof key !== 'string' && typeof key !== 'number') || key === '') {
|
|
23
|
+
throw new Error(`assignment key must be a non-empty string or number`);
|
|
24
|
+
}
|
|
25
|
+
const id = String(key);
|
|
26
|
+
const isActive = useMemo(() => {
|
|
27
|
+
return activated?.id === id;
|
|
28
|
+
}, [activated?.id, id]);
|
|
29
|
+
const isOver = useMemo(() => {
|
|
30
|
+
return highlighted?.id === id;
|
|
31
|
+
}, [highlighted?.id, id]);
|
|
32
|
+
const assigned = useMemo(() => {
|
|
33
|
+
return assignments[id] || null;
|
|
34
|
+
}, [assignments, id]);
|
|
35
|
+
const removeAll = useCallback((axis) => {
|
|
36
|
+
dispatch({
|
|
37
|
+
type: 'REMOVE',
|
|
38
|
+
payload: { ids: [id], axis },
|
|
39
|
+
});
|
|
40
|
+
}, [dispatch, id]);
|
|
41
|
+
const toggle = useCallback((atomIDs, dimension) => {
|
|
42
|
+
dispatch({
|
|
43
|
+
type: 'TOGGLE',
|
|
44
|
+
payload: { atomIDs, id, dimension },
|
|
45
|
+
});
|
|
46
|
+
}, [dispatch, id]);
|
|
47
|
+
const setActive = useCallback((axis) => {
|
|
48
|
+
dispatch({
|
|
49
|
+
type: 'SET_ACTIVE',
|
|
50
|
+
payload: {
|
|
51
|
+
id,
|
|
52
|
+
axis,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}, [dispatch, id]);
|
|
56
|
+
const show = useCallback((axis) => {
|
|
57
|
+
dispatch({
|
|
58
|
+
type: 'SHOW',
|
|
59
|
+
payload: {
|
|
60
|
+
id,
|
|
61
|
+
axis,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}, [dispatch, id]);
|
|
65
|
+
const hide = useCallback(() => {
|
|
66
|
+
dispatch({
|
|
67
|
+
type: 'HIDE',
|
|
68
|
+
});
|
|
69
|
+
}, [dispatch]);
|
|
70
|
+
return {
|
|
71
|
+
id,
|
|
72
|
+
activated,
|
|
73
|
+
isActive,
|
|
74
|
+
isOver,
|
|
75
|
+
highlighted,
|
|
76
|
+
assigned,
|
|
77
|
+
removeAll,
|
|
78
|
+
toggle,
|
|
79
|
+
setActive,
|
|
80
|
+
show,
|
|
81
|
+
hide,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Data1D } from '../../data/types/data1d';
|
|
2
|
+
import { Data2D } from '../../data/types/data2d';
|
|
3
|
+
import { ActionType } from '../reducer/types/Types';
|
|
4
|
+
import { AssignmentDimension, AssignmentState, Axis } from './AssignmentsContext';
|
|
5
|
+
export declare type InitiateAction = ActionType<'INITIATE_ASSIGNMENTS', {
|
|
6
|
+
spectra: (Data1D | Data2D)[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare type ToggleAction = ActionType<'TOGGLE', {
|
|
9
|
+
atomIDs: string[];
|
|
10
|
+
id: string;
|
|
11
|
+
dimension: AssignmentDimension;
|
|
12
|
+
}>;
|
|
13
|
+
export declare type AddAction = ActionType<'ADD', {
|
|
14
|
+
id: string;
|
|
15
|
+
atomID: string;
|
|
16
|
+
axis: Axis;
|
|
17
|
+
}>;
|
|
18
|
+
export declare type RemoveAction = ActionType<'REMOVE', {
|
|
19
|
+
ids: string[];
|
|
20
|
+
atomID?: string;
|
|
21
|
+
axis: Axis;
|
|
22
|
+
}>;
|
|
23
|
+
export declare type SetActiveAction = ActionType<'SET_ACTIVE', {
|
|
24
|
+
id: string;
|
|
25
|
+
axis: Axis;
|
|
26
|
+
}>;
|
|
27
|
+
export declare type ShowAction = ActionType<'SHOW', {
|
|
28
|
+
id: string;
|
|
29
|
+
axis?: Axis;
|
|
30
|
+
}>;
|
|
31
|
+
export declare type AssignmentsActions = InitiateAction | ToggleAction | AddAction | RemoveAction | SetActiveAction | ShowAction | ActionType<'HIDE'>;
|
|
32
|
+
export default function assignmentReducer(state: AssignmentState, action: AssignmentsActions): AssignmentState;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import initAssignment from './actions/initAssignment';
|
|
2
|
+
import removeAssignments from './actions/removeAssignment';
|
|
3
|
+
import setActiveAssignment from './actions/setActiveAssignment';
|
|
4
|
+
import toggleAssignment from './actions/toggleAssignment';
|
|
5
|
+
export default function assignmentReducer(state, action) {
|
|
6
|
+
switch (action.type) {
|
|
7
|
+
case 'INITIATE_ASSIGNMENTS': {
|
|
8
|
+
return initAssignment(action);
|
|
9
|
+
}
|
|
10
|
+
case 'REMOVE': {
|
|
11
|
+
const { axis, ids, atomID } = action.payload;
|
|
12
|
+
return removeAssignments(state, { axis, ids, atomID });
|
|
13
|
+
}
|
|
14
|
+
case 'TOGGLE': {
|
|
15
|
+
return toggleAssignment(state, action);
|
|
16
|
+
}
|
|
17
|
+
case 'SET_ACTIVE': {
|
|
18
|
+
return setActiveAssignment(state, action);
|
|
19
|
+
}
|
|
20
|
+
case 'SHOW': {
|
|
21
|
+
const { id, axis } = action.payload;
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
highlighted: {
|
|
25
|
+
id,
|
|
26
|
+
axis: axis || null,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case 'HIDE': {
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
highlighted: null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
default:
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isSpectrum1D } from '../../../data/data1d/Spectrum1D';
|
|
2
|
+
import { assignmentState } from '../AssignmentsContext';
|
|
3
|
+
export default function initAssignment(action) {
|
|
4
|
+
const newState = {
|
|
5
|
+
...assignmentState,
|
|
6
|
+
};
|
|
7
|
+
const spectra = (action.payload.spectra || []);
|
|
8
|
+
for (const spectrum of spectra) {
|
|
9
|
+
if (isSpectrum1D(spectrum)) {
|
|
10
|
+
setRangesAssignments(newState, spectrum.ranges);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
setZonesAssignments(newState, spectrum.zones);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return newState;
|
|
17
|
+
}
|
|
18
|
+
function setRangesAssignments(state, ranges) {
|
|
19
|
+
const diaIDRecords = ranges.values.reduce((acc, { id, diaIDs, signals }) => {
|
|
20
|
+
acc.push({ id, diaIDs: diaIDs || [] });
|
|
21
|
+
for (const signal of signals) {
|
|
22
|
+
acc.push({ id: signal.id, diaIDs: signal.diaIDs || [] });
|
|
23
|
+
}
|
|
24
|
+
return acc;
|
|
25
|
+
}, []);
|
|
26
|
+
for (const { id, diaIDs } of diaIDRecords) {
|
|
27
|
+
for (const diaID of diaIDs) {
|
|
28
|
+
setAssignment(state, id, 'x', diaID);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function setZonesAssignments(state, zones) {
|
|
33
|
+
const diaIDRecords = zones.values.reduce((acc, { id, x, y, signals }) => {
|
|
34
|
+
acc.push({ id, diaIDs: { x: x.diaIDs || [], y: y.diaIDs || [] } });
|
|
35
|
+
for (const signal of signals) {
|
|
36
|
+
acc.push({
|
|
37
|
+
id: signal.id,
|
|
38
|
+
diaIDs: { x: signal.x.diaIDs || [], y: signal.y.diaIDs || [] },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return acc;
|
|
42
|
+
}, []);
|
|
43
|
+
for (const { id, diaIDs } of diaIDRecords) {
|
|
44
|
+
['x', 'y'].forEach((axis) => {
|
|
45
|
+
for (const diaID of diaIDs[axis]) {
|
|
46
|
+
setAssignment(state, id, axis, diaID);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function setAssignment(state, id, axis, diaID) {
|
|
52
|
+
if (Array.isArray(state.assignments?.[id]?.[axis]) &&
|
|
53
|
+
!state.assignments[id][axis].includes(diaID)) {
|
|
54
|
+
state.assignments[id][axis].push(diaID);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
state.assignments = {
|
|
58
|
+
...state.assignments,
|
|
59
|
+
[id]: { ...state.assignments[id], [axis]: [diaID] },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AssignmentState, Axis } from '../AssignmentsContext';
|
|
2
|
+
interface RemoveAction {
|
|
3
|
+
ids: string[];
|
|
4
|
+
atomID?: string;
|
|
5
|
+
axis: Axis;
|
|
6
|
+
}
|
|
7
|
+
interface AssignmentRemoveOptions extends Omit<RemoveAction, 'ids'> {
|
|
8
|
+
id: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function removeAssignment(state: AssignmentState, options: AssignmentRemoveOptions): void;
|
|
11
|
+
export default function removeAssignments(state: AssignmentState, action: RemoveAction): {
|
|
12
|
+
assignments: import("../AssignmentsContext").Assignments;
|
|
13
|
+
activated: import("../AssignmentsContext").AssignmentAction | null;
|
|
14
|
+
highlighted: import("../AssignmentsContext").AssignmentAction | null;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function removeAssignment(state, options) {
|
|
2
|
+
const { id, atomID = '', axis } = options;
|
|
3
|
+
const atomIDs = state.assignments?.[id]?.[axis] || null;
|
|
4
|
+
if (atomIDs) {
|
|
5
|
+
if (atomID) {
|
|
6
|
+
atomIDs.filter((id) => id !== atomID);
|
|
7
|
+
state.assignments[id][axis] = atomIDs;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
state.assignments[id][axis] = [];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export default function removeAssignments(state, action) {
|
|
15
|
+
const newState = {
|
|
16
|
+
...state,
|
|
17
|
+
};
|
|
18
|
+
// signal id
|
|
19
|
+
const { ids, atomID = '', axis } = action;
|
|
20
|
+
for (const id of ids) {
|
|
21
|
+
removeAssignment(newState, { id, atomID, axis });
|
|
22
|
+
}
|
|
23
|
+
return newState;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AssignmentState } from '../AssignmentsContext';
|
|
2
|
+
import { SetActiveAction } from '../AssignmentsReducer';
|
|
3
|
+
export default function setActiveAssignment(state: AssignmentState, action: SetActiveAction): {
|
|
4
|
+
activated: {
|
|
5
|
+
id: string;
|
|
6
|
+
axis: import("../AssignmentsContext").Axis;
|
|
7
|
+
} | null;
|
|
8
|
+
assignments: import("../AssignmentsContext").Assignments;
|
|
9
|
+
highlighted: import("../AssignmentsContext").AssignmentAction | null;
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AssignmentState } from '../AssignmentsContext';
|
|
2
|
+
import { ToggleAction } from '../AssignmentsReducer';
|
|
3
|
+
export default function ToggleAssignments(state: AssignmentState, action: ToggleAction): {
|
|
4
|
+
assignments: import("../AssignmentsContext").Assignments;
|
|
5
|
+
activated: import("../AssignmentsContext").AssignmentAction | null;
|
|
6
|
+
highlighted: import("../AssignmentsContext").AssignmentAction | null;
|
|
7
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { removeAssignment } from './removeAssignment';
|
|
2
|
+
function addAssignment(state, action) {
|
|
3
|
+
const { id, atomID, axis, dimension } = action;
|
|
4
|
+
const assignment = state.assignments?.[id] || null;
|
|
5
|
+
const axisAssignments = assignment?.[axis] || null;
|
|
6
|
+
// avoid duplicates
|
|
7
|
+
if (axisAssignments) {
|
|
8
|
+
if (!axisAssignments.includes(id)) {
|
|
9
|
+
axisAssignments.push(atomID);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const otherAxis = axis === 'x' ? 'y' : 'x';
|
|
14
|
+
state.assignments = {
|
|
15
|
+
...state.assignments,
|
|
16
|
+
[id]: {
|
|
17
|
+
...state.assignments[id],
|
|
18
|
+
[axis]: [atomID],
|
|
19
|
+
...(dimension === '2D' && {
|
|
20
|
+
[otherAxis]: assignment?.[otherAxis] ? assignment[otherAxis] : [],
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export default function ToggleAssignments(state, action) {
|
|
27
|
+
const newState = {
|
|
28
|
+
...state,
|
|
29
|
+
};
|
|
30
|
+
const { id, atomIDs: atomsKeys, dimension } = action.payload;
|
|
31
|
+
const axis = state.activated?.axis;
|
|
32
|
+
if (axis) {
|
|
33
|
+
const atomIDs = state.assignments?.[id]?.[axis] || [];
|
|
34
|
+
for (const atomID of atomsKeys) {
|
|
35
|
+
if (!atomIDs.includes(id)) {
|
|
36
|
+
addAssignment(newState, { axis, id, atomID, dimension });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
removeAssignment(newState, { atomID, axis, id });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return newState;
|
|
44
|
+
}
|
|
@@ -1,20 +1,2 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export declare function AssignmentProvider(props: any): JSX.Element;
|
|
3
|
-
export declare function useAssignmentData(): any;
|
|
4
|
-
export declare function useAssignment(key: any): {
|
|
5
|
-
id: string;
|
|
6
|
-
isActive: any;
|
|
7
|
-
activeAxis: any;
|
|
8
|
-
assigned: any;
|
|
9
|
-
add: (_id: any) => void;
|
|
10
|
-
remove: (_id: any) => void;
|
|
11
|
-
removeAll: (axis: any) => void;
|
|
12
|
-
toggle: (_id: any) => void;
|
|
13
|
-
deleteRecord: () => void;
|
|
14
|
-
onClick: (axis: any) => void;
|
|
15
|
-
isOnHover: any;
|
|
16
|
-
onHoverAxis: any;
|
|
17
|
-
onMouseEnter: (axis: any) => void;
|
|
18
|
-
onMouseLeave: (axis: any) => void;
|
|
19
|
-
};
|
|
20
|
-
export declare function filterForIDsWithAssignment(assignmentData: any, ids: any): any;
|