@datarailsshared/dr_renderer 1.5.88 → 1.5.90
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-renderer-helpers.js +0 -6
- package/src/dr_pivottable.js +1 -192
- package/src/highcharts_renderer.js +13 -354
- package/src/pivottable.js +7 -653
- package/tests/dr-renderer-helpers.test.js +0 -32
- package/tests/highcharts_renderer.test.js +116 -244
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash');
|
|
2
2
|
|
|
3
|
-
function backendSortingKeysAreNotEmpty(keys) {
|
|
4
|
-
return !!keys && (!!keys.row_keys && !!keys.row_keys.length || !!keys.col_keys && !!keys.col_keys.length);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
function capitalize(string) {
|
|
8
4
|
if (typeof string !== 'string') return '';
|
|
9
5
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
@@ -79,12 +75,10 @@ const FEATURES = {
|
|
|
79
75
|
FORMAT_DATES_AS_OTHER_AXIS_TYPES: 'format_dates_as_other_axis_types',
|
|
80
76
|
MULTIPLE_DIMENSION_TAGS: 'multiple_dimension_tags',
|
|
81
77
|
USE_NEW_SCENARIO_TAG: 'use_new_scenario_tag',
|
|
82
|
-
ENABLE_SERVER_WIDGET_DATA_SORTING: 'enable_server_widget_data_sorting',
|
|
83
78
|
ENABLE_GAUGE_DYNAMIC_GOAL: 'enable_gauge_dynamic_goal',
|
|
84
79
|
}
|
|
85
80
|
|
|
86
81
|
module.exports = {
|
|
87
|
-
backendSortingKeysAreNotEmpty,
|
|
88
82
|
capitalize,
|
|
89
83
|
clamp,
|
|
90
84
|
isNumber,
|
package/src/dr_pivottable.js
CHANGED
|
@@ -4,10 +4,9 @@ const { TooMuchDataError } = require('./errors');
|
|
|
4
4
|
|
|
5
5
|
let initDRPivotTable = function($, window, document) {
|
|
6
6
|
var hasProp = {}.hasOwnProperty;
|
|
7
|
-
var slice = [].slice;
|
|
8
7
|
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
9
8
|
|
|
10
|
-
var DRPivotData,
|
|
9
|
+
var DRPivotData, processKey, SubtotalRenderer, getFormattedNumber, NovixRenderer;
|
|
11
10
|
const newTableColors = ['rgb(127, 196, 255)', 'rgb(200, 243,243)', 'rgb(247, 161, 173)', 'rgb(255, 237, 178)', 'rgb(221, 239, 255)',
|
|
12
11
|
'rgb(171, 216, 255)', 'rgb(174, 231, 220)', 'rgb(227, 255, 236)', 'rgb(162, 215, 227)', 'rgb(223, 239, 236)'];
|
|
13
12
|
|
|
@@ -15,10 +14,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
15
14
|
document.ReportHippo.user.organization.settings && document.ReportHippo.user.organization.settings.use_new_ux;
|
|
16
15
|
// const numberOfRows = 500; // change to activate the handsontable when num of rows bigger then this.
|
|
17
16
|
|
|
18
|
-
const isFlatKeyInPivotKeys = function(keys, flatKey) {
|
|
19
|
-
return keys.some(key => key.join(DELIMER) === flatKey);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
17
|
DRPivotData = (function(superClass) {
|
|
23
18
|
extend(DRPivotData, superClass);
|
|
24
19
|
|
|
@@ -26,16 +21,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
26
21
|
DRPivotData.__super__.constructor.call(this, input, opts);
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
getSort = function(sorters, attr) {
|
|
30
|
-
var sort;
|
|
31
|
-
sort = sorters(attr);
|
|
32
|
-
if ($.isFunction(sort)) {
|
|
33
|
-
return sort;
|
|
34
|
-
} else {
|
|
35
|
-
return $.pivotUtilities.naturalSort;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
24
|
DRPivotData.prototype.forEachRecord = function(input, derivedAttributes, f) {
|
|
40
25
|
var addRecord, compactRecord, i, j, k, l, len1, record, ref, results, results1, tblCols;
|
|
41
26
|
if ($.isEmptyObject(derivedAttributes)) {
|
|
@@ -96,41 +81,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
96
81
|
}
|
|
97
82
|
};
|
|
98
83
|
|
|
99
|
-
DRPivotData.prototype.arrSort = function(attrs) {
|
|
100
|
-
var a, sortersArr;
|
|
101
|
-
const sortByValueAttrs = this.sortByValueAttrs;
|
|
102
|
-
sortersArr = (function() {
|
|
103
|
-
var l, len1, results;
|
|
104
|
-
results = [];
|
|
105
|
-
for (l = 0, len1 = attrs.length; l < len1; l++) {
|
|
106
|
-
a = attrs[l];
|
|
107
|
-
results.push(getSort(this.sorters, a));
|
|
108
|
-
}
|
|
109
|
-
return results;
|
|
110
|
-
}).call(this);
|
|
111
|
-
|
|
112
|
-
return function(a, b) {
|
|
113
|
-
var comparison, i, sorter;
|
|
114
|
-
for (i in sortersArr) {
|
|
115
|
-
const index = parseInt(i);
|
|
116
|
-
sorter = sortersArr[index];
|
|
117
|
-
if (sortByValueAttrs.indexOf(attrs[index]) !== -1) {
|
|
118
|
-
|
|
119
|
-
// For case current Field attrs[index] is sorted by value we are concatenating values passed to sorter function
|
|
120
|
-
// Concatenation is done from first field in a block (first axis or first series) until current field index.
|
|
121
|
-
// Cause for this case sorting will be as list of these concatenated strings (which is prepared in getSortingByValueOrderList)
|
|
122
|
-
comparison = sorter(a.slice(0, index + 1).join(','), b.slice(0, index + 1).join(','));
|
|
123
|
-
} else {
|
|
124
|
-
comparison = sorter(a[index], b[index]);
|
|
125
|
-
}
|
|
126
|
-
if (comparison !== 0) {
|
|
127
|
-
return comparison;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return 0;
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
84
|
processKey = function(record, totals, keys, attrs, containsAverage, containsOthers, getAggregator) {
|
|
135
85
|
var addKey, attr, flatKey, k, key, len, ref;
|
|
136
86
|
key = [];
|
|
@@ -199,15 +149,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
199
149
|
let flatRowKey = rowKey.join(DELIMER);
|
|
200
150
|
let flatColKey = colKey.join(DELIMER);
|
|
201
151
|
|
|
202
|
-
if (this.keysLength === rowKey.length + colKey.length) {
|
|
203
|
-
if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.rowKeys, flatRowKey)) {
|
|
204
|
-
this.rowKeys.push(rowKey);
|
|
205
|
-
}
|
|
206
|
-
if (!this.isKeysSortingDoneOnBackendSide && !isFlatKeyInPivotKeys(this.colKeys, flatColKey)) {
|
|
207
|
-
this.colKeys.push(colKey);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
152
|
if (!colKey.length && !rowKey.length) {
|
|
212
153
|
this.allTotal.push(record);
|
|
213
154
|
} else if (!colKey.length && rowKey.length) {
|
|
@@ -258,135 +199,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
258
199
|
|
|
259
200
|
})($.pivotUtilities.PivotData);
|
|
260
201
|
|
|
261
|
-
sortDateStrings = function(month_order) {
|
|
262
|
-
var i, mapping, x;
|
|
263
|
-
mapping = {};
|
|
264
|
-
var order = [
|
|
265
|
-
{"month":"jan", "versions": ['january', 'jan', 'ja'], weight:1},
|
|
266
|
-
{"month":"feb", "versions": ['february', 'feb', 'fe'], weight:2},
|
|
267
|
-
{"month":"mar", "versions": ['march', 'mar', 'mr'], weight:3},
|
|
268
|
-
{"month":"apr", "versions": ['april', 'apr', 'ap','al'], weight:4},
|
|
269
|
-
{"month":"may", "versions": ['may', 'ma'], weight:5},
|
|
270
|
-
{"month":"jun", "versions": ['june', 'jun','jn'], weight:6},
|
|
271
|
-
{"month":"jul", "versions": ['july', 'jul','jl'], weight:7},
|
|
272
|
-
{"month":"aug", "versions": ['august', 'aug', 'au'], weight:8},
|
|
273
|
-
{"month":"sep", "versions": ['september', 'sept', 'sep','sp','se'], weight:9},
|
|
274
|
-
{"month":"oct", "versions": ['october','oct', 'oc'], weight:10},
|
|
275
|
-
{"month":"nov", "versions": ['november', 'nov', 'no'], weight:11},
|
|
276
|
-
{"month":"dec", "versions": ['december', 'dec', 'de'], weight:12}
|
|
277
|
-
];
|
|
278
|
-
var pattern = /(\d{1,4})|(Ja(n)?(uary)?|Fe(b)?(ruary)?|Mar(ch)?|mr|Ap(r)?(il)?|al|Ma(y)?|Jun(e)?|jn|Jul(y)?|jl|Aug(ust)?|au|Se(p)?(t)?(ember)?|sp|Oc(t)?(ober)?|No(v)?(ember)?|De(c)?(ember)?)/ig
|
|
279
|
-
if(month_order){
|
|
280
|
-
for(i=0; i<month_order.length; i++){
|
|
281
|
-
var find_row = _.find(order, {month:month_order[i]});
|
|
282
|
-
if(find_row){
|
|
283
|
-
find_row.weight = i+1;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
_.forEach(order, function(month_obj){
|
|
289
|
-
_.forEach(month_obj.versions, function(val){
|
|
290
|
-
mapping[val] = month_obj.weight*31;
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
var getIndexForVal = function(value){
|
|
295
|
-
var to_return = 0, matches, i;
|
|
296
|
-
if (typeof value === 'string' || value instanceof String){
|
|
297
|
-
matches = value.match(pattern);
|
|
298
|
-
var numbers = 0;
|
|
299
|
-
var i = 0;
|
|
300
|
-
_.forEach(matches, function(v)
|
|
301
|
-
{
|
|
302
|
-
i++;
|
|
303
|
-
v = v.trim().toLowerCase();
|
|
304
|
-
var res = 0;
|
|
305
|
-
|
|
306
|
-
if(mapping[v] != undefined){
|
|
307
|
-
res = mapping[v];
|
|
308
|
-
}
|
|
309
|
-
else{
|
|
310
|
-
try {
|
|
311
|
-
res = parseInt(v)
|
|
312
|
-
if(res > 31 || numbers > 1 || i == matches.length)
|
|
313
|
-
res *=1000
|
|
314
|
-
numbers++;
|
|
315
|
-
}
|
|
316
|
-
catch(er){
|
|
317
|
-
res = 0
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if(res == NaN){
|
|
321
|
-
res = 0
|
|
322
|
-
}
|
|
323
|
-
to_return += res
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
else{
|
|
327
|
-
try {
|
|
328
|
-
to_return = parseInt(value)
|
|
329
|
-
}
|
|
330
|
-
catch(er){
|
|
331
|
-
to_return = value
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return to_return;
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
return function(a, b) {
|
|
339
|
-
return $.pivotUtilities.naturalSort(getIndexForVal(a), getIndexForVal(b));
|
|
340
|
-
};
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
largeToSmallSortByAbsolute = function (as, bs) {
|
|
344
|
-
return largeToSmallSort(as , bs, true);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
largeToSmallSort = function(as, bs, is_abs = false) {
|
|
348
|
-
var a, a1, b, b1, rd, rx, rz;
|
|
349
|
-
rx = /(\d+)|(\D+)/g;
|
|
350
|
-
rd = /\d/;
|
|
351
|
-
rz = /^0/;
|
|
352
|
-
if (typeof as === "number" || typeof bs === "number") {
|
|
353
|
-
if (isNaN(as)) {
|
|
354
|
-
return -1;
|
|
355
|
-
}
|
|
356
|
-
if (isNaN(bs)) {
|
|
357
|
-
return 1;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (is_abs) {
|
|
361
|
-
return Math.abs(bs) - Math.abs(as);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return bs - as;
|
|
365
|
-
}
|
|
366
|
-
a = String(as).toLowerCase();
|
|
367
|
-
b = String(bs).toLowerCase();
|
|
368
|
-
if (a === b) {
|
|
369
|
-
return 0;
|
|
370
|
-
}
|
|
371
|
-
if (!(rd.test(a) && rd.test(b))) {
|
|
372
|
-
return (b > a ? 1 : -1);
|
|
373
|
-
}
|
|
374
|
-
a = a.match(rx);
|
|
375
|
-
b = b.match(rx);
|
|
376
|
-
while (a.length && b.length) {
|
|
377
|
-
a1 = a.shift();
|
|
378
|
-
b1 = b.shift();
|
|
379
|
-
if (a1 !== b1) {
|
|
380
|
-
if (rd.test(a1) && rd.test(b1)) {
|
|
381
|
-
return b1.replace(rz, ".0") - a1.replace(rz, ".0");
|
|
382
|
-
} else {
|
|
383
|
-
return (b1 > a1 ? 1 : -1);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return b.length - a.length;
|
|
388
|
-
};
|
|
389
|
-
|
|
390
202
|
$.pivotUtilities.DRPivotData = DRPivotData;
|
|
391
203
|
|
|
392
204
|
getFormattedNumber = function(val, aggregator, opts, format_argument) {
|
|
@@ -2508,9 +2320,6 @@ let initDRPivotTable = function($, window, document) {
|
|
|
2508
2320
|
$.pivotUtilities.delim = DELIMER;
|
|
2509
2321
|
|
|
2510
2322
|
$.pivotUtilities.getFormattedNumber = getFormattedNumber;
|
|
2511
|
-
$.pivotUtilities.sortDateStrings = sortDateStrings;
|
|
2512
|
-
$.pivotUtilities.largeToSmallSort = largeToSmallSort;
|
|
2513
|
-
$.pivotUtilities.largeToSmallSortByAbsolute = largeToSmallSortByAbsolute;
|
|
2514
2323
|
$.pivotUtilities.getPivotDataModel = function(input, opts){ return new DRPivotData(input, opts); }
|
|
2515
2324
|
$.pivotUtilities.getPivotTableFormula = function(rowData, opts, func, colFields, rowFields, aggregationDefaults, utils) {
|
|
2516
2325
|
let totalStr = 'Grand Totals';
|