@datarailsshared/dr_renderer 1.2.415 → 1.2.417

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.415",
3
+ "version": "1.2.417",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -859,7 +859,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
859
859
 
860
860
  /* model renderers */
861
861
 
862
- highchartsRenderer.tableCSVExportRenderer = function (pivotData) {
862
+ highchartsRenderer.tableCSVExportRenderer = function (pivotData, chartOptions) {
863
863
  var aggregator, colAttrs, colKey, colKeys, i, j, rowAttrs, rowKey, rowKeys, tempAr,
864
864
  totalAggregator, val;
865
865
 
@@ -867,11 +867,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
867
867
  var forExport = [];
868
868
 
869
869
  const TOTAL_CELL = 'Totals';
870
+
870
871
  colAttrs = pivotData.colAttrs;
871
872
  rowAttrs = pivotData.rowAttrs;
872
873
  rowKeys = pivotData.getRowKeys();
873
874
  colKeys = pivotData.getColKeys();
874
875
 
876
+ let isDisplayingColTotals = lodash.get(chartOptions, 'table_options.show_column_total') && colKeys.length;
877
+ let isDisplayingRowTotals = lodash.get(chartOptions, 'table_options.show_row_total') && rowKeys.length;
878
+
875
879
  for (j in colAttrs) {
876
880
  if (!hasProp.call(colAttrs, j)) continue;
877
881
  tempAr = [];
@@ -888,7 +892,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
888
892
  tempAr = tempAr.concat(lodash.map(colKeys, function (row) {
889
893
  return row[j];
890
894
  }));
891
- tempAr.push(TOTAL_CELL);
895
+
896
+ if (isDisplayingRowTotals) {
897
+ tempAr.push(TOTAL_CELL);
898
+ }
899
+
892
900
  forExport.push(tempAr);
893
901
  }
894
902
 
@@ -911,31 +919,42 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
911
919
  val = aggregator.value();
912
920
  tempAr.push(val);
913
921
  }
914
- totalAggregator = pivotData.getAggregator(rowKey, []);
915
- val = totalAggregator.value();
916
- tempAr.push(val);
922
+
923
+ if (isDisplayingRowTotals) {
924
+ totalAggregator = pivotData.getAggregator(rowKey, []);
925
+ val = totalAggregator.value();
926
+ tempAr.push(val);
927
+ }
928
+
917
929
  forExport.push(tempAr);
918
930
  }
919
931
 
920
932
  tempAr = [];
921
933
 
922
- for (j in rowAttrs) {
923
- if (!hasProp.call(rowAttrs, j)) continue;
924
- tempAr.push(TOTAL_CELL)
934
+ if (isDisplayingColTotals) {
935
+ for (j in rowAttrs) {
936
+ if (!hasProp.call(rowAttrs, j)) continue;
937
+ tempAr.push(TOTAL_CELL)
938
+ }
939
+
940
+ for (j in colKeys) {
941
+ if (!hasProp.call(colKeys, j)) continue;
942
+ colKey = colKeys[j];
943
+ aggregator = pivotData.getAggregator([], colKey);
944
+ val = aggregator.value();
945
+ tempAr.push(val);
946
+ }
925
947
  }
926
948
 
927
- for (j in colKeys) {
928
- if (!hasProp.call(colKeys, j)) continue;
929
- colKey = colKeys[j];
930
- aggregator = pivotData.getAggregator([], colKey);
931
- val = aggregator.value();
949
+ if (isDisplayingColTotals && isDisplayingRowTotals) {
950
+ totalAggregator = pivotData.getAggregator([], []);
951
+ val = totalAggregator.value();
932
952
  tempAr.push(val);
933
953
  }
934
954
 
935
- totalAggregator = pivotData.getAggregator([], []);
936
- val = totalAggregator.value();
937
- tempAr.push(val);
938
- forExport.push(tempAr);
955
+ if (tempAr.length) {
956
+ forExport.push(tempAr);
957
+ }
939
958
 
940
959
  return forExport;
941
960
  };
@@ -5962,7 +5962,15 @@ describe('highcharts_renderer', () => {
5962
5962
 
5963
5963
  describe('Function tableCSVExportRenderer', () => {
5964
5964
  window._ = lodash;
5965
- it('should create csv json object representation based on pivot data', () => {
5965
+
5966
+ it('should create csv json object representation based on pivot data (only cols)', () => {
5967
+ const chartOptions = {
5968
+ table_options: {
5969
+ show_column_total: true,
5970
+ show_row_total: true,
5971
+ },
5972
+ };
5973
+
5966
5974
  const inputs = [
5967
5975
  {
5968
5976
  "Date": 1653955200,
@@ -6026,7 +6034,7 @@ describe('highcharts_renderer', () => {
6026
6034
  },
6027
6035
  };
6028
6036
  const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6029
- const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData);
6037
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
6030
6038
  expect(csvJson).toEqual(
6031
6039
  [
6032
6040
  [ 1651363200, 1652400000, 1653177600, 1653955200, 'Totals' ],
@@ -6037,6 +6045,164 @@ describe('highcharts_renderer', () => {
6037
6045
  ]
6038
6046
  );
6039
6047
  });
6048
+
6049
+ describe('cases for both col and row present', () => {
6050
+ const inputs = [
6051
+ {
6052
+ "Date": 1653955200,
6053
+ "Type": 'Food',
6054
+ "Amount": 2849521.69
6055
+ },
6056
+ {
6057
+ "Date": 1653955200,
6058
+ "Type": 'Technology',
6059
+ "Amount": 321123
6060
+ },
6061
+ {
6062
+ "Date": 1653177600,
6063
+ "Type": 'Food',
6064
+ "Amount": 3141257.27
6065
+ },
6066
+ {
6067
+ "Date": 1653177600,
6068
+ "Type": 'Technology',
6069
+ "Amount": 4321
6070
+ },
6071
+ {
6072
+ "Date": 1653955200,
6073
+ "Amount": 123
6074
+ },
6075
+ {
6076
+ "Type": 'Technology',
6077
+ "Amount": 1
6078
+ },
6079
+ {
6080
+ "Type": 'Food',
6081
+ "Amount": 2
6082
+ },
6083
+ {
6084
+ "Date": 1653177600,
6085
+ "Amount": 321
6086
+ },
6087
+ {
6088
+ "Amount": 9834311.05
6089
+ },
6090
+ {
6091
+ "col_keys": [
6092
+ [
6093
+ 1651363200
6094
+ ],
6095
+ [
6096
+ 1653177600
6097
+ ],
6098
+ ],
6099
+ "row_keys": [
6100
+ [
6101
+ 'Food'
6102
+ ],
6103
+ [
6104
+ 'Technology'
6105
+ ]
6106
+ ]
6107
+ }
6108
+ ];
6109
+ const subOptions = {
6110
+ "sorters": () => null,
6111
+ "sortByValueAttrs": [],
6112
+ "cols": ["Date"],
6113
+ "rows": ["Type"],
6114
+ "colFormats": [
6115
+ {
6116
+ "type": "Date",
6117
+ "name": "Date",
6118
+ "val_not_convert": []
6119
+ },
6120
+ ],
6121
+ "rowFormats": [
6122
+ {
6123
+ "type": "Text",
6124
+ "name": "Type",
6125
+ "val_not_convert": []
6126
+ },
6127
+ ],
6128
+ "rendererOptions": {
6129
+ },
6130
+ };
6131
+
6132
+ it('should create csv json object representation based on pivot data, with totals', () => {
6133
+ const chartOptions = {
6134
+ table_options: {
6135
+ show_column_total: true,
6136
+ show_row_total: true,
6137
+ },
6138
+ };
6139
+ const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6140
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
6141
+ expect(csvJson).toEqual(
6142
+ [
6143
+ ["Date", 1653177600, 1653955200, "Totals"],
6144
+ ["Type"],
6145
+ ["Food", 1, 1, 1],
6146
+ ["Technology", 1, 1, 1],
6147
+ ["Totals", 1, 1, 2]
6148
+ ]
6149
+ );
6150
+ });
6151
+
6152
+ it('should create csv json object representation based on pivot data, without col totals', () => {
6153
+ const chartOptions = {
6154
+ table_options: {
6155
+ show_column_total: false,
6156
+ show_row_total: true,
6157
+ },
6158
+ };
6159
+ const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6160
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
6161
+ expect(csvJson).toEqual([
6162
+ ["Date", 1653177600, 1653955200, "Totals"],
6163
+ ["Type"],
6164
+ ["Food", 1, 1, 1],
6165
+ ["Technology", 1, 1, 1]
6166
+ ]);
6167
+ });
6168
+
6169
+ it('should create csv json object representation based on pivot data, without row totals', () => {
6170
+ const chartOptions = {
6171
+ table_options: {
6172
+ show_column_total: true,
6173
+ show_row_total: false,
6174
+ },
6175
+ };
6176
+
6177
+ const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6178
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
6179
+ expect(csvJson).toEqual([
6180
+ ["Date", 1653177600, 1653955200],
6181
+ ["Type"],
6182
+ ["Food", 1, 1],
6183
+ ["Technology", 1, 1],
6184
+ ["Totals", 1, 1]
6185
+ ]);
6186
+ });
6187
+
6188
+ it('should create csv json object representation based on pivot data, without col and row totals', () => {
6189
+ const chartOptions = {
6190
+ table_options: {
6191
+ show_column_total: false,
6192
+ show_row_total: false,
6193
+ },
6194
+ };
6195
+
6196
+ const pivotData = $.pivotUtilities.getPivotDataModel(inputs, subOptions);
6197
+ const csvJson = highchartsRenderer.tableCSVExportRenderer(pivotData, chartOptions);
6198
+ expect(csvJson).toEqual([
6199
+ ["Date", 1653177600, 1653955200],
6200
+ ["Type"],
6201
+ ["Food", 1, 1],
6202
+ ["Technology", 1, 1],
6203
+ ]);
6204
+ });
6205
+ });
6040
6206
  });
6041
6207
 
6042
6208
  describe("Function returnRawDataValue", () => {
@@ -8392,4 +8558,199 @@ describe('highcharts_renderer', () => {
8392
8558
  highchartsRenderer.ptRenderSolidGauge('mock_pivot_data', 'mock_opts');
8393
8559
  expect(highchartsRenderer.ptRenderGauge).toHaveBeenCalledWith('mock_pivot_data', 'mock_opts', true);
8394
8560
  });
8561
+
8562
+ describe("Function ptCreateWaterfallBreakdownSeries", () => {
8563
+ const format = null;
8564
+ const additionalOptionsMock = { testOption: 'test additional option 1' }
8565
+
8566
+ const commonPivotDataMockProps = {
8567
+ colFormats: 'mock_formats',
8568
+ colAttrs: ['Test Number Field'],
8569
+ allTotal: {
8570
+ uniq: 1
8571
+ }
8572
+ };
8573
+
8574
+ const optsMock = {
8575
+ breakdown_options: {
8576
+ colors: {
8577
+ decrease: "#BF1D30",
8578
+ increase: "#20A452",
8579
+ total: "rgba(0, 254, 87, 1)",
8580
+ },
8581
+ },
8582
+ };
8583
+
8584
+ const pivotDataMockWithNoBreakdownField = {
8585
+ getAggregator: (rows, cols) => {
8586
+ let aggregator = highchartsRenderer.rhPivotAggregatorSum([''], format, true, {}, {});
8587
+ const agg = aggregator({}, '', '');
8588
+
8589
+ if (lodash.isEqual(cols, [1]) && lodash.isEqual(rows, [])) {
8590
+ agg.sum = 10;
8591
+ } else if (lodash.isEqual(cols, [2]) && lodash.isEqual(rows, [])) {
8592
+ agg.sum = 30;
8593
+ } else if (lodash.isEqual(cols, [3]) && lodash.isEqual(rows, [])) {
8594
+ agg.sum = 80;
8595
+ } else if (lodash.isEqual(cols, [1]) && lodash.isEqual(rows, ['Variance'])) {
8596
+ agg.sum = 20;
8597
+ } else if (lodash.isEqual(cols, [2]) && lodash.isEqual(rows, ['Variance'])) {
8598
+ agg.sum = 50;
8599
+ }
8600
+ return agg;
8601
+ },
8602
+ getColKeys: () => [[1], [2], [3]],
8603
+ getRowKeys: () => [],
8604
+ getRowKeysByCols: () => [[["Variance"]], [["Variance"]]],
8605
+ ...commonPivotDataMockProps,
8606
+ };
8607
+
8608
+ const pivotDataMockWithBreakdownField = {
8609
+ getAggregator: (rows, cols) => {
8610
+ let aggregator = highchartsRenderer.rhPivotAggregatorSum([''], format, true, {}, {});
8611
+ const agg = aggregator({}, '', '');
8612
+
8613
+ if (lodash.isEqual(cols, [1]) && lodash.isEqual(rows, [])) {
8614
+ agg.sum = 10;
8615
+ } else if (lodash.isEqual(cols, [2]) && lodash.isEqual(rows, [])) {
8616
+ agg.sum = 30;
8617
+ } else if (lodash.isEqual(cols, [3]) && lodash.isEqual(rows, [])) {
8618
+ agg.sum = 80;
8619
+ } else if (lodash.isEqual(cols, [1]) && lodash.isEqual(rows, ['val1'])) {
8620
+ agg.sum = 5;
8621
+ } else if (lodash.isEqual(cols, [1]) && lodash.isEqual(rows, ['val2'])) {
8622
+ agg.sum = 15;
8623
+ } else if (lodash.isEqual(cols, [2]) && lodash.isEqual(rows, ['val1'])) {
8624
+ agg.sum = 30;
8625
+ } else if (lodash.isEqual(cols, [2]) && lodash.isEqual(rows, ['val2'])) {
8626
+ agg.sum = 20;
8627
+ }
8628
+ return agg;
8629
+ },
8630
+ getColKeys: () => [[1], [2], [3]],
8631
+ getRowKeys: () => [],
8632
+ getRowKeysByCols: () => [[["val2"], ["val1"]], [["val1"], ["val2"]]],
8633
+ ...commonPivotDataMockProps,
8634
+ };
8635
+
8636
+ beforeEach(() => {
8637
+ spyOn(highchartsRenderer, "defaultDataLabelFormatter").and.returnValue("mock formatter function");
8638
+ spyOn(highchartsRenderer, "getDataLabelsStyle").and.returnValue({ height: '100px' });
8639
+ spyOn(highchartsRenderer, "getOthersName").and.returnValue({ height: 'Test Others Name' });
8640
+ spyOn(highchartsRenderer, 'getDataLabelsOptions').and.callFake((additionOptions, resultObject) => {
8641
+ resultObject.dataLabels.additionalTestProp = 'test_value';
8642
+ return resultObject;
8643
+ });
8644
+ spyOn(highchartsRenderer, 'getFormattedColKey')
8645
+ .and.callFake((initialName, pivotData) => `formatted_col(${ initialName })`);
8646
+ spyOn(highchartsRenderer, 'getFormattedRowKey')
8647
+ .and.callFake((initialName, pivotData) => `formatted_row(${ initialName })`);
8648
+ spyOn(highchartsRenderer, 'isFormattingDatesAsOtherAxisTypes').and.returnValue(true);
8649
+ });
8650
+
8651
+ it("should create appropriate series for case no breakdown field (one row value - Variance instead)", () => {
8652
+ const pivotDataMock = lodash.cloneDeep(pivotDataMockWithNoBreakdownField);
8653
+
8654
+ const series = highchartsRenderer.ptCreateWaterfallBreakdownSeries(pivotDataMock, additionalOptionsMock, optsMock);
8655
+ expect(series).toEqual([
8656
+ {
8657
+ className: 'waterfallBreakdown',
8658
+ color: '#BF1D30',
8659
+ data: [
8660
+ {
8661
+ color: 'rgba(0, 254, 87, 1)',
8662
+ initialName: '1',
8663
+ isSum: false,
8664
+ isTotal: true,
8665
+ name: 'formatted_col(1)',
8666
+ y: 10,
8667
+ },
8668
+ { colKeys: ['1', '2'], initialName: 'Variance', name: 'formatted_row(Variance)', y: 20 },
8669
+ {
8670
+ color: 'rgba(0, 254, 87, 1)',
8671
+ initialName: '2',
8672
+ isSum: true,
8673
+ isTotal: true,
8674
+ name: 'formatted_col(2)',
8675
+ y: 30,
8676
+ },
8677
+ { colKeys: ['2', '3'], initialName: 'Variance', name: 'formatted_row(Variance)', y: 50 },
8678
+ {
8679
+ color: 'rgba(0, 254, 87, 1)',
8680
+ initialName: '3',
8681
+ isSum: true,
8682
+ isTotal: true,
8683
+ name: 'formatted_col(3)',
8684
+ y: 80,
8685
+ },
8686
+ ],
8687
+ dataLabels: {
8688
+ additionalTestProp: 'test_value',
8689
+ allowOverlap: false,
8690
+ enabled: true,
8691
+ formatter: 'mock formatter function',
8692
+ style: { height: '100px' },
8693
+ },
8694
+ name: 'Test Number Field',
8695
+ upColor: '#20A452',
8696
+ },
8697
+ { color: '#20A452', name: 'Positive', visible: false },
8698
+ { color: '#BF1D30', name: 'Negative', visible: false },
8699
+ ]);
8700
+ });
8701
+
8702
+ it("should create appropriate series for case there is breakdown field (differently sorted vals)", () => {
8703
+ const pivotDataMock = lodash.cloneDeep(pivotDataMockWithBreakdownField);
8704
+
8705
+ const series = highchartsRenderer.ptCreateWaterfallBreakdownSeries(pivotDataMock, additionalOptionsMock, optsMock);
8706
+ expect(series).toEqual([
8707
+ {
8708
+ className: 'waterfallBreakdown',
8709
+ color: '#BF1D30',
8710
+ data: [
8711
+ {
8712
+ color: 'rgba(0, 254, 87, 1)',
8713
+ initialName: '1',
8714
+ isSum: false,
8715
+ isTotal: true,
8716
+ name: 'formatted_col(1)',
8717
+ y: 10,
8718
+ },
8719
+ { colKeys: ['1', '2'], initialName: 'val2', name: 'formatted_row(val2)', y: 15 },
8720
+ { colKeys: ['1', '2'], initialName: 'val1', name: 'formatted_row(val1)', y: 5 },
8721
+ {
8722
+ color: 'rgba(0, 254, 87, 1)',
8723
+ initialName: '2',
8724
+ isSum: true,
8725
+ isTotal: true,
8726
+ name: 'formatted_col(2)',
8727
+ y: 30,
8728
+ },
8729
+ { colKeys: ['2', '3'], initialName: 'val1', name: 'formatted_row(val1)', y: 30 },
8730
+ { colKeys: ['2', '3'], initialName: 'val2', name: 'formatted_row(val2)', y: 20 },
8731
+ {
8732
+ color: 'rgba(0, 254, 87, 1)',
8733
+ initialName: '3',
8734
+ isSum: true,
8735
+ isTotal: true,
8736
+ name: 'formatted_col(3)',
8737
+ y: 80,
8738
+ },
8739
+ ],
8740
+ dataLabels: {
8741
+ additionalTestProp: 'test_value',
8742
+ allowOverlap: false,
8743
+ enabled: true,
8744
+ formatter: 'mock formatter function',
8745
+ style: { height: '100px' },
8746
+ },
8747
+ name: 'Test Number Field',
8748
+ upColor: '#20A452',
8749
+ },
8750
+ { color: '#20A452', name: 'Positive', visible: false },
8751
+ { color: '#BF1D30', name: 'Negative', visible: false },
8752
+ ]);
8753
+ });
8754
+ });
8755
+
8395
8756
  });