@datarailsshared/dr_renderer 1.5.100 → 1.5.103

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.5.100",
3
+ "version": "1.5.103",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -10,8 +10,6 @@ let initDRPivotTable = function($, window, document) {
10
10
  const newTableColors = ['rgb(127, 196, 255)', 'rgb(200, 243,243)', 'rgb(247, 161, 173)', 'rgb(255, 237, 178)', 'rgb(221, 239, 255)',
11
11
  'rgb(171, 216, 255)', 'rgb(174, 231, 220)', 'rgb(227, 255, 236)', 'rgb(162, 215, 227)', 'rgb(223, 239, 236)'];
12
12
 
13
- const useNewUx = document.ReportHippo && document.ReportHippo && document.ReportHippo.user &&
14
- document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
15
13
  // const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
16
14
 
17
15
  DRPivotData = (function(superClass) {
@@ -437,7 +435,7 @@ let initDRPivotTable = function($, window, document) {
437
435
  colors = newTableColors;
438
436
  }
439
437
 
440
- var isNewDesign = useNewUx && opts.chartOptions.table_options.use_new_table_design;
438
+ var isNewDesign = opts.chartOptions && opts.chartOptions.table_options && opts.chartOptions.table_options.use_new_table_design;
441
439
  if (value) {
442
440
  var offset = parseInt(value);
443
441
  if (offset) {
@@ -500,12 +498,12 @@ let initDRPivotTable = function($, window, document) {
500
498
  };
501
499
 
502
500
  createTotalValsBolder = function(element){
503
- if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
501
+ if(opts.chartOptions.table_options.colorize_headers == true && (!opts.chartOptions.table_options.use_new_table_design)){
504
502
  element.style.setProperty("border-bottom", "3px double #000000", "important");
505
503
  }
506
504
  };
507
505
  createGrandTotalBolder = function(element){
508
- if(opts.chartOptions.table_options.colorize_headers == true && (!useNewUx || !opts.chartOptions.table_options.use_new_table_design)){
506
+ if(opts.chartOptions.table_options.colorize_headers == true && (!opts.chartOptions.table_options.use_new_table_design)){
509
507
  element.style.setProperty("border-top", "3px solid #000000", "important");
510
508
  }
511
509
  };
@@ -173,7 +173,7 @@ const FEATURES = helpers.FEATURES;
173
173
  const TICKS_COUNT = 5;
174
174
 
175
175
  let getHighchartsRenderer = function ($, document, Highcharts, default_colors, highchartsRenderer,
176
- DataFormatter, lodash, moment_lib, isNewAngular) {
176
+ DataFormatter, lodash, moment_lib, isNewAngular, envOptions) {
177
177
 
178
178
  /** Highcharts initial configuration section **/
179
179
  if(!lodash){
@@ -214,6 +214,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
214
214
 
215
215
  highchartsRenderer.enabledNewWidgetValueFormatting = false;
216
216
  let disableAnimation = false;
217
+ const environment = envOptions || {};
218
+ highchartsRenderer.environment = environment;
217
219
 
218
220
  const _handleComputationalError = (err, onlyOptions) => {
219
221
  if (err instanceof BaseRendererError) {
@@ -244,13 +246,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
244
246
  }
245
247
 
246
248
  highchartsRenderer.hasFeature = function(featureFlagKey) {
247
- return lodash.includes(lodash.get(document, 'ReportHippo.user.features', []), featureFlagKey);
249
+ return lodash.includes(highchartsRenderer.features || [], featureFlagKey);
248
250
  }
249
-
250
- if (!!lodash.get(document, 'ReportHippo.user')) {
251
- disableAnimation = document.ReportHippo.user.organization && document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.disable_animation
251
+ highchartsRenderer.setFeatures = function(features) {
252
+ highchartsRenderer.features = features || [];
252
253
  highchartsRenderer.enabledNewWidgetValueFormatting = highchartsRenderer.hasFeature(FEATURES.ENABLE_NEW_WIDGET_VALUE_FORMATTING);
253
254
  }
255
+ highchartsRenderer.setFeatures(lodash.get(environment, 'features', []));
256
+ disableAnimation = !!lodash.get(environment, 'disable_animation', false);
254
257
 
255
258
  // fix issue of use tootip.stickOnContact with tooltip.outside , source: https://github.com/highcharts/highcharts/pull/15960
256
259
  // TODO: remove it after it is fixed in highcharts library new version
@@ -964,7 +967,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
964
967
  tempAr[temp_len - 1] = highchartsRenderer.getFieldName(colAttrs[j]);
965
968
  }
966
969
 
967
- const formattedColKeys = highchartsRenderer.getFormattedColKeys(pivotData, null);
970
+ const formattedColKeys = highchartsRenderer.getFormattedColKeys(pivotData, null, true);
968
971
  tempAr = tempAr.concat(lodash.map(formattedColKeys, function (row) {
969
972
  return row[j];
970
973
  }));
@@ -9440,11 +9443,11 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9440
9443
  }
9441
9444
 
9442
9445
  highchartsRenderer.getFiscalYearMonthModifier = function() {
9443
- return lodash.get(document, 'ReportHippo.user.organization.fiscal_year_starts_from', 1) - 1;
9446
+ return lodash.get(highchartsRenderer, 'environment.fiscal_year_starts_from', 1) - 1;
9444
9447
  }
9445
9448
 
9446
9449
  highchartsRenderer.isFiscalYearBackEnabled = function() {
9447
- return lodash.get(document, 'ReportHippo.user.organization.fiscal_year_back');
9450
+ return lodash.get(highchartsRenderer, 'environment.fiscal_year_back');
9448
9451
  }
9449
9452
 
9450
9453
  highchartsRenderer.getTimeframeByFormat = function(format) {
@@ -9504,7 +9507,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9504
9507
  }
9505
9508
 
9506
9509
  // Method for getting formatted kyes for Axis (cols, rows)
9507
- highchartsRenderer.getFormattedKey = function (initialKey, pivotData, type) {
9510
+ highchartsRenderer.getFormattedKey = function (initialKey, pivotData, type, forceFormatDates) {
9508
9511
  const isFlatKey = lodash.isString(initialKey) || lodash.isNumber(initialKey);
9509
9512
  if (isFlatKey || lodash.isArray(initialKey)) {
9510
9513
  let values = isFlatKey ? initialKey.toString().split(highchartsRenderer.delimer) : lodash.cloneDeep(initialKey);
@@ -9513,7 +9516,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9513
9516
  const formatInfo = pivotData[type][key] || {};
9514
9517
  const valueToFloat = parseFloat(value);
9515
9518
  const isDate = formatInfo.type === 'Date' && (moment_lib(valueToFloat).isValid() || moment_lib(value, formatInfo.format).isValid());
9516
- const isDateFormatting = isDate && highchartsRenderer.isFormattingDatesAsOtherAxisTypes();
9519
+ const isDateFormatting = isDate && (forceFormatDates || highchartsRenderer.isFormattingDatesAsOtherAxisTypes());
9517
9520
  const isNumberFormatting = !isDate && formatInfo.format && highchartsRenderer.isFormattingNumberAxis(pivotData);
9518
9521
 
9519
9522
  if (isNumberFormatting || isDateFormatting) {
@@ -9541,13 +9544,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
9541
9544
  return highchartsRenderer.getFormattedKey(initialValue, pivotData, 'rowFormats')
9542
9545
  }
9543
9546
 
9544
- highchartsRenderer.getFormattedKeys = function(pivotData, isCols, keys) {
9547
+ highchartsRenderer.getFormattedKeys = function(pivotData, isCols, keys, forceFormatDates) {
9545
9548
  keys = keys || (isCols ? pivotData.getColKeys() : pivotData.getRowKeys());
9546
- return lodash.map(keys, key => highchartsRenderer.getFormattedKey(key, pivotData, isCols ? 'colFormats' : 'rowFormats'));
9549
+ return lodash.map(keys, key => highchartsRenderer.getFormattedKey(key, pivotData, isCols ? 'colFormats' : 'rowFormats', forceFormatDates));
9547
9550
  }
9548
9551
 
9549
- highchartsRenderer.getFormattedColKeys = function(pivotData, keys) {
9550
- return highchartsRenderer.getFormattedKeys(pivotData, true, keys);
9552
+ highchartsRenderer.getFormattedColKeys = function(pivotData, keys, forceFormatDates) {
9553
+ return highchartsRenderer.getFormattedKeys(pivotData, true, keys, forceFormatDates);
9551
9554
  }
9552
9555
 
9553
9556
  highchartsRenderer.getFormattedRowKeys = function(pivotData, keys) {
package/src/index.d.ts CHANGED
@@ -31,6 +31,13 @@ declare namespace DrRenderFactory {
31
31
  isNewAngular: boolean;
32
32
  }
33
33
 
34
+ interface EnvironmentOptions {
35
+ features?: string[];
36
+ disable_animation?: boolean;
37
+ fiscal_year_starts_from?: number;
38
+ fiscal_year_back?: boolean;
39
+ }
40
+
34
41
  interface Factory {
35
42
  init($: any, window: Window, document: Document, Handsontable?: any): void;
36
43
  getInitHighchartsRenderer(
@@ -41,12 +48,13 @@ declare namespace DrRenderFactory {
41
48
  highchartsRenderer: any,
42
49
  lodash: any,
43
50
  moment_lib: any,
44
- isNewAngular: boolean
51
+ isNewAngular: boolean,
52
+ envOptions?: EnvironmentOptions
45
53
  ): any;
46
54
  getInitPublishedItemsRenderer(publishedItemsRenderer: any, bind?: any): any;
47
55
 
48
56
  DataFormatter: typeof DataFormatterType;
49
-
57
+
50
58
  // Error types and classes
51
59
  RendererErrorCodes: typeof ErrorTypes.RendererErrorCodes;
52
60
  BaseRendererError: typeof ErrorTypes.BaseRendererError;
package/src/index.js CHANGED
@@ -17,8 +17,8 @@ dr_render_factory.init = function($, window, document, Handsontable){
17
17
  }
18
18
  }
19
19
 
20
- dr_render_factory.getInitHighchartsRenderer = function($, document, Highcharts, default_colors, highchartsRenderer, lodash, moment_lib, isNewAngular){
21
- return getHighchartsRenderer($, document, Highcharts, default_colors, highchartsRenderer, DataFormatter, lodash, moment_lib, isNewAngular);
20
+ dr_render_factory.getInitHighchartsRenderer = function($, document, Highcharts, default_colors, highchartsRenderer, lodash, moment_lib, isNewAngular, envOptions){
21
+ return getHighchartsRenderer($, document, Highcharts, default_colors, highchartsRenderer, DataFormatter, lodash, moment_lib, isNewAngular, envOptions);
22
22
  }
23
23
 
24
24
  dr_render_factory.getInitPublishedItemsRenderer = function (publishedItemsRenderer, bind = {}) {
@@ -1624,7 +1624,7 @@ describe('highcharts_renderer', () => {
1624
1624
 
1625
1625
  describe('dynamic system fields', () => {
1626
1626
  it('should count Scenario & Budget Cycle as system field', () => {
1627
- lodash.set(document, 'ReportHippo.user.features', ['multiple_dimension_tags', 'use_new_scenario_tag']);
1627
+ highchartsRenderer.setFeatures(['multiple_dimension_tags', 'use_new_scenario_tag']);
1628
1628
 
1629
1629
  const fieldWithScenario = { name: 'Scenario' };
1630
1630
  expect(highchartsRenderer.isSystemField(fieldWithScenario)).toBe(true);
@@ -5085,7 +5085,7 @@ describe('highcharts_renderer', () => {
5085
5085
  });
5086
5086
 
5087
5087
  it('should return formatted multivalue colKey as array (format_dates_as_other_axis_types is ON)', () => {
5088
- lodash.set(document, 'ReportHippo.user.features', ['format_dates_as_other_axis_types']);
5088
+ highchartsRenderer.setFeatures(['format_dates_as_other_axis_types']);
5089
5089
  const initialKey = [1687277052, 1687277052];
5090
5090
  const pivotData = {
5091
5091
  colFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
@@ -5097,7 +5097,7 @@ describe('highcharts_renderer', () => {
5097
5097
  });
5098
5098
 
5099
5099
  it('should return formatted multivalue rowKey as array (format_dates_as_other_axis_types is ON)', () => {
5100
- lodash.set(document, 'ReportHippo.user.features', ['format_dates_as_other_axis_types']);
5100
+ highchartsRenderer.setFeatures(['format_dates_as_other_axis_types']);
5101
5101
  const initialKey = [1687277052, 1687277052];
5102
5102
  const pivotData = {
5103
5103
  rowFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
@@ -5109,7 +5109,7 @@ describe('highcharts_renderer', () => {
5109
5109
  });
5110
5110
 
5111
5111
  it('should return NOT formatted multivalue colKey as array (format_dates_as_other_axis_types is OFF)', () => {
5112
- lodash.set(document, 'ReportHippo.user.features', []);
5112
+ highchartsRenderer.setFeatures([]);
5113
5113
  const initialKeyAlreadyFormatted = ['10/10/2020', '10/10/2021'];
5114
5114
  const pivotData = {
5115
5115
  colFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
@@ -5121,7 +5121,7 @@ describe('highcharts_renderer', () => {
5121
5121
  });
5122
5122
 
5123
5123
  it('should return NOT formatted multivalue rowKey as array (format_dates_as_other_axis_types is OFF)', () => {
5124
- lodash.set(document, 'ReportHippo.user.features', []);
5124
+ highchartsRenderer.setFeatures([]);
5125
5125
  const initialKeyAlreadyFormatted = ['10/10/2020', '10/10/2021'];
5126
5126
  const pivotData = {
5127
5127
  rowFormats: [{ type: 'Date', format: 'MM/DD/YYYY' }, { type: 'Date', format: 'MMM-yy' }],
@@ -5266,7 +5266,7 @@ describe('highcharts_renderer', () => {
5266
5266
 
5267
5267
  it('should getFormattedColKeys call getFormattedKeys for colFormats', () => {
5268
5268
  highchartsRenderer.getFormattedColKeys('test1', 'test2');
5269
- expect(highchartsRenderer.getFormattedKeys).toHaveBeenCalledWith('test1', true, 'test2');
5269
+ expect(highchartsRenderer.getFormattedKeys).toHaveBeenCalledWith('test1', true, 'test2', undefined);
5270
5270
  });
5271
5271
 
5272
5272
  it('should getFormattedRowKeys call getFormattedKeys for rowFormats', () => {