@complat/react-spectra-editor 1.5.4 → 1.6.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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setWorkWithMaxPeak = exports.setCylicVoltaRefFactor = exports.setCylicVoltaRef = exports.selectRefPeaks = exports.selectPairPeak = exports.removeCylicVoltaPecker = exports.removeCylicVoltaPairPeak = exports.removeCylicVoltaMinPeak = exports.removeCylicVoltaMaxPeak = exports.addNewCylicVoltaPairPeak = exports.addCylicVoltaPecker = exports.addCylicVoltaMinPeak = exports.addCylicVoltaMaxPeak = void 0;
6
+ exports.toggleCyclicVoltaDensity = exports.setWorkWithMaxPeak = exports.setCylicVoltaRefFactor = exports.setCylicVoltaRef = exports.setCyclicVoltaAreaValue = exports.setCyclicVoltaAreaUnit = exports.selectRefPeaks = exports.selectPairPeak = exports.removeCylicVoltaPecker = exports.removeCylicVoltaPairPeak = exports.removeCylicVoltaMinPeak = exports.removeCylicVoltaMaxPeak = exports.addNewCylicVoltaPairPeak = exports.addCylicVoltaPecker = exports.addCylicVoltaMinPeak = exports.addCylicVoltaMaxPeak = void 0;
7
7
  var _action_type = require("../constants/action_type");
8
8
  const addNewCylicVoltaPairPeak = payload => ({
9
9
  type: _action_type.CYCLIC_VOLTA_METRY.ADD_PAIR_PEAKS,
@@ -69,4 +69,23 @@ const setCylicVoltaRef = payload => ({
69
69
  type: _action_type.CYCLIC_VOLTA_METRY.SET_REF,
70
70
  payload
71
71
  });
72
- exports.setCylicVoltaRef = setCylicVoltaRef;
72
+ exports.setCylicVoltaRef = setCylicVoltaRef;
73
+ const setCyclicVoltaAreaValue = value => ({
74
+ type: _action_type.CYCLIC_VOLTA_METRY.SET_AREA_VALUE,
75
+ payload: {
76
+ value
77
+ }
78
+ });
79
+ exports.setCyclicVoltaAreaValue = setCyclicVoltaAreaValue;
80
+ const setCyclicVoltaAreaUnit = unit => ({
81
+ type: _action_type.CYCLIC_VOLTA_METRY.SET_AREA_UNIT,
82
+ payload: {
83
+ unit
84
+ }
85
+ });
86
+ exports.setCyclicVoltaAreaUnit = setCyclicVoltaAreaUnit;
87
+ const toggleCyclicVoltaDensity = payload => ({
88
+ type: _action_type.CYCLIC_VOLTA_METRY.TOGGLE_DENSITY,
89
+ payload
90
+ });
91
+ exports.toggleCyclicVoltaDensity = toggleCyclicVoltaDensity;
@@ -24,6 +24,8 @@ var _r07_wavelength_btn = _interopRequireDefault(require("./r07_wavelength_btn")
24
24
  var _pecker = _interopRequireDefault(require("./07_pecker"));
25
25
  var _r08_change_axes = _interopRequireDefault(require("./r08_change_axes"));
26
26
  var _r09_detector = _interopRequireDefault(require("./r09_detector"));
27
+ var _r10_cv_density = _interopRequireDefault(require("./r10_cv_density"));
28
+ var _format = _interopRequireDefault(require("../../helpers/format"));
27
29
  var _jsxRuntime = require("react/jsx-runtime");
28
30
  /* eslint-disable prefer-object-spread, function-paren-newline,
29
31
  react/function-component-definition, react/require-default-props */
@@ -37,34 +39,40 @@ const CmdBar = ({
37
39
  operations,
38
40
  editorOnly,
39
41
  jcampIdx,
40
- hideThreshold
41
- }) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
42
- className: classes.card,
43
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_viewer.default, {
44
- editorOnly: editorOnly
45
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_zoom.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_peak.default, {
46
- jcampIdx: jcampIdx,
47
- feature: feature
48
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_pecker.default, {
49
- jcampIdx: jcampIdx
50
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_integration.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_multiplicity.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_undo_redo.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r04_submit.default, {
51
- operations: operations,
52
- feature: feature,
53
- forecast: forecast,
54
- editorOnly: editorOnly,
55
- hideSwitch: false,
56
- disabled: false
57
- }), hideThreshold ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_r03_threshold.default, {
58
- feature: feature,
59
- hasEdit: hasEdit
60
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r01_layout.default, {
61
- feature: feature,
62
- hasEdit: hasEdit
63
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r07_wavelength_btn.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r08_change_axes.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r09_detector.default, {})]
64
- });
42
+ hideThreshold,
43
+ layoutSt
44
+ }) => {
45
+ const isCvLayout = _format.default.isCyclicVoltaLayout(layoutSt);
46
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
47
+ className: classes.card,
48
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_viewer.default, {
49
+ editorOnly: editorOnly
50
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_zoom.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_peak.default, {
51
+ jcampIdx: jcampIdx,
52
+ feature: feature
53
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_pecker.default, {
54
+ jcampIdx: jcampIdx
55
+ }), isCvLayout ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_integration.default, {}), isCvLayout ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_multiplicity.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_undo_redo.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r04_submit.default, {
56
+ operations: operations,
57
+ feature: feature,
58
+ forecast: forecast,
59
+ editorOnly: editorOnly,
60
+ hideSwitch: false,
61
+ disabled: false
62
+ }), hideThreshold ? null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_r03_threshold.default, {
63
+ feature: feature,
64
+ hasEdit: hasEdit
65
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r01_layout.default, {
66
+ feature: feature,
67
+ hasEdit: hasEdit
68
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r07_wavelength_btn.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r10_cv_density.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r08_change_axes.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_r09_detector.default, {})]
69
+ });
70
+ };
65
71
  const mapStateToProps = (state, _) => (
66
72
  // eslint-disable-line
67
- {});
73
+ {
74
+ layoutSt: state.layout
75
+ });
68
76
  const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({}, dispatch);
69
77
  CmdBar.propTypes = {
70
78
  classes: _propTypes.default.object.isRequired,
@@ -73,6 +81,7 @@ CmdBar.propTypes = {
73
81
  hasEdit: _propTypes.default.bool.isRequired,
74
82
  operations: _propTypes.default.array.isRequired,
75
83
  editorOnly: _propTypes.default.bool.isRequired,
84
+ layoutSt: _propTypes.default.string.isRequired,
76
85
  jcampIdx: _propTypes.default.any,
77
86
  hideThreshold: _propTypes.default.bool
78
87
  };
@@ -16,14 +16,144 @@ var _styles = require("@mui/styles");
16
16
  var _chem = require("../../helpers/chem");
17
17
  var _common = require("./common");
18
18
  var _extractPeaksEdit = require("../../helpers/extractPeaksEdit");
19
+ var _format = _interopRequireDefault(require("../../helpers/format"));
19
20
  var _jsxRuntime = require("react/jsx-runtime");
20
21
  /* eslint-disable prefer-object-spread, function-paren-newline,
21
22
  react/function-component-definition, function-call-argument-newline,
22
23
  react/require-default-props */
23
24
 
24
25
  const styles = () => Object.assign({}, _common.commonStyle);
25
- const onClickCb = (operation, peaksEdit, isAscend, isIntensity, scan, thres, layoutSt, shiftSt, analysis, decimalSt, integrationSt, multiplicitySt, allIntegrationSt, aucValues, waveLengthSt, cyclicvoltaSt, curveSt, axesUnitsSt, detectorSt, dscMetaData) => () => {
26
- operation({
26
+ const getAxesSelection = (axesUnitsSt, curveIdx) => {
27
+ const axes = axesUnitsSt?.axes;
28
+ if (!Array.isArray(axes) || axes.length === 0) return {
29
+ xUnit: '',
30
+ yUnit: ''
31
+ };
32
+ const idx = Number.isFinite(curveIdx) ? curveIdx : 0;
33
+ return axes[idx] || axes[0] || {
34
+ xUnit: '',
35
+ yUnit: ''
36
+ };
37
+ };
38
+ const resolveAxisLabels = (xLabel, yLabel, axesUnitsSt, curveIdx) => {
39
+ const {
40
+ xUnit,
41
+ yUnit
42
+ } = getAxesSelection(axesUnitsSt, curveIdx);
43
+ return {
44
+ xLabel: xUnit === '' ? xLabel : xUnit,
45
+ yLabel: yUnit === '' ? yLabel : yUnit
46
+ };
47
+ };
48
+ const getBaseCurrentUnit = label => /mA/i.test(String(label)) ? 'mA' : 'A';
49
+ const buildCvAxisYLabel = (yLabel, cyclicvoltaSt) => {
50
+ const baseUnit = getBaseCurrentUnit(yLabel);
51
+ const areaUnit = cyclicvoltaSt?.areaUnit || 'cm²';
52
+ if (cyclicvoltaSt?.useCurrentDensity) {
53
+ return `Current density in ${baseUnit}/${areaUnit}`;
54
+ }
55
+ return `Current in ${baseUnit}`;
56
+ };
57
+ const computeCvYScaleFactor = (feature, cyclicvoltaSt) => {
58
+ if (!cyclicvoltaSt?.useCurrentDensity) return 1.0;
59
+ const rawArea = (cyclicvoltaSt.areaValue === '' ? 1.0 : cyclicvoltaSt.areaValue) || 1.0;
60
+ const areaUnit = cyclicvoltaSt.areaUnit || 'cm²';
61
+ const safeArea = rawArea > 0 ? rawArea : 1.0;
62
+ const areaInCm2 = areaUnit === 'mm²' ? safeArea / 100.0 : safeArea;
63
+ let factor = 1.0 / areaInCm2;
64
+ const baseY = feature && feature.yUnit ? String(feature.yUnit) : 'A';
65
+ if (/mA/i.test(baseY)) {
66
+ factor *= 1000.0;
67
+ }
68
+ if (areaUnit === 'mm²') {
69
+ factor /= 100.0;
70
+ }
71
+ return factor;
72
+ };
73
+ const defaultThreshold = {
74
+ isEdit: true,
75
+ value: false,
76
+ upper: false,
77
+ lower: false
78
+ };
79
+ const pickFromList = (list, index, fallback = null) => Array.isArray(list) && list[index] !== undefined ? list[index] : fallback;
80
+ const buildDstPayload = ({
81
+ feature,
82
+ curveIdx,
83
+ editPeakSt,
84
+ thresList,
85
+ shiftSt,
86
+ layoutSt,
87
+ scanSt,
88
+ integrationSt,
89
+ multiplicitySt,
90
+ allIntegrationSt,
91
+ aucValues,
92
+ waveLengthSt,
93
+ cyclicvoltaSt,
94
+ curveSt,
95
+ axesUnitsSt,
96
+ detectorSt,
97
+ dscMetaData,
98
+ isAscend,
99
+ isIntensity,
100
+ analysis,
101
+ decimalSt
102
+ }) => {
103
+ const threshold = thresList?.[curveIdx] || thresList?.[0] || defaultThreshold;
104
+ const editPeakAtIndex = Object.assign({}, editPeakSt, {
105
+ selectedIdx: curveIdx
106
+ });
107
+ const peaksEdit = (0, _extractPeaksEdit.extractPeaksEdit)(feature, editPeakAtIndex, threshold, shiftSt, layoutSt, curveIdx);
108
+ const scan = (0, _chem.Convert2Scan)(feature, scanSt);
109
+ const thres = (0, _chem.Convert2Thres)(feature, threshold);
110
+ const integration = pickFromList(integrationSt?.integrations, curveIdx, integrationSt);
111
+ const multiplicity = pickFromList(multiplicitySt?.multiplicities, curveIdx, multiplicitySt);
112
+ const {
113
+ xLabel,
114
+ yLabel
115
+ } = resolveAxisLabels(feature?.xUnit, feature?.yUnit, axesUnitsSt, curveIdx);
116
+ const axisYLabel = _format.default.isCyclicVoltaLayout(layoutSt) ? buildCvAxisYLabel(yLabel, cyclicvoltaSt) : yLabel;
117
+ const axisDisplay = {
118
+ xLabel,
119
+ yLabel: axisYLabel
120
+ };
121
+ const cvDisplay = _format.default.isCyclicVoltaLayout(layoutSt) ? {
122
+ mode: cyclicvoltaSt?.useCurrentDensity ? 'density' : 'current',
123
+ yScaleFactor: computeCvYScaleFactor(feature, cyclicvoltaSt)
124
+ } : null;
125
+ const cyclicvoltaPayload = {
126
+ ...cyclicvoltaSt,
127
+ axisDisplay,
128
+ cvDisplay
129
+ };
130
+ const perCurveSt = Object.assign({}, curveSt, {
131
+ curveIdx
132
+ });
133
+ return {
134
+ peaks: peaksEdit,
135
+ layout: layoutSt,
136
+ shift: shiftSt,
137
+ scan,
138
+ thres,
139
+ isAscend,
140
+ isIntensity,
141
+ analysis,
142
+ decimal: decimalSt,
143
+ integration,
144
+ multiplicity,
145
+ allIntegration: allIntegrationSt,
146
+ aucValues,
147
+ waveLength: waveLengthSt,
148
+ cyclicvoltaSt: cyclicvoltaPayload,
149
+ curveSt: perCurveSt,
150
+ axesUnitsSt,
151
+ detectorSt,
152
+ dscMetaData
153
+ };
154
+ };
155
+ const onClickCb = (operation, peaksEdit, isAscend, isIntensity, scan, thres, layoutSt, shiftSt, analysis, decimalSt, integrationSt, multiplicitySt, allIntegrationSt, aucValues, waveLengthSt, cyclicvoltaSt, curveSt, axesUnitsSt, detectorSt, dscMetaData, curveList, editPeakSt, thresList, scanSt, feature) => () => {
156
+ const payload = {
27
157
  peaks: peaksEdit,
28
158
  layout: layoutSt,
29
159
  shift: shiftSt,
@@ -43,7 +173,41 @@ const onClickCb = (operation, peaksEdit, isAscend, isIntensity, scan, thres, lay
43
173
  axesUnitsSt,
44
174
  detectorSt,
45
175
  dscMetaData
176
+ };
177
+ const defaultCurves = feature ? [{
178
+ feature
179
+ }] : [];
180
+ const curves = Array.isArray(curveList) && curveList.length > 0 ? curveList : defaultCurves;
181
+ const fallbackIdx = Number.isFinite(curveSt?.curveIdx) ? curveSt.curveIdx : 0;
182
+ const indicesToSend = curves.length > 0 ? curves.map((_, index) => index) : [fallbackIdx];
183
+ payload.dst_list = indicesToSend.map(curveIdx => {
184
+ const curve = curves[curveIdx] || {};
185
+ const curveFeature = curve.feature || feature;
186
+ return buildDstPayload({
187
+ feature: curveFeature,
188
+ curveIdx,
189
+ editPeakSt,
190
+ thresList,
191
+ shiftSt,
192
+ layoutSt,
193
+ scanSt,
194
+ integrationSt,
195
+ multiplicitySt,
196
+ allIntegrationSt,
197
+ aucValues,
198
+ waveLengthSt,
199
+ cyclicvoltaSt,
200
+ curveSt,
201
+ axesUnitsSt,
202
+ detectorSt,
203
+ dscMetaData,
204
+ isAscend,
205
+ isIntensity,
206
+ analysis,
207
+ decimalSt
208
+ });
46
209
  });
210
+ operation(payload);
47
211
  };
48
212
  const BtnSubmit = ({
49
213
  classes,
@@ -53,6 +217,7 @@ const BtnSubmit = ({
53
217
  isIntensity,
54
218
  editPeakSt,
55
219
  thresSt,
220
+ thresList,
56
221
  layoutSt,
57
222
  shiftSt,
58
223
  scanSt,
@@ -64,6 +229,7 @@ const BtnSubmit = ({
64
229
  waveLengthSt,
65
230
  cyclicvoltaSt,
66
231
  curveSt,
232
+ curveList,
67
233
  axesUnitsSt,
68
234
  detectorSt,
69
235
  metaSt
@@ -76,6 +242,25 @@ const BtnSubmit = ({
76
242
  const {
77
243
  dscMetaData
78
244
  } = metaSt;
245
+ const isCvLayout = _format.default.isCyclicVoltaLayout(layoutSt);
246
+ const {
247
+ xLabel,
248
+ yLabel
249
+ } = resolveAxisLabels(feature?.xUnit, feature?.yUnit, axesUnitsSt, curveSt?.curveIdx);
250
+ const axisYLabel = isCvLayout ? buildCvAxisYLabel(yLabel, cyclicvoltaSt) : yLabel;
251
+ const axisDisplay = {
252
+ xLabel,
253
+ yLabel: axisYLabel
254
+ };
255
+ const cvDisplay = isCvLayout ? {
256
+ mode: cyclicvoltaSt?.useCurrentDensity ? 'density' : 'current',
257
+ yScaleFactor: computeCvYScaleFactor(feature, cyclicvoltaSt)
258
+ } : null;
259
+ const cyclicvoltaPayload = {
260
+ ...cyclicvoltaSt,
261
+ axisDisplay,
262
+ cvDisplay
263
+ };
79
264
  if (!operation) return null;
80
265
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
81
266
  title: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -85,7 +270,7 @@ const BtnSubmit = ({
85
270
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_common.MuButton, {
86
271
  className: (0, _classnames.default)('btn-sv-bar-submit'),
87
272
  color: "primary",
88
- onClick: onClickCb(operation.value, peaksEdit, isAscend, isIntensity, scan, thres, layoutSt, shiftSt, forecastSt.predictions, decimalSt, integrationSt, multiplicitySt, allIntegrationSt, aucValues, waveLengthSt, cyclicvoltaSt, curveSt, axesUnitsSt, detectorSt, dscMetaData),
273
+ onClick: onClickCb(operation.value, peaksEdit, isAscend, isIntensity, scan, thres, layoutSt, shiftSt, forecastSt.predictions, decimalSt, integrationSt, multiplicitySt, allIntegrationSt, aucValues, waveLengthSt, cyclicvoltaPayload, curveSt, axesUnitsSt, detectorSt, dscMetaData, curveList, editPeakSt, thresList, scanSt, feature),
89
274
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PlayCircleOutline.default, {
90
275
  className: classes.icon
91
276
  })
@@ -97,6 +282,7 @@ const mapStateToProps = (state, props) => (
97
282
  {
98
283
  editPeakSt: state.editPeak.present,
99
284
  thresSt: state.threshold.list[state.curve.curveIdx],
285
+ thresList: state.threshold.list,
100
286
  layoutSt: state.layout,
101
287
  shiftSt: state.shift,
102
288
  scanSt: state.scan,
@@ -108,6 +294,7 @@ const mapStateToProps = (state, props) => (
108
294
  waveLengthSt: state.wavelength,
109
295
  cyclicvoltaSt: state.cyclicvolta,
110
296
  curveSt: state.curve,
297
+ curveList: state.curve.listCurves,
111
298
  axesUnitsSt: state.axesUnits,
112
299
  detectorSt: state.detector,
113
300
  metaSt: state.meta
@@ -121,6 +308,7 @@ BtnSubmit.propTypes = {
121
308
  operation: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.bool]).isRequired,
122
309
  editPeakSt: _propTypes.default.object.isRequired,
123
310
  thresSt: _propTypes.default.object.isRequired,
311
+ thresList: _propTypes.default.array.isRequired,
124
312
  layoutSt: _propTypes.default.string.isRequired,
125
313
  shiftSt: _propTypes.default.object.isRequired,
126
314
  scanSt: _propTypes.default.object.isRequired,
@@ -132,6 +320,7 @@ BtnSubmit.propTypes = {
132
320
  waveLengthSt: _propTypes.default.object.isRequired,
133
321
  cyclicvoltaSt: _propTypes.default.object.isRequired,
134
322
  curveSt: _propTypes.default.object,
323
+ curveList: _propTypes.default.array.isRequired,
135
324
  axesUnitsSt: _propTypes.default.object.isRequired,
136
325
  detectorSt: _propTypes.default.object.isRequired,
137
326
  metaSt: _propTypes.default.object.isRequired
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
10
  var _reactRedux = require("react-redux");
11
11
  var _classnames = _interopRequireDefault(require("classnames"));
@@ -17,6 +17,7 @@ var _list_layout = require("../../constants/list_layout");
17
17
  var _list_axes = require("../../constants/list_axes");
18
18
  var _axes = require("../../actions/axes");
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
20
21
  /* eslint-disable prefer-object-spread, react/jsx-one-expression-per-line,
21
22
  react/function-component-definition,
22
23
  max-len, no-unused-vars, no-multiple-empty-lines */
@@ -99,18 +100,18 @@ const axisY = (classes, layoutSt, axesUnitsSt, updateYAxisAct, curveSt) => {
99
100
  yUnit: ''
100
101
  };
101
102
  }
102
- const {
103
- yUnit
104
- } = selectedAxes;
103
+ const yUnit = '';
105
104
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.FormControl, {
106
105
  className: (0, _classnames.default)(classes.fieldLayout),
107
106
  variant: "outlined",
107
+ disabled: true,
108
108
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Select, {
109
109
  labelId: "select-y-axis-label",
110
110
  label: "y-Axis",
111
111
  value: yUnit,
112
112
  onChange: onChange,
113
113
  className: (0, _classnames.default)(classes.selectInput, 'input-sv-bar-layout'),
114
+ disabled: true,
114
115
  children: options.map(item => {
115
116
  // eslint-disable-line
116
117
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
@@ -143,11 +144,29 @@ const ChangeAxes = ({
143
144
  axesUnitsSt,
144
145
  updateXAxisAct,
145
146
  updateYAxisAct
146
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
147
- className: classes.groupRight,
148
- "data-testid": "ChangeAxes",
149
- children: showSelect(classes, layoutSt, curveSt, axesUnitsSt, updateXAxisAct, updateYAxisAct)
150
- });
147
+ }) => {
148
+ const {
149
+ curveIdx
150
+ } = curveSt;
151
+ const axes = axesUnitsSt?.axes || [];
152
+ (0, _react.useEffect)(() => {
153
+ if (layoutSt !== _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY) return;
154
+ const selectedAxes = axes[curveIdx] || {
155
+ yUnit: ''
156
+ };
157
+ if (selectedAxes.yUnit !== '') {
158
+ updateYAxisAct({
159
+ value: '',
160
+ curveIndex: curveIdx
161
+ });
162
+ }
163
+ }, [layoutSt, axes, curveIdx, updateYAxisAct]);
164
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
165
+ className: classes.groupRight,
166
+ "data-testid": "ChangeAxes",
167
+ children: showSelect(classes, layoutSt, curveSt, axesUnitsSt, updateXAxisAct, updateYAxisAct)
168
+ });
169
+ };
151
170
  const mapStateToProps = (state, props) => (
152
171
  // eslint-disable-line
153
172
  {
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _reactRedux = require("react-redux");
11
+ var _classnames = _interopRequireDefault(require("classnames"));
12
+ var _redux = require("redux");
13
+ var _material = require("@mui/material");
14
+ var _withStyles = _interopRequireDefault(require("@mui/styles/withStyles"));
15
+ var _list_layout = require("../../constants/list_layout");
16
+ var _common = require("./common");
17
+ var _cyclic_voltammetry = require("../../actions/cyclic_voltammetry");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ /* eslint-disable react/function-component-definition, react/jsx-one-expression-per-line,
20
+ react/jsx-boolean-value */
21
+
22
+ const styles = () => ({
23
+ ..._common.commonStyle,
24
+ fieldArea: {
25
+ width: 100
26
+ },
27
+ fieldUnit: {
28
+ width: 75
29
+ },
30
+ toggleGroup: {
31
+ height: 30,
32
+ marginLeft: 8
33
+ },
34
+ toggleBtn: {
35
+ fontSize: 10,
36
+ padding: '0 6px',
37
+ height: 30,
38
+ minHeight: 30,
39
+ lineHeight: '30px',
40
+ textTransform: 'none'
41
+ }
42
+ });
43
+ const units = ['cm²', 'mm²'];
44
+ const CvDensityControls = ({
45
+ classes,
46
+ layoutSt,
47
+ areaValue,
48
+ areaUnit,
49
+ useCurrentDensity,
50
+ setAreaValueAct,
51
+ setAreaUnitAct,
52
+ toggleDensityAct
53
+ }) => {
54
+ if (layoutSt !== _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY) return /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {});
55
+ const handleAreaChange = e => {
56
+ const raw = e.target.value;
57
+ if (raw === '') {
58
+ setAreaValueAct('');
59
+ return;
60
+ }
61
+ const val = parseFloat(raw);
62
+ if (Number.isNaN(val)) return;
63
+ if (val < 0) return;
64
+ setAreaValueAct(val);
65
+ };
66
+ const handleAreaBlur = e => {
67
+ const raw = e.target.value;
68
+ const val = parseFloat(raw);
69
+ if (raw === '' || Number.isNaN(val) || val <= 0) {
70
+ setAreaValueAct(1.0);
71
+ }
72
+ };
73
+ const handleUnitChange = e => {
74
+ const newUnit = e.target.value;
75
+ const currVal = areaValue;
76
+ if (currVal !== '' && Number.isFinite(Number(currVal))) {
77
+ const num = Number(currVal);
78
+ const from = areaUnit;
79
+ const to = newUnit;
80
+ let converted = num;
81
+ if (from === 'cm²' && to === 'mm²') converted = num * 100.0;
82
+ if (from === 'mm²' && to === 'cm²') converted = num / 100.0;
83
+ setAreaValueAct(converted);
84
+ }
85
+ setAreaUnitAct(newUnit);
86
+ };
87
+ const handleToggle = (_, val) => {
88
+ if (val === null) return;
89
+ const shouldBeDensity = val === 'density';
90
+ if (shouldBeDensity !== useCurrentDensity) {
91
+ toggleDensityAct();
92
+ }
93
+ };
94
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
95
+ className: classes.group,
96
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.FormControl, {
97
+ className: (0, _classnames.default)(classes.fieldArea),
98
+ variant: "outlined",
99
+ disabled: !useCurrentDensity,
100
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputLabel, {
101
+ htmlFor: "cv-area",
102
+ className: (0, _classnames.default)(classes.selectLabel, 'select-sv-bar-label'),
103
+ children: "WE-ECSA"
104
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.OutlinedInput, {
105
+ id: "cv-area",
106
+ label: "WE-ECSA",
107
+ type: "number",
108
+ inputProps: {
109
+ step: '0.0001',
110
+ min: '0'
111
+ },
112
+ value: areaValue,
113
+ onChange: handleAreaChange,
114
+ onBlur: handleAreaBlur,
115
+ className: (0, _classnames.default)(classes.txtInput, 'input-sv-bar-layout'),
116
+ disabled: !useCurrentDensity
117
+ })]
118
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.FormControl, {
119
+ className: (0, _classnames.default)(classes.fieldUnit),
120
+ variant: "outlined",
121
+ disabled: !useCurrentDensity,
122
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputLabel, {
123
+ id: "cv-area-unit",
124
+ className: (0, _classnames.default)(classes.selectLabel, 'select-sv-bar-label'),
125
+ children: "Unit"
126
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Select, {
127
+ value: areaUnit,
128
+ onChange: handleUnitChange,
129
+ labelId: "cv-area-unit",
130
+ label: "Unit",
131
+ className: (0, _classnames.default)(classes.selectInput, 'input-sv-bar-layout'),
132
+ disabled: !useCurrentDensity,
133
+ children: units.map(u => /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
134
+ value: u,
135
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
136
+ className: (0, _classnames.default)(classes.txtOpt, 'option-sv-bar-layout'),
137
+ children: u
138
+ })
139
+ }, u))
140
+ })]
141
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.ToggleButtonGroup, {
142
+ exclusive: true,
143
+ size: "small",
144
+ value: useCurrentDensity ? 'density' : 'current',
145
+ onChange: handleToggle,
146
+ className: (0, _classnames.default)(classes.selectInput, classes.toggleGroup, 'input-sv-bar-layout'),
147
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ToggleButton, {
148
+ value: "current",
149
+ className: (0, _classnames.default)(classes.txtOpt, classes.toggleBtn),
150
+ children: "Current"
151
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ToggleButton, {
152
+ value: "density",
153
+ className: (0, _classnames.default)(classes.txtOpt, classes.toggleBtn),
154
+ children: "Current / Area"
155
+ })]
156
+ })]
157
+ });
158
+ };
159
+ CvDensityControls.propTypes = {
160
+ classes: _propTypes.default.object.isRequired,
161
+ layoutSt: _propTypes.default.string.isRequired,
162
+ areaValue: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
163
+ areaUnit: _propTypes.default.string.isRequired,
164
+ useCurrentDensity: _propTypes.default.bool.isRequired,
165
+ setAreaValueAct: _propTypes.default.func.isRequired,
166
+ setAreaUnitAct: _propTypes.default.func.isRequired,
167
+ toggleDensityAct: _propTypes.default.func.isRequired
168
+ };
169
+ const mapStateToProps = state => ({
170
+ layoutSt: state.layout,
171
+ areaValue: state.cyclicvolta.areaValue,
172
+ areaUnit: state.cyclicvolta.areaUnit,
173
+ useCurrentDensity: state.cyclicvolta.useCurrentDensity
174
+ });
175
+ const mapDispatchToProps = dispatch => (0, _redux.bindActionCreators)({
176
+ setAreaValueAct: _cyclic_voltammetry.setCyclicVoltaAreaValue,
177
+ setAreaUnitAct: _cyclic_voltammetry.setCyclicVoltaAreaUnit,
178
+ toggleDensityAct: _cyclic_voltammetry.toggleCyclicVoltaDensity
179
+ }, dispatch);
180
+ var _default = exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)((0, _withStyles.default)(styles)(CvDensityControls));