@datarailsshared/dr_renderer 1.2.436 → 1.2.437

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.436",
3
+ "version": "1.2.437",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -1,4 +1,5 @@
1
1
  const helpers = require('./dr-renderer-helpers');
2
+ const seriesPointStylesHelper= require('./seriesPointStyles-helper')
2
3
 
3
4
  const mobileBrowserRegex = new RegExp([
4
5
  '(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)',
@@ -2530,6 +2531,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2530
2531
 
2531
2532
  chartOptions.series = highchartsRenderer.ptCreateSeriesToDrillDownChart(pivotData, chartOptions, additionOptions, opts);
2532
2533
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, 1, false, true);
2534
+ chartOptions.drilldown = highchartsRenderer.getDataLabelsStylesForDrillDown(additionOptions);
2533
2535
  if (drilldownFunc)
2534
2536
  chartOptions.drilldown = {}
2535
2537
  else if (!pivotData.isDrillDownDisabled)
@@ -2641,6 +2643,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2641
2643
  chartOptions.series = highchartsRenderer.ptCreateBasicLineSeries(pivotData, null, null, null, additionOptions, opts, chartOptions);
2642
2644
 
2643
2645
  highchartsRenderer.handleGridLines(additionOptions, chartOptions)
2646
+ if (opts.selectedPoint) {
2647
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2648
+ }
2644
2649
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2645
2650
  };
2646
2651
 
@@ -2722,6 +2727,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2722
2727
  chartOptions.series = highchartsRenderer.ptCreateBasicLineSeries(pivotData, colors, null, null, additionOptions, opts, chartOptions);
2723
2728
 
2724
2729
  highchartsRenderer.handleGridLines(additionOptions, chartOptions)
2730
+ if (opts.selectedPoint) {
2731
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2732
+ }
2725
2733
 
2726
2734
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2727
2735
  };
@@ -2816,6 +2824,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2816
2824
  chartOptions.series = highchartsRenderer.ptCreateBasicLineSeries(pivotData, null, null, null, additionOptions, opts, chartOptions);
2817
2825
 
2818
2826
  highchartsRenderer.handleGridLines(additionOptions, chartOptions);
2827
+ if (opts.selectedPoint) {
2828
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2829
+ }
2819
2830
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2820
2831
  };
2821
2832
 
@@ -2900,6 +2911,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2900
2911
 
2901
2912
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
2902
2913
 
2914
+ if (opts.selectedPoint) {
2915
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
2916
+ }
2903
2917
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
2904
2918
  };
2905
2919
 
@@ -2991,7 +3005,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2991
3005
  drilldownFunc(e, this, "drillup");
2992
3006
 
2993
3007
  }
2994
-
2995
3008
  }
2996
3009
  };
2997
3010
  if (disableAnimation) {
@@ -3066,8 +3079,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3066
3079
  }
3067
3080
  }
3068
3081
  };
3069
-
3070
3082
  if (opts.drillDownListFunc) {
3083
+ chartOptions.plotOptions.series = {
3084
+ animation: !disableAnimation,
3085
+ };
3071
3086
  chartOptions.plotOptions.series.cursor = 'pointer';
3072
3087
  chartOptions.plotOptions.series.point = {
3073
3088
  events: {
@@ -3076,6 +3091,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3076
3091
  };
3077
3092
  }
3078
3093
  chartOptions.plotOptions.series = highchartsRenderer.getDataLabelsOptions(additionOptions, chartOptions.plotOptions.series);
3094
+
3095
+ if (opts.selectedPoint) {
3096
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3097
+ }
3079
3098
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
3080
3099
 
3081
3100
  chartOptions.drilldown = highchartsRenderer.getDataLabelsStylesForDrillDown(additionOptions);
@@ -3220,6 +3239,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3220
3239
  }
3221
3240
  chartOptions.series = highchartsRenderer.ptCreateColumnSeries(pivotData, chartOptions.colors, null, true, true, additionOptions, opts, chartOptions, chartType);
3222
3241
  //chartOptions.drilldown = {}
3242
+ if (opts.selectedPoint) {
3243
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3244
+ }
3223
3245
 
3224
3246
  highchartsRenderer.handleGridLines(additionOptions, chartOptions)
3225
3247
 
@@ -3386,9 +3408,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3386
3408
  }
3387
3409
  };
3388
3410
  }
3389
-
3390
3411
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
3391
-
3412
+ if (opts.selectedPoint) {
3413
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3414
+ }
3392
3415
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3393
3416
  };
3394
3417
 
@@ -3478,6 +3501,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3478
3501
  chartOptions = highchartsRenderer.prepareAxisX(chartOptions, additionOptions, pivotData.getColKeys());
3479
3502
  chartOptions.series = highchartsRenderer.ptCreateBasicLineSeries(pivotData, null, null, null, null, opts, chartOptions);
3480
3503
 
3504
+ if (opts.selectedPoint) {
3505
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3506
+ }
3481
3507
  highchartsRenderer.handleGridLines(additionOptions, chartOptions)
3482
3508
 
3483
3509
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
@@ -3600,6 +3626,9 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3600
3626
  formatter: highchartsRenderer.getBreakdownXAxisLabelFormatter(chartOptions.series),
3601
3627
  };
3602
3628
 
3629
+ if (opts.selectedPoint) {
3630
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3631
+ }
3603
3632
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3604
3633
  };
3605
3634
 
@@ -3716,6 +3745,10 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3716
3745
  }
3717
3746
  }
3718
3747
 
3748
+ if (opts.selectedPoint) {
3749
+ seriesPointStylesHelper.setInitialPointStyles(opts, chartOptions.series);
3750
+ }
3751
+
3719
3752
  return highchartsRenderer.ptCreateElementAndDraw(chartOptions, opts);
3720
3753
  }
3721
3754
 
@@ -5933,22 +5966,28 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5933
5966
  if (fnToReturn == null)
5934
5967
  fnToReturn = highchartsRenderer.ptRenderBasicLine;
5935
5968
 
5936
- var fnunctionToReturn = function (pivotData, opt) {
5969
+ return function(pivotData, opt) {
5937
5970
  if (drillDownListFunc) {
5938
5971
  if (!opt) {
5939
5972
  opt = {};
5940
5973
  }
5941
- opt.drillDownListFunc = (e) => {
5942
- highchartsRenderer.modifyEventPointForDrilldown(e);
5943
- drillDownListFunc(e);
5944
- };
5974
+ if (opt.isUpdatingPointStylesOnClick) {
5975
+ opt.drillDownListFunc = (e) => {
5976
+ seriesPointStylesHelper.setSeriesPointStylesOnClick(e);
5977
+ highchartsRenderer.modifyEventPointForDrilldown(e);
5978
+ drillDownListFunc(e);
5979
+ };
5980
+ } else {
5981
+ opt.drillDownListFunc = (e) => {
5982
+ highchartsRenderer.modifyEventPointForDrilldown(e);
5983
+ drillDownListFunc(e);
5984
+ };
5985
+ }
5945
5986
  } else {
5946
5987
  opt.drillDownListFunc = null;
5947
5988
  }
5948
- return fnToReturn(pivotData, opt, drilldownFunc, newChartType); //todo pass drilldownFunc
5989
+ return fnToReturn(pivotData, opt, drilldownFunc, newChartType);
5949
5990
  };
5950
-
5951
- return fnunctionToReturn;
5952
5991
  };
5953
5992
 
5954
5993
  highchartsRenderer.getAggregatorFunctionById = function (aggrigatorId) {
@@ -0,0 +1,43 @@
1
+ function getSeriesPointStyles(isSelected) {
2
+ return {
3
+ opacity: isSelected ? 1 : 0.1,
4
+ marker: {
5
+ enabled: true,
6
+ radius: isSelected ? 8 : 3,
7
+ },
8
+ dataLabels: {
9
+ style: {
10
+ fontWeight: isSelected ? "bold" : "normal",
11
+ },
12
+ },
13
+ };
14
+ }
15
+
16
+ function setSeriesPointStylesOnClick(e) {
17
+ const selectedPoint = e.point;
18
+ e.point.series.chart.series.forEach((series) =>
19
+ series.points.forEach((point) => {
20
+ point.update(getSeriesPointStyles(point === selectedPoint), false);
21
+ })
22
+ );
23
+ e.point.series.chart.redraw();
24
+ }
25
+
26
+ function setInitialPointStyles(opts, series) {
27
+ series.forEach((series) => {
28
+ if (Array.isArray(series.data)) {
29
+ series.data.forEach((item) => {
30
+ const isSelected =
31
+ item && opts.selectedPoint &&
32
+ item.initialName === opts.selectedPoint.initialName &&
33
+ item.y === opts.selectedPoint.y;
34
+ item = Object.assign(item, getSeriesPointStyles(isSelected));
35
+ });
36
+ }
37
+ });
38
+ }
39
+
40
+ module.exports = {
41
+ setSeriesPointStylesOnClick,
42
+ setInitialPointStyles,
43
+ };
@@ -1,6 +1,7 @@
1
1
  import drRendererHelpers from '../src/dr-renderer-helpers';
2
2
 
3
3
  describe('dr-renderer-helpers', () => {
4
+
4
5
  describe('backendSortingKeysAreNotEmpty', () => {
5
6
  it('should return true if keys are not empty', () => {
6
7
  const keys = {
@@ -0,0 +1,114 @@
1
+ import seriesPointStylesHelper from '../src/seriesPointStyles-helper';
2
+
3
+ describe('setSeriesPointStylesOnClick', () => {
4
+ it('should update point styles on click and update other points to non-selected styles on click', () => {
5
+ const selectedPoint = {
6
+ update: jest.fn(),
7
+ series: {
8
+ chart: {
9
+ series: [{ points: [] }],
10
+ redraw: jest.fn()
11
+ }
12
+ }
13
+ };
14
+
15
+ const otherPoint = {
16
+ update: jest.fn(),
17
+ series: selectedPoint.series
18
+ };
19
+
20
+ selectedPoint.series.chart.series[0].points.push(selectedPoint, otherPoint);
21
+
22
+ const mockEvent = { point: selectedPoint };
23
+
24
+ seriesPointStylesHelper.setSeriesPointStylesOnClick(mockEvent);
25
+
26
+ expect(selectedPoint.update).toHaveBeenCalledWith(
27
+ {
28
+ opacity: 1,
29
+ marker: {
30
+ enabled: true,
31
+ radius: 8
32
+ },
33
+ dataLabels: {
34
+ style: {
35
+ fontWeight: 'bold'
36
+ }
37
+ }
38
+ },
39
+ false
40
+ );
41
+ expect(otherPoint.update).toHaveBeenCalledWith(
42
+ {
43
+ opacity: 0.1,
44
+ marker: {
45
+ enabled: true,
46
+ radius: 3
47
+ },
48
+ dataLabels: {
49
+ style: {
50
+ fontWeight: 'normal'
51
+ }
52
+ }
53
+ },
54
+ false
55
+ );
56
+ expect(selectedPoint.series.chart.redraw).toHaveBeenCalled();
57
+ });
58
+ });
59
+
60
+ describe('setInitialPointStyles', () => {
61
+ it('should set initial point styles based on selection', () => {
62
+ const opts = { selectedPoint: { initialName: 'point1', y: 10 } };
63
+ const mockPoint = { initialName: 'point1', y: 10 };
64
+ const mockSeries = { data: [mockPoint] };
65
+ const series = [mockSeries];
66
+
67
+ seriesPointStylesHelper.setInitialPointStyles(opts, series);
68
+
69
+ expect(mockPoint).toEqual(
70
+ Object.assign(
71
+ mockPoint,
72
+ {
73
+ opacity: 1,
74
+ marker: {
75
+ enabled: true,
76
+ radius: 8
77
+ },
78
+ dataLabels: {
79
+ style: {
80
+ fontWeight: 'bold'
81
+ }
82
+ }
83
+ }
84
+ )
85
+ );
86
+ });
87
+
88
+ it('should not set styles if point is not selected', () => {
89
+ const opts = { selectedPoint: { initialName: 'point1', y: 10 } };
90
+ const mockPoint = { initialName: 'point2', y: 20 };
91
+ const mockSeries = { data: [mockPoint] };
92
+ const series = [mockSeries];
93
+
94
+ seriesPointStylesHelper.setInitialPointStyles(opts, series);
95
+
96
+ expect(mockPoint).toEqual(
97
+ Object.assign(
98
+ mockPoint,
99
+ {
100
+ opacity: 0.1,
101
+ marker: {
102
+ enabled: true,
103
+ radius: 3
104
+ },
105
+ dataLabels: {
106
+ style: {
107
+ fontWeight: 'normal'
108
+ }
109
+ }
110
+ }
111
+ )
112
+ );
113
+ });
114
+ });