nmrium 1.4.0 → 1.6.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/FloatPublicationString.d.ts.map +1 -1
- package/lib/component/1d/FloatPublicationString.js +4 -9
- package/lib/component/1d/FloatPublicationString.js.map +1 -1
- package/lib/component/1d/peaks/PeakAnnotations.d.ts.map +1 -1
- package/lib/component/1d/peaks/PeakAnnotations.js +99 -3
- package/lib/component/1d/peaks/PeakAnnotations.js.map +1 -1
- package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.js +3 -3
- package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.js.map +1 -1
- package/lib/component/1d/peaks/Peaks.d.ts +4 -2
- package/lib/component/1d/peaks/Peaks.d.ts.map +1 -1
- package/lib/component/1d/peaks/Peaks.js +23 -19
- package/lib/component/1d/peaks/Peaks.js.map +1 -1
- package/lib/component/1d/ranges/Ranges.js +4 -4
- package/lib/component/1d/ranges/Ranges.js.map +1 -1
- package/lib/component/2d/zones/SignalsGuideLines.d.ts.map +1 -1
- package/lib/component/2d/zones/SignalsGuideLines.js +10 -6
- package/lib/component/2d/zones/SignalsGuideLines.js.map +1 -1
- package/lib/component/elements/DraggableDialog.js +0 -2
- package/lib/component/elements/DraggableDialog.js.map +1 -1
- package/lib/component/elements/EditableColumn.d.ts.map +1 -1
- package/lib/component/elements/EditableColumn.js +2 -0
- package/lib/component/elements/EditableColumn.js.map +1 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.d.ts.map +1 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +0 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.js.map +1 -1
- package/lib/component/elements/ReactTable/ReactTable.d.ts.map +1 -1
- package/lib/component/elements/ReactTable/ReactTable.js +1 -4
- package/lib/component/elements/ReactTable/ReactTable.js.map +1 -1
- package/lib/component/elements/Sections.d.ts.map +1 -1
- package/lib/component/elements/Sections.js +1 -1
- package/lib/component/elements/Sections.js.map +1 -1
- package/lib/component/elements/Tab/Tabs.js +1 -1
- package/lib/component/elements/Tab/Tabs.js.map +1 -1
- package/lib/component/hooks/useActiveSpectrumRangesViewState.d.ts +1 -1
- package/lib/component/hooks/useActiveSpectrumRangesViewState.d.ts.map +1 -1
- package/lib/component/hooks/useActiveSpectrumRangesViewState.js +20 -16
- package/lib/component/hooks/useActiveSpectrumRangesViewState.js.map +1 -1
- package/lib/component/hooks/useCombinedRefs.js +1 -1
- package/lib/component/hooks/useCombinedRefs.js.map +1 -1
- package/lib/component/hooks/useTextMetrics.d.ts +4 -0
- package/lib/component/hooks/useTextMetrics.d.ts.map +1 -0
- package/lib/component/hooks/useTextMetrics.js +21 -0
- package/lib/component/hooks/useTextMetrics.js.map +1 -0
- package/lib/component/modal/MultipletAnalysisModal.js +2 -0
- package/lib/component/modal/MultipletAnalysisModal.js.map +1 -1
- package/lib/component/modal/changeSum/ChangeSumModalContents.d.ts.map +1 -1
- package/lib/component/modal/changeSum/ChangeSumModalContents.js +2 -0
- package/lib/component/modal/changeSum/ChangeSumModalContents.js.map +1 -1
- package/lib/component/modal/changeSum/SelectMolecule.d.ts.map +1 -1
- package/lib/component/modal/changeSum/SelectMolecule.js +2 -0
- package/lib/component/modal/changeSum/SelectMolecule.js.map +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanel.d.ts.map +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanel.js +2 -0
- package/lib/component/panels/MoleculesPanel/MoleculePanel.js.map +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts.map +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js.map +1 -1
- package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +1 -1
- package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditPathLength.d.ts.map +1 -1
- package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditPathLength.js +2 -5
- package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditPathLength.js.map +1 -1
- package/lib/component/panels/SummaryPanel/SummaryPanel.d.ts.map +1 -1
- package/lib/component/panels/SummaryPanel/SummaryPanel.js +8 -9
- package/lib/component/panels/SummaryPanel/SummaryPanel.js.map +1 -1
- package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrection.js +10 -10
- package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrection.js.map +1 -1
- package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.d.ts.map +1 -1
- package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.js +7 -5
- package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.js.map +1 -1
- package/lib/component/panels/multipleAnalysisPanel/preferences/MultipleAnalysisCodeEditor.d.ts.map +1 -1
- package/lib/component/panels/multipleAnalysisPanel/preferences/MultipleAnalysisCodeEditor.js +2 -0
- package/lib/component/panels/multipleAnalysisPanel/preferences/MultipleAnalysisCodeEditor.js.map +1 -1
- package/lib/component/reducer/actions/InsetActions.js +6 -6
- package/lib/component/reducer/actions/InsetActions.js.map +1 -1
- package/lib/component/reducer/actions/PeaksActions.d.ts.map +1 -1
- package/lib/component/reducer/actions/PeaksActions.js +3 -2
- package/lib/component/reducer/actions/PeaksActions.js.map +1 -1
- package/lib/component/reducer/actions/RangesActions.d.ts.map +1 -1
- package/lib/component/reducer/actions/RangesActions.js +16 -10
- package/lib/component/reducer/actions/RangesActions.js.map +1 -1
- package/lib/component/reducer/helper/setRangesViewProperty.d.ts.map +1 -1
- package/lib/component/reducer/helper/setRangesViewProperty.js +5 -5
- package/lib/component/reducer/helper/setRangesViewProperty.js.map +1 -1
- package/lib/component/utility/isHomoNuclear.d.ts +2 -0
- package/lib/component/utility/isHomoNuclear.d.ts.map +1 -0
- package/lib/component/utility/isHomoNuclear.js +11 -0
- package/lib/component/utility/isHomoNuclear.js.map +1 -0
- package/lib/data/data1d/Spectrum1D/peaks/autoPeakPicking.d.ts.map +1 -1
- package/lib/data/data1d/Spectrum1D/peaks/autoPeakPicking.js +2 -1
- package/lib/data/data1d/Spectrum1D/peaks/autoPeakPicking.js.map +1 -1
- package/lib/data/data1d/Spectrum1D/ranges/autoRangesDetection.d.ts.map +1 -1
- package/lib/data/data1d/Spectrum1D/ranges/autoRangesDetection.js +8 -5
- package/lib/data/data1d/Spectrum1D/ranges/autoRangesDetection.js.map +1 -1
- package/lib/utils/clipboard/clipboardComponents.d.ts.map +1 -1
- package/lib/utils/clipboard/clipboardComponents.js +12 -4
- package/lib/utils/clipboard/clipboardComponents.js.map +1 -1
- package/lib/versionInfo.js +1 -1
- package/package.json +22 -20
- package/src/component/1d/FloatPublicationString.tsx +4 -9
- package/src/component/1d/peaks/PeakAnnotations.tsx +147 -22
- package/src/component/1d/peaks/PeakAnnotationsSpreadMode.tsx +3 -3
- package/src/component/1d/peaks/Peaks.tsx +37 -31
- package/src/component/1d/ranges/Ranges.tsx +4 -4
- package/src/component/2d/zones/SignalsGuideLines.tsx +11 -6
- package/src/component/elements/DraggableDialog.tsx +0 -2
- package/src/component/elements/EditableColumn.tsx +2 -0
- package/src/component/elements/ReactTable/Elements/ReactTableRow.tsx +0 -1
- package/src/component/elements/ReactTable/ReactTable.tsx +0 -3
- package/src/component/elements/Sections.tsx +10 -11
- package/src/component/elements/Tab/Tabs.tsx +1 -1
- package/src/component/hooks/useActiveSpectrumRangesViewState.ts +24 -16
- package/src/component/hooks/useCombinedRefs.ts +1 -1
- package/src/component/hooks/useTextMetrics.ts +27 -0
- package/src/component/modal/MultipletAnalysisModal.tsx +2 -0
- package/src/component/modal/changeSum/ChangeSumModalContents.tsx +2 -0
- package/src/component/modal/changeSum/SelectMolecule.tsx +2 -0
- package/src/component/panels/MoleculesPanel/MoleculePanel.tsx +2 -0
- package/src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx +4 -3
- package/src/component/panels/SpectraPanel/SpectraPanelHeader.tsx +1 -1
- package/src/component/panels/SummaryPanel/CorrelationTable/editLink/EditPathLength.tsx +3 -6
- package/src/component/panels/SummaryPanel/SummaryPanel.tsx +10 -16
- package/src/component/panels/filtersPanel/Filters/hooks/usePhaseCorrection.tsx +14 -14
- package/src/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.tsx +10 -8
- package/src/component/panels/multipleAnalysisPanel/preferences/MultipleAnalysisCodeEditor.tsx +2 -0
- package/src/component/reducer/actions/InsetActions.ts +6 -6
- package/src/component/reducer/actions/PeaksActions.ts +7 -2
- package/src/component/reducer/actions/RangesActions.ts +17 -16
- package/src/component/reducer/helper/setRangesViewProperty.ts +8 -5
- package/src/component/utility/isHomoNuclear.ts +11 -0
- package/src/data/data1d/Spectrum1D/peaks/autoPeakPicking.ts +2 -0
- package/src/data/data1d/Spectrum1D/ranges/autoRangesDetection.ts +8 -5
- package/src/utils/clipboard/clipboardComponents.tsx +15 -5
- package/src/versionInfo.ts +1 -1
- package/lib/component/elements/pdnd.cjs +0 -25
- package/lib/component/elements/pdnd.cjs.map +0 -1
- package/lib/component/elements/pdnd.d.cts +0 -7
- package/lib/component/elements/pdnd.d.cts.map +0 -1
- package/lib/component/hooks/useCanvasContext.d.ts +0 -2
- package/lib/component/hooks/useCanvasContext.d.ts.map +0 -1
- package/lib/component/hooks/useCanvasContext.js +0 -13
- package/lib/component/hooks/useCanvasContext.js.map +0 -1
- package/src/component/elements/pdnd.cts +0 -19
- package/src/component/hooks/useCanvasContext.ts +0 -15
|
@@ -1,41 +1,161 @@
|
|
|
1
1
|
import { useScaleChecked } from '../../context/ScaleContext.js';
|
|
2
2
|
import { useHighlight } from '../../highlight/index.js';
|
|
3
3
|
import { useActiveSpectrum } from '../../hooks/useActiveSpectrum.js';
|
|
4
|
+
import { useTextMetrics } from '../../hooks/useTextMetrics.ts';
|
|
4
5
|
import { formatNumber } from '../../utility/formatNumber.js';
|
|
5
6
|
|
|
6
7
|
import { PeakEditionListener } from './PeakEditionManager.js';
|
|
7
8
|
import type { Peak, PeaksAnnotationsProps, PeaksSource } from './Peaks.js';
|
|
8
9
|
import { getHighlightExtraId, getHighlightSource } from './Peaks.js';
|
|
9
10
|
|
|
11
|
+
const textSize = 11;
|
|
12
|
+
const textXOffset = 2;
|
|
13
|
+
const labelHeight = 13;
|
|
14
|
+
|
|
15
|
+
function resolvePeaksCluster(
|
|
16
|
+
overlapPeaksById: Record<string, boolean>,
|
|
17
|
+
cluster: Peak[],
|
|
18
|
+
) {
|
|
19
|
+
if (cluster.length === 0) return;
|
|
20
|
+
|
|
21
|
+
let maxPeak = cluster[0];
|
|
22
|
+
for (const p of cluster) {
|
|
23
|
+
if (p.y > maxPeak.y) {
|
|
24
|
+
maxPeak = p;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const p of cluster) {
|
|
28
|
+
overlapPeaksById[p.id] = p.id !== maxPeak.id;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveYOverlaps(
|
|
33
|
+
overlapPeaksById: Record<string, boolean>,
|
|
34
|
+
inputCluster: Peak[],
|
|
35
|
+
) {
|
|
36
|
+
let lastLabelPosition = 0;
|
|
37
|
+
let cluster: Peak[] = [];
|
|
38
|
+
|
|
39
|
+
const sortedPeaks = inputCluster.toSorted((a, b) => b.y - a.y);
|
|
40
|
+
for (const peak of sortedPeaks) {
|
|
41
|
+
const { yInPixel } = peak;
|
|
42
|
+
const labelPosition = yInPixel;
|
|
43
|
+
const overlapY = Math.abs(labelPosition - lastLabelPosition) < labelHeight;
|
|
44
|
+
|
|
45
|
+
if (overlapY) {
|
|
46
|
+
cluster.push(peak);
|
|
47
|
+
} else {
|
|
48
|
+
resolvePeaksCluster(overlapPeaksById, cluster);
|
|
49
|
+
cluster = [peak];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
lastLabelPosition = labelPosition;
|
|
53
|
+
}
|
|
54
|
+
resolvePeaksCluster(overlapPeaksById, cluster);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function useDetectPeakOverlaps(peaks: Peak[], format: string) {
|
|
58
|
+
const { getTextWidth } = useTextMetrics(textSize);
|
|
59
|
+
const overlapPeaksById: Record<string, boolean> = {};
|
|
60
|
+
|
|
61
|
+
let cluster: Peak[] = [];
|
|
62
|
+
let lastLabelPosition = 0;
|
|
63
|
+
|
|
64
|
+
for (const peak of peaks) {
|
|
65
|
+
const { xInPixel, x } = peak;
|
|
66
|
+
const label = formatNumber(x, format);
|
|
67
|
+
const labelWidth = getTextWidth(label) + textXOffset;
|
|
68
|
+
const labelPosition = xInPixel + labelWidth;
|
|
69
|
+
|
|
70
|
+
const overlapX = Math.abs(labelPosition - lastLabelPosition) < labelWidth;
|
|
71
|
+
|
|
72
|
+
if (overlapX) {
|
|
73
|
+
// add to current overlap cluster
|
|
74
|
+
cluster.push(peak);
|
|
75
|
+
} else {
|
|
76
|
+
// resolve the previous cluster
|
|
77
|
+
resolveYOverlaps(overlapPeaksById, cluster);
|
|
78
|
+
// Start a new cluster
|
|
79
|
+
cluster = [peak];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!overlapX) {
|
|
83
|
+
lastLabelPosition = labelPosition;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resolveYOverlaps(overlapPeaksById, cluster);
|
|
88
|
+
return overlapPeaksById;
|
|
89
|
+
}
|
|
90
|
+
|
|
10
91
|
function PeakAnnotations(props: PeaksAnnotationsProps) {
|
|
11
92
|
const { peaks, peaksSource, spectrumKey, peakFormat } = props;
|
|
12
93
|
const activeSpectrum = useActiveSpectrum();
|
|
13
94
|
const { shiftY } = useScaleChecked();
|
|
95
|
+
const overlapPeaksById = useDetectPeakOverlaps(peaks, peakFormat);
|
|
14
96
|
|
|
15
97
|
return (
|
|
16
98
|
<g className="peaks">
|
|
17
99
|
<g transform={`translate(0,-${(activeSpectrum?.index || 0) * shiftY})`}>
|
|
18
|
-
{peaks.map((peak) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
100
|
+
{peaks.map((peak) => {
|
|
101
|
+
return (
|
|
102
|
+
<PeakAnnotation
|
|
103
|
+
key={peak.id}
|
|
104
|
+
spectrumKey={spectrumKey}
|
|
105
|
+
peak={peak}
|
|
106
|
+
color="#730000"
|
|
107
|
+
peaksSource={peaksSource}
|
|
108
|
+
format={peakFormat}
|
|
109
|
+
isOverlap={overlapPeaksById[peak.id]}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
28
113
|
</g>
|
|
29
114
|
</g>
|
|
30
115
|
);
|
|
31
116
|
}
|
|
32
117
|
|
|
118
|
+
function adjustValue(baseValue: number, isOverlap: boolean) {
|
|
119
|
+
return isOverlap ? baseValue / 2 : baseValue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const basePeakYCoordinates: Record<
|
|
123
|
+
'positive' | 'negative',
|
|
124
|
+
{ y1: number; y2: number }
|
|
125
|
+
> = {
|
|
126
|
+
positive: {
|
|
127
|
+
y1: 0,
|
|
128
|
+
y2: -18,
|
|
129
|
+
},
|
|
130
|
+
negative: {
|
|
131
|
+
y1: 10,
|
|
132
|
+
y2: 28,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function getLineYCoordinates(sign: number, isOverlap: boolean) {
|
|
137
|
+
const { negative, positive } = basePeakYCoordinates;
|
|
138
|
+
if (sign === -1) {
|
|
139
|
+
const { y1, y2 } = negative;
|
|
140
|
+
return {
|
|
141
|
+
y1: adjustValue(y1, isOverlap),
|
|
142
|
+
y2: adjustValue(y2, isOverlap),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const { y1, y2 } = positive;
|
|
146
|
+
return {
|
|
147
|
+
y1,
|
|
148
|
+
y2: adjustValue(y2, isOverlap),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
33
152
|
interface PeakAnnotationProps {
|
|
34
153
|
peak: Peak;
|
|
35
154
|
spectrumKey: string;
|
|
36
155
|
color: string;
|
|
37
156
|
peaksSource: PeaksSource;
|
|
38
157
|
format: string;
|
|
158
|
+
isOverlap?: boolean;
|
|
39
159
|
}
|
|
40
160
|
|
|
41
161
|
function PeakAnnotation({
|
|
@@ -44,6 +164,7 @@ function PeakAnnotation({
|
|
|
44
164
|
color,
|
|
45
165
|
peaksSource,
|
|
46
166
|
format,
|
|
167
|
+
isOverlap = false,
|
|
47
168
|
}: PeakAnnotationProps) {
|
|
48
169
|
const { id, parentKeys, x, y } = peak;
|
|
49
170
|
const sign = Math.sign(y);
|
|
@@ -59,6 +180,8 @@ function PeakAnnotation({
|
|
|
59
180
|
const sx = scaleX()(x);
|
|
60
181
|
const sy = scaleY(spectrumKey)(y) - 5;
|
|
61
182
|
|
|
183
|
+
const { y1, y2 } = getLineYCoordinates(sign, isOverlap);
|
|
184
|
+
|
|
62
185
|
return (
|
|
63
186
|
<g
|
|
64
187
|
style={{ outline: 'none' }}
|
|
@@ -69,8 +192,8 @@ function PeakAnnotation({
|
|
|
69
192
|
<line
|
|
70
193
|
x1="0"
|
|
71
194
|
x2="0"
|
|
72
|
-
y1={
|
|
73
|
-
y2={
|
|
195
|
+
y1={y1}
|
|
196
|
+
y2={y2}
|
|
74
197
|
stroke={color}
|
|
75
198
|
strokeWidth={highlight.isActive ? '3px' : '1px'}
|
|
76
199
|
/>
|
|
@@ -83,16 +206,18 @@ function PeakAnnotation({
|
|
|
83
206
|
id={id}
|
|
84
207
|
dy={sign === -1 ? 0 : -26}
|
|
85
208
|
>
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
209
|
+
{!isOverlap && (
|
|
210
|
+
<text
|
|
211
|
+
x="0"
|
|
212
|
+
y={sign === -1 ? 26 : -10}
|
|
213
|
+
dy="0"
|
|
214
|
+
dx={`${textXOffset}px`}
|
|
215
|
+
fontSize={`${textSize}px`}
|
|
216
|
+
fill={color}
|
|
217
|
+
>
|
|
218
|
+
{formatNumber(x, format)}
|
|
219
|
+
</text>
|
|
220
|
+
)}
|
|
96
221
|
</PeakEditionListener>
|
|
97
222
|
</g>
|
|
98
223
|
);
|
|
@@ -95,7 +95,7 @@ function PeakAnnotationsSpreadMode(props: PeakAnnotationsSpreadModeProps) {
|
|
|
95
95
|
];
|
|
96
96
|
|
|
97
97
|
const mapPeaks = resolve(peaks, {
|
|
98
|
-
key: '
|
|
98
|
+
key: 'xInPixel',
|
|
99
99
|
width: notationWidth,
|
|
100
100
|
margin: notationMargin,
|
|
101
101
|
groupMargin: 10,
|
|
@@ -144,9 +144,9 @@ function PeakAnnotationsSpreadMode(props: PeakAnnotationsSpreadModeProps) {
|
|
|
144
144
|
transform={`translate(${group.meta.groupStartX},0)`}
|
|
145
145
|
>
|
|
146
146
|
{group.group.map((item, index) => {
|
|
147
|
-
const { id, x: value,
|
|
147
|
+
const { id, x: value, xInPixel, parentKeys } = item;
|
|
148
148
|
const startX = index * (notationWidth + notationMargin);
|
|
149
|
-
const x =
|
|
149
|
+
const x = xInPixel - group.meta.groupStartX;
|
|
150
150
|
return (
|
|
151
151
|
<PeakAnnotation
|
|
152
152
|
key={id}
|
|
@@ -3,12 +3,12 @@ import type { Spectrum1D } from '@zakodium/nmrium-core';
|
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
4
|
|
|
5
5
|
import { useChartData } from '../../context/ChartContext.js';
|
|
6
|
+
import { useScaleChecked } from '../../context/ScaleContext.tsx';
|
|
6
7
|
import { useActiveSpectrumPeaksViewState } from '../../hooks/useActiveSpectrumPeaksViewState.js';
|
|
7
8
|
import { useActiveSpectrumRangesViewState } from '../../hooks/useActiveSpectrumRangesViewState.js';
|
|
8
9
|
import { usePanelPreferences } from '../../hooks/usePanelPreferences.js';
|
|
9
10
|
import useSpectrum from '../../hooks/useSpectrum.js';
|
|
10
11
|
import type { Margin } from '../../reducer/Reducer.js';
|
|
11
|
-
import { useScaleX } from '../utilities/scale.js';
|
|
12
12
|
|
|
13
13
|
import PeakAnnotations from './PeakAnnotations.js';
|
|
14
14
|
import PeakAnnotationsSpreadMode from './PeakAnnotationsSpreadMode.js';
|
|
@@ -21,18 +21,18 @@ interface NMRPeak1DWithParentKeys extends NMRPeak1D {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
interface SpreadPeak1D extends Peak1DWithParentKeys {
|
|
24
|
-
|
|
24
|
+
xInPixel: number;
|
|
25
|
+
yInPixel: number;
|
|
25
26
|
}
|
|
26
27
|
interface SpreadNMRPeak1D extends NMRPeak1DWithParentKeys {
|
|
27
|
-
|
|
28
|
+
xInPixel: number;
|
|
29
|
+
yInPixel: number;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export type Peak = Required<SpreadPeak1D | SpreadNMRPeak1D>;
|
|
31
33
|
type PeaksMode = 'spread' | 'single';
|
|
32
34
|
export type PeaksSource = 'peaks' | 'ranges';
|
|
33
35
|
|
|
34
|
-
type FilterPeaksBy = `Source[${PeaksSource}]_Mode[${PeaksMode}]`;
|
|
35
|
-
|
|
36
36
|
interface BasePeaksProps {
|
|
37
37
|
peaksSource: PeaksSource;
|
|
38
38
|
displayerKey: string;
|
|
@@ -70,36 +70,45 @@ function flatRangesPeaks(ranges: Range[]) {
|
|
|
70
70
|
return results;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function mapPeaks(
|
|
73
|
+
function mapPeaks(
|
|
74
|
+
peaks: Peak[],
|
|
75
|
+
options: {
|
|
76
|
+
scaleX: (value: number) => number;
|
|
77
|
+
scaleY: (value: number) => number;
|
|
78
|
+
},
|
|
79
|
+
) {
|
|
80
|
+
const { scaleX, scaleY } = options;
|
|
74
81
|
const mappedPeaks = peaks.map((peak) => ({
|
|
75
82
|
...peak,
|
|
76
|
-
|
|
83
|
+
xInPixel: scaleX(peak.x),
|
|
84
|
+
yInPixel: scaleY(peak.y),
|
|
77
85
|
}));
|
|
78
|
-
mappedPeaks.sort((p1, p2) => p2.x - p1.x);
|
|
79
86
|
return mappedPeaks;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
function
|
|
83
|
-
|
|
89
|
+
function sortPeaks(peaks: Peak[]) {
|
|
90
|
+
return peaks.toSorted((a, b) => b.x - a.x);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function useMapPeaks(spectrum: Spectrum1D, peaksSource: PeaksSource) {
|
|
94
|
+
const { scaleX, scaleY } = useScaleChecked();
|
|
84
95
|
return useMemo(() => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
case 'Source[peaks]_Mode[spread]':
|
|
89
|
-
return mapPeaks(spectrum.peaks.values as Peak[], (val) =>
|
|
90
|
-
scaleX()(val),
|
|
91
|
-
);
|
|
92
|
-
case 'Source[ranges]_Mode[single]':
|
|
93
|
-
return flatRangesPeaks(spectrum.ranges.values);
|
|
94
|
-
case 'Source[ranges]_Mode[spread]':
|
|
95
|
-
return mapPeaks(
|
|
96
|
-
flatRangesPeaks(spectrum.ranges.values) as Peak[],
|
|
97
|
-
(val) => scaleX()(val),
|
|
98
|
-
);
|
|
99
|
-
default:
|
|
100
|
-
return [];
|
|
96
|
+
let sourcePeaks: Peak[] = [];
|
|
97
|
+
if (peaksSource === 'peaks') {
|
|
98
|
+
sourcePeaks = spectrum.peaks.values as Peak[];
|
|
101
99
|
}
|
|
102
|
-
|
|
100
|
+
|
|
101
|
+
if (peaksSource === 'ranges') {
|
|
102
|
+
sourcePeaks = flatRangesPeaks(spectrum.ranges.values) as Peak[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const sortedPeaks = sortPeaks(sourcePeaks);
|
|
106
|
+
|
|
107
|
+
return mapPeaks(sortedPeaks, {
|
|
108
|
+
scaleX: (val) => scaleX()(val),
|
|
109
|
+
scaleY: (val) => scaleY()(val),
|
|
110
|
+
});
|
|
111
|
+
}, [peaksSource, spectrum, scaleX, scaleY]);
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
interface InnerPeaksProps extends BasePeaksProps {
|
|
@@ -121,10 +130,7 @@ function InnerPeaks(props: InnerPeaksProps) {
|
|
|
121
130
|
peakFormat,
|
|
122
131
|
} = props;
|
|
123
132
|
|
|
124
|
-
const peaks = useMapPeaks(
|
|
125
|
-
spectrum,
|
|
126
|
-
`Source[${peaksSource}]_Mode[${mode}]`,
|
|
127
|
-
) as Peak[];
|
|
133
|
+
const peaks = useMapPeaks(spectrum, peaksSource);
|
|
128
134
|
|
|
129
135
|
if (mode === 'spread') {
|
|
130
136
|
return (
|
|
@@ -8,9 +8,9 @@ import { memo } from 'react';
|
|
|
8
8
|
import { useChartData } from '../../context/ChartContext.js';
|
|
9
9
|
import { useScaleChecked } from '../../context/ScaleContext.js';
|
|
10
10
|
import { ShareDataProvider } from '../../context/ShareDataContext.js';
|
|
11
|
-
import { useCanvasContext } from '../../hooks/useCanvasContext.js';
|
|
12
11
|
import { usePanelPreferences } from '../../hooks/usePanelPreferences.js';
|
|
13
12
|
import useSpectrum from '../../hooks/useSpectrum.js';
|
|
13
|
+
import { useTextMetrics } from '../../hooks/useTextMetrics.ts';
|
|
14
14
|
import { stackOverlappingLabelsMap } from '../../utility/stackOverlappingLabels.js';
|
|
15
15
|
|
|
16
16
|
import Range from './Range.js';
|
|
@@ -31,13 +31,13 @@ type ProcessedRange = RangeType & {
|
|
|
31
31
|
function useStackRangesAssignmentsLabels(ranges: RangeType[]) {
|
|
32
32
|
const { scaleX } = useScaleChecked();
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const { getTextWidth } = useTextMetrics(labelSize);
|
|
35
35
|
|
|
36
|
-
if (
|
|
36
|
+
if (ranges.length === 0) return null;
|
|
37
37
|
|
|
38
38
|
const processedRanges: ProcessedRange[] = ranges.map((range) => {
|
|
39
39
|
const { from, assignment = '' } = range;
|
|
40
|
-
const
|
|
40
|
+
const labelWidth = getTextWidth(assignment);
|
|
41
41
|
|
|
42
42
|
return {
|
|
43
43
|
...range,
|
|
@@ -21,9 +21,11 @@ import {
|
|
|
21
21
|
import type { ActionsButtonsPopoverProps } from '../../elements/ActionsButtonsPopover.js';
|
|
22
22
|
import { ActionsButtonsPopover } from '../../elements/ActionsButtonsPopover.js';
|
|
23
23
|
import { useHighlight } from '../../highlight/index.js';
|
|
24
|
-
import {
|
|
24
|
+
import { useActiveNucleusTab } from '../../hooks/useActiveNucleusTab.ts';
|
|
25
25
|
import { useHighlightColor } from '../../hooks/useHighlightColor.ts';
|
|
26
|
+
import { useTextMetrics } from '../../hooks/useTextMetrics.ts';
|
|
26
27
|
import { useTriggerNewAssignmentLabel } from '../../hooks/useTriggerNewAssignmentLabel.js';
|
|
28
|
+
import { isHomoNuclear } from '../../utility/isHomoNuclear.ts';
|
|
27
29
|
import { stackOverlappingLabelsArray } from '../../utility/stackOverlappingLabels.js';
|
|
28
30
|
import { useTracesSpectra } from '../useTracesSpectra.js';
|
|
29
31
|
import type { ExtractedSignal } from '../utilities/extractSpectrumSignals.js';
|
|
@@ -67,16 +69,16 @@ function useSignalsOverlap(axis: IndicationLinesAxis, spectrum: Spectrum1D) {
|
|
|
67
69
|
});
|
|
68
70
|
const scaleX = useScale2DX();
|
|
69
71
|
const scaleY = useScale2DY();
|
|
70
|
-
const
|
|
72
|
+
const { getTextWidth } = useTextMetrics(labelSize);
|
|
71
73
|
|
|
72
|
-
if (!signals
|
|
74
|
+
if (!signals) return null;
|
|
73
75
|
|
|
74
76
|
const isOverXAxis = axis === 'x';
|
|
75
77
|
|
|
76
78
|
const processedSignals: ProcessedSignal[] = signals.map((signal) => {
|
|
77
79
|
const { delta } = signal;
|
|
78
80
|
const text = signal.assignment ?? '';
|
|
79
|
-
const
|
|
81
|
+
const labelWidth = getTextWidth(text);
|
|
80
82
|
|
|
81
83
|
return {
|
|
82
84
|
...signal,
|
|
@@ -200,6 +202,9 @@ function IndicationLine(props: IndicationLineProps) {
|
|
|
200
202
|
const signalsIds = signals.map(({ id }) => id);
|
|
201
203
|
const { margin, width, height } = useChartData();
|
|
202
204
|
const { setData: addNewAssignmentLabel } = useShareData();
|
|
205
|
+
const nuclei = useActiveNucleusTab();
|
|
206
|
+
const isHomoNuclei = isHomoNuclear(nuclei);
|
|
207
|
+
|
|
203
208
|
const dispatch = useDispatch();
|
|
204
209
|
const { assignmentContext, highlightContext } = useRangeAssignment({
|
|
205
210
|
rangeId,
|
|
@@ -240,7 +245,7 @@ function IndicationLine(props: IndicationLineProps) {
|
|
|
240
245
|
}
|
|
241
246
|
|
|
242
247
|
function mouseEnterHandler() {
|
|
243
|
-
assignmentContext.highlight(axis);
|
|
248
|
+
assignmentContext.highlight(isHomoNuclei ? 'x' : axis);
|
|
244
249
|
highlightContext.show();
|
|
245
250
|
}
|
|
246
251
|
|
|
@@ -251,7 +256,7 @@ function IndicationLine(props: IndicationLineProps) {
|
|
|
251
256
|
|
|
252
257
|
function assignHandler() {
|
|
253
258
|
isAssignBtnTrigged.current = true;
|
|
254
|
-
assignmentContext.activate(axis);
|
|
259
|
+
assignmentContext.activate(isHomoNuclei ? 'x' : axis);
|
|
255
260
|
}
|
|
256
261
|
|
|
257
262
|
function unAssignHandler() {
|
|
@@ -129,8 +129,6 @@ function InnerDraggableDialog(props: InnerDraggableDialogProps) {
|
|
|
129
129
|
parentContainerRect,
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
// Mutating a ref.
|
|
133
|
-
// eslint-disable-next-line react-hooks/react-compiler
|
|
134
132
|
innerDialogRef.current.style.transform = `translate(${transformX}px, ${transformY}px)`;
|
|
135
133
|
};
|
|
136
134
|
|
|
@@ -108,6 +108,8 @@ export const EditableColumn = forwardRef(function EditableColumn(
|
|
|
108
108
|
const mouseClickCallback = useCallback((e: MouseEvent) => {
|
|
109
109
|
if (!(e.target as HTMLInputElement).classList.contains('editable-column')) {
|
|
110
110
|
enableEdit(false);
|
|
111
|
+
// TODO: refactor this
|
|
112
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
111
113
|
globalThis.removeEventListener('mousedown', mouseClickCallback);
|
|
112
114
|
}
|
|
113
115
|
}, []);
|
|
@@ -192,11 +192,8 @@ function TableInner<T extends object>(
|
|
|
192
192
|
data,
|
|
193
193
|
autoResetSortBy: false,
|
|
194
194
|
} as TableOptions<T>,
|
|
195
|
-
// Will be fixed by migrating to tanstack table.
|
|
196
|
-
/* eslint-disable react-hooks/react-compiler */
|
|
197
195
|
useSortBy,
|
|
198
196
|
useRowSpan,
|
|
199
|
-
/* eslint-enable react-hooks/react-compiler */
|
|
200
197
|
) as TableInstanceWithHooks<T>;
|
|
201
198
|
|
|
202
199
|
const { sortBy } = state as any;
|
|
@@ -3,6 +3,16 @@ import type { ElementDragPayload } from '@atlaskit/pragmatic-drag-and-drop/dist/
|
|
|
3
3
|
import type { Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge';
|
|
4
4
|
import { Colors, Icon, Tag } from '@blueprintjs/core';
|
|
5
5
|
import styled from '@emotion/styled';
|
|
6
|
+
import {
|
|
7
|
+
attachClosestEdge,
|
|
8
|
+
combine,
|
|
9
|
+
draggable,
|
|
10
|
+
dropTargetForElements,
|
|
11
|
+
extractClosestEdge,
|
|
12
|
+
getReorderDestinationIndex,
|
|
13
|
+
pointerOutsideOfPreview,
|
|
14
|
+
setCustomNativeDragPreview,
|
|
15
|
+
} from '@zakodium/pdnd-esm';
|
|
6
16
|
import type {
|
|
7
17
|
CSSProperties,
|
|
8
18
|
HTMLAttributes,
|
|
@@ -21,17 +31,6 @@ import {
|
|
|
21
31
|
import { createPortal } from 'react-dom';
|
|
22
32
|
import { assert } from 'react-science/ui';
|
|
23
33
|
|
|
24
|
-
import {
|
|
25
|
-
attachClosestEdge,
|
|
26
|
-
combine,
|
|
27
|
-
draggable,
|
|
28
|
-
dropTargetForElements,
|
|
29
|
-
extractClosestEdge,
|
|
30
|
-
getReorderDestinationIndex,
|
|
31
|
-
pointerOutsideOfPreview,
|
|
32
|
-
setCustomNativeDragPreview,
|
|
33
|
-
} from './pdnd.cjs';
|
|
34
|
-
|
|
35
34
|
interface DropIndicatorProps {
|
|
36
35
|
edge: Edge;
|
|
37
36
|
}
|
|
@@ -112,7 +112,7 @@ function Tabs({
|
|
|
112
112
|
|
|
113
113
|
if (tabid === activeTab) {
|
|
114
114
|
// TODO: avoid this by not implementing a custom tabs component.
|
|
115
|
-
// eslint-disable-next-line react-hooks/
|
|
115
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
116
116
|
contentChild = child.props.children;
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -5,25 +5,33 @@ import { useChartData } from '../context/ChartContext.js';
|
|
|
5
5
|
|
|
6
6
|
import { useActiveSpectrum } from './useActiveSpectrum.js';
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
export function getDefaultRangesViewState(nucleus: string): RangesViewState {
|
|
9
|
+
const isProton = nucleus === '1H';
|
|
10
|
+
const isCarbon = nucleus === '13C';
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
showPeaks: isCarbon,
|
|
14
|
+
showMultiplicityTrees: false,
|
|
15
|
+
showIntegrals: false,
|
|
16
|
+
showIntegralsValues: isProton,
|
|
17
|
+
showJGraph: false,
|
|
18
|
+
displayingMode: 'spread',
|
|
19
|
+
integralsScaleRatio: 1,
|
|
20
|
+
showAssignmentsLabels: false,
|
|
21
|
+
showPublicationString: false,
|
|
22
|
+
showRanges: false,
|
|
23
|
+
publicationStringBounding: { x: 0, y: 0, width: 400, height: 0 },
|
|
24
|
+
rangesBounding: { x: 0, y: 0, width: 200, height: 150 },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
22
27
|
|
|
23
28
|
export function useActiveSpectrumRangesViewState() {
|
|
24
29
|
const activeSpectrum = useActiveSpectrum();
|
|
25
30
|
const {
|
|
26
|
-
view: {
|
|
31
|
+
view: {
|
|
32
|
+
ranges,
|
|
33
|
+
spectra: { activeTab: nucleus },
|
|
34
|
+
},
|
|
27
35
|
} = useChartData();
|
|
28
36
|
|
|
29
37
|
const inset = useInsetOptions();
|
|
@@ -39,6 +47,6 @@ export function useActiveSpectrumRangesViewState() {
|
|
|
39
47
|
) {
|
|
40
48
|
return ranges[activeSpectrum?.id];
|
|
41
49
|
} else {
|
|
42
|
-
return
|
|
50
|
+
return getDefaultRangesViewState(nucleus);
|
|
43
51
|
}
|
|
44
52
|
}
|
|
@@ -13,7 +13,7 @@ export default function useCombinedRefs<T>(
|
|
|
13
13
|
ref(targetRef.current);
|
|
14
14
|
} else {
|
|
15
15
|
// Mutating a ref.
|
|
16
|
-
// eslint-disable-next-line react-hooks/
|
|
16
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
17
17
|
ref.current = targetRef.current;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
function measureTextWidth(
|
|
4
|
+
context: CanvasRenderingContext2D | null,
|
|
5
|
+
text: string,
|
|
6
|
+
) {
|
|
7
|
+
if (!context) return 0;
|
|
8
|
+
return Math.round(context.measureText(text).width);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useTextMetrics(labelSize = 12) {
|
|
12
|
+
const contextRef = useRef<CanvasRenderingContext2D | null>(null);
|
|
13
|
+
|
|
14
|
+
if (!contextRef.current) {
|
|
15
|
+
const canvas = document.createElement('canvas');
|
|
16
|
+
contextRef.current = canvas.getContext('2d');
|
|
17
|
+
if (contextRef.current) {
|
|
18
|
+
contextRef.current.font = `${labelSize}px Arial`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getTextWidth(text: string): number {
|
|
23
|
+
return measureTextWidth(contextRef.current, text);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { getTextWidth };
|
|
27
|
+
}
|
|
@@ -162,6 +162,8 @@ function InnerMultipleAnalysis(props: InnerMultipleAnalysisProps) {
|
|
|
162
162
|
debug: true,
|
|
163
163
|
},
|
|
164
164
|
});
|
|
165
|
+
// TODO: refactor to not use an effect
|
|
166
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
165
167
|
setCalcFinished(true);
|
|
166
168
|
setAnalysisData(result);
|
|
167
169
|
} catch (error) {
|
|
@@ -80,6 +80,8 @@ export function ChangeSumModalContents(props: ChangeSumModalContentsProps) {
|
|
|
80
80
|
|
|
81
81
|
useEffect(() => {
|
|
82
82
|
if (sumOptions?.sumAuto && panels?.structuresPanel?.display) {
|
|
83
|
+
// TODO: refactor to not use an effect
|
|
84
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
83
85
|
setActiveOption('auto');
|
|
84
86
|
const { mf, moleculeId: id } = sumOptions;
|
|
85
87
|
reset({
|
|
@@ -76,6 +76,8 @@ export default function SelectMolecule<
|
|
|
76
76
|
const index = value
|
|
77
77
|
? molecules.findIndex((molecule) => molecule.id === value.id)
|
|
78
78
|
: -1;
|
|
79
|
+
// TODO: refactor to not use an effect
|
|
80
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
79
81
|
setValue(index !== -1 ? index : 0);
|
|
80
82
|
}
|
|
81
83
|
}, [molecules, setValue, value]);
|
|
@@ -75,6 +75,8 @@ function MoleculePanelInner(props: MoleculePanelInnerProps) {
|
|
|
75
75
|
|
|
76
76
|
useEffect(() => {
|
|
77
77
|
if (moleculesProp) {
|
|
78
|
+
// TODO: refactor to not use an effect
|
|
79
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
78
80
|
setMolecules((prevMolecules) => {
|
|
79
81
|
if (moleculesProp.length > prevMolecules.length) {
|
|
80
82
|
setCurrentIndex(molecules.length);
|