@datarailsshared/dr_renderer 1.2.275 → 1.2.277

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.275",
3
+ "version": "1.2.277",
4
4
  "description": "DataRails charts and tables renderer",
5
5
  "keywords": [
6
6
  "datarails",
@@ -143,6 +143,11 @@ let initDRPivotTable = function($, window, document) {
143
143
  return key;
144
144
  };
145
145
 
146
+ DRPivotData.prototype.getInsight = function(colKey, rowKey) {
147
+ const insightInfo = _.find(this.insights, insight => insight.colKey === colKey && insight.rowKey === rowKey);
148
+ return _.get(insightInfo, 'insight', null);
149
+ }
150
+
146
151
  DRPivotData.prototype.processRecord = function(record, useTotalsCalculation) {
147
152
  if (useTotalsCalculation) {
148
153
  if (!this.notFirst) {
@@ -207,6 +212,16 @@ let initDRPivotTable = function($, window, document) {
207
212
  this.tree[flatRowKey][flatColKey] = this.aggregator(this, rowKey, colKey);
208
213
  this.tree[flatRowKey][flatColKey].push(record);
209
214
  }
215
+
216
+ if (flatRowKey || flatColKey) {
217
+ this.insights.push({
218
+ colKey: flatColKey,
219
+ rowKey: flatRowKey,
220
+ insight: record.insight || null,
221
+ });
222
+ delete record.insight;
223
+ }
224
+
210
225
  return;
211
226
  }
212
227
 
@@ -666,6 +666,30 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
666
666
  return func;
667
667
  };
668
668
 
669
+ highchartsRenderer.customFormatterTooltipInsights = function(pivotData, opts) {
670
+ return {
671
+ useHTML: true,
672
+ outside: true,
673
+ backgroundColor: 'transparent',
674
+ borderWidth: 0,
675
+ borderRadius: 0,
676
+ shadow: false,
677
+ shape: 'square',
678
+ padding: 0,
679
+ stickOnContact: true,
680
+ formatter: function () {
681
+ const rowKey = pivotData.rowAttrs.length ? _.get(this.point, 'series.name') || "" : "";
682
+ const colKey = _.get(this.point, 'name') || this.x.name[0] || "";
683
+ const insight = pivotData.getInsight(colKey, rowKey) || {};
684
+ setTimeout(() => {
685
+ var aggr = highchartsRenderer.defaultFormatterToTooltip(pivotData, opts);
686
+ const formatted_value_to_return = aggr.bind(this)();
687
+ opts.insightsTooltipFunc({...this, formatted_value_to_return, ...insight});
688
+ });
689
+ }
690
+ }
691
+ }
692
+
669
693
  highchartsRenderer.defaultFormatterToTooltip = function (pivotData, opts, is_drill_down_pie) {
670
694
  var variant_name = null;
671
695
  var variant_name_default_name = null;
@@ -673,7 +697,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
673
697
  variant_name = opts.chartOptions.delta_column.name.replace('_', '');
674
698
  variant_name_default_name = opts.chartOptions.delta_column.name;
675
699
  }
676
-
677
700
  const tooltipOptions = lodash.get(opts, 'chartOptions.tooltips');
678
701
 
679
702
  let percentageLabels = {
@@ -2444,6 +2467,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2444
2467
  highchartsRenderer.ptRenderBasicLine = function (pivotData, opts) {
2445
2468
  var chartOptions = {};
2446
2469
  var rowAttrs = pivotData.rowAttrs;
2470
+ var colAttrs = pivotData.colAttrs;
2447
2471
 
2448
2472
  var additionOptions = opts.chartOptions ? opts.chartOptions : highchartsRenderer.getDefaultValueForChart('line-chart');
2449
2473
 
@@ -2504,13 +2528,17 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2504
2528
  };
2505
2529
  }
2506
2530
 
2507
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
2508
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
2531
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
2532
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
2509
2533
 
2510
- chartOptions.tooltip = {
2511
- formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
2512
- valueDecimals: 2,
2513
- };
2534
+ if(colAttrs.length > 1 || !opts.insightsTooltipFunc) {
2535
+ chartOptions.tooltip = {
2536
+ formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
2537
+ valueDecimals: 2,
2538
+ };
2539
+ } else {
2540
+ chartOptions.tooltip = highchartsRenderer.customFormatterTooltipInsights(pivotData, opts);
2541
+ }
2514
2542
 
2515
2543
  chartOptions.xAxis = {
2516
2544
  categories: pivotData.getColKeys(),
@@ -2586,8 +2614,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2586
2614
  };
2587
2615
  }
2588
2616
 
2589
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
2590
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
2617
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
2618
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
2591
2619
 
2592
2620
  chartOptions.tooltip = {
2593
2621
  formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
@@ -2681,8 +2709,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2681
2709
  };
2682
2710
  }
2683
2711
 
2684
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
2685
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
2712
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
2713
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
2686
2714
 
2687
2715
  chartOptions.tooltip = {
2688
2716
  formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
@@ -2918,10 +2946,13 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2918
2946
  highchartsRenderer.setYAxisMinMax(chartOptions.yAxis, additionOptions.axisY);
2919
2947
  }
2920
2948
 
2921
- chartOptions.tooltip = {
2922
- formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
2923
- valueDecimals: 2,
2924
- };
2949
+
2950
+ chartOptions.tooltip = opts.insightsTooltipFunc
2951
+ ? highchartsRenderer.customFormatterTooltipInsights(pivotData, opts)
2952
+ : {
2953
+ formatter: highchartsRenderer.defaultFormatterToTooltip(pivotData, opts),
2954
+ valueDecimals: 2,
2955
+ };
2925
2956
 
2926
2957
  highchartsRenderer.handleGridLines(additionOptions, chartOptions);
2927
2958
 
@@ -2960,8 +2991,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2960
2991
  }
2961
2992
  };
2962
2993
  }
2963
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
2964
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
2994
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
2995
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
2965
2996
 
2966
2997
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
2967
2998
 
@@ -3096,8 +3127,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3096
3127
  };
3097
3128
  }
3098
3129
 
3099
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
3100
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
3130
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
3131
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
3101
3132
 
3102
3133
  chartOptions.xAxis = {
3103
3134
  type: 'category',
@@ -3281,8 +3312,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3281
3312
  };
3282
3313
  }
3283
3314
 
3284
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
3285
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
3315
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
3316
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
3286
3317
 
3287
3318
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, rowAttrs.length, false);
3288
3319
 
@@ -3362,8 +3393,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3362
3393
  };
3363
3394
  }
3364
3395
 
3365
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
3366
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
3396
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
3397
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
3367
3398
 
3368
3399
  chartOptions.xAxis = {
3369
3400
  categories: pivotData.getColKeys(),
@@ -3474,8 +3505,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3474
3505
  };
3475
3506
  }
3476
3507
 
3477
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
3478
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
3508
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
3509
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
3479
3510
 
3480
3511
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, 3, false);
3481
3512
  chartOptions.legend.useHTML = true;
@@ -3593,8 +3624,8 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
3593
3624
  };
3594
3625
  }
3595
3626
 
3596
- chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
3597
- chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
3627
+ chartOptions.plotOptions.series.point.events.mouseOver = opts.trackUserInsightsTooltipFunc;
3628
+ chartOptions.plotOptions.series.point.events.mouseOut = opts.trackUserInsightsTooltipFunc;
3598
3629
 
3599
3630
  if (waterfallOptions.colors) {
3600
3631
  chartOptions.legend = highchartsRenderer.getOptionsForLegends(additionOptions, 3, false);
@@ -5102,7 +5133,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5102
5133
  options.chartOptions = lodash.merge(defaultOptions, options.chartOptions);
5103
5134
  };
5104
5135
 
5105
- highchartsRenderer.addPivotOptions = function (selectedTemplateWOData, widgetOptions, drilldownFunction, drillDownListFunction, insightsTooltipFunction) {
5136
+ highchartsRenderer.addPivotOptions = function (selectedTemplateWOData, widgetOptions, drilldownFunction, drillDownListFunction, insightsTooltipFunction, trackUserInsightsTooltipFunction) {
5106
5137
  // Check if not rendered data, than it will render
5107
5138
 
5108
5139
  var fields = highchartsRenderer.objectCopyJsonMethod(selectedTemplateWOData.fields);
@@ -5113,6 +5144,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5113
5144
  var drilldownFunc = drilldownFunction;
5114
5145
  var drillDownListFunc = drillDownListFunction;
5115
5146
  var insightsTooltipFunc = insightsTooltipFunction;
5147
+ var trackUserInsightsTooltipFunc = trackUserInsightsTooltipFunction;
5116
5148
 
5117
5149
  // fill value fields
5118
5150
  lodash.forEach(widgetOptions.vals, function (valObj) {
@@ -5167,7 +5199,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5167
5199
  widgetOptions.pivot.valuesArray = valuesFields;
5168
5200
  widgetOptions.pivot.chartType = widgetOptions.chart_type;
5169
5201
  widgetOptions.pivot.chartOptions = widgetOptions.options;
5170
- widgetOptions.pivot.chartRender = highchartsRenderer.getChartRendererFunction(widgetOptions.pivot.chartType, drilldownFunc, drillDownListFunc, insightsTooltipFunc);
5202
+ widgetOptions.pivot.chartRender = highchartsRenderer.getChartRendererFunction(widgetOptions.pivot.chartType, drilldownFunc, drillDownListFunc, insightsTooltipFunc, trackUserInsightsTooltipFunc);
5171
5203
 
5172
5204
  // TODO: remove this logic after BE sort is implemented
5173
5205
  // it is required to do sort by totals for comparative analysis - we need to change deltas if columns swaped vice versa
@@ -5697,7 +5729,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5697
5729
  return toReturn;
5698
5730
  };
5699
5731
 
5700
- highchartsRenderer.getChartRendererFunction = function (newChartType, drilldownFunc, drillDownListFunc, insightsTooltipFunc) {
5732
+ highchartsRenderer.getChartRendererFunction = function (newChartType, drilldownFunc, drillDownListFunc, insightsTooltipFunc, trackUserInsightsTooltipFunc) {
5701
5733
  var fnToReturn = null;
5702
5734
 
5703
5735
  if (newChartType == highchartsRenderer.richTextSubType.type) {
@@ -5726,6 +5758,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
5726
5758
  }
5727
5759
  opt.drillDownListFunc = drillDownListFunc;
5728
5760
  opt.insightsTooltipFunc = insightsTooltipFunc;
5761
+ opt.trackUserInsightsTooltipFunc = trackUserInsightsTooltipFunc;
5729
5762
  } else {
5730
5763
  opt.drillDownListFunc = null;
5731
5764
  }
@@ -8481,7 +8514,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8481
8514
  return $.pivotUtilities.getPivotTableFormula(rowData, opts, func, axisFields, legendFields, aggregationDefaults, utils);
8482
8515
  };
8483
8516
 
8484
-
8485
8517
  // widget Renderer
8486
8518
  highchartsRenderer.updateSelectedOverrideValues = function (widget, override_values, res) {
8487
8519
  if (override_values && override_values.length > 0) {
package/src/pivottable.js CHANGED
@@ -684,6 +684,7 @@ let initPivotTable = function($, window, document) {
684
684
  return true;
685
685
  });
686
686
  this.tree = {};
687
+ this.insights = [];
687
688
  this.rowKeys = [];
688
689
  this.colKeys = [];
689
690
  this.rowTotals = {};