@datarailsshared/dr_renderer 1.5.116 → 1.5.120
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 +141 -8
- package/src/index.js +0 -2
- package/src/options/builders.js +36 -25
- package/tests/__snapshots__/suboptions.test.js.snap +290 -279
- package/tests/highcharts_renderer.test.js +0 -2
- package/tests/options-builder.test.js +2 -2
- package/tests/ptCreateDrillDownSeriesToDrilldownChart.test.js +0 -2
- package/tests/suboptions.test.js +1 -1
- package/src/pivottable.js +0 -715
package/package.json
CHANGED
package/src/dr_pivottable.js
CHANGED
|
@@ -3,20 +3,136 @@ const { DELIMER } = require('./dr-renderer-helpers');
|
|
|
3
3
|
const { TooMuchDataError } = require('./errors');
|
|
4
4
|
|
|
5
5
|
let initDRPivotTable = function($, window, document) {
|
|
6
|
-
var
|
|
7
|
-
|
|
6
|
+
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
7
|
+
hasProp = {}.hasOwnProperty;
|
|
8
8
|
|
|
9
9
|
var DRPivotData, processKey, SubtotalRenderer, getFormattedNumber, NovixRenderer;
|
|
10
10
|
const newTableColors = ['rgb(127, 196, 255)', 'rgb(200, 243,243)', 'rgb(247, 161, 173)', 'rgb(255, 237, 178)', 'rgb(221, 239, 255)',
|
|
11
11
|
'rgb(171, 216, 255)', 'rgb(174, 231, 220)', 'rgb(227, 255, 236)', 'rgb(162, 215, 227)', 'rgb(223, 239, 236)'];
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/*
|
|
14
|
+
Utilities (from pivottable@2.23.0)
|
|
15
|
+
*/
|
|
16
|
+
var addSeparators, aggregatorTemplates, locales, numberFormat, usFmtInt;
|
|
17
|
+
addSeparators = function(nStr, thousandsSep, decimalSep) {
|
|
18
|
+
var rgx, x, x1, x2;
|
|
19
|
+
nStr += '';
|
|
20
|
+
x = nStr.split('.');
|
|
21
|
+
x1 = x[0];
|
|
22
|
+
x2 = x.length > 1 ? decimalSep + x[1] : '';
|
|
23
|
+
rgx = /(\d+)(\d{3})/;
|
|
24
|
+
while (rgx.test(x1)) {
|
|
25
|
+
x1 = x1.replace(rgx, '$1' + thousandsSep + '$2');
|
|
26
|
+
}
|
|
27
|
+
return x1 + x2;
|
|
28
|
+
};
|
|
14
29
|
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
numberFormat = function(opts) {
|
|
31
|
+
var defaults;
|
|
32
|
+
defaults = {
|
|
33
|
+
digitsAfterDecimal: 2,
|
|
34
|
+
scaler: 1,
|
|
35
|
+
thousandsSep: ",",
|
|
36
|
+
decimalSep: ".",
|
|
37
|
+
prefix: "",
|
|
38
|
+
suffix: ""
|
|
39
|
+
};
|
|
40
|
+
opts = $.extend({}, defaults, opts);
|
|
41
|
+
return function(x) {
|
|
42
|
+
var result;
|
|
43
|
+
if (isNaN(x) || !isFinite(x)) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
result = addSeparators((opts.scaler * x).toFixed(opts.digitsAfterDecimal), opts.thousandsSep, opts.decimalSep);
|
|
47
|
+
return "" + opts.prefix + result + opts.suffix;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
usFmtInt = numberFormat({
|
|
51
|
+
digitsAfterDecimal: 0
|
|
52
|
+
});
|
|
53
|
+
aggregatorTemplates = {
|
|
54
|
+
count: function(formatter) {
|
|
55
|
+
if (formatter == null) {
|
|
56
|
+
formatter = usFmtInt;
|
|
57
|
+
}
|
|
58
|
+
return function() {
|
|
59
|
+
return function(data, rowKey, colKey) {
|
|
60
|
+
return {
|
|
61
|
+
count: 0,
|
|
62
|
+
push: function() {
|
|
63
|
+
return this.count++;
|
|
64
|
+
},
|
|
65
|
+
value: function() {
|
|
66
|
+
return this.count;
|
|
67
|
+
},
|
|
68
|
+
format: formatter
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
locales = {
|
|
75
|
+
en: {
|
|
76
|
+
localeStrings: {
|
|
77
|
+
selectAll: "Select All",
|
|
78
|
+
selectNone: "Select None",
|
|
79
|
+
tooMany: "(too many to list)",
|
|
80
|
+
filterResults: "Filter values",
|
|
81
|
+
apply: "Apply",
|
|
82
|
+
cancel: "Cancel",
|
|
83
|
+
totals: "Totals",
|
|
84
|
+
vs: "vs",
|
|
85
|
+
by: "by"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
DRPivotData = (function() {
|
|
17
91
|
|
|
18
92
|
function DRPivotData(input, opts) {
|
|
19
|
-
|
|
93
|
+
if (opts == null) {
|
|
94
|
+
opts = {};
|
|
95
|
+
}
|
|
96
|
+
this.getAggregator = bind(this.getAggregator, this);
|
|
97
|
+
this.getRowKeys = bind(this.getRowKeys, this);
|
|
98
|
+
this.getColKeys = bind(this.getColKeys, this);
|
|
99
|
+
this.getRowKeysByCols = bind(this.getRowKeysByCols, this);
|
|
100
|
+
this.input = input;
|
|
101
|
+
this.aggregator = opts.aggregator != null ? opts.aggregator : aggregatorTemplates.count()();
|
|
102
|
+
this.aggregatorName = opts.aggregatorName != null ? opts.aggregatorName : "Count";
|
|
103
|
+
this.colAttrs = opts.cols != null ? opts.cols : [];
|
|
104
|
+
this.rowAttrs = opts.rows != null ? opts.rows : [];
|
|
105
|
+
this.derivedAttributes = opts.derivedAttributes != null ? opts.derivedAttributes : {};
|
|
106
|
+
this.filter = opts.filter != null ? opts.filter : (function() {
|
|
107
|
+
return true;
|
|
108
|
+
});
|
|
109
|
+
this.isSmartQueriesEnabled = _.some(input, item => item.Scenario === DR_SCENARIO.SQ_Actuals);
|
|
110
|
+
|
|
111
|
+
this.tree = {};
|
|
112
|
+
|
|
113
|
+
// some chart types don't have row/col keys (for example, KPI_WIDGET)
|
|
114
|
+
this.rowKeys = opts.keysObject ? opts.keysObject.row_keys : [];
|
|
115
|
+
this.colKeys = opts.keysObject ? opts.keysObject.col_keys : [];
|
|
116
|
+
this.rowKeysByCols = opts.keysObject ? opts.keysObject.row_keys_by_cols : [];
|
|
117
|
+
|
|
118
|
+
this.rowTotals = {};
|
|
119
|
+
this.colTotals = {};
|
|
120
|
+
this.allTotal = this.aggregator(this, [], []);
|
|
121
|
+
this.dateValuesDictionary = opts.dateValuesDictionary;
|
|
122
|
+
this.colFormats = opts.colFormats || [];
|
|
123
|
+
this.rowFormats = opts.rowFormats || [];
|
|
124
|
+
this.isFormattingAxisLabels = opts.rendererOptions && opts.rendererOptions.isFormattingAxisLabels;
|
|
125
|
+
this.getFormattedColKeys = (keys) => opts.getFormattedColKeys(this, keys);
|
|
126
|
+
this.getFormattedRowKeys = (keys) => opts.getFormattedRowKeys(this, keys);
|
|
127
|
+
this.isDrillDownDisabled = opts.isDrillDownDisabled;
|
|
128
|
+
|
|
129
|
+
this.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
|
|
130
|
+
return function(record) {
|
|
131
|
+
if (_this.filter(record)) {
|
|
132
|
+
return _this.processRecord(record, _this.isSmartQueriesEnabled);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
})(this));
|
|
20
136
|
}
|
|
21
137
|
|
|
22
138
|
DRPivotData.prototype.forEachRecord = function(input, derivedAttributes, f) {
|
|
@@ -193,11 +309,28 @@ let initDRPivotTable = function($, window, document) {
|
|
|
193
309
|
};
|
|
194
310
|
};
|
|
195
311
|
|
|
312
|
+
DRPivotData.prototype.getColKeys = function() {
|
|
313
|
+
return this.colKeys;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
DRPivotData.prototype.getRowKeys = function() {
|
|
317
|
+
return this.rowKeys;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
DRPivotData.prototype.getRowKeysByCols = function() {
|
|
321
|
+
return this.rowKeysByCols;
|
|
322
|
+
};
|
|
323
|
+
|
|
196
324
|
return DRPivotData;
|
|
197
325
|
|
|
198
|
-
})(
|
|
326
|
+
})();
|
|
199
327
|
|
|
200
|
-
$.pivotUtilities
|
|
328
|
+
$.pivotUtilities = {
|
|
329
|
+
aggregatorTemplates: aggregatorTemplates,
|
|
330
|
+
locales: locales,
|
|
331
|
+
numberFormat: numberFormat,
|
|
332
|
+
DRPivotData: DRPivotData
|
|
333
|
+
};
|
|
201
334
|
|
|
202
335
|
getFormattedNumber = function(val, aggregator, opts, format_argument) {
|
|
203
336
|
if (!aggregator) {
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const getPublishedItemsRenderer = require('./published_items_renderer');
|
|
2
2
|
const getHighchartsRenderer = require('./highcharts_renderer');
|
|
3
|
-
const initPivotTable = require('./pivottable');
|
|
4
3
|
const initDRPivotTable = require('./dr_pivottable');
|
|
5
4
|
const initNovixRenderer = require('./novix_renderer');
|
|
6
5
|
const DataFormatter = require('./dataformatter');
|
|
@@ -12,7 +11,6 @@ let dr_render_factory = {};
|
|
|
12
11
|
|
|
13
12
|
dr_render_factory.init = function($, window, document, Handsontable){
|
|
14
13
|
window.DataFormatter = DataFormatter;
|
|
15
|
-
initPivotTable($, window, document);
|
|
16
14
|
initDRPivotTable($, window, document);
|
|
17
15
|
if(Handsontable){
|
|
18
16
|
initNovixRenderer($, window, document, Handsontable);
|
package/src/options/builders.js
CHANGED
|
@@ -404,6 +404,10 @@ const withTooltipPie = () => createSuboption('tooltips', 'Tooltip', [
|
|
|
404
404
|
const withTooltipGauge = () => createSuboption('tooltips', 'Tooltip', [
|
|
405
405
|
GAUGE_SHOW_TOGGLE,
|
|
406
406
|
...createTooltipStyleGroup(),
|
|
407
|
+
createDivider(),
|
|
408
|
+
createCheckbox('show_segment_name', 'Segment name', true),
|
|
409
|
+
createCheckbox('show_percentage_in_value', 'Value % out of Goal', true),
|
|
410
|
+
createCheckbox('show_percentage_in_segments', 'Segment % out Goal', true),
|
|
407
411
|
]);
|
|
408
412
|
|
|
409
413
|
// ============================================================================
|
|
@@ -495,7 +499,7 @@ const withTableOptionsTranspose = (config = {}) => {
|
|
|
495
499
|
createCheckbox('show_subtotals_for_columns', 'Subtotals for columns', false),
|
|
496
500
|
createCheckbox('show_subtotals_for_rows', 'Subtotals for rows', false),
|
|
497
501
|
createCheckbox('show_subtotals_in_brackets', 'Subtotals in brackets', false),
|
|
498
|
-
createCheckbox('transpose_table', 'Transpose',
|
|
502
|
+
createCheckbox('transpose_table', 'Transpose', false),
|
|
499
503
|
createCheckbox('start_collapsed_rows', 'Start collapsed rows <small>(old table only)</small>', false),
|
|
500
504
|
createCheckbox('start_collapsed_columns', 'Start collapsed columns <small>(old table only)</small>', false),
|
|
501
505
|
createCheckbox('colorize_headers', 'Colorize headers', true),
|
|
@@ -503,7 +507,6 @@ const withTableOptionsTranspose = (config = {}) => {
|
|
|
503
507
|
createCheckbox('use_handsOnTable', 'Use big data table', false),
|
|
504
508
|
createCheckbox('use_new_table_design', 'Use new table design', true),
|
|
505
509
|
createCheckbox('hide_nulls_in_headers', 'Null values appear as blank', true),
|
|
506
|
-
createCheckbox('show_all', 'Show All', false),
|
|
507
510
|
createCheckbox('freeze_panes', 'Freeze panes <small>(old table only)</small>', false),
|
|
508
511
|
createCheckbox('eliminate_calc_totals', 'Eliminate grand totals for calculated values', false),
|
|
509
512
|
createCheckbox('show_more_than_thousand_rows', 'Show data in dashboard if more than 1000 rows', false, {
|
|
@@ -529,36 +532,36 @@ const withTableOptionsGauge = () => createSuboption('table_options', 'Table', [
|
|
|
529
532
|
const withTableDesignOptions = () => createSuboption('table_design_options', 'Table design', [
|
|
530
533
|
createDivider('Columns'),
|
|
531
534
|
createSelect('columns_font_style', 'Font style', SUBOPTIONS_FONTS, LABEL_DEFAULT_SETTINGS.FONT_FAMILY),
|
|
532
|
-
createSelect('columns_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES,
|
|
533
|
-
createSelect('
|
|
535
|
+
createSelect('columns_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES, '10'),
|
|
536
|
+
createSelect('columns_align_text', 'Alignment', [
|
|
534
537
|
{ label: 'Left', value: 'left' },
|
|
535
538
|
{ label: 'Center', value: 'center' },
|
|
536
539
|
{ label: 'Right', value: 'right' },
|
|
537
540
|
], 'left'),
|
|
538
541
|
createDivider('Rows'),
|
|
539
542
|
createSelect('rows_font_style', 'Font style', SUBOPTIONS_FONTS, LABEL_DEFAULT_SETTINGS.FONT_FAMILY),
|
|
540
|
-
createSelect('rows_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES,
|
|
541
|
-
createSelect('
|
|
543
|
+
createSelect('rows_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES, '10'),
|
|
544
|
+
createSelect('rows_align_text', 'Alignment', [
|
|
542
545
|
{ label: 'Left', value: 'left' },
|
|
543
546
|
{ label: 'Center', value: 'center' },
|
|
544
547
|
{ label: 'Right', value: 'right' },
|
|
545
548
|
], 'left'),
|
|
546
549
|
createDivider('Values'),
|
|
547
550
|
createSelect('values_font_style', 'Font style', SUBOPTIONS_FONTS, LABEL_DEFAULT_SETTINGS.FONT_FAMILY),
|
|
548
|
-
createSelect('values_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES,
|
|
549
|
-
createSelect('
|
|
551
|
+
createSelect('values_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES, '10'),
|
|
552
|
+
createSelect('values_align_text', 'Alignment', [
|
|
550
553
|
{ label: 'Left', value: 'left' },
|
|
551
554
|
{ label: 'Center', value: 'center' },
|
|
552
555
|
{ label: 'Right', value: 'right' },
|
|
553
|
-
], '
|
|
554
|
-
createDivider('
|
|
555
|
-
createSelect('
|
|
556
|
-
createSelect('
|
|
557
|
-
createSelect('
|
|
556
|
+
], 'left'),
|
|
557
|
+
createDivider('Totals'),
|
|
558
|
+
createSelect('totals_font_style', 'Font style', SUBOPTIONS_FONTS, LABEL_DEFAULT_SETTINGS.FONT_FAMILY),
|
|
559
|
+
createSelect('totals_font_size', 'Font size', SUBOPTIONS_FONT_SIZE_VALUES, '10'),
|
|
560
|
+
createSelect('totals_align_text', 'Alignment', [
|
|
558
561
|
{ label: 'Left', value: 'left' },
|
|
559
562
|
{ label: 'Center', value: 'center' },
|
|
560
563
|
{ label: 'Right', value: 'right' },
|
|
561
|
-
], '
|
|
564
|
+
], 'left'),
|
|
562
565
|
]);
|
|
563
566
|
|
|
564
567
|
// ============================================================================
|
|
@@ -666,12 +669,17 @@ const withName = () => createSuboption('name', 'Name', [
|
|
|
666
669
|
* Creates a negative number format suboption.
|
|
667
670
|
* @returns {SuboptionDefinition}
|
|
668
671
|
*/
|
|
669
|
-
const withNegativeNumberFormat = () =>
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
672
|
+
const withNegativeNumberFormat = () => ({
|
|
673
|
+
...createSuboption('negative_numbers', 'Negative num', [
|
|
674
|
+
createRadio('value', 'Show like', [
|
|
675
|
+
{ label: '-1234', value: 'minus' },
|
|
676
|
+
{ label: '-1234[red]', value: 'red_minus' },
|
|
677
|
+
{ label: '(1234)', value: 'absolute' },
|
|
678
|
+
{ label: '(1234)[red]', value: 'red_absolute' },
|
|
679
|
+
], 'minus'),
|
|
680
|
+
]),
|
|
681
|
+
is_hidden: true,
|
|
682
|
+
});
|
|
675
683
|
|
|
676
684
|
/**
|
|
677
685
|
* Creates a value suboption for KPI widgets.
|
|
@@ -806,10 +814,13 @@ const withTotalValueLabelDonut = () => createSuboption('total_value_label', 'Tot
|
|
|
806
814
|
* @returns {SuboptionDefinition}
|
|
807
815
|
*/
|
|
808
816
|
const withGaugeGoal = () => ({
|
|
809
|
-
|
|
817
|
+
category_class: DEFAULT_CATEGORY_CLASS,
|
|
818
|
+
category_label: 'Gauge goal',
|
|
819
|
+
category_type: 'goal',
|
|
820
|
+
elements: [
|
|
810
821
|
createInput('title', 'Goal title', 'Goal'),
|
|
811
822
|
createInput('value', 'Goal value', 1000000),
|
|
812
|
-
]
|
|
823
|
+
],
|
|
813
824
|
is_hidden: true,
|
|
814
825
|
});
|
|
815
826
|
|
|
@@ -839,9 +850,9 @@ const withGaugeSegments = (config = {}) => ({
|
|
|
839
850
|
category_type: 'segments',
|
|
840
851
|
is_hidden: true,
|
|
841
852
|
default_value: config.defaultSegments || [
|
|
842
|
-
{ from: 0, to: 50, color: '
|
|
843
|
-
{ from:
|
|
844
|
-
{ from:
|
|
853
|
+
{ from: 0, to: 50, color: '#BF1D30', title: 'Low' },
|
|
854
|
+
{ from: 50, to: 90, color: '#FFA310', title: 'Medium' },
|
|
855
|
+
{ from: 90, to: 100, color: '#037C5A', title: 'High' },
|
|
845
856
|
],
|
|
846
857
|
});
|
|
847
858
|
|