Skip to content
Merged
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.1",
"@hookform/resolvers": "^5.2.2",
"@zakodium/nmr-types": "^0.4.5",
"@zakodium/nmrium-core": "^0.4.13",
"@zakodium/nmrium-core-plugins": "^0.6.17",
"@zakodium/nmr-types": "^0.5.0",
"@zakodium/nmrium-core": "^0.5.0",
"@zakodium/nmrium-core-plugins": "^0.6.18",
"@zakodium/pdnd-esm": "^1.0.2",
"@zip.js/zip.js": "^2.8.11",
"cheminfo-font": "^1.13.1",
Expand All @@ -96,7 +96,7 @@
"ml-spectra-processing": "^14.18.1",
"ml-tree-similarity": "^2.2.0",
"nmr-correlation": "2.3.3",
"nmr-processing": "^21.2.4",
"nmr-processing": "^22.0.0",
"numeral": "^2.0.6",
"openchemlib": "^9.18.2",
"openchemlib-utils": "^8.8.1",
Expand Down
1 change: 1 addition & 0 deletions public/data/ibuprofen.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/component/1d/SVGContent1D.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ClipPathContainer } from '../1d-2d/components/ClipPathContainer.js';
import SpectrumInfoBlock from '../1d-2d/components/SpectrumInfoBlock.js';
import { ShareDataProvider } from '../context/ShareDataContext.tsx';

import { ApodizationLine } from './ApodizationLine.js';
import ExclusionZonesAnnotations from './ExclusionZonesAnnotations.js';
Expand Down Expand Up @@ -30,9 +31,12 @@ export function SVGContent1D() {
<IntegralsSeries />
<Peaks peaksSource="peaks" />
<RangesIntegrals />
<Ranges />
<ShareDataProvider>
<Ranges />
<MultiplicityTrees />
</ShareDataProvider>

<Peaks peaksSource="ranges" />
<MultiplicityTrees />
<MultiAnalysisRanges />
<BaseLineZones />
<ExclusionZonesAnnotations />
Expand Down
47 changes: 24 additions & 23 deletions src/component/1d/multiplicityTree/MultiplicityTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import type { Spectrum1D } from '@zakodium/nmrium-core';
import { xFindClosestIndex } from 'ml-spectra-processing';
import { useRef } from 'react';
import { LuLink, LuUnlink } from 'react-icons/lu';

import { isSpectrum1D } from '../../../data/data1d/Spectrum1D/index.js';
import type { AssignmentsData } from '../../assignment/AssignmentsContext.js';
import { useAssignment } from '../../assignment/AssignmentsContext.js';
import { useChartData } from '../../context/ChartContext.js';
import { useDispatch } from '../../context/DispatchContext.js';
import { useScaleChecked } from '../../context/ScaleContext.js';
import type { ActionsButtonsPopoverProps } from '../../elements/ActionsButtonsPopover.js';
import { ActionsButtonsPopover } from '../../elements/ActionsButtonsPopover.js';
import { useHighlight } from '../../highlight/index.js';
import { useActiveSpectrum } from '../../hooks/useActiveSpectrum.ts';
import useSpectrum from '../../hooks/useSpectrum.js';
import { useIsInset } from '../inset/InsetProvider.js';
import { useAssignmentsPopoverActionsButtons } from '../ranges/useAssignmentsPopoverActionsButtons.tsx';

import type { TreeNodes } from './generateTreeNodes.js';
import { generateTreeNodes } from './generateTreeNodes.js';
Expand Down Expand Up @@ -76,7 +75,15 @@
signalIndex,
range,
startY: originStartY,
treeNodes: { multiplicity = '', nodes, min, max, signalKey, diaIDs },
treeNodes: {
multiplicity = '',
nodes,
min,
max,
signalKey,
diaIDs,
assignment: assignmentLabel,
},
} = props;
const { from, to } = range;
const { width } = useChartData();
Expand Down Expand Up @@ -118,6 +125,18 @@
startY,
});

const hasDiaIDs = Array.isArray(diaIDs) && diaIDs.length > 0;
const isAssignmentActive = assignment.isActive;

const actionsButtons = useAssignmentsPopoverActionsButtons({
isUnAssignButtonVisible: isAssignmentActive || hasDiaIDs,
isAssignLabelButtonVisible: !assignmentLabel,
isUnAssignLabelButtonVisible: !!assignmentLabel,
onAssign: assignHandler,
onUnAssign: unAssignHandler,
rangeId: range.id,
});

if (!multiplicity) return null;

function assignHandler() {
Expand All @@ -127,38 +146,20 @@

function unAssignHandler() {
dispatch({
type: 'UNLINK_RANGE',
type: 'UNASSIGN_1D_SIGNAL',
payload: {
rangeKey: range.id,
signalIndex,
},
});
}
const hasDiaIDs = Array.isArray(diaIDs) && diaIDs.length > 0;
const isAssignmentActive = assignment.isActive;

const isHighlighted = highlight.isActive || isAssignmentActive;
const padding = boxPadding * widthRatio;
const x = scaleX()(max) - padding;
const y = startY - headTextMargin - headerTextSize - padding;
const boxWidth = treeWidth + padding * 2;
const boxHeight = treeHeight + headTextMargin + headerTextSize + padding * 2;

const actionsButtons: ActionsButtonsPopoverProps['buttons'] = [
{
icon: <LuLink />,
onClick: assignHandler,
intent: 'success',
title: 'Assign range',
},
{
icon: <LuUnlink />,
onClick: () => unAssignHandler(),
intent: 'danger',
title: 'Unassign range',
visible: isAssignmentActive || hasDiaIDs,
},
];

const isOpen = isAssignBtnTrigged.current ? isAssignmentActive : undefined;

return (
Expand Down Expand Up @@ -240,7 +241,7 @@

return (
<text
key={index}

Check warning on line 244 in src/component/1d/multiplicityTree/MultiplicityTree.tsx

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Do not use Array index in keys
x={x1}
y={startY + y}
textAnchor="middle"
Expand Down
11 changes: 10 additions & 1 deletion src/component/1d/multiplicityTree/generateTreeNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
multiplicity?: string;
nodes: TreeNode[];
diaIDs?: string[];
assignment?: string;
min: number;
max: number;
}

export function generateTreeNodes(range: Range, spectrumData: Spectrum1D) {
// TODO: make sure spectrumData is not a lie and remove the optional chaining.

Check warning on line 28 in src/component/1d/multiplicityTree/generateTreeNodes.ts

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Unexpected 'todo' comment: 'TODO: make sure spectrumData is not a...'
const frequency = spectrumData?.info?.originFrequency;

const result: TreeNodes[] = [];
Expand Down Expand Up @@ -78,7 +79,14 @@
for (const signal of signals || []) {
nodes = [];

const { multiplicity, js, delta, id: signalKey, diaIDs } = signal;
const {
multiplicity,
js,
delta,
id: signalKey,
diaIDs,
assignment,
} = signal;
const minMax = { min: delta, max: delta };

nodes.push({
Expand All @@ -104,6 +112,7 @@
rangeKey,
signalKey,
diaIDs,
assignment,
multiplicity,
nodes,
...minMax,
Expand Down
13 changes: 8 additions & 5 deletions src/component/1d/ranges/AssignmentLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Range } from '@zakodium/nmr-types';
import type { Range, Signal1D } from '@zakodium/nmr-types';
import { useRef } from 'react';

import { FieldEdition } from '../../1d-2d/FieldEdition.js';
Expand All @@ -11,31 +11,34 @@ const marginTop = 15;

interface AssignmentLabelProps {
range: Range;
signal: Signal1D;
width: number;
stackIndex: number;
}

export function AssignmentLabel(props: AssignmentLabelProps) {
const { range, width, stackIndex } = props;
const { id, assignment } = range;
const { range, width, stackIndex, signal } = props;
const { id } = range;
const { assignment } = signal;
const { showAssignmentsLabels } = useActiveSpectrumRangesViewState();
const dispatch = useDispatch();
const textRef = useRef<SVGTextElement>(null);
const { margin } = useChartData();
const { isNewAssignment, dismissNewLabel } = useTriggerNewAssignmentLabel(id);

if ((!range.assignment || !showAssignmentsLabels) && !isNewAssignment) {
if ((!assignment || !showAssignmentsLabels) && !isNewAssignment) {
return null;
}

function handleChange(value: string) {
dismissNewLabel();

dispatch({
type: 'CHANGE_RANGE_ASSIGNMENT_LABEL',
type: 'CHANGE_1D_SIGNAL_ASSIGNMENT_LABEL',
payload: {
value,
rangeId: id,
signalId: signal.id,
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/component/1d/ranges/Atoms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const fontSize = 12;
const marginTop = 45;

function getDiaIds(range: Range) {
const { diaIDs = [], signals } = range;
const ids = diaIDs.slice();
const { signals } = range;
const ids = [];
for (const signal of signals) {
if (signal?.diaIDs) {
ids.push(...signal.diaIDs);
Expand Down
Loading
Loading