@datarailsshared/dr_renderer 1.4.116 → 1.4.118

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.118",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -702,11 +702,14 @@ 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
+ cols = pivotData.getColKeys()[0];
710
713
  }
711
714
 
712
715
  if (pivotData.rowAttrs.length == 0
@@ -715,7 +718,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
715
718
  rows = [];
716
719
  }
717
720
 
718
- var cols = highchartsRenderer.getColsInFormatterContext(this);
719
721
  if (typeof (cols) == 'object' && cols && cols.name) {
720
722
  cols = cols.name;
721
723
  }
@@ -740,7 +742,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
740
742
  try {
741
743
  const percentageArray = [];
742
744
 
743
- if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name, "Series ")) {
745
+ if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name, "Series ") && !isChartWithMultiValues) {
744
746
  let temp = cols;
745
747
  cols = rows;
746
748
  rows = temp;
@@ -863,18 +865,22 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
863
865
  var y = parseFloat(this.y);
864
866
 
865
867
  if (pivotData) {
868
+ const isChartWithMultiValues = highchartsRenderer.isChartWithMultiValues(pivotData);
866
869
  let series_name = highchartsRenderer.getSeriesNameInFormatterContext(this);
867
870
  var rows = series_name.split(highchartsRenderer.delimer);
868
- if (is_drill_down_pie && highchartsRenderer.selfStartsWith(series_name,"Series ")) {
871
+ var cols = highchartsRenderer.getColsInFormatterContext(this);
872
+
873
+ if (is_drill_down_pie && (highchartsRenderer.selfStartsWith(series_name,"Series ") || isChartWithMultiValues)) {
869
874
  rows = [];
875
+ cols = pivotData.getColKeys()[0];
870
876
  }
877
+
871
878
  if (pivotData.rowAttrs.length == 0
872
879
  || this.series.options.className === 'totalSeries'
873
880
  || isTrendSeries) {
874
881
  rows = [];
875
882
  }
876
883
 
877
- var cols = highchartsRenderer.getColsInFormatterContext(this);
878
884
  if (lodash.isNil(cols) && is_drill_down_pie) {
879
885
  cols = this.name;
880
886
  }
@@ -891,7 +897,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
891
897
  }
892
898
 
893
899
  try {
894
- if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name,"Series ")) {
900
+ if (is_drill_down_pie && !highchartsRenderer.selfStartsWith(series_name,"Series ") && !isChartWithMultiValues) {
895
901
  let temp = cols;
896
902
  cols = rows;
897
903
  rows = temp;
@@ -932,9 +938,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
932
938
  var aggr = pivotData.getAggregator(rows, cols);
933
939
 
934
940
  let formatted_value_to_return = $.pivotUtilities.getFormattedNumber(y, null, opts);
935
- if (aggr.value() || isWaterfallBreakdown) {
941
+ if (aggr.value() || isWaterfallBreakdown || isChartWithMultiValues) {
936
942
  formatted_value_to_return = $.pivotUtilities.getFormattedNumber(
937
- isWaterfallBreakdown || isWaterfallWalkthrough || isTrendSeries ? y : aggr.value(), aggr, opts
943
+ isChartWithMultiValues || isWaterfallBreakdown || isWaterfallWalkthrough || isTrendSeries ? y : aggr.value(), aggr, opts
938
944
  );
939
945
  }
940
946
 
@@ -2056,17 +2062,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2056
2062
  col_ob.name = highchartsRenderer.getFormattedColKey(col_ob.initialName, pivotData);
2057
2063
  col_ob.data = [];
2058
2064
  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);
2065
+ var agg = pivotData.getAggregator(row_n_value, col_n_value);
2063
2066
  var val = agg.value();
2064
- if (val != null && rowKey[0]) {
2067
+ if (val != null && row_n_value.length) {
2065
2068
  if ($.isNumeric(val)) {
2066
2069
  val = parseFloat(val);
2067
2070
  }
2068
2071
 
2069
- const row_initial_name = rowKey[0] === highchartsRenderer.DR_OTHERS_KEY ? othersName : rowKey;
2072
+ const row_initial_name = row_n_value[0] === highchartsRenderer.DR_OTHERS_KEY ? othersName : row_n_value;
2070
2073
  const row_name = highchartsRenderer.getFormattedRowKey(row_initial_name, pivotData);
2071
2074
  col_ob.data.push({
2072
2075
  name: row_name,
@@ -2075,11 +2078,20 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2075
2078
  });
2076
2079
  }
2077
2080
  });
2081
+
2082
+ col_ob.data = Object.values(
2083
+ lodash.reduce(col_ob.data, (acc, item) => {
2084
+ const key = Array.isArray(item.name) ? item.name[0] : item.name;
2085
+ const name = key ? [key] : [col_n];
2086
+ if (!acc[key]) {
2087
+ acc[key] = { name: name, initialName: name, y: 0 };
2088
+ }
2089
+ acc[key].y += item.y;
2090
+ return acc;
2091
+ }, {})
2092
+ );
2093
+
2078
2094
  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
2095
  pie_drill_down_series.push(col_ob);
2084
2096
  }
2085
2097
  }
@@ -9980,7 +9992,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9980
9992
 
9981
9993
  // Check if chart has multiple values
9982
9994
  highchartsRenderer.isChartWithMultiValues = function(pivotData) {
9983
- return lodash.get(pivotData, 'rowAttrs[0]') === 'DR_Values';
9995
+ return lodash.some(lodash.get(pivotData, 'rowAttrs'), attr => attr === 'DR_Values');
9984
9996
  }
9985
9997
 
9986
9998
  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: {
@@ -658,6 +660,17 @@ describe('highcharts_renderer', () => {
658
660
  expect(result).toBe('500');
659
661
  });
660
662
 
663
+ it('should handle drill-down pie when is a multi values chart', () => {
664
+ highchartsRenderer.isChartWithMultiValues.and.returnValue(true);
665
+
666
+ opts = { chartOptions: {} };
667
+ let fn = highchartsRenderer.defaultDataLabelFormatter(mockPivotData, opts, true);
668
+ let result = fn.call(funcContext);
669
+
670
+ expect(highchartsRenderer.isChartWithMultiValues).toHaveBeenCalledWith(mockPivotData);
671
+ expect(result).toBe('500');
672
+ });
673
+
661
674
  it('should use point name for columns when cols is null in drill-down pie', () => {
662
675
  highchartsRenderer.getColsInFormatterContext.and.returnValue(null);
663
676
  funcContext.point.name = 'DrillDownPoint';
@@ -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', () => {