@datarailsshared/dr_renderer 1.2.219-dragons → 1.2.221-unittests

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.
@@ -31,6 +31,12 @@ jobs:
31
31
  - run:
32
32
  name: Authenticate with registry
33
33
  command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/repo/.npmrc
34
+ - run:
35
+ name: Install dependencies
36
+ command: npm install
37
+ - run:
38
+ name: Run npm test
39
+ command: npm test
34
40
  - run:
35
41
  name: Publish package
36
42
  command: npm publish . --access=public
@@ -65,3 +71,4 @@ workflows:
65
71
  - /tigers/
66
72
  - /wizards/
67
73
  - /rocket/
74
+ - /unittests/
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
3
+ };
package/jest.config.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ clearMocks: true,
3
+ setupFilesAfterEnv: ['regenerator-runtime/runtime'],
4
+ testPathIgnorePatterns: [
5
+ "/node_modules/",
6
+ ],
7
+ transformIgnorePatterns: [
8
+ "<rootDir>/node_modules/(?!jquery|lodash|moment/)",
9
+ ],
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarailsshared/dr_renderer",
3
- "version": "1.2.219-dragons",
3
+ "version": "1.2.221-unittests",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -9,7 +9,8 @@
9
9
  "tables"
10
10
  ],
11
11
  "scripts": {
12
- "login": "npm login"
12
+ "login": "npm login",
13
+ "test": "jest"
13
14
  },
14
15
  "author": "Sergey Spivakov",
15
16
  "repository": {
@@ -17,6 +18,21 @@
17
18
  "url": "git+https://bitbucket.org/datarails/dr_renderer.git"
18
19
  },
19
20
  "license": "",
21
+ "dependencies": {
22
+ "jquery": "^3.6.0",
23
+ "lodash": "^4.17.20",
24
+ "regenerator-runtime": "^0.13.5"
25
+ },
26
+ "devDependencies": {
27
+ "@babel/core": "^7.20.12",
28
+ "@babel/preset-env": "^7.20.2",
29
+ "@testing-library/dom": "^7.2.1",
30
+ "@testing-library/jest-dom": "^5.5.0",
31
+ "babel-jest": "^25.5.1",
32
+ "jest": "^25.3.0",
33
+ "moment": "^2.29.1",
34
+ "serve": "^11.3.0"
35
+ },
20
36
  "bugs": {
21
37
  "url": ""
22
38
  },
@@ -24,5 +40,10 @@
24
40
  "whitelistedNonPeerDependencies": [],
25
41
  "main": "src/index.js",
26
42
  "module": "src/index.js",
27
- "sideEffects": false
43
+ "sideEffects": false,
44
+ "jest": {
45
+ "setupFiles": [
46
+ "./setup-jest.js"
47
+ ]
48
+ }
28
49
  }
@@ -1,6 +1,5 @@
1
1
  const SERIES_CLASSNAMES = {
2
2
  WATERFALL_BREAKDOWN: 'waterfallBreakdown',
3
- WATERFALL_WALKTHROUGH: 'waterfallWalkthrough',
4
3
  TOTAL_SERIES: 'totalSeries',
5
4
  TREND_SERIES: 'trendSeries',
6
5
  };
@@ -26,7 +25,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
26
25
  const textColor = "#151a41";
27
26
  const chartLabelColor = "#cfd7dd";
28
27
  const HIGHCHARTS_FONT_FAMILY = 'Poppins';
29
- let firstBarColor = null;
30
28
 
31
29
  if(!Highcharts){
32
30
  Highcharts = {
@@ -84,16 +82,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
84
82
  KPI_WIDGET: 'kpi-widget',
85
83
  TEXT_WIDGET: 'text-widget',
86
84
  WATERFALL_BREAKDOWN: 'waterfall-chart-breakdown',
87
- WATERFALL_WALKTHROUGH: 'waterfall-chart-walkthrough',
88
85
  PUBLISHED_ITEM: 'published_item',
89
86
  RICH_TEXT: 'rich_text',
90
87
  EXCEL_VIEWER: 'excel_viewer',
91
88
  };
92
89
 
93
- highchartsRenderer.VIRTUAL_FIELDS = {
94
- WATERFALL_VARIANCE: 'DR_WATERFALL_BREAKDOWN_VARIANCE',
95
- };
96
-
97
90
  highchartsRenderer.highcharts_theme = {
98
91
  "colors": highchartsRenderer.defaults_colors,
99
92
  "chart": {
@@ -469,7 +462,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
469
462
  highchartsRenderer.getOthersName(opts) :
470
463
  undefined;
471
464
  var drOthersInColumn = lodash.find(
472
- pivotData.getColKeys(),
465
+ pivotData.getColKeys(),
473
466
  keys => keys.length && (lodash.includes(keys, 'DR_Others') || lodash.includes(keys, othersName))
474
467
  );
475
468
 
@@ -489,7 +482,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
489
482
  rows = [];
490
483
  }
491
484
 
492
- var cols = lodash.get(this, 'point.options.colsForTotal') || this.key;
485
+ var cols = this.key;
493
486
  if (typeof (cols) == 'object' && cols.name) {
494
487
  cols = cols.name;
495
488
  }
@@ -497,7 +490,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
497
490
  if (!cols && is_drill_down_pie) {
498
491
  cols = this.point.name;
499
492
  }
500
-
493
+
501
494
  if (drOthersInColumn) {
502
495
  if (!lodash.isArray(cols) && othersName === cols) {
503
496
  cols = ['DR_Others'];
@@ -635,8 +628,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
635
628
  || this.series.options.className === 'trendSeries') {
636
629
  rows = [];
637
630
  }
638
-
639
- var cols = lodash.get(this, 'point.options.colsForTotal') || this.key;
631
+ var cols = this.key;
640
632
  if (!cols && is_drill_down_pie) {
641
633
  cols = this.name;
642
634
  }
@@ -659,9 +651,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
659
651
  rows = temp;
660
652
  }
661
653
 
662
- var category_text = `<span style="font-weight: bold;">
663
- ${ lodash.get(this, 'point.options.colsForTotal') ? cols[0] : cols } ${ isWaterfallBreakdown ? ': ' : ' ' }
664
- </span>`;
654
+ var category_text = `<span style="font-weight: bold;">${ cols }${ isWaterfallBreakdown ? ': ' : ' ' }</span>`;
665
655
  if (this.category) {
666
656
  category_text = '';
667
657
  }
@@ -678,7 +668,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
678
668
  const modifiedRowsAndCols = highchartsRenderer.transformRowsAndColsForBreakdown(rows, cols, this.point, opts);
679
669
  rows = modifiedRowsAndCols.rows;
680
670
  cols = modifiedRowsAndCols.cols;
681
- }
671
+ }
682
672
 
683
673
  var aggr = pivotData.getAggregator(rows, cols);
684
674
 
@@ -1354,6 +1344,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1354
1344
  const chart_series = [];
1355
1345
  const row_n_keys = pivotData.getRowKeys();
1356
1346
  const col_n_keys = pivotData.getColKeys();
1347
+ const hasBreakdownValues = lodash.get(opts, 'breakdown_options.values.breakdown.length');
1357
1348
 
1358
1349
  let resultObject = {
1359
1350
  data: [],
@@ -1372,6 +1363,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1372
1363
  lodash.forEach(col_n_keys, function(col_n_value, col_index) {
1373
1364
 
1374
1365
  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;
1375
1368
  resultObject.data.push({
1376
1369
  y: totalColumnValue,
1377
1370
  name: lodash.unescape(col_n_value).replace('DR_Others', highchartsRenderer.getOthersName(opts)),
@@ -1383,7 +1376,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1383
1376
  if (col_index !== col_n_keys.length - 1) {
1384
1377
  lodash.forEach(row_n_keys, function (row_n_value) {
1385
1378
  const agg = pivotData.getAggregator(row_n_value, col_n_value);
1386
- let val = agg.value();
1379
+ let val = hasBreakdownValues
1380
+ ? agg.value()
1381
+ : nextTotalColumnValue - totalColumnValue;
1387
1382
 
1388
1383
  val = $.isNumeric(val) ? parseFloat(val) : 0;
1389
1384
  if (val) {
@@ -1394,7 +1389,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1394
1389
  if (tmoobj.name) {
1395
1390
  tmoobj.name = tmoobj.name.replace('DR_Others', highchartsRenderer.getOthersName(opts));
1396
1391
  }
1397
-
1398
1392
  if (lodash.isEmpty(String(tmoobj.name))) {
1399
1393
  tmoobj.name = lodash.unescape(col_n_value);
1400
1394
  tmoobj.visible = false;
@@ -1404,12 +1398,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1404
1398
  tmoobj.colKeys = [lodash.unescape(col_n_keys[col_index - 1]), lodash.unescape(col_n_value)];
1405
1399
  resultObject.data.push(tmoobj);
1406
1400
  }
1407
-
1408
1401
  });
1409
1402
  }
1410
1403
  });
1411
1404
 
1412
1405
  chart_series.push(resultObject);
1406
+
1413
1407
  opts.chart_series = [];
1414
1408
  if (!lodash.isEqual(row_n_keys, EMPTY_ROW_N_KEYS)) {
1415
1409
  chart_series.forEach(series => {
@@ -1420,89 +1414,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1420
1414
  return chart_series;
1421
1415
  }
1422
1416
 
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
-
1506
1417
  highchartsRenderer.setChartTypeBySeriesType = function (type, series) {
1507
1418
  const types = {
1508
1419
  'line-chart': 'line',
@@ -1706,7 +1617,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1706
1617
  highchartsRenderer.getDataLabelsStylesForDrillDown = function(additionOptions) {
1707
1618
  let result = highchartsRenderer.getDataLabelsOptions(additionOptions, { dataLabels: {} });
1708
1619
 
1709
- if (!result.dataLabels) return {};
1620
+ if (!result.dataLabels) return {};
1710
1621
  return {
1711
1622
  activeDataLabelStyle: {
1712
1623
  color: result.dataLabels.color,
@@ -3262,7 +3173,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3262
3173
 
3263
3174
  highchartsRenderer.ptRenderWaterfallBreakdown = function (pivotData, opts, drilldownFunc, chartType) {
3264
3175
  let chartOptions = {};
3265
- const additionOptions = opts.chartOptions
3176
+ const additionOptions = opts.chartOptions
3266
3177
  ? opts.chartOptions
3267
3178
  : highchartsRenderer.getDefaultValueForChart(highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN);
3268
3179
 
@@ -3361,122 +3272,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3361
3272
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3362
3273
  };
3363
3274
 
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
-
3480
3275
  highchartsRenderer.formatFieldValue = function (field, value) {
3481
3276
  let currentType = '';
3482
3277
  let format = field.format;
@@ -4545,17 +4340,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4545
4340
  }
4546
4341
  };
4547
4342
 
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
-
4559
4343
  highchartsRenderer.rhPivotView = function (rowData, options, isTable = false, widget = null) {
4560
4344
  if (!rowData || !rowData) {
4561
4345
  if (options.onlyOptions) {
@@ -4564,15 +4348,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4564
4348
  return null;
4565
4349
  }
4566
4350
 
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;
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;
4576
4355
  const uniqueCategories = lodash.filter(
4577
4356
  lodash.uniq(
4578
4357
  lodash.map(rowData, row => row[widget.cols[0].name])
@@ -4582,8 +4361,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4582
4361
 
4583
4362
  if (uniqueCategories && (uniqueCategories.length > maxCategories || uniqueCategories.length < minCategories )) {
4584
4363
  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. `;
4587
4364
  options.error_params = {
4588
4365
  title: 'Data Conflict',
4589
4366
  text: `Please adjust your dashboard's reference date and filter selections as \
@@ -4832,25 +4609,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4832
4609
  return highchartsRenderer.getWeekNumber(dateObj);
4833
4610
  };
4834
4611
 
4835
- highchartsRenderer.check_values_not_for_convert = function (currentgraph, field_name) {
4836
- let vals_not_convert = [];
4612
+ highchartsRenderer.check_value_not_for_convert = function (currentgraph, field_name) {
4613
+ let val_not_convert = null;
4837
4614
  if (lodash.has(currentgraph, "options.chartOptions.delta_column") && currentgraph.options.chartOptions.delta_column) {
4838
4615
  let delta_options = currentgraph.options.chartOptions.delta_column;
4839
4616
  if (delta_options.field == 'series' && currentgraph.rows && currentgraph.rows[0] &&
4840
4617
  currentgraph.rows[0].name == field_name) {
4841
- vals_not_convert = [delta_options.name];
4618
+ val_not_convert = delta_options.name;
4842
4619
  } else if (delta_options.field == 'category' && currentgraph.rows && currentgraph.cols[0] &&
4843
4620
  currentgraph.cols[0].name == field_name) {
4844
- vals_not_convert = [delta_options.name];
4621
+ val_not_convert = delta_options.name;
4845
4622
  }
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
- });
4852
4623
  }
4853
- return vals_not_convert;
4624
+ return val_not_convert;
4854
4625
  };
4855
4626
 
4856
4627
  highchartsRenderer.updateFiltersShowNames = function (filters) {
@@ -4870,8 +4641,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4870
4641
  })
4871
4642
  };
4872
4643
 
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)) {
4644
+ highchartsRenderer.returnRawDataValue = function (type, value, format, field_name, val_not_for_convert) {
4645
+ if (val_not_for_convert && val_not_for_convert == value) {
4875
4646
  return value;
4876
4647
  }
4877
4648
 
@@ -5183,28 +4954,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5183
4954
  }
5184
4955
  });
5185
4956
 
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
-
5198
4957
  // fill rows fields
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
- }
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});
5208
4963
  }
5209
4964
  });
5210
4965
 
@@ -5894,7 +5649,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5894
5649
  return valToReturn;
5895
5650
  };
5896
5651
 
5897
-
5652
+
5898
5653
  highchartsRenderer.getChartAxisLabel = function(type) {
5899
5654
  return highchartsRenderer.chartsTypesInfo[type] ? highchartsRenderer.chartsTypesInfo[type].axisName : CHART_AXIS_DEFAULT_LABEL;
5900
5655
  };
@@ -6729,7 +6484,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6729
6484
  value_name: 'show',
6730
6485
  default_value: true,
6731
6486
  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',
6732
- disabled_fn: (value) => !value.show_out_of_x_axis
6487
+ disabled_fn: (value) => !value.show_out_of_x_axis
6733
6488
  && !value.show_out_of_data_series
6734
6489
  && !value.show_value
6735
6490
  && !value.show_x_axis
@@ -6770,8 +6525,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6770
6525
  element_label: '[X Axis]',
6771
6526
  value_name: 'show_x_axis',
6772
6527
  default_value: true,
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
6528
+ clickFn: (value) => value.show = value.show
6529
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6775
6530
  : value.show,
6776
6531
  },
6777
6532
  {
@@ -6779,8 +6534,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6779
6534
  element_label: '[Data Series]',
6780
6535
  value_name: 'show_data_series',
6781
6536
  default_value: true,
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
6537
+ clickFn: (value) => value.show = value.show
6538
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6784
6539
  : value.show,
6785
6540
  },
6786
6541
  {
@@ -6788,8 +6543,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6788
6543
  element_label: 'Value',
6789
6544
  value_name: 'show_value',
6790
6545
  default_value: true,
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
6546
+ clickFn: (value) => value.show = value.show
6547
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6793
6548
  : value.show,
6794
6549
  },
6795
6550
  {
@@ -6797,8 +6552,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6797
6552
  element_label: '% Out of [X Axis]',
6798
6553
  value_name: 'show_out_of_x_axis',
6799
6554
  default_value: false,
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
6555
+ clickFn: (value) => value.show = value.show
6556
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6802
6557
  : value.show,
6803
6558
  },
6804
6559
  {
@@ -6806,8 +6561,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6806
6561
  element_label: '% Out of [Data Series]',
6807
6562
  value_name: 'show_out_of_data_series',
6808
6563
  default_value: false,
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
6564
+ clickFn: (value) => value.show = value.show
6565
+ ? value.show_out_of_x_axis || value.show_out_of_data_series || value.show_value || value.show_x_axis || value.show_data_series
6811
6566
  : value.show,
6812
6567
  },
6813
6568
  ]
@@ -6981,16 +6736,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
6981
6736
  value_name: 'name',
6982
6737
  element_label: 'Name',
6983
6738
  default_value: '_Variance'
6984
- }, {
6985
- element_type: 'input',
6986
- value_name: 'formula',
6987
- element_label: 'Formula',
6988
- default_value: 'x2-x1'
6989
6739
  }, {
6990
6740
  element_type: 'input',
6991
- value_name: 'color',
6992
- element_label: 'Color',
6993
- default_value: ''
6741
+ value_name: 'formula',
6742
+ element_label: 'Formula',
6743
+ default_value: 'x2-x1'
6744
+ }, {
6745
+ element_type: 'input',
6746
+ value_name: 'color',
6747
+ element_label: 'Color',
6748
+ default_value: ''
6994
6749
  }, {
6995
6750
  element_type: 'radio',
6996
6751
  value_name: 'chart',
@@ -7113,17 +6868,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7113
6868
  axisTooltipDescription: 'The category (usually an independent variable) is shown on the x-axis and should be between 2 to 5 total columns. ',
7114
6869
  legendTooltipTitle: 'Drag one field to further configure your x-axis.',
7115
6870
  legendTooltipDescription: 'The breakdown subdivides the chart by a category field for further analysis of what’s contributing to the increase or decrease.',
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
- },
6871
+ },
7127
6872
  'combo-chart': {
7128
6873
  name: 'Combo Chart ',
7129
6874
  label: 'Combo Chart ',
@@ -7779,24 +7524,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7779
7524
  highchartsRenderer.suboptions["legends"],
7780
7525
  ]
7781
7526
  },
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
- },
7800
7527
  ]
7801
7528
  },
7802
7529
  ];
@@ -7953,7 +7680,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7953
7680
  _.forEach(Object.keys(dates), key => {
7954
7681
  const dateConfiguration = dates[key];
7955
7682
  const timestamp = dateConfiguration.timestamp;
7956
- if (timestamp) {
7683
+ if (timestamp) {
7957
7684
  const dateTzOffsetInSeconds = new Date(timestamp * 1000).getTimezoneOffset() * 60;
7958
7685
  dateConfiguration.displayedValue = new Date((timestamp + dateTzOffsetInSeconds) * 1000)
7959
7686
  .toLocaleDateString();
@@ -8249,10 +7976,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8249
7976
  };
8250
7977
 
8251
7978
  highchartsRenderer.createDateFromString = function (dateString, format) {
8252
- if (!(format && highchartsRenderer.isDateFormat(dateString, format) || highchartsRenderer.isDate(dateString))) {
7979
+ if ((format && !highchartsRenderer.isDateFormat(dateString, format)) || !highchartsRenderer.isDate(dateString)) {
8253
7980
  return null;
8254
7981
  }
8255
- const utcDate = format
7982
+ const utcDate = format
8256
7983
  ? moment_lib.utc(dateString, format, true)
8257
7984
  : moment_lib.utc(dateString);
8258
7985
  return utcDate.startOf('day').unix();
@@ -8270,7 +7997,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8270
7997
  }
8271
7998
 
8272
7999
  let filters = [];
8273
-
8000
+
8274
8001
  if (widget.chart_type === highchartsRenderer.CHART_TYPES.WATERFALL_BREAKDOWN) {
8275
8002
  const colFilter = highchartsRenderer.createFilterObject(widget.cols[0]);
8276
8003
  const labels = [];
@@ -8298,7 +8025,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8298
8025
  col_value,
8299
8026
  highchartsRenderer.getDateFieldFormat(widget, widget.cols[index])
8300
8027
  );
8301
-
8028
+
8302
8029
  if ($.isEmptyObject(datetrange)) {
8303
8030
  return;
8304
8031
  }
@@ -8403,7 +8130,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8403
8130
  filter.is_excluded = false;
8404
8131
  } else {
8405
8132
  filter = highchartsRenderer.createDrillDownFilterObject(widget, widget.cols[0], colKey[0]);
8406
- filters.push(filter);
8407
8133
  }
8408
8134
  filter.values = [];
8409
8135
  for (let i = 0; i < colKey.length; i++) {
@@ -8541,7 +8267,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8541
8267
  var data = res;
8542
8268
 
8543
8269
  lodash.forEach(datesFields, function (row) {
8544
- row.val_not_convert = highchartsRenderer.check_values_not_for_convert(widget, row.name);
8270
+ row.val_not_convert = highchartsRenderer.check_value_not_for_convert(widget, row.name);
8545
8271
  });
8546
8272
 
8547
8273
  if (datesFields.length > 0) {
@@ -8947,14 +8673,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8947
8673
  return rightPosition;
8948
8674
  case 'none':
8949
8675
  return none;
8950
- }
8951
- } else if (isLine) {
8952
- return useNewUx ? leftPosition : rightPosition;
8953
- } else if (isPie) {
8954
- return useNewUx ? rightPosition : topPosition;
8955
8676
  }
8677
+ } else if (isLine) {
8678
+ return useNewUx ? leftPosition : rightPosition;
8679
+ } else if (isPie) {
8680
+ return useNewUx ? rightPosition : topPosition;
8681
+ }
8956
8682
 
8957
- return useNewUx ? topPosition : bottomPosition;
8683
+ return useNewUx ? topPosition : bottomPosition;
8958
8684
  }
8959
8685
 
8960
8686
  highchartsRenderer.setYAxisMinMax = function (yAxis, axisYOptions) {
@@ -8969,7 +8695,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8969
8695
  }
8970
8696
 
8971
8697
  highchartsRenderer.getDateFieldFormat = function(widget, dateField) {
8972
- const aggregationConfig = widget.options && widget.options.date_aggregation_configs
8698
+ const aggregationConfig = widget.options && widget.options.date_aggregation_configs
8973
8699
  ? _.find(widget.options.date_aggregation_configs, { field_id: dateField.id })
8974
8700
  : null;
8975
8701
 
@@ -0,0 +1,48 @@
1
+ import * as $ from 'jquery';
2
+ import * as lodash from 'lodash';
3
+ import * as moment from 'moment';
4
+ import initPivotTable from "../src/pivottable";
5
+ import initDRPivotTable from "../src/dr_pivottable";
6
+
7
+ const getHighchartsRenderer = require('../src/highcharts_renderer');
8
+ const DataFormatter = require('../src/dataformatter');
9
+ const DEFAULT_USER_COLORS = {
10
+ colors: ['#008aff', '#91e7e7', '#f37789', '#ffdc65', '#0e569d', '#bbe0ff', '#57b2ff', '#5ecfb9', '#c7ffda', '#179ab9'],
11
+ variance_color: null
12
+ };
13
+
14
+ let highchartsRenderer = {};
15
+ let _window = window;
16
+ let _document = document;
17
+
18
+ describe('highcharts_renderer', () => {
19
+ beforeAll(() => {
20
+ const Highcharts = {
21
+ opt: {},
22
+ setOptions: function(value) {Highcharts.opt = value;},
23
+ numberFormat: function(value) { return value ;},
24
+ getOptions: function() { return Highcharts.opt; }
25
+ };
26
+ _window.DataFormatter = DataFormatter;
27
+ initPivotTable($, _window, _document);
28
+ initDRPivotTable($, _window, _document);
29
+
30
+ highchartsRenderer = getHighchartsRenderer($, _document, Highcharts, DEFAULT_USER_COLORS, highchartsRenderer,
31
+ DataFormatter, lodash, moment, true)
32
+ })
33
+
34
+ describe('function isSystemField', () => {
35
+ it('system name', () => {
36
+ const field = {
37
+ name: 'Doc_ID'
38
+ };
39
+ expect(highchartsRenderer.isSystemField(field)).toBe(true)
40
+ });
41
+ it('not system name', () => {
42
+ const field = {
43
+ name: 'field name'
44
+ };
45
+ expect(highchartsRenderer.isSystemField(field)).toBe(false)
46
+ });
47
+ });
48
+ });