@complat/react-spectra-editor 1.5.3 → 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.
@@ -10,6 +10,7 @@ var _reactRedux = require("react-redux");
10
10
  var _redux = require("redux");
11
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
12
12
  var _chem = require("../../helpers/chem");
13
+ var _format = _interopRequireDefault(require("../../helpers/format"));
13
14
  var _manager = require("../../actions/manager");
14
15
  var _ui = require("../../actions/ui");
15
16
  var _list_ui = require("../../constants/list_ui");
@@ -33,6 +34,9 @@ class ViewerMulti extends _react.default.Component {
33
34
  scrollUiWheelAct
34
35
  } = this.props;
35
36
  this.rootKlass = '.d3Line';
37
+ this.containerRef = /*#__PURE__*/_react.default.createRef();
38
+ this.currentSize = null;
39
+ this.resizeObserver = null;
36
40
  this.focus = new _multi_focus.default({
37
41
  W,
38
42
  H,
@@ -42,8 +46,11 @@ class ViewerMulti extends _react.default.Component {
42
46
  scrollUiWheelAct
43
47
  });
44
48
  this.normChange = this.normChange.bind(this);
49
+ this.handleResize = this.handleResize.bind(this);
45
50
  }
46
51
  componentDidMount() {
52
+ this.renderChart(this.props, true);
53
+ this.setupResizeObserver();
47
54
  const {
48
55
  curveSt,
49
56
  seed,
@@ -90,6 +97,11 @@ class ViewerMulti extends _react.default.Component {
90
97
  xxLabel = xUnit === '' ? xLabel : xUnit;
91
98
  yyLabel = yUnit === '' ? yLabel : yUnit;
92
99
  }
100
+ if (cyclicvoltaSt && cyclicvoltaSt.useCurrentDensity) {
101
+ const areaUnit = cyclicvoltaSt.areaUnit || 'cm²';
102
+ const baseUnit = /mA/i.test(String(yyLabel)) ? 'mA' : 'A';
103
+ yyLabel = `Current density in ${baseUnit}/${areaUnit}`;
104
+ }
93
105
  const filterSeed = seed;
94
106
  const filterPeak = peak;
95
107
  (0, _draw.drawMain)(this.rootKlass, W, H);
@@ -156,8 +168,16 @@ class ViewerMulti extends _react.default.Component {
156
168
  xxLabel = xUnit === '' ? xLabel : xUnit;
157
169
  yyLabel = yUnit === '' ? yLabel : yUnit;
158
170
  }
171
+ if (cyclicvoltaSt && cyclicvoltaSt.useCurrentDensity) {
172
+ const areaUnit = cyclicvoltaSt.areaUnit || 'cm²';
173
+ const baseUnit = /mA/i.test(String(yyLabel)) ? 'mA' : 'A';
174
+ yyLabel = `Current density in ${baseUnit}/${areaUnit}`;
175
+ }
159
176
  const filterSeed = seed;
160
177
  const filterPeak = peak;
178
+ if (_format.default.isCyclicVoltaLayout(layoutSt)) {
179
+ this.handleResize();
180
+ }
161
181
  this.focus.update({
162
182
  entities,
163
183
  curveSt,
@@ -179,6 +199,53 @@ class ViewerMulti extends _react.default.Component {
179
199
  }
180
200
  componentWillUnmount() {
181
201
  (0, _draw.drawDestroy)(this.rootKlass);
202
+ this.teardownResizeObserver();
203
+ }
204
+ handleResize() {
205
+ const {
206
+ layoutSt
207
+ } = this.props;
208
+ if (!_format.default.isCyclicVoltaLayout(layoutSt)) return;
209
+ const size = this.getContainerSize();
210
+ if (!size) return;
211
+ if (!this.currentSize || size.width !== this.currentSize.width || size.height !== this.currentSize.height) {
212
+ this.renderChart(this.props, false);
213
+ }
214
+ }
215
+ getContainerSize() {
216
+ const node = this.containerRef.current;
217
+ if (!node) return null;
218
+ const {
219
+ clientWidth,
220
+ clientHeight
221
+ } = node;
222
+ if (!clientWidth || !clientHeight) return null;
223
+ return {
224
+ width: clientWidth,
225
+ height: clientHeight
226
+ };
227
+ }
228
+ getTargetSize(layoutSt) {
229
+ if (_format.default.isCyclicVoltaLayout(layoutSt)) {
230
+ const size = this.getContainerSize();
231
+ if (size) return size;
232
+ }
233
+ return {
234
+ width: W,
235
+ height: H
236
+ };
237
+ }
238
+ setupResizeObserver() {
239
+ if (typeof ResizeObserver === 'undefined') return;
240
+ if (!this.containerRef.current || this.resizeObserver) return;
241
+ this.resizeObserver = new ResizeObserver(this.handleResize);
242
+ this.resizeObserver.observe(this.containerRef.current);
243
+ }
244
+ teardownResizeObserver() {
245
+ if (this.resizeObserver) {
246
+ this.resizeObserver.disconnect();
247
+ this.resizeObserver = null;
248
+ }
182
249
  }
183
250
  normChange(prevProps) {
184
251
  const {
@@ -191,9 +258,101 @@ class ViewerMulti extends _react.default.Component {
191
258
  resetAllAct(feature);
192
259
  }
193
260
  }
261
+ renderChart(props, shouldReset) {
262
+ const {
263
+ curveSt,
264
+ seed,
265
+ peak,
266
+ cLabel,
267
+ xLabel,
268
+ yLabel,
269
+ feature,
270
+ tTrEndPts,
271
+ tSfPeaks,
272
+ editPeakSt,
273
+ layoutSt,
274
+ sweepExtentSt,
275
+ isUiNoBrushSt,
276
+ isHidden,
277
+ resetAllAct,
278
+ cyclicvoltaSt,
279
+ integationSt,
280
+ mtplySt,
281
+ axesUnitsSt,
282
+ entities,
283
+ clickUiTargetAct,
284
+ selectUiSweepAct,
285
+ scrollUiWheelAct
286
+ } = props;
287
+ const size = this.getTargetSize(layoutSt);
288
+ this.currentSize = size;
289
+ (0, _draw.drawDestroy)(this.rootKlass);
290
+ if (shouldReset) {
291
+ resetAllAct(feature);
292
+ }
293
+ let xxLabel = xLabel;
294
+ let yyLabel = yLabel;
295
+ if (axesUnitsSt) {
296
+ const {
297
+ curveIdx
298
+ } = curveSt;
299
+ const {
300
+ axes
301
+ } = axesUnitsSt;
302
+ let selectedAxes = axes[curveIdx];
303
+ if (!selectedAxes) {
304
+ selectedAxes = {
305
+ xUnit: '',
306
+ yUnit: ''
307
+ };
308
+ }
309
+ const {
310
+ xUnit,
311
+ yUnit
312
+ } = selectedAxes;
313
+ xxLabel = xUnit === '' ? xLabel : xUnit;
314
+ yyLabel = yUnit === '' ? yLabel : yUnit;
315
+ }
316
+ const filterSeed = seed;
317
+ const filterPeak = peak;
318
+ this.focus = new _multi_focus.default({
319
+ W: size.width,
320
+ H: size.height,
321
+ entities,
322
+ clickUiTargetAct,
323
+ selectUiSweepAct,
324
+ scrollUiWheelAct
325
+ });
326
+ (0, _draw.drawMain)(this.rootKlass, size.width, size.height);
327
+ this.focus.create({
328
+ curveSt,
329
+ filterSeed,
330
+ filterPeak,
331
+ tTrEndPts,
332
+ tSfPeaks,
333
+ editPeakSt,
334
+ layoutSt,
335
+ sweepExtentSt,
336
+ isUiNoBrushSt,
337
+ cyclicvoltaSt,
338
+ integationSt,
339
+ mtplySt
340
+ });
341
+ (0, _draw.drawLabel)(this.rootKlass, cLabel, xxLabel, yyLabel);
342
+ (0, _draw.drawDisplay)(this.rootKlass, isHidden);
343
+ (0, _draw.drawArrowOnCurve)(this.rootKlass, isHidden);
344
+ }
194
345
  render() {
346
+ const {
347
+ layoutSt
348
+ } = this.props;
349
+ const isCyclicVolta = _format.default.isCyclicVoltaLayout(layoutSt);
195
350
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
196
- className: "d3Line"
351
+ className: "d3Line",
352
+ ref: this.containerRef,
353
+ style: isCyclicVolta ? {
354
+ height: '100%'
355
+ } : undefined
197
356
  });
198
357
  }
199
358
  }
@@ -96,6 +96,7 @@ class MultiFocus {
96
96
  this.onClickPecker = this.onClickPecker.bind(this);
97
97
  this.isFirefox = typeof InstallTrigger !== 'undefined';
98
98
  this.cyclicvoltaSt = null;
99
+ this.yTransformFactor = 1.0;
99
100
  }
100
101
  getShouldUpdate(nextEpSt) {
101
102
  const {
@@ -106,7 +107,8 @@ class MultiFocus {
106
107
  prevTePt,
107
108
  prevDtPk,
108
109
  prevSfPk,
109
- prevData
110
+ prevData,
111
+ prevYFactor
110
112
  } = this.shouldUpdate;
111
113
  const {
112
114
  xt,
@@ -119,6 +121,7 @@ class MultiFocus {
119
121
  const sameDtPk = prevDtPk === this.dataPks.length;
120
122
  const sameSfPk = JSON.stringify(prevSfPk) === JSON.stringify(this.tSfPeaks);
121
123
  const sameData = prevData === this.data.length;
124
+ const sameYFactor = prevYFactor === this.yTransformFactor;
122
125
  this.shouldUpdate = Object.assign({}, this.shouldUpdate, {
123
126
  sameXY,
124
127
  sameEpSt,
@@ -127,7 +130,8 @@ class MultiFocus {
127
130
  sameTePt,
128
131
  sameDtPk,
129
132
  sameSfPk,
130
- sameData // eslint-disable-line
133
+ sameData,
134
+ sameYFactor // eslint-disable-line
131
135
  });
132
136
  }
133
137
  resetShouldUpdate(prevEpSt) {
@@ -142,6 +146,7 @@ class MultiFocus {
142
146
  const prevSfPk = this.tSfPeaks;
143
147
  const prevData = this.data.length;
144
148
  const prevLySt = this.layout;
149
+ const prevYFactor = this.yTransformFactor;
145
150
  this.shouldUpdate = Object.assign({}, this.shouldUpdate, {
146
151
  prevXt,
147
152
  prevYt,
@@ -151,17 +156,41 @@ class MultiFocus {
151
156
  prevTePt,
152
157
  prevDtPk,
153
158
  prevSfPk,
154
- prevData // eslint-disable-line
159
+ prevData,
160
+ prevYFactor // eslint-disable-line
155
161
  });
156
162
  }
157
163
  setTip() {
158
164
  this.tip = (0, _init.InitTip)();
159
165
  this.root.call(this.tip);
160
166
  }
167
+ computeYTransformFactor(layout, cyclicvoltaSt, feature) {
168
+ let factor = 1.0;
169
+ if (layout === _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY && cyclicvoltaSt && cyclicvoltaSt.useCurrentDensity) {
170
+ const rawArea = (cyclicvoltaSt.areaValue === '' ? 1.0 : cyclicvoltaSt.areaValue) || 1.0;
171
+ const areaUnit = cyclicvoltaSt.areaUnit || 'cm²';
172
+ const safeArea = rawArea > 0 ? rawArea : 1.0;
173
+ const areaInCm2 = areaUnit === 'mm²' ? safeArea / 100.0 : safeArea;
174
+ factor = 1.0 / areaInCm2;
175
+ const baseY = feature && feature.yUnit ? String(feature.yUnit) : 'A';
176
+ if (/mA/i.test(baseY)) {
177
+ factor *= 1000.0;
178
+ }
179
+ if (areaUnit === 'mm²') {
180
+ factor /= 100.0;
181
+ }
182
+ }
183
+ return factor;
184
+ }
185
+ transformYValue(y) {
186
+ return y * this.yTransformFactor;
187
+ }
161
188
  setDataParams(filterSeed, peaks, tTrEndPts, tSfPeaks, layout, cyclicvoltaSt, jcampIdx = 0) {
162
189
  this.data = [];
163
190
  this.otherLineData = [];
164
191
  let filterSubLayoutValue = null;
192
+ const currFeature = this.entities && this.entities[0] ? this.entities[0].feature : null;
193
+ this.yTransformFactor = this.computeYTransformFactor(layout, cyclicvoltaSt, currFeature);
165
194
  this.entities.forEach((entry, idx) => {
166
195
  const {
167
196
  topic,
@@ -205,6 +234,11 @@ class MultiFocus {
205
234
  updatePathCall(xt, yt) {
206
235
  this.pathCall = d3.line().x(d => xt(d.x)).y(d => yt(d.y));
207
236
  }
237
+ setYAxisTickFormat() {
238
+ const f = this.yTransformFactor || 1;
239
+ const format = d3.format('.2n');
240
+ this.axisCall.y.tickFormat(v => format(v * f));
241
+ }
208
242
  setConfig(sweepExtentSt) {
209
243
  // Domain Calculate
210
244
  let {
@@ -246,6 +280,9 @@ class MultiFocus {
246
280
  // Axis Call
247
281
  this.axisCall.x.scale(xt);
248
282
  this.axisCall.y.scale(yt);
283
+ if (this.layout === _list_layout.LIST_LAYOUT.CYCLIC_VOLTAMMETRY) {
284
+ this.setYAxisTickFormat();
285
+ }
249
286
  this.currentExtent = {
250
287
  xExtent,
251
288
  yExtent
@@ -299,9 +336,10 @@ class MultiFocus {
299
336
  }
300
337
  drawGrid() {
301
338
  const {
302
- sameXY
339
+ sameXY,
340
+ sameYFactor
303
341
  } = this.shouldUpdate;
304
- if (sameXY) return;
342
+ if (sameXY && sameYFactor) return;
305
343
  this.grid.x.call(this.axisCall.x.tickSize(-this.h, 0, 0)).selectAll('line').attr('stroke', '#ddd').attr('stroke-opacity', 0.6).attr('fill', 'none');
306
344
  this.grid.y.call(this.axisCall.y.tickSize(-this.w, 0, 0)).selectAll('line').attr('stroke', '#ddd').attr('stroke-opacity', 0.6).attr('fill', 'none');
307
345
  }
@@ -473,7 +511,8 @@ class MultiFocus {
473
511
  d3.select(`#bpt${Math.round(1000 * d.x)}`).style('fill', 'blue');
474
512
  const tipParams = {
475
513
  d,
476
- layout: this.layout
514
+ layout: this.layout,
515
+ yFactor: this.yTransformFactor
477
516
  };
478
517
  this.tip.show(tipParams, event.target);
479
518
  }).on('mouseout', (event, d) => {
@@ -481,7 +520,8 @@ class MultiFocus {
481
520
  d3.select(`#bpt${Math.round(1000 * d.x)}`).style('fill', 'red');
482
521
  const tipParams = {
483
522
  d,
484
- layout: this.layout
523
+ layout: this.layout,
524
+ yFactor: this.yTransformFactor
485
525
  };
486
526
  this.tip.hide(tipParams, event.target);
487
527
  }).on('click', (event, d) => this.onClickTarget(event, d));
@@ -534,7 +574,8 @@ class MultiFocus {
534
574
  d3.select(`#bpt${Math.round(1000 * d.x)}`).style('fill', 'blue');
535
575
  const tipParams = {
536
576
  d,
537
- layout: this.layout
577
+ layout: this.layout,
578
+ yFactor: this.yTransformFactor
538
579
  };
539
580
  this.tip.show(tipParams, event.target);
540
581
  }).on('mouseout', (event, d) => {
@@ -542,7 +583,8 @@ class MultiFocus {
542
583
  d3.select(`#bpt${Math.round(1000 * d.x)}`).style('fill', '#228B22');
543
584
  const tipParams = {
544
585
  d,
545
- layout: this.layout
586
+ layout: this.layout,
587
+ yFactor: this.yTransformFactor
546
588
  };
547
589
  this.tip.hide(tipParams, event.target);
548
590
  }).on('click', (event, d) => this.onClickPecker(event, d));
@@ -7,11 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _classnames = _interopRequireDefault(require("classnames"));
10
11
  var _reactRedux = require("react-redux");
11
12
  var _redux = require("redux");
12
13
  var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
13
14
  var _styles = require("@mui/styles");
14
15
  var _index = _interopRequireDefault(require("./panel/index"));
16
+ var _cyclic_voltamery_data = _interopRequireDefault(require("./panel/cyclic_voltamery_data"));
15
17
  var _index2 = _interopRequireDefault(require("./cmd_bar/index"));
16
18
  var _index3 = _interopRequireDefault(require("./d3_multi/index"));
17
19
  var _curve = require("../actions/curve");
@@ -33,6 +35,32 @@ const styles = () => ({
33
35
  },
34
36
  tabLabel: {
35
37
  fontSize: '14px'
38
+ },
39
+ cvEditor: {
40
+ height: 'calc(90vh - 220px)',
41
+ display: 'flex',
42
+ flexDirection: 'column',
43
+ minHeight: 0,
44
+ overflow: 'hidden'
45
+ },
46
+ cvTopRow: {
47
+ flex: '1 1 auto',
48
+ minHeight: 0,
49
+ overflow: 'hidden'
50
+ },
51
+ cvViewerCol: {
52
+ height: '100%',
53
+ minHeight: 0,
54
+ display: 'flex',
55
+ flexDirection: 'column'
56
+ },
57
+ cvViewerWrap: {
58
+ flex: '1 1 auto',
59
+ minHeight: 0
60
+ },
61
+ cvPanelBelow: {
62
+ marginTop: 16,
63
+ width: '100%'
36
64
  }
37
65
  });
38
66
  const seperatingSubLayout = (entities, featureCondition, layoutSt) => {
@@ -86,6 +114,7 @@ class MultiJcampsViewer extends _react.default.Component {
86
114
  integrations
87
115
  } = integrationSt;
88
116
  const currentIntegration = integrations[curveIdx];
117
+ const isCyclicVolta = _format.default.isCyclicVoltaLayout(layoutSt);
89
118
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
90
119
  className: classes.root,
91
120
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.default, {
@@ -94,19 +123,31 @@ class MultiJcampsViewer extends _react.default.Component {
94
123
  editorOnly: true,
95
124
  hideThreshold: !_format.default.isNmrLayout(layoutSt)
96
125
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
97
- className: "react-spectrum-editor",
126
+ className: (0, _classnames.default)('react-spectrum-editor', isCyclicVolta && classes.cvEditor),
98
127
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
99
128
  container: true,
100
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
129
+ className: isCyclicVolta ? classes.cvTopRow : undefined,
130
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Grid.default, {
101
131
  item: true,
102
132
  xs: 9,
103
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.default, {
104
- entities: entities,
105
- topic: topic,
106
- xLabel: feature.xUnit,
107
- yLabel: feature.yUnit,
108
- feature: feature
109
- })
133
+ className: isCyclicVolta ? classes.cvViewerCol : undefined,
134
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
135
+ className: isCyclicVolta ? classes.cvViewerWrap : undefined,
136
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.default, {
137
+ entities: entities,
138
+ topic: topic,
139
+ xLabel: feature.xUnit,
140
+ yLabel: feature.yUnit,
141
+ feature: feature
142
+ })
143
+ }), isCyclicVolta ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
144
+ className: classes.cvPanelBelow,
145
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_cyclic_voltamery_data.default, {
146
+ jcampIdx: curveIdx,
147
+ feature: feature,
148
+ userManualLink: userManualLink ? userManualLink.cv : undefined
149
+ })
150
+ }) : null]
110
151
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
111
152
  item: true,
112
153
  xs: 3,
@@ -122,7 +163,8 @@ class MultiJcampsViewer extends _react.default.Component {
122
163
  integration: currentIntegration,
123
164
  descriptions: descriptions,
124
165
  canChangeDescription: canChangeDescription,
125
- onDescriptionChanged: onDescriptionChanged
166
+ onDescriptionChanged: onDescriptionChanged,
167
+ hideCyclicVolta: isCyclicVolta
126
168
  })
127
169
  })]
128
170
  })