nmrium 1.4.0 → 1.5.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/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/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/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/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 +17 -17
- 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/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/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/helper/setRangesViewProperty.ts +8 -5
- package/src/component/utility/isHomoNuclear.ts +11 -0
- package/src/utils/clipboard/clipboardComponents.tsx +15 -5
- package/src/versionInfo.ts +1 -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/hooks/useCanvasContext.ts +0 -15
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nmrium",
|
|
3
3
|
"description": "React component to display and process nuclear magnetic resonance (NMR) spectra.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"@emotion/styled": "^11.14.1",
|
|
70
70
|
"@hookform/resolvers": "^5.2.2",
|
|
71
71
|
"@zakodium/nmr-types": "^0.2.0",
|
|
72
|
-
"@zakodium/nmrium-core": "^0.2.
|
|
73
|
-
"@zakodium/nmrium-core-plugins": "^0.3.
|
|
72
|
+
"@zakodium/nmrium-core": "^0.2.2",
|
|
73
|
+
"@zakodium/nmrium-core-plugins": "^0.3.4",
|
|
74
74
|
"@zip.js/zip.js": "^2.8.7",
|
|
75
75
|
"cheminfo-font": "^1.13.1",
|
|
76
76
|
"cheminfo-types": "^1.8.1",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"nmr-correlation": "2.3.3",
|
|
97
97
|
"nmr-processing": "^19.3.2",
|
|
98
98
|
"numeral": "^2.0.6",
|
|
99
|
-
"openchemlib": "^9.
|
|
99
|
+
"openchemlib": "^9.10.0",
|
|
100
100
|
"openchemlib-utils": "^8.6.0",
|
|
101
101
|
"papaparse": "^5.5.3",
|
|
102
102
|
"react-d3-utils": "^3.1.2",
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"react-ocl-nmr": "^4.1.1",
|
|
111
111
|
"react-plot": "^3.1.1",
|
|
112
112
|
"react-rnd": "^10.5.2",
|
|
113
|
-
"react-science": "^19.
|
|
113
|
+
"react-science": "^19.3.0",
|
|
114
114
|
"react-table": "^7.8.0",
|
|
115
115
|
"smart-array-filter": "^5.0.0",
|
|
116
116
|
"yup": "^1.7.1"
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"@blueprintjs/core": "^6.3.1",
|
|
120
120
|
"@blueprintjs/icons": "^6.1.0",
|
|
121
121
|
"@blueprintjs/select": "^6.0.5",
|
|
122
|
-
"@playwright/test": "^1.
|
|
122
|
+
"@playwright/test": "^1.56.0",
|
|
123
123
|
"@simbathesailor/use-what-changed": "^2.0.0",
|
|
124
124
|
"@types/d3-array": "^3.2.2",
|
|
125
125
|
"@types/d3-scale": "^4.0.9",
|
|
@@ -127,35 +127,35 @@
|
|
|
127
127
|
"@types/dlv": "^1.1.5",
|
|
128
128
|
"@types/file-saver": "^2.0.7",
|
|
129
129
|
"@types/lodash": "^4.17.20",
|
|
130
|
-
"@types/node": "^24.7.
|
|
130
|
+
"@types/node": "^24.7.1",
|
|
131
131
|
"@types/numeral": "^2.0.5",
|
|
132
132
|
"@types/papaparse": "^5.3.16",
|
|
133
133
|
"@types/react": "^18.3.13",
|
|
134
134
|
"@types/react-dom": "^18.3.1",
|
|
135
135
|
"@types/react-table": "^7.7.20",
|
|
136
|
-
"@vitejs/plugin-react": "^5.0.
|
|
136
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
137
137
|
"@vitest/coverage-v8": "^3.2.4",
|
|
138
138
|
"@zakodium/tsconfig": "^1.0.2",
|
|
139
|
-
"cross-env": "^10.
|
|
139
|
+
"cross-env": "^10.1.0",
|
|
140
140
|
"cspell": "^9.2.1",
|
|
141
|
-
"eslint": "^9.
|
|
142
|
-
"eslint-config-cheminfo-react": "^18.0.
|
|
141
|
+
"eslint": "^9.37.0",
|
|
142
|
+
"eslint-config-cheminfo-react": "^18.0.1",
|
|
143
143
|
"eslint-config-cheminfo-typescript": "^20.0.0",
|
|
144
|
-
"knip": "^5.64.
|
|
144
|
+
"knip": "^5.64.3",
|
|
145
145
|
"modern-normalize": "^3.0.1",
|
|
146
146
|
"postcss-styled-syntax": "^0.7.1",
|
|
147
147
|
"prettier": "^3.6.2",
|
|
148
148
|
"rc-menu": "^9.16.1",
|
|
149
149
|
"react": "^18.3.1",
|
|
150
150
|
"react-dom": "^18.3.1",
|
|
151
|
-
"react-router-dom": "^7.9.
|
|
151
|
+
"react-router-dom": "^7.9.4",
|
|
152
152
|
"rimraf": "^6.0.1",
|
|
153
153
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
154
154
|
"serve": "^14.2.5",
|
|
155
|
-
"stylelint": "^16.
|
|
156
|
-
"stylelint-config-standard": "^39.0.
|
|
157
|
-
"typescript": "^5.9.
|
|
158
|
-
"vite": "^7.1.
|
|
155
|
+
"stylelint": "^16.25.0",
|
|
156
|
+
"stylelint-config-standard": "^39.0.1",
|
|
157
|
+
"typescript": "^5.9.3",
|
|
158
|
+
"vite": "^7.1.9",
|
|
159
159
|
"vitest": "^3.2.4"
|
|
160
160
|
},
|
|
161
161
|
"volta": {
|
|
@@ -13,10 +13,10 @@ import { useGlobal } from '../context/GlobalContext.js';
|
|
|
13
13
|
import type { ActionsButtonsPopoverProps } from '../elements/ActionsButtonsPopover.js';
|
|
14
14
|
import { ActionsButtonsPopover } from '../elements/ActionsButtonsPopover.js';
|
|
15
15
|
import { useActiveNucleusTab } from '../hooks/useActiveNucleusTab.ts';
|
|
16
|
-
import { useCanvasContext } from '../hooks/useCanvasContext.js';
|
|
17
16
|
import { usePanelPreferences } from '../hooks/usePanelPreferences.js';
|
|
18
17
|
import { useSVGUnitConverter } from '../hooks/useSVGUnitConverter.js';
|
|
19
18
|
import useSpectraByActiveNucleus from '../hooks/useSpectraPerNucleus.js';
|
|
19
|
+
import { useTextMetrics } from '../hooks/useTextMetrics.ts';
|
|
20
20
|
import { useCheckExportStatus } from '../hooks/useViewportSize.js';
|
|
21
21
|
|
|
22
22
|
const ReactRnd = styled(Rnd)`
|
|
@@ -32,11 +32,6 @@ const ReactRnd = styled(Rnd)`
|
|
|
32
32
|
}
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
|
-
function calculateWorldWidth(context: any, word: any) {
|
|
36
|
-
if (!context) return 0;
|
|
37
|
-
return Math.round(context.measureText(word).width);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
35
|
interface UseWrapSVGTextParams {
|
|
41
36
|
text: string;
|
|
42
37
|
width: number;
|
|
@@ -45,7 +40,7 @@ interface UseWrapSVGTextParams {
|
|
|
45
40
|
|
|
46
41
|
function useWrapSVGText(params: UseWrapSVGTextParams) {
|
|
47
42
|
const { text, width, fontSize } = params;
|
|
48
|
-
const
|
|
43
|
+
const { getTextWidth } = useTextMetrics(fontSize);
|
|
49
44
|
|
|
50
45
|
const formattedText = text
|
|
51
46
|
.replaceAll(/<sup>(?<n>.*?)<\/sup>/g, '++$1++ ')
|
|
@@ -57,11 +52,11 @@ function useWrapSVGText(params: UseWrapSVGTextParams) {
|
|
|
57
52
|
let line: string[] = [];
|
|
58
53
|
let lineWidth = 0;
|
|
59
54
|
|
|
60
|
-
const spaceWidth =
|
|
55
|
+
const spaceWidth = getTextWidth(' ');
|
|
61
56
|
const words = formattedText.split(' ');
|
|
62
57
|
|
|
63
58
|
for (const word of words) {
|
|
64
|
-
const wordWidth =
|
|
59
|
+
const wordWidth = getTextWidth(word);
|
|
65
60
|
if (lineWidth + wordWidth > width) {
|
|
66
61
|
lines.push(line);
|
|
67
62
|
line = [word];
|
|
@@ -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;
|
|
@@ -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
|
|