@deephaven/chart 0.15.5 → 0.15.6-beta.5
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.d.ts +5 -12
- package/dist/Chart.d.ts.map +1 -1
- package/dist/Chart.js +7 -3
- package/dist/Chart.js.map +1 -1
- package/dist/ChartModel.d.ts +12 -11
- package/dist/ChartModel.d.ts.map +1 -1
- package/dist/ChartModel.js +3 -3
- package/dist/ChartModel.js.map +1 -1
- package/dist/ChartModelFactory.d.ts +2 -7
- package/dist/ChartModelFactory.d.ts.map +1 -1
- package/dist/ChartModelFactory.js.map +1 -1
- package/dist/ChartTestUtils.d.ts +16 -15
- package/dist/ChartTestUtils.d.ts.map +1 -1
- package/dist/ChartTestUtils.js +5 -0
- package/dist/ChartTestUtils.js.map +1 -1
- package/dist/ChartUtils.d.ts +252 -225
- package/dist/ChartUtils.d.ts.map +1 -1
- package/dist/ChartUtils.js +216 -174
- package/dist/ChartUtils.js.map +1 -1
- package/dist/FigureChartModel.d.ts +70 -106
- package/dist/FigureChartModel.d.ts.map +1 -1
- package/dist/FigureChartModel.js +90 -36
- package/dist/FigureChartModel.js.map +1 -1
- package/dist/MockChartModel.d.ts +3 -201
- package/dist/MockChartModel.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -11
package/dist/ChartUtils.js
CHANGED
|
@@ -8,17 +8,35 @@ import Log from '@deephaven/log';
|
|
|
8
8
|
import { TableUtils } from '@deephaven/jsapi-utils';
|
|
9
9
|
import dh from '@deephaven/jsapi-shim';
|
|
10
10
|
import set from 'lodash.set';
|
|
11
|
+
import { assertNotNull } from '@deephaven/utils';
|
|
12
|
+
import ChartTheme from "./ChartTheme.js";
|
|
11
13
|
var log = Log.module('ChartUtils');
|
|
12
14
|
var DAYS = Object.freeze(dh.calendar.DayOfWeek.values());
|
|
13
15
|
var BUSINESS_COLUMN_TYPE = 'io.deephaven.time.DateTime';
|
|
14
16
|
var MILLIS_PER_HOUR = 3600000;
|
|
15
17
|
var NANOS_PER_MILLI = 1000000;
|
|
16
18
|
|
|
19
|
+
function isDateWrapper(value) {
|
|
20
|
+
return value.asDate !== undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isLongWrapper(value) {
|
|
24
|
+
return value.asNumber !== undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isDateTimeColumnFormatter(value) {
|
|
28
|
+
return value.dhTimeZone !== undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isRangedPlotlyAxis(value) {
|
|
32
|
+
return value != null && value.range && !value.autorange;
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
class ChartUtils {
|
|
18
36
|
/**
|
|
19
37
|
* Converts the Iris plot style into a plotly chart type
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
38
|
+
* @param plotStyle The plotStyle to use, see dh.plot.SeriesPlotStyle
|
|
39
|
+
* @param isBusinessTime If the plot is using business time for an axis
|
|
22
40
|
*/
|
|
23
41
|
static getPlotlyChartType(plotStyle, isBusinessTime) {
|
|
24
42
|
switch (plotStyle) {
|
|
@@ -49,12 +67,12 @@ class ChartUtils {
|
|
|
49
67
|
return 'ohlc';
|
|
50
68
|
|
|
51
69
|
default:
|
|
52
|
-
return
|
|
70
|
+
return undefined;
|
|
53
71
|
}
|
|
54
72
|
}
|
|
55
73
|
/**
|
|
56
74
|
* Converts the Iris plot style into a plotly chart mode
|
|
57
|
-
* @param
|
|
75
|
+
* @param plotStyle The plotStyle to use, see dh.plot.SeriesPlotStyle.*
|
|
58
76
|
*/
|
|
59
77
|
|
|
60
78
|
|
|
@@ -67,13 +85,13 @@ class ChartUtils {
|
|
|
67
85
|
return 'lines';
|
|
68
86
|
|
|
69
87
|
default:
|
|
70
|
-
return
|
|
88
|
+
return undefined;
|
|
71
89
|
}
|
|
72
90
|
}
|
|
73
91
|
/**
|
|
74
92
|
* Get the property to set on the series data for plotly
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
93
|
+
* @param plotStyle The plot style of the series
|
|
94
|
+
* @param sourceType The source type for the series
|
|
77
95
|
*/
|
|
78
96
|
|
|
79
97
|
|
|
@@ -210,11 +228,11 @@ class ChartUtils {
|
|
|
210
228
|
/**
|
|
211
229
|
* Generate the plotly error bar data from the passed in data.
|
|
212
230
|
* Iris passes in the values as absolute, plotly needs them as relative.
|
|
213
|
-
* @param
|
|
214
|
-
* @param
|
|
215
|
-
* @param
|
|
231
|
+
* @param x The main data array
|
|
232
|
+
* @param xLow The absolute low values
|
|
233
|
+
* @param xHigh
|
|
216
234
|
*
|
|
217
|
-
* @returns
|
|
235
|
+
* @returns The error_x object required by plotly, or null if none is required
|
|
218
236
|
*/
|
|
219
237
|
|
|
220
238
|
|
|
@@ -230,12 +248,12 @@ class ChartUtils {
|
|
|
230
248
|
}
|
|
231
249
|
|
|
232
250
|
static getPlotlyDateFormat(formatter, columnType, formatPattern) {
|
|
233
|
-
var tickformat = formatPattern == null ?
|
|
251
|
+
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
|
|
234
252
|
|
|
235
|
-
var ticksuffix
|
|
236
|
-
var dataFormatter = formatter.getColumnTypeFormatter(columnType);
|
|
253
|
+
var ticksuffix;
|
|
254
|
+
var dataFormatter = formatter === null || formatter === void 0 ? void 0 : formatter.getColumnTypeFormatter(columnType);
|
|
237
255
|
|
|
238
|
-
if (dataFormatter.dhTimeZone != null && dataFormatter.showTimeZone) {
|
|
256
|
+
if (dataFormatter != null && isDateTimeColumnFormatter(dataFormatter) && dataFormatter.dhTimeZone != null && dataFormatter.showTimeZone) {
|
|
239
257
|
ticksuffix = dh.i18n.DateTimeFormat.format(' z', new Date(), dataFormatter.dhTimeZone);
|
|
240
258
|
}
|
|
241
259
|
|
|
@@ -260,7 +278,9 @@ class ChartUtils {
|
|
|
260
278
|
|
|
261
279
|
|
|
262
280
|
var subpatterns = formatPattern.split(';');
|
|
263
|
-
var
|
|
281
|
+
var matchArray = subpatterns[0].match(/^([^#,0.]*)([#,]*)([0,]*)(\.?)(0*)(#*)(E?0*)(%?)(.*)/);
|
|
282
|
+
assertNotNull(matchArray);
|
|
283
|
+
var [, prefix, placeholderDigits, zeroDigits,, decimalDigits, optionalDecimalDigits, numberType, percentSign, suffix] = matchArray;
|
|
264
284
|
var paddingLength = zeroDigits.replace(',', '').length;
|
|
265
285
|
var isCommaSeparated = placeholderDigits.indexOf(',') >= 0 || zeroDigits.indexOf(',') >= 0;
|
|
266
286
|
var comma = isCommaSeparated ? ',' : '';
|
|
@@ -284,8 +304,8 @@ class ChartUtils {
|
|
|
284
304
|
}
|
|
285
305
|
/**
|
|
286
306
|
* Gets the plotly axis formatting information from the source passed in
|
|
287
|
-
* @param
|
|
288
|
-
* @param
|
|
307
|
+
* @param source The Source to get the formatter information from
|
|
308
|
+
* @param formatter The current formatter for formatting data
|
|
289
309
|
*/
|
|
290
310
|
|
|
291
311
|
|
|
@@ -314,8 +334,8 @@ class ChartUtils {
|
|
|
314
334
|
} else {
|
|
315
335
|
axisFormat = {
|
|
316
336
|
type: 'category',
|
|
317
|
-
tickformat:
|
|
318
|
-
ticksuffix:
|
|
337
|
+
tickformat: undefined,
|
|
338
|
+
ticksuffix: undefined
|
|
319
339
|
};
|
|
320
340
|
}
|
|
321
341
|
}
|
|
@@ -325,9 +345,9 @@ class ChartUtils {
|
|
|
325
345
|
/**
|
|
326
346
|
* Adds tick spacing for an axis that has gapBetweenMajorTicks defined.
|
|
327
347
|
*
|
|
328
|
-
* @param
|
|
329
|
-
* @param
|
|
330
|
-
* @param
|
|
348
|
+
* @param axisFormat the current axis format, may be null
|
|
349
|
+
* @param axis the current axis
|
|
350
|
+
* @param isDateType indicates if the columns is a date type
|
|
331
351
|
*/
|
|
332
352
|
|
|
333
353
|
|
|
@@ -359,9 +379,9 @@ class ChartUtils {
|
|
|
359
379
|
}
|
|
360
380
|
/**
|
|
361
381
|
* Retrieve the data source for a given axis in a chart
|
|
362
|
-
* @param
|
|
363
|
-
* @param
|
|
364
|
-
* @returns
|
|
382
|
+
* @param chart The chart to get the source for
|
|
383
|
+
* @param axis The axis to find the source for
|
|
384
|
+
* @returns The first source matching this axis
|
|
365
385
|
*/
|
|
366
386
|
|
|
367
387
|
|
|
@@ -382,9 +402,9 @@ class ChartUtils {
|
|
|
382
402
|
}
|
|
383
403
|
/**
|
|
384
404
|
* Get visibility setting for the series object
|
|
385
|
-
* @param
|
|
386
|
-
* @param
|
|
387
|
-
* @returns
|
|
405
|
+
* @param name The series name to get the visibility for
|
|
406
|
+
* @param settings Chart settings
|
|
407
|
+
* @returns True for visible series and 'legendonly' for hidden
|
|
388
408
|
*/
|
|
389
409
|
|
|
390
410
|
|
|
@@ -399,8 +419,8 @@ class ChartUtils {
|
|
|
399
419
|
}
|
|
400
420
|
/**
|
|
401
421
|
* Get hidden labels array from chart settings
|
|
402
|
-
* @param
|
|
403
|
-
* @returns
|
|
422
|
+
* @param settings Chart settings
|
|
423
|
+
* @returns Array of hidden series names
|
|
404
424
|
*/
|
|
405
425
|
|
|
406
426
|
|
|
@@ -413,7 +433,7 @@ class ChartUtils {
|
|
|
413
433
|
}
|
|
414
434
|
/**
|
|
415
435
|
* Create a default series data object. Apply styling to the object afterward.
|
|
416
|
-
* @returns
|
|
436
|
+
* @returns A simple series data object with no styling
|
|
417
437
|
*/
|
|
418
438
|
|
|
419
439
|
|
|
@@ -428,15 +448,16 @@ class ChartUtils {
|
|
|
428
448
|
}
|
|
429
449
|
/**
|
|
430
450
|
* Create a data series (trace) for use with plotly
|
|
431
|
-
* @param
|
|
432
|
-
* @param
|
|
433
|
-
* @param
|
|
434
|
-
* @param
|
|
435
|
-
* @returns
|
|
451
|
+
* @param series The series to create the series data with
|
|
452
|
+
* @param axisTypeMap The map of axes grouped by type
|
|
453
|
+
* @param seriesVisibility Visibility setting for the series
|
|
454
|
+
* @param theme The theme properties for the plot. See ChartTheme.js for an example
|
|
455
|
+
* @returns The series data (trace) object for use with plotly.
|
|
436
456
|
*/
|
|
437
457
|
|
|
438
458
|
|
|
439
|
-
static makeSeriesDataFromSeries(series, axisTypeMap, seriesVisibility
|
|
459
|
+
static makeSeriesDataFromSeries(series, axisTypeMap, seriesVisibility) {
|
|
460
|
+
var theme = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ChartTheme;
|
|
440
461
|
var {
|
|
441
462
|
name,
|
|
442
463
|
plotStyle,
|
|
@@ -464,24 +485,27 @@ class ChartUtils {
|
|
|
464
485
|
for (var k = 0; k < sources.length; k += 1) {
|
|
465
486
|
var source = sources[k];
|
|
466
487
|
var {
|
|
467
|
-
axis,
|
|
488
|
+
axis: _axis,
|
|
468
489
|
type: sourceType
|
|
469
490
|
} = source;
|
|
470
491
|
var dataAttributeName = ChartUtils.getPlotlyProperty(plotStyle, sourceType);
|
|
471
492
|
set(seriesData, dataAttributeName, []);
|
|
472
|
-
var axisProperty =
|
|
493
|
+
var axisProperty = _axis ? ChartUtils.getAxisPropertyName(_axis.type) : null;
|
|
473
494
|
|
|
474
495
|
if (axisProperty != null) {
|
|
475
|
-
var axes = axisTypeMap.get(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
496
|
+
var axes = axisTypeMap.get(_axis.type);
|
|
497
|
+
|
|
498
|
+
if (axes) {
|
|
499
|
+
var axisIndex = axes.indexOf(_axis);
|
|
500
|
+
var axisIndexString = axisIndex > 0 ? "".concat(axisIndex + 1) : '';
|
|
501
|
+
seriesData["".concat(axisProperty, "axis")] = "".concat(axisProperty).concat(axisIndexString);
|
|
502
|
+
}
|
|
479
503
|
}
|
|
480
504
|
}
|
|
481
505
|
}
|
|
482
506
|
|
|
483
507
|
static addStylingToSeriesData(seriesDataParam, plotStyle) {
|
|
484
|
-
var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] :
|
|
508
|
+
var theme = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ChartTheme;
|
|
485
509
|
var lineColor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
486
510
|
var shapeColor = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
487
511
|
var seriesVisibility = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
|
|
@@ -522,7 +546,10 @@ class ChartUtils {
|
|
|
522
546
|
}
|
|
523
547
|
};
|
|
524
548
|
} else if (plotStyle === dh.plot.SeriesPlotStyle.PIE) {
|
|
525
|
-
seriesData.textinfo = 'label+percent';
|
|
549
|
+
seriesData.textinfo = 'label+percent'; // TODO Open DefinitelyTyped/Plotly PR to mark family and size as optional
|
|
550
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/plotly.js/lib/traces/pie.d.ts#L6
|
|
551
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
552
|
+
|
|
526
553
|
seriesData.outsidetextfont = {
|
|
527
554
|
color: theme.title_color
|
|
528
555
|
};
|
|
@@ -533,7 +560,8 @@ class ChartUtils {
|
|
|
533
560
|
packing: 'squarify',
|
|
534
561
|
pad: 0
|
|
535
562
|
};
|
|
536
|
-
seriesData.textposition = 'middle center';
|
|
563
|
+
seriesData.textposition = 'middle center'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
564
|
+
|
|
537
565
|
seriesData.outsidetextfont = {
|
|
538
566
|
color: theme.title_color
|
|
539
567
|
};
|
|
@@ -560,9 +588,9 @@ class ChartUtils {
|
|
|
560
588
|
/**
|
|
561
589
|
* Retrieve the axis formats from the provided figure.
|
|
562
590
|
* Currently defaults to just the x/y axes.
|
|
563
|
-
* @param
|
|
564
|
-
* @param
|
|
565
|
-
* @returns
|
|
591
|
+
* @param figure The figure to get the axis formats for
|
|
592
|
+
* @param formatter The formatter to use when getting the axis format
|
|
593
|
+
* @returns A map of axis layout property names to axis formats
|
|
566
594
|
*/
|
|
567
595
|
|
|
568
596
|
|
|
@@ -590,20 +618,22 @@ class ChartUtils {
|
|
|
590
618
|
for (var k = 0; k < axisSources.length; k += 1) {
|
|
591
619
|
var source = axisSources[k];
|
|
592
620
|
var {
|
|
593
|
-
axis
|
|
621
|
+
axis: _axis2
|
|
594
622
|
} = source;
|
|
595
623
|
var {
|
|
596
624
|
type: axisType
|
|
597
|
-
} =
|
|
625
|
+
} = _axis2;
|
|
598
626
|
var typeAxes = axisTypeMap.get(axisType);
|
|
599
|
-
|
|
627
|
+
assertNotNull(typeAxes);
|
|
628
|
+
var axisIndex = typeAxes.indexOf(_axis2);
|
|
600
629
|
var axisProperty = ChartUtils.getAxisPropertyName(axisType);
|
|
601
|
-
var axisLayoutProperty = ChartUtils.getAxisLayoutProperty(axisProperty, axisIndex);
|
|
602
630
|
|
|
603
|
-
if (
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
631
|
+
if (axisProperty != null) {
|
|
632
|
+
var axisLayoutProperty = ChartUtils.getAxisLayoutProperty(axisProperty, axisIndex);
|
|
633
|
+
|
|
634
|
+
if (axisFormats.has(axisLayoutProperty)) {
|
|
635
|
+
log.debug("".concat(axisLayoutProperty, " already added."));
|
|
636
|
+
} else {
|
|
607
637
|
log.debug("Adding ".concat(axisLayoutProperty, " to axisFormats."));
|
|
608
638
|
var axisFormat = ChartUtils.getPlotlyAxisFormat(source, formatter);
|
|
609
639
|
|
|
@@ -613,47 +643,51 @@ class ChartUtils {
|
|
|
613
643
|
axisFormats.set(axisLayoutProperty, axisFormat);
|
|
614
644
|
var {
|
|
615
645
|
businessCalendar
|
|
616
|
-
} =
|
|
646
|
+
} = _axis2;
|
|
617
647
|
|
|
618
648
|
if (businessCalendar) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
649
|
+
(function () {
|
|
650
|
+
var rangebreaks = [];
|
|
651
|
+
var {
|
|
652
|
+
businessPeriods,
|
|
653
|
+
businessDays,
|
|
654
|
+
holidays,
|
|
655
|
+
timeZone: calendarTimeZone
|
|
656
|
+
} = businessCalendar;
|
|
657
|
+
var typeFormatter = formatter === null || formatter === void 0 ? void 0 : formatter.getColumnTypeFormatter(BUSINESS_COLUMN_TYPE);
|
|
658
|
+
var formatterTimeZone = void 0;
|
|
659
|
+
|
|
660
|
+
if (isDateTimeColumnFormatter(typeFormatter)) {
|
|
661
|
+
formatterTimeZone = typeFormatter.dhTimeZone;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
var timeZoneDiff = formatterTimeZone ? (calendarTimeZone.standardOffset - formatterTimeZone.standardOffset) / 60 : 0;
|
|
665
|
+
|
|
666
|
+
if (holidays.length > 0) {
|
|
667
|
+
rangebreaks.push(...ChartUtils.createRangeBreakValuesFromHolidays(holidays, calendarTimeZone, formatterTimeZone));
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
businessPeriods.forEach(period => rangebreaks.push({
|
|
671
|
+
pattern: 'hour',
|
|
672
|
+
bounds: [ChartUtils.periodToDecimal(period.close) + timeZoneDiff, ChartUtils.periodToDecimal(period.open) + timeZoneDiff]
|
|
673
|
+
})); // If there are seven business days, then there is no weekend
|
|
674
|
+
|
|
675
|
+
if (businessDays.length < DAYS.length) {
|
|
676
|
+
ChartUtils.createBoundsFromDays(businessDays).forEach(weekendBounds => rangebreaks.push({
|
|
677
|
+
pattern: 'day of week',
|
|
678
|
+
bounds: weekendBounds
|
|
679
|
+
}));
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
axisFormat.rangebreaks = rangebreaks;
|
|
683
|
+
})();
|
|
646
684
|
}
|
|
647
685
|
|
|
648
686
|
if (axisFormats.size === chart.axes.length) {
|
|
649
|
-
return
|
|
650
|
-
v: axisFormats
|
|
651
|
-
};
|
|
687
|
+
return axisFormats;
|
|
652
688
|
}
|
|
653
689
|
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
if (typeof _ret === "object") return _ret.v;
|
|
690
|
+
}
|
|
657
691
|
}
|
|
658
692
|
}
|
|
659
693
|
}
|
|
@@ -675,7 +709,7 @@ class ChartUtils {
|
|
|
675
709
|
}
|
|
676
710
|
/**
|
|
677
711
|
* Return the plotly axis property name
|
|
678
|
-
* @param
|
|
712
|
+
* @param axisType The axis type to get the property name for
|
|
679
713
|
*/
|
|
680
714
|
|
|
681
715
|
|
|
@@ -693,7 +727,7 @@ class ChartUtils {
|
|
|
693
727
|
}
|
|
694
728
|
/**
|
|
695
729
|
* Returns the plotly "side" value for the provided axis position
|
|
696
|
-
* @param
|
|
730
|
+
* @param axisPosition The Iris AxisPosition of the axis
|
|
697
731
|
*/
|
|
698
732
|
|
|
699
733
|
|
|
@@ -712,13 +746,13 @@ class ChartUtils {
|
|
|
712
746
|
return 'right';
|
|
713
747
|
|
|
714
748
|
default:
|
|
715
|
-
return
|
|
749
|
+
return undefined;
|
|
716
750
|
}
|
|
717
751
|
}
|
|
718
752
|
/**
|
|
719
753
|
* Retrieve the chart that contains the passed in series from the figure
|
|
720
|
-
* @param
|
|
721
|
-
* @param
|
|
754
|
+
* @param figure The figure to retrieve the chart from
|
|
755
|
+
* @param series The series to get the chart for
|
|
722
756
|
*/
|
|
723
757
|
|
|
724
758
|
|
|
@@ -741,8 +775,8 @@ class ChartUtils {
|
|
|
741
775
|
}
|
|
742
776
|
/**
|
|
743
777
|
* Get an object mapping axis to their ranges
|
|
744
|
-
* @param
|
|
745
|
-
* @returns
|
|
778
|
+
* @param layout The plotly layout object to get the ranges from
|
|
779
|
+
* @returns An object mapping the axis name to it's range
|
|
746
780
|
*/
|
|
747
781
|
|
|
748
782
|
|
|
@@ -752,10 +786,11 @@ class ChartUtils {
|
|
|
752
786
|
|
|
753
787
|
for (var i = 0; i < keys.length; i += 1) {
|
|
754
788
|
var key = keys[i];
|
|
789
|
+
var value = layout[key];
|
|
755
790
|
|
|
756
|
-
if (
|
|
791
|
+
if (isRangedPlotlyAxis(value)) {
|
|
757
792
|
// Only want to add the range if it's not autoranged
|
|
758
|
-
ranges[key] = [...
|
|
793
|
+
ranges[key] = [...value.range];
|
|
759
794
|
}
|
|
760
795
|
}
|
|
761
796
|
|
|
@@ -766,11 +801,11 @@ class ChartUtils {
|
|
|
766
801
|
* If the axis did not exist in the layout previously, it is created and added.
|
|
767
802
|
* Any axis that no longer exists in axes is removed.
|
|
768
803
|
* With Downsampling enabled, will also update the range on the axis itself as appropriate
|
|
769
|
-
* @param
|
|
770
|
-
* @param
|
|
771
|
-
* @param
|
|
772
|
-
* @param
|
|
773
|
-
* @param
|
|
804
|
+
* @param layoutParam The layout object to update
|
|
805
|
+
* @param axes The axes to update the layout with
|
|
806
|
+
* @param plotWidth The width of the plot to calculate the axis sizes for
|
|
807
|
+
* @param plotHeight The height of the plot to calculate the axis sizes for
|
|
808
|
+
* @param getRangeParser A function to retrieve the range parser for a given axis
|
|
774
809
|
*/
|
|
775
810
|
|
|
776
811
|
|
|
@@ -778,7 +813,7 @@ class ChartUtils {
|
|
|
778
813
|
var plotWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
779
814
|
var plotHeight = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
780
815
|
var getRangeParser = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
781
|
-
var theme = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] :
|
|
816
|
+
var theme = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : ChartTheme;
|
|
782
817
|
var xAxisSize = plotWidth > 0 ? Math.max(ChartUtils.MIN_AXIS_SIZE, Math.min(ChartUtils.AXIS_SIZE_PX / plotHeight, ChartUtils.MAX_AXIS_SIZE)) : ChartUtils.DEFAULT_AXIS_SIZE;
|
|
783
818
|
var yAxisSize = plotHeight > 0 ? Math.max(ChartUtils.MIN_AXIS_SIZE, Math.min(ChartUtils.AXIS_SIZE_PX / plotWidth, ChartUtils.MAX_AXIS_SIZE)) : ChartUtils.DEFAULT_AXIS_SIZE; // Adjust the bounds based on where the legend is
|
|
784
819
|
// For now, always assume the legend is shown on the right
|
|
@@ -812,10 +847,11 @@ class ChartUtils {
|
|
|
812
847
|
var typeAxes = axisTypeMap.get(axisType);
|
|
813
848
|
var isYAxis = axisType === dh.plot.AxisType.Y;
|
|
814
849
|
var plotSize = isYAxis ? plotHeight : plotWidth;
|
|
850
|
+
assertNotNull(typeAxes);
|
|
815
851
|
var axisIndex = 0;
|
|
816
852
|
|
|
817
853
|
for (axisIndex = 0; axisIndex < typeAxes.length; axisIndex += 1) {
|
|
818
|
-
var
|
|
854
|
+
var _axis3 = typeAxes[axisIndex];
|
|
819
855
|
|
|
820
856
|
var _axisLayoutProperty = ChartUtils.getAxisLayoutProperty(axisProperty, axisIndex);
|
|
821
857
|
|
|
@@ -824,19 +860,23 @@ class ChartUtils {
|
|
|
824
860
|
}
|
|
825
861
|
|
|
826
862
|
var layoutAxis = layout[_axisLayoutProperty];
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
863
|
+
|
|
864
|
+
if (layoutAxis != null) {
|
|
865
|
+
ChartUtils.updateLayoutAxis(layoutAxis, _axis3, axisIndex, axisPositionMap, xAxisSize, yAxisSize, bounds);
|
|
866
|
+
var {
|
|
867
|
+
range: _range,
|
|
868
|
+
autorange
|
|
869
|
+
} = layoutAxis;
|
|
870
|
+
|
|
871
|
+
if (getRangeParser && _range && !autorange) {
|
|
872
|
+
var rangeParser = getRangeParser(_axis3);
|
|
873
|
+
var [rangeStart, rangeEnd] = rangeParser(_range);
|
|
874
|
+
log.debug('Setting downsample range', plotSize, rangeStart, rangeEnd);
|
|
875
|
+
|
|
876
|
+
_axis3.range(plotSize, rangeStart, rangeEnd);
|
|
877
|
+
} else {
|
|
878
|
+
_axis3.range(plotSize);
|
|
879
|
+
}
|
|
840
880
|
}
|
|
841
881
|
}
|
|
842
882
|
|
|
@@ -853,16 +893,16 @@ class ChartUtils {
|
|
|
853
893
|
|
|
854
894
|
static getAxisLayoutProperty(axisProperty, axisIndex) {
|
|
855
895
|
var axisIndexString = axisIndex > 0 ? "".concat(axisIndex + 1) : '';
|
|
856
|
-
return "".concat(axisProperty, "axis").concat(axisIndexString);
|
|
896
|
+
return "".concat(axisProperty !== null && axisProperty !== void 0 ? axisProperty : '', "axis").concat(axisIndexString);
|
|
857
897
|
}
|
|
858
898
|
/**
|
|
859
899
|
* Updates the layout axis object in place
|
|
860
|
-
* @param
|
|
861
|
-
* @param
|
|
862
|
-
* @param
|
|
863
|
-
* @param
|
|
864
|
-
* @param
|
|
865
|
-
* @param
|
|
900
|
+
* @param layoutAxisParam The plotly layout axis param
|
|
901
|
+
* @param axis The Iris Axis to update the plotly layout with
|
|
902
|
+
* @param axisIndex The type index for this axis
|
|
903
|
+
* @param axisPositionMap All the axes mapped by position
|
|
904
|
+
* @param axisSize The size of each axis in percent
|
|
905
|
+
* @param bounds The bounds of the axes domains
|
|
866
906
|
*/
|
|
867
907
|
|
|
868
908
|
|
|
@@ -870,7 +910,14 @@ class ChartUtils {
|
|
|
870
910
|
var isYAxis = axis.type === dh.plot.AxisType.Y;
|
|
871
911
|
var axisSize = isYAxis ? yAxisSize : xAxisSize;
|
|
872
912
|
var layoutAxis = layoutAxisParam;
|
|
873
|
-
|
|
913
|
+
|
|
914
|
+
if (layoutAxis.title !== undefined && typeof layoutAxis.title !== 'string') {
|
|
915
|
+
layoutAxis.title.text = axis.label;
|
|
916
|
+
} else {
|
|
917
|
+
layoutAxis.title = {
|
|
918
|
+
text: axis.label
|
|
919
|
+
};
|
|
920
|
+
}
|
|
874
921
|
|
|
875
922
|
if (axis.log) {
|
|
876
923
|
layoutAxis.type = 'log';
|
|
@@ -879,8 +926,10 @@ class ChartUtils {
|
|
|
879
926
|
layoutAxis.side = ChartUtils.getAxisSide(axis.position);
|
|
880
927
|
|
|
881
928
|
if (axisIndex > 0) {
|
|
882
|
-
|
|
883
|
-
|
|
929
|
+
var _ChartUtils$getAxisPr, _axisPositionMap$get;
|
|
930
|
+
|
|
931
|
+
layoutAxis.overlaying = (_ChartUtils$getAxisPr = ChartUtils.getAxisPropertyName(axis.type)) !== null && _ChartUtils$getAxisPr !== void 0 ? _ChartUtils$getAxisPr : undefined;
|
|
932
|
+
var positionAxes = (_axisPositionMap$get = axisPositionMap.get(axis.position)) !== null && _axisPositionMap$get !== void 0 ? _axisPositionMap$get : [];
|
|
884
933
|
var sideIndex = positionAxes.indexOf(axis);
|
|
885
934
|
|
|
886
935
|
if (sideIndex > 0) {
|
|
@@ -913,13 +962,13 @@ class ChartUtils {
|
|
|
913
962
|
/**
|
|
914
963
|
* Converts an open or close period to a declimal. e.g '09:30" to 9.5
|
|
915
964
|
*
|
|
916
|
-
* @param
|
|
965
|
+
* @param period the open or close value of the period
|
|
917
966
|
*/
|
|
918
967
|
|
|
919
968
|
|
|
920
969
|
static periodToDecimal(period) {
|
|
921
970
|
var values = period.split(':');
|
|
922
|
-
return Number(values[0]) + Number(values[1] / 60
|
|
971
|
+
return Number(values[0]) + Number(values[1]) / 60;
|
|
923
972
|
}
|
|
924
973
|
/**
|
|
925
974
|
* Creates range break bounds for plotly from business days.
|
|
@@ -927,7 +976,7 @@ class ChartUtils {
|
|
|
927
976
|
* will result in [[6,1]] meaning close on Saturday and open on Monday.
|
|
928
977
|
* If you remove Wednesday from the array, then you get two closures [[6, 1], [3, 4]]
|
|
929
978
|
*
|
|
930
|
-
* @param
|
|
979
|
+
* @param businessDays the days to display on the x-axis
|
|
931
980
|
*/
|
|
932
981
|
|
|
933
982
|
|
|
@@ -964,9 +1013,9 @@ class ChartUtils {
|
|
|
964
1013
|
/**
|
|
965
1014
|
* Creates an array of range breaks for all holidays.
|
|
966
1015
|
*
|
|
967
|
-
* @param
|
|
968
|
-
* @param
|
|
969
|
-
* @param
|
|
1016
|
+
* @param holidays an array of holidays
|
|
1017
|
+
* @param calendarTimeZone the time zone for the business calendar
|
|
1018
|
+
* @param formatterTimeZone the time zone for the formatter
|
|
970
1019
|
*/
|
|
971
1020
|
|
|
972
1021
|
|
|
@@ -987,9 +1036,9 @@ class ChartUtils {
|
|
|
987
1036
|
/**
|
|
988
1037
|
* Creates the range break value for a full holiday. A full holiday is day that has no business periods.
|
|
989
1038
|
*
|
|
990
|
-
* @param
|
|
991
|
-
* @param
|
|
992
|
-
* @param
|
|
1039
|
+
* @param holiday the full holiday
|
|
1040
|
+
* @param calendarTimeZone the time zone for the business calendar
|
|
1041
|
+
* @param formatterTimeZone the time zone for the formatter
|
|
993
1042
|
*/
|
|
994
1043
|
|
|
995
1044
|
|
|
@@ -1000,9 +1049,9 @@ class ChartUtils {
|
|
|
1000
1049
|
* Creates the range break for a partial holiday. A partial holiday is holiday with business periods
|
|
1001
1050
|
* that are different than the default business periods.
|
|
1002
1051
|
*
|
|
1003
|
-
* @param
|
|
1004
|
-
* @param
|
|
1005
|
-
* @param
|
|
1052
|
+
* @param holiday the partial holiday
|
|
1053
|
+
* @param calendarTimeZone the time zone for the business calendar
|
|
1054
|
+
* @param formatterTimeZone the time zone for the formatter
|
|
1006
1055
|
*/
|
|
1007
1056
|
|
|
1008
1057
|
|
|
@@ -1041,9 +1090,9 @@ class ChartUtils {
|
|
|
1041
1090
|
/**
|
|
1042
1091
|
* Adjusts a date string from the calendar time zone to the formatter time zone.
|
|
1043
1092
|
*
|
|
1044
|
-
* @param
|
|
1045
|
-
* @param
|
|
1046
|
-
* @param
|
|
1093
|
+
* @param dateString the date string
|
|
1094
|
+
* @param calendarTimeZone the time zone for the business calendar
|
|
1095
|
+
* @param formatterTimeZone the time zone for the formatter
|
|
1047
1096
|
*/
|
|
1048
1097
|
|
|
1049
1098
|
|
|
@@ -1056,9 +1105,9 @@ class ChartUtils {
|
|
|
1056
1105
|
}
|
|
1057
1106
|
/**
|
|
1058
1107
|
* Groups an array and returns a map
|
|
1059
|
-
* @param
|
|
1060
|
-
* @param
|
|
1061
|
-
* @returns
|
|
1108
|
+
* @param array The object to group
|
|
1109
|
+
* @param property The property name to group by
|
|
1110
|
+
* @returns A map containing the items grouped by their values for the property
|
|
1062
1111
|
*/
|
|
1063
1112
|
|
|
1064
1113
|
|
|
@@ -1071,27 +1120,19 @@ class ChartUtils {
|
|
|
1071
1120
|
return result;
|
|
1072
1121
|
}, new Map());
|
|
1073
1122
|
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Update
|
|
1076
|
-
*/
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
static updateRanges() {}
|
|
1080
1123
|
/**
|
|
1081
1124
|
* Unwraps a value provided from API to a value plotly can understand
|
|
1082
1125
|
* Eg. Unwraps DateWrapper, LongWrapper objects.
|
|
1083
1126
|
*/
|
|
1084
1127
|
|
|
1085
1128
|
|
|
1086
|
-
static unwrapValue(value) {
|
|
1087
|
-
var timeZone = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1088
|
-
|
|
1129
|
+
static unwrapValue(value, timeZone) {
|
|
1089
1130
|
if (value != null) {
|
|
1090
|
-
if (value
|
|
1131
|
+
if (isDateWrapper(value)) {
|
|
1091
1132
|
return dh.i18n.DateTimeFormat.format(ChartUtils.DATE_FORMAT, value, timeZone);
|
|
1092
1133
|
}
|
|
1093
1134
|
|
|
1094
|
-
if (value
|
|
1135
|
+
if (isLongWrapper(value)) {
|
|
1095
1136
|
return value.asNumber();
|
|
1096
1137
|
}
|
|
1097
1138
|
}
|
|
@@ -1100,9 +1141,9 @@ class ChartUtils {
|
|
|
1100
1141
|
}
|
|
1101
1142
|
/**
|
|
1102
1143
|
*
|
|
1103
|
-
* @param
|
|
1104
|
-
* @param
|
|
1105
|
-
* @param
|
|
1144
|
+
* @param value The value to wrap up
|
|
1145
|
+
* @param columnType The type of column this value is from
|
|
1146
|
+
* @param timeZone The time zone if applicable
|
|
1106
1147
|
*/
|
|
1107
1148
|
|
|
1108
1149
|
|
|
@@ -1135,7 +1176,7 @@ class ChartUtils {
|
|
|
1135
1176
|
}
|
|
1136
1177
|
|
|
1137
1178
|
static makeLayoutAxis(type) {
|
|
1138
|
-
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
1179
|
+
var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ChartTheme;
|
|
1139
1180
|
var axis = {
|
|
1140
1181
|
automargin: true,
|
|
1141
1182
|
gridcolor: theme.gridcolor,
|
|
@@ -1174,12 +1215,13 @@ class ChartUtils {
|
|
|
1174
1215
|
/**
|
|
1175
1216
|
* Parses the colorway property of a theme and returns an array of colors
|
|
1176
1217
|
* Theme could have a single string with space separated colors or an array of strings representing the colorway
|
|
1177
|
-
* @param
|
|
1178
|
-
* @returns
|
|
1218
|
+
* @param theme The theme to get colorway from
|
|
1219
|
+
* @returns Colorway array for the theme
|
|
1179
1220
|
*/
|
|
1180
1221
|
|
|
1181
1222
|
|
|
1182
|
-
static getColorwayFromTheme(
|
|
1223
|
+
static getColorwayFromTheme() {
|
|
1224
|
+
var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ChartTheme;
|
|
1183
1225
|
var colorway = [];
|
|
1184
1226
|
|
|
1185
1227
|
if (theme.colorway) {
|
|
@@ -1196,7 +1238,7 @@ class ChartUtils {
|
|
|
1196
1238
|
}
|
|
1197
1239
|
|
|
1198
1240
|
static makeDefaultLayout() {
|
|
1199
|
-
var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
1241
|
+
var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ChartTheme;
|
|
1200
1242
|
|
|
1201
1243
|
var layout = _objectSpread(_objectSpread({}, theme), {}, {
|
|
1202
1244
|
autosize: true,
|
|
@@ -1227,7 +1269,7 @@ class ChartUtils {
|
|
|
1227
1269
|
}
|
|
1228
1270
|
/**
|
|
1229
1271
|
* Hydrate settings from a JSONable object
|
|
1230
|
-
* @param
|
|
1272
|
+
* @param settings Dehydrated settings
|
|
1231
1273
|
*/
|
|
1232
1274
|
|
|
1233
1275
|
|
|
@@ -1251,11 +1293,11 @@ class ChartUtils {
|
|
|
1251
1293
|
* This logic will still need to exist to translate existing charts, but could be part of a migration script
|
|
1252
1294
|
* to translate the data.
|
|
1253
1295
|
* Change when we decide to add more functionality to the Chart Builder.
|
|
1254
|
-
* @param
|
|
1255
|
-
* @param
|
|
1256
|
-
* @param
|
|
1257
|
-
* @param
|
|
1258
|
-
* @param
|
|
1296
|
+
* @param settings The chart builder settings
|
|
1297
|
+
* @param settings.title The title for this figure
|
|
1298
|
+
* @param settings.xAxis The name of the column to use for the x-axis
|
|
1299
|
+
* @param settings.series The name of the columns to use for the series of this figure
|
|
1300
|
+
* @param settings.type The plot style for this figure
|
|
1259
1301
|
*/
|
|
1260
1302
|
|
|
1261
1303
|
|