@datarailsshared/dr_renderer 1.2.56 → 1.2.60

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.56",
3
+ "version": "1.2.60",
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;
@@ -909,6 +909,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
909
909
  var variat_serias = null;
910
910
  const n = col_n_keys.length;
911
911
  const xSum = (1 + n) / 2 * n;
912
+ const trendSerieses = [];
912
913
 
913
914
  lodash.forEach(row_n_keys, function (row_n_value) {
914
915
  var ob = {};
@@ -916,8 +917,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
916
917
  let xySum = 0;
917
918
  let squareXSum = 0;
918
919
  ob.data = [];
919
- if (row_n_value && row_n_value.length > 0)
920
- 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
+ }
921
924
 
922
925
  lodash.forEach(col_n_keys, function (col_n_value, index) {
923
926
  var agg = pivotData.getAggregator(row_n_value, col_n_value);
@@ -973,11 +976,12 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
973
976
  trendSeries.color = colors[i];
974
977
  }
975
978
 
976
- chart_series.push(trendSeries);
979
+ trendSerieses.push(trendSeries);
977
980
  }
978
981
 
979
982
  i++;
980
983
  });
984
+ const ethalonSeries = chart_series[chart_series.length - 1];
981
985
 
982
986
  if (has_delta && additionOptions && additionOptions.delta_column.only_variant) {
983
987
  if (variat_serias)
@@ -996,10 +1000,19 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
996
1000
  }
997
1001
  }
998
1002
 
999
- highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts);
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
+ }
1000
1010
 
1001
1011
  if (opts.total) {
1002
- const newSeries = lodash.clone(chart_series[chart_series.length - 1]);
1012
+ const newSeries = lodash.clone(ethalonSeries);
1013
+ if (opts.totalSeriesSettings) {
1014
+ newSeries.yAxis = opts.totalSeriesSettings.secondaryAxis ? 1 : undefined;
1015
+ }
1003
1016
  newSeries.name = 'Total';
1004
1017
  newSeries.data = [];
1005
1018
  col_n_keys.forEach(columnKey => {
@@ -1013,6 +1026,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1013
1026
  chart_series.push(newSeries);
1014
1027
  }
1015
1028
 
1029
+ chart_series = [...chart_series, ...trendSerieses]
1030
+
1031
+ highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts, opts.total && opts.totalSeriesSettings && opts.totalSeriesSettings.secondaryAxis);
1032
+
1016
1033
  return chart_series;
1017
1034
  };
1018
1035
 
@@ -1033,6 +1050,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1033
1050
  var variat_serias = null;
1034
1051
  const n = col_n_keys.length;
1035
1052
  const xSum = (1 + n) / 2 * n;
1053
+ const trendSerieses = [];
1036
1054
 
1037
1055
  lodash.forEach(row_n_keys, function (row_n_value) {
1038
1056
  let ySum = 0;
@@ -1040,8 +1058,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1040
1058
  let squareXSum = 0;
1041
1059
  var ob = {};
1042
1060
  ob.data = [];
1043
- if (row_n_value && row_n_value.length > 0)
1044
- 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
+ }
1045
1065
 
1046
1066
  ob.dataLabels = {
1047
1067
  allowOverlap: additionOptions && additionOptions.label ? additionOptions.label.overlap : false,
@@ -1101,6 +1121,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1101
1121
 
1102
1122
  chart_series.push(ob);
1103
1123
 
1124
+
1104
1125
  if (opts.trendLine) {
1105
1126
  const a = ((ySum * squareXSum) - (xSum * xySum)) / ((n * squareXSum) - (xSum * xSum));
1106
1127
  const b = ((n * xySum) - (xSum* ySum)) / ((n * squareXSum) - (xSum * xSum));
@@ -1115,11 +1136,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1115
1136
  trendSeries.color = colors[i];
1116
1137
  }
1117
1138
 
1118
- chart_series.push(trendSeries);
1139
+ trendSerieses.push(trendSeries);
1119
1140
  }
1120
1141
  i++;
1121
1142
  });
1122
1143
 
1144
+ const ethalonSeries = chart_series[chart_series.length - 1];
1145
+
1123
1146
  if (has_delta && additionOptions.delta_column.only_variant) {
1124
1147
  if (variat_serias)
1125
1148
  return [variat_serias];
@@ -1128,42 +1151,38 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1128
1151
  }
1129
1152
  }
1130
1153
 
1131
- highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts);
1132
-
1133
1154
  let weights = { line: 2,spline: 3 ,area:-2, areaspline: -1, scatter:4, column: 1 };
1134
1155
 
1135
- if (opts.comboOptions && chartType.includes('combo')) {
1156
+ if (opts.comboOptions && chartType.includes('combo') && !lodash.isEqual(row_n_keys, [[]])) {
1136
1157
  chart_series.forEach((series, seriesIndex) => {
1137
1158
  const savedSeriesOption = lodash.find(opts.comboOptions.seriesOptions, {series: series.name});
1138
1159
  if (savedSeriesOption) {
1139
- switch (savedSeriesOption.chartType) {
1140
- case 'line-chart':
1141
- series.type = 'line';
1142
- break;
1143
- case 'line-chart-smooth':
1144
- series.type = 'spline';
1145
- break;
1146
- case 'area-chart':
1147
- series.type = 'area';
1148
- break;
1149
- case 'area-chart-smooth':
1150
- series.type = 'areaspline';
1151
- break;
1152
- case 'scatter-chart':
1153
- series.type = 'scatter';
1154
- break;
1155
- case 'column-chart' || 'column-chart-stacked':
1156
- delete series.type;
1157
- break;
1158
- }
1159
- } else if (seriesIndex === chart_series.length - 1 && !has_delta) {
1160
+ highchartsRenderer.setChartTypeBySeriesType(savedSeriesOption.chartType, series);
1161
+ } else if (seriesIndex === chart_series.length - 1 && chart_series.length > 1 && !has_delta && !opts.total && !trendSerieses.length) {
1160
1162
  series.type = 'line';
1161
1163
  }
1162
1164
  });
1163
1165
  }
1164
1166
 
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
+ }
1174
+
1165
1175
  if (opts.total) {
1166
- const totalSeries = lodash.clone(chart_series[chart_series.length - 1]);
1176
+ const totalSeries = lodash.clone(ethalonSeries);
1177
+ if (opts.totalSeriesSettings) {
1178
+ if (chartType.includes('combo')) {
1179
+ highchartsRenderer.setChartTypeBySeriesType(opts.totalSeriesSettings.chartType, totalSeries);
1180
+ }
1181
+
1182
+ totalSeries.yAxis = opts.totalSeriesSettings.secondaryAxis ? 1 : undefined;
1183
+ } else if (chartType === 'combo-column-chart' || chartType === 'combo-stacked-chart') {
1184
+ totalSeries.type = 'column';
1185
+ }
1167
1186
  totalSeries.name = 'Total';
1168
1187
  totalSeries.data = [];
1169
1188
  col_n_keys.forEach(columnKey => {
@@ -1179,6 +1198,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1179
1198
  chart_series.push(totalSeries);
1180
1199
  }
1181
1200
 
1201
+ chart_series = [...chart_series, ...trendSerieses];
1202
+
1203
+ highchartsRenderer.moveSeriesToSecondYAxisIfNeeded(chart_series, pivotData, chartOptions, additionOptions, opts, opts.total && opts.totalSeriesSettings && opts.totalSeriesSettings.secondaryAxis);
1204
+
1182
1205
  chart_series.sort((a,b) => {
1183
1206
  return (weights[a.type] || 0) > (weights[b.type] || 0) ? 1 : (weights[a.type] || 0) < (weights[b.type] || 0) ? -1 : 0
1184
1207
  });
@@ -1186,6 +1209,22 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1186
1209
  return chart_series;
1187
1210
  }
1188
1211
 
1212
+ highchartsRenderer.setChartTypeBySeriesType = function (type, series) {
1213
+ const types = {
1214
+ 'line-chart': 'line',
1215
+ 'line-chart-smooth': 'spline',
1216
+ 'area-chart': 'area',
1217
+ 'area-chart-smooth': 'areaspline',
1218
+ 'scatter-chart': 'scatter',
1219
+ }
1220
+
1221
+ if (type === 'column-chart' || type === 'column-chart-stacked') {
1222
+ delete series.type;
1223
+ } else {
1224
+ series.type = types[type]
1225
+ }
1226
+ }
1227
+
1189
1228
  highchartsRenderer.getVariantSeries = function (series, delta_column_options) {
1190
1229
  const varianceColor = delta_column_options.color || highchartsRenderer.variance_color || Highcharts.getOptions().colors[7];
1191
1230
  series.name = delta_column_options.name.replace('_', '');
@@ -1357,7 +1396,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1357
1396
  });
1358
1397
  };
1359
1398
 
1360
- highchartsRenderer.moveSeriesToSecondYAxisIfNeeded = function(chartSeries, pivotData, chartOptions, additionOptions, opts) {
1399
+ highchartsRenderer.moveSeriesToSecondYAxisIfNeeded = function(chartSeries, pivotData, chartOptions, additionOptions, opts, forceAddSecondaryAxis) {
1361
1400
  if (!opts || !opts.comboOptions) {
1362
1401
  return;
1363
1402
  }
@@ -1373,11 +1412,15 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1373
1412
  }
1374
1413
  });
1375
1414
 
1376
- if (addSecondYAxis) {
1415
+ if (addSecondYAxis || forceAddSecondaryAxis) {
1377
1416
  highchartsRenderer.addSecondYAxis(pivotData, chartOptions, additionOptions, opts);
1378
1417
  }
1379
1418
  }
1380
1419
 
1420
+ highchartsRenderer.encodeHTMLBrackets = function (string) {
1421
+ return string.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
1422
+ };
1423
+
1381
1424
  highchartsRenderer.addSecondYAxis = function (pivotData, chartOptions, additionOptions, opts) {
1382
1425
  const varianceColor = (additionOptions && additionOptions.delta_column.color) || (highchartsRenderer && highchartsRenderer.variance_color) || Highcharts.getOptions().colors[7];
1383
1426
  let labels_formatter = opts.comboOptions.secondaryAxisSettings.is_percentage ?
@@ -1389,7 +1432,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1389
1432
  min: !isNaN(parseInt(opts.comboOptions.secondaryAxisSettings.min)) ? opts.comboOptions.secondaryAxisSettings.min : null,
1390
1433
  max: !isNaN(parseInt(opts.comboOptions.secondaryAxisSettings.max)) ? opts.comboOptions.secondaryAxisSettings.max : null,
1391
1434
  title: {
1392
- text: opts.comboOptions.secondaryAxisSettings.name,
1435
+ text: highchartsRenderer.encodeHTMLBrackets(opts.comboOptions.secondaryAxisSettings.name),
1393
1436
  style: {
1394
1437
  color: varianceColor
1395
1438
  }
@@ -3716,15 +3759,25 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3716
3759
  };
3717
3760
 
3718
3761
  highchartsRenderer.getNewAttrSortingForCol = function (pivotData, sortingOptions) {
3719
- let colAttrs, colKeys;
3720
- colAttrs = pivotData.colAttrs;
3762
+ let rowAttrs, rowKeys, colKeys, colAttrs;
3763
+ rowAttrs = pivotData.rowAttrs;
3764
+ rowKeys = pivotData.rowKeys;
3721
3765
  colKeys = pivotData.colKeys;
3766
+ colAttrs = pivotData.colAttrs;
3767
+
3768
+
3722
3769
  if (!colAttrs || colAttrs.length == 0) {
3723
3770
  return null;
3724
3771
  }
3772
+
3725
3773
  let values_names_arr = [];
3726
- lodash.forEach(colKeys, function (val) {
3727
- 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
+
3728
3781
  if (aggregator_subtotal) {
3729
3782
  let value_subtotal = aggregator_subtotal.value();
3730
3783
  if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
@@ -3743,19 +3796,28 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3743
3796
 
3744
3797
  // map only names
3745
3798
  let attr_sorted_values = lodash.map(values_names_arr, 'name');
3746
- return {name: colAttrs[0], values: attr_sorted_values};
3799
+ return {name: sortingOptions.field ? rowAttrs[0] : colAttrs[0], values: attr_sorted_values};
3747
3800
  };
3748
3801
 
3749
3802
  highchartsRenderer.getNewAttrSortingForRow = function (pivotData, sortingOptions) {
3750
- let rowAttrs, rowKeys;
3803
+ let rowAttrs, rowKeys, colKeys, colAttrs;
3751
3804
  rowAttrs = pivotData.rowAttrs;
3752
3805
  rowKeys = pivotData.rowKeys;
3806
+ colKeys = pivotData.colKeys;
3807
+ colAttrs = pivotData.colAttrs;
3808
+
3753
3809
  if (!rowAttrs || rowAttrs.length == 0) {
3754
3810
  return null;
3755
3811
  }
3812
+
3756
3813
  let values_names_arr = [];
3757
- lodash.forEach(rowKeys, function (val) {
3758
- 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
+
3759
3821
  if (aggregator_subtotal) {
3760
3822
  let value_subtotal = aggregator_subtotal.value();
3761
3823
  if (sortingOptions && sortingOptions.is_absolute && !isNaN(parseFloat(value_subtotal))) {
@@ -3774,7 +3836,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3774
3836
 
3775
3837
  // map only names
3776
3838
  let attr_sorted_values = lodash.map(values_names_arr, 'name');
3777
- return {name: rowAttrs[0], values: attr_sorted_values};
3839
+ return {name: sortingOptions.field ? colAttrs[0] : rowAttrs[0], values: attr_sorted_values};
3778
3840
  };
3779
3841
 
3780
3842
  highchartsRenderer.generateSortingFunctionByValues = function (sortingOptions, pivotData, opts) {
@@ -7085,12 +7147,18 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
7085
7147
  return data_row[field_with_variant.name] == variance_config.name && data_row[field_for_sorting.name] != undefined;
7086
7148
  });
7087
7149
 
7150
+ const sorting_variance = widget.options.total_value_options.sorting_variance === '' ? 'asc' : 'desc';
7151
+
7088
7152
  if (widget.options.chartOptions.delta_column.sort_by_absolute_variance) {
7089
7153
  data_sorted = lodash.sortBy(data_sorted, function (o) {
7090
- 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;
7091
7159
  });
7092
7160
  } else {
7093
- data_sorted = lodash.orderBy(data_sorted, [val_field.name], ['desc']);
7161
+ data_sorted = lodash.orderBy(data_sorted, [val_field.name], [sorting_variance]);
7094
7162
  }
7095
7163
 
7096
7164
  let values_for_sort = lodash.map(data_sorted, function (data_row) {