Skip to content

Commit

Permalink
fix: map the filters and be sure to have an id object
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Oct 5, 2023
1 parent 0b1e030 commit 094d6ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/data/data1d/Spectrum1D/initiateDatum1D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { initiatePeaks } from './peaks/initiatePeaks';
import { initiateRanges } from './ranges/initiateRanges';
import { initSumOptions } from './SumManager';
import { StateMoleculeExtended } from '../../molecules/Molecule';
import { initiateFilters } from '../../initiateFilters';

export interface InitiateDatum1DOptions {
usedColors?: UsedColors;
Expand Down Expand Up @@ -53,7 +54,7 @@ export function initiateDatum1D(

spectrumObj.originalData = spectrumObj.data;

spectrumObj.filters = Object.assign([], spectrum.filters); //array of object {name: "FilterName", options: FilterOptions = {value | object} }
spectrumObj.filters = initiateFilters(spectrum?.filters); //array of object {name: "FilterName", options: FilterOptions = {value | object} }

const { nucleus } = spectrumObj.info;

Expand Down
3 changes: 2 additions & 1 deletion src/data/data2d/Spectrum2D/initiateDatum2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FiltersManager } from 'nmr-processing';
import { DEFAULT_CONTOURS_OPTIONS } from './contours';
import { get2DColor } from './get2DColor';
import { initiateZones } from './zones/initiateZones';
import { initiateFilters } from '../../initiateFilters';

const defaultMinMax = { z: [], minX: 0, minY: 0, maxX: 0, maxY: 0 };

Expand Down Expand Up @@ -40,7 +41,7 @@ export function initiateDatum2D(spectrum: any, usedColors = {}): Spectrum2D {

datum.data = getData(datum, spectrum);
datum.originalData = datum.data;
datum.filters = Object.assign([], spectrum.filters);
datum.filters = initiateFilters(spectrum?.filters);

datum.zones = initiateZones(spectrum, datum as Spectrum2D);

Expand Down
8 changes: 8 additions & 0 deletions src/data/initiateFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { v4 } from '@lukeed/uuid';
import { Filter } from 'nmr-processing';

export function initiateFilters(inputFilters: Filter[] | undefined) {
if (!inputFilters || !Array.isArray(inputFilters)) return [];

return inputFilters.map((filter) => ({ ...filter, id: filter?.id || v4() }));
}

0 comments on commit 094d6ee

Please sign in to comment.