@datarailsshared/dr_renderer 1.2.275 → 1.2.276

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.276",
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
 
@@ -2507,10 +2531,14 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
2507
2531
  chartOptions.plotOptions.series.point.events.mouseOver = opts.insightsTooltipFunc;
2508
2532
  chartOptions.plotOptions.series.point.events.mouseOut = opts.insightsTooltipFunc;
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(),
@@ -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
 
@@ -8481,7 +8512,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
8481
8512
  return $.pivotUtilities.getPivotTableFormula(rowData, opts, func, axisFields, legendFields, aggregationDefaults, utils);
8482
8513
  };
8483
8514
 
8484
-
8485
8515
  // widget Renderer
8486
8516
  highchartsRenderer.updateSelectedOverrideValues = function (widget, override_values, res) {
8487
8517
  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 = {};