@deephaven/chart 0.5.0 → 0.5.2-lessredux.14

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.
package/dist/Chart.js CHANGED
@@ -1,86 +1,59 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
-
5
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
8
-
9
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
-
11
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
-
13
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
-
15
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
-
17
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
18
-
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
-
21
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
22
-
23
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
24
2
 
25
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
26
4
 
27
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
28
-
29
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
30
-
31
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
32
-
33
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
34
-
35
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
36
-
37
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
38
-
39
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
40
-
41
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
42
-
43
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
44
-
45
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
46
-
47
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
48
6
 
49
7
  import React, { Component } from 'react';
50
8
  import PropTypes from 'prop-types';
51
9
  import deepEqual from 'deep-equal';
52
- import { connect } from 'react-redux';
53
10
  import memoize from 'memoize-one';
54
11
  import { vsLoading, dhGraphLineDown, dhWarningFilled } from '@deephaven/icons';
55
- import { Formatter, FormatterUtils } from '@deephaven/iris-grid';
12
+ import { Formatter, FormatterUtils, DateUtils } from '@deephaven/iris-grid';
56
13
  import Log from '@deephaven/log';
57
- import { getSettings } from '@deephaven/redux';
58
- import Plotly from './plotly/Plotly';
59
- import Plot from './plotly/Plot';
60
- import ChartModel from './ChartModel';
61
- import ChartUtils from './ChartUtils';
14
+ import Plotly from "./plotly/Plotly.js";
15
+ import Plot from "./plotly/Plot.js";
16
+ import ChartModel from "./ChartModel.js";
17
+ import ChartUtils from "./ChartUtils.js";
62
18
  import ChartConstants from "./Chart.module.css";
63
19
  import "./Chart.css";
64
20
  var log = Log.module('Chart');
65
- export var Chart = /*#__PURE__*/function (_Component) {
66
- _inherits(Chart, _Component);
67
-
68
- var _super = _createSuper(Chart);
21
+ export class Chart extends Component {
22
+ /**
23
+ * Convert a font awesome icon definition to a plotly icon definition
24
+ * @param {FontAwesome.IconDefinition} faIcon The icon to convert
25
+ */
26
+ static convertIcon(faIcon) {
27
+ var [width,,,, path] = faIcon.icon; // By default the icons are flipped upside down, so we need to add our own transform
28
+ // https://github.com/plotly/plotly.js/issues/1335
29
+
30
+ return {
31
+ width,
32
+ path,
33
+ ascent: width,
34
+ descent: 0,
35
+ transform: "matrix(1, 0, 0, 1, 0, 0)"
36
+ };
37
+ }
69
38
 
70
- function Chart(props) {
71
- var _this;
39
+ static downsampleButtonTitle(isDownsampleInProgress, isDownsamplingDisabled) {
40
+ if (isDownsampleInProgress) {
41
+ return ChartConstants['title-downsampling-in-progress'];
42
+ }
72
43
 
73
- _classCallCheck(this, Chart);
44
+ return isDownsamplingDisabled ? ChartConstants['title-downsampling-disabled'] : ChartConstants['title-downsampling-enabled'];
45
+ }
74
46
 
75
- _this = _super.call(this, props);
47
+ constructor(props) {
48
+ super(props);
76
49
 
77
- _defineProperty(_assertThisInitialized(_this), "getCachedConfig", memoize(function (downsamplingError, isDownsampleFinished, isDownsampleInProgress, isDownsamplingDisabled) {
50
+ _defineProperty(this, "getCachedConfig", memoize((downsamplingError, isDownsampleFinished, isDownsampleInProgress, isDownsamplingDisabled) => {
78
51
  var customButtons = [];
79
52
 
80
53
  if (downsamplingError) {
81
54
  customButtons.push({
82
55
  name: "".concat(ChartConstants['title-downsampling-failed'], ": ").concat(downsamplingError),
83
- click: function click() {},
56
+ click: () => {},
84
57
  icon: Chart.convertIcon(dhWarningFilled)
85
58
  });
86
59
  }
@@ -89,9 +62,9 @@ export var Chart = /*#__PURE__*/function (_Component) {
89
62
  var name = Chart.downsampleButtonTitle(isDownsampleInProgress, isDownsamplingDisabled);
90
63
  var icon = isDownsampleInProgress ? vsLoading : dhGraphLineDown;
91
64
  customButtons.push({
92
- name: name,
65
+ name,
93
66
  icon: Chart.convertIcon(icon),
94
- click: _this.handleDownsampleClick
67
+ click: this.handleDownsampleClick
95
68
  });
96
69
  }
97
70
 
@@ -105,21 +78,21 @@ export var Chart = /*#__PURE__*/function (_Component) {
105
78
  };
106
79
  }));
107
80
 
108
- _this.handleAfterPlot = _this.handleAfterPlot.bind(_assertThisInitialized(_this));
109
- _this.handleDownsampleClick = _this.handleDownsampleClick.bind(_assertThisInitialized(_this));
110
- _this.handleModelEvent = _this.handleModelEvent.bind(_assertThisInitialized(_this));
111
- _this.handlePlotUpdate = _this.handlePlotUpdate.bind(_assertThisInitialized(_this));
112
- _this.handleRelayout = _this.handleRelayout.bind(_assertThisInitialized(_this));
113
- _this.handleRestyle = _this.handleRestyle.bind(_assertThisInitialized(_this));
114
- _this.plot = /*#__PURE__*/React.createRef();
115
- _this.plotWrapper = /*#__PURE__*/React.createRef();
116
- _this.columnFormats = [];
117
- _this.dateTimeFormatterOptions = {};
118
- _this.rect = null;
119
- _this.ranges = null;
120
- _this.isSubscribed = false;
121
- _this.isLoadedFired = false;
122
- _this.state = {
81
+ this.handleAfterPlot = this.handleAfterPlot.bind(this);
82
+ this.handleDownsampleClick = this.handleDownsampleClick.bind(this);
83
+ this.handleModelEvent = this.handleModelEvent.bind(this);
84
+ this.handlePlotUpdate = this.handlePlotUpdate.bind(this);
85
+ this.handleRelayout = this.handleRelayout.bind(this);
86
+ this.handleRestyle = this.handleRestyle.bind(this);
87
+ this.plot = /*#__PURE__*/React.createRef();
88
+ this.plotWrapper = /*#__PURE__*/React.createRef();
89
+ this.columnFormats = [];
90
+ this.dateTimeFormatterOptions = {};
91
+ this.rect = null;
92
+ this.ranges = null;
93
+ this.isSubscribed = false;
94
+ this.isLoadedFired = false;
95
+ this.state = {
123
96
  data: null,
124
97
  downsamplingError: null,
125
98
  isDownsampleFinished: false,
@@ -130,407 +103,401 @@ export var Chart = /*#__PURE__*/function (_Component) {
130
103
  },
131
104
  revision: 0
132
105
  };
133
- return _this;
134
106
  }
135
107
 
136
- _createClass(Chart, [{
137
- key: "componentDidMount",
138
- value: function componentDidMount() {
139
- // Need to make sure the model dimensions are up to date before initializing the data
140
- this.updateDimensions();
141
- this.updateModelDimensions();
142
- this.initData();
143
- this.initFormatter();
144
- var isActive = this.props.isActive;
108
+ componentDidMount() {
109
+ // Need to make sure the model dimensions are up to date before initializing the data
110
+ this.updateDimensions();
111
+ this.updateModelDimensions();
112
+ this.initData();
113
+ this.initFormatter();
114
+ var {
115
+ isActive
116
+ } = this.props;
117
+
118
+ if (isActive) {
119
+ this.subscribe();
120
+ }
121
+ }
122
+
123
+ componentDidUpdate(prevProps) {
124
+ var {
125
+ isActive,
126
+ settings
127
+ } = this.props;
128
+ this.updateFormatterSettings(settings);
145
129
 
130
+ if (isActive !== prevProps.isActive) {
146
131
  if (isActive) {
147
132
  this.subscribe();
133
+ } else {
134
+ this.unsubscribe();
148
135
  }
149
136
  }
150
- }, {
151
- key: "componentDidUpdate",
152
- value: function componentDidUpdate(prevProps) {
153
- var _this$props = this.props,
154
- isActive = _this$props.isActive,
155
- settings = _this$props.settings;
156
- this.updateFormatterSettings(settings);
157
-
158
- if (isActive !== prevProps.isActive) {
159
- if (isActive) {
160
- this.subscribe();
161
- } else {
162
- this.unsubscribe();
163
- }
164
- }
165
- }
166
- }, {
167
- key: "componentWillUnmount",
168
- value: function componentWillUnmount() {
169
- this.unsubscribe();
170
- }
171
- }, {
172
- key: "getPlotRect",
173
- value: function getPlotRect() {
174
- var _this$plotWrapper$cur, _this$plotWrapper$cur2;
137
+ }
175
138
 
176
- return (_this$plotWrapper$cur = (_this$plotWrapper$cur2 = this.plotWrapper.current) === null || _this$plotWrapper$cur2 === void 0 ? void 0 : _this$plotWrapper$cur2.getBoundingClientRect()) !== null && _this$plotWrapper$cur !== void 0 ? _this$plotWrapper$cur : null;
177
- }
178
- }, {
179
- key: "initData",
180
- value: function initData() {
181
- var model = this.props.model;
182
- var layout = this.state.layout;
183
- this.setState({
184
- data: model.getData(),
185
- layout: _objectSpread(_objectSpread({}, layout), model.getLayout())
186
- });
187
- }
188
- }, {
189
- key: "subscribe",
190
- value: function subscribe() {
191
- if (this.isSubscribed) {
192
- return;
193
- }
139
+ componentWillUnmount() {
140
+ this.unsubscribe();
141
+ }
194
142
 
195
- var model = this.props.model;
143
+ getPlotRect() {
144
+ var _this$plotWrapper$cur, _this$plotWrapper$cur2;
196
145
 
197
- if (!this.rect || this.rect.width === 0 || this.rect.height === 0) {
198
- log.debug2('Delaying subscription until model dimensions are set');
199
- return;
200
- }
146
+ return (_this$plotWrapper$cur = (_this$plotWrapper$cur2 = this.plotWrapper.current) === null || _this$plotWrapper$cur2 === void 0 ? void 0 : _this$plotWrapper$cur2.getBoundingClientRect()) !== null && _this$plotWrapper$cur !== void 0 ? _this$plotWrapper$cur : null;
147
+ }
201
148
 
202
- model.subscribe(this.handleModelEvent);
203
- this.isSubscribed = true;
204
- }
205
- }, {
206
- key: "unsubscribe",
207
- value: function unsubscribe() {
208
- if (!this.isSubscribed) {
209
- return;
210
- }
149
+ initData() {
150
+ var {
151
+ model
152
+ } = this.props;
153
+ var {
154
+ layout
155
+ } = this.state;
156
+ this.setState({
157
+ data: model.getData(),
158
+ layout: _objectSpread(_objectSpread({}, layout), model.getLayout())
159
+ });
160
+ }
211
161
 
212
- var model = this.props.model;
213
- model.unsubscribe(this.handleModelEvent);
214
- this.isSubscribed = false;
215
- }
216
- }, {
217
- key: "handleAfterPlot",
218
- value: function handleAfterPlot() {
219
- if (this.plot.current) {// TODO: Translate whatever Don was doing in plotting.js in the afterplot here so that area graphs show up properly
220
- }
162
+ subscribe() {
163
+ if (this.isSubscribed) {
164
+ return;
221
165
  }
222
- }, {
223
- key: "handleDownsampleClick",
224
- value: function handleDownsampleClick() {
225
- var _this2 = this;
226
-
227
- this.setState(function (_ref) {
228
- var isDownsamplingDisabled = _ref.isDownsamplingDisabled;
229
- return {
230
- downsamplingError: null,
231
- isDownsampleInProgress: false,
232
- isDownsampleFinished: false,
233
- isDownsamplingDisabled: !isDownsamplingDisabled
234
- };
235
- }, function () {
236
- var model = _this2.props.model;
237
- var isDownsamplingDisabled = _this2.state.isDownsamplingDisabled;
238
- model.setDownsamplingDisabled(isDownsamplingDisabled);
239
- });
166
+
167
+ var {
168
+ model
169
+ } = this.props;
170
+
171
+ if (!this.rect || this.rect.width === 0 || this.rect.height === 0) {
172
+ log.debug2('Delaying subscription until model dimensions are set');
173
+ return;
240
174
  }
241
- }, {
242
- key: "handleModelEvent",
243
- value: function handleModelEvent(event) {
244
- var type = event.type,
245
- detail = event.detail;
246
- log.debug2('Received data update', type, detail);
247
-
248
- switch (type) {
249
- case ChartModel.EVENT_UPDATED:
250
- {
251
- this.currentSeries += 1;
252
- this.setState(function (state) {
253
- var layout = state.layout,
254
- revision = state.revision;
255
- layout.datarevision += 1;
256
- return {
257
- data: detail,
258
- layout: layout,
259
- revision: revision + 1
260
- };
261
- });
262
- var onUpdate = this.props.onUpdate;
263
- onUpdate({
264
- isLoading: !this.isLoadedFired
265
- });
266
- break;
267
- }
268
-
269
- case ChartModel.EVENT_LOADFINISHED:
270
- {
271
- var _onUpdate = this.props.onUpdate;
272
- this.isLoadedFired = true;
273
-
274
- _onUpdate({
275
- isLoading: false
276
- });
277
-
278
- break;
279
- }
280
-
281
- case ChartModel.EVENT_DISCONNECT:
282
- {
283
- var onDisconnect = this.props.onDisconnect;
284
- onDisconnect();
285
- break;
286
- }
287
-
288
- case ChartModel.EVENT_RECONNECT:
289
- {
290
- var onReconnect = this.props.onReconnect;
291
- onReconnect();
292
- break;
293
- }
294
-
295
- case ChartModel.EVENT_DOWNSAMPLESTARTED:
296
- {
297
- this.setState({
298
- isDownsampleFinished: false,
299
- isDownsampleInProgress: true,
300
- downsamplingError: null
301
- });
302
- break;
303
- }
304
-
305
- case ChartModel.EVENT_DOWNSAMPLEFINISHED:
306
- {
307
- this.setState({
308
- isDownsampleFinished: true,
309
- isDownsampleInProgress: false,
310
- downsamplingError: null
311
- });
312
- break;
313
- }
314
-
315
- case ChartModel.EVENT_DOWNSAMPLENEEDED:
316
- case ChartModel.EVENT_DOWNSAMPLEFAILED:
317
- {
318
- var downsamplingError = detail.message ? detail.message : detail;
319
- this.setState({
320
- isDownsampleFinished: false,
321
- isDownsampleInProgress: false,
322
- isDownsamplingDisabled: false,
323
- downsamplingError: downsamplingError
324
- });
325
- var onError = this.props.onError;
326
- onError(new Error(downsamplingError));
327
- break;
328
- }
329
-
330
- default:
331
- log.debug('Unknown event type', type, event);
332
- }
175
+
176
+ model.subscribe(this.handleModelEvent);
177
+ this.isSubscribed = true;
178
+ }
179
+
180
+ unsubscribe() {
181
+ if (!this.isSubscribed) {
182
+ return;
333
183
  }
334
- }, {
335
- key: "handlePlotUpdate",
336
- value: function handlePlotUpdate(figure) {
337
- // User could have modified zoom/pan here, update the model dimensions
338
- // We don't need to update the datarevision, as we don't have any data changes
339
- // until an update comes back from the server anyway
340
- var layout = figure.layout;
341
- var ranges = ChartUtils.getLayoutRanges(layout);
342
- var isRangesChanged = !deepEqual(ranges, this.ranges);
343
-
344
- if (isRangesChanged) {
345
- this.ranges = ranges;
346
- this.updateModelDimensions(true);
347
- }
184
+
185
+ var {
186
+ model
187
+ } = this.props;
188
+ model.unsubscribe(this.handleModelEvent);
189
+ this.isSubscribed = false;
190
+ }
191
+
192
+ handleAfterPlot() {
193
+ if (this.plot.current) {// TODO: Translate whatever Don was doing in plotting.js in the afterplot here so that area graphs show up properly
348
194
  }
349
- }, {
350
- key: "handleRelayout",
351
- value: function handleRelayout(changes) {
352
- log.debug('handleRelayout', changes);
195
+ }
196
+
197
+ handleDownsampleClick() {
198
+ this.setState((_ref) => {
199
+ var {
200
+ isDownsamplingDisabled
201
+ } = _ref;
202
+ return {
203
+ downsamplingError: null,
204
+ isDownsampleInProgress: false,
205
+ isDownsampleFinished: false,
206
+ isDownsamplingDisabled: !isDownsamplingDisabled
207
+ };
208
+ }, () => {
209
+ var {
210
+ model
211
+ } = this.props;
212
+ var {
213
+ isDownsamplingDisabled
214
+ } = this.state;
215
+ model.setDownsamplingDisabled(isDownsamplingDisabled);
216
+ });
217
+ }
353
218
 
354
- if (Object.keys(changes).includes('hiddenlabels')) {
355
- var onSettingsChanged = this.props.onSettingsChanged; // Pie charts store series visibility in layout.hiddenlabels and trigger relayout on changes
356
- // Series visibility for other types of charts is handled in handleRestyle
219
+ handleModelEvent(event) {
220
+ var {
221
+ type,
222
+ detail
223
+ } = event;
224
+ log.debug2('Received data update', type, detail);
225
+
226
+ switch (type) {
227
+ case ChartModel.EVENT_UPDATED:
228
+ {
229
+ this.currentSeries += 1;
230
+ this.setState(state => {
231
+ var {
232
+ layout,
233
+ revision
234
+ } = state;
235
+ layout.datarevision += 1;
236
+ return {
237
+ data: detail,
238
+ layout,
239
+ revision: revision + 1
240
+ };
241
+ });
242
+ var {
243
+ onUpdate
244
+ } = this.props;
245
+ onUpdate({
246
+ isLoading: !this.isLoadedFired
247
+ });
248
+ break;
249
+ }
357
250
 
358
- var hiddenSeries = _toConsumableArray(changes.hiddenlabels);
251
+ case ChartModel.EVENT_LOADFINISHED:
252
+ {
253
+ var {
254
+ onUpdate: _onUpdate
255
+ } = this.props;
256
+ this.isLoadedFired = true;
359
257
 
360
- onSettingsChanged({
361
- hiddenSeries: hiddenSeries
362
- });
363
- }
258
+ _onUpdate({
259
+ isLoading: false
260
+ });
364
261
 
365
- this.updateModelDimensions();
366
- }
367
- }, {
368
- key: "handleRestyle",
369
- value: function handleRestyle(_ref2) {
370
- var _ref3 = _slicedToArray(_ref2, 2),
371
- changes = _ref3[0],
372
- seriesIndexes = _ref3[1];
373
-
374
- log.debug('handleRestyle', changes, seriesIndexes);
375
-
376
- if (Object.keys(changes).includes('visible')) {
377
- var data = this.state.data;
378
- var onSettingsChanged = this.props.onSettingsChanged;
379
- var hiddenSeries = data.reduce(function (acc, _ref4) {
380
- var name = _ref4.name,
381
- visible = _ref4.visible;
382
- return visible === 'legendonly' ? [].concat(_toConsumableArray(acc), [name]) : acc;
383
- }, []);
384
- onSettingsChanged({
385
- hiddenSeries: hiddenSeries
386
- });
387
- }
388
- }
389
- /**
390
- * Update the models dimensions and ranges.
391
- * Note that this will update it all whether the plot size changes OR the range
392
- * the user is looking at has changed (eg. panning/zooming).
393
- * Could update each independently, but doing them at the same time keeps the
394
- * ChartModel API a bit cleaner.
395
- * @param {boolean} force Force a change even if the chart dimensions haven't changed (eg. after pan/zoom)
396
- */
397
-
398
- }, {
399
- key: "updateModelDimensions",
400
- value: function updateModelDimensions() {
401
- var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
402
- var rect = this.getPlotRect();
403
-
404
- if (!rect) {
405
- log.warn('Unable to get plotting rect');
406
- return;
407
- }
262
+ break;
263
+ }
408
264
 
409
- var isRectChanged = !this.rect || this.rect.width !== rect.width || this.rect.height !== rect.height;
265
+ case ChartModel.EVENT_DISCONNECT:
266
+ {
267
+ var {
268
+ onDisconnect
269
+ } = this.props;
270
+ onDisconnect();
271
+ break;
272
+ }
410
273
 
411
- if (isRectChanged || force) {
412
- this.rect = rect;
413
- var _this$props2 = this.props,
414
- isActive = _this$props2.isActive,
415
- model = _this$props2.model;
416
- model.setDimensions(rect); // We may need to resubscribe if dimensions were too small before
274
+ case ChartModel.EVENT_RECONNECT:
275
+ {
276
+ var {
277
+ onReconnect
278
+ } = this.props;
279
+ onReconnect();
280
+ break;
281
+ }
417
282
 
418
- if (isActive) {
419
- this.subscribe();
283
+ case ChartModel.EVENT_DOWNSAMPLESTARTED:
284
+ {
285
+ this.setState({
286
+ isDownsampleFinished: false,
287
+ isDownsampleInProgress: true,
288
+ downsamplingError: null
289
+ });
290
+ break;
420
291
  }
421
- }
292
+
293
+ case ChartModel.EVENT_DOWNSAMPLEFINISHED:
294
+ {
295
+ this.setState({
296
+ isDownsampleFinished: true,
297
+ isDownsampleInProgress: false,
298
+ downsamplingError: null
299
+ });
300
+ break;
301
+ }
302
+
303
+ case ChartModel.EVENT_DOWNSAMPLENEEDED:
304
+ case ChartModel.EVENT_DOWNSAMPLEFAILED:
305
+ {
306
+ var downsamplingError = detail.message ? detail.message : detail;
307
+ this.setState({
308
+ isDownsampleFinished: false,
309
+ isDownsampleInProgress: false,
310
+ isDownsamplingDisabled: false,
311
+ downsamplingError
312
+ });
313
+ var {
314
+ onError
315
+ } = this.props;
316
+ onError(new Error(downsamplingError));
317
+ break;
318
+ }
319
+
320
+ default:
321
+ log.debug('Unknown event type', type, event);
422
322
  }
423
- }, {
424
- key: "initFormatter",
425
- value: function initFormatter() {
426
- var settings = this.props.settings;
427
- this.updateFormatterSettings(settings);
323
+ }
324
+
325
+ handlePlotUpdate(figure) {
326
+ // User could have modified zoom/pan here, update the model dimensions
327
+ // We don't need to update the datarevision, as we don't have any data changes
328
+ // until an update comes back from the server anyway
329
+ var {
330
+ layout
331
+ } = figure;
332
+ var ranges = ChartUtils.getLayoutRanges(layout);
333
+ var isRangesChanged = !deepEqual(ranges, this.ranges);
334
+
335
+ if (isRangesChanged) {
336
+ this.ranges = ranges;
337
+ this.updateModelDimensions(true);
428
338
  }
429
- }, {
430
- key: "updateFormatterSettings",
431
- value: function updateFormatterSettings(settings) {
432
- var columnFormats = FormatterUtils.getColumnFormats(settings);
433
- var dateTimeFormatterOptions = FormatterUtils.getDateTimeFormatterOptions(settings);
434
-
435
- if (!deepEqual(this.columnFormats, columnFormats) || !deepEqual(this.dateTimeFormatterOptions, dateTimeFormatterOptions)) {
436
- this.columnFormats = FormatterUtils.getColumnFormats(settings);
437
- this.dateTimeFormatterOptions = FormatterUtils.getDateTimeFormatterOptions(settings);
438
- this.updateFormatter();
439
- }
339
+ }
340
+
341
+ handleRelayout(changes) {
342
+ log.debug('handleRelayout', changes);
343
+
344
+ if (Object.keys(changes).includes('hiddenlabels')) {
345
+ var {
346
+ onSettingsChanged
347
+ } = this.props; // Pie charts store series visibility in layout.hiddenlabels and trigger relayout on changes
348
+ // Series visibility for other types of charts is handled in handleRestyle
349
+
350
+ var hiddenSeries = [...changes.hiddenlabels];
351
+ onSettingsChanged({
352
+ hiddenSeries
353
+ });
354
+ }
355
+
356
+ this.updateModelDimensions();
357
+ }
358
+
359
+ handleRestyle(_ref2) {
360
+ var [changes, seriesIndexes] = _ref2;
361
+ log.debug('handleRestyle', changes, seriesIndexes);
362
+
363
+ if (Object.keys(changes).includes('visible')) {
364
+ var {
365
+ data
366
+ } = this.state;
367
+ var {
368
+ onSettingsChanged
369
+ } = this.props;
370
+ var hiddenSeries = data.reduce((acc, _ref3) => {
371
+ var {
372
+ name,
373
+ visible
374
+ } = _ref3;
375
+ return visible === 'legendonly' ? [...acc, name] : acc;
376
+ }, []);
377
+ onSettingsChanged({
378
+ hiddenSeries
379
+ });
440
380
  }
441
- }, {
442
- key: "updateFormatter",
443
- value: function updateFormatter() {
444
- var formatter = new Formatter(this.columnFormats, this.dateTimeFormatterOptions);
445
- var model = this.props.model;
446
- model.setFormatter(formatter);
381
+ }
382
+ /**
383
+ * Update the models dimensions and ranges.
384
+ * Note that this will update it all whether the plot size changes OR the range
385
+ * the user is looking at has changed (eg. panning/zooming).
386
+ * Could update each independently, but doing them at the same time keeps the
387
+ * ChartModel API a bit cleaner.
388
+ * @param {boolean} force Force a change even if the chart dimensions haven't changed (eg. after pan/zoom)
389
+ */
390
+
391
+
392
+ updateModelDimensions() {
393
+ var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
394
+ var rect = this.getPlotRect();
395
+
396
+ if (!rect) {
397
+ log.warn('Unable to get plotting rect');
398
+ return;
447
399
  }
448
- }, {
449
- key: "updateDimensions",
450
- value: function updateDimensions() {
451
- var rect = this.getPlotRect();
452
-
453
- if (this.plot.current != null && rect != null && rect.width > 0 && rect.height > 0) {
454
- // Call relayout to resize avoiding the debouncing plotly does
455
- // https://github.com/plotly/plotly.js/issues/2769#issuecomment-402099552
456
- Plotly.relayout(this.plot.current.el, {
457
- autosize: true
458
- })["catch"](function (e) {
459
- log.debug('Unable to resize, promise rejected', e);
460
- });
400
+
401
+ var isRectChanged = !this.rect || this.rect.width !== rect.width || this.rect.height !== rect.height;
402
+
403
+ if (isRectChanged || force) {
404
+ this.rect = rect;
405
+ var {
406
+ isActive,
407
+ model
408
+ } = this.props;
409
+ model.setDimensions(rect); // We may need to resubscribe if dimensions were too small before
410
+
411
+ if (isActive) {
412
+ this.subscribe();
461
413
  }
462
414
  }
463
- }, {
464
- key: "render",
465
- value: function render() {
466
- var _this$state = this.state,
467
- data = _this$state.data,
468
- downsamplingError = _this$state.downsamplingError,
469
- isDownsampleFinished = _this$state.isDownsampleFinished,
470
- isDownsampleInProgress = _this$state.isDownsampleInProgress,
471
- isDownsamplingDisabled = _this$state.isDownsamplingDisabled,
472
- layout = _this$state.layout,
473
- revision = _this$state.revision;
474
- var config = this.getCachedConfig(downsamplingError, isDownsampleFinished, isDownsampleInProgress, isDownsamplingDisabled);
475
- var isPlotShown = data != null;
476
- return /*#__PURE__*/React.createElement("div", {
477
- className: "h-100 w-100 chart-wrapper",
478
- ref: this.plotWrapper
479
- }, isPlotShown && /*#__PURE__*/React.createElement(Plot, {
480
- ref: this.plot,
481
- data: data,
482
- layout: layout,
483
- revision: revision,
484
- config: config,
485
- onAfterPlot: this.handleAfterPlot,
486
- onRelayout: this.handleRelayout,
487
- onUpdate: this.handlePlotUpdate,
488
- onRestyle: this.handleRestyle,
489
- useResizeHandler: true,
490
- style: {
491
- height: '100%',
492
- width: '100%'
493
- }
494
- }));
495
- }
496
- }], [{
497
- key: "convertIcon",
498
- value:
499
- /**
500
- * Convert a font awesome icon definition to a plotly icon definition
501
- * @param {FontAwesome.IconDefinition} faIcon The icon to convert
502
- */
503
- function convertIcon(faIcon) {
504
- var _faIcon$icon = _slicedToArray(faIcon.icon, 5),
505
- width = _faIcon$icon[0],
506
- path = _faIcon$icon[4]; // By default the icons are flipped upside down, so we need to add our own transform
507
- // https://github.com/plotly/plotly.js/issues/1335
415
+ }
508
416
 
417
+ initFormatter() {
418
+ var {
419
+ settings
420
+ } = this.props;
421
+ this.updateFormatterSettings(settings);
422
+ }
509
423
 
510
- return {
511
- width: width,
512
- path: path,
513
- ascent: width,
514
- descent: 0,
515
- transform: "matrix(1, 0, 0, 1, 0, 0)"
516
- };
424
+ updateFormatterSettings(settings) {
425
+ var columnFormats = FormatterUtils.getColumnFormats(settings);
426
+ var dateTimeFormatterOptions = FormatterUtils.getDateTimeFormatterOptions(settings);
427
+
428
+ if (!deepEqual(this.columnFormats, columnFormats) || !deepEqual(this.dateTimeFormatterOptions, dateTimeFormatterOptions)) {
429
+ this.columnFormats = FormatterUtils.getColumnFormats(settings);
430
+ this.dateTimeFormatterOptions = FormatterUtils.getDateTimeFormatterOptions(settings);
431
+ this.updateFormatter();
517
432
  }
518
- }, {
519
- key: "downsampleButtonTitle",
520
- value: function downsampleButtonTitle(isDownsampleInProgress, isDownsamplingDisabled) {
521
- if (isDownsampleInProgress) {
522
- return ChartConstants['title-downsampling-in-progress'];
523
- }
433
+ }
434
+
435
+ updateFormatter() {
436
+ var formatter = new Formatter(this.columnFormats, this.dateTimeFormatterOptions);
437
+ var {
438
+ model
439
+ } = this.props;
440
+ model.setFormatter(formatter);
441
+ }
442
+
443
+ updateDimensions() {
444
+ var rect = this.getPlotRect();
524
445
 
525
- return isDownsamplingDisabled ? ChartConstants['title-downsampling-disabled'] : ChartConstants['title-downsampling-enabled'];
446
+ if (this.plot.current != null && rect != null && rect.width > 0 && rect.height > 0) {
447
+ // Call relayout to resize avoiding the debouncing plotly does
448
+ // https://github.com/plotly/plotly.js/issues/2769#issuecomment-402099552
449
+ Plotly.relayout(this.plot.current.el, {
450
+ autosize: true
451
+ }).catch(e => {
452
+ log.debug('Unable to resize, promise rejected', e);
453
+ });
526
454
  }
527
- }]);
455
+ }
528
456
 
529
- return Chart;
530
- }(Component);
457
+ render() {
458
+ var {
459
+ data,
460
+ downsamplingError,
461
+ isDownsampleFinished,
462
+ isDownsampleInProgress,
463
+ isDownsamplingDisabled,
464
+ layout,
465
+ revision
466
+ } = this.state;
467
+ var config = this.getCachedConfig(downsamplingError, isDownsampleFinished, isDownsampleInProgress, isDownsamplingDisabled);
468
+ var isPlotShown = data != null;
469
+ return /*#__PURE__*/React.createElement("div", {
470
+ className: "h-100 w-100 chart-wrapper",
471
+ ref: this.plotWrapper
472
+ }, isPlotShown && /*#__PURE__*/React.createElement(Plot, {
473
+ ref: this.plot,
474
+ data: data,
475
+ layout: layout,
476
+ revision: revision,
477
+ config: config,
478
+ onAfterPlot: this.handleAfterPlot,
479
+ onRelayout: this.handleRelayout,
480
+ onUpdate: this.handlePlotUpdate,
481
+ onRestyle: this.handleRestyle,
482
+ useResizeHandler: true,
483
+ style: {
484
+ height: '100%',
485
+ width: '100%'
486
+ }
487
+ }));
488
+ }
489
+
490
+ }
531
491
  Chart.propTypes = {
532
492
  model: PropTypes.instanceOf(ChartModel).isRequired,
533
- settings: PropTypes.shape({}).isRequired,
493
+ // These settings come from the redux store
494
+ settings: PropTypes.shape({
495
+ timeZone: PropTypes.string.isRequired,
496
+ defaultDateTimeFormat: PropTypes.string.isRequired,
497
+ showTimeZone: PropTypes.bool.isRequired,
498
+ showTSeparator: PropTypes.bool.isRequired,
499
+ formatter: PropTypes.arrayOf(PropTypes.shape({})).isRequired
500
+ }),
534
501
  isActive: PropTypes.bool,
535
502
  onDisconnect: PropTypes.func,
536
503
  onReconnect: PropTypes.func,
@@ -540,20 +507,18 @@ Chart.propTypes = {
540
507
  };
541
508
  Chart.defaultProps = {
542
509
  isActive: true,
543
- onDisconnect: function onDisconnect() {},
544
- onReconnect: function onReconnect() {},
545
- onUpdate: function onUpdate() {},
546
- onError: function onError() {},
547
- onSettingsChanged: function onSettingsChanged() {}
510
+ settings: {
511
+ timeZone: 'America/New_York',
512
+ defaultDateTimeFormat: DateUtils.FULL_DATE_FORMAT,
513
+ showTimeZone: false,
514
+ showTSeparator: true,
515
+ formatter: []
516
+ },
517
+ onDisconnect: () => {},
518
+ onReconnect: () => {},
519
+ onUpdate: () => {},
520
+ onError: () => {},
521
+ onSettingsChanged: () => {}
548
522
  };
549
-
550
- var mapStateToProps = function mapStateToProps(state) {
551
- return {
552
- settings: getSettings(state)
553
- };
554
- };
555
-
556
- export default connect(mapStateToProps, null, null, {
557
- forwardRef: true
558
- })(Chart);
523
+ export default Chart;
559
524
  //# sourceMappingURL=Chart.js.map