@datarailsshared/dr_renderer 1.2.217 → 1.2.219-dragons

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.217",
3
+ "version": "1.2.219-dragons",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1,5 +1,6 @@
1
1
  const SERIES_CLASSNAMES = {
2
2
  WATERFALL_BREAKDOWN: 'waterfallBreakdown',
3
+ WATERFALL_WALKTHROUGH: 'waterfallWalkthrough',
3
4
  TOTAL_SERIES: 'totalSeries',
4
5
  TREND_SERIES: 'trendSeries',
5
6
  };
@@ -25,6 +26,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
25
26
  const textColor = "#151a41";
26
27
  const chartLabelColor = "#cfd7dd";
27
28
  const HIGHCHARTS_FONT_FAMILY = 'Poppins';
29
+ let firstBarColor = null;
28
30
 
29
31
  if(!Highcharts){
30
32
  Highcharts = {
@@ -82,11 +84,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
82
84
  KPI_WIDGET: 'kpi-widget',
83
85
  TEXT_WIDGET: 'text-widget',
84
86
  WATERFALL_BREAKDOWN: 'waterfall-chart-breakdown',
87
+ WATERFALL_WALKTHROUGH: 'waterfall-chart-walkthrough',
85
88
  PUBLISHED_ITEM: 'published_item',
86
89
  RICH_TEXT: 'rich_text',
87
90
  EXCEL_VIEWER: 'excel_viewer',
88
91
  };
89
92
 
93
+ highchartsRenderer.VIRTUAL_FIELDS = {
94
+ WATERFALL_VARIANCE: 'DR_WATERFALL_BREAKDOWN_VARIANCE',
95
+ };
96
+
90
97
  highchartsRenderer.highcharts_theme = {
91
98
  "colors": highchartsRenderer.defaults_colors,
92
99
  "chart": {
@@ -462,7 +469,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
462
469
  highchartsRenderer.getOthersName(opts) :
463
470
  undefined;
464
471
  var drOthersInColumn = lodash.find(
465
- pivotData.getColKeys(),
472
+ pivotData.getColKeys(),
466
473
  keys => keys.length && (lodash.includes(keys, 'DR_Others') || lodash.includes(keys, othersName))
467
474
  );
468
475
 
@@ -482,7 +489,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
482
489
  rows = [];
483
490
  }
484
491
 
485
- var cols = this.key;
492
+ var cols = lodash.get(this, 'point.options.colsForTotal') || this.key;
486
493
  if (typeof (cols) == 'object' && cols.name) {
487
494
  cols = cols.name;
488
495
  }
@@ -490,7 +497,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
490
497
  if (!cols && is_drill_down_pie) {
491
498
  cols = this.point.name;
492
499
  }
493
-
500
+
494
501
  if (drOthersInColumn) {
495
502
  if (!lodash.isArray(cols) && othersName === cols) {
496
503
  cols = ['DR_Others'];
@@ -628,7 +635,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
628
635
  || this.series.options.className === 'trendSeries') {
629
636
  rows = [];
630
637
  }
631
- var cols = this.key;
638
+
639
+ var cols = lodash.get(this, 'point.options.colsForTotal') || this.key;
632
640
  if (!cols && is_drill_down_pie) {
633
641
  cols = this.name;
634
642
  }
@@ -651,7 +659,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
651
659
  rows = temp;
652
660
  }
653
661
 
654
- var category_text = `<span style="font-weight: bold;">${ cols }${ isWaterfallBreakdown ? ': ' : ' ' }</span>`;
662
+ var category_text = `<span style="font-weight: bold;">
663
+ ${ lodash.get(this, 'point.options.colsForTotal') ? cols[0] : cols } ${ isWaterfallBreakdown ? ': ' : ' ' }
664
+ </span>`;
655
665
  if (this.category) {
656
666
  category_text = '';
657
667
  }
@@ -668,7 +678,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
668
678
  const modifiedRowsAndCols = highchartsRenderer.transformRowsAndColsForBreakdown(rows, cols, this.point, opts);
669
679
  rows = modifiedRowsAndCols.rows;
670
680
  cols = modifiedRowsAndCols.cols;
671
- }
681
+ }
672
682
 
673
683
  var aggr = pivotData.getAggregator(rows, cols);
674
684
 
@@ -1344,7 +1354,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1344
1354
  const chart_series = [];
1345
1355
  const row_n_keys = pivotData.getRowKeys();
1346
1356
  const col_n_keys = pivotData.getColKeys();
1347
- const hasBreakdownValues = lodash.get(opts, 'breakdown_options.values.breakdown.length');
1348
1357
 
1349
1358
  let resultObject = {
1350
1359
  data: [],
@@ -1363,8 +1372,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1363
1372
  lodash.forEach(col_n_keys, function(col_n_value, col_index) {
1364
1373
 
1365
1374
  const totalColumnValue = pivotData.getAggregator([], col_n_value).value();
1366
- const nextTotalColumnKey = col_n_keys[col_index + 1];
1367
- const nextTotalColumnValue = nextTotalColumnKey ? pivotData.getAggregator([], nextTotalColumnKey).value() : null;
1368
1375
  resultObject.data.push({
1369
1376
  y: totalColumnValue,
1370
1377
  name: lodash.unescape(col_n_value).replace('DR_Others', highchartsRenderer.getOthersName(opts)),
@@ -1376,9 +1383,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1376
1383
  if (col_index !== col_n_keys.length - 1) {
1377
1384
  lodash.forEach(row_n_keys, function (row_n_value) {
1378
1385
  const agg = pivotData.getAggregator(row_n_value, col_n_value);
1379
- let val = hasBreakdownValues
1380
- ? agg.value()
1381
- : nextTotalColumnValue - totalColumnValue;
1386
+ let val = agg.value();
1382
1387
 
1383
1388
  val = $.isNumeric(val) ? parseFloat(val) : 0;
1384
1389
  if (val) {
@@ -1389,6 +1394,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1389
1394
  if (tmoobj.name) {
1390
1395
  tmoobj.name = tmoobj.name.replace('DR_Others', highchartsRenderer.getOthersName(opts));
1391
1396
  }
1397
+
1392
1398
  if (lodash.isEmpty(String(tmoobj.name))) {
1393
1399
  tmoobj.name = lodash.unescape(col_n_value);
1394
1400
  tmoobj.visible = false;
@@ -1398,12 +1404,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1398
1404
  tmoobj.colKeys = [lodash.unescape(col_n_keys[col_index - 1]), lodash.unescape(col_n_value)];
1399
1405
  resultObject.data.push(tmoobj);
1400
1406
  }
1407
+
1401
1408
  });
1402
1409
  }
1403
1410
  });
1404
1411
 
1405
1412
  chart_series.push(resultObject);
1406
-
1407
1413
  opts.chart_series = [];
1408
1414
  if (!lodash.isEqual(row_n_keys, EMPTY_ROW_N_KEYS)) {
1409
1415
  chart_series.forEach(series => {
@@ -1414,6 +1420,89 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1414
1420
  return chart_series;
1415
1421
  }
1416
1422
 
1423
+ highchartsRenderer.ptCreateWaterfallWalkthroughSeries = function (pivotData, onlyNumbers, additionOptions, opts) {
1424
+ const waterfallOptions = opts.walkthrough_options;
1425
+ const chart_series = [];
1426
+ let resultObject = {
1427
+ data: [],
1428
+ dataLabels: {
1429
+ allowOverlap: additionOptions && additionOptions.label ? additionOptions.label.overlap : false,
1430
+ enabled: additionOptions && additionOptions.label ? additionOptions.label.show : true,
1431
+ formatter: highchartsRenderer.defaultDataLabelFormatter(pivotData, {'chartOptions': additionOptions, total_value_options: opts.total_value_options}),
1432
+ style: highchartsRenderer.getDataLabelsStyle(additionOptions),
1433
+ },
1434
+ upColor: waterfallOptions.colors.increase,
1435
+ color: waterfallOptions.colors.decrease,
1436
+ className: SERIES_CLASSNAMES.WATERFALL_WALKTHROUGH
1437
+ };
1438
+ resultObject = highchartsRenderer.getDataLabelsOptions(additionOptions, resultObject);
1439
+ lodash.forEach(waterfallOptions.values.walkthrough, function(value, index) {
1440
+
1441
+ let keys = [];
1442
+ if (value.trend === 'total') {
1443
+ keys = ['Total'];
1444
+ } else {
1445
+ _.forEach(value.key, (item) => {
1446
+ const findKeyByValue = Object.keys(pivotData.dateValuesDictionary || {}).find(key => pivotData.dateValuesDictionary[key] === item);
1447
+ keys.push(findKeyByValue ? findKeyByValue : item);
1448
+ })
1449
+ }
1450
+
1451
+ const agg = pivotData.getAggregator([], keys);
1452
+ let val = agg.value();
1453
+
1454
+ if (val != null && $.isNumeric(val)) {
1455
+ val = parseFloat(val);
1456
+ } else if (onlyNumbers) {
1457
+ val = NaN;
1458
+ } else {
1459
+ val = 0;
1460
+ }
1461
+
1462
+ if (value.trend === 'decrease') {
1463
+ val = val * -1;
1464
+ }
1465
+
1466
+ const name = value.trend === 'total' ? value.formattedKey || value.key[0] : keys.join(highchartsRenderer.delimer);
1467
+ let color = '';
1468
+ if (value.trend !== 'total') {
1469
+ if (index === 0 && !firstBarColor) {
1470
+ color = waterfallOptions.colors.total;
1471
+ firstBarColor = waterfallOptions.colors.total;
1472
+ } else {
1473
+ color = value.color
1474
+ }
1475
+ } else {
1476
+ color = waterfallOptions.colors.total;
1477
+ }
1478
+
1479
+ resultObject.data.push({
1480
+ y: val,
1481
+ name: lodash.unescape(name).replace('DR_Others', highchartsRenderer.getOthersName(opts)),
1482
+ isSum: value.trend === 'total',
1483
+ isTotal: value.trend === 'total',
1484
+ color,
1485
+ colsForTotal: value.trend === 'total' ? keys : null,
1486
+ });
1487
+ });
1488
+ chart_series.push(resultObject);
1489
+ chart_series.push(
1490
+ {
1491
+ name: 'Increase',
1492
+ visible: false,
1493
+ color: waterfallOptions.colors.increase
1494
+ });
1495
+
1496
+ chart_series.push(
1497
+ {
1498
+ name: 'Decrease',
1499
+ visible: false,
1500
+ color: waterfallOptions.colors.decrease
1501
+ });
1502
+
1503
+ return chart_series;
1504
+ }
1505
+
1417
1506
  highchartsRenderer.setChartTypeBySeriesType = function (type, series) {
1418
1507
  const types = {
1419
1508
  'line-chart': 'line',
@@ -1617,7 +1706,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1617
1706
  highchartsRenderer.getDataLabelsStylesForDrillDown = function(additionOptions) {
1618
1707
  let result = highchartsRenderer.getDataLabelsOptions(additionOptions, { dataLabels: {} });
1619
1708
 
1620
- if (!result.dataLabels) return {};
1709
+ if (!result.dataLabels) return {};
1621
1710
  return {
1622
1711
  activeDataLabelStyle: {
1623
1712
  color: result.dataLabels.color,
@@ -3173,7 +3262,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3173
3262
 
3174
3263
  highchartsRenderer.ptRenderWaterfallBreakdown = function (pivotData, opts, drilldownFunc, chartType) {
3175
3264
  let chartOptions = {};
3176
- const additionOptions = opts.chartOptions
3265
+ const additionOptions = opts.chartOptions
3177
3266
  ? opts.chartOptions
3178
3267
  : highchartsRenderer.getDefaultValueForChart(highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN);
3179
3268
 
@@ -3272,6 +3361,122 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3272
3361
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3273
3362
  };
3274
3363
 
3364
+ highchartsRenderer.ptRenderWaterfallWalkthrough = function (pivotData, opts) {
3365
+ let chartOptions = {};
3366
+ const waterfallOptions = opts?.walkthrough_options;
3367
+ const additionOptions = opts.chartOptions
3368
+ ? opts.chartOptions
3369
+ : highchartsRenderer.getDefaultValueForChart(highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH);
3370
+
3371
+ chartOptions.chart = {
3372
+ type: 'waterfall',
3373
+ zoomType: additionOptions && additionOptions.chart && additionOptions.chart.zoom_type ? additionOptions.chart.zoom_type : 'None',
3374
+ };
3375
+ if (disableAnimation) {
3376
+ chartOptions.chart.animation = false;
3377
+ }
3378
+ const walkthroughFieldIsNotSet = lodash.some(pivotData.getRowKeys(), rowKey => !rowKey || lodash.isArray(rowKey) && !rowKey.length);
3379
+
3380
+ chartOptions.xAxis = {
3381
+ type: 'category',
3382
+ crosshair: true,
3383
+ min: 0,
3384
+ title: {
3385
+ text : additionOptions && additionOptions.axisX ? additionOptions.axisX.name : '',
3386
+ },
3387
+ uniqueNames: walkthroughFieldIsNotSet,
3388
+ };
3389
+
3390
+ highchartsRenderer.setTitleAndSubTitle(chartOptions, opts, additionOptions);
3391
+
3392
+ chartOptions.yAxis = {
3393
+ min: null,
3394
+ max: null,
3395
+ title: {
3396
+ text: additionOptions && additionOptions.axisY ? additionOptions.axisY.name : '',
3397
+ autoylabel: additionOptions && additionOptions.axisY ? additionOptions.axisY.autoylabel : ''
3398
+ },
3399
+ labels: {
3400
+ formatter: highchartsRenderer.defaultValueLabelsFormatter(pivotData, opts)
3401
+ },
3402
+ };
3403
+ if (additionOptions) {
3404
+ highchartsRenderer.setYAxisMinMax(chartOptions.yAxis, additionOptions.axisY);
3405
+ }
3406
+
3407
+ chartOptions.tooltip = {
3408
+ formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
3409
+ valueDecimals: 2,
3410
+ };
3411
+
3412
+ highchartsRenderer.handleGridLines(additionOptions, chartOptions);
3413
+
3414
+ if (lodash.get(opts, 'paletteOptions.widgetPalette', null)) {
3415
+ const mc_palette = lodash.find(lodash.get(opts.paletteOptions, 'monochromePalettes', []), { selected: true });
3416
+ chartOptions.colors = mc_palette ? mc_palette.colors : opts.paletteOptions.widgetPalette;
3417
+ } else if (lodash.get(opts, 'paletteOptions.dashboardPalette.colors', null)) {
3418
+ chartOptions.colors = opts.paletteOptions.dashboardPalette.colors;
3419
+ }
3420
+ chartOptions.series = highchartsRenderer
3421
+ .ptCreateWaterfallWalkthroughSeries(pivotData, null, additionOptions, opts);
3422
+
3423
+ chartOptions = highchartsRenderer.prepareAxisX(chartOptions, additionOptions, pivotData.getColKeys());
3424
+ chartOptions.plotOptions = {
3425
+ waterfall: {
3426
+ pointPadding: 0.2,
3427
+ borderWidth: 0,
3428
+ borderRadius: 1,
3429
+ lineWidth: 0,
3430
+ },
3431
+ series: {
3432
+ animation: !disableAnimation,
3433
+ cropThreshold: 1000,
3434
+ dataLabels: {
3435
+ allowOverlap: additionOptions && additionOptions.label ? additionOptions.label.overlap : false,
3436
+ enabled: additionOptions && additionOptions.label ? additionOptions.label.show : true,
3437
+ formatter: highchartsRenderer.defaultDataLabelFormatter(pivotData, opts),
3438
+ style: highchartsRenderer.getDataLabelsStyle(additionOptions),
3439
+ inside: false
3440
+ },
3441
+ events: {
3442
+ legendItemClick: () => {
3443
+ return false;
3444
+ }
3445
+ }
3446
+ }
3447
+ };
3448
+
3449
+ if (opts.drillDownListFunc) {
3450
+ chartOptions.plotOptions.series.cursor = 'pointer';
3451
+ chartOptions.plotOptions.series.point = {
3452
+ events: {
3453
+ click: opts.drillDownListFunc
3454
+ }
3455
+ };
3456
+ }
3457
+ if (waterfallOptions.colors) {
3458
+ chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, 3, false);
3459
+ chartOptions.legend.useHTML = true;
3460
+ chartOptions.legend.labelFormatter = function() {
3461
+ const name = this.options.className ? 'Total': this.name;
3462
+ const findTotal = _.find(this.options.data, {isTotal: true});
3463
+ const color = findTotal?.color ? findTotal.color : this.color;
3464
+ return '<span style="margin: 5px; vertical-align: middle; display:inline-block; background-color: '+ color + '; width: 12px; height: 12px; border-radius: 50%"></span><span style="color: #000; display: inline-block; margin: 5px; vertical-align: middle;">' + name + '</span>';
3465
+ }
3466
+
3467
+ chartOptions.legend.symbolPadding = 0;
3468
+ chartOptions.legend.symbolWidth = 0;
3469
+ chartOptions.legend.symbolHeight = 0;
3470
+ chartOptions.legend.squareSymbol = false;
3471
+ } else {
3472
+ chartOptions.legend = {
3473
+ enabled: false
3474
+ }
3475
+ }
3476
+
3477
+ return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3478
+ }
3479
+
3275
3480
  highchartsRenderer.formatFieldValue = function (field, value) {
3276
3481
  let currentType = '';
3277
3482
  let format = field.format;
@@ -4340,6 +4545,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4340
4545
  }
4341
4546
  };
4342
4547
 
4548
+ highchartsRenderer.waterfallConstants = {
4549
+ [highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN]: {
4550
+ minCategoriesCount: 2,
4551
+ maxCategoriesCount: 5,
4552
+ },
4553
+ [highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH]: {
4554
+ minCategoriesCount: 2,
4555
+ maxCategoriesCount: 10,
4556
+ }
4557
+ };
4558
+
4343
4559
  highchartsRenderer.rhPivotView = function (rowData, options, isTable = false, widget = null) {
4344
4560
  if (!rowData || !rowData) {
4345
4561
  if (options.onlyOptions) {
@@ -4348,10 +4564,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4348
4564
  return null;
4349
4565
  }
4350
4566
 
4351
- if (widget && widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
4352
- const breakdownSettings = widget.options.breakdown_options.settings;
4353
- const maxCategories = breakdownSettings.maxCategoriesCount;
4354
- const minCategories = breakdownSettings.minCategoriesCount;
4567
+ const isWaterfall = widget
4568
+ && (
4569
+ widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN
4570
+ || widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH
4571
+ );
4572
+
4573
+ if (isWaterfall) {
4574
+ const maxCategories = highchartsRenderer.waterfallConstants[widget.chart_type].maxCategoriesCount;
4575
+ const minCategories = highchartsRenderer.waterfallConstants[widget.chart_type].minCategoriesCount;
4355
4576
  const uniqueCategories = lodash.filter(
4356
4577
  lodash.uniq(
4357
4578
  lodash.map(rowData, row => row[widget.cols[0].name])
@@ -4361,11 +4582,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4361
4582
 
4362
4583
  if (uniqueCategories && (uniqueCategories.length > maxCategories || uniqueCategories.length < minCategories )) {
4363
4584
  options.error_has_occurred = true;
4585
+ const isDateField = widget.cols[0].type === 'Date';
4586
+ const commonMessagePart = `This chart support a selection of ${minCategories}-${maxCategories} items from the category section. `;
4364
4587
  options.error_params = {
4365
4588
  title: 'Data Conflict',
4366
4589
  text: `Please adjust your dashboard's reference date and filter selections as \
4367
4590
  the quantity of data doesn't match the chart's ${ minCategories }-${ maxCategories } value limit.`,
4368
- class: 'nodata',
4591
+ class: uniqueCategories.length < minCategories ? 'waterfall-nodata' : 'waterfall-too-much-data',
4369
4592
  }
4370
4593
  return highchartsRenderer.getNoDataResult(options.rendererOptions, true);
4371
4594
  }
@@ -4609,19 +4832,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4609
4832
  return highchartsRenderer.getWeekNumber(dateObj);
4610
4833
  };
4611
4834
 
4612
- highchartsRenderer.check_value_not_for_convert = function (currentgraph, field_name) {
4613
- let val_not_convert = null;
4835
+ highchartsRenderer.check_values_not_for_convert = function (currentgraph, field_name) {
4836
+ let vals_not_convert = [];
4614
4837
  if (lodash.has(currentgraph, "options.chartOptions.delta_column") && currentgraph.options.chartOptions.delta_column) {
4615
4838
  let delta_options = currentgraph.options.chartOptions.delta_column;
4616
4839
  if (delta_options.field == 'series' && currentgraph.rows && currentgraph.rows[0] &&
4617
4840
  currentgraph.rows[0].name == field_name) {
4618
- val_not_convert = delta_options.name;
4841
+ vals_not_convert = [delta_options.name];
4619
4842
  } else if (delta_options.field == 'category' && currentgraph.rows && currentgraph.cols[0] &&
4620
4843
  currentgraph.cols[0].name == field_name) {
4621
- val_not_convert = delta_options.name;
4844
+ vals_not_convert = [delta_options.name];
4622
4845
  }
4846
+ } else if (currentgraph.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH) {
4847
+ lodash.forEach(currentgraph.options.walkthrough_options.values.walkthrough, value => {
4848
+ if (value.trend === 'total') {
4849
+ vals_not_convert.push(value.key[0]);
4850
+ }
4851
+ });
4623
4852
  }
4624
- return val_not_convert;
4853
+ return vals_not_convert;
4625
4854
  };
4626
4855
 
4627
4856
  highchartsRenderer.updateFiltersShowNames = function (filters) {
@@ -4641,8 +4870,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4641
4870
  })
4642
4871
  };
4643
4872
 
4644
- highchartsRenderer.returnRawDataValue = function (type, value, format, field_name, val_not_for_convert) {
4645
- if (val_not_for_convert && val_not_for_convert == value) {
4873
+ highchartsRenderer.returnRawDataValue = function (type, value, format, field_name, vals_not_for_convert) {
4874
+ if (vals_not_for_convert && vals_not_for_convert.length && lodash.includes(vals_not_for_convert, value)) {
4646
4875
  return value;
4647
4876
  }
4648
4877
 
@@ -4954,12 +5183,28 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4954
5183
  }
4955
5184
  });
4956
5185
 
5186
+ // add virtual fields to rows if required
5187
+ let rows = widgetOptions.rows;
5188
+ if (!lodash.get(widgetOptions, 'rows.length') && widgetOptions.options.breakdown_options) {
5189
+ rows = [
5190
+ {
5191
+ id: -1,
5192
+ name: highchartsRenderer.VIRTUAL_FIELDS.WATERFALL_VARIANCE,
5193
+ type: 'Text',
5194
+ },
5195
+ ];
5196
+ }
5197
+
4957
5198
  // fill rows fields
4958
- lodash.forEach(widgetOptions.rows, function (valObj) {
4959
- fieldOb = lodash.find(fields, {id: valObj.id});
4960
- if (fieldOb) {
4961
- legendFields.push(fieldOb);
4962
- lodash.remove(fields, {id: fieldOb.id});
5199
+ lodash.forEach(rows, function (valObj) {
5200
+ if (lodash.includes(highchartsRenderer.VIRTUAL_FIELDS, valObj.name)) {
5201
+ legendFields.push(valObj);
5202
+ } else {
5203
+ fieldOb = lodash.find(fields, {id: valObj.id});
5204
+ if (fieldOb) {
5205
+ legendFields.push(fieldOb);
5206
+ lodash.remove(fields, {id: fieldOb.id});
5207
+ }
4963
5208
  }
4964
5209
  });
4965
5210
 
@@ -5086,22 +5331,71 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5086
5331
  highchartsRenderer.addTemplateDataToCalcModel = function (selectedTemplate, calcModelOptions) {
5087
5332
  highchartsRenderer.setWidgetFieldsToTemplate(selectedTemplate);
5088
5333
 
5089
- var fields = highchartsRenderer.objectCopyJsonMethod(selectedTemplate.widget_fields);
5090
- var fieldOb;
5091
- var selectedFields = [];
5334
+ const scenarioName = 'scenario';
5335
+ const fields = highchartsRenderer.objectCopyJsonMethod(selectedTemplate.fields);
5336
+ const fieldScenarioAlias = _.find(fields, field => (field.alias || '').toLowerCase() === scenarioName)
5337
+ const fieldScenario = _.find(fields, field => (field.name || '').toLowerCase() === scenarioName)
5338
+ const filters = calcModelOptions.config && calcModelOptions.config.filters;
5092
5339
 
5093
- // fill selected fields
5094
- lodash.forEach(calcModelOptions.fields, function (valObj) {
5095
- fieldOb = lodash.find(fields, {id: valObj.id});
5096
- if (fieldOb) {
5097
- selectedFields.push(fieldOb);
5098
- lodash.remove(fields, {id: fieldOb.id});
5340
+ const filterFields = [];
5341
+ const valueFields = [];
5342
+ const dateFields = [];
5343
+ const dataTypeFields = [];
5344
+ const dataSeriesFields = [];
5345
+
5346
+ let scenarioField = lodash.get(calcModelOptions, 'config.scenario', undefined) || fieldScenarioAlias || fieldScenario;
5347
+ let fieldOb;
5348
+
5349
+ const fillData = (fieldsArr, destinationArr) => {
5350
+ lodash.forEach(fieldsArr, function (valObj) {
5351
+ fieldOb = lodash.find(fields, { id: valObj.id });
5352
+ if (fieldOb) {
5353
+ destinationArr.push(fieldOb);
5354
+ lodash.remove(fields, { id: fieldOb.id });
5355
+ }
5356
+ });
5357
+ }
5358
+
5359
+ lodash.forEach(filters, function (filterObj) {
5360
+ fieldOb = lodash.find(fields, { id: filterObj.id });
5361
+ if (fieldOb && lodash.get(filterObj, 'values.datetype') === 'list') {
5362
+ filterObj.values = filterObj.values.val
5363
+ } else if (fieldOb && filterObj.values && filterObj.values.datetype && filterObj.values.datetype !== 'list') {
5364
+ fieldOb.values = filterObj.values;
5365
+ } else if (fieldOb && filterObj.values && filterObj.values.type === 'advanced') {
5366
+ fieldOb.values = filterObj.values;
5367
+ }
5368
+ if (fieldOb && filterObj.values && filterObj.values instanceof Array) {
5369
+ if (filterObj.is_excluded === true) {
5370
+ fieldOb.excludes = filterObj.values;
5371
+ } else {
5372
+ fieldOb.includes = filterObj.values;
5373
+ }
5374
+ }
5375
+ if (filterObj.allow_nulls && fieldOb) {
5376
+ fieldOb.allow_nulls = filterObj.allow_nulls;
5099
5377
  }
5100
5378
  });
5101
5379
 
5380
+ const storedGroupByFields = lodash.get(calcModelOptions, 'config.group_by', []);
5381
+ const storedDateFields = [lodash.get(calcModelOptions, 'config.date_field', undefined)].filter(f => !!f);
5382
+ const storedAggFields = [lodash.get(calcModelOptions, 'config.agg_field', undefined)].filter(f => !!f);
5383
+ const storedDataTypeFields = [lodash.get(calcModelOptions, 'config.data_type_field', undefined)].filter(f => !!f);
5384
+
5385
+ fillData(storedGroupByFields, dataSeriesFields);
5386
+ fillData(storedDateFields, dateFields);
5387
+ fillData(storedAggFields, valueFields);
5388
+ fillData(storedDataTypeFields, dataTypeFields);
5389
+ fillData(filters, filterFields);
5390
+
5102
5391
  calcModelOptions.pivot = {
5103
5392
  fieldsArray: fields,
5104
- selectedFieldsArray: selectedFields
5393
+ selectedFieldsArray: dataSeriesFields,
5394
+ filtersArray: filterFields,
5395
+ scenarioField,
5396
+ dateFields,
5397
+ dataTypeFields,
5398
+ valueFields
5105
5399
  };
5106
5400
  }
5107
5401
 
@@ -5600,7 +5894,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5600
5894
  return valToReturn;
5601
5895
  };
5602
5896
 
5603
-
5897
+
5604
5898
  highchartsRenderer.getChartAxisLabel = function(type) {
5605
5899
  return highchartsRenderer.chartsTypesInfo[type] ? highchartsRenderer.chartsTypesInfo[type].axisName : CHART_AXIS_DEFAULT_LABEL;
5606
5900
  };
@@ -6435,7 +6729,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6435
6729
  value_name: 'show',
6436
6730
  default_value: true,
6437
6731
  disabled_str: '!{var}.show_out_of_x_axis && !{var}.show_out_of_data_series && !{var}.show_value && !{var}.show_x_axis && !{var}.show_data_series',
6438
- disabled_fn: (value) => !value.show_out_of_x_axis
6732
+ disabled_fn: (value) => !value.show_out_of_x_axis
6439
6733
  && !value.show_out_of_data_series
6440
6734
  && !value.show_value
6441
6735
  && !value.show_x_axis
@@ -6476,8 +6770,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6476
6770
  element_label: '[X Axis]',
6477
6771
  value_name: 'show_x_axis',
6478
6772
  default_value: true,
6479
- clickFn: (value) => value.show = value.show
6480
- ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6773
+ clickFn: (value) => value.show = value.show
6774
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6481
6775
  : value.show,
6482
6776
  },
6483
6777
  {
@@ -6485,8 +6779,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6485
6779
  element_label: '[Data Series]',
6486
6780
  value_name: 'show_data_series',
6487
6781
  default_value: true,
6488
- clickFn: (value) => value.show = value.show
6489
- ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6782
+ clickFn: (value) => value.show = value.show
6783
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6490
6784
  : value.show,
6491
6785
  },
6492
6786
  {
@@ -6494,8 +6788,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6494
6788
  element_label: 'Value',
6495
6789
  value_name: 'show_value',
6496
6790
  default_value: true,
6497
- clickFn: (value) => value.show = value.show
6498
- ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6791
+ clickFn: (value) => value.show = value.show
6792
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6499
6793
  : value.show,
6500
6794
  },
6501
6795
  {
@@ -6503,8 +6797,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6503
6797
  element_label: '% Out of [X Axis]',
6504
6798
  value_name: 'show_out_of_x_axis',
6505
6799
  default_value: false,
6506
- clickFn: (value) => value.show = value.show
6507
- ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6800
+ clickFn: (value) => value.show = value.show
6801
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6508
6802
  : value.show,
6509
6803
  },
6510
6804
  {
@@ -6512,8 +6806,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6512
6806
  element_label: '% Out of [Data Series]',
6513
6807
  value_name: 'show_out_of_data_series',
6514
6808
  default_value: false,
6515
- clickFn: (value) => value.show = value.show
6516
- ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6809
+ clickFn: (value) => value.show = value.show
6810
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6517
6811
  : value.show,
6518
6812
  },
6519
6813
  ]
@@ -6687,16 +6981,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6687
6981
  value_name: 'name',
6688
6982
  element_label: 'Name',
6689
6983
  default_value: '_Variance'
6690
- }, {
6691
- element_type: 'input',
6692
- value_name: 'formula',
6693
- element_label: 'Formula',
6694
- default_value: 'x2-x1'
6695
6984
  }, {
6696
6985
  element_type: 'input',
6697
- value_name: 'color',
6698
- element_label: 'Color',
6699
- default_value: ''
6986
+ value_name: 'formula',
6987
+ element_label: 'Formula',
6988
+ default_value: 'x2-x1'
6989
+ }, {
6990
+ element_type: 'input',
6991
+ value_name: 'color',
6992
+ element_label: 'Color',
6993
+ default_value: ''
6700
6994
  }, {
6701
6995
  element_type: 'radio',
6702
6996
  value_name: 'chart',
@@ -6819,7 +7113,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6819
7113
  axisTooltipDescription: 'The category (usually an independent variable) is shown on the x-axis and should be between 2 to 5 total columns. ',
6820
7114
  legendTooltipTitle: 'Drag one field to further configure your x-axis.',
6821
7115
  legendTooltipDescription: 'The breakdown subdivides the chart by a category field for further analysis of what’s contributing to the increase or decrease.',
6822
- },
7116
+ },
7117
+ [highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH]: {
7118
+ name: 'Waterfall Walkthrough Chart ',
7119
+ label: 'Waterfall Walkthrough Chart ',
7120
+ title: 'TODO: add text',
7121
+ description: 'TODO: add text',
7122
+ axisName: 'Category',
7123
+ startedMessage: 'TODO: add text',
7124
+ axisTooltipTitle: 'TODO: add text',
7125
+ legendTooltipTitle: 'TODO: add text',
7126
+ },
6823
7127
  'combo-chart': {
6824
7128
  name: 'Combo Chart ',
6825
7129
  label: 'Combo Chart ',
@@ -7475,6 +7779,24 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7475
7779
  highchartsRenderer.suboptions["legends"],
7476
7780
  ]
7477
7781
  },
7782
+ {
7783
+ type: highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH,
7784
+ name: highchartsRenderer.chartsTypesInfo[highchartsRenderer.CHART_TYPES.WATERFALL_WALKTHROUGH].name,
7785
+ class: 'google-visualization-charteditor-thumbs-columnchart',
7786
+ render: highchartsRenderer.ptRenderWaterfallWalkthrough,
7787
+ suboptions: [
7788
+ highchartsRenderer.suboptions["axisX"],
7789
+ highchartsRenderer.suboptions["tooltips"],
7790
+ highchartsRenderer.suboptions["label"],
7791
+ highchartsRenderer.suboptions["subtitle"],
7792
+ highchartsRenderer.suboptions["widget_library"],
7793
+ highchartsRenderer.suboptions["chart"],
7794
+ highchartsRenderer.suboptions["negative_number_format"],
7795
+ highchartsRenderer.suboptions["advanced"],
7796
+ highchartsRenderer.suboptions["legends"],
7797
+ ],
7798
+ hidden: true,
7799
+ },
7478
7800
  ]
7479
7801
  },
7480
7802
  ];
@@ -7631,7 +7953,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7631
7953
  _.forEach(Object.keys(dates), key => {
7632
7954
  const dateConfiguration = dates[key];
7633
7955
  const timestamp = dateConfiguration.timestamp;
7634
- if (timestamp) {
7956
+ if (timestamp) {
7635
7957
  const dateTzOffsetInSeconds = new Date(timestamp * 1000).getTimezoneOffset() * 60;
7636
7958
  dateConfiguration.displayedValue = new Date((timestamp + dateTzOffsetInSeconds) * 1000)
7637
7959
  .toLocaleDateString();
@@ -7927,10 +8249,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7927
8249
  };
7928
8250
 
7929
8251
  highchartsRenderer.createDateFromString = function (dateString, format) {
7930
- if ((format && !highchartsRenderer.isDateFormat(dateString, format)) || !highchartsRenderer.isDate(dateString)) {
8252
+ if (!(format && highchartsRenderer.isDateFormat(dateString, format) || highchartsRenderer.isDate(dateString))) {
7931
8253
  return null;
7932
8254
  }
7933
- const utcDate = format
8255
+ const utcDate = format
7934
8256
  ? moment_lib.utc(dateString, format, true)
7935
8257
  : moment_lib.utc(dateString);
7936
8258
  return utcDate.startOf('day').unix();
@@ -7948,7 +8270,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7948
8270
  }
7949
8271
 
7950
8272
  let filters = [];
7951
-
8273
+
7952
8274
  if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
7953
8275
  const colFilter = highchartsRenderer.createFilterObject(widget.cols[0]);
7954
8276
  const labels = [];
@@ -7976,7 +8298,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7976
8298
  col_value,
7977
8299
  highchartsRenderer.getDateFieldFormat(widget, widget.cols[index])
7978
8300
  );
7979
-
8301
+
7980
8302
  if ($.isEmptyObject(datetrange)) {
7981
8303
  return;
7982
8304
  }
@@ -8081,6 +8403,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8081
8403
  filter.is_excluded = false;
8082
8404
  } else {
8083
8405
  filter = highchartsRenderer.createDrillDownFilterObject(widget, widget.cols[0], colKey[0]);
8406
+ filters.push(filter);
8084
8407
  }
8085
8408
  filter.values = [];
8086
8409
  for (let i = 0; i < colKey.length; i++) {
@@ -8218,7 +8541,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8218
8541
  var data = res;
8219
8542
 
8220
8543
  lodash.forEach(datesFields, function (row) {
8221
- row.val_not_convert = highchartsRenderer.check_value_not_for_convert(widget, row.name);
8544
+ row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
8222
8545
  });
8223
8546
 
8224
8547
  if (datesFields.length > 0) {
@@ -8624,14 +8947,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8624
8947
  return rightPosition;
8625
8948
  case 'none':
8626
8949
  return none;
8950
+ }
8951
+ } else if (isLine) {
8952
+ return useNewUx ? leftPosition : rightPosition;
8953
+ } else if (isPie) {
8954
+ return useNewUx ? rightPosition : topPosition;
8627
8955
  }
8628
- } else if (isLine) {
8629
- return useNewUx ? leftPosition : rightPosition;
8630
- } else if (isPie) {
8631
- return useNewUx ? rightPosition : topPosition;
8632
- }
8633
8956
 
8634
- return useNewUx ? topPosition : bottomPosition;
8957
+ return useNewUx ? topPosition : bottomPosition;
8635
8958
  }
8636
8959
 
8637
8960
  highchartsRenderer.setYAxisMinMax = function (yAxis, axisYOptions) {
@@ -8646,7 +8969,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8646
8969
  }
8647
8970
 
8648
8971
  highchartsRenderer.getDateFieldFormat = function(widget, dateField) {
8649
- const aggregationConfig = widget.options && widget.options.date_aggregation_configs
8972
+ const aggregationConfig = widget.options && widget.options.date_aggregation_configs
8650
8973
  ? _.find(widget.options.date_aggregation_configs, { field_id: dateField.id })
8651
8974
  : null;
8652
8975