@complat/react-spectra-editor 1.0.1-beta.2 → 1.1.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.
@@ -10,19 +10,19 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  /* eslint-disable prefer-object-spread */
12
12
 
13
- const wheeled = focus => {
13
+ const wheeled = (focus, event) => {
14
14
  const {
15
15
  currentExtent,
16
16
  scrollUiWheelAct
17
17
  } = focus;
18
18
  // WORKAROUND: firefox wheel compatibilty
19
- const wheelEvent = focus.isFirefox ? -d3.event.deltaY : d3.event.wheelDelta; // eslint-disable-line
19
+ const wheelEvent = focus.isFirefox ? -event.deltaY : event.wheelDelta; // eslint-disable-line
20
20
  const direction = wheelEvent > 0;
21
21
  scrollUiWheelAct(Object.assign({}, currentExtent, {
22
22
  direction
23
23
  }));
24
24
  };
25
- const brushed = (focus, isUiAddIntgSt) => {
25
+ const brushed = (focus, isUiAddIntgSt, event) => {
26
26
  const {
27
27
  selectUiSweepAct,
28
28
  data,
@@ -32,7 +32,7 @@ const brushed = (focus, isUiAddIntgSt) => {
32
32
  h,
33
33
  scales
34
34
  } = focus;
35
- const selection = d3.event.selection && d3.event.selection.reverse();
35
+ const selection = event.selection && event.selection.reverse();
36
36
  if (!selection) return;
37
37
  let xes = [w, 0].map(scales.x.invert).sort((a, b) => a - b);
38
38
  let yes = [h, 0].map(scales.y.invert).sort((a, b) => a - b);
@@ -82,15 +82,15 @@ const MountBrush = (focus, isUiAddIntgSt, isUiNoBrushSt) => {
82
82
  } = focus;
83
83
  svg.selectAll('.brush').remove();
84
84
  svg.selectAll('.brushX').remove();
85
- const brushedCb = () => brushed(focus, isUiAddIntgSt);
86
- const wheeledCb = () => wheeled(focus);
85
+ const brushedCb = event => brushed(focus, isUiAddIntgSt, event);
86
+ const wheeledCb = event => wheeled(focus, event);
87
87
  if (isUiNoBrushSt) {
88
88
  const target = isUiAddIntgSt ? brushX : brush;
89
89
  target.handleSize(10).extent([[0, 0], [w, h]]).on('end', brushedCb);
90
90
 
91
91
  // append brush components
92
92
  const klass = isUiAddIntgSt ? 'brushX' : 'brush';
93
- root.append('g').attr('class', klass).on('mousemove', () => (0, _compass.MouseMove)(focus)).call(target);
93
+ root.append('g').attr('class', klass).on('mousemove', event => (0, _compass.MouseMove)(event, focus)).call(target);
94
94
  }
95
95
  svg.on('wheel', wheeledCb);
96
96
  };
@@ -773,7 +773,10 @@ const extrFeaturesCylicVolta = (jcamp, layout, peakUp) => {
773
773
  const lowerThres = _format.default.isXRDLayout(layout) ? 100 : calcLowerThres(s);
774
774
  const cpo = buildPeakFeature(jcamp, layout, peakUp, s, 100, upperThres, lowerThres);
775
775
  const bnd = getBoundary(s);
776
- return Object.assign({}, base, cpo, bnd);
776
+ const detector = _format.default.isSECLayout(layout) && jcamp.info.$DETECTOR ? jcamp.info.$DETECTOR : '';
777
+ return Object.assign({}, base, cpo, bnd, {
778
+ detector
779
+ });
777
780
  }).filter(r => r != null);
778
781
  return features;
779
782
  };
@@ -819,7 +822,7 @@ const extractTemperature = jcamp => {
819
822
  const ExtractJcamp = source => {
820
823
  const jcamp = _jcampconverter.default.convert(source, {
821
824
  xy: true,
822
- keepRecordsRegExp: /(\$CSTHRESHOLD|\$CSSCANAUTOTARGET|\$CSSCANEDITTARGET|\$CSSCANCOUNT|\$CSSOLVENTNAME|\$CSSOLVENTVALUE|\$CSSOLVENTX|\$CSCATEGORY|\$CSITAREA|\$CSITFACTOR|\$OBSERVEDINTEGRALS|\$OBSERVEDMULTIPLETS|\$OBSERVEDMULTIPLETSPEAKS|\.SOLVENTNAME|\.OBSERVEFREQUENCY|\$CSSIMULATIONPEAKS|\$CSUPPERTHRESHOLD|\$CSLOWERTHRESHOLD|\$CSCYCLICVOLTAMMETRYDATA|UNITS|SYMBOL|CSAUTOMETADATA)/ // eslint-disable-line
825
+ keepRecordsRegExp: /(\$CSTHRESHOLD|\$CSSCANAUTOTARGET|\$CSSCANEDITTARGET|\$CSSCANCOUNT|\$CSSOLVENTNAME|\$CSSOLVENTVALUE|\$CSSOLVENTX|\$CSCATEGORY|\$CSITAREA|\$CSITFACTOR|\$OBSERVEDINTEGRALS|\$OBSERVEDMULTIPLETS|\$OBSERVEDMULTIPLETSPEAKS|\.SOLVENTNAME|\.OBSERVEFREQUENCY|\$CSSIMULATIONPEAKS|\$CSUPPERTHRESHOLD|\$CSLOWERTHRESHOLD|\$CSCYCLICVOLTAMMETRYDATA|UNITS|SYMBOL|CSAUTOMETADATA|\$DETECTOR)/ // eslint-disable-line
823
826
  });
824
827
  const layout = readLayout(jcamp);
825
828
  const peakUp = !_format.default.isIrLayout(layout);
@@ -19,11 +19,11 @@ const TfRescale = focus => {
19
19
  };
20
20
  };
21
21
  exports.TfRescale = TfRescale;
22
- const fetchPt = (focus, xt) => {
22
+ const fetchPt = (event, focus, xt) => {
23
23
  // const rawMouseX = focus.isFirefox // WORKAROUND d3.mouse firefox compatibility
24
24
  // ? d3.event.offsetX
25
25
  // : d3.mouse(focus.root.node())[0];
26
- const rawMouseX = d3.mouse(focus.root.node())[0];
26
+ const rawMouseX = d3.pointer(event, focus.root.node())[0];
27
27
  const mouseX = xt.invert(rawMouseX);
28
28
  const bisectDate = d3.bisector(d => +d.x).left;
29
29
  const dt = focus.data;
@@ -32,15 +32,15 @@ const fetchPt = (focus, xt) => {
32
32
  const idx = bisectDate(sortData, +mouseX);
33
33
  return sortData[idx];
34
34
  };
35
- const fetchFreePt = (focus, xt, yt) => {
35
+ const fetchFreePt = (event, focus, xt, yt) => {
36
36
  // const rawMouseX = focus.isFirefox // WORKAROUND d3.mouse firefox compatibility
37
37
  // ? d3.event.offsetX
38
38
  // : d3.mouse(focus.root.node())[0];
39
39
  // const rawMouseY = focus.isFirefox // WORKAROUND d3.mouse firefox compatibility
40
40
  // ? d3.event.offsetY
41
41
  // : d3.mouse(focus.root.node())[1];
42
- const rawMouseX = d3.mouse(focus.root.node())[0];
43
- const rawMouseY = d3.mouse(focus.root.node())[1];
42
+ const rawMouseX = d3.pointer(event, focus.root.node())[0];
43
+ const rawMouseY = d3.pointer(event, focus.root.node())[1];
44
44
  const mouseX = xt.invert(rawMouseX);
45
45
  const mouseY = yt.invert(rawMouseY);
46
46
  const distance2 = (x1, x2, y1, y2) => {
@@ -60,7 +60,7 @@ const fetchFreePt = (focus, xt, yt) => {
60
60
  });
61
61
  return selectPoint;
62
62
  };
63
- const MouseMove = focus => {
63
+ const MouseMove = (event, focus) => {
64
64
  const {
65
65
  xt,
66
66
  yt
@@ -71,7 +71,7 @@ const MouseMove = focus => {
71
71
  wavelength
72
72
  } = focus;
73
73
  if (_format.default.isCyclicVoltaLayout(layout)) {
74
- const pt = fetchFreePt(focus, xt, yt);
74
+ const pt = fetchFreePt(event, focus, xt, yt);
75
75
  if (pt) {
76
76
  const tx = xt(pt.x);
77
77
  const ty = yt(pt.y);
@@ -85,7 +85,7 @@ const MouseMove = focus => {
85
85
  }
86
86
  }
87
87
  } else {
88
- const pt = fetchPt(focus, xt);
88
+ const pt = fetchPt(event, focus, xt);
89
89
  if (pt) {
90
90
  const tx = xt(pt.x);
91
91
  const ty = yt(pt.y);
@@ -99,6 +99,8 @@ const MouseMove = focus => {
99
99
  dValue = (0, _chem.Convert2DValue)(pt.x).toExponential(2);
100
100
  }
101
101
  focus.root.select('.cursor-txt-hz').attr('transform', `translate(${tx},${ty - 30})`).text(`2Theta: ${pt.x.toExponential(2)}, d-value: ${dValue}`);
102
+ } else if (_format.default.isTGALayout(layout)) {
103
+ focus.root.select('.cursor-txt').attr('transform', `translate(${tx},${10})`).text(`X: ${pt.x.toFixed(3)}, Y: ${pt.y.toFixed(3)}`);
102
104
  } else {
103
105
  focus.root.select('.cursor-txt').attr('transform', `translate(${tx},${10})`).text(pt.x.toFixed(3));
104
106
  if (freq) {
@@ -111,21 +113,21 @@ const MouseMove = focus => {
111
113
  }
112
114
  };
113
115
  exports.MouseMove = MouseMove;
114
- const ClickCompass = focus => {
115
- d3.event.stopPropagation();
116
- d3.event.preventDefault();
116
+ const ClickCompass = (event, focus) => {
117
+ event.stopPropagation();
118
+ event.preventDefault();
117
119
  const {
118
120
  xt,
119
121
  yt
120
122
  } = TfRescale(focus);
121
- let pt = fetchPt(focus, xt);
123
+ let pt = fetchPt(event, focus, xt);
122
124
  const {
123
125
  layout,
124
126
  cyclicvoltaSt,
125
127
  jcampIdx
126
128
  } = focus;
127
129
  if (_format.default.isCyclicVoltaLayout(layout)) {
128
- pt = fetchFreePt(focus, xt, yt);
130
+ pt = fetchFreePt(event, focus, xt, yt);
129
131
  const onPeak = false;
130
132
  if (cyclicvoltaSt) {
131
133
  const {
@@ -155,6 +157,6 @@ const MountCompass = focus => {
155
157
  compass.append('circle').attr('r', 4).attr('fill', 'none').attr('stroke', '#777').attr('stroke-width', 2);
156
158
  cursor.append('text').attr('class', 'cursor-txt').attr('font-family', 'Helvetica').style('font-size', '12px').style('text-anchor', 'middle');
157
159
  cursor.append('text').attr('class', 'cursor-txt-hz').attr('font-family', 'Helvetica').style('font-size', '12px').style('text-anchor', 'middle').style('fill', '#D68910');
158
- overlay.on('mousemove', () => MouseMove(focus)).on('click', () => ClickCompass(focus));
160
+ overlay.on('mousemove', event => MouseMove(event, focus)).on('click', event => ClickCompass(event, focus));
159
161
  };
160
162
  exports.MountCompass = MountCompass;
@@ -45,13 +45,13 @@ const MountRef = target => {
45
45
  };
46
46
  exports.MountRef = MountRef;
47
47
  const MountPath = (target, color) => {
48
- const path = target.root.append('g').attr('class', 'line-clip').attr('clip-path', 'url(#clip)').append('path').attr('class', 'line').style('fill', 'none').style('stroke', color).style('stroke-width', 1).on('click', () => (0, _compass.ClickCompass)(target));
48
+ const path = target.root.append('g').attr('class', 'line-clip').attr('clip-path', 'url(#clip)').append('path').attr('class', 'line').style('fill', 'none').style('stroke', color).style('stroke-width', 1).on('click', event => (0, _compass.ClickCompass)(event, target));
49
49
  return path;
50
50
  };
51
51
  exports.MountPath = MountPath;
52
52
  const MountComparePath = function (target, color, id) {
53
53
  let alpha = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
54
- const path = target.root.append('g').attr('class', 'line-clip-compare').attr('id', id).attr('clip-path', 'url(#clip)').append('path').attr('class', 'line').style('fill', 'none').style('stroke', color).style('stroke-opacity', alpha).style('stroke-width', 1).style('stroke-dasharray', '30, 3').on('click', () => (0, _compass.ClickCompass)(target));
54
+ const path = target.root.append('g').attr('class', 'line-clip-compare').attr('id', id).attr('clip-path', 'url(#clip)').append('path').attr('class', 'line').style('fill', 'none').style('stroke', color).style('stroke-opacity', alpha).style('stroke-width', 1).style('stroke-dasharray', '30, 3').on('click', event => (0, _compass.ClickCompass)(event, target));
55
55
  return path;
56
56
  };
57
57
  exports.MountComparePath = MountComparePath;
@@ -12,10 +12,10 @@ const resetZoom = main => {
12
12
  main.svg.selectAll('.brush').call(main.brush.move, null);
13
13
  };
14
14
  const MountZoom = (main, zoomed) => {
15
- const zoomedCb = () => zoomed(main);
16
- const resetZoomCb = () => {
17
- d3.event.stopPropagation();
18
- d3.event.preventDefault();
15
+ const zoomedCb = event => zoomed(event, main);
16
+ const resetZoomCb = event => {
17
+ event.stopPropagation();
18
+ event.preventDefault();
19
19
  resetZoom(main);
20
20
  };
21
21
  main.zoom.on('zoom', zoomedCb);
package/dist/index.js CHANGED
@@ -604,30 +604,35 @@ class DemoWriteIr extends _react.default.Component {
604
604
  },
605
605
  onClick: this.onClick('raman')
606
606
  }, "RAMAN"), /*#__PURE__*/_react.default.createElement(_material.Button, {
607
+ id: "btn-uv-vis",
607
608
  variant: "contained",
608
609
  style: {
609
610
  margin: '0 10px 0 10px'
610
611
  },
611
612
  onClick: this.onClick('uv/vis')
612
613
  }, "UV/VIS"), /*#__PURE__*/_react.default.createElement(_material.Button, {
614
+ id: "btn-hplc",
613
615
  variant: "contained",
614
616
  style: {
615
617
  margin: '0 10px 0 10px'
616
618
  },
617
619
  onClick: this.onClick('hplc uv/vis')
618
620
  }, "HPLC UV/VIS"), /*#__PURE__*/_react.default.createElement(_material.Button, {
621
+ id: "btn-tga",
619
622
  variant: "contained",
620
623
  style: {
621
624
  margin: '0 10px 0 10px'
622
625
  },
623
626
  onClick: this.onClick('tga')
624
627
  }, "TGA"), /*#__PURE__*/_react.default.createElement(_material.Button, {
628
+ id: "btn-xrd",
625
629
  variant: "contained",
626
630
  style: {
627
631
  margin: '0 10px 0 10px'
628
632
  },
629
633
  onClick: this.onClick('xrd')
630
634
  }, "XRD"), /*#__PURE__*/_react.default.createElement(_material.Button, {
635
+ id: "btn-cv",
631
636
  variant: "contained",
632
637
  style: {
633
638
  margin: '0 10px 0 10px'
@@ -640,12 +645,14 @@ class DemoWriteIr extends _react.default.Component {
640
645
  },
641
646
  onClick: this.onClick('cds')
642
647
  }, "CDS"), /*#__PURE__*/_react.default.createElement(_material.Button, {
648
+ id: "btn-sec",
643
649
  variant: "contained",
644
650
  style: {
645
651
  margin: '0 10px 0 10px'
646
652
  },
647
653
  onClick: this.onClick('sec')
648
654
  }, "SEC"), /*#__PURE__*/_react.default.createElement(_material.Button, {
655
+ id: "btn-sod",
649
656
  variant: "contained",
650
657
  style: {
651
658
  margin: '0 10px 0 10px'
@@ -60,9 +60,11 @@ class LayerInit extends _react.default.Component {
60
60
  resetInitCommonAct,
61
61
  resetInitMsAct,
62
62
  resetInitNmrAct,
63
- resetInitCommonWithIntergationAct
63
+ resetInitCommonWithIntergationAct,
64
+ resetDetectorAct
64
65
  } = this.props;
65
66
  resetInitCommonAct();
67
+ resetDetectorAct();
66
68
  const {
67
69
  layout,
68
70
  features
@@ -185,6 +187,7 @@ const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({
185
187
  resetInitNmrAct: _manager.resetInitNmr,
186
188
  resetInitMsAct: _manager.resetInitMs,
187
189
  resetInitCommonWithIntergationAct: _manager.resetInitCommonWithIntergation,
190
+ resetDetectorAct: _manager.resetDetector,
188
191
  updateOperationAct: _submit.updateOperation,
189
192
  updateMetaPeaksAct: _meta.updateMetaPeaks,
190
193
  addOthersAct: _jcamp.addOthers,
@@ -217,7 +220,9 @@ LayerInit.propTypes = {
217
220
  onDescriptionChanged: _propTypes.default.func,
218
221
  // eslint-disable-line
219
222
  setAllCurvesAct: _propTypes.default.func.isRequired,
220
- userManualLink: _propTypes.default.object // eslint-disable-line
223
+ userManualLink: _propTypes.default.object,
224
+ // eslint-disable-line
225
+ resetDetectorAct: _propTypes.default.func.isRequired
221
226
  };
222
227
  var _default = exports.default = (0, _reactRedux.connect)(
223
228
  // eslint-disable-line
@@ -25,6 +25,7 @@ var _reducer_wavelength = _interopRequireDefault(require("./reducer_wavelength")
25
25
  var _reducer_voltammetry = _interopRequireDefault(require("./reducer_voltammetry"));
26
26
  var _reducer_curve = _interopRequireDefault(require("./reducer_curve"));
27
27
  var _reducer_axes = _interopRequireDefault(require("./reducer_axes"));
28
+ var _reducer_detector = _interopRequireDefault(require("./reducer_detector"));
28
29
  const rootReducer = (0, _redux.combineReducers)({
29
30
  threshold: _reducer_threshold.default,
30
31
  editPeak: _reducer_edit_peak.default,
@@ -44,6 +45,7 @@ const rootReducer = (0, _redux.combineReducers)({
44
45
  wavelength: _reducer_wavelength.default,
45
46
  cyclicvolta: _reducer_voltammetry.default,
46
47
  curve: _reducer_curve.default,
47
- axesUnits: _reducer_axes.default
48
+ axesUnits: _reducer_axes.default,
49
+ detector: _reducer_detector.default
48
50
  });
49
51
  var _default = exports.default = rootReducer;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _action_type = require("../constants/action_type");
8
+ /* eslint-disable no-case-declarations */
9
+ /* eslint-disable default-param-last */
10
+
11
+ const initialState = {
12
+ curves: [{
13
+ curveIdx: 0,
14
+ selectedDetector: ''
15
+ }]
16
+ };
17
+ const findCurveIndex = (curves, targetCurveIdx) => curves.findIndex(curve => curve.curveIdx === targetCurveIdx);
18
+ const updateOrAppendCurve = (curves, targetCurveIdx, newCurve) => {
19
+ const existingCurveIndex = findCurveIndex(curves, targetCurveIdx);
20
+ if (existingCurveIndex !== -1) {
21
+ return curves.map((curve, index) => index === existingCurveIndex ? {
22
+ ...curve,
23
+ ...newCurve
24
+ } : curve);
25
+ }
26
+ return [...curves, newCurve];
27
+ };
28
+ const detectorReducer = function () {
29
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
30
+ let action = arguments.length > 1 ? arguments[1] : undefined;
31
+ switch (action.type) {
32
+ case _action_type.SEC.UPDATE_DETECTOR:
33
+ const {
34
+ curveIdx,
35
+ selectedDetector
36
+ } = action.payload;
37
+ // eslint-disable-next-line max-len
38
+ const updatedCurves = updateOrAppendCurve(state.curves, curveIdx, {
39
+ curveIdx,
40
+ selectedDetector
41
+ });
42
+ return {
43
+ ...state,
44
+ curves: updatedCurves
45
+ };
46
+ case _action_type.MANAGER.RESET_DETECTOR:
47
+ return initialState;
48
+ default:
49
+ return state;
50
+ }
51
+ };
52
+ var _default = exports.default = detectorReducer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@complat/react-spectra-editor",
3
- "version": "1.0.1-beta.2",
3
+ "version": "1.1.0",
4
4
  "description": "An editor to View and Edit Chemical Spectra data (NMR, IR and MS, CV, UIVIS, XRD).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,9 +23,7 @@
23
23
  "babel-plugin-transform-object-rest-spread": "^6.26.0",
24
24
  "browserslist": "^4.21.5",
25
25
  "classnames": "^2.3.2",
26
- "d3": "^5.16.0",
27
- "d3-brush": "3.0.0",
28
- "d3-selection": "^2.0.0",
26
+ "d3": "^7.8.5",
29
27
  "d3-tip": "^0.9.1",
30
28
  "jcampconverter": "4.1.0",
31
29
  "ml-savitzky-golay-generalized": "1.1.1",
@@ -48,7 +46,8 @@
48
46
  "test:coverage": "CI=true react-scripts test --env=jsdom --verbose --testPathIgnorePatterns=./src/__tests__/fixtures/ --coverage",
49
47
  "eject": "react-scripts eject",
50
48
  "storybook": "start-storybook -p 3001 -c .storybook",
51
- "buildbook": "build-storybook -c .storybook -o .out"
49
+ "buildbook": "build-storybook -c .storybook -o .out",
50
+ "e2e": "cypress open"
52
51
  },
53
52
  "peerDependencies": {
54
53
  "react": "^17.0.2",
@@ -65,6 +64,7 @@
65
64
  "@types/enzyme": "^3.10.13",
66
65
  "@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
67
66
  "babel-loader": "8.2.5",
67
+ "cypress": "^13.6.2",
68
68
  "enzyme": "^3.11.0",
69
69
  "enzyme-to-json": "^3.6.2",
70
70
  "eslint-config-airbnb": "^19.0.4",
@@ -90,5 +90,10 @@
90
90
  ],
91
91
  "publishConfig": {
92
92
  "access": "public"
93
+ },
94
+ "jest": {
95
+ "transformIgnorePatterns": [
96
+ "/node_modules/(?!d3|d3-array|internmap|delaunator|robust-predicates)"
97
+ ]
93
98
  }
94
99
  }