@datarailsshared/dr_renderer 1.2.355 → 1.2.357

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.357",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -21,6 +21,9 @@ const CHART_COLORS = {
21
21
  LABEL: '#cfd7dd',
22
22
  LABEL_SECOND: '#85889c',
23
23
  DRILL_UP_FILL: '#eef3f6',
24
+ DRILL_BUTTON_COLOR_FILL: 'white',
25
+ DRILL_BUTTON_COLOR: '#6D6E6F',
26
+ DRILL_BUTTON_COLOR_HOVER: '#333333',
24
27
  PLOT_BORDER: '#606063',
25
28
  MINOR_GRID_LINE: '#505053',
26
29
  TICK_COLOR: '#666',
@@ -61,6 +64,7 @@ const CHART_TYPES = {
61
64
 
62
65
  const HIGHCHARTS_CONSTANTS = {
63
66
  delimer: ' , ',
67
+ DRILL_BUTTON_FONT_SIZE: '14px',
64
68
  MAX_ROWS_FOR_AUTO_REFRESH: 100000,
65
69
  MAX_ROWS_FOR_SHOW_RESULTS: 10000,
66
70
  DR_OTHERS_KEY: 'DR_Others',
@@ -1036,8 +1040,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1036
1040
  chartOptions.yAxis && chartOptions.yAxis.title && (chartOptions.yAxis.title.text || chartOptions.yAxis.title.autoylabel) ? -60 : -40;
1037
1041
  const y = isPieChart ? 27 :
1038
1042
  chartOptions.xAxis && chartOptions.xAxis.title && (chartOptions.xAxis.title.text || chartOptions.xAxis.title.autoxlabel) ? 65 : 43;
1043
+ chartOptions.chart.spacingBottom = 30;
1039
1044
  chartOptions.drilldown.breadcrumbs = {
1040
- formatter: () => '< Back',
1045
+ formatter: () => 'Back',
1041
1046
  showFullPath: false,
1042
1047
  position: {
1043
1048
  align: 'left',
@@ -1046,23 +1051,21 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1046
1051
  y: y,
1047
1052
  },
1048
1053
  floating: true,
1054
+ position: { align: 'left', x: 12, y: 6, verticalAlign: 'bottom' },
1055
+ relativeTo: 'spacingBox',
1049
1056
  buttonTheme: {
1050
- fill: 'white',
1051
- color: CHART_COLORS.LABEL_SECOND,
1052
- 'stroke-width': 1,
1053
- stroke: CHART_COLORS.LABEL_SECOND,
1054
- r: 3,
1055
- padding: 3,
1057
+ fill: CHART_COLORS.DRILL_BUTTON_COLOR_FILL,
1058
+ style: {
1059
+ fontSize: HIGHCHARTS_CONSTANTS.DRILL_BUTTON_FONT_SIZE,
1060
+ color: CHART_COLORS.DRILL_BUTTON_COLOR,
1061
+ },
1056
1062
  states: {
1057
1063
  hover: {
1058
- fill: CHART_COLORS.DRILL_UP_FILL,
1059
- stroke: CHART_COLORS.LABEL_SECOND,
1060
- color: CHART_COLORS.LABEL_SECOND
1061
- },
1062
- select: {
1063
- stroke: CHART_COLORS.LABEL_SECOND,
1064
- fill: CHART_COLORS.DRILL_UP_FILL,
1065
- color: CHART_COLORS.LABEL_SECOND
1064
+ fill: CHART_COLORS.DRILL_BUTTON_COLOR_FILL,
1065
+ style: {
1066
+ fontSize: HIGHCHARTS_CONSTANTS.DRILL_BUTTON_FONT_SIZE,
1067
+ color: CHART_COLORS.DRILL_BUTTON_COLOR_HOVER,
1068
+ }
1066
1069
  }
1067
1070
  }
1068
1071
  },
@@ -1507,7 +1510,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1507
1510
  totalSeries.color = colors[i];
1508
1511
  }
1509
1512
 
1510
- if (!lodash.isEmpty(pivotData.colTotals)) {
1513
+
1511
1514
  col_n_keys.forEach(columnKey => {
1512
1515
  let key = columnKey;
1513
1516
  let totalKey = columnKey;
@@ -1518,18 +1521,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1518
1521
  const value = pivotData.colTotals[totalKey] ? pivotData.colTotals[totalKey].value() : 0;
1519
1522
  totalSeries.data.push({name: lodash.unescape(key), y: value});
1520
1523
  });
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
1524
 
1534
1525
  chart_series.push(totalSeries);
1535
1526
  }
@@ -8999,6 +8990,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8999
8990
  res = highchartsRenderer.addTotalsToWalkthroughRowData(widget_obj, res);
9000
8991
  }
9001
8992
 
8993
+ res = highchartsRenderer.fixIncompatibleCalculatedValuesTotals(widget_obj, res);
8994
+
9002
8995
  let pivot = {};
9003
8996
 
9004
8997
  let templateNoData = lodash.find(templates, {id: widget_obj.template_id});
@@ -9508,6 +9501,73 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9508
9501
  }));
9509
9502
  }
9510
9503
 
9504
+ // We are receiving not correct format for subtotals from BE for now - so we modyfing the response
9505
+ // in order to transform it to acceptable one. It is complex to fix currently on BE side.
9506
+ // TODO: remove it when fixed on BE side
9507
+ highchartsRenderer.fixIncompatibleCalculatedValuesTotals = function(widget, res) {
9508
+
9509
+ // if it is FE side calculation or empty response - just return unmodified
9510
+ if (!highchartsRenderer.useTotalsCalculation || !lodash.get(res, 'length')) return res;
9511
+
9512
+ const calculatedValuesInValsCount = lodash.filter(
9513
+ widget.calculated_values, calcVal => lodash.some(widget.vals, { field: calcVal.field })
9514
+ ).length;
9515
+
9516
+ // do transformations only if widget has calculated in values
9517
+ if (calculatedValuesInValsCount) {
9518
+ const fieldWithDrValuesNames = lodash.reduce(
9519
+ widget.calculated_values,
9520
+ (fieldNames, calcVal) => {
9521
+ const fieldName = lodash.get(lodash.find(widget.vals, { field: calcVal.field }), 'name');
9522
+ return fieldName ? lodash.concat(fieldNames, [fieldName]) : fieldNames;
9523
+ },
9524
+ []
9525
+ );
9526
+
9527
+ const existingRecords = [];
9528
+ lodash.forEach(res, (record) => {
9529
+
9530
+ // example: replace record { Type: "Discount", City: "Brest", DR_Values: "Normal 1", Amount: 52585.14 }
9531
+ // with { Type: "Discount", City: "Brest", DR_Values: "Normal 1", value: 52585.14 }
9532
+ if (widget.vals.length > 1 && !widget.rows.length) {
9533
+ const valueFieldNameFound = lodash.find(fieldWithDrValuesNames, name => record[name]);
9534
+ if (valueFieldNameFound) {
9535
+ record.value = record[valueFieldNameFound];
9536
+ delete record[valueFieldNameFound];
9537
+ }
9538
+ }
9539
+
9540
+ // in response from BE we have currently improper column subtotals:
9541
+ // they returned with 'DR_Values' not empty - same as for regular cell values
9542
+ // so we have two records with same column values and can't define which is subtotal
9543
+ const isSameColValuesWasBefore = lodash.some(existingRecords, existingRecord =>
9544
+ lodash.every(
9545
+ lodash.concat(['DR_Values'], lodash.map(widget.cols, 'name')), fieldName => existingRecord[fieldName] === record[fieldName]
9546
+ )
9547
+ );
9548
+ const isNoRowValues = lodash.every(widget.rows, field => typeof record[field.name] === 'undefined');
9549
+ const isSubtotal = isSameColValuesWasBefore && isNoRowValues;
9550
+
9551
+ // we need to remove DR_Values for response records which suppose to be subtotals
9552
+ if (isSubtotal) {
9553
+ delete record.DR_Values;
9554
+ }
9555
+
9556
+ existingRecords.push(record);
9557
+ });
9558
+
9559
+ // Another BE issue - it is not returning correct subtotals for case we have more than one calculated values
9560
+ // It is just not counting sum there. So we remove it in order not to show improper values
9561
+ if ((calculatedValuesInValsCount > 1 || calculatedValuesInValsCount && widget.vals.length > 1) && !widget.rows.length) {
9562
+ res = lodash.filter(res, record => {
9563
+ const isColsTotal = typeof record['DR_Values'] === 'undefined';
9564
+ return !isColsTotal;
9565
+ })
9566
+ }
9567
+ }
9568
+ return res;
9569
+ }
9570
+
9511
9571
  return highchartsRenderer;
9512
9572
  };
9513
9573