@datarailsshared/dr_renderer 1.2.333 → 1.2.335

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.333",
3
+ "version": "1.2.335",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -549,7 +549,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
549
549
  var func = function () {
550
550
  var value = parseFloat(this.y);
551
551
  if (pivotData) {
552
- let series_name = (this.series.name || '') + "";
552
+ let series_name = highchartsRenderer.getSeriesNameInFormatterContext(this);
553
553
  var rows = series_name.split(highchartsRenderer.delimer);
554
554
 
555
555
  if (is_drill_down_pie && highchartsRenderer.selfStartsWith(series_name, "Series ")) {
@@ -562,7 +562,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
562
562
  rows = [];
563
563
  }
564
564
 
565
- var cols = lodash.get(this, 'point.options.colsForTotal') || this.key;
565
+ var cols = highchartsRenderer.getColsInFormatterContext(this);
566
566
  if (typeof (cols) == 'object' && cols.name) {
567
567
  cols = cols.name;
568
568
  }
@@ -730,7 +730,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
730
730
 
731
731
  var y = parseFloat(this.y);
732
732
  if (pivotData) {
733
- let series_name = (this.series.name || '') + "";
733
+ let series_name = highchartsRenderer.getSeriesNameInFormatterContext(this);
734
734
  var rows = series_name.split(highchartsRenderer.delimer);
735
735
  if (is_drill_down_pie && highchartsRenderer.selfStartsWith(series_name,"Series ")) {
736
736
  rows = [];
@@ -741,7 +741,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
741
741
  rows = [];
742
742
  }
743
743
 
744
- var cols = lodash.get(this, 'point.options.colsForTotal') || this.key;
744
+ var cols = highchartsRenderer.getColsInFormatterContext(this);
745
745
  if (!cols && is_drill_down_pie) {
746
746
  cols = this.name;
747
747
  }
@@ -768,7 +768,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
768
768
  ? isWaterfallWalkthrough
769
769
  ? this.key
770
770
  : cols[0]
771
- : cols
771
+ : highchartsRenderer.isFormattingAxis() && lodash.get(this, 'point.name') || cols
772
772
  );
773
773
 
774
774
  highchartsRenderer.replaceDrOthersKeys(cols, rows, drOthersInAxis, othersName);
@@ -3929,11 +3929,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3929
3929
 
3930
3930
  highchartsRenderer.rhPivotCount = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
3931
3931
  var attr = arg[0];
3932
- // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
3933
- // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
3934
- // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
3935
- const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
3936
-
3937
3932
  return function (data, rowKey, colKey) {
3938
3933
  return {
3939
3934
  sum: 0,
@@ -3993,11 +3988,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3993
3988
  number_format = 'General';
3994
3989
  }
3995
3990
 
3996
- if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
3997
- number_format = this.widget_values_format;
3998
- }
3999
-
4000
- if (isCustomValuesFormat) {
3991
+ if (this.widget_values_format && highchartsRenderer.isUsingWidgetValuesFormat(data, render_options, widget_values_format)) {
4001
3992
  number_format = this.widget_values_format;
4002
3993
  }
4003
3994
 
@@ -4085,11 +4076,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4085
4076
 
4086
4077
  highchartsRenderer.rhPivotAggregatorSum = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4087
4078
  var attr = arg[0];
4088
- // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4089
- // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4090
- // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4091
- const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4092
-
4093
4079
  return function (data, rowKey, colKey) {
4094
4080
  return {
4095
4081
  sum: 0,
@@ -4161,13 +4147,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4161
4147
  number_format = 'General';
4162
4148
  }
4163
4149
 
4164
- if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4150
+ if (this.widget_values_format && highchartsRenderer.isUsingWidgetValuesFormat(data, render_options, widget_values_format)) {
4165
4151
  number_format = this.widget_values_format;
4166
4152
  }
4167
4153
 
4168
- if (isCustomValuesFormat) {
4169
- number_format = this.widget_values_format;
4170
- }
4171
4154
  number_format = highchartsRenderer.getCalculatedValueFormat(this.calculated_formats, rowKey, colKey) || number_format;
4172
4155
  var formated_value = highchartsRenderer.formatValue('n', number_format, x)
4173
4156
 
@@ -4185,11 +4168,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4185
4168
 
4186
4169
  highchartsRenderer.rhPivotAggregatorMin = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4187
4170
  var attr = arg[0];
4188
- // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4189
- // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4190
- // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4191
- const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4192
-
4193
4171
  return function (data, rowKey, colKey) {
4194
4172
  return {
4195
4173
  val: null,
@@ -4259,11 +4237,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4259
4237
  number_format = 'General';
4260
4238
  }
4261
4239
 
4262
- if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4263
- number_format = this.widget_values_format;
4264
- }
4265
-
4266
- if (isCustomValuesFormat) {
4240
+ if (this.widget_values_format && highchartsRenderer.isUsingWidgetValuesFormat(data, render_options, widget_values_format)) {
4267
4241
  number_format = this.widget_values_format;
4268
4242
  }
4269
4243
 
@@ -4284,11 +4258,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4284
4258
 
4285
4259
  highchartsRenderer.rhPivotAggregatorMax = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4286
4260
  var attr = arg[0];
4287
- // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4288
- // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4289
- // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4290
- const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4291
-
4292
4261
  return function (data, rowKey, colKey) {
4293
4262
  return {
4294
4263
  val: null,
@@ -4359,11 +4328,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4359
4328
  number_format = 'General';
4360
4329
  }
4361
4330
 
4362
- if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4363
- number_format = this.widget_values_format;
4364
- }
4365
-
4366
- if (isCustomValuesFormat) {
4331
+ if (this.widget_values_format && highchartsRenderer.isUsingWidgetValuesFormat(data, render_options, widget_values_format)) {
4367
4332
  number_format = this.widget_values_format;
4368
4333
  }
4369
4334
 
@@ -4384,11 +4349,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4384
4349
 
4385
4350
  highchartsRenderer.rhPivotAggregatorAverage = function (arg, widget_values_format, is_graph, render_options, calculated_info) {
4386
4351
  var attr = arg[0];
4387
- // isCustomValues format need for check in case when customer apply SecondaryAxis and one of them is true
4388
- // in that case we take formats from seriesOptions and apply those format to each one of them their format from the table
4389
- // method isCustomValuesFormat check if format was added custom format by self or it's a default format from table
4390
- const isCustomValuesFormat = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4391
-
4392
4352
  return function (data, rowKey, colKey) {
4393
4353
  return {
4394
4354
  sum: 0,
@@ -4466,11 +4426,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
4466
4426
  number_format = 'General';
4467
4427
  }
4468
4428
 
4469
- if (this.widget_values_format && !highchartsRenderer.enabledNewWidgetValueFormatting) {
4470
- number_format = this.widget_values_format;
4471
- }
4472
-
4473
- if (isCustomValuesFormat) {
4429
+ if (this.widget_values_format && highchartsRenderer.isUsingWidgetValuesFormat(data, render_options, widget_values_format)) {
4474
4430
  number_format = this.widget_values_format;
4475
4431
  }
4476
4432
 
@@ -9331,6 +9287,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9331
9287
  }
9332
9288
  }
9333
9289
 
9290
+ // Check if chart has multiple values
9291
+ highchartsRenderer.isChartWithMultiValues = function(pivotData) {
9292
+ return lodash.get(pivotData, 'rowAttrs[0]') === 'DR_Values';
9293
+ }
9294
+
9334
9295
  highchartsRenderer.checkFormats = function(render_options, widget_values_format) {
9335
9296
  let isSecondaryAxis = false;
9336
9297
  let formats = [];
@@ -9353,9 +9314,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9353
9314
  return formats;
9354
9315
  }
9355
9316
 
9356
- highchartsRenderer.isCustomValuesFormat = function (render_options, widget_values_format) {
9317
+ // Will be FALSE when all 4 conditions true: 1. User applies SecondaryAxis 2. Format on 'format editor panel' is same as any Value field table format
9318
+ // 3. Chart has more than one value fields in Values block 4. enable_new_widget_value_formatting is turned ON
9319
+ // In that case we apply for both value fields their format from the table
9320
+ // In all other cases we are applying format from editor panel to both of them (specification: DR-20955)
9321
+ highchartsRenderer.isUsingWidgetValuesFormat = function (pivotData, render_options, widget_values_format) {
9357
9322
  const { isSecondaryAxis, isCustomFormat } = highchartsRenderer.checkFormats(render_options, widget_values_format);
9358
- return highchartsRenderer.enabledNewWidgetValueFormatting && (isCustomFormat || !isSecondaryAxis);
9323
+ return !highchartsRenderer.enabledNewWidgetValueFormatting || !highchartsRenderer.isChartWithMultiValues(pivotData) || !isSecondaryAxis || isCustomFormat;
9359
9324
  }
9360
9325
 
9361
9326
  highchartsRenderer.isFormattingAxis = function () {
@@ -9414,6 +9379,16 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9414
9379
  lodash.set(e, 'point.category.userOptions', e.point.initialName.toString().split(highchartsRenderer.delimer));
9415
9380
  }
9416
9381
 
9382
+ highchartsRenderer.getSeriesNameInFormatterContext = function(context) {
9383
+ return ((highchartsRenderer.isFormattingAxis() && lodash.get(context, 'series.userOptions.initialName')) || context.series.name || '') + "";
9384
+ }
9385
+
9386
+ highchartsRenderer.getColsInFormatterContext = function(context) {
9387
+ return lodash.get(context, 'point.options.colsForTotal')
9388
+ || highchartsRenderer.isFormattingAxis() && (lodash.get(context, 'point.initialName') || lodash.get(context, 'options.initialName'))
9389
+ || context.key;
9390
+ }
9391
+
9417
9392
  return highchartsRenderer;
9418
9393
  };
9419
9394
 
@@ -4741,8 +4741,18 @@ describe('highcharts_renderer', () => {
4741
4741
  });
4742
4742
  });
4743
4743
 
4744
- describe('function isCustomValuesFormat', () => {
4745
- const render_options = {
4744
+ describe('function isChartWithMultiValues', () => {
4745
+ it('should return true if DR_Values in attributes', () => {
4746
+ expect(highchartsRenderer.isChartWithMultiValues({ rowAttrs: ['DR_Values'] })).toEqual(true);
4747
+ });
4748
+
4749
+ it('should return false if no DR_Values in attributes', () => {
4750
+ expect(highchartsRenderer.isChartWithMultiValues({ rowAttrs: ['Profit'] })).toEqual(false);
4751
+ });
4752
+ });
4753
+
4754
+ describe('function isUsingWidgetValuesFormat', () => {
4755
+ const renderOptions = {
4746
4756
  comboOptions: {
4747
4757
  seriesOptions: [
4748
4758
  { series: 'Profit', format: '#,###', secondaryAxis: false },
@@ -4751,40 +4761,51 @@ describe('highcharts_renderer', () => {
4751
4761
  }
4752
4762
  };
4753
4763
 
4754
- it('should return true if new widget value formatting is enabled and the format is custom or there is no secondary axis', () => {
4755
- const widget_values_format = '$####.##';
4756
-
4757
- highchartsRenderer.enabledNewWidgetValueFormatting = true;
4758
-
4759
- const expectedValue = true;
4760
-
4761
- const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4764
+ it('should return true (enable_new_widget_value_formatting !== true, format is not custom, secondary axis present, >1 value fields)', () => {
4765
+ const widgetValuesFormat = '#,###';
4766
+ const pivotData = { rowAttrs: ['DR_Values'] };
4767
+ highchartsRenderer.enabledNewWidgetValueFormatting = false;
4762
4768
 
4763
- expect(result).toEqual(expectedValue);
4769
+ const result = highchartsRenderer.isUsingWidgetValuesFormat(pivotData, renderOptions, widgetValuesFormat);
4770
+ expect(result).toEqual(true);
4764
4771
  });
4765
4772
 
4766
- it('should return false if new widget value formatting is disabled', () => {
4767
- const widget_values_format = '#,###';
4768
-
4769
- highchartsRenderer.enabledNewWidgetValueFormatting = false;
4773
+ it('should return true (enable_new_widget_value_formatting === true, format is custom, secondary axis present, >1 value fields)', () => {
4774
+ const widgetValuesFormat = '$#,###';
4775
+ const pivotData = { rowAttrs: ['DR_Values'] };
4776
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4770
4777
 
4771
- const expectedValue = false;
4778
+ const result = highchartsRenderer.isUsingWidgetValuesFormat(pivotData, renderOptions, widgetValuesFormat);
4779
+ expect(result).toEqual(true);
4780
+ });
4772
4781
 
4773
- const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4782
+ it('should return true (enable_new_widget_value_formatting === true, format is not custom, secondary axis not present, >1 value fields)', () => {
4783
+ const widgetValuesFormat = '#,###';
4784
+ const pivotData = { rowAttrs: ['DR_Values'] };
4785
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4786
+ const renderOptionsNoSecondary = lodash.cloneDeep(renderOptions);
4787
+ renderOptionsNoSecondary.comboOptions.seriesOptions[1].secondaryAxis = false;
4774
4788
 
4775
- expect(result).toEqual(expectedValue);
4789
+ const result = highchartsRenderer.isUsingWidgetValuesFormat(pivotData, renderOptionsNoSecondary, widgetValuesFormat);
4790
+ expect(result).toEqual(true);
4776
4791
  });
4777
4792
 
4778
- it('should return false if the format is not custom and there is a secondary axis', () => {
4779
- const widget_values_format = '#,###';
4780
-
4793
+ it('should return true (enable_new_widget_value_formatting === true, format is not custom, secondary axis present, 1 value fields)', () => {
4794
+ const widgetValuesFormat = '#,###';
4795
+ const pivotData = { rowAttrs: ['Profit'] };
4781
4796
  highchartsRenderer.enabledNewWidgetValueFormatting = true;
4782
4797
 
4783
- const expectedValue = false;
4798
+ const result = highchartsRenderer.isUsingWidgetValuesFormat(pivotData, renderOptions, widgetValuesFormat);
4799
+ expect(result).toEqual(true);
4800
+ });
4784
4801
 
4785
- const result = highchartsRenderer.isCustomValuesFormat(render_options, widget_values_format);
4802
+ it('should return false (enable_new_widget_value_formatting === true, format is not custom, secondary axis present, >1 value fields)', () => {
4803
+ const widgetValuesFormat = '#,###';
4804
+ const pivotData = { rowAttrs: ['DR_Values'] };
4805
+ highchartsRenderer.enabledNewWidgetValueFormatting = true;
4786
4806
 
4787
- expect(result).toEqual(expectedValue);
4807
+ const result = highchartsRenderer.isUsingWidgetValuesFormat(pivotData, renderOptions, widgetValuesFormat);
4808
+ expect(result).toEqual(false);
4788
4809
  });
4789
4810
  });
4790
4811
 
@@ -5162,4 +5183,117 @@ describe('highcharts_renderer', () => {
5162
5183
  expect(e.point.category.userOptions).toEqual([event.point.initialName]);
5163
5184
  });
5164
5185
  });
5186
+
5187
+ describe('Function getSeriesNameInFormatterContext', () => {
5188
+
5189
+ const name1 = 'test series name';
5190
+ const name2 = 'test series name 2';
5191
+
5192
+ it('should return series.userOptions.initialName if it is present and axis formatting is on', () => {
5193
+ lodash.set(document, 'ReportHippo.user.features', ['use_default_table_format_for_axis']);
5194
+ const context = {
5195
+ series: {
5196
+ userOptions: {
5197
+ initialName: name1,
5198
+ },
5199
+ name: name2,
5200
+ }
5201
+ }
5202
+ expect(highchartsRenderer.getSeriesNameInFormatterContext(context)).toEqual(name1);
5203
+ });
5204
+
5205
+ it('should return series.name if axis formatting is on but series.userOptions.initialName is not present', () => {
5206
+ lodash.set(document, 'ReportHippo.user.features', ['use_default_table_format_for_axis']);
5207
+ const context = {
5208
+ series: {
5209
+ name: name2,
5210
+ }
5211
+ }
5212
+ expect(highchartsRenderer.getSeriesNameInFormatterContext(context)).toEqual(name2);
5213
+ });
5214
+
5215
+ it('should return series.name if series.userOptions.initialName is present but axis formatting is off', () => {
5216
+ lodash.set(document, 'ReportHippo.user.features', []);
5217
+ const context = {
5218
+ series: {
5219
+ userOptions: {
5220
+ initialName: name1,
5221
+ },
5222
+ name: name2,
5223
+ }
5224
+ }
5225
+ expect(highchartsRenderer.getSeriesNameInFormatterContext(context)).toEqual(name2);
5226
+ });
5227
+ });
5228
+
5229
+ describe('Function getColsInFormatterContext', () => {
5230
+
5231
+ const name1 = 'test series name 1';
5232
+ const name2 = 'test series name 2';
5233
+ const name3 = 'test series name 3';
5234
+
5235
+ it('should return point.options.colsForTotal if it is present', () => {
5236
+ const context = {
5237
+ point: {
5238
+ initialName: name1,
5239
+ options: {
5240
+ colsForTotal: name3
5241
+ }
5242
+ },
5243
+ key: name2,
5244
+ }
5245
+
5246
+ lodash.forEach(['use_default_table_format_for_axis'], [], features => {
5247
+ lodash.set(document, 'ReportHippo.user.features', features);
5248
+ expect(highchartsRenderer.getColsInFormatterContext(context)).toEqual(name3);
5249
+ });
5250
+ });
5251
+
5252
+ it('should return point.initialName if it is present and FF is on and colsForTotal is not present', () => {
5253
+ lodash.set(document, 'ReportHippo.user.features', ['use_default_table_format_for_axis']);
5254
+ const context = {
5255
+ point: {
5256
+ initialName: name1,
5257
+ },
5258
+ options: {
5259
+ initialName: name3,
5260
+ },
5261
+ key: name2,
5262
+ }
5263
+ expect(highchartsRenderer.getColsInFormatterContext(context)).toEqual(name1);
5264
+ });
5265
+
5266
+ it('should return context.key if FF is off and colsForTotal is not present', () => {
5267
+ lodash.set(document, 'ReportHippo.user.features', []);
5268
+ const context = {
5269
+ point: {
5270
+ initialName: name1,
5271
+ },
5272
+ options: {
5273
+ initialName: name3,
5274
+ },
5275
+ key: name2,
5276
+ }
5277
+ expect(highchartsRenderer.getColsInFormatterContext(context)).toEqual(name2);
5278
+ });
5279
+
5280
+ it('should return options.initialName if FF is on, colsForTotal is not present and point.initialName is not present', () => {
5281
+ lodash.set(document, 'ReportHippo.user.features', ['use_default_table_format_for_axis']);
5282
+ const context = {
5283
+ options: {
5284
+ initialName: name3,
5285
+ },
5286
+ key: name2,
5287
+ }
5288
+ expect(highchartsRenderer.getColsInFormatterContext(context)).toEqual(name3);
5289
+ });
5290
+
5291
+ it('should return context.key if FF is on, no colsForTotal a, no point.initialName no options.initialName', () => {
5292
+ lodash.set(document, 'ReportHippo.user.features', ['use_default_table_format_for_axis']);
5293
+ const context = {
5294
+ key: name2,
5295
+ }
5296
+ expect(highchartsRenderer.getColsInFormatterContext(context)).toEqual(name2);
5297
+ });
5298
+ });
5165
5299
  });