@datarailsshared/dr_renderer 1.4.114 → 1.4.116

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.4.114",
3
+ "version": "1.4.116",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -641,7 +641,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
641
641
  highchartsRenderer.persantageValueLabelsFormatter = function (pivotData, opts) {
642
642
  var func = function () {
643
643
  var value = parseFloat(this.value);
644
- return $.pivotUtilities.getFormattedNumber(value, null, null) + "%";
644
+ return $.pivotUtilities.getFormattedNumber(value * 100, null, null) + "%";
645
645
  };
646
646
  return func;
647
647
  };
@@ -1918,9 +1918,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
1918
1918
  lodash.forEach(series.data, function (it, index) {
1919
1919
  if (pivotData.rowKeys && pivotData.rowKeys.length && pivotData.colKeys && pivotData.colKeys.length) {
1920
1920
  const agg = pivotData.getAggregator([pivotData.rowKeys[0]], pivotData.colKeys[index]);
1921
- if (agg) {
1921
+ if (agg && valueFormatter.isAbsoluteValue(delta_column_options.formula)) {
1922
1922
  const baseValue = pivotData.getAggregator([pivotData.rowKeys[0]], pivotData.colKeys[index]).value();
1923
- it.y = valueFormatter.getPercentageValue(it.y, baseValue);
1923
+ it.y = valueFormatter.getRelatedValue(it.y, baseValue);
1924
1924
  }
1925
1925
  }
1926
1926
  });
@@ -2130,7 +2130,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2130
2130
 
2131
2131
  highchartsRenderer.addSecondYAxis = function (pivotData, chartOptions, additionOptions, opts) {
2132
2132
  const varianceColor = (additionOptions && additionOptions.delta_column.color) || (highchartsRenderer && highchartsRenderer.variance_color) || Highcharts.getOptions().colors[7];
2133
- const forcePercentage = lodash.get(opts, 'comboOptions.secondaryAxisSettings.is_percentage', false);
2133
+ const forcePercentage = lodash.get(opts, 'comboOptions.secondaryAxisSettings.is_percentage', false) || lodash.get(additionOptions, 'delta_column.is_percentage', false);
2134
2134
 
2135
2135
  chartOptions.yAxis = [chartOptions.yAxis];
2136
2136
  chartOptions.yAxis[1] = {
@@ -3749,8 +3749,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3749
3749
  }
3750
3750
 
3751
3751
  highchartsRenderer.isRowKeyShouldBePercentage = function(render_options, rowKey) {
3752
- if (render_options && render_options.comboOptions && render_options.comboOptions.secondaryAxisSettings &&
3753
- render_options.comboOptions.secondaryAxisSettings.is_percentage) {
3752
+ if (lodash.get(render_options, 'comboOptions.secondaryAxisSettings.is_percentage', false) || lodash.get(render_options, 'chartOptions.delta_column.is_percentage', false)) {
3754
3753
  const rowKeyString = rowKey.join(highchartsRenderer.delimer);
3755
3754
  const rowKeyOptions = lodash.find(render_options.comboOptions.seriesOptions, {series: rowKeyString});
3756
3755
  if (rowKeyOptions && rowKeyOptions.secondaryAxis) {
@@ -5308,7 +5307,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5308
5307
  break;
5309
5308
  }
5310
5309
  options.comboOptions.seriesOptions.push(deltaColumnSeries);
5311
- options.comboOptions.secondaryAxisSettings.is_percentage = options.chartOptions.delta_column.is_percentage;
5312
5310
  }
5313
5311
  };
5314
5312
 
@@ -1,30 +1,41 @@
1
1
  const lodash = require('lodash');
2
2
 
3
3
  function getAggregatorPercentageValueIfRequired(value, render_options, data, rowKey, colKey) {
4
- const isPercentage = lodash.get(render_options, 'comboOptions.secondaryAxisSettings.is_percentage', false);
5
- const deltaColumnName = lodash.get(render_options, 'chartOptions.delta_column.name', '');
4
+ const deltaColumn = lodash.get(render_options, 'chartOptions.delta_column', null);
5
+ const isPercentage = lodash.get(render_options, 'comboOptions.secondaryAxisSettings.is_percentage', false) || deltaColumn && deltaColumn.is_percentage;
6
6
  const currentRowName = rowKey && rowKey.length ? String(rowKey[0]) : '';
7
- const isVariance = currentRowName.replace('_', '').toLowerCase() === deltaColumnName.replace('_', '').toLowerCase();
7
+ const isVariance = deltaColumn && currentRowName.replace('_', '').toLowerCase() === deltaColumn.name.replace('_', '').toLowerCase();
8
8
  const baseRowKey = data && data.rowKeys && data.rowKeys.length ? data.rowKeys[0] : null;
9
9
  const currentColKey = colKey ? colKey : [];
10
10
  const agg = data && baseRowKey ? data.getAggregator(baseRowKey, currentColKey) : null;
11
11
 
12
12
  if (isPercentage && isVariance && baseRowKey && agg) {
13
- const baseValue = agg.value();
14
- return getPercentageValue(value, baseValue) + '%';
13
+ if (deltaColumn && isAbsoluteValue(deltaColumn.formula)) {
14
+ value = getRelatedValue(value, agg.value());
15
+ }
16
+
17
+ return Math.round(value * 100) + '%';
15
18
  }
16
19
 
17
20
  return null;
18
21
  };
19
22
 
20
- function getPercentageValue(value, baseValue) {
23
+ function getRelatedValue(value, baseValue) {
21
24
  if (!baseValue)
22
- return value < 0 ? -100 : 100;
25
+ return value < 0 ? -1 : 1;
23
26
 
24
- return Math.round(value / baseValue * 100);
27
+ return value / baseValue;
28
+ };
29
+
30
+ function isAbsoluteValue(formula) {
31
+ if (!formula)
32
+ return false;
33
+
34
+ return lodash.includes(formula.replace(/\s+/g, ''), 'x2-x1');
25
35
  };
26
36
 
27
37
  module.exports = {
28
38
  getAggregatorPercentageValueIfRequired,
29
- getPercentageValue
39
+ getRelatedValue,
40
+ isAbsoluteValue
30
41
  };
@@ -453,7 +453,7 @@ describe('highcharts_renderer', () => {
453
453
  let funcContext = { value: '12345.678' };
454
454
  let persantageValueLabelsFormatterFn = highchartsRenderer.persantageValueLabelsFormatter(null, {})
455
455
  let result = persantageValueLabelsFormatterFn.call(funcContext)
456
- expect(result).toBe('12,345.678%');
456
+ expect(result).toBe('1,234,567.8%');
457
457
  });
458
458
  });
459
459
 
@@ -2057,7 +2057,7 @@ describe('highcharts_renderer', () => {
2057
2057
  field: 'series',
2058
2058
  name: 'TEST_test',
2059
2059
  same_yaxis: true,
2060
- is_percentage: true,
2060
+ is_percentage: false,
2061
2061
  }
2062
2062
  }
2063
2063
  };
@@ -2074,7 +2074,7 @@ describe('highcharts_renderer', () => {
2074
2074
  name: 'Secondary Axis',
2075
2075
  max: null,
2076
2076
  min: null,
2077
- is_percentage: true
2077
+ is_percentage: false
2078
2078
  },
2079
2079
  seriesOptions: [{
2080
2080
  series: 'TEST_test',
@@ -1,4 +1,4 @@
1
- const { getAggregatorPercentageValueIfRequired, getPercentageValue } = require('../src/value.formatter');
1
+ const { getAggregatorPercentageValueIfRequired, getRelatedValue, isAbsoluteValue } = require('../src/value.formatter');
2
2
 
3
3
  describe('Function getAggregatorPercentageValueIfRequired', () => {
4
4
  let render_options, rowKey, colKey;
@@ -6,7 +6,12 @@ describe('Function getAggregatorPercentageValueIfRequired', () => {
6
6
  beforeEach(() => {
7
7
  render_options = {
8
8
  comboOptions: { secondaryAxisSettings: { is_percentage: true } },
9
- chartOptions: { delta_column: { name: 'Variance' } }
9
+ chartOptions: {
10
+ delta_column: {
11
+ name: 'Variance',
12
+ formula: 'x2-x1'
13
+ }
14
+ }
10
15
  };
11
16
  rowKey = ['Variance'];
12
17
  colKey = ['SomeCol'];
@@ -82,18 +87,44 @@ describe('Function getAggregatorPercentageValueIfRequired', () => {
82
87
  });
83
88
  });
84
89
 
85
- describe('Function getPercentageValue', () => {
86
- it('should return -100 when baseValue is falsy and value < 0', () => {
87
- expect(getPercentageValue(-50, 0)).toBe(-100);
90
+ describe('Function getRelatedValue', () => {
91
+ it('should return -1 when baseValue is falsy and value < 0', () => {
92
+ expect(getRelatedValue(-50, 0)).toBe(-1);
88
93
  });
89
94
 
90
- it('should return 100 when baseValue is falsy and value >= 0', () => {
91
- expect(getPercentageValue(50, null)).toBe(100);
95
+ it('should return 1 when baseValue is falsy and value >= 0', () => {
96
+ expect(getRelatedValue(50, null)).toBe(1);
92
97
  });
93
98
 
94
- it('should return rounded percentage when baseValue is truthy', () => {
95
- expect(getPercentageValue(25, 200)).toBe(13);
96
- expect(getPercentageValue(50, 200)).toBe(25);
97
- expect(getPercentageValue(200, 200)).toBe(100);
99
+ it('should return related value when baseValue is truthy', () => {
100
+ expect(getRelatedValue(50, 200)).toBe(0.25);
101
+ expect(getRelatedValue(200, 200)).toBe(1);
102
+ });
103
+ });
104
+
105
+ describe('Function isAbsoluteValue', () => {
106
+ it('should return false if formula is undefined', () => {
107
+ expect(isAbsoluteValue(undefined)).toBe(false);
108
+ });
109
+
110
+ it('should return false if formula is null', () => {
111
+ expect(isAbsoluteValue(null)).toBe(false);
112
+ });
113
+
114
+ it('should return false if formula does not contain "x2-x1"', () => {
115
+ expect(isAbsoluteValue('x2 + x1')).toBe(false);
116
+ expect(isAbsoluteValue('x1-x2')).toBe(false);
117
+ expect(isAbsoluteValue('')).toBe(false);
118
+ });
119
+
120
+ it('should return true if formula contains "x2-x1"', () => {
121
+ expect(isAbsoluteValue('x2-x1')).toBe(true);
122
+ expect(isAbsoluteValue(' x2 - x1 ')).toBe(true);
123
+ expect(isAbsoluteValue('some text x2-x1 more text')).toBe(true);
124
+ });
125
+
126
+ it('should ignore spaces in formula', () => {
127
+ expect(isAbsoluteValue('x2 - x1')).toBe(true);
128
+ expect(isAbsoluteValue(' x2 - x1 ')).toBe(true);
98
129
  });
99
130
  });