@datarailsshared/dr_renderer 1.2.57 → 1.2.61

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.57",
3
+ "version": "1.2.61",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -113,7 +113,7 @@ let initDRPivotTable = function($, window, document) {
113
113
  };
114
114
  };
115
115
 
116
- processKey = function(record, totals, keys, attrs, getAggregator) {
116
+ processKey = function(record, totals, keys, attrs, containsAverage, containsOthers, getAggregator) {
117
117
  var addKey, attr, flatKey, k, key, len, ref;
118
118
  key = [];
119
119
  addKey = false;
@@ -125,7 +125,17 @@ let initDRPivotTable = function($, window, document) {
125
125
  totals[flatKey] = getAggregator(key.slice());
126
126
  addKey = true;
127
127
  }
128
- totals[flatKey].push(record);
128
+
129
+ if (containsAverage || containsOthers) {
130
+ if (containsAverage && key[0] === 'DR_Average') {
131
+ totals[flatKey].push(record);
132
+ }
133
+ if (containsOthers && key[0] === 'DR_Others') {
134
+ totals[flatKey].push(record);
135
+ }
136
+ } else {
137
+ totals[flatKey].push(record);
138
+ }
129
139
  }
130
140
  if (addKey) {
131
141
  keys.push(key);
@@ -203,13 +213,18 @@ let initDRPivotTable = function($, window, document) {
203
213
  var colKey, fColKey, fRowKey, flatColKey, flatRowKey, i, j, k, m, n, ref, results, rowKey;
204
214
  rowKey = [];
205
215
  colKey = [];
206
- this.allTotal.push(record);
207
- rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, (function(_this) {
216
+ const recordValues = Object.values(record);
217
+ const containsAverage = recordValues.includes('DR_Average');
218
+ const containsOthers = recordValues.includes('DR_Others');
219
+ if (!containsAverage && !containsOthers) {
220
+ this.allTotal.push(record);
221
+ }
222
+ rowKey = processKey(record, this.rowTotals, this.rowKeys, this.rowAttrs, containsAverage, containsOthers, (function(_this) {
208
223
  return function(key) {
209
224
  return _this.aggregator(_this, key, []);
210
225
  };
211
226
  })(this));
212
- colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, (function(_this) {
227
+ colKey = processKey(record, this.colTotals, this.colKeys, this.colAttrs, containsAverage, containsOthers, (function(_this) {
213
228
  return function(key) {
214
229
  return _this.aggregator(_this, [], key);
215
230
  };
@@ -1194,6 +1209,9 @@ let initDRPivotTable = function($, window, document) {
1194
1209
  if (opts.chartOptions.table_options.hide_nulls_in_headers) {
1195
1210
  th.textContent = th.textContent.replace('[null]', '');
1196
1211
  }
1212
+ if (th.textContent === 'DR Others') {
1213
+ th.textContent = _.get(opts, "total_value_options.filter_options.filteredOutFieldName") || 'Others'
1214
+ }
1197
1215
 
1198
1216
  if (th.hasAttribute('data_show_more') && th.colSpan > 0 && !hasColLabels) {
1199
1217
  th.colSpan = th.colSpan - 1;
@@ -917,8 +917,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
917
917
  let xySum = 0;
918
918
  let squareXSum = 0;
919
919
  ob.data = [];
920
- if (row_n_value && row_n_value.length > 0)
921
- ob.name = row_n_value.join(highchartsRenderer.delimer);
920
+ if (row_n_value && row_n_value.length > 0) {
921
+ let othersName = lodash.get(opts, "total_value_options.filter_options.filteredOutFieldName") || 'Others';
922
+ ob.name = row_n_value.join(highchartsRenderer.delimer).replace('DR_Others', othersName);
923
+ }
922
924
 
923
925
  lodash.forEach(col_n_keys, function (col_n_value, index) {
924
926
  var agg = pivotData.getAggregator(row_n_value, col_n_value);
@@ -998,7 +1000,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
998
1000
  }
999
1001
  }
1000
1002
 
1001
- chart_series = [...chart_series, ...trendSerieses]
1003
+ opts.chart_series = []
1004
+
1005
+ if (!lodash.isEqual(row_n_keys, [[]])) {
1006
+ chart_series.forEach(series => {
1007
+ opts.chart_series.push(series.name);
1008
+ })
1009
+ }
1002
1010
 
1003
1011
  if (opts.total) {
1004
1012
  const newSeries = lodash.clone(ethalonSeries);
@@ -1018,6 +1026,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1018
1026
  chart_series.push(newSeries);
1019
1027
  }
1020
1028
 
1029
+ chart_series = [...chart_series, ...trendSerieses]
1030
+
1021
1031
  highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts, opts.total && opts.totalSeriesSettings && opts.totalSeriesSettings.secondaryAxis);
1022
1032
 
1023
1033
  return chart_series;
@@ -1048,8 +1058,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1048
1058
  let squareXSum = 0;
1049
1059
  var ob = {};
1050
1060
  ob.data = [];
1051
- if (row_n_value && row_n_value.length > 0)
1052
- ob.name = lodash.unescape(row_n_value.join(highchartsRenderer.delimer));
1061
+ if (row_n_value && row_n_value.length > 0) {
1062
+ let othersName = lodash.get(opts, "total_value_options.filter_options.filteredOutFieldName") || 'Others';
1063
+ ob.name = lodash.unescape(row_n_value.join(highchartsRenderer.delimer).replace('DR_Others', othersName));
1064
+ }
1053
1065
 
1054
1066
  ob.dataLabels = {
1055
1067
  allowOverlap: additionOptions && additionOptions.label ? additionOptions.label.overlap : false,
@@ -1141,18 +1153,24 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1141
1153
 
1142
1154
  let weights = { line: 2,spline: 3 ,area:-2, areaspline: -1, scatter:4, column: 1 };
1143
1155
 
1144
- if (opts.comboOptions && chartType.includes('combo')) {
1156
+ if (opts.comboOptions && chartType.includes('combo') && !lodash.isEqual(row_n_keys, [[]])) {
1145
1157
  chart_series.forEach((series, seriesIndex) => {
1146
1158
  const savedSeriesOption = lodash.find(opts.comboOptions.seriesOptions, {series: series.name});
1147
1159
  if (savedSeriesOption) {
1148
1160
  highchartsRenderer.setChartTypeBySeriesType(savedSeriesOption.chartType, series);
1149
- } else if (seriesIndex === chart_series.length - 1 && !has_delta) {
1161
+ } else if (seriesIndex === chart_series.length - 1 && chart_series.length > 1 && !has_delta && !opts.total && !trendSerieses.length) {
1150
1162
  series.type = 'line';
1151
1163
  }
1152
1164
  });
1153
1165
  }
1154
1166
 
1155
- chart_series = [...chart_series, ...trendSerieses]
1167
+ opts.chart_series = []
1168
+
1169
+ if (!lodash.isEqual(row_n_keys, [[]])) {
1170
+ chart_series.forEach(series => {
1171
+ opts.chart_series.push(series.name);
1172
+ })
1173
+ }
1156
1174
 
1157
1175
  if (opts.total) {
1158
1176
  const totalSeries = lodash.clone(ethalonSeries);
@@ -1162,6 +1180,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1162
1180
  }
1163
1181
 
1164
1182
  totalSeries.yAxis = opts.totalSeriesSettings.secondaryAxis ? 1 : undefined;
1183
+ } else if (chartType === 'combo-column-chart' || chartType === 'combo-stacked-chart') {
1184
+ totalSeries.type = 'column';
1165
1185
  }
1166
1186
  totalSeries.name = 'Total';
1167
1187
  totalSeries.data = [];
@@ -1178,6 +1198,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1178
1198
  chart_series.push(totalSeries);
1179
1199
  }
1180
1200
 
1201
+ chart_series = [...chart_series, ...trendSerieses];
1202
+
1181
1203
  highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts, opts.total && opts.totalSeriesSettings && opts.totalSeriesSettings.secondaryAxis);
1182
1204
 
1183
1205
  chart_series.sort((a,b) => {
@@ -1395,6 +1417,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1395
1417
  }
1396
1418
  }
1397
1419
 
1420
+ highchartsRenderer.encodeHTMLBrackets = function (string) {
1421
+ return string.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
1422
+ };
1423
+
1398
1424
  highchartsRenderer.addSecondYAxis = function (pivotData, chartOptions, additionOptions, opts) {
1399
1425
  const varianceColor = (additionOptions && additionOptions.delta_column.color) || (highchartsRenderer && highchartsRenderer.variance_color) || Highcharts.getOptions().colors[7];
1400
1426
  let labels_formatter = opts.comboOptions.secondaryAxisSettings.is_percentage ?
@@ -1406,7 +1432,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1406
1432
  min: !isNaN(parseInt(opts.comboOptions.secondaryAxisSettings.min)) ? opts.comboOptions.secondaryAxisSettings.min : null,
1407
1433
  max: !isNaN(parseInt(opts.comboOptions.secondaryAxisSettings.max)) ? opts.comboOptions.secondaryAxisSettings.max : null,
1408
1434
  title: {
1409
- text: opts.comboOptions.secondaryAxisSettings.name,
1435
+ text: highchartsRenderer.encodeHTMLBrackets(opts.comboOptions.secondaryAxisSettings.name),
1410
1436
  style: {
1411
1437
  color: varianceColor
1412
1438
  }
@@ -3733,15 +3759,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3733
3759
  };
3734
3760
 
3735
3761
  highchartsRenderer.getNewAttrSortingForCol = function (pivotData, sortingOptions) {
3736
- let colAttrs, colKeys;
3737
- colAttrs = pivotData.colAttrs;
3762
+ let rowAttrs, rowKeys, colKeys, colAttrs;
3763
+ rowAttrs = pivotData.rowAttrs;
3764
+ rowKeys = pivotData.rowKeys;
3738
3765
  colKeys = pivotData.colKeys;
3766
+ colAttrs = pivotData.colAttrs;
3767
+
3768
+
3739
3769
  if (!colAttrs || colAttrs.length == 0) {
3740
3770
  return null;
3741
3771
  }
3772
+
3742
3773
  let values_names_arr = [];
3743
- lodash.forEach(colKeys, function (val) {
3744
- let aggregator_subtotal = pivotData.getAggregator([], [val[0]]);
3774
+ let keysArray = sortingOptions.field ? rowKeys : colKeys;
3775
+
3776
+ lodash.forEach(keysArray, function (val) {
3777
+ let firstArray = sortingOptions.field ? [val[0]] : [];
3778
+ let secondArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
3779
+ let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
3780
+
3745
3781
  if (aggregator_subtotal) {
3746
3782
  let value_subtotal = aggregator_subtotal.value();
3747
3783
  if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
@@ -3760,19 +3796,28 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3760
3796
 
3761
3797
  // map only names
3762
3798
  let attr_sorted_values = lodash.map(values_names_arr, 'name');
3763
- return {name: colAttrs[0], values: attr_sorted_values};
3799
+ return {name: sortingOptions.field ? rowAttrs[0] : colAttrs[0], values: attr_sorted_values};
3764
3800
  };
3765
3801
 
3766
3802
  highchartsRenderer.getNewAttrSortingForRow = function (pivotData, sortingOptions) {
3767
- let rowAttrs, rowKeys;
3803
+ let rowAttrs, rowKeys, colKeys, colAttrs;
3768
3804
  rowAttrs = pivotData.rowAttrs;
3769
3805
  rowKeys = pivotData.rowKeys;
3806
+ colKeys = pivotData.colKeys;
3807
+ colAttrs = pivotData.colAttrs;
3808
+
3770
3809
  if (!rowAttrs || rowAttrs.length == 0) {
3771
3810
  return null;
3772
3811
  }
3812
+
3773
3813
  let values_names_arr = [];
3774
- lodash.forEach(rowKeys, function (val) {
3775
- let aggregator_subtotal = pivotData.getAggregator([val[0]], []);
3814
+ let keysArray = sortingOptions.field ? colKeys : rowKeys;
3815
+
3816
+ lodash.forEach(keysArray, function (val) {
3817
+ let firstArray = sortingOptions.field ? sortingOptions.field.split(highchartsRenderer.delimer) : [val[0]];
3818
+ let secondArray = sortingOptions.field ? [val[0]] : [];
3819
+ let aggregator_subtotal = pivotData.getAggregator(firstArray, secondArray);
3820
+
3776
3821
  if (aggregator_subtotal) {
3777
3822
  let value_subtotal = aggregator_subtotal.value();
3778
3823
  if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
@@ -3791,7 +3836,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3791
3836
 
3792
3837
  // map only names
3793
3838
  let attr_sorted_values = lodash.map(values_names_arr, 'name');
3794
- return {name: rowAttrs[0], values: attr_sorted_values};
3839
+ return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
3795
3840
  };
3796
3841
 
3797
3842
  highchartsRenderer.generateSortingFunctionByValues = function (sortingOptions, pivotData, opts) {
@@ -4958,7 +5003,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4958
5003
  return valToReturn;
4959
5004
  };
4960
5005
 
4961
- highchartsRenderer.widgetPlaceholders = Object.assign({}, $.pivotUtilities.errorHandling.placeholders);
5006
+ highchartsRenderer.widgetPlaceholders = lodash.assign({}, $.pivotUtilities.errorHandling.placeholders);
4962
5007
 
4963
5008
  highchartsRenderer.suboptions = {
4964
5009
  'default_show': {
@@ -7102,12 +7147,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7102
7147
  return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
7103
7148
  });
7104
7149
 
7150
+ const sorting_variance = widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
7151
+
7105
7152
  if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
7106
7153
  data_sorted = lodash.sortBy(data_sorted, function (o) {
7107
- return Math.abs(o[val_field.name]) * -1;
7154
+ if (sorting_variance === 'desc') {
7155
+ return Math.abs(o[val_field.name]) * -1;
7156
+ }
7157
+
7158
+ return Math.abs(o[val_field.name]) * 1;
7108
7159
  });
7109
7160
  } else {
7110
- data_sorted = lodash.orderBy(data_sorted, [val_field.name], ['desc']);
7161
+ data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
7111
7162
  }
7112
7163
 
7113
7164
  let values_for_sort = lodash.map(data_sorted, function (data_row) {