@datarailsshared/dr_renderer 1.4.116 → 1.4.121

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.4.116",
3
+ "version": "1.4.121",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -702,11 +702,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
702
702
  var value = parseFloat(this.y);
703
703
 
704
704
  if (pivotData) {
705
+ const isChartWithMultiValues = highchartsRenderer.isChartWithMultiValues(pivotData);
705
706
  let series_name = highchartsRenderer.getSeriesNameInFormatterContext(this);
706
707
  var rows = series_name.split(highchartsRenderer.delimer);
708
+ var cols = highchartsRenderer.getColsInFormatterContext(this);
707
709
 
708
- if (is_drill_down_pie && highchartsRenderer.selfStartsWith(series_name, "Series ")) {
710
+ if (is_drill_down_pie && (highchartsRenderer.selfStartsWith(series_name, "Series ") || isChartWithMultiValues)) {
709
711
  rows = [];
712
+
713
+ if (isChartWithMultiValues) {
714
+ cols = pivotData.getColKeys()[0];
715
+ }
710
716
  }
711
717
 
712
718
  if (pivotData.rowAttrs.length == 0
@@ -715,7 +721,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
715
721
  rows = [];
716
722
  }
717
723
 
718
- var cols = highchartsRenderer.getColsInFormatterContext(this);
719
724
  if (typeof (cols) == 'object' && cols && cols.name) {
720
725
  cols = cols.name;
721
726
  }
@@ -740,7 +745,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
740
745
  try {
741
746
  const percentageArray = [];
742
747
 
743
- if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name, "Series ")) {
748
+ if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name, "Series ") && !isChartWithMultiValues) {
744
749
  let temp = cols;
745
750
  cols = rows;
746
751
  rows = temp;
@@ -863,18 +868,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
863
868
  var y = parseFloat(this.y);
864
869
 
865
870
  if (pivotData) {
871
+ const isChartWithMultiValues = highchartsRenderer.isChartWithMultiValues(pivotData);
866
872
  let series_name = highchartsRenderer.getSeriesNameInFormatterContext(this);
867
873
  var rows = series_name.split(highchartsRenderer.delimer);
868
- if (is_drill_down_pie && highchartsRenderer.selfStartsWith(series_name,"Series ")) {
874
+ var cols = highchartsRenderer.getColsInFormatterContext(this);
875
+
876
+ if (is_drill_down_pie && (highchartsRenderer.selfStartsWith(series_name,"Series ") || isChartWithMultiValues)) {
869
877
  rows = [];
878
+
879
+ if (isChartWithMultiValues) {
880
+ cols = pivotData.getColKeys()[0];
881
+ }
870
882
  }
883
+
871
884
  if (pivotData.rowAttrs.length == 0
872
885
  || this.series.options.className === 'totalSeries'
873
886
  || isTrendSeries) {
874
887
  rows = [];
875
888
  }
876
889
 
877
- var cols = highchartsRenderer.getColsInFormatterContext(this);
878
890
  if (lodash.isNil(cols) && is_drill_down_pie) {
879
891
  cols = this.name;
880
892
  }
@@ -891,7 +903,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
891
903
  }
892
904
 
893
905
  try {
894
- if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name,"Series ")) {
906
+ if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name,"Series ") && !isChartWithMultiValues) {
895
907
  let temp = cols;
896
908
  cols = rows;
897
909
  rows = temp;
@@ -932,9 +944,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
932
944
  var aggr = pivotData.getAggregator(rows, cols);
933
945
 
934
946
  let formatted_value_to_return = $.pivotUtilities.getFormattedNumber(y, null, opts);
935
- if (aggr.value() || isWaterfallBreakdown) {
947
+ if (aggr.value() || isWaterfallBreakdown || isChartWithMultiValues) {
936
948
  formatted_value_to_return = $.pivotUtilities.getFormattedNumber(
937
- isWaterfallBreakdown || isWaterfallWalkthrough || isTrendSeries ? y : aggr.value(), aggr, opts
949
+ isChartWithMultiValues || isWaterfallBreakdown || isWaterfallWalkthrough || isTrendSeries ? y : aggr.value(), aggr, opts
938
950
  );
939
951
  }
940
952
 
@@ -2056,17 +2068,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2056
2068
  col_ob.name = highchartsRenderer.getFormattedColKey(col_ob.initialName, pivotData);
2057
2069
  col_ob.data = [];
2058
2070
  lodash.forEach(row_n_keys, function (row_n_value) {
2059
- // always takes the first key during drilldown,
2060
- // we are only supporting one level drilldown but pivot table could have multiple nested row keys
2061
- const rowKey = [row_n_value[0]];
2062
- var agg = pivotData.getAggregator(rowKey, col_n_value);
2071
+ var agg = pivotData.getAggregator(row_n_value, col_n_value);
2063
2072
  var val = agg.value();
2064
- if (val != null && rowKey[0]) {
2073
+ if (val != null && row_n_value.length) {
2065
2074
  if ($.isNumeric(val)) {
2066
2075
  val = parseFloat(val);
2067
2076
  }
2068
2077
 
2069
- const row_initial_name = rowKey[0] === highchartsRenderer.DR_OTHERS_KEY ? othersName : rowKey;
2078
+ const row_initial_name = row_n_value[0] === highchartsRenderer.DR_OTHERS_KEY ? othersName : row_n_value;
2070
2079
  const row_name = highchartsRenderer.getFormattedRowKey(row_initial_name, pivotData);
2071
2080
  col_ob.data.push({
2072
2081
  name: row_name,
@@ -2075,11 +2084,20 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2075
2084
  });
2076
2085
  }
2077
2086
  });
2087
+
2088
+ col_ob.data = Object.values(
2089
+ lodash.reduce(col_ob.data, (acc, item) => {
2090
+ const key = Array.isArray(item.name) ? item.name[0] : item.name;
2091
+ const name = key ? [key] : [col_n];
2092
+ if (!acc[key]) {
2093
+ acc[key] = { name: name, initialName: name, y: 0 };
2094
+ }
2095
+ acc[key].y += item.y;
2096
+ return acc;
2097
+ }, {})
2098
+ );
2099
+
2078
2100
  if (col_ob.data.length) {
2079
- // filtering out when there are multiple data series
2080
- col_ob.data = lodash.uniqBy(col_ob.data, item =>
2081
- Array.isArray(item.name) ? item.name.join(highchartsRenderer.delimer) : item.name
2082
- );
2083
2101
  pie_drill_down_series.push(col_ob);
2084
2102
  }
2085
2103
  }
@@ -9980,7 +9998,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9980
9998
 
9981
9999
  // Check if chart has multiple values
9982
10000
  highchartsRenderer.isChartWithMultiValues = function(pivotData) {
9983
- return lodash.get(pivotData, 'rowAttrs[0]') === 'DR_Values';
10001
+ return lodash.some(lodash.get(pivotData, 'rowAttrs'), attr => attr === 'DR_Values');
9984
10002
  }
9985
10003
 
9986
10004
  highchartsRenderer.checkFormats = function(render_options, widget_values_format) {
@@ -545,6 +545,7 @@ describe('highcharts_renderer', () => {
545
545
  mockPivotData = {
546
546
  rowAttrs: ['row1'],
547
547
  colAttrs: ['col1'],
548
+ getColKeys: jest.fn(() => [['col1'], ['col2']]),
548
549
  getRowKeys: jest.fn(() => [['row1'], ['row2']]),
549
550
  getAggregator: jest.fn(() => ({
550
551
  value: () => 1000
@@ -561,6 +562,7 @@ describe('highcharts_renderer', () => {
561
562
  });
562
563
  spyOn(highchartsRenderer, 'replaceDrOthersKeys');
563
564
  spyOn(highchartsRenderer, 'selfStartsWith').and.returnValue(false);
565
+ spyOn(highchartsRenderer, 'isChartWithMultiValues').and.returnValue(true);
564
566
 
565
567
  global.$ = {
566
568
  pivotUtilities: {
@@ -646,15 +648,28 @@ describe('highcharts_renderer', () => {
646
648
  funcContext.y = 500;
647
649
  });
648
650
 
649
- it('should handle drill-down pie when series name starts with "Series "', () => {
651
+ it('should handle drill-down pie when series name starts with "Series " and chart does not have multi values', () => {
650
652
  highchartsRenderer.selfStartsWith.and.returnValue(true);
651
653
  highchartsRenderer.getSeriesNameInFormatterContext.and.returnValue('Series 1');
654
+ highchartsRenderer.isChartWithMultiValues.and.returnValue(false);
652
655
 
653
656
  opts = { chartOptions: {} };
654
657
  let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts, true);
655
658
  let result = fn.call(funcContext);
656
659
 
657
660
  expect(highchartsRenderer.selfStartsWith).toHaveBeenCalledWith('Series 1', 'Series ');
661
+ expect(highchartsRenderer.isChartWithMultiValues).toHaveBeenCalledWith(mockPivotData);
662
+ expect(result).toBe('500');
663
+ });
664
+
665
+ it('should handle drill-down pie when is a multi values chart', () => {
666
+ highchartsRenderer.isChartWithMultiValues.and.returnValue(true);
667
+
668
+ opts = { chartOptions: {} };
669
+ let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts, true);
670
+ let result = fn.call(funcContext);
671
+
672
+ expect(highchartsRenderer.isChartWithMultiValues).toHaveBeenCalledWith(mockPivotData);
658
673
  expect(result).toBe('500');
659
674
  });
660
675
 
@@ -405,6 +405,26 @@ describe('ptCreateDrillDownSeriesToDrilldownChart', () => {
405
405
  );
406
406
  expect(highchartsRenderer.getDataLabelsStylesForDrillDown).toHaveBeenCalledWith(mockAdditionOptions);
407
407
  });
408
+
409
+ it('should merge values when row name is a plain string (not array)', () => {
410
+ jest.spyOn(highchartsRenderer, 'getFormattedRowKey').mockImplementation(name => name);
411
+
412
+ mockPivotData.getRowKeys.mockReturnValue([ 'PLAIN_STRING_NAME' ]);
413
+ mockPivotData.getColKeys.mockReturnValue([ ['valid-key'] ]);
414
+ mockPivotData.getAggregator.mockImplementation(() => ({ value: () => 100 }));
415
+
416
+ const result = highchartsRenderer.ptCreateDrillDownSeriesToDrilldownChart(
417
+ mockPivotData,
418
+ mockChartOptions,
419
+ mockAdditionOptions,
420
+ mockOpts
421
+ );
422
+
423
+ expect(result.series).toHaveLength(1);
424
+ const dataPoint = result.series[0].data[0];
425
+ expect(dataPoint.name).toEqual(['PLAIN_STRING_NAME']);
426
+ expect(dataPoint.y).toBe(100);
427
+ });
408
428
  });
409
429
 
410
430
  describe('edge cases', () => {