@datarailsshared/dr_renderer 1.2.355 → 1.2.356

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.355",
3
+ "version": "1.2.356",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1507,7 +1507,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1507
1507
  totalSeries.color = colors[i];
1508
1508
  }
1509
1509
 
1510
- if (!lodash.isEmpty(pivotData.colTotals)) {
1510
+
1511
1511
  col_n_keys.forEach(columnKey => {
1512
1512
  let key = columnKey;
1513
1513
  let totalKey = columnKey;
@@ -1518,18 +1518,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1518
1518
  const value = pivotData.colTotals[totalKey] ? pivotData.colTotals[totalKey].value() : 0;
1519
1519
  totalSeries.data.push({name: lodash.unescape(key), y: value});
1520
1520
  });
1521
- } else {
1522
- lodash.forEach(row_n_keys, (rowKey, index) => {
1523
- let key = rowKey;
1524
- let totalKey = rowKey;
1525
- if (lodash.isArray(rowKey)) {
1526
- key = col_n_keys[index];
1527
- totalKey = totalKey.join(highchartsRenderer.delimer);
1528
- }
1529
- const value = pivotData.rowTotals[totalKey] ? pivotData.rowTotals[totalKey].value() : 0;
1530
- totalSeries.data.push({name: lodash.unescape(key), y: value});
1531
- });
1532
- }
1533
1521
 
1534
1522
  chart_series.push(totalSeries);
1535
1523
  }
@@ -8999,6 +8987,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8999
8987
  res = highchartsRenderer.addTotalsToWalkthroughRowData(widget_obj, res);
9000
8988
  }
9001
8989
 
8990
+ res = highchartsRenderer.fixIncompatibleCalculatedValuesTotals(widget_obj, res);
8991
+
9002
8992
  let pivot = {};
9003
8993
 
9004
8994
  let templateNoData = lodash.find(templates, {id: widget_obj.template_id});
@@ -9508,6 +9498,73 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9508
9498
  }));
9509
9499
  }
9510
9500
 
9501
+ // We are receiving not correct format for subtotals from BE for now - so we modyfing the response
9502
+ // in order to transform it to acceptable one. It is complex to fix currently on BE side.
9503
+ // TODO: remove it when fixed on BE side
9504
+ highchartsRenderer.fixIncompatibleCalculatedValuesTotals = function(widget, res) {
9505
+
9506
+ // if it is FE side calculation or empty response - just return unmodified
9507
+ if (!highchartsRenderer.useTotalsCalculation || !lodash.get(res, 'length')) return res;
9508
+
9509
+ const calculatedValuesInValsCount = lodash.filter(
9510
+ widget.calculated_values, calcVal => lodash.some(widget.vals, { field: calcVal.field })
9511
+ ).length;
9512
+
9513
+ // do transformations only if widget has calculated in values
9514
+ if (calculatedValuesInValsCount) {
9515
+ const fieldWithDrValuesNames = lodash.reduce(
9516
+ widget.calculated_values,
9517
+ (fieldNames, calcVal) => {
9518
+ const fieldName = lodash.get(lodash.find(widget.vals, { field: calcVal.field }), 'name');
9519
+ return fieldName ? lodash.concat(fieldNames, [fieldName]) : fieldNames;
9520
+ },
9521
+ []
9522
+ );
9523
+
9524
+ const existingRecords = [];
9525
+ lodash.forEach(res, (record) => {
9526
+
9527
+ // example: replace record { Type: "Discount", City: "Brest", DR_Values: "Normal 1", Amount: 52585.14 }
9528
+ // with { Type: "Discount", City: "Brest", DR_Values: "Normal 1", value: 52585.14 }
9529
+ if (widget.vals.length > 1 && !widget.rows.length) {
9530
+ const valueFieldNameFound = lodash.find(fieldWithDrValuesNames, name => record[name]);
9531
+ if (valueFieldNameFound) {
9532
+ record.value = record[valueFieldNameFound];
9533
+ delete record[valueFieldNameFound];
9534
+ }
9535
+ }
9536
+
9537
+ // in response from BE we have currently improper column subtotals:
9538
+ // they returned with 'DR_Values' not empty - same as for regular cell values
9539
+ // so we have two records with same column values and can't define which is subtotal
9540
+ const isSameColValuesWasBefore = lodash.some(existingRecords, existingRecord =>
9541
+ lodash.every(
9542
+ lodash.concat(['DR_Values'], lodash.map(widget.cols, 'name')), fieldName => existingRecord[fieldName] === record[fieldName]
9543
+ )
9544
+ );
9545
+ const isNoRowValues = lodash.every(widget.rows, field => typeof record[field.name] === 'undefined');
9546
+ const isSubtotal = isSameColValuesWasBefore && isNoRowValues;
9547
+
9548
+ // we need to remove DR_Values for response records which suppose to be subtotals
9549
+ if (isSubtotal) {
9550
+ delete record.DR_Values;
9551
+ }
9552
+
9553
+ existingRecords.push(record);
9554
+ });
9555
+
9556
+ // Another BE issue - it is not returning correct subtotals for case we have more than one calculated values
9557
+ // It is just not counting sum there. So we remove it in order not to show improper values
9558
+ if ((calculatedValuesInValsCount > 1 || calculatedValuesInValsCount && widget.vals.length > 1) && !widget.rows.length) {
9559
+ res = lodash.filter(res, record => {
9560
+ const isColsTotal = typeof record['DR_Values'] === 'undefined';
9561
+ return !isColsTotal;
9562
+ })
9563
+ }
9564
+ }
9565
+ return res;
9566
+ }
9567
+
9511
9568
  return highchartsRenderer;
9512
9569
  };
9513
9570