@deephaven/chart 0.22.3-embed-pandas.11 → 0.23.1-beta.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.
@@ -1,9 +1,6 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  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; }
6
-
7
4
  import Log from '@deephaven/log';
8
5
  import { TableUtils } from '@deephaven/jsapi-utils';
9
6
  import dh from '@deephaven/jsapi-shim';
@@ -15,23 +12,18 @@ var DAYS = Object.freeze(dh.calendar.DayOfWeek.values());
15
12
  var BUSINESS_COLUMN_TYPE = 'io.deephaven.time.DateTime';
16
13
  var MILLIS_PER_HOUR = 3600000;
17
14
  var NANOS_PER_MILLI = 1000000;
18
-
19
15
  function isDateWrapper(value) {
20
16
  return value.asDate !== undefined;
21
17
  }
22
-
23
18
  function isLongWrapper(value) {
24
19
  return value.asNumber !== undefined;
25
20
  }
26
-
27
21
  function isDateTimeColumnFormatter(value) {
28
22
  return value.dhTimeZone !== undefined;
29
23
  }
30
-
31
24
  function isRangedPlotlyAxis(value) {
32
- return value != null && value.range && (value.autorange === false || value.autorange === undefined);
25
+ return value != null && value.range != null && (value.autorange === false || value.autorange === undefined);
33
26
  }
34
-
35
27
  class ChartUtils {
36
28
  /**
37
29
  * Converts the Iris plot style into a plotly chart type
@@ -43,188 +35,140 @@ class ChartUtils {
43
35
  case dh.plot.SeriesPlotStyle.SCATTER:
44
36
  // scattergl mode is more performant, but doesn't support the rangebreaks we need for businessTime calendars
45
37
  return !isBusinessTime ? 'scattergl' : 'scatter';
46
-
47
38
  case dh.plot.SeriesPlotStyle.LINE:
48
39
  // There is also still some artifacting bugs with scattergl: https://github.com/plotly/plotly.js/issues/3522
49
40
  // The artifacting only occurs on line plots, which we can draw with fairly decent performance using SVG paths
50
41
  // Once the above plotly issue is fixed, scattergl should be used here (when !isBusinessTime)
51
42
  return 'scatter';
52
-
53
43
  case dh.plot.SeriesPlotStyle.BAR:
54
44
  case dh.plot.SeriesPlotStyle.STACKED_BAR:
55
45
  return 'bar';
56
-
57
46
  case dh.plot.SeriesPlotStyle.PIE:
58
47
  return 'pie';
59
-
60
48
  case dh.plot.SeriesPlotStyle.TREEMAP:
61
49
  return 'treemap';
62
-
63
50
  case dh.plot.SeriesPlotStyle.HISTOGRAM:
64
51
  return 'histogram';
65
-
66
52
  case dh.plot.SeriesPlotStyle.OHLC:
67
53
  return 'ohlc';
68
-
69
54
  default:
70
55
  return undefined;
71
56
  }
72
57
  }
58
+
73
59
  /**
74
60
  * Converts the Iris plot style into a plotly chart mode
75
61
  * @param plotStyle The plotStyle to use, see dh.plot.SeriesPlotStyle.*
76
62
  */
77
-
78
-
79
63
  static getPlotlyChartMode(plotStyle) {
80
64
  switch (plotStyle) {
81
65
  case dh.plot.SeriesPlotStyle.SCATTER:
82
66
  return 'markers';
83
-
84
67
  case dh.plot.SeriesPlotStyle.LINE:
85
68
  return 'lines';
86
-
87
69
  default:
88
70
  return undefined;
89
71
  }
90
72
  }
73
+
91
74
  /**
92
75
  * Get the property to set on the series data for plotly
93
76
  * @param plotStyle The plot style of the series
94
77
  * @param sourceType The source type for the series
95
78
  */
96
-
97
-
98
79
  static getPlotlyProperty(plotStyle, sourceType) {
99
80
  switch (plotStyle) {
100
81
  case dh.plot.SeriesPlotStyle.PIE:
101
82
  switch (sourceType) {
102
83
  case dh.plot.SourceType.X:
103
84
  return 'labels';
104
-
105
85
  case dh.plot.SourceType.Y:
106
86
  return 'values';
107
-
108
87
  default:
109
88
  break;
110
89
  }
111
-
112
90
  break;
113
-
114
91
  case dh.plot.SeriesPlotStyle.OHLC:
115
92
  switch (sourceType) {
116
93
  case dh.plot.SourceType.TIME:
117
94
  return 'x';
118
-
119
95
  default:
120
96
  break;
121
97
  }
122
-
123
98
  break;
124
-
125
99
  case dh.plot.SeriesPlotStyle.TREEMAP:
126
100
  switch (sourceType) {
127
101
  case dh.plot.SourceType.X:
128
102
  return 'ids';
129
-
130
103
  case dh.plot.SourceType.Y:
131
104
  return 'values';
132
-
133
105
  case dh.plot.SourceType.LABEL:
134
106
  return 'labels';
135
-
136
107
  case dh.plot.SourceType.PARENT:
137
108
  return 'parents';
138
-
139
109
  case dh.plot.SourceType.COLOR:
140
110
  return 'marker.colors';
141
-
142
111
  default:
143
112
  break;
144
113
  }
145
-
146
114
  break;
147
-
148
115
  default:
149
116
  break;
150
117
  }
151
-
152
118
  switch (sourceType) {
153
119
  case dh.plot.SourceType.X:
154
120
  return 'x';
155
-
156
121
  case dh.plot.SourceType.Y:
157
122
  return 'y';
158
-
159
123
  case dh.plot.SourceType.Z:
160
124
  return 'z';
161
-
162
125
  case dh.plot.SourceType.X_LOW:
163
126
  return 'xLow';
164
-
165
127
  case dh.plot.SourceType.X_HIGH:
166
128
  return 'xHigh';
167
-
168
129
  case dh.plot.SourceType.Y_LOW:
169
130
  return 'yLow';
170
-
171
131
  case dh.plot.SourceType.Y_HIGH:
172
132
  return 'yHigh';
173
-
174
133
  case dh.plot.SourceType.TIME:
175
134
  return 'time';
176
-
177
135
  case dh.plot.SourceType.OPEN:
178
136
  return 'open';
179
-
180
137
  case dh.plot.SourceType.HIGH:
181
138
  return 'high';
182
-
183
139
  case dh.plot.SourceType.LOW:
184
140
  return 'low';
185
-
186
141
  case dh.plot.SourceType.CLOSE:
187
142
  return 'close';
188
-
189
143
  case dh.plot.SourceType.SHAPE:
190
144
  return 'shape';
191
-
192
145
  case dh.plot.SourceType.SIZE:
193
146
  return 'size';
194
-
195
147
  case dh.plot.SourceType.LABEL:
196
148
  return 'label';
197
-
198
149
  case dh.plot.SourceType.COLOR:
199
150
  return 'color';
200
-
201
151
  case dh.plot.SourceType.PARENT:
202
152
  return 'parent';
203
-
204
153
  case dh.plot.SourceType.HOVER_TEXT:
205
154
  return 'hovertext';
206
-
207
155
  case dh.plot.SourceType.TEXT:
208
156
  return 'text';
209
-
210
157
  default:
211
158
  throw new Error("Unrecognized source type: ".concat(sourceType));
212
159
  }
213
160
  }
214
-
215
161
  static getPlotlySeriesOrientation(series) {
216
162
  var _sources$, _sources$$axis;
217
-
218
163
  var {
219
164
  sources
220
165
  } = series;
221
-
222
166
  if (sources.length === 2 && ((_sources$ = sources[0]) === null || _sources$ === void 0 ? void 0 : (_sources$$axis = _sources$.axis) === null || _sources$$axis === void 0 ? void 0 : _sources$$axis.type) === dh.plot.AxisType.Y) {
223
167
  return ChartUtils.ORIENTATION.HORIZONTAL;
224
168
  }
225
-
226
169
  return ChartUtils.ORIENTATION.VERTICAL;
227
170
  }
171
+
228
172
  /**
229
173
  * Generate the plotly error bar data from the passed in data.
230
174
  * Iris passes in the values as absolute, plotly needs them as relative.
@@ -234,8 +178,6 @@ class ChartUtils {
234
178
  *
235
179
  * @returns The error_x object required by plotly, or null if none is required
236
180
  */
237
-
238
-
239
181
  static getPlotlyErrorBars(x, xLow, xHigh) {
240
182
  var array = xHigh.map((value, i) => value - x[i]);
241
183
  var arrayminus = xLow.map((value, i) => x[i] - value);
@@ -246,37 +188,32 @@ class ChartUtils {
246
188
  arrayminus
247
189
  };
248
190
  }
249
-
250
191
  static getPlotlyDateFormat(formatter, columnType, formatPattern) {
251
192
  var tickformat = formatPattern == null ? undefined : formatPattern.replace('%', '%%').replace(/S{9}/g, '%9f').replace(/S{8}/g, '%8f').replace(/S{7}/g, '%7f').replace(/S{6}/g, '%6f').replace(/S{5}/g, '%5f').replace(/S{4}/g, '%4f').replace(/S{3}/g, '%3f').replace(/S{2}/g, '%2f').replace(/S{1}/g, '%1f').replace(/y{4}/g, '%Y').replace(/y{2}/g, '%y').replace(/M{4}/g, '%B').replace(/M{3}/g, '%b').replace(/M{2}/g, '%m').replace(/M{1}/g, '%-m').replace(/E{4,}/g, '%A').replace(/E{1,}/g, '%a').replace(/d{2}/g, '%d').replace(/([^%]|^)d{1}/g, '$1%-d').replace(/H{2}/g, '%H').replace(/h{2}/g, '%I').replace(/h{1}/g, '%-I').replace(/m{2}/g, '%M').replace(/s{2}/g, '%S').replace("'T'", 'T').replace(' z', ''); // timezone added as suffix if necessary
252
193
 
253
194
  var ticksuffix;
254
195
  var dataFormatter = formatter === null || formatter === void 0 ? void 0 : formatter.getColumnTypeFormatter(columnType);
255
-
256
196
  if (dataFormatter != null && isDateTimeColumnFormatter(dataFormatter) && dataFormatter.dhTimeZone != null && dataFormatter.showTimeZone) {
257
197
  ticksuffix = dh.i18n.DateTimeFormat.format(' z', new Date(), dataFormatter.dhTimeZone);
258
198
  }
259
-
260
199
  return {
261
200
  tickformat,
262
201
  ticksuffix,
263
202
  automargin: true
264
203
  };
265
204
  }
266
-
267
205
  static convertNumberPrefix(prefix) {
268
206
  return prefix.replace(/\u00A4\u00A4/g, 'USD').replace(/\u00A4/g, '$');
269
207
  }
270
-
271
208
  static getPlotlyNumberFormat(formatter, columnType, formatPattern) {
272
209
  if (!formatPattern) {
273
210
  return null;
274
- } // We translate java formatting: https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
211
+ }
212
+
213
+ // We translate java formatting: https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
275
214
  // Into d3 number formatting: https://github.com/d3/d3-format
276
215
  // We can't translate number formatting exactly, but should be able to translate the most common cases
277
216
  // First split it into the subpatterns; currently only handling the positive subpattern, ignoring the rest
278
-
279
-
280
217
  var subpatterns = formatPattern.split(';');
281
218
  var matchArray = subpatterns[0].match(/^([^#,0.]*)([#,]*)([0,]*)(\.?)(0*)(#*)(E?0*)(%?)(.*)/);
282
219
  assertNotNull(matchArray);
@@ -286,14 +223,14 @@ class ChartUtils {
286
223
  var comma = isCommaSeparated ? ',' : '';
287
224
  var plotlyNumberType = numberType != null && numberType !== '' ? 'e' : 'f';
288
225
  var type = percentSign !== '' ? percentSign : plotlyNumberType;
289
- var decimalLength = decimalDigits.length + optionalDecimalDigits.length; // IDS-4565 Plotly uses an older version of d3 which doesn't support the trim option or negative brackets
226
+ var decimalLength = decimalDigits.length + optionalDecimalDigits.length;
227
+ // IDS-4565 Plotly uses an older version of d3 which doesn't support the trim option or negative brackets
290
228
  // If plotly updates it's d3 version, this should be re-enabled
291
229
  // const trimOption = optionalDecimalDigits.length > 0 ? '~' : '';
292
-
293
230
  var trimOption = '';
294
231
  var tickformat = "0".concat(paddingLength).concat(comma, ".").concat(decimalLength).concat(trimOption).concat(type);
295
- var tickprefix = ChartUtils.convertNumberPrefix(prefix); // prefix and suffix are processed the same
296
-
232
+ var tickprefix = ChartUtils.convertNumberPrefix(prefix);
233
+ // prefix and suffix are processed the same
297
234
  var ticksuffix = ChartUtils.convertNumberPrefix(suffix);
298
235
  return {
299
236
  tickformat,
@@ -302,13 +239,12 @@ class ChartUtils {
302
239
  automargin: true
303
240
  };
304
241
  }
242
+
305
243
  /**
306
244
  * Gets the plotly axis formatting information from the source passed in
307
245
  * @param source The Source to get the formatter information from
308
246
  * @param formatter The current formatter for formatting data
309
247
  */
310
-
311
-
312
248
  static getPlotlyAxisFormat(source) {
313
249
  var formatter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
314
250
  var {
@@ -319,7 +255,6 @@ class ChartUtils {
319
255
  formatPattern
320
256
  } = axis;
321
257
  var axisFormat = null;
322
-
323
258
  if (TableUtils.isDateType(columnType)) {
324
259
  axisFormat = ChartUtils.getPlotlyDateFormat(formatter, columnType, formatPattern);
325
260
  axisFormat = ChartUtils.addTickSpacing(axisFormat, axis, true);
@@ -327,7 +262,6 @@ class ChartUtils {
327
262
  axisFormat = ChartUtils.getPlotlyNumberFormat(formatter, columnType, formatPattern);
328
263
  axisFormat = ChartUtils.addTickSpacing(axisFormat, axis, false);
329
264
  }
330
-
331
265
  if (axis.formatType === dh.plot.AxisFormatType.CATEGORY) {
332
266
  if (axisFormat) {
333
267
  axisFormat.type = 'category';
@@ -339,9 +273,9 @@ class ChartUtils {
339
273
  };
340
274
  }
341
275
  }
342
-
343
276
  return axisFormat;
344
277
  }
278
+
345
279
  /**
346
280
  * Adds tick spacing for an axis that has gapBetweenMajorTicks defined.
347
281
  *
@@ -349,92 +283,76 @@ class ChartUtils {
349
283
  * @param axis the current axis
350
284
  * @param isDateType indicates if the columns is a date type
351
285
  */
352
-
353
-
354
286
  static addTickSpacing(axisFormat, axis, isDateType) {
355
287
  var {
356
288
  gapBetweenMajorTicks
357
289
  } = axis;
358
-
359
290
  if (gapBetweenMajorTicks > 0) {
360
291
  var updatedFormat = axisFormat || {};
361
292
  var tickSpacing = gapBetweenMajorTicks;
362
-
363
293
  if (isDateType) {
364
294
  // Need to convert from nanoseconds to milliseconds
365
295
  tickSpacing = gapBetweenMajorTicks / NANOS_PER_MILLI;
366
296
  }
367
-
368
297
  if (axis.log) {
369
298
  tickSpacing = Math.log(tickSpacing);
370
- } // Note that tickmode defaults to 'auto'
371
-
372
-
299
+ }
300
+ // Note that tickmode defaults to 'auto'
373
301
  updatedFormat.tickmode = 'linear';
374
302
  updatedFormat.dtick = tickSpacing;
375
303
  return updatedFormat;
376
304
  }
377
-
378
305
  return axisFormat;
379
306
  }
307
+
380
308
  /**
381
309
  * Retrieve the data source for a given axis in a chart
382
310
  * @param chart The chart to get the source for
383
311
  * @param axis The axis to find the source for
384
312
  * @returns The first source matching this axis
385
313
  */
386
-
387
-
388
314
  static getSourceForAxis(chart, axis) {
389
315
  for (var i = 0; i < chart.series.length; i += 1) {
390
316
  var series = chart.series[i];
391
-
392
317
  for (var j = 0; j < series.sources.length; j += 1) {
393
318
  var source = series.sources[j];
394
-
395
319
  if (source.axis === axis) {
396
320
  return source;
397
321
  }
398
322
  }
399
323
  }
400
-
401
324
  return null;
402
325
  }
326
+
403
327
  /**
404
328
  * Get visibility setting for the series object
405
329
  * @param name The series name to get the visibility for
406
330
  * @param settings Chart settings
407
331
  * @returns True for visible series and 'legendonly' for hidden
408
332
  */
409
-
410
-
411
333
  static getSeriesVisibility(name, settings) {
412
334
  if (settings != null && settings.hiddenSeries != null && settings.hiddenSeries.includes(name)) {
413
335
  return 'legendonly';
414
336
  }
415
-
416
337
  return true;
417
338
  }
339
+
418
340
  /**
419
341
  * Get hidden labels array from chart settings
420
342
  * @param settings Chart settings
421
343
  * @returns Array of hidden series names
422
344
  */
423
-
424
-
425
345
  static getHiddenLabels(settings) {
426
346
  if (settings !== null && settings !== void 0 && settings.hiddenSeries) {
427
347
  return [...settings.hiddenSeries];
428
348
  }
429
-
430
349
  return [];
431
350
  }
351
+
432
352
  /**
433
353
  * Create a default series data object. Apply styling to the object afterward.
434
354
  * @returns A simple series data object with no styling
435
355
  */
436
-
437
-
438
356
  static makeSeriesData(type, mode, name) {
439
357
  var orientation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ChartUtils.ORIENTATION.VERTICAL;
440
358
  return {
@@ -444,6 +362,7 @@ class ChartUtils {
444
362
  orientation
445
363
  };
446
364
  }
365
+
447
366
  /**
448
367
  * Create a data series (trace) for use with plotly
449
368
  * @param series The series to create the series data with
@@ -452,8 +371,6 @@ class ChartUtils {
452
371
  * @param theme The theme properties for the plot. See ChartTheme.js for an example
453
372
  * @returns The series data (trace) object for use with plotly.
454
373
  */
455
-
456
-
457
374
  static makeSeriesDataFromSeries(series, axisTypeMap, seriesVisibility) {
458
375
  var theme = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ChartTheme;
459
376
  var {
@@ -465,7 +382,6 @@ class ChartUtils {
465
382
  } = series;
466
383
  var isBusinessTime = sources.some(source => {
467
384
  var _source$axis;
468
-
469
385
  return (_source$axis = source.axis) === null || _source$axis === void 0 ? void 0 : _source$axis.businessCalendar;
470
386
  });
471
387
  var type = ChartUtils.getChartType(plotStyle, isBusinessTime);
@@ -476,10 +392,8 @@ class ChartUtils {
476
392
  ChartUtils.addStylingToSeriesData(seriesData, plotStyle, theme, lineColor, shapeColor, seriesVisibility);
477
393
  return seriesData;
478
394
  }
479
-
480
395
  static addSourcesToSeriesData(seriesDataParam, plotStyle, sources, axisTypeMap) {
481
396
  var seriesData = seriesDataParam;
482
-
483
397
  for (var k = 0; k < sources.length; k += 1) {
484
398
  var source = sources[k];
485
399
  var {
@@ -489,10 +403,8 @@ class ChartUtils {
489
403
  var dataAttributeName = ChartUtils.getPlotlyProperty(plotStyle, sourceType);
490
404
  set(seriesData, dataAttributeName, []);
491
405
  var axisProperty = _axis != null ? ChartUtils.getAxisPropertyName(_axis.type) : null;
492
-
493
406
  if (axisProperty != null) {
494
407
  var axes = axisTypeMap.get(_axis.type);
495
-
496
408
  if (axes) {
497
409
  var axisIndex = axes.indexOf(_axis);
498
410
  var axisIndexString = axisIndex > 0 ? "".concat(axisIndex + 1) : '';
@@ -501,21 +413,18 @@ class ChartUtils {
501
413
  }
502
414
  }
503
415
  }
504
-
505
416
  static addStylingToSeriesData(seriesDataParam, plotStyle) {
506
417
  var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ChartTheme;
507
418
  var lineColor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
508
419
  var shapeColor = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
509
420
  var seriesVisibility = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
510
- var seriesData = seriesDataParam; // Add some empty objects so we can fill them in later with details without checking for existence
511
-
421
+ var seriesData = seriesDataParam;
422
+ // Add some empty objects so we can fill them in later with details without checking for existence
512
423
  seriesData.marker = {
513
424
  line: {}
514
425
  }; // border line width on markers
515
-
516
426
  seriesData.line = {
517
427
  width: 1 // default line width for lines, should eventually be able to override
518
-
519
428
  };
520
429
 
521
430
  if (plotStyle === dh.plot.SeriesPlotStyle.AREA) {
@@ -528,7 +437,6 @@ class ChartUtils {
528
437
  // The default histfunc in plotly is 'count', but the data passed up from the API provides explicit x/y values and bins
529
438
  // Since it's converted to bar, just set the widths of each bar
530
439
  seriesData.width = [];
531
-
532
440
  if (seriesData.marker.line !== undefined) {
533
441
  Object.assign(seriesData.marker.line, {
534
442
  color: theme.paper_bgcolor,
@@ -547,10 +455,11 @@ class ChartUtils {
547
455
  }
548
456
  };
549
457
  } else if (plotStyle === dh.plot.SeriesPlotStyle.PIE) {
550
- seriesData.textinfo = 'label+percent'; // TODO Open DefinitelyTyped/Plotly PR to mark family and size as optional
458
+ seriesData.textinfo = 'label+percent';
459
+
460
+ // TODO Open DefinitelyTyped/Plotly PR to mark family and size as optional
551
461
  // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/plotly.js/lib/traces/pie.d.ts#L6
552
462
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
553
-
554
463
  seriesData.outsidetextfont = {
555
464
  color: theme.title_color
556
465
  };
@@ -561,13 +470,12 @@ class ChartUtils {
561
470
  packing: 'squarify',
562
471
  pad: 0
563
472
  };
564
- seriesData.textposition = 'middle center'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
565
-
473
+ seriesData.textposition = 'middle center';
474
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
566
475
  seriesData.outsidetextfont = {
567
476
  color: theme.title_color
568
477
  };
569
478
  }
570
-
571
479
  if (lineColor != null) {
572
480
  if (plotStyle === dh.plot.SeriesPlotStyle.BAR) {
573
481
  seriesData.marker.color = lineColor;
@@ -575,17 +483,17 @@ class ChartUtils {
575
483
  seriesData.line.color = lineColor;
576
484
  }
577
485
  }
578
-
579
486
  if (shapeColor != null) {
580
487
  seriesData.marker.color = shapeColor;
581
- } // Skipping pie charts
582
- // Pie slice visibility is configured in chart layout instead of series data
583
-
488
+ }
584
489
 
490
+ // Skipping pie charts
491
+ // Pie slice visibility is configured in chart layout instead of series data
585
492
  if (seriesVisibility != null && plotStyle !== dh.plot.SeriesPlotStyle.PIE) {
586
493
  seriesData.visible = seriesVisibility;
587
494
  }
588
495
  }
496
+
589
497
  /**
590
498
  * Retrieve the axis formats from the provided figure.
591
499
  * Currently defaults to just the x/y axes.
@@ -593,8 +501,6 @@ class ChartUtils {
593
501
  * @param formatter The formatter to use when getting the axis format
594
502
  * @returns A map of axis layout property names to axis formats
595
503
  */
596
-
597
-
598
504
  static getAxisFormats(figure, formatter) {
599
505
  var axisFormats = new Map();
600
506
  var nullFormat = {
@@ -606,17 +512,14 @@ class ChartUtils {
606
512
  var {
607
513
  charts
608
514
  } = figure;
609
-
610
515
  for (var i = 0; i < charts.length; i += 1) {
611
516
  var _chart = charts[i];
612
-
613
517
  for (var j = 0; j < _chart.series.length; j += 1) {
614
518
  var series = _chart.series[j];
615
519
  var {
616
520
  sources
617
521
  } = series;
618
522
  var axisSources = sources.filter(source => source.axis);
619
-
620
523
  for (var k = 0; k < axisSources.length; k += 1) {
621
524
  var source = axisSources[k];
622
525
  var {
@@ -629,16 +532,13 @@ class ChartUtils {
629
532
  assertNotNull(typeAxes);
630
533
  var axisIndex = typeAxes.indexOf(_axis2);
631
534
  var axisProperty = ChartUtils.getAxisPropertyName(axisType);
632
-
633
535
  if (axisProperty != null) {
634
536
  var axisLayoutProperty = ChartUtils.getAxisLayoutProperty(axisProperty, axisIndex);
635
-
636
537
  if (axisFormats.has(axisLayoutProperty)) {
637
538
  log.debug("".concat(axisLayoutProperty, " already added."));
638
539
  } else {
639
540
  log.debug("Adding ".concat(axisLayoutProperty, " to axisFormats."));
640
541
  var axisFormat = ChartUtils.getPlotlyAxisFormat(source, formatter);
641
-
642
542
  if (axisFormat === null) {
643
543
  axisFormats.set(axisLayoutProperty, nullFormat);
644
544
  } else {
@@ -646,7 +546,6 @@ class ChartUtils {
646
546
  var {
647
547
  businessCalendar
648
548
  } = _axis2;
649
-
650
549
  if (businessCalendar != null) {
651
550
  (function () {
652
551
  var rangebreaks = [];
@@ -658,33 +557,27 @@ class ChartUtils {
658
557
  } = businessCalendar;
659
558
  var typeFormatter = formatter === null || formatter === void 0 ? void 0 : formatter.getColumnTypeFormatter(BUSINESS_COLUMN_TYPE);
660
559
  var formatterTimeZone = void 0;
661
-
662
560
  if (isDateTimeColumnFormatter(typeFormatter)) {
663
561
  formatterTimeZone = typeFormatter.dhTimeZone;
664
562
  }
665
-
666
563
  var timeZoneDiff = formatterTimeZone ? (calendarTimeZone.standardOffset - formatterTimeZone.standardOffset) / 60 : 0;
667
-
668
564
  if (holidays.length > 0) {
669
565
  rangebreaks.push(...ChartUtils.createRangeBreakValuesFromHolidays(holidays, calendarTimeZone, formatterTimeZone));
670
566
  }
671
-
672
567
  businessPeriods.forEach(period => rangebreaks.push({
673
568
  pattern: 'hour',
674
569
  bounds: [ChartUtils.periodToDecimal(period.close) + timeZoneDiff, ChartUtils.periodToDecimal(period.open) + timeZoneDiff]
675
- })); // If there are seven business days, then there is no weekend
676
-
570
+ }));
571
+ // If there are seven business days, then there is no weekend
677
572
  if (businessDays.length < DAYS.length) {
678
573
  ChartUtils.createBoundsFromDays(businessDays).forEach(weekendBounds => rangebreaks.push({
679
574
  pattern: 'day of week',
680
575
  bounds: weekendBounds
681
576
  }));
682
577
  }
683
-
684
578
  axisFormat.rangebreaks = rangebreaks;
685
579
  })();
686
580
  }
687
-
688
581
  if (axisFormats.size === _chart.axes.length) {
689
582
  return axisFormats;
690
583
  }
@@ -694,119 +587,100 @@ class ChartUtils {
694
587
  }
695
588
  }
696
589
  }
697
-
698
590
  return axisFormats;
699
591
  }
700
-
701
592
  static getChartType(plotStyle, isBusinessTime) {
702
593
  switch (plotStyle) {
703
594
  case dh.plot.SeriesPlotStyle.HISTOGRAM:
704
595
  // When reading data from the `Figure`, it already provides bins and values, so rather than using
705
596
  // plot.ly to calculate the bins and sum values, just convert it to a bar chart
706
597
  return 'bar';
707
-
708
598
  default:
709
599
  return ChartUtils.getPlotlyChartType(plotStyle, isBusinessTime);
710
600
  }
711
601
  }
602
+
712
603
  /**
713
604
  * Return the plotly axis property name
714
605
  * @param axisType The axis type to get the property name for
715
606
  */
716
-
717
-
718
607
  static getAxisPropertyName(axisType) {
719
608
  switch (axisType) {
720
609
  case dh.plot.AxisType.X:
721
610
  return 'x';
722
-
723
611
  case dh.plot.AxisType.Y:
724
612
  return 'y';
725
-
726
613
  default:
727
614
  return null;
728
615
  }
729
616
  }
617
+
730
618
  /**
731
619
  * Returns the plotly "side" value for the provided axis position
732
620
  * @param axisPosition The Iris AxisPosition of the axis
733
621
  */
734
-
735
-
736
622
  static getAxisSide(axisPosition) {
737
623
  switch (axisPosition) {
738
624
  case dh.plot.AxisPosition.BOTTOM:
739
625
  return 'bottom';
740
-
741
626
  case dh.plot.AxisPosition.TOP:
742
627
  return 'top';
743
-
744
628
  case dh.plot.AxisPosition.LEFT:
745
629
  return 'left';
746
-
747
630
  case dh.plot.AxisPosition.RIGHT:
748
631
  return 'right';
749
-
750
632
  default:
751
633
  return undefined;
752
634
  }
753
635
  }
636
+
754
637
  /**
755
638
  * Get all axes for a given `Figure`. Iterates through all charts axes and concatenates them.
756
639
  * @param figure Figure to get all axes for
757
640
  */
758
-
759
-
760
641
  static getAllAxes(figure) {
761
642
  return figure.charts.reduce((axes, chart) => [...axes, ...chart.axes], []);
762
643
  }
644
+
763
645
  /**
764
646
  * Retrieve the chart that contains the passed in series from the figure
765
647
  * @param figure The figure to retrieve the chart from
766
648
  * @param series The series to get the chart for
767
649
  */
768
-
769
-
770
650
  static getChartForSeries(figure, series) {
771
651
  var {
772
652
  charts
773
653
  } = figure;
774
-
775
654
  for (var i = 0; i < charts.length; i += 1) {
776
655
  var _chart2 = charts[i];
777
-
778
656
  for (var j = 0; j < _chart2.series.length; j += 1) {
779
657
  if (series === _chart2.series[j]) {
780
658
  return _chart2;
781
659
  }
782
660
  }
783
661
  }
784
-
785
662
  return null;
786
663
  }
664
+
787
665
  /**
788
666
  * Get an object mapping axis to their ranges
789
667
  * @param layout The plotly layout object to get the ranges from
790
668
  * @returns An object mapping the axis name to it's range
791
669
  */
792
-
793
-
794
670
  static getLayoutRanges(layout) {
795
671
  var ranges = {};
796
672
  var keys = Object.keys(layout).filter(key => key.indexOf('axis') >= 0);
797
-
798
673
  for (var i = 0; i < keys.length; i += 1) {
799
674
  var key = keys[i];
800
675
  var value = layout[key];
801
-
802
676
  if (isRangedPlotlyAxis(value)) {
803
677
  // Only want to add the range if it's not autoranged
804
678
  ranges[key] = [...value.range];
805
679
  }
806
680
  }
807
-
808
681
  return ranges;
809
682
  }
683
+
810
684
  /**
811
685
  * Update the layout with all the axes information for the provided figure
812
686
  * @param figure Figure to update the axes for
@@ -816,28 +690,22 @@ class ChartUtils {
816
690
  * @param plotHeight Height of the plot in pixels
817
691
  * @param theme Theme used for displaying the plot
818
692
  */
819
-
820
-
821
693
  static updateFigureAxes(layoutParam, figure, chartAxisRangeParser) {
822
694
  var plotWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
823
695
  var plotHeight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
824
696
  var theme = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ChartTheme;
825
697
  var layout = layoutParam;
826
698
  var figureAxes = ChartUtils.getAllAxes(figure);
827
-
828
699
  for (var i = 0; i < figure.charts.length; i += 1) {
829
700
  var _chart3 = figure.charts[i];
830
701
  var axisRangeParser = chartAxisRangeParser === null || chartAxisRangeParser === void 0 ? void 0 : chartAxisRangeParser(_chart3);
831
702
  var bounds = ChartUtils.getChartBounds(figure, _chart3, plotWidth, plotHeight);
832
703
  ChartUtils.updateLayoutAxes(layout, _chart3.axes, figureAxes, plotWidth, plotHeight, bounds, axisRangeParser, theme);
833
704
  }
834
-
835
705
  ChartUtils.removeStaleAxes(layout, figureAxes);
836
706
  }
837
-
838
707
  static getChartBounds(figure, chart) {
839
708
  var _axisPositionMap$get;
840
-
841
709
  var plotWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
842
710
  var plotHeight = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
843
711
  var {
@@ -861,12 +729,12 @@ class ChartUtils {
861
729
  bottom: row * rowSize + (row > 0 ? yMarginSize / 2 : 0),
862
730
  top: endRow * rowSize - (endRow < rows ? yMarginSize / 2 : 0),
863
731
  right: endColumn * columnSize - (endColumn < cols ? xMarginSize / 2 : 0)
864
- }; // Adjust the bounds based on where the legend is
865
- // For now, always assume the legend is shown on the right
732
+ };
866
733
 
734
+ // Adjust the bounds based on where the legend is
735
+ // For now, always assume the legend is shown on the right
867
736
  var axisPositionMap = ChartUtils.groupArray(chart.axes, 'position');
868
737
  var rightAxes = (_axisPositionMap$get = axisPositionMap.get(dh.plot.AxisPosition.RIGHT)) !== null && _axisPositionMap$get !== void 0 ? _axisPositionMap$get : [];
869
-
870
738
  if (rightAxes.length > 0) {
871
739
  if (plotWidth > 0) {
872
740
  bounds.right -= (bounds.right - bounds.left) * Math.max(0, Math.min(ChartUtils.LEGEND_WIDTH_PX / plotWidth, ChartUtils.MAX_LEGEND_SIZE));
@@ -874,9 +742,9 @@ class ChartUtils {
874
742
  bounds.right -= (bounds.right - bounds.left) * ChartUtils.DEFAULT_AXIS_SIZE;
875
743
  }
876
744
  }
877
-
878
745
  return bounds;
879
746
  }
747
+
880
748
  /**
881
749
  * Updates the axes positions and sizes in the layout object provided.
882
750
  * If the axis did not exist in the layout previously, it is created and added.
@@ -890,8 +758,6 @@ class ChartUtils {
890
758
  * @param bounds The bounds for this set of axes
891
759
  * @param axisRangeParser A function to retrieve the range parser for a given axis
892
760
  */
893
-
894
-
895
761
  static updateLayoutAxes(layoutParam, chartAxes, figureAxes) {
896
762
  var plotWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
897
763
  var plotHeight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
@@ -910,11 +776,9 @@ class ChartUtils {
910
776
  var axisTypeMap = ChartUtils.groupArray(chartAxes, 'type');
911
777
  var axisTypes = [...axisTypeMap.keys()];
912
778
  var figureAxisTypeMap = ChartUtils.groupArray(figureAxes, 'type');
913
-
914
779
  for (var j = 0; j < axisTypes.length; j += 1) {
915
780
  var axisType = axisTypes[j];
916
781
  var axisProperty = ChartUtils.getAxisPropertyName(axisType);
917
-
918
782
  if (axisProperty != null) {
919
783
  var typeAxes = axisTypeMap.get(axisType);
920
784
  var figureTypeAxes = figureAxisTypeMap.get(axisType);
@@ -922,30 +786,24 @@ class ChartUtils {
922
786
  var plotSize = isYAxis ? plotHeight : plotWidth;
923
787
  assertNotNull(typeAxes);
924
788
  assertNotNull(figureTypeAxes);
925
-
926
789
  for (var chartAxisIndex = 0; chartAxisIndex < typeAxes.length; chartAxisIndex += 1) {
927
790
  var _axis3 = typeAxes[chartAxisIndex];
928
791
  var figureAxisIndex = figureTypeAxes.indexOf(_axis3);
929
792
  var axisLayoutProperty = ChartUtils.getAxisLayoutProperty(axisProperty, figureAxisIndex);
930
-
931
793
  if (layout[axisLayoutProperty] == null) {
932
794
  layout[axisLayoutProperty] = ChartUtils.makeLayoutAxis(axisType, theme);
933
795
  }
934
-
935
796
  var layoutAxis = layout[axisLayoutProperty];
936
-
937
797
  if (layoutAxis != null) {
938
798
  ChartUtils.updateLayoutAxis(layoutAxis, _axis3, chartAxisIndex, axisPositionMap, xAxisSize, yAxisSize, bounds);
939
799
  var {
940
800
  range: _range,
941
801
  autorange
942
802
  } = layoutAxis;
943
-
944
803
  if (axisRangeParser != null && _range !== undefined && (autorange === undefined || autorange === false)) {
945
804
  var rangeParser = axisRangeParser(_axis3);
946
805
  var [rangeStart, rangeEnd] = rangeParser(_range);
947
806
  log.debug('Setting downsample range', plotSize, rangeStart, rangeEnd);
948
-
949
807
  _axis3.range(plotSize, rangeStart, rangeEnd);
950
808
  } else {
951
809
  _axis3.range(plotSize);
@@ -955,29 +813,25 @@ class ChartUtils {
955
813
  }
956
814
  }
957
815
  }
816
+
958
817
  /**
959
818
  * Remove any axes from the layout param that no longer belong to any series
960
819
  * @param layoutParam Layout object to remove stale axes from
961
820
  * @param axes All axes in the figure
962
821
  */
963
-
964
-
965
822
  static removeStaleAxes(layoutParam, axes) {
966
823
  var layout = layoutParam;
967
824
  var figureAxisTypeMap = ChartUtils.groupArray(axes, 'type');
968
825
  var figureAxisTypes = [...figureAxisTypeMap.keys()];
969
-
970
826
  for (var i = 0; i < figureAxisTypes.length; i += 1) {
971
827
  var axisType = figureAxisTypes[i];
972
828
  var typeAxes = figureAxisTypeMap.get(axisType);
973
829
  assertNotNull(typeAxes);
974
- var axisIndex = typeAxes.length; // Delete any axes that may no longer exist
975
-
830
+ var axisIndex = typeAxes.length;
831
+ // Delete any axes that may no longer exist
976
832
  var axisProperty = ChartUtils.getAxisPropertyName(axisType);
977
-
978
833
  if (axisProperty != null) {
979
834
  var axisLayoutProperty = ChartUtils.getAxisLayoutProperty(axisProperty, axisIndex);
980
-
981
835
  while (layout[axisLayoutProperty] != null) {
982
836
  delete layout[axisLayoutProperty];
983
837
  axisIndex += 1;
@@ -986,11 +840,11 @@ class ChartUtils {
986
840
  }
987
841
  }
988
842
  }
989
-
990
843
  static getAxisLayoutProperty(axisProperty, axisIndex) {
991
844
  var axisIndexString = axisIndex > 0 ? "".concat(axisIndex + 1) : '';
992
845
  return "".concat(axisProperty !== null && axisProperty !== void 0 ? axisProperty : '', "axis").concat(axisIndexString);
993
846
  }
847
+
994
848
  /**
995
849
  * Updates the layout axis object in place
996
850
  * @param layoutAxisParam The plotly layout axis param
@@ -1000,18 +854,14 @@ class ChartUtils {
1000
854
  * @param axisSize The size of each axis in percent
1001
855
  * @param bounds The bounds of the axes domains
1002
856
  */
1003
-
1004
-
1005
857
  static updateLayoutAxis(layoutAxisParam, axis, axisIndex, axisPositionMap, xAxisSize, yAxisSize, bounds) {
1006
858
  var _axis$label;
1007
-
1008
859
  var isYAxis = axis.type === dh.plot.AxisType.Y;
1009
860
  var axisSize = isYAxis ? yAxisSize : xAxisSize;
1010
- var layoutAxis = layoutAxisParam; // Enterprise API returns null for empty axis labels
861
+ var layoutAxis = layoutAxisParam;
862
+ // Enterprise API returns null for empty axis labels
1011
863
  // Passing null title text to Plotly results in incorrect axis position, DH-9164
1012
-
1013
864
  var label = (_axis$label = axis.label) !== null && _axis$label !== void 0 ? _axis$label : '';
1014
-
1015
865
  if (layoutAxis.title !== undefined && typeof layoutAxis.title !== 'string') {
1016
866
  layoutAxis.title.text = label;
1017
867
  } else {
@@ -1019,23 +869,17 @@ class ChartUtils {
1019
869
  text: label
1020
870
  };
1021
871
  }
1022
-
1023
872
  if (axis.log) {
1024
873
  layoutAxis.type = 'log';
1025
874
  }
1026
-
1027
875
  layoutAxis.side = ChartUtils.getAxisSide(axis.position);
1028
-
1029
876
  if (axisIndex > 0) {
1030
877
  var _ChartUtils$getAxisPr, _axisPositionMap$get2;
1031
-
1032
878
  layoutAxis.overlaying = (_ChartUtils$getAxisPr = ChartUtils.getAxisPropertyName(axis.type)) !== null && _ChartUtils$getAxisPr !== void 0 ? _ChartUtils$getAxisPr : undefined;
1033
879
  var positionAxes = (_axisPositionMap$get2 = axisPositionMap.get(axis.position)) !== null && _axisPositionMap$get2 !== void 0 ? _axisPositionMap$get2 : [];
1034
880
  var sideIndex = positionAxes.indexOf(axis);
1035
-
1036
881
  if (sideIndex > 0) {
1037
882
  layoutAxis.anchor = 'free';
1038
-
1039
883
  if (axis.position === dh.plot.AxisPosition.RIGHT) {
1040
884
  layoutAxis.position = bounds.right + (sideIndex - positionAxes.length + 1) * axisSize;
1041
885
  } else if (axis.position === dh.plot.AxisPosition.TOP) {
@@ -1060,17 +904,17 @@ class ChartUtils {
1060
904
  layoutAxis.domain = [bottom, top];
1061
905
  }
1062
906
  }
907
+
1063
908
  /**
1064
909
  * Converts an open or close period to a declimal. e.g '09:30" to 9.5
1065
910
  *
1066
911
  * @param period the open or close value of the period
1067
912
  */
1068
-
1069
-
1070
913
  static periodToDecimal(period) {
1071
914
  var values = period.split(':');
1072
915
  return Number(values[0]) + Number(values[1]) / 60;
1073
916
  }
917
+
1074
918
  /**
1075
919
  * Creates range break bounds for plotly from business days.
1076
920
  * For example a standard business week of ['MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY']
@@ -1079,29 +923,25 @@ class ChartUtils {
1079
923
  *
1080
924
  * @param businessDays the days to display on the x-axis
1081
925
  */
1082
-
1083
-
1084
926
  static createBoundsFromDays(businessDays) {
1085
927
  var businessDaysInt = businessDays.map(day => DAYS.indexOf(day));
1086
- var nonBusinessDaysInt = DAYS.filter(day => !businessDays.includes(day)).map(day => DAYS.indexOf(day)); // These are the days when business reopens (e.g. Monday after a weekend)
1087
-
928
+ var nonBusinessDaysInt = DAYS.filter(day => !businessDays.includes(day)).map(day => DAYS.indexOf(day));
929
+ // These are the days when business reopens (e.g. Monday after a weekend)
1088
930
  var reopenDays = new Set();
1089
931
  nonBusinessDaysInt.forEach(closed => {
1090
932
  for (var i = closed + 1; i < closed + DAYS.length; i += 1) {
1091
933
  var adjustedDay = i % DAYS.length;
1092
-
1093
934
  if (businessDaysInt.includes(adjustedDay)) {
1094
935
  reopenDays.add(adjustedDay);
1095
936
  break;
1096
937
  }
1097
938
  }
1098
939
  });
1099
- var boundsArray = []; // For each reopen day, find the furthest previous closed day
1100
-
940
+ var boundsArray = [];
941
+ // For each reopen day, find the furthest previous closed day
1101
942
  reopenDays.forEach(open => {
1102
943
  for (var i = open - 1; i > open - DAYS.length; i -= 1) {
1103
944
  var adjustedDay = i < 0 ? i + DAYS.length : i;
1104
-
1105
945
  if (businessDaysInt.includes(adjustedDay)) {
1106
946
  var closedDay = (adjustedDay + 1) % 7;
1107
947
  boundsArray.push([closedDay, open]);
@@ -1111,6 +951,7 @@ class ChartUtils {
1111
951
  });
1112
952
  return boundsArray;
1113
953
  }
954
+
1114
955
  /**
1115
956
  * Creates an array of range breaks for all holidays.
1116
957
  *
@@ -1118,8 +959,6 @@ class ChartUtils {
1118
959
  * @param calendarTimeZone the time zone for the business calendar
1119
960
  * @param formatterTimeZone the time zone for the formatter
1120
961
  */
1121
-
1122
-
1123
962
  static createRangeBreakValuesFromHolidays(holidays, calendarTimeZone, formatterTimeZone) {
1124
963
  var fullHolidays = [];
1125
964
  var partialHolidays = [];
@@ -1134,6 +973,7 @@ class ChartUtils {
1134
973
  values: fullHolidays
1135
974
  }, ...partialHolidays];
1136
975
  }
976
+
1137
977
  /**
1138
978
  * Creates the range break value for a full holiday. A full holiday is day that has no business periods.
1139
979
  *
@@ -1141,11 +981,10 @@ class ChartUtils {
1141
981
  * @param calendarTimeZone the time zone for the business calendar
1142
982
  * @param formatterTimeZone the time zone for the formatter
1143
983
  */
1144
-
1145
-
1146
984
  static createFullHoliday(holiday, calendarTimeZone, formatterTimeZone) {
1147
985
  return ChartUtils.adjustDateForTimeZone("".concat(holiday.date.toString(), " 00:00:00.000000"), calendarTimeZone, formatterTimeZone);
1148
986
  }
987
+
1149
988
  /**
1150
989
  * Creates the range break for a partial holiday. A partial holiday is holiday with business periods
1151
990
  * that are different than the default business periods.
@@ -1154,8 +993,6 @@ class ChartUtils {
1154
993
  * @param calendarTimeZone the time zone for the business calendar
1155
994
  * @param formatterTimeZone the time zone for the formatter
1156
995
  */
1157
-
1158
-
1159
996
  static createPartialHoliday(holiday, calendarTimeZone, formatterTimeZone) {
1160
997
  // If a holiday has business periods {open1, close1} and {open2, close2}
1161
998
  // This will generate range breaks for:
@@ -1167,15 +1004,14 @@ class ChartUtils {
1167
1004
  holiday.businessPeriods.forEach(period => {
1168
1005
  closedPeriods.push(period.open);
1169
1006
  closedPeriods.push(period.close);
1170
- }); // To go up to 23:59:59.999999, we calculate the dvalue using 24 - close
1171
-
1007
+ });
1008
+ // To go up to 23:59:59.999999, we calculate the dvalue using 24 - close
1172
1009
  closedPeriods.push('24:00');
1173
1010
  var rangeBreaks = [];
1174
-
1175
1011
  for (var i = 0; i < closedPeriods.length; i += 2) {
1176
1012
  var startClose = closedPeriods[i];
1177
- var endClose = closedPeriods[i + 1]; // Skip over any periods where start and close are the same (zero hours)
1178
-
1013
+ var endClose = closedPeriods[i + 1];
1014
+ // Skip over any periods where start and close are the same (zero hours)
1179
1015
  if (startClose !== endClose) {
1180
1016
  var values = [ChartUtils.adjustDateForTimeZone("".concat(dateString, " ").concat(startClose, ":00.000000"), calendarTimeZone, formatterTimeZone)];
1181
1017
  var dvalue = MILLIS_PER_HOUR * (ChartUtils.periodToDecimal(endClose) - ChartUtils.periodToDecimal(startClose));
@@ -1185,9 +1021,9 @@ class ChartUtils {
1185
1021
  });
1186
1022
  }
1187
1023
  }
1188
-
1189
1024
  return rangeBreaks;
1190
1025
  }
1026
+
1191
1027
  /**
1192
1028
  * Adjusts a date string from the calendar time zone to the formatter time zone.
1193
1029
  *
@@ -1195,27 +1031,22 @@ class ChartUtils {
1195
1031
  * @param calendarTimeZone the time zone for the business calendar
1196
1032
  * @param formatterTimeZone the time zone for the formatter
1197
1033
  */
1198
-
1199
-
1200
1034
  static adjustDateForTimeZone(dateString, calendarTimeZone, formatterTimeZone) {
1201
1035
  if (formatterTimeZone && formatterTimeZone.standardOffset !== calendarTimeZone.standardOffset) {
1202
1036
  return ChartUtils.unwrapValue(ChartUtils.wrapValue(dateString, BUSINESS_COLUMN_TYPE, calendarTimeZone), formatterTimeZone);
1203
1037
  }
1204
-
1205
1038
  return dateString;
1206
1039
  }
1040
+
1207
1041
  /**
1208
1042
  * Groups an array and returns a map
1209
1043
  * @param array The object to group
1210
1044
  * @param property The property name to group by
1211
1045
  * @returns A map containing the items grouped by their values for the property
1212
1046
  */
1213
-
1214
-
1215
1047
  static groupArray(array, property) {
1216
1048
  return array.reduce((result, item) => {
1217
1049
  var _result$get;
1218
-
1219
1050
  var key = item[property];
1220
1051
  var group = (_result$get = result.get(key)) !== null && _result$get !== void 0 ? _result$get : [];
1221
1052
  group.push(item);
@@ -1223,61 +1054,53 @@ class ChartUtils {
1223
1054
  return result;
1224
1055
  }, new Map());
1225
1056
  }
1057
+
1226
1058
  /**
1227
1059
  * Unwraps a value provided from API to a value plotly can understand
1228
1060
  * Eg. Unwraps DateWrapper, LongWrapper objects.
1229
1061
  */
1230
-
1231
-
1232
1062
  static unwrapValue(value, timeZone) {
1233
1063
  if (value != null) {
1234
1064
  if (isDateWrapper(value)) {
1235
1065
  return dh.i18n.DateTimeFormat.format(ChartUtils.DATE_FORMAT, value, timeZone);
1236
1066
  }
1237
-
1238
1067
  if (isLongWrapper(value)) {
1239
1068
  return value.asNumber();
1240
1069
  }
1241
1070
  }
1242
-
1243
1071
  return value;
1244
1072
  }
1073
+
1245
1074
  /**
1246
1075
  *
1247
1076
  * @param value The value to wrap up
1248
1077
  * @param columnType The type of column this value is from
1249
1078
  * @param timeZone The time zone if applicable
1250
1079
  */
1251
-
1252
-
1253
1080
  static wrapValue(value, columnType) {
1254
1081
  var timeZone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
1255
-
1256
1082
  if (TableUtils.isDateType(columnType) && typeof value === 'string') {
1257
1083
  // Need to limit the format to the actual length of the string range set in plotly
1258
1084
  // Otherwise parse will fail
1259
1085
  var text = value;
1260
1086
  var format = ChartUtils.DATE_FORMAT.substr(0, value.length);
1261
1087
  var date = dh.i18n.DateTimeFormat.parse(format, text);
1262
-
1263
1088
  if (!timeZone) {
1264
1089
  return date;
1265
- } // IDS-5994 Due to date parsing, time zone, and daylight savings shenanigans, we need
1090
+ }
1091
+
1092
+ // IDS-5994 Due to date parsing, time zone, and daylight savings shenanigans, we need
1266
1093
  // to pass the actual offset with the time to have it parse correctly.
1267
1094
  // However, the offset can change based on the date because of Daylight Savings
1268
1095
  // So we end up parsing the date multiple times. And curse daylight savings.
1269
-
1270
-
1271
1096
  var tzFormat = "".concat(format, " Z");
1272
1097
  var estimatedOffset = dh.i18n.DateTimeFormat.format('Z', date, timeZone);
1273
1098
  var estimatedDate = dh.i18n.DateTimeFormat.parse(tzFormat, "".concat(text, " ").concat(estimatedOffset));
1274
1099
  var offset = dh.i18n.DateTimeFormat.format('Z', estimatedDate, timeZone);
1275
1100
  return dh.i18n.DateTimeFormat.parse(tzFormat, "".concat(text, " ").concat(offset));
1276
1101
  }
1277
-
1278
1102
  return value;
1279
1103
  }
1280
-
1281
1104
  static makeLayoutAxis(type) {
1282
1105
  var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ChartTheme;
1283
1106
  var axis = {
@@ -1301,7 +1124,6 @@ class ChartUtils {
1301
1124
  }
1302
1125
  }
1303
1126
  };
1304
-
1305
1127
  if (type === dh.plot.AxisType.X) {
1306
1128
  Object.assign(axis, {
1307
1129
  showgrid: true
@@ -1312,21 +1134,18 @@ class ChartUtils {
1312
1134
  zerolinewidth: 2
1313
1135
  });
1314
1136
  }
1315
-
1316
1137
  return axis;
1317
1138
  }
1139
+
1318
1140
  /**
1319
1141
  * Parses the colorway property of a theme and returns an array of colors
1320
1142
  * Theme could have a single string with space separated colors or an array of strings representing the colorway
1321
1143
  * @param theme The theme to get colorway from
1322
1144
  * @returns Colorway array for the theme
1323
1145
  */
1324
-
1325
-
1326
1146
  static getColorwayFromTheme() {
1327
1147
  var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ChartTheme;
1328
1148
  var colorway = [];
1329
-
1330
1149
  if (theme.colorway) {
1331
1150
  if (Array.isArray(theme.colorway)) {
1332
1151
  colorway = theme.colorway;
@@ -1336,13 +1155,10 @@ class ChartUtils {
1336
1155
  log.warn("Unable to handle colorway property: ".concat(theme.colorway));
1337
1156
  }
1338
1157
  }
1339
-
1340
1158
  return colorway;
1341
1159
  }
1342
-
1343
1160
  static makeDefaultLayout() {
1344
1161
  var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ChartTheme;
1345
-
1346
1162
  var layout = _objectSpread(_objectSpread({}, theme), {}, {
1347
1163
  autosize: true,
1348
1164
  colorway: ChartUtils.getColorwayFromTheme(theme),
@@ -1366,22 +1182,19 @@ class ChartUtils {
1366
1182
  xaxis: ChartUtils.makeLayoutAxis(dh.plot.AxisType.X, theme),
1367
1183
  yaxis: ChartUtils.makeLayoutAxis(dh.plot.AxisType.Y, theme)
1368
1184
  });
1369
-
1370
1185
  layout.datarevision = 0;
1371
1186
  return layout;
1372
1187
  }
1188
+
1373
1189
  /**
1374
1190
  * Hydrate settings from a JSONable object
1375
1191
  * @param settings Dehydrated settings
1376
1192
  */
1377
-
1378
-
1379
1193
  static hydrateSettings(settings) {
1380
1194
  return _objectSpread(_objectSpread({}, settings), {}, {
1381
1195
  type: dh.plot.SeriesPlotStyle[settings.type]
1382
1196
  });
1383
1197
  }
1384
-
1385
1198
  static titleFromSettings(settings) {
1386
1199
  var {
1387
1200
  series,
@@ -1390,6 +1203,7 @@ class ChartUtils {
1390
1203
  } = settings;
1391
1204
  return title;
1392
1205
  }
1206
+
1393
1207
  /**
1394
1208
  * Creates the Figure settings from the Chart Builder settings
1395
1209
  * This should be deprecated at some point, and have Chart Builder create the figure settings directly.
@@ -1402,8 +1216,6 @@ class ChartUtils {
1402
1216
  * @param settings.series The name of the columns to use for the series of this figure
1403
1217
  * @param settings.type The plot style for this figure
1404
1218
  */
1405
-
1406
-
1407
1219
  static makeFigureSettings(settings, table) {
1408
1220
  var {
1409
1221
  series,
@@ -1444,28 +1256,18 @@ class ChartUtils {
1444
1256
  title
1445
1257
  };
1446
1258
  }
1447
-
1448
1259
  }
1449
-
1450
1260
  _defineProperty(ChartUtils, "DEFAULT_AXIS_SIZE", 0.15);
1451
-
1452
1261
  _defineProperty(ChartUtils, "MIN_AXIS_SIZE", 0.025);
1453
-
1454
1262
  _defineProperty(ChartUtils, "MAX_AXIS_SIZE", 0.2);
1455
-
1456
1263
  _defineProperty(ChartUtils, "AXIS_SIZE_PX", 75);
1457
-
1458
1264
  _defineProperty(ChartUtils, "LEGEND_WIDTH_PX", 50);
1459
-
1460
1265
  _defineProperty(ChartUtils, "MAX_LEGEND_SIZE", 0.25);
1461
-
1462
1266
  _defineProperty(ChartUtils, "ORIENTATION", Object.freeze({
1463
1267
  HORIZONTAL: 'h',
1464
1268
  VERTICAL: 'v'
1465
1269
  }));
1466
-
1467
1270
  _defineProperty(ChartUtils, "DATE_FORMAT", 'yyyy-MM-dd HH:mm:ss.SSSSSS');
1468
-
1469
1271
  _defineProperty(ChartUtils, "DEFAULT_MARGIN", Object.freeze({
1470
1272
  l: 60,
1471
1273
  r: 50,
@@ -1473,12 +1275,9 @@ _defineProperty(ChartUtils, "DEFAULT_MARGIN", Object.freeze({
1473
1275
  b: 60,
1474
1276
  pad: 0
1475
1277
  }));
1476
-
1477
1278
  _defineProperty(ChartUtils, "DEFAULT_TITLE_PADDING", Object.freeze({
1478
1279
  t: 8
1479
1280
  }));
1480
-
1481
1281
  _defineProperty(ChartUtils, "SUBTITLE_LINE_HEIGHT", 25);
1482
-
1483
1282
  export default ChartUtils;
1484
1283
  //# sourceMappingURL=ChartUtils.js.map