@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/src/pivottable.js
CHANGED
|
@@ -5,14 +5,12 @@ const { GenericRenderingError, GenericComputationalError} = require('./errors');
|
|
|
5
5
|
|
|
6
6
|
// from pivottable@2.23.0
|
|
7
7
|
let initPivotTable = function($, window, document) {
|
|
8
|
-
var
|
|
9
|
-
slice = [].slice,
|
|
10
|
-
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
8
|
+
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
11
9
|
hasProp = {}.hasOwnProperty;
|
|
12
10
|
/*
|
|
13
11
|
Utilities
|
|
14
12
|
*/
|
|
15
|
-
var PivotData, addSeparators, aggregatorTemplates,
|
|
13
|
+
var PivotData, addSeparators, aggregatorTemplates, locales, numberFormat, pivotTableRenderer, usFmtInt;
|
|
16
14
|
addSeparators = function(nStr, thousandsSep, decimalSep) {
|
|
17
15
|
var rgx, x, x1, x2;
|
|
18
16
|
nStr += '';
|
|
@@ -46,15 +44,9 @@ let initPivotTable = function($, window, document) {
|
|
|
46
44
|
return "" + opts.prefix + result + opts.suffix;
|
|
47
45
|
};
|
|
48
46
|
};
|
|
49
|
-
usFmt = numberFormat();
|
|
50
47
|
usFmtInt = numberFormat({
|
|
51
48
|
digitsAfterDecimal: 0
|
|
52
49
|
});
|
|
53
|
-
usFmtPct = numberFormat({
|
|
54
|
-
digitsAfterDecimal: 1,
|
|
55
|
-
scaler: 100,
|
|
56
|
-
suffix: "%"
|
|
57
|
-
});
|
|
58
50
|
aggregatorTemplates = {
|
|
59
51
|
count: function(formatter) {
|
|
60
52
|
if (formatter == null) {
|
|
@@ -75,367 +67,9 @@ let initPivotTable = function($, window, document) {
|
|
|
75
67
|
};
|
|
76
68
|
};
|
|
77
69
|
},
|
|
78
|
-
uniques: function(fn, formatter) {
|
|
79
|
-
if (formatter == null) {
|
|
80
|
-
formatter = usFmtInt;
|
|
81
|
-
}
|
|
82
|
-
return function(arg) {
|
|
83
|
-
var attr;
|
|
84
|
-
attr = arg[0];
|
|
85
|
-
return function(data, rowKey, colKey) {
|
|
86
|
-
return {
|
|
87
|
-
uniq: [],
|
|
88
|
-
push: function(record) {
|
|
89
|
-
var ref;
|
|
90
|
-
if (ref = record[attr], indexOf.call(this.uniq, ref) < 0) {
|
|
91
|
-
return this.uniq.push(record[attr]);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
value: function() {
|
|
95
|
-
return fn(this.uniq);
|
|
96
|
-
},
|
|
97
|
-
format: formatter,
|
|
98
|
-
numInputs: attr != null ? 0 : 1
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
sum: function(formatter) {
|
|
104
|
-
if (formatter == null) {
|
|
105
|
-
formatter = usFmt;
|
|
106
|
-
}
|
|
107
|
-
return function(arg) {
|
|
108
|
-
var attr;
|
|
109
|
-
attr = arg[0];
|
|
110
|
-
return function(data, rowKey, colKey) {
|
|
111
|
-
return {
|
|
112
|
-
sum: 0,
|
|
113
|
-
push: function(record) {
|
|
114
|
-
if (!isNaN(parseFloat(record[attr]))) {
|
|
115
|
-
return this.sum += parseFloat(record[attr]);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
value: function() {
|
|
119
|
-
return this.sum;
|
|
120
|
-
},
|
|
121
|
-
format: formatter,
|
|
122
|
-
numInputs: attr != null ? 0 : 1
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
extremes: function(mode, formatter) {
|
|
128
|
-
if (formatter == null) {
|
|
129
|
-
formatter = usFmt;
|
|
130
|
-
}
|
|
131
|
-
return function(arg) {
|
|
132
|
-
var attr;
|
|
133
|
-
attr = arg[0];
|
|
134
|
-
return function(data, rowKey, colKey) {
|
|
135
|
-
return {
|
|
136
|
-
val: null,
|
|
137
|
-
sorter: getSort(data != null ? data.sorters : void 0, attr),
|
|
138
|
-
push: function(record) {
|
|
139
|
-
var ref, ref1, ref2, x;
|
|
140
|
-
x = record[attr];
|
|
141
|
-
if (mode === "min" || mode === "max") {
|
|
142
|
-
x = parseFloat(x);
|
|
143
|
-
if (!isNaN(x)) {
|
|
144
|
-
this.val = Math[mode](x, (ref = this.val) != null ? ref : x);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (mode === "first") {
|
|
148
|
-
if (this.sorter(x, (ref1 = this.val) != null ? ref1 : x) <= 0) {
|
|
149
|
-
this.val = x;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (mode === "last") {
|
|
153
|
-
if (this.sorter(x, (ref2 = this.val) != null ? ref2 : x) >= 0) {
|
|
154
|
-
return this.val = x;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
value: function() {
|
|
159
|
-
return this.val;
|
|
160
|
-
},
|
|
161
|
-
format: function(x) {
|
|
162
|
-
if (isNaN(x)) {
|
|
163
|
-
return x;
|
|
164
|
-
} else {
|
|
165
|
-
return formatter(x);
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
numInputs: attr != null ? 0 : 1
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
},
|
|
173
|
-
quantile: function(q, formatter) {
|
|
174
|
-
if (formatter == null) {
|
|
175
|
-
formatter = usFmt;
|
|
176
|
-
}
|
|
177
|
-
return function(arg) {
|
|
178
|
-
var attr;
|
|
179
|
-
attr = arg[0];
|
|
180
|
-
return function(data, rowKey, colKey) {
|
|
181
|
-
return {
|
|
182
|
-
vals: [],
|
|
183
|
-
push: function(record) {
|
|
184
|
-
var x;
|
|
185
|
-
x = parseFloat(record[attr]);
|
|
186
|
-
if (!isNaN(x)) {
|
|
187
|
-
return this.vals.push(x);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
value: function() {
|
|
191
|
-
var i;
|
|
192
|
-
if (this.vals.length === 0) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
this.vals.sort(function(a, b) {
|
|
196
|
-
return a - b;
|
|
197
|
-
});
|
|
198
|
-
i = (this.vals.length - 1) * q;
|
|
199
|
-
return (this.vals[Math.floor(i)] + this.vals[Math.ceil(i)]) / 2.0;
|
|
200
|
-
},
|
|
201
|
-
format: formatter,
|
|
202
|
-
numInputs: attr != null ? 0 : 1
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
},
|
|
207
|
-
runningStat: function(mode, ddof, formatter) {
|
|
208
|
-
if (mode == null) {
|
|
209
|
-
mode = "mean";
|
|
210
|
-
}
|
|
211
|
-
if (ddof == null) {
|
|
212
|
-
ddof = 1;
|
|
213
|
-
}
|
|
214
|
-
if (formatter == null) {
|
|
215
|
-
formatter = usFmt;
|
|
216
|
-
}
|
|
217
|
-
return function(arg) {
|
|
218
|
-
var attr;
|
|
219
|
-
attr = arg[0];
|
|
220
|
-
return function(data, rowKey, colKey) {
|
|
221
|
-
return {
|
|
222
|
-
n: 0.0,
|
|
223
|
-
m: 0.0,
|
|
224
|
-
s: 0.0,
|
|
225
|
-
push: function(record) {
|
|
226
|
-
var m_new, x;
|
|
227
|
-
x = parseFloat(record[attr]);
|
|
228
|
-
if (isNaN(x)) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
this.n += 1.0;
|
|
232
|
-
if (this.n === 1.0) {
|
|
233
|
-
return this.m = x;
|
|
234
|
-
} else {
|
|
235
|
-
m_new = this.m + (x - this.m) / this.n;
|
|
236
|
-
this.s = this.s + (x - this.m) * (x - m_new);
|
|
237
|
-
return this.m = m_new;
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
value: function() {
|
|
241
|
-
if (mode === "mean") {
|
|
242
|
-
if (this.n === 0) {
|
|
243
|
-
return 0 / 0;
|
|
244
|
-
} else {
|
|
245
|
-
return this.m;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
if (this.n <= ddof) {
|
|
249
|
-
return 0;
|
|
250
|
-
}
|
|
251
|
-
switch (mode) {
|
|
252
|
-
case "var":
|
|
253
|
-
return this.s / (this.n - ddof);
|
|
254
|
-
case "stdev":
|
|
255
|
-
return Math.sqrt(this.s / (this.n - ddof));
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
format: formatter,
|
|
259
|
-
numInputs: attr != null ? 0 : 1
|
|
260
|
-
};
|
|
261
|
-
};
|
|
262
|
-
};
|
|
263
|
-
},
|
|
264
|
-
sumOverSum: function(formatter) {
|
|
265
|
-
if (formatter == null) {
|
|
266
|
-
formatter = usFmt;
|
|
267
|
-
}
|
|
268
|
-
return function(arg) {
|
|
269
|
-
var denom, num;
|
|
270
|
-
num = arg[0], denom = arg[1];
|
|
271
|
-
return function(data, rowKey, colKey) {
|
|
272
|
-
return {
|
|
273
|
-
sumNum: 0,
|
|
274
|
-
sumDenom: 0,
|
|
275
|
-
push: function(record) {
|
|
276
|
-
if (!isNaN(parseFloat(record[num]))) {
|
|
277
|
-
this.sumNum += parseFloat(record[num]);
|
|
278
|
-
}
|
|
279
|
-
if (!isNaN(parseFloat(record[denom]))) {
|
|
280
|
-
return this.sumDenom += parseFloat(record[denom]);
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
value: function() {
|
|
284
|
-
return this.sumNum / this.sumDenom;
|
|
285
|
-
},
|
|
286
|
-
format: formatter,
|
|
287
|
-
numInputs: (num != null) && (denom != null) ? 0 : 2
|
|
288
|
-
};
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
},
|
|
292
|
-
sumOverSumBound80: function(upper, formatter) {
|
|
293
|
-
if (upper == null) {
|
|
294
|
-
upper = true;
|
|
295
|
-
}
|
|
296
|
-
if (formatter == null) {
|
|
297
|
-
formatter = usFmt;
|
|
298
|
-
}
|
|
299
|
-
return function(arg) {
|
|
300
|
-
var denom, num;
|
|
301
|
-
num = arg[0], denom = arg[1];
|
|
302
|
-
return function(data, rowKey, colKey) {
|
|
303
|
-
return {
|
|
304
|
-
sumNum: 0,
|
|
305
|
-
sumDenom: 0,
|
|
306
|
-
push: function(record) {
|
|
307
|
-
if (!isNaN(parseFloat(record[num]))) {
|
|
308
|
-
this.sumNum += parseFloat(record[num]);
|
|
309
|
-
}
|
|
310
|
-
if (!isNaN(parseFloat(record[denom]))) {
|
|
311
|
-
return this.sumDenom += parseFloat(record[denom]);
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
value: function() {
|
|
315
|
-
var sign;
|
|
316
|
-
sign = upper ? 1 : -1;
|
|
317
|
-
return (0.821187207574908 / this.sumDenom + this.sumNum / this.sumDenom + 1.2815515655446004 * sign * Math.sqrt(0.410593603787454 / (this.sumDenom * this.sumDenom) + (this.sumNum * (1 - this.sumNum / this.sumDenom)) / (this.sumDenom * this.sumDenom))) / (1 + 1.642374415149816 / this.sumDenom);
|
|
318
|
-
},
|
|
319
|
-
format: formatter,
|
|
320
|
-
numInputs: (num != null) && (denom != null) ? 0 : 2
|
|
321
|
-
};
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
},
|
|
325
|
-
fractionOf: function(wrapped, type, formatter) {
|
|
326
|
-
if (type == null) {
|
|
327
|
-
type = "total";
|
|
328
|
-
}
|
|
329
|
-
if (formatter == null) {
|
|
330
|
-
formatter = usFmtPct;
|
|
331
|
-
}
|
|
332
|
-
return function() {
|
|
333
|
-
var x;
|
|
334
|
-
x = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
335
|
-
return function(data, rowKey, colKey) {
|
|
336
|
-
return {
|
|
337
|
-
selector: {
|
|
338
|
-
total: [[], []],
|
|
339
|
-
row: [rowKey, []],
|
|
340
|
-
col: [[], colKey]
|
|
341
|
-
}[type],
|
|
342
|
-
inner: wrapped.apply(null, x)(data, rowKey, colKey),
|
|
343
|
-
push: function(record) {
|
|
344
|
-
return this.inner.push(record);
|
|
345
|
-
},
|
|
346
|
-
format: formatter,
|
|
347
|
-
value: function() {
|
|
348
|
-
return this.inner.value() / data.getAggregator.apply(data, this.selector).inner.value();
|
|
349
|
-
},
|
|
350
|
-
numInputs: wrapped.apply(null, x)().numInputs
|
|
351
|
-
};
|
|
352
|
-
};
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
aggregatorTemplates.countUnique = function(f) {
|
|
357
|
-
return aggregatorTemplates.uniques((function(x) {
|
|
358
|
-
return x.length;
|
|
359
|
-
}), f);
|
|
360
|
-
};
|
|
361
|
-
aggregatorTemplates.listUnique = function(s) {
|
|
362
|
-
return aggregatorTemplates.uniques((function(x) {
|
|
363
|
-
return x.sort(naturalSort).join(s);
|
|
364
|
-
}), (function(x) {
|
|
365
|
-
return x;
|
|
366
|
-
}));
|
|
367
|
-
};
|
|
368
|
-
aggregatorTemplates.max = function(f) {
|
|
369
|
-
return aggregatorTemplates.extremes('max', f);
|
|
370
|
-
};
|
|
371
|
-
aggregatorTemplates.min = function(f) {
|
|
372
|
-
return aggregatorTemplates.extremes('min', f);
|
|
373
|
-
};
|
|
374
|
-
aggregatorTemplates.first = function(f) {
|
|
375
|
-
return aggregatorTemplates.extremes('first', f);
|
|
376
|
-
};
|
|
377
|
-
aggregatorTemplates.last = function(f) {
|
|
378
|
-
return aggregatorTemplates.extremes('last', f);
|
|
379
|
-
};
|
|
380
|
-
aggregatorTemplates.median = function(f) {
|
|
381
|
-
return aggregatorTemplates.quantile(0.5, f);
|
|
382
|
-
};
|
|
383
|
-
aggregatorTemplates.average = function(f) {
|
|
384
|
-
return aggregatorTemplates.runningStat("mean", 1, f);
|
|
385
|
-
};
|
|
386
|
-
aggregatorTemplates["var"] = function(ddof, f) {
|
|
387
|
-
return aggregatorTemplates.runningStat("var", ddof, f);
|
|
388
|
-
};
|
|
389
|
-
aggregatorTemplates.stdev = function(ddof, f) {
|
|
390
|
-
return aggregatorTemplates.runningStat("stdev", ddof, f);
|
|
391
|
-
};
|
|
392
|
-
aggregators = (function(tpl) {
|
|
393
|
-
return {
|
|
394
|
-
"Count": tpl.count(usFmtInt),
|
|
395
|
-
"Count Unique Values": tpl.countUnique(usFmtInt),
|
|
396
|
-
"List Unique Values": tpl.listUnique(", "),
|
|
397
|
-
"Sum": tpl.sum(usFmt),
|
|
398
|
-
"Integer Sum": tpl.sum(usFmtInt),
|
|
399
|
-
"Average": tpl.average(usFmt),
|
|
400
|
-
"Median": tpl.median(usFmt),
|
|
401
|
-
"Sample Variance": tpl["var"](1, usFmt),
|
|
402
|
-
"Sample Standard Deviation": tpl.stdev(1, usFmt),
|
|
403
|
-
"Minimum": tpl.min(usFmt),
|
|
404
|
-
"Maximum": tpl.max(usFmt),
|
|
405
|
-
"First": tpl.first(usFmt),
|
|
406
|
-
"Last": tpl.last(usFmt),
|
|
407
|
-
"Sum over Sum": tpl.sumOverSum(usFmt),
|
|
408
|
-
"80% Upper Bound": tpl.sumOverSumBound80(true, usFmt),
|
|
409
|
-
"80% Lower Bound": tpl.sumOverSumBound80(false, usFmt),
|
|
410
|
-
"Sum as Fraction of Total": tpl.fractionOf(tpl.sum(), "total", usFmtPct),
|
|
411
|
-
"Sum as Fraction of Rows": tpl.fractionOf(tpl.sum(), "row", usFmtPct),
|
|
412
|
-
"Sum as Fraction of Columns": tpl.fractionOf(tpl.sum(), "col", usFmtPct),
|
|
413
|
-
"Count as Fraction of Total": tpl.fractionOf(tpl.count(), "total", usFmtPct),
|
|
414
|
-
"Count as Fraction of Rows": tpl.fractionOf(tpl.count(), "row", usFmtPct),
|
|
415
|
-
"Count as Fraction of Columns": tpl.fractionOf(tpl.count(), "col", usFmtPct)
|
|
416
|
-
};
|
|
417
|
-
})(aggregatorTemplates);
|
|
418
|
-
renderers = {
|
|
419
|
-
"Table": function(data, opts) {
|
|
420
|
-
return pivotTableRenderer(data, opts);
|
|
421
|
-
},
|
|
422
|
-
"Table Barchart": function(data, opts) {
|
|
423
|
-
return $(pivotTableRenderer(data, opts)).barchart();
|
|
424
|
-
},
|
|
425
|
-
"Heatmap": function(data, opts) {
|
|
426
|
-
return $(pivotTableRenderer(data, opts)).heatmap("heatmap", opts);
|
|
427
|
-
},
|
|
428
|
-
"Row Heatmap": function(data, opts) {
|
|
429
|
-
return $(pivotTableRenderer(data, opts)).heatmap("rowheatmap", opts);
|
|
430
|
-
},
|
|
431
|
-
"Col Heatmap": function(data, opts) {
|
|
432
|
-
return $(pivotTableRenderer(data, opts)).heatmap("colheatmap", opts);
|
|
433
|
-
}
|
|
434
70
|
};
|
|
435
71
|
locales = {
|
|
436
72
|
en: {
|
|
437
|
-
aggregators: aggregators,
|
|
438
|
-
renderers: renderers,
|
|
439
73
|
localeStrings: {
|
|
440
74
|
selectAll: "Select All",
|
|
441
75
|
selectNone: "Select None",
|
|
@@ -449,171 +83,6 @@ let initPivotTable = function($, window, document) {
|
|
|
449
83
|
}
|
|
450
84
|
}
|
|
451
85
|
};
|
|
452
|
-
mthNamesEn = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
453
|
-
dayNamesEn = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
454
|
-
zeroPad = function(number) {
|
|
455
|
-
return ("0" + number).substr(-2, 2);
|
|
456
|
-
};
|
|
457
|
-
derivers = {
|
|
458
|
-
bin: function(col, binWidth) {
|
|
459
|
-
return function(record) {
|
|
460
|
-
return record[col] - record[col] % binWidth;
|
|
461
|
-
};
|
|
462
|
-
},
|
|
463
|
-
dateFormat: function(col, formatString, utcOutput, mthNames, dayNames) {
|
|
464
|
-
var utc;
|
|
465
|
-
if (utcOutput == null) {
|
|
466
|
-
utcOutput = false;
|
|
467
|
-
}
|
|
468
|
-
if (mthNames == null) {
|
|
469
|
-
mthNames = mthNamesEn;
|
|
470
|
-
}
|
|
471
|
-
if (dayNames == null) {
|
|
472
|
-
dayNames = dayNamesEn;
|
|
473
|
-
}
|
|
474
|
-
utc = utcOutput ? "UTC" : "";
|
|
475
|
-
return function(record) {
|
|
476
|
-
var date;
|
|
477
|
-
date = new Date(Date.parse(record[col]));
|
|
478
|
-
if (isNaN(date)) {
|
|
479
|
-
return "";
|
|
480
|
-
}
|
|
481
|
-
return formatString.replace(/%(.)/g, function(m, p) {
|
|
482
|
-
switch (p) {
|
|
483
|
-
case "y":
|
|
484
|
-
return date["get" + utc + "FullYear"]();
|
|
485
|
-
case "m":
|
|
486
|
-
return zeroPad(date["get" + utc + "Month"]() + 1);
|
|
487
|
-
case "n":
|
|
488
|
-
return mthNames[date["get" + utc + "Month"]()];
|
|
489
|
-
case "d":
|
|
490
|
-
return zeroPad(date["get" + utc + "Date"]());
|
|
491
|
-
case "w":
|
|
492
|
-
return dayNames[date["get" + utc + "Day"]()];
|
|
493
|
-
case "x":
|
|
494
|
-
return date["get" + utc + "Day"]();
|
|
495
|
-
case "H":
|
|
496
|
-
return zeroPad(date["get" + utc + "Hours"]());
|
|
497
|
-
case "M":
|
|
498
|
-
return zeroPad(date["get" + utc + "Minutes"]());
|
|
499
|
-
case "S":
|
|
500
|
-
return zeroPad(date["get" + utc + "Seconds"]());
|
|
501
|
-
default:
|
|
502
|
-
return "%" + p;
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
rx = /(\d+)|(\D+)/g;
|
|
509
|
-
rd = /\d/;
|
|
510
|
-
rz = /^0/;
|
|
511
|
-
naturalSort = (function(_this) {
|
|
512
|
-
return function(as, bs) {
|
|
513
|
-
var a, a1, b, b1, nas, nbs;
|
|
514
|
-
if ((bs != null) && (as == null)) {
|
|
515
|
-
return -1;
|
|
516
|
-
}
|
|
517
|
-
if ((as != null) && (bs == null)) {
|
|
518
|
-
return 1;
|
|
519
|
-
}
|
|
520
|
-
if (typeof as === "number" && isNaN(as)) {
|
|
521
|
-
return -1;
|
|
522
|
-
}
|
|
523
|
-
if (typeof bs === "number" && isNaN(bs)) {
|
|
524
|
-
return 1;
|
|
525
|
-
}
|
|
526
|
-
nas = +as;
|
|
527
|
-
nbs = +bs;
|
|
528
|
-
if (nas < nbs) {
|
|
529
|
-
return -1;
|
|
530
|
-
}
|
|
531
|
-
if (nas > nbs) {
|
|
532
|
-
return 1;
|
|
533
|
-
}
|
|
534
|
-
if (typeof as === "number" && typeof bs !== "number") {
|
|
535
|
-
return -1;
|
|
536
|
-
}
|
|
537
|
-
if (typeof bs === "number" && typeof as !== "number") {
|
|
538
|
-
return 1;
|
|
539
|
-
}
|
|
540
|
-
if (typeof as === "number" && typeof bs === "number") {
|
|
541
|
-
return 0;
|
|
542
|
-
}
|
|
543
|
-
if (isNaN(nbs) && !isNaN(nas)) {
|
|
544
|
-
return -1;
|
|
545
|
-
}
|
|
546
|
-
if (isNaN(nas) && !isNaN(nbs)) {
|
|
547
|
-
return 1;
|
|
548
|
-
}
|
|
549
|
-
a = String(as).toLowerCase();
|
|
550
|
-
b = String(bs).toLowerCase();
|
|
551
|
-
if (a === b) {
|
|
552
|
-
return 0;
|
|
553
|
-
}
|
|
554
|
-
if (!(rd.test(a) && rd.test(b))) {
|
|
555
|
-
return (a > b ? 1 : -1);
|
|
556
|
-
}
|
|
557
|
-
a = a.match(rx);
|
|
558
|
-
b = b.match(rx);
|
|
559
|
-
while (a.length && b.length) {
|
|
560
|
-
a1 = a.shift();
|
|
561
|
-
b1 = b.shift();
|
|
562
|
-
if (a1 !== b1) {
|
|
563
|
-
if (rd.test(a1) && rd.test(b1)) {
|
|
564
|
-
return a1.replace(rz, ".0") - b1.replace(rz, ".0");
|
|
565
|
-
} else {
|
|
566
|
-
return (a1 > b1 ? 1 : -1);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
return a.length - b.length;
|
|
571
|
-
};
|
|
572
|
-
})(this);
|
|
573
|
-
sortAs = function(order) {
|
|
574
|
-
var i, l_mapping, mapping, x;
|
|
575
|
-
mapping = {};
|
|
576
|
-
l_mapping = {};
|
|
577
|
-
for (i in order) {
|
|
578
|
-
x = order[i];
|
|
579
|
-
if (order[i] === null) x = '[null]';
|
|
580
|
-
mapping[x] = i;
|
|
581
|
-
if (typeof x === "string") {
|
|
582
|
-
l_mapping[x.toLowerCase()] = i;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
return function(a, b) {
|
|
586
|
-
if ((mapping[a] != null) && (mapping[b] != null)) {
|
|
587
|
-
return mapping[a] - mapping[b];
|
|
588
|
-
} else if (mapping[a] != null) {
|
|
589
|
-
return -1;
|
|
590
|
-
} else if (mapping[b] != null) {
|
|
591
|
-
return 1;
|
|
592
|
-
} else if ((l_mapping[a] != null) && (l_mapping[b] != null)) {
|
|
593
|
-
return l_mapping[a] - l_mapping[b];
|
|
594
|
-
} else if (l_mapping[a] != null) {
|
|
595
|
-
return -1;
|
|
596
|
-
} else if (l_mapping[b] != null) {
|
|
597
|
-
return 1;
|
|
598
|
-
} else {
|
|
599
|
-
return naturalSort(a, b);
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
};
|
|
603
|
-
getSort = function(sorters, attr) {
|
|
604
|
-
var sort;
|
|
605
|
-
if (sorters != null) {
|
|
606
|
-
if ($.isFunction(sorters)) {
|
|
607
|
-
sort = sorters(attr);
|
|
608
|
-
if ($.isFunction(sort)) {
|
|
609
|
-
return sort;
|
|
610
|
-
}
|
|
611
|
-
} else if (sorters[attr] != null) {
|
|
612
|
-
return sorters[attr];
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return naturalSort;
|
|
616
|
-
};
|
|
617
86
|
|
|
618
87
|
/*
|
|
619
88
|
Data Model class
|
|
@@ -628,40 +97,28 @@ let initPivotTable = function($, window, document) {
|
|
|
628
97
|
this.getRowKeys = bind(this.getRowKeys, this);
|
|
629
98
|
this.getColKeys = bind(this.getColKeys, this);
|
|
630
99
|
this.getRowKeysByCols = bind(this.getRowKeysByCols, this);
|
|
631
|
-
this.sortKeys = bind(this.sortKeys, this);
|
|
632
|
-
this.arrSort = bind(this.arrSort, this);
|
|
633
100
|
this.input = input;
|
|
634
101
|
this.aggregator = (ref = opts.aggregator) != null ? ref : aggregatorTemplates.count()();
|
|
635
102
|
this.aggregatorName = (ref1 = opts.aggregatorName) != null ? ref1 : "Count";
|
|
636
103
|
this.colAttrs = (ref2 = opts.cols) != null ? ref2 : [];
|
|
637
104
|
this.rowAttrs = (ref3 = opts.rows) != null ? ref3 : [];
|
|
638
|
-
this.valAttrs = (ref4 = opts.vals) != null ? ref4 : [];
|
|
639
|
-
this.sorters = (ref5 = opts.sorters) != null ? ref5 : {};
|
|
640
|
-
this.rowOrder = (ref6 = opts.rowOrder) != null ? ref6 : "key_a_to_z";
|
|
641
|
-
this.colOrder = (ref7 = opts.colOrder) != null ? ref7 : "key_a_to_z";
|
|
642
105
|
this.derivedAttributes = (ref8 = opts.derivedAttributes) != null ? ref8 : {};
|
|
643
106
|
this.filter = (ref9 = opts.filter) != null ? ref9 : (function() {
|
|
644
107
|
return true;
|
|
645
108
|
});
|
|
646
109
|
this.isSmartQueriesEnabled = _.some(input, item => item.Scenario === DR_SCENARIO.SQ_Actuals);
|
|
110
|
+
|
|
647
111
|
this.tree = {};
|
|
648
112
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
this.rowKeysByCols = opts.keysObject.row_keys_by_cols;
|
|
654
|
-
} else {
|
|
655
|
-
this.rowKeys = [];
|
|
656
|
-
this.colKeys = [];
|
|
657
|
-
}
|
|
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 : [];
|
|
658
117
|
|
|
659
118
|
this.rowTotals = {};
|
|
660
119
|
this.colTotals = {};
|
|
661
120
|
this.allTotal = this.aggregator(this, [], []);
|
|
662
|
-
this.sorted = false;
|
|
663
121
|
this.dateValuesDictionary = opts.dateValuesDictionary;
|
|
664
|
-
this.sortByValueAttrs = opts.sortByValueAttrs || [];
|
|
665
122
|
this.colFormats = opts.colFormats || [];
|
|
666
123
|
this.rowFormats = opts.rowFormats || [];
|
|
667
124
|
this.isFormattingAxisLabels = opts.rendererOptions && opts.rendererOptions.isFormattingAxisLabels;
|
|
@@ -738,106 +195,11 @@ let initPivotTable = function($, window, document) {
|
|
|
738
195
|
}
|
|
739
196
|
};
|
|
740
197
|
|
|
741
|
-
PivotData.prototype.forEachMatchingRecord = function(criteria, callback) {
|
|
742
|
-
return PivotData.forEachRecord(this.input, this.derivedAttributes, (function(_this) {
|
|
743
|
-
return function(record) {
|
|
744
|
-
var k, ref, v;
|
|
745
|
-
if (!_this.filter(record)) {
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
for (k in criteria) {
|
|
749
|
-
v = criteria[k];
|
|
750
|
-
if (v !== ((ref = record[k]) != null ? ref : "null")) {
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
return callback(record);
|
|
755
|
-
};
|
|
756
|
-
})(this));
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
PivotData.prototype.arrSort = function(attrs) {
|
|
760
|
-
var a, sortersArr;
|
|
761
|
-
sortersArr = (function() {
|
|
762
|
-
var l, len1, results;
|
|
763
|
-
results = [];
|
|
764
|
-
for (l = 0, len1 = attrs.length; l < len1; l++) {
|
|
765
|
-
a = attrs[l];
|
|
766
|
-
results.push(getSort(this.sorters, a));
|
|
767
|
-
}
|
|
768
|
-
return results;
|
|
769
|
-
}).call(this);
|
|
770
|
-
return function(a, b) {
|
|
771
|
-
var comparison, i, sorter;
|
|
772
|
-
for (i in sortersArr) {
|
|
773
|
-
if (!hasProp.call(sortersArr, i)) continue;
|
|
774
|
-
sorter = sortersArr[i];
|
|
775
|
-
comparison = sorter(a[i], b[i]);
|
|
776
|
-
if (comparison !== 0) {
|
|
777
|
-
return comparison;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
return 0;
|
|
781
|
-
};
|
|
782
|
-
};
|
|
783
|
-
|
|
784
|
-
PivotData.prototype.sortKeys = function() {
|
|
785
|
-
var v;
|
|
786
|
-
if (!this.sorted) {
|
|
787
|
-
this.sorted = true;
|
|
788
|
-
v = (function(_this) {
|
|
789
|
-
return function(r, c) {
|
|
790
|
-
return _this.getAggregator(r, c).value();
|
|
791
|
-
};
|
|
792
|
-
})(this);
|
|
793
|
-
switch (this.rowOrder) {
|
|
794
|
-
case "value_a_to_z":
|
|
795
|
-
this.rowKeys.sort((function(_this) {
|
|
796
|
-
return function(a, b) {
|
|
797
|
-
return naturalSort(v(a, []), v(b, []));
|
|
798
|
-
};
|
|
799
|
-
})(this));
|
|
800
|
-
break;
|
|
801
|
-
case "value_z_to_a":
|
|
802
|
-
this.rowKeys.sort((function(_this) {
|
|
803
|
-
return function(a, b) {
|
|
804
|
-
return -naturalSort(v(a, []), v(b, []));
|
|
805
|
-
};
|
|
806
|
-
})(this));
|
|
807
|
-
break;
|
|
808
|
-
default:
|
|
809
|
-
this.rowKeys.sort(this.arrSort(this.rowAttrs));
|
|
810
|
-
}
|
|
811
|
-
switch (this.colOrder) {
|
|
812
|
-
case "value_a_to_z":
|
|
813
|
-
return this.colKeys.sort((function(_this) {
|
|
814
|
-
return function(a, b) {
|
|
815
|
-
return naturalSort(v([], a), v([], b));
|
|
816
|
-
};
|
|
817
|
-
})(this));
|
|
818
|
-
case "value_z_to_a":
|
|
819
|
-
return this.colKeys.sort((function(_this) {
|
|
820
|
-
return function(a, b) {
|
|
821
|
-
return -naturalSort(v([], a), v([], b));
|
|
822
|
-
};
|
|
823
|
-
})(this));
|
|
824
|
-
default:
|
|
825
|
-
return this.colKeys.sort(this.arrSort(this.colAttrs));
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
|
|
830
198
|
PivotData.prototype.getColKeys = function() {
|
|
831
|
-
if (!this.isKeysSortingDoneOnBackendSide) {
|
|
832
|
-
this.sortKeys();
|
|
833
|
-
}
|
|
834
199
|
return this.colKeys;
|
|
835
200
|
};
|
|
836
201
|
|
|
837
202
|
PivotData.prototype.getRowKeys = function() {
|
|
838
|
-
if (!this.isKeysSortingDoneOnBackendSide) {
|
|
839
|
-
this.sortKeys();
|
|
840
|
-
}
|
|
841
203
|
return this.rowKeys;
|
|
842
204
|
};
|
|
843
205
|
|
|
@@ -916,13 +278,8 @@ let initPivotTable = function($, window, document) {
|
|
|
916
278
|
|
|
917
279
|
$.pivotUtilities = {
|
|
918
280
|
aggregatorTemplates: aggregatorTemplates,
|
|
919
|
-
aggregators: aggregators,
|
|
920
|
-
renderers: renderers,
|
|
921
|
-
derivers: derivers,
|
|
922
281
|
locales: locales,
|
|
923
|
-
naturalSort: naturalSort,
|
|
924
282
|
numberFormat: numberFormat,
|
|
925
|
-
sortAs: sortAs,
|
|
926
283
|
PivotData: PivotData,
|
|
927
284
|
};
|
|
928
285
|
if (window.$) {
|
|
@@ -1168,15 +525,12 @@ let initPivotTable = function($, window, document) {
|
|
|
1168
525
|
cols: [],
|
|
1169
526
|
rows: [],
|
|
1170
527
|
vals: [],
|
|
1171
|
-
rowOrder: "key_a_to_z",
|
|
1172
|
-
colOrder: "key_a_to_z",
|
|
1173
528
|
dataClass: PivotData,
|
|
1174
529
|
filter: function() {
|
|
1175
530
|
return true;
|
|
1176
531
|
},
|
|
1177
532
|
aggregator: aggregatorTemplates.count()(),
|
|
1178
533
|
aggregatorName: "Count",
|
|
1179
|
-
sorters: {},
|
|
1180
534
|
derivedAttributes: {},
|
|
1181
535
|
renderer: pivotTableRenderer
|
|
1182
536
|
};
|