Skip to content

Commit

Permalink
feat: improve signal kinds for ranges and integrals
Browse files Browse the repository at this point in the history
close #2600
  • Loading branch information
hamed-musallam committed Sep 13, 2023
1 parent 53fff90 commit a8ca174
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/component/2d/zones/IndicationLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from '@emotion/react';
import { Spectrum1D } from 'nmr-load-save';
import { useState, useEffect, useMemo } from 'react';

import { SignalKindsToInclude } from '../../../data/constants/SignalsKinds';
import { SIGNAL_INLCUDED_KINDS } from '../../../data/constants/signalsKinds';
import { isSpectrum1D } from '../../../data/data1d/Spectrum1D';
import { useChartData } from '../../context/ChartContext';
import { get2DXScale, get2DYScale } from '../utilities/scale';
Expand Down Expand Up @@ -52,7 +52,7 @@ function IndicationLines({ axis, show }: IndicationLinesProps) {
const deltas = ranges.flatMap((_range) =>
_range.signals
.filter((_signal) =>
SignalKindsToInclude.includes(_signal.kind as string),
SIGNAL_INLCUDED_KINDS.includes(_signal.kind as string),
)
.map((_signal) => _signal.delta),
);
Expand Down
4 changes: 2 additions & 2 deletions src/component/panels/IntegralsPanel/IntegralTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Info1D, Integral } from 'nmr-processing';
import { useCallback, useMemo, memo } from 'react';
import { FaRegTrashAlt } from 'react-icons/fa';

import { SignalKinds } from '../../../data/constants/SignalsKinds';
import { SIGNAL_KINDS } from '../../../data/constants/signalsKinds';
import { checkIntegralKind } from '../../../data/data1d/Spectrum1D';
import { useDispatch } from '../../context/DispatchContext';
import EditableColumn from '../../elements/EditableColumn';
Expand Down Expand Up @@ -139,7 +139,7 @@ function IntegralTable({ activeTab, data, info }: IntegralTableProps) {
Cell: ({ row }) => (
<Select
onChange={(value) => changeIntegralDataHandler(value, row)}
items={SignalKinds}
items={SIGNAL_KINDS}
style={selectStyle}
defaultValue={row.original.kind}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from '@emotion/react';
import { Fragment, CSSProperties } from 'react';
import { FaRegTrashAlt, FaSearchPlus, FaEdit } from 'react-icons/fa';

import { SignalKinds } from '../../../../data/constants/SignalsKinds';
import { SIGNAL_KINDS } from '../../../../data/constants/signalsKinds';
import Select from '../../../elements/Select';
import {
OnHoverEvent,
Expand Down Expand Up @@ -64,7 +64,7 @@ function ActionsColumn({
<td {...onHoverSignal}>
<Select
onChange={changeRangeSignalKind}
items={SignalKinds}
items={SIGNAL_KINDS}
defaultValue={row.tableMetaInfo.signal.kind}
style={selectBoxStyle}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CSSProperties, Fragment, useCallback } from 'react';
import { FaEdit, FaRegTrashAlt, FaSearchPlus } from 'react-icons/fa';

import { SignalKinds } from '../../../../data/constants/SignalsKinds';
import { SIGNAL_KINDS } from '../../../../data/constants/signalsKinds';
import { useAssignmentData } from '../../../assignment/AssignmentsContext';
import { useDispatch } from '../../../context/DispatchContext';
import Select from '../../../elements/Select';
Expand Down Expand Up @@ -128,7 +128,7 @@ function ActionsColumn({
onChange={(value) => {
changeSignalKindHandler(value);
}}
items={SignalKinds}
items={SIGNAL_KINDS}
defaultValue={rowData.tableMetaInfo.signal.kind}
style={selectBoxStyle}
/>
Expand Down
12 changes: 6 additions & 6 deletions src/component/reducer/actions/RangesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { RangesViewState, Spectrum, Spectrum1D } from 'nmr-load-save';
import { Signal1D, Range, Filters, FiltersManager } from 'nmr-processing';

import {
DatumKind,
SignalKindsToInclude,
} from '../../../data/constants/SignalsKinds';
DATUM_KIND,
SIGNAL_INLCUDED_KINDS,
} from '../../../data/constants/signalsKinds';
import {
addRange,
changeRangeSignal,
Expand Down Expand Up @@ -279,9 +279,9 @@ function handleChangeRangeSignalKind(
const _range = (draft.data[index] as Spectrum1D).ranges.values[rangeIndex];
if (_range?.signals) {
_range.signals[range.tableMetaInfo.signalIndex].kind = kind;
_range.kind = SignalKindsToInclude.includes(kind)
? DatumKind.signal
: DatumKind.mixed;
_range.kind = SIGNAL_INLCUDED_KINDS.includes(kind)
? DATUM_KIND.signal
: DATUM_KIND.mixed;
updateRangesRelativeValues(draft.data[index] as Spectrum1D);
handleUpdateCorrelations(draft);
}
Expand Down
12 changes: 6 additions & 6 deletions src/component/reducer/actions/ZonesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { Signal2D, Zone } from 'nmr-processing';
import { Filters, FiltersManager } from 'nmr-processing';

import {
DatumKind,
SignalKindsToInclude,
} from '../../../data/constants/SignalsKinds';
DATUM_KIND,
SIGNAL_INLCUDED_KINDS,
} from '../../../data/constants/signalsKinds';
import {
changeZoneSignal,
detectZones,
Expand Down Expand Up @@ -245,9 +245,9 @@ function handleChangeZoneSignalKind(
const zoneIndex = getZoneIndex(state, index, zoneData.id);
const _zone = (draft.data[index] as Spectrum2D).zones.values[zoneIndex];
_zone.signals[zoneData.tableMetaInfo.signalIndex].kind = kind;
_zone.kind = SignalKindsToInclude.includes(kind)
? DatumKind.signal
: DatumKind.mixed;
_zone.kind = SIGNAL_INLCUDED_KINDS.includes(kind)
? DATUM_KIND.signal
: DATUM_KIND.mixed;
handleUpdateCorrelations(draft);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/PredictionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from 'nmr-processing';
import OCL from 'openchemlib/full';

import { DatumKind } from './constants/SignalsKinds';
import { DATUM_KIND } from './constants/signalsKinds';
import {
initiateDatum1D,
mapRanges,
Expand Down Expand Up @@ -306,7 +306,7 @@ function mapZones(zones: Array<Partial<Zone>>) {
id: v4(),
...resZone,
signals: newSignals,
kind: DatumKind.signal,
kind: DATUM_KIND.signal,
};
});
}
Expand Down
37 changes: 0 additions & 37 deletions src/data/constants/SignalsKinds.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/data/constants/signalsKinds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { stringCapitalize } from '../../utils/stringCapitalize';
import { SignalKind } from '../types/common/SignalKind';

const KINDS: SignalKind[] = [
'undefined',
'signal',
'reference',
'solvent',
'standard',
'p1',
'p2',
'p3',
];

interface SignalKindItem {
value: SignalKind;
label: string;
}

export const SIGNAL_KINDS: SignalKindItem[] = KINDS.map((key) => ({
value: key,
label: stringCapitalize(key),
}));

export const SIGNAL_INLCUDED_KINDS: SignalKind[] = ['signal'];
export const DATUM_KIND = { signal: 'signal', mixed: 'mixed' } as const;
4 changes: 2 additions & 2 deletions src/data/data1d/Spectrum1D/ranges/addRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { xyIntegration } from 'ml-spectra-processing';
import { Spectrum1D } from 'nmr-load-save';
import { Signal1D, mapRanges } from 'nmr-processing';

import { DatumKind } from '../../../constants/SignalsKinds';
import { DATUM_KIND } from '../../../constants/signalsKinds';

import detectSignal from './detectSignal';

Expand All @@ -24,7 +24,7 @@ export function createRangeObj({
to,
absolute, // the real value,
signals: [{ id: v4(), ...signal }],
kind: DatumKind.signal,
kind: DATUM_KIND.signal,
integration: 0,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/data1d/Spectrum1D/ranges/checkRangeKind.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Range } from 'nmr-processing';

import { SignalKindsToInclude } from '../../../constants/SignalsKinds';
import { SIGNAL_INLCUDED_KINDS } from '../../../constants/signalsKinds';
import { checkSignalKinds } from '../../../utilities/RangeUtilities';

export function checkRangeKind(range: Range): boolean {
return range.signals && checkSignalKinds(range, SignalKindsToInclude);
return range.signals && checkSignalKinds(range, SIGNAL_INLCUDED_KINDS);
}
11 changes: 11 additions & 0 deletions src/data/types/common/SignalKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type SignalKind =
| 'undefined'
| 'signal'
| 'reference'
| 'impurity'
| 'standard'
| 'p1'
| 'p2'
| 'p3'
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {});
4 changes: 2 additions & 2 deletions src/data/utilities/RangeUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import omit from 'lodash/omit';
import { Range, Signal1D } from 'nmr-processing';

import { DatumKind } from '../constants/SignalsKinds';
import { DATUM_KIND } from '../constants/signalsKinds';

export function getDiaIDs(range: Range): string[] {
return ([] as string[]).concat(
Expand Down Expand Up @@ -88,7 +88,7 @@ export function addDefaultSignal(range) {
}

export function checkRangeKind(range) {
return range.kind === DatumKind.signal;
return range.kind === DATUM_KIND.signal;
}

export function checkSignalKinds(range, kinds) {
Expand Down
4 changes: 2 additions & 2 deletions src/data/utilities/ZoneUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Zone } from 'nmr-processing';

import { DatumKind } from '../constants/SignalsKinds';
import { DATUM_KIND } from '../constants/signalsKinds';

export function getDiaIDs(zone: Zone, axis: string): string[] {
return ([] as string[]).concat(
Expand Down Expand Up @@ -39,7 +39,7 @@ export function resetDiaIDs(zone: Zone, axis: string) {
}

export function checkZoneKind(zone: Zone): boolean {
return zone.kind === DatumKind.signal;
return zone.kind === DATUM_KIND.signal;
}

export function checkSignalKinds(zone: Zone, kinds: string[]): boolean {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/stringCapitalize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function stringCapitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

0 comments on commit a8ca174

Please sign in to comment.