@datarailsshared/dr_renderer 1.2.274 → 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 +1 -1
- package/src/dr_pivottable.js +15 -0
- package/src/highcharts_renderer.js +41 -198
- package/src/pivottable.js +1 -0
package/package.json
CHANGED
package/src/dr_pivottable.js
CHANGED
|
@@ -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
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
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
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
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
|
|
|
@@ -4251,155 +4282,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
4251
4282
|
};
|
|
4252
4283
|
};
|
|
4253
4284
|
|
|
4254
|
-
highchartsRenderer.createTotalColFiltersArr = function (colKeys, colTotals, totalFilters, pivotData) {
|
|
4255
|
-
var colIndexesToFilter = []
|
|
4256
|
-
if (!totalFilters || !totalFilters.type)
|
|
4257
|
-
return colIndexesToFilter
|
|
4258
|
-
|
|
4259
|
-
var colTotalsWithoutSubTotals = {};
|
|
4260
|
-
var i, flatKey;
|
|
4261
|
-
for (i in colKeys) {
|
|
4262
|
-
flatKey = colKeys[i].join($.pivotUtilities.delim);
|
|
4263
|
-
if (colTotals[flatKey])
|
|
4264
|
-
colTotalsWithoutSubTotals[flatKey] = colTotals[flatKey];
|
|
4265
|
-
}
|
|
4266
|
-
|
|
4267
|
-
var filterFunc = highchartsRenderer.getTotalsFilter(totalFilters.type, totalFilters.value, totalFilters.is_absolute, colTotalsWithoutSubTotals)
|
|
4268
|
-
for (var j in colKeys) {
|
|
4269
|
-
var totalVal = pivotData.getAggregator([], colKeys[j]).value();
|
|
4270
|
-
if (filterFunc(totalVal)) {
|
|
4271
|
-
colIndexesToFilter.push(j)
|
|
4272
|
-
}
|
|
4273
|
-
}
|
|
4274
|
-
|
|
4275
|
-
let keyAttListToFilter = [];
|
|
4276
|
-
for (var attr in pivotData.colAttrs) {
|
|
4277
|
-
for (var key in pivotData.colKeys) {
|
|
4278
|
-
if ($.inArray(key, colIndexesToFilter) >= 0) {
|
|
4279
|
-
keyAttListToFilter.push(pivotData.colKeys[key])
|
|
4280
|
-
}
|
|
4281
|
-
}
|
|
4282
|
-
}
|
|
4283
|
-
return keyAttListToFilter;
|
|
4284
|
-
};
|
|
4285
|
-
|
|
4286
|
-
highchartsRenderer.createTotalRowFiltersArr = function (rowKeys, rowTotals, totalFilters, pivotData) {
|
|
4287
|
-
var rowIndexesToFilter = [];
|
|
4288
|
-
if (!totalFilters || !totalFilters.type)
|
|
4289
|
-
return rowIndexesToFilter;
|
|
4290
|
-
|
|
4291
|
-
var rowTotalsWithoutSubTotals = {};
|
|
4292
|
-
var i, flatKey;
|
|
4293
|
-
for (i in rowKeys) {
|
|
4294
|
-
flatKey = rowKeys[i].join($.pivotUtilities.delim);
|
|
4295
|
-
if (rowTotals[flatKey])
|
|
4296
|
-
rowTotalsWithoutSubTotals[flatKey] = rowTotals[flatKey];
|
|
4297
|
-
}
|
|
4298
|
-
|
|
4299
|
-
var filterFunc = highchartsRenderer.getTotalsFilter(totalFilters.type, totalFilters.value, totalFilters.is_absolute, rowTotalsWithoutSubTotals)
|
|
4300
|
-
for (var j in rowKeys) {
|
|
4301
|
-
var totalVal = pivotData.getAggregator(rowKeys[j], []).value();
|
|
4302
|
-
if (filterFunc(totalVal)) {
|
|
4303
|
-
rowIndexesToFilter.push(j)
|
|
4304
|
-
}
|
|
4305
|
-
}
|
|
4306
|
-
|
|
4307
|
-
let keyAttListToFilter = [];
|
|
4308
|
-
for (var attr in pivotData.rowAttrs) {
|
|
4309
|
-
for (var key in pivotData.rowKeys) {
|
|
4310
|
-
if ($.inArray(key, rowIndexesToFilter) >= 0) {
|
|
4311
|
-
keyAttListToFilter.push(pivotData.rowKeys[key])
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
}
|
|
4315
|
-
return keyAttListToFilter;
|
|
4316
|
-
};
|
|
4317
|
-
|
|
4318
|
-
highchartsRenderer.getTotalsFilter = function (type, vals, is_absolute, totals) {
|
|
4319
|
-
var filter = (a) => false;
|
|
4320
|
-
switch (type) {
|
|
4321
|
-
case "filter_above":
|
|
4322
|
-
if (is_absolute)
|
|
4323
|
-
filter = (a) => Math.abs(a) <= vals[0];
|
|
4324
|
-
else
|
|
4325
|
-
filter = (a) => a <= vals[0];
|
|
4326
|
-
break;
|
|
4327
|
-
case "filter_below":
|
|
4328
|
-
if (is_absolute)
|
|
4329
|
-
filter = (a) => Math.abs(a) >= vals[0];
|
|
4330
|
-
else
|
|
4331
|
-
filter = (a) => a >= vals[0];
|
|
4332
|
-
break;
|
|
4333
|
-
case "filter_between":
|
|
4334
|
-
if (is_absolute)
|
|
4335
|
-
filter = (a) => Math.abs(a) <= vals[0] || Math.abs(a) >= vals[1];
|
|
4336
|
-
else
|
|
4337
|
-
filter = (a) => a <= vals[0] || a >= vals[1];
|
|
4338
|
-
break;
|
|
4339
|
-
case "filter_out_of_range":
|
|
4340
|
-
if (is_absolute)
|
|
4341
|
-
filter = (a) => Math.abs(a) >= vals[0] && Math.abs(a) <= vals[1];
|
|
4342
|
-
else
|
|
4343
|
-
filter = (a) => a >= vals[0] && a <= vals[1];
|
|
4344
|
-
break;
|
|
4345
|
-
case "filter_top_x":
|
|
4346
|
-
var topx;
|
|
4347
|
-
if (is_absolute)
|
|
4348
|
-
topx = lodash.map(totals, (x) => Math.abs(x.value())).filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => b - a).slice(0, vals[0]).pop();
|
|
4349
|
-
else
|
|
4350
|
-
topx = lodash.map(totals, (x) => x.value()).filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => b - a).slice(0, vals[0]).pop();
|
|
4351
|
-
|
|
4352
|
-
if (topx != undefined) {
|
|
4353
|
-
if (is_absolute)
|
|
4354
|
-
filter = (a) => Math.abs(a) < topx;
|
|
4355
|
-
else
|
|
4356
|
-
filter = (a) => a < topx;
|
|
4357
|
-
}
|
|
4358
|
-
break;
|
|
4359
|
-
case "filter_bottom_x":
|
|
4360
|
-
var bottomx;
|
|
4361
|
-
if (is_absolute)
|
|
4362
|
-
bottomx = lodash.map(totals, (x) => Math.abs(x.value())).filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b).slice(0, vals[0]).pop();
|
|
4363
|
-
else
|
|
4364
|
-
bottomx = lodash.map(totals, (x) => x.value()).filter((v, i, a) => a.indexOf(v) === i).sort((a, b) => a - b).slice(0, vals[0]).pop();
|
|
4365
|
-
|
|
4366
|
-
if (bottomx != undefined) {
|
|
4367
|
-
if (is_absolute)
|
|
4368
|
-
filter = (a) => Math.abs(a) > bottomx;
|
|
4369
|
-
else
|
|
4370
|
-
filter = (a) => a > bottomx;
|
|
4371
|
-
}
|
|
4372
|
-
break;
|
|
4373
|
-
case "filter_smallest":
|
|
4374
|
-
const smallest_sumOfFields = lodash.reduce(totals, (acc, curr) => acc += curr.sum, 0);
|
|
4375
|
-
const smallest = Math.floor((smallest_sumOfFields * vals[0])/100);
|
|
4376
|
-
|
|
4377
|
-
if (is_absolute)
|
|
4378
|
-
filter = (a) => Math.abs(a) > smallest;
|
|
4379
|
-
else
|
|
4380
|
-
filter = (a) => a > smallest;
|
|
4381
|
-
break;
|
|
4382
|
-
case "filter_largest":
|
|
4383
|
-
const largest_sumOfFields = lodash.reduce(totals, (acc, curr) => acc += curr.sum, 0);
|
|
4384
|
-
const largest = Math.floor((largest_sumOfFields * vals[0])/100);
|
|
4385
|
-
|
|
4386
|
-
if (is_absolute)
|
|
4387
|
-
filter = (a) => Math.abs(a) < largest;
|
|
4388
|
-
else
|
|
4389
|
-
filter = (a) => a < largest;
|
|
4390
|
-
break;
|
|
4391
|
-
case "filter_out_zero":
|
|
4392
|
-
if (is_absolute)
|
|
4393
|
-
filter = (a) => Math.abs(a) == 0;
|
|
4394
|
-
else
|
|
4395
|
-
filter = (a) => a == 0;
|
|
4396
|
-
break;
|
|
4397
|
-
default:
|
|
4398
|
-
|
|
4399
|
-
}
|
|
4400
|
-
return filter;
|
|
4401
|
-
};
|
|
4402
|
-
|
|
4403
4285
|
highchartsRenderer.getAxis = function (axis, opts, farceIsTable = false) {
|
|
4404
4286
|
let is_transpose = lodash.get(opts, 'rendererOptions.chartOptions.table_options.transpose_table', false);
|
|
4405
4287
|
let is_table = opts.isTable;
|
|
@@ -4413,43 +4295,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
4413
4295
|
return axis;
|
|
4414
4296
|
};
|
|
4415
4297
|
|
|
4416
|
-
highchartsRenderer.generateFilteredResult = function (totalFilters, optsFiltered, rowData, opts, pivotData) {
|
|
4417
|
-
let keyAttListToFilter;
|
|
4418
|
-
let axis = highchartsRenderer.getAxis(totalFilters.filter_options.axis, opts);
|
|
4419
|
-
|
|
4420
|
-
if (axis == 'col_total') {
|
|
4421
|
-
keyAttListToFilter = highchartsRenderer.createTotalColFiltersArr(pivotData.colKeys, pivotData.colTotals, totalFilters.filter_options, pivotData);
|
|
4422
|
-
return highchartsRenderer.generateFilteredResultForRowAndCol(keyAttListToFilter, optsFiltered, pivotData.colAttrs, rowData, opts, pivotData);
|
|
4423
|
-
} else if (axis == 'row_total') {
|
|
4424
|
-
keyAttListToFilter = highchartsRenderer.createTotalRowFiltersArr(pivotData.rowKeys, pivotData.rowTotals, totalFilters.filter_options, pivotData);
|
|
4425
|
-
return highchartsRenderer.generateFilteredResultForRowAndCol(keyAttListToFilter, optsFiltered, pivotData.rowAttrs, rowData, opts, pivotData);
|
|
4426
|
-
} else {
|
|
4427
|
-
return opts.renderer(pivotData, opts.rendererOptions);
|
|
4428
|
-
}
|
|
4429
|
-
};
|
|
4430
|
-
|
|
4431
|
-
highchartsRenderer.generateFilteredResultForRowAndCol = function (keyAttListToFilter, optsFiltered, attrs, rowData, opts, pivotData) {
|
|
4432
|
-
let pivotDataFiltered = pivotData;
|
|
4433
|
-
if (!lodash.isEmpty(keyAttListToFilter)) {
|
|
4434
|
-
var myfilter = function (rec) {
|
|
4435
|
-
for (var i in keyAttListToFilter) {
|
|
4436
|
-
var allsame = true;
|
|
4437
|
-
var find_one = lodash.find(attrs, function (val, j) {
|
|
4438
|
-
return ((rec[val] != keyAttListToFilter[i][j]) && !(!rec[val] && keyAttListToFilter[i][j] == "null"))
|
|
4439
|
-
});
|
|
4440
|
-
if (find_one == undefined) {
|
|
4441
|
-
return false;
|
|
4442
|
-
}
|
|
4443
|
-
}
|
|
4444
|
-
return true;
|
|
4445
|
-
}
|
|
4446
|
-
optsFiltered.filter = myfilter;
|
|
4447
|
-
|
|
4448
|
-
pivotDataFiltered = $.pivotUtilities.getPivotDataModel(rowData, optsFiltered);
|
|
4449
|
-
}
|
|
4450
|
-
return opts.renderer(pivotDataFiltered, opts.rendererOptions);
|
|
4451
|
-
};
|
|
4452
|
-
|
|
4453
4298
|
highchartsRenderer.sanitizeOptions = function (opts) {
|
|
4454
4299
|
if (opts && opts.rendererOptions) {
|
|
4455
4300
|
if (opts.rendererOptions.chart_title) {
|
|
@@ -7510,8 +7355,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
7510
7355
|
},
|
|
7511
7356
|
};
|
|
7512
7357
|
|
|
7513
|
-
highchartsRenderer.chartsData =
|
|
7514
|
-
[
|
|
7358
|
+
highchartsRenderer.chartsData = [
|
|
7515
7359
|
{
|
|
7516
7360
|
type: 'line',
|
|
7517
7361
|
name: 'Line',
|
|
@@ -8668,7 +8512,6 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
|
8668
8512
|
return $.pivotUtilities.getPivotTableFormula(rowData, opts, func, axisFields, legendFields, aggregationDefaults, utils);
|
|
8669
8513
|
};
|
|
8670
8514
|
|
|
8671
|
-
|
|
8672
8515
|
// widget Renderer
|
|
8673
8516
|
highchartsRenderer.updateSelectedOverrideValues = function (widget, override_values, res) {
|
|
8674
8517
|
if (override_values && override_values.length > 0) {
|