@complat/react-spectra-editor 1.2.2 → 1.3.2

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.
@@ -20,6 +20,7 @@ const spectraDigit = layout => {
20
20
  case _list_layout.LIST_LAYOUT.UVVIS:
21
21
  case _list_layout.LIST_LAYOUT.HPLC_UVVIS:
22
22
  case _list_layout.LIST_LAYOUT.TGA:
23
+ case _list_layout.LIST_LAYOUT.DSC:
23
24
  case _list_layout.LIST_LAYOUT.XRD:
24
25
  case _list_layout.LIST_LAYOUT.CDS:
25
26
  case _list_layout.LIST_LAYOUT.SEC:
@@ -110,6 +111,10 @@ const spectraOps = {
110
111
  head: 'THERMOGRAVIMETRIC ANALYSIS',
111
112
  tail: ' SECONDS'
112
113
  },
114
+ [_list_layout.LIST_LAYOUT.DSC]: {
115
+ head: 'DIFFERENTIAL SCANNING CALORIMETRY',
116
+ tail: ' SECONDS'
117
+ },
113
118
  [_list_layout.LIST_LAYOUT.MS]: {
114
119
  head: 'MASS',
115
120
  tail: ' m/z'
@@ -119,7 +124,7 @@ const spectraOps = {
119
124
  tail: '.'
120
125
  },
121
126
  [_list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY]: {
122
- head: 'CYCLIC VOLTAMMETRY',
127
+ head: 'CV',
123
128
  tail: '.'
124
129
  },
125
130
  [_list_layout.LIST_LAYOUT.CDS]: {
@@ -411,7 +416,7 @@ const peaksBody = _ref => {
411
416
  if (layout === _list_layout.LIST_LAYOUT.DLS_INTENSITY) {
412
417
  return formatedDLSIntensity(ordered, maxY, decimal, isAscend, isIntensity, boundary, false);
413
418
  }
414
- if (layout === _list_layout.LIST_LAYOUT.RAMAN || layout === _list_layout.LIST_LAYOUT.TGA || layout === _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY || layout === _list_layout.LIST_LAYOUT.CDS || layout === _list_layout.LIST_LAYOUT.SEC) {
419
+ if (layout === _list_layout.LIST_LAYOUT.RAMAN || layout === _list_layout.LIST_LAYOUT.TGA || layout === _list_layout.LIST_LAYOUT.DSC || layout === _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY || layout === _list_layout.LIST_LAYOUT.CDS || layout === _list_layout.LIST_LAYOUT.SEC) {
415
420
  return formatedEm(ordered, maxY, decimal, isAscend, isIntensity, boundary, false);
416
421
  }
417
422
  if (layout === _list_layout.LIST_LAYOUT.XRD) {
@@ -454,6 +459,7 @@ const isRamanLayout = layoutSt => _list_layout.LIST_LAYOUT.RAMAN === layoutSt;
454
459
  const isUvVisLayout = layoutSt => _list_layout.LIST_LAYOUT.UVVIS === layoutSt;
455
460
  const isHplcUvVisLayout = layoutSt => _list_layout.LIST_LAYOUT.HPLC_UVVIS === layoutSt;
456
461
  const isTGALayout = layoutSt => _list_layout.LIST_LAYOUT.TGA === layoutSt;
462
+ const isDSCLayout = layoutSt => _list_layout.LIST_LAYOUT.DSC === layoutSt;
457
463
  const isXRDLayout = layoutSt => _list_layout.LIST_LAYOUT.XRD === layoutSt;
458
464
  const isCyclicVoltaLayout = layoutSt => _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY === layoutSt;
459
465
  const isCDSLayout = layoutSt => _list_layout.LIST_LAYOUT.CDS === layoutSt;
@@ -538,6 +544,92 @@ const strNumberFixedLength = function (number) {
538
544
 
539
545
  return number.toFixed(lengthToFix);
540
546
  };
547
+ const inlineNotation = function (layout, data) {
548
+ let sampleName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
549
+ let formattedString = '';
550
+ let quillData = [];
551
+ const {
552
+ scanRate,
553
+ voltaData
554
+ } = data;
555
+ switch (layout) {
556
+ case _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY:
557
+ {
558
+ if (!voltaData) {
559
+ break;
560
+ }
561
+ let refString = '';
562
+ let nonRefString = '';
563
+ let refOps = [];
564
+ const nonRefOps = [];
565
+ const {
566
+ listPeaks,
567
+ xyData
568
+ } = voltaData;
569
+ const {
570
+ x
571
+ } = xyData;
572
+ listPeaks.forEach(item => {
573
+ const {
574
+ isRef,
575
+ e12,
576
+ max,
577
+ min
578
+ } = item;
579
+ const e12Str = e12 ? strNumberFixedLength(e12, 3) : '0';
580
+ const scanRateStr = scanRate ? strNumberFixedLength(scanRate, 3) : '0';
581
+ if (isRef) {
582
+ const posNegString = x[0] > x[1] ? 'neg.' : 'pos.';
583
+ refString = `CV (<conc. of sample> mM in <solvent> vs. Ref (Fc+/Fc) = ${e12Str} V, v = ${scanRateStr} V/s, to ${posNegString}):`;
584
+ refOps = [{
585
+ insert: 'CV (<conc. of sample> mM in <solvent> vs. Ref '
586
+ }, {
587
+ insert: '(Fc'
588
+ }, {
589
+ insert: '+',
590
+ attributes: {
591
+ script: 'super'
592
+ }
593
+ }, {
594
+ insert: '/Fc) '
595
+ }, {
596
+ insert: `= ${e12Str} V, v = ${scanRateStr} V/s, to ${posNegString}):`
597
+ }];
598
+ } else {
599
+ const delta = max && min ? strNumberFixedLength(Math.abs(max.x - min.x) * 1000, 3) : '0';
600
+ nonRefString += `\nE1/2 = ([${sampleName}] , ΔEp) = ${e12Str} V (${delta} mV)`;
601
+ const currentNoneOps = [{
602
+ insert: '\nE'
603
+ }, {
604
+ insert: '1/2',
605
+ attributes: {
606
+ script: 'sub'
607
+ }
608
+ }, {
609
+ insert: ` = ([${sampleName}] , ΔE`
610
+ }, {
611
+ insert: 'p',
612
+ attributes: {
613
+ script: 'sub'
614
+ }
615
+ }, {
616
+ insert: `) = ${e12Str} V (${delta} mV)`
617
+ }];
618
+ nonRefOps.push(...currentNoneOps);
619
+ }
620
+ });
621
+ formattedString = refString + nonRefString;
622
+ quillData = [...refOps, ...nonRefOps];
623
+ break;
624
+ }
625
+ default:
626
+ break;
627
+ }
628
+ return {
629
+ quillData,
630
+ formattedString
631
+ };
632
+ };
541
633
  const Format = {
542
634
  toPeakStr,
543
635
  buildData,
@@ -560,6 +652,7 @@ const Format = {
560
652
  isUvVisLayout,
561
653
  isHplcUvVisLayout,
562
654
  isTGALayout,
655
+ isDSCLayout,
563
656
  isXRDLayout,
564
657
  isCyclicVoltaLayout,
565
658
  isCDSLayout,
@@ -579,6 +672,7 @@ const Format = {
579
672
  isDLSACFLayout,
580
673
  strNumberFixedDecimal,
581
674
  formatedXRD,
582
- strNumberFixedLength
675
+ strNumberFixedLength,
676
+ inlineNotation
583
677
  };
584
678
  var _default = exports.default = Format;
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ var _uv_vis_jcamp = _interopRequireDefault(require("./__tests__/fixtures/uv_vis_
27
27
  var _hplc_uvvis_jcamp = _interopRequireDefault(require("./__tests__/fixtures/hplc_uvvis_jcamp"));
28
28
  var _hplc_uvvis_jcamp_ = _interopRequireDefault(require("./__tests__/fixtures/hplc_uvvis_jcamp_2"));
29
29
  var _tga_jcamp = _interopRequireDefault(require("./__tests__/fixtures/tga_jcamp"));
30
+ var _dsc_jcamp = _interopRequireDefault(require("./__tests__/fixtures/dsc_jcamp"));
30
31
  var _xrd_jcamp_ = _interopRequireDefault(require("./__tests__/fixtures/xrd_jcamp_1"));
31
32
  var _xrd_jcamp_2 = _interopRequireDefault(require("./__tests__/fixtures/xrd_jcamp_2"));
32
33
  var _cyclic_voltammetry_ = _interopRequireDefault(require("./__tests__/fixtures/cyclic_voltammetry_1"));
@@ -64,6 +65,7 @@ const compUvVisEntity = _app.FN.ExtractJcamp(_compare_uv_vis_jcamp.default);
64
65
  const hplcUVVisEntity = _app.FN.ExtractJcamp(_hplc_uvvis_jcamp.default);
65
66
  const hplcUVVisEntity2 = _app.FN.ExtractJcamp(_hplc_uvvis_jcamp_.default);
66
67
  const tgaEntity = _app.FN.ExtractJcamp(_tga_jcamp.default);
68
+ const dscEntity = _app.FN.ExtractJcamp(_dsc_jcamp.default);
67
69
  const xrdEntity1 = _app.FN.ExtractJcamp(_xrd_jcamp_.default);
68
70
  const xrdEntity2 = _app.FN.ExtractJcamp(_xrd_jcamp_2.default);
69
71
  const cyclicVoltaEntity1 = _app.FN.ExtractJcamp(_cyclic_voltammetry_.default);
@@ -156,6 +158,8 @@ class DemoWriteIr extends _react.default.Component {
156
158
  return hplcUVVisEntity;
157
159
  case 'tga':
158
160
  return tgaEntity;
161
+ case 'dsc':
162
+ return dscEntity;
159
163
  case 'xrd':
160
164
  return xrdEntity1;
161
165
  case 'cyclic volta':
@@ -221,6 +225,7 @@ class DemoWriteIr extends _react.default.Component {
221
225
  case 'uv/vis':
222
226
  case 'hplc uv/vis':
223
227
  case 'tga':
228
+ case 'dsc':
224
229
  case 'xrd':
225
230
  case 'ms':
226
231
  case 'cyclic volta':
@@ -259,7 +264,9 @@ class DemoWriteIr extends _react.default.Component {
259
264
  decimal,
260
265
  isIntensity,
261
266
  integration,
262
- waveLength
267
+ waveLength,
268
+ cyclicvoltaSt,
269
+ curveSt
263
270
  } = _ref;
264
271
  const entity = this.loadEntity();
265
272
  const {
@@ -289,7 +296,36 @@ class DemoWriteIr extends _react.default.Component {
289
296
  temperature
290
297
  });
291
298
  const wrapper = _app.FN.peaksWrapper(layout, shift);
292
- const desc = this.rmDollarSign(wrapper.head) + body + wrapper.tail;
299
+ let desc = this.rmDollarSign(wrapper.head) + body + wrapper.tail;
300
+ if (_app.FN.isCyclicVoltaLayout(layout)) {
301
+ const {
302
+ spectraList
303
+ } = cyclicvoltaSt;
304
+ const {
305
+ curveIdx,
306
+ listCurves
307
+ } = curveSt;
308
+ const selectedVolta = spectraList[curveIdx];
309
+ const selectedCurve = listCurves[curveIdx];
310
+ const {
311
+ feature
312
+ } = selectedCurve;
313
+ const {
314
+ scanRate
315
+ } = feature;
316
+ const data = {
317
+ scanRate,
318
+ voltaData: {
319
+ listPeaks: selectedVolta.list,
320
+ xyData: feature.data[0]
321
+ }
322
+ };
323
+ const inlineData = _app.FN.inlineNotation(layout, data);
324
+ const {
325
+ formattedString
326
+ } = inlineData;
327
+ desc = formattedString;
328
+ }
293
329
  return desc;
294
330
  }
295
331
  formatMpy(_ref2) {
@@ -393,7 +429,9 @@ class DemoWriteIr extends _react.default.Component {
393
429
  decimal,
394
430
  isIntensity,
395
431
  integration,
396
- waveLength
432
+ waveLength,
433
+ cyclicvoltaSt,
434
+ curveSt
397
435
  } = _ref4;
398
436
  const desc = this.formatPks({
399
437
  peaks,
@@ -403,7 +441,10 @@ class DemoWriteIr extends _react.default.Component {
403
441
  decimal,
404
442
  isIntensity,
405
443
  integration,
406
- waveLength
444
+ waveLength,
445
+ // eslint-disable-line
446
+ cyclicvoltaSt,
447
+ curveSt // eslint-disable-line
407
448
  });
408
449
  this.setState({
409
450
  desc
@@ -625,6 +666,13 @@ class DemoWriteIr extends _react.default.Component {
625
666
  },
626
667
  onClick: this.onClick('tga')
627
668
  }, "TGA"), /*#__PURE__*/_react.default.createElement(_material.Button, {
669
+ id: "btn-dsc",
670
+ variant: "contained",
671
+ style: {
672
+ margin: '0 10px 0 10px'
673
+ },
674
+ onClick: this.onClick('dsc')
675
+ }, "DSC"), /*#__PURE__*/_react.default.createElement(_material.Button, {
628
676
  id: "btn-xrd",
629
677
  variant: "contained",
630
678
  style: {
@@ -61,7 +61,8 @@ class LayerInit extends _react.default.Component {
61
61
  resetInitMsAct,
62
62
  resetInitNmrAct,
63
63
  resetInitCommonWithIntergationAct,
64
- resetDetectorAct
64
+ resetDetectorAct,
65
+ updateDSCMetaDataAct
65
66
  } = this.props;
66
67
  resetInitCommonAct();
67
68
  resetDetectorAct();
@@ -96,6 +97,11 @@ class LayerInit extends _react.default.Component {
96
97
  resetInitCommonWithIntergationAct({
97
98
  integration
98
99
  });
100
+ } else if (_format.default.isDSCLayout(layout)) {
101
+ const {
102
+ dscMetaData
103
+ } = features;
104
+ updateDSCMetaDataAct(dscMetaData);
99
105
  }
100
106
  }
101
107
  initReducer() {
@@ -191,7 +197,8 @@ const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({
191
197
  updateOperationAct: _submit.updateOperation,
192
198
  updateMetaPeaksAct: _meta.updateMetaPeaks,
193
199
  addOthersAct: _jcamp.addOthers,
194
- setAllCurvesAct: _curve.setAllCurves
200
+ setAllCurvesAct: _curve.setAllCurves,
201
+ updateDSCMetaDataAct: _meta.updateDSCMetaData
195
202
  }, dispatch);
196
203
  LayerInit.propTypes = {
197
204
  entity: _propTypes.default.object.isRequired,
@@ -222,7 +229,8 @@ LayerInit.propTypes = {
222
229
  setAllCurvesAct: _propTypes.default.func.isRequired,
223
230
  userManualLink: _propTypes.default.object,
224
231
  // eslint-disable-line
225
- resetDetectorAct: _propTypes.default.func.isRequired
232
+ resetDetectorAct: _propTypes.default.func.isRequired,
233
+ updateDSCMetaDataAct: _propTypes.default.func.isRequired
226
234
  };
227
235
  var _default = exports.default = (0, _reactRedux.connect)(
228
236
  // eslint-disable-line
@@ -8,18 +8,40 @@ var _action_type = require("../constants/action_type");
8
8
  /* eslint-disable default-param-last, prefer-object-spread */
9
9
 
10
10
  const initialState = {
11
- xUnit: '',
12
- yUnit: ''
11
+ axes: [{
12
+ xUnit: '',
13
+ yUnit: ''
14
+ }]
13
15
  };
14
16
  const updateAxis = function (state, payload) {
15
17
  let isYAxis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
18
+ const {
19
+ value,
20
+ curveIndex
21
+ } = payload;
22
+ const {
23
+ axes
24
+ } = state;
25
+ let selectedAxes = axes[curveIndex];
26
+ if (!selectedAxes) {
27
+ selectedAxes = {
28
+ xUnit: '',
29
+ yUnit: ''
30
+ };
31
+ }
32
+ let newAxes = null;
16
33
  if (isYAxis) {
17
- return Object.assign({}, state, {
18
- yUnit: payload
34
+ newAxes = Object.assign({}, selectedAxes, {
35
+ yUnit: value
36
+ });
37
+ } else {
38
+ newAxes = Object.assign({}, selectedAxes, {
39
+ xUnit: value
19
40
  });
20
41
  }
42
+ axes[curveIndex] = newAxes;
21
43
  return Object.assign({}, state, {
22
- xUnit: payload
44
+ axes
23
45
  });
24
46
  };
25
47
  const axesReducer = function () {
@@ -13,14 +13,28 @@ const initialState = {
13
13
  intervalR: null,
14
14
  observeFrequency: null,
15
15
  deltaX: null
16
+ },
17
+ dscMetaData: {
18
+ meltingPoint: null,
19
+ tg: null
16
20
  }
17
21
  };
22
+ const updateMetaData = (state, action) => {
23
+ const {
24
+ dscMetaData
25
+ } = action.payload;
26
+ return Object.assign({}, state, {
27
+ dscMetaData
28
+ });
29
+ };
18
30
  const metaReducer = function () {
19
31
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
20
32
  let action = arguments.length > 1 ? arguments[1] : undefined;
21
33
  switch (action.type) {
22
34
  case _action_type.META.UPDATE_PEAKS_RDC:
23
35
  return Object.assign({}, state, action.payload);
36
+ case _action_type.META.UPDATE_META_DATA_RDC:
37
+ return updateMetaData(state, action);
24
38
  default:
25
39
  return state;
26
40
  }
@@ -13,6 +13,7 @@ const initialState = {
13
13
  };
14
14
  const initSpectra = {
15
15
  list: [],
16
+ origin: [],
16
17
  selectedIdx: -1,
17
18
  isWorkMaxPeak: true,
18
19
  jcampIdx: -1,
@@ -20,7 +21,9 @@ const initSpectra = {
20
21
  ref: null,
21
22
  val: 0,
22
23
  prevValue: 0
23
- }
24
+ },
25
+ hasRefPeak: false,
26
+ history: []
24
27
  };
25
28
  const addPairPeak = (state, action) => {
26
29
  const {
@@ -51,12 +54,14 @@ const addPairPeak = (state, action) => {
51
54
  min: null,
52
55
  max: null,
53
56
  isRef: false,
54
- e12: null
57
+ e12: null,
58
+ createdAt: Date.now()
55
59
  });
56
60
  spectraList[payload] = Object.assign({}, spectra, {
57
61
  list: newList,
58
- selectedIdx: index
59
- });
62
+ selectedIdx: index,
63
+ origin: [...newList]
64
+ }); // eslint-disable-line
60
65
  return Object.assign({}, state, {
61
66
  spectraList
62
67
  });
@@ -78,12 +83,15 @@ const removePairPeak = (state, action) => {
78
83
  const spectra = spectraList[jcampIdx];
79
84
  if (spectra) {
80
85
  const {
81
- list
86
+ list,
87
+ origin
82
88
  } = spectra;
83
89
  list.splice(index, 1);
90
+ origin.splice(index, 1);
84
91
  spectraList[jcampIdx] = Object.assign({}, spectra, {
85
92
  list,
86
- selectedIdx: index
93
+ selectedIdx: index,
94
+ origin
87
95
  });
88
96
  return Object.assign({}, state, {
89
97
  spectraList
@@ -139,11 +147,13 @@ const addPeak = function (state, action) {
139
147
  });
140
148
  }
141
149
  pairPeak.e12 = getE12(pairPeak);
150
+ pairPeak.updatedAt = Date.now();
142
151
  newList[index] = pairPeak;
143
152
  spectraList[jcampIdx] = Object.assign({}, spectra, {
144
153
  list: newList,
145
154
  selectedIdx: index,
146
- jcampIdx
155
+ jcampIdx,
156
+ origin: [...newList]
147
157
  });
148
158
  return Object.assign({}, state, {
149
159
  spectraList
@@ -176,11 +186,13 @@ const removePeak = function (state, action) {
176
186
  pairPeak.min = null;
177
187
  }
178
188
  pairPeak.e12 = getE12(pairPeak);
189
+ pairPeak.updatedAt = Date.now();
179
190
  newList[index] = pairPeak;
180
191
  spectraList[jcampIdx] = Object.assign({}, spectra, {
181
192
  list: newList,
182
193
  selectedIdx: index,
183
- jcampIdx
194
+ jcampIdx,
195
+ origin: [...newList]
184
196
  });
185
197
  return Object.assign({}, state, {
186
198
  spectraList
@@ -258,11 +270,13 @@ const addPecker = (state, action) => {
258
270
  const newList = list;
259
271
  const pairPeak = newList[index];
260
272
  pairPeak.pecker = peak;
273
+ pairPeak.updatedAt = Date.now();
261
274
  newList[index] = pairPeak;
262
275
  spectraList[jcampIdx] = Object.assign({}, spectra, {
263
276
  list: newList,
264
277
  selectedIdx: index,
265
- jcampIdx
278
+ jcampIdx,
279
+ origin: [...newList]
266
280
  });
267
281
  return Object.assign({}, state, {
268
282
  spectraList
@@ -289,11 +303,13 @@ const removePecker = (state, action) => {
289
303
  const newList = list;
290
304
  const pairPeak = newList[index];
291
305
  pairPeak.pecker = null;
306
+ pairPeak.updatedAt = Date.now();
292
307
  newList[index] = pairPeak;
293
308
  spectraList[jcampIdx] = Object.assign({}, spectra, {
294
309
  list: newList,
295
310
  selectedIdx: index,
296
- jcampIdx
311
+ jcampIdx,
312
+ origin: [...newList]
297
313
  });
298
314
  return Object.assign({}, state, {
299
315
  spectraList
@@ -315,12 +331,14 @@ const setRef = (state, action) => {
315
331
  const spectra = spectraList[jcampIdx];
316
332
  const {
317
333
  list,
318
- shift
334
+ shift,
335
+ hasRefPeak,
336
+ history
319
337
  } = spectra;
320
338
  const newShift = Object.assign({}, shift);
321
339
  const refPeaks = list.filter(pairPeak => pairPeak.isRef === true);
322
340
  let offset = 0.0;
323
- if (refPeaks.length > 0) {
341
+ if (hasRefPeak) {
324
342
  const currRefPeaks = refPeaks[0];
325
343
  newShift.ref = currRefPeaks;
326
344
  const {
@@ -330,51 +348,107 @@ const setRef = (state, action) => {
330
348
  e12
331
349
  } = currRefPeaks;
332
350
  offset = e12 - val;
351
+ const newList = spectra.list.map(pairPeak => {
352
+ //eslint-disable-line
353
+ const {
354
+ max,
355
+ min,
356
+ pecker,
357
+ isRef
358
+ } = pairPeak;
359
+ let newMax = null;
360
+ let newMin = null;
361
+ let newPecker = null;
362
+ if (max) {
363
+ newMax = hasRefPeak ? {
364
+ x: max.x - offset,
365
+ y: max.y
366
+ } : {
367
+ x: max.x + parseFloat(offset),
368
+ y: max.y
369
+ };
370
+ }
371
+ if (min) {
372
+ newMin = hasRefPeak ? {
373
+ x: min.x - offset,
374
+ y: min.y
375
+ } : {
376
+ x: min.x + parseFloat(offset),
377
+ y: min.y
378
+ };
379
+ }
380
+ if (pecker) {
381
+ newPecker = hasRefPeak ? {
382
+ x: pecker.x - offset,
383
+ y: pecker.y
384
+ } : {
385
+ x: pecker.x + parseFloat(offset),
386
+ y: pecker.y
387
+ }; //eslint-disable-line
388
+ }
389
+ const newPairPeak = Object.assign({}, pairPeak, {
390
+ max: newMax,
391
+ min: newMin,
392
+ pecker: newPecker
393
+ }); //eslint-disable-line
394
+ newPairPeak.e12 = getE12(newPairPeak);
395
+ newPairPeak.updatedAt = Date.now();
396
+ if (isRef) {
397
+ newShift.ref = newPairPeak;
398
+ newShift.prevValue += offset;
399
+ }
400
+ return newPairPeak;
401
+ });
402
+ history.push(...[newList]);
403
+ spectra.list = newList;
333
404
  } else {
334
405
  newShift.ref = null;
335
- }
336
- const newList = spectra.list.map(pairPeak => {
337
- //eslint-disable-line
338
406
  const {
339
- max,
340
- min,
341
- pecker,
342
- isRef
343
- } = pairPeak;
344
- let newMax = null;
345
- let newMin = null;
346
- let newPecker = null;
347
- if (max) {
348
- newMax = {
349
- x: max.x - offset,
350
- y: max.y
351
- };
352
- }
353
- if (min) {
354
- newMin = {
355
- x: min.x - offset,
356
- y: min.y
357
- };
358
- }
359
- if (pecker) {
360
- newPecker = {
361
- x: pecker.x - offset,
362
- y: pecker.y
363
- };
364
- }
365
- const newPairPeak = Object.assign({}, pairPeak, {
366
- max: newMax,
367
- min: newMin,
368
- pecker: newPecker
369
- }); //eslint-disable-line
370
- newPairPeak.e12 = getE12(newPairPeak);
371
- if (isRef) {
372
- newShift.ref = newPairPeak;
373
- newShift.prevValue += offset;
374
- }
375
- return newPairPeak;
376
- });
377
- spectra.list = newList;
407
+ val
408
+ } = newShift;
409
+ offset = val;
410
+ const newList = spectra.origin.map(pairPeak => {
411
+ //eslint-disable-line
412
+ const {
413
+ max,
414
+ min,
415
+ pecker
416
+ } = pairPeak;
417
+ let newMax = null;
418
+ let newMin = null;
419
+ let newPecker = null;
420
+ if (max) {
421
+ newMax = {
422
+ x: max.x + parseFloat(val),
423
+ y: max.y
424
+ };
425
+ }
426
+ if (min) {
427
+ newMin = {
428
+ x: min.x + parseFloat(val),
429
+ y: min.y
430
+ };
431
+ }
432
+ if (pecker) {
433
+ newPecker = {
434
+ x: pecker.x + parseFloat(val),
435
+ y: pecker.y
436
+ };
437
+ }
438
+ const newPairPeak = Object.assign({}, pairPeak, {
439
+ max: newMax,
440
+ min: newMin,
441
+ pecker: newPecker,
442
+ isRef: false
443
+ }); //eslint-disable-line
444
+ newPairPeak.e12 = getE12(newPairPeak);
445
+ newPairPeak.updatedAt = Date.now();
446
+ return newPairPeak;
447
+ });
448
+ history.push(...[newList]);
449
+ spectra.list = newList;
450
+ newShift.prevValue = parseFloat(offset);
451
+ }
378
452
  spectraList[jcampIdx] = Object.assign({}, spectra, {
379
453
  shift: newShift,
380
454
  jcampIdx
@@ -400,21 +474,30 @@ const selectRefPeaks = (state, action) => {
400
474
  } = payload;
401
475
  const spectra = spectraList[jcampIdx];
402
476
  const {
403
- list
477
+ list,
478
+ shift,
479
+ history
404
480
  } = spectra;
481
+ const newShift = shift;
405
482
  const newList = list;
406
483
  newList.forEach((pairPeak, idx) => {
407
484
  const newPairPeak = pairPeak;
408
485
  newPairPeak.isRef = false;
486
+ newPairPeak.updatedAt = Date.now();
409
487
  if (idx === index) {
410
488
  newPairPeak.isRef = checked;
411
489
  newList[index] = newPairPeak;
412
490
  }
413
491
  });
492
+ const refPeaks = newList.filter(pairPeak => pairPeak.isRef === true);
493
+ const hasRefPeak = refPeaks.length > 0;
494
+ history.push(...[newList]);
414
495
  spectraList[jcampIdx] = Object.assign({}, spectra, {
415
496
  list: newList,
416
497
  selectedIdx: index,
417
- jcampIdx
498
+ jcampIdx,
499
+ hasRefPeak,
500
+ shift: newShift
418
501
  });
419
502
  return Object.assign({}, state, {
420
503
  spectraList