@datarailsshared/dr_renderer 1.3.25 → 1.3.27

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.3.25",
3
+ "version": "1.3.27",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1,3 +1,5 @@
1
+ const helpers = require('./../dr-renderer-helpers');
2
+
1
3
  function DrDonutChart(highchartsRenderer, pivotData, opts, drilldownFunc, disableAnimation) {
2
4
  const additionOptions = opts.chartOptions
3
5
  ? opts.chartOptions
@@ -19,6 +21,7 @@ function DrDonutChart(highchartsRenderer, pivotData, opts, drilldownFunc, disabl
19
21
 
20
22
  config.series = highchartsRenderer.ptCreateSeriesToDrillDownChart(pivotData, config, additionOptions, opts);
21
23
  highchartsRenderer.setTitleAndSubTitle(config, opts, additionOptions);
24
+ helpers.disableLegendInteractionIfRequired(config, additionOptions);
22
25
  this.setDrilldownConfig(config);
23
26
 
24
27
  return config;
@@ -87,7 +90,10 @@ function DrDonutChart(highchartsRenderer, pivotData, opts, drilldownFunc, disabl
87
90
  const series = chart.series[0];
88
91
 
89
92
  const aggTotal = pivotData.getAggregator([], []);
90
- const formattedValue = aggTotal.format(series.total, true);
93
+ const formattedValue =
94
+ additionOptions && additionOptions.customTotalValueFormatFn
95
+ ? additionOptions.customTotalValueFormatFn(series.total)
96
+ : aggTotal.format(series.total, true);
91
97
 
92
98
  if (totalLabel) {
93
99
  totalLabel.destroy();
@@ -124,7 +130,12 @@ function DrDonutChart(highchartsRenderer, pivotData, opts, drilldownFunc, disabl
124
130
  if (drilldownFunc) {
125
131
  chartConfig.drilldown = {};
126
132
  } else if (!pivotData.isDrillDownDisabled) {
127
- chartConfig.drilldown = highchartsRenderer.ptCreateDrillDownSeriesToDrilldownChart(pivotData, chartConfig, additionOptions, opts);
133
+ chartConfig.drilldown = highchartsRenderer.ptCreateDrillDownSeriesToDrilldownChart(
134
+ pivotData,
135
+ chartConfig,
136
+ additionOptions,
137
+ opts,
138
+ );
128
139
  } else {
129
140
  chartConfig.drilldown = highchartsRenderer.getDataLabelsStylesForDrillDown(additionOptions);
130
141
  }
@@ -1,3 +1,5 @@
1
+ const _ = require('lodash');
2
+
1
3
  function backendSortingKeysAreNotEmpty(keys) {
2
4
  return !!keys && (!!keys.row_keys && !!keys.row_keys.length || !!keys.col_keys && !!keys.col_keys.length);
3
5
  }
@@ -48,6 +50,18 @@ function removeSVGTextCorrection(svgEl, corr = 'yCorr') {
48
50
  return svgEl;
49
51
  }
50
52
 
53
+ function disableLegendInteractionIfRequired(chartOptions, additionOptions) {
54
+ const type = _.get(chartOptions, 'chart.type');
55
+ if (!type || !_.get(additionOptions, 'disable_legend_interaction')) return;
56
+
57
+ const legendItemClickFnPath = type === 'pie'
58
+ ? 'plotOptions.pie.point.events.legendItemClick'
59
+ : 'plotOptions.series.events.legendItemClick';
60
+
61
+ _.set(chartOptions, legendItemClickFnPath, () => false);
62
+ _.set(chartOptions, 'legend.itemStyle.cursor', 'default');
63
+ }
64
+
51
65
  module.exports = {
52
66
  backendSortingKeysAreNotEmpty,
53
67
  capitalize,
@@ -55,4 +69,5 @@ module.exports = {
55
69
  isNumber,
56
70
  mergeDeep,
57
71
  removeSVGTextCorrection,
72
+ disableLegendInteractionIfRequired,
58
73
  }
@@ -2203,6 +2203,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2203
2203
  }];
2204
2204
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, 1, false, true);
2205
2205
 
2206
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2207
+
2206
2208
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2207
2209
  };
2208
2210
 
@@ -2418,6 +2420,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2418
2420
  else if (!pivotData.isDrillDownDisabled)
2419
2421
  chartOptions.drilldown = highchartsRenderer.ptCreateDrillDownSeriesToDrilldownChart(pivotData, chartOptions, additionOptions, opts);
2420
2422
 
2423
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2424
+
2421
2425
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2422
2426
 
2423
2427
  };
@@ -2531,6 +2535,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2531
2535
  if (opts.selectedPoint) {
2532
2536
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2533
2537
  }
2538
+
2539
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2540
+
2534
2541
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2535
2542
  };
2536
2543
 
@@ -2616,6 +2623,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2616
2623
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2617
2624
  }
2618
2625
 
2626
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2627
+
2619
2628
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2620
2629
  };
2621
2630
 
@@ -2712,6 +2721,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2712
2721
  if (opts.selectedPoint) {
2713
2722
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2714
2723
  }
2724
+
2725
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2726
+
2715
2727
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2716
2728
  };
2717
2729
 
@@ -2799,6 +2811,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2799
2811
  if (opts.selectedPoint) {
2800
2812
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2801
2813
  }
2814
+
2815
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2816
+
2802
2817
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2803
2818
  };
2804
2819
 
@@ -2866,6 +2881,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2866
2881
 
2867
2882
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
2868
2883
 
2884
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
2885
+
2869
2886
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2870
2887
  };
2871
2888
 
@@ -2983,6 +3000,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2983
3000
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
2984
3001
 
2985
3002
  chartOptions.drilldown = highchartsRenderer.getDataLabelsStylesForDrillDown(additionOptions);
3003
+
3004
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3005
+
2986
3006
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2987
3007
  };
2988
3008
 
@@ -3128,7 +3148,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3128
3148
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3129
3149
  }
3130
3150
 
3131
- highchartsRenderer.handleGridLines(additionOptions, chartOptions)
3151
+ highchartsRenderer.handleGridLines(additionOptions, chartOptions);
3152
+
3153
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3132
3154
 
3133
3155
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3134
3156
  };
@@ -3217,6 +3239,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3217
3239
 
3218
3240
  highchartsRenderer.handleGridLines(additionOptions, chartOptions)
3219
3241
 
3242
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3243
+
3220
3244
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3221
3245
  };
3222
3246
 
@@ -3297,6 +3321,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3297
3321
  if (opts.selectedPoint) {
3298
3322
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3299
3323
  }
3324
+
3325
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3326
+
3300
3327
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3301
3328
  };
3302
3329
 
@@ -3389,7 +3416,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3389
3416
  if (opts.selectedPoint) {
3390
3417
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3391
3418
  }
3392
- highchartsRenderer.handleGridLines(additionOptions, chartOptions)
3419
+ highchartsRenderer.handleGridLines(additionOptions, chartOptions);
3420
+
3421
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3393
3422
 
3394
3423
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3395
3424
  };
@@ -3514,6 +3543,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3514
3543
  if (opts.selectedPoint) {
3515
3544
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3516
3545
  }
3546
+
3547
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3548
+
3517
3549
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3518
3550
  };
3519
3551
 
@@ -3634,6 +3666,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3634
3666
  seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3635
3667
  }
3636
3668
 
3669
+ helpers.disableLegendInteractionIfRequired(chartOptions, additionOptions);
3670
+
3637
3671
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3638
3672
  }
3639
3673
 
@@ -147,4 +147,52 @@ describe('dr-renderer-helpers', () => {
147
147
  expect(svg.xCorr).toBe(0);
148
148
  });
149
149
  });
150
+
151
+ describe('disableLegendInteractionIfRequired', () => {
152
+ const notPieTypes = ['column', 'line', 'area', 'areaspline', 'scatter', 'spline', 'bar', 'waterfall'];
153
+
154
+ it('should not update legend settings', () => {
155
+ const chartOptionsMock = {
156
+ chart: {
157
+ type: 'column',
158
+ },
159
+ };
160
+ const additionOptionsMock = {
161
+ disable_legend_interaction: false,
162
+ };
163
+ drRendererHelpers.disableLegendInteractionIfRequired(chartOptionsMock, additionOptionsMock);
164
+ expect(chartOptionsMock.plotOptions).toBeFalsy();
165
+ expect(chartOptionsMock.legend).toBeFalsy();
166
+ });
167
+
168
+ it('should update legend styles and set click event (for pie chart)', () => {
169
+ const chartOptionsMock = {
170
+ chart: {
171
+ type: 'pie',
172
+ },
173
+ };
174
+ const additionOptionsMock = {
175
+ disable_legend_interaction: true,
176
+ };
177
+ drRendererHelpers.disableLegendInteractionIfRequired(chartOptionsMock, additionOptionsMock);
178
+ expect(chartOptionsMock.plotOptions.pie.point.events.legendItemClick).toEqual(jasmine.any(Function));
179
+ expect(chartOptionsMock.legend.itemStyle.cursor).toEqual('default');
180
+ });
181
+
182
+ notPieTypes.forEach((chartType) => {
183
+ it(`should update legend styles and set click event (for ${ chartType } chart)`, () => {
184
+ const chartOptionsMock = {
185
+ chart: {
186
+ type: chartType,
187
+ },
188
+ };
189
+ const additionOptionsMock = {
190
+ disable_legend_interaction: true,
191
+ };
192
+ drRendererHelpers.disableLegendInteractionIfRequired(chartOptionsMock, additionOptionsMock);
193
+ expect(chartOptionsMock.plotOptions.series.events.legendItemClick).toEqual(jasmine.any(Function));
194
+ expect(chartOptionsMock.legend.itemStyle.cursor).toEqual('default');
195
+ });
196
+ });
197
+ });
150
198
  });