@hrforte/react-pivottable 2.2.2 → 3.0.0
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/dist/PivotDataWorker.js +219 -13
- package/dist/PivotDataWorker.js.map +1 -1
- package/dist/PivotTable.js +2 -1
- package/dist/PivotTable.js.map +1 -1
- package/dist/PivotTableUI.js +39 -66
- package/dist/PivotTableUI.js.map +1 -1
- package/dist/TableRenderers.js +568 -106
- package/dist/TableRenderers.js.map +1 -1
- package/dist/Utilities.js +104 -179
- package/dist/Utilities.js.map +1 -1
- package/dist/__tests__/PivotDataWorker-test.js +437 -7
- package/dist/__tests__/PivotDataWorker-test.js.map +1 -1
- package/dist/__tests__/PivotTableUI-processing-test.js +41 -2
- package/dist/__tests__/PivotTableUI-processing-test.js.map +1 -1
- package/dist/__tests__/TableRenderers-showNumericalOrder-test.js +449 -0
- package/dist/__tests__/TableRenderers-showNumericalOrder-test.js.map +1 -1
- package/dist/__tests__/pivotCompute-test.js +137 -0
- package/dist/__tests__/pivotCompute-test.js.map +1 -1
- package/dist/pivot-worker.js +509 -201
- package/dist/pivotCompute.js +237 -12
- package/dist/pivotCompute.js.map +1 -1
- package/dist/pivotWorker.js +165 -9
- package/dist/pivotWorker.js.map +1 -1
- package/dist/pivottable.css +274 -266
- package/package.json +1 -1
package/dist/pivot-worker.js
CHANGED
|
@@ -303,13 +303,26 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
|
|
303
303
|
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__pivotCompute__ = __webpack_require__(5);
|
|
304
304
|
|
|
305
305
|
|
|
306
|
-
var MAX_CACHED_DATASETS =
|
|
306
|
+
var MAX_CACHED_DATASETS = 2;
|
|
307
|
+
var MAX_CACHED_PIVOTS = 2;
|
|
307
308
|
|
|
308
309
|
var datasetCache = new Map();
|
|
310
|
+
var pendingDatasets = new Map();
|
|
311
|
+
var pivotCache = new Map();
|
|
312
|
+
var pivotDataKeys = new Map();
|
|
313
|
+
var pivotOwners = new Map();
|
|
309
314
|
|
|
310
315
|
var debugEnabled = false;
|
|
311
316
|
|
|
312
|
-
var cacheDataset = function cacheDataset(dataKey, dataset) {
|
|
317
|
+
var cacheDataset = function cacheDataset(dataKey, dataset, ownerKey) {
|
|
318
|
+
if (ownerKey) {
|
|
319
|
+
datasetCache.forEach(function (cached, cachedKey) {
|
|
320
|
+
if (cached.ownerKey === ownerKey && cachedKey !== dataKey) {
|
|
321
|
+
datasetCache.delete(cachedKey);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
dataset.ownerKey = ownerKey || null;
|
|
313
326
|
datasetCache.delete(dataKey);
|
|
314
327
|
datasetCache.set(dataKey, dataset);
|
|
315
328
|
while (datasetCache.size > MAX_CACHED_DATASETS) {
|
|
@@ -346,7 +359,7 @@ self.addEventListener('message', function (event) {
|
|
|
346
359
|
var startedAt = Date.now();
|
|
347
360
|
log('#' + message.id + ' setData received: ' + (message.data || []).length + ' records (dataKey=' + message.dataKey + ')');
|
|
348
361
|
try {
|
|
349
|
-
var dataset = cacheDataset(message.dataKey, Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["
|
|
362
|
+
var dataset = cacheDataset(message.dataKey, Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["i" /* materializeData */])(message.data, {}), message.ownerKey);
|
|
350
363
|
log('#' + message.id + ' materialized ' + dataset.totalRecords + ' records in ' + (Date.now() - startedAt + 'ms (attributes: ' + Object.keys(dataset.attrValues).join(', ') + ')'));
|
|
351
364
|
} catch (error) {
|
|
352
365
|
log('#' + message.id + ' setData failed: ' + toErrorMessage(error));
|
|
@@ -359,20 +372,78 @@ self.addEventListener('message', function (event) {
|
|
|
359
372
|
return;
|
|
360
373
|
}
|
|
361
374
|
|
|
362
|
-
if (message.type === 'pivot:
|
|
375
|
+
if (message.type === 'pivot:setDataStart') {
|
|
376
|
+
pendingDatasets.set(message.dataKey, {
|
|
377
|
+
records: [],
|
|
378
|
+
ownerKey: message.ownerKey
|
|
379
|
+
});
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (message.type === 'pivot:setDataChunk') {
|
|
384
|
+
var pending = pendingDatasets.get(message.dataKey);
|
|
385
|
+
if (pending) {
|
|
386
|
+
(message.data || []).forEach(function (record) {
|
|
387
|
+
return pending.records.push(record);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (message.type === 'pivot:setDataEnd') {
|
|
363
394
|
var _startedAt = Date.now();
|
|
395
|
+
try {
|
|
396
|
+
var _pending = pendingDatasets.get(message.dataKey);
|
|
397
|
+
if (!_pending) {
|
|
398
|
+
throw new Error('no dataset staging buffer for key ' + message.dataKey);
|
|
399
|
+
}
|
|
400
|
+
pendingDatasets.delete(message.dataKey);
|
|
401
|
+
var _dataset = cacheDataset(message.dataKey, Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["i" /* materializeData */])(_pending.records, {}), _pending.ownerKey);
|
|
402
|
+
log('#' + message.id + ' materialized ' + _dataset.totalRecords + ' chunked records ' + ('in ' + (Date.now() - _startedAt) + 'ms'));
|
|
403
|
+
} catch (error) {
|
|
404
|
+
pendingDatasets.delete(message.dataKey);
|
|
405
|
+
postToMain({
|
|
406
|
+
type: 'pivot:error',
|
|
407
|
+
id: message.id,
|
|
408
|
+
message: toErrorMessage(error)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (message.type === 'pivot:compute') {
|
|
415
|
+
var _startedAt2 = Date.now();
|
|
364
416
|
var config = message.config || {};
|
|
365
417
|
try {
|
|
366
|
-
var
|
|
367
|
-
if (!
|
|
418
|
+
var _dataset2 = datasetCache.get(message.dataKey);
|
|
419
|
+
if (!_dataset2) {
|
|
368
420
|
throw new Error('no dataset staged for key ' + message.dataKey);
|
|
369
421
|
}
|
|
370
422
|
log('#' + message.id + ' compute received (rows=[' + (config.rows || []).join(', ') + '] cols=[' + (config.cols || []).join(', ') + '])');
|
|
371
|
-
var result = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["
|
|
372
|
-
|
|
423
|
+
var result = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["d" /* computePivotState */])(_dataset2, message.config);
|
|
424
|
+
var columnMode = config.aggregationDisplayMode === 'column';
|
|
425
|
+
var totalRows = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["h" /* getPivotViewportRowCount */])(result, columnMode);
|
|
426
|
+
var totalColumns = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["g" /* getPivotViewportColumnCount */])(result, columnMode);
|
|
427
|
+
var useVirtualSummary = config.virtualizeRows && (config.rendererName || 'Table') === 'Table' && !config.sortersRequireMainThread && (totalRows > __WEBPACK_IMPORTED_MODULE_0__pivotCompute__["b" /* VIRTUAL_ROW_THRESHOLD */] || totalColumns > __WEBPACK_IMPORTED_MODULE_0__pivotCompute__["a" /* VIRTUAL_COLUMN_THRESHOLD */]);
|
|
428
|
+
var sparseColumnsAligned = useVirtualSummary && Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["c" /* alignSparseColumnsToRows */])(result);
|
|
429
|
+
var resultForMain = useVirtualSummary ? Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["f" /* createVirtualPivotSummary */])(result, columnMode) : result;
|
|
430
|
+
resultForMain.viewportKey = message.id;
|
|
431
|
+
pivotCache.set(message.id, useVirtualSummary ? result : {
|
|
432
|
+
rowKeys: result.rowKeys,
|
|
433
|
+
aggregations: result.aggregations
|
|
434
|
+
});
|
|
435
|
+
pivotDataKeys.set(message.id, message.dataKey);
|
|
436
|
+
pivotOwners.set(message.id, message.ownerKey || null);
|
|
437
|
+
while (pivotCache.size > MAX_CACHED_PIVOTS) {
|
|
438
|
+
var oldestKey = pivotCache.keys().next().value;
|
|
439
|
+
pivotCache.delete(oldestKey);
|
|
440
|
+
pivotDataKeys.delete(oldestKey);
|
|
441
|
+
pivotOwners.delete(oldestKey);
|
|
442
|
+
}
|
|
443
|
+
log('#' + message.id + ' computed in ' + (Date.now() - _startedAt2) + 'ms (rowKeys: ' + result.rowKeys.length + ', colKeys: ' + result.colKeys.length + ', sparse columns aligned: ' + sparseColumnsAligned + ', aggregations: ' + result.aggregations.map(function (agg) {
|
|
373
444
|
return agg.key;
|
|
374
445
|
}).join(', ') + ')');
|
|
375
|
-
postToMain({ type: 'pivot:result', id: message.id, result:
|
|
446
|
+
postToMain({ type: 'pivot:result', id: message.id, result: resultForMain });
|
|
376
447
|
} catch (error) {
|
|
377
448
|
log('#' + message.id + ' compute failed: ' + toErrorMessage(error));
|
|
378
449
|
postToMain({
|
|
@@ -381,6 +452,91 @@ self.addEventListener('message', function (event) {
|
|
|
381
452
|
message: toErrorMessage(error)
|
|
382
453
|
});
|
|
383
454
|
}
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (message.type === 'pivot:viewport') {
|
|
459
|
+
try {
|
|
460
|
+
var pivot = pivotCache.get(message.viewportKey);
|
|
461
|
+
if (!pivot) {
|
|
462
|
+
throw new Error('Pivot viewport cache is unavailable');
|
|
463
|
+
}
|
|
464
|
+
var _result = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["e" /* computePivotViewport */])(pivot, message.start, message.end, message.columnMode, message.columnStart, message.columnEnd);
|
|
465
|
+
postToMain({ type: 'pivot:viewportResult', id: message.id, result: _result });
|
|
466
|
+
log('#' + message.id + ' viewport released after postMessage', {
|
|
467
|
+
rows: _result.rows.length,
|
|
468
|
+
datasets: datasetCache.size,
|
|
469
|
+
pivots: pivotCache.size
|
|
470
|
+
});
|
|
471
|
+
} catch (error) {
|
|
472
|
+
postToMain({
|
|
473
|
+
type: 'pivot:error',
|
|
474
|
+
id: message.id,
|
|
475
|
+
message: toErrorMessage(error)
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (message.type === 'pivot:release') {
|
|
482
|
+
pivotCache.delete(message.viewportKey);
|
|
483
|
+
pivotDataKeys.delete(message.viewportKey);
|
|
484
|
+
pivotOwners.delete(message.viewportKey);
|
|
485
|
+
log('released pivot ' + message.viewportKey, {
|
|
486
|
+
datasets: datasetCache.size,
|
|
487
|
+
pivots: pivotCache.size
|
|
488
|
+
});
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (message.type === 'pivot:releaseData') {
|
|
493
|
+
var _dataset3 = datasetCache.get(message.dataKey);
|
|
494
|
+
if (_dataset3) {
|
|
495
|
+
if (Array.isArray(_dataset3.materializedInput)) {
|
|
496
|
+
_dataset3.materializedInput.length = 0;
|
|
497
|
+
}
|
|
498
|
+
_dataset3.attrValues = null;
|
|
499
|
+
}
|
|
500
|
+
datasetCache.delete(message.dataKey);
|
|
501
|
+
pendingDatasets.delete(message.dataKey);
|
|
502
|
+
pivotCache.forEach(function (pivot, viewportKey) {
|
|
503
|
+
if (pivotDataKeys.get(viewportKey) === message.dataKey) {
|
|
504
|
+
pivot.attrValues = null;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
log('released dataset ' + message.dataKey, {
|
|
508
|
+
datasets: datasetCache.size,
|
|
509
|
+
pivots: pivotCache.size
|
|
510
|
+
});
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (message.type === 'pivot:releaseOwner') {
|
|
515
|
+
pendingDatasets.forEach(function (pending, dataKey) {
|
|
516
|
+
if (pending.ownerKey === message.ownerKey) {
|
|
517
|
+
pending.records.length = 0;
|
|
518
|
+
pendingDatasets.delete(dataKey);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
datasetCache.forEach(function (dataset, dataKey) {
|
|
522
|
+
if (dataset.ownerKey === message.ownerKey) {
|
|
523
|
+
if (Array.isArray(dataset.materializedInput)) {
|
|
524
|
+
dataset.materializedInput.length = 0;
|
|
525
|
+
}
|
|
526
|
+
datasetCache.delete(dataKey);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
pivotCache.forEach(function (pivot, viewportKey) {
|
|
530
|
+
if (pivotOwners.get(viewportKey) === message.ownerKey) {
|
|
531
|
+
pivotCache.delete(viewportKey);
|
|
532
|
+
pivotDataKeys.delete(viewportKey);
|
|
533
|
+
pivotOwners.delete(viewportKey);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
log('released owner ' + message.ownerKey, {
|
|
537
|
+
datasets: datasetCache.size,
|
|
538
|
+
pivots: pivotCache.size
|
|
539
|
+
});
|
|
384
540
|
}
|
|
385
541
|
});
|
|
386
542
|
|
|
@@ -390,10 +546,17 @@ self.addEventListener('message', function (event) {
|
|
|
390
546
|
|
|
391
547
|
"use strict";
|
|
392
548
|
/* unused harmony export DEFAULT_WORKER_THRESHOLD */
|
|
549
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return VIRTUAL_ROW_THRESHOLD; });
|
|
550
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return VIRTUAL_COLUMN_THRESHOLD; });
|
|
393
551
|
/* unused harmony export WORKER_DEBOUNCE_MS */
|
|
394
|
-
/* harmony export (immutable) */ __webpack_exports__["
|
|
395
|
-
/* harmony export (immutable) */ __webpack_exports__["
|
|
552
|
+
/* harmony export (immutable) */ __webpack_exports__["i"] = materializeData;
|
|
553
|
+
/* harmony export (immutable) */ __webpack_exports__["d"] = computePivotState;
|
|
396
554
|
/* unused harmony export serializePivotData */
|
|
555
|
+
/* harmony export (immutable) */ __webpack_exports__["h"] = getPivotViewportRowCount;
|
|
556
|
+
/* harmony export (immutable) */ __webpack_exports__["g"] = getPivotViewportColumnCount;
|
|
557
|
+
/* harmony export (immutable) */ __webpack_exports__["c"] = alignSparseColumnsToRows;
|
|
558
|
+
/* harmony export (immutable) */ __webpack_exports__["f"] = createVirtualPivotSummary;
|
|
559
|
+
/* harmony export (immutable) */ __webpack_exports__["e"] = computePivotViewport;
|
|
397
560
|
/* unused harmony export sortersHaveFunctions */
|
|
398
561
|
/* unused harmony export sanitizeSorters */
|
|
399
562
|
/* unused harmony export createWorkerConfig */
|
|
@@ -420,21 +583,34 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
|
|
420
583
|
// larger ones are handed off to the Web Worker.
|
|
421
584
|
var DEFAULT_WORKER_THRESHOLD = 200;
|
|
422
585
|
|
|
586
|
+
// Keep this in the computation module so the worker and renderer make the
|
|
587
|
+
// same decision about when a compact, viewport-backed result can be used.
|
|
588
|
+
var VIRTUAL_ROW_THRESHOLD = 300;
|
|
589
|
+
var VIRTUAL_COLUMN_THRESHOLD = 100;
|
|
590
|
+
|
|
591
|
+
var FLAT_KEY_SEPARATOR = String.fromCharCode(0);
|
|
592
|
+
var SPARSE_CELL_FACTOR = 4;
|
|
593
|
+
|
|
423
594
|
// Trailing debounce before a worker computation is dispatched, so rapid
|
|
424
595
|
// interactions do not queue one full computation per single change.
|
|
425
596
|
var WORKER_DEBOUNCE_MS = 100;
|
|
426
597
|
|
|
427
598
|
/*
|
|
428
599
|
* Walks the raw input once and computes the attribute-value inventory plus a
|
|
429
|
-
*
|
|
600
|
+
* materialized view of the records (with derived attributes applied). Object
|
|
601
|
+
* arrays without derived attributes are reused to avoid a second pointer
|
|
602
|
+
* array for large datasets.
|
|
430
603
|
* This is an exact extraction of the historical PivotTableUI behavior.
|
|
431
604
|
*/
|
|
432
605
|
function materializeData(data, derivedAttributes) {
|
|
433
606
|
var attrValues = {};
|
|
434
|
-
var
|
|
607
|
+
var canReuseInput = Array.isArray(data) && !Array.isArray(data[0]) && Object.keys(derivedAttributes || {}).length === 0;
|
|
608
|
+
var materializedInput = canReuseInput ? data : [];
|
|
435
609
|
var recordsProcessed = 0;
|
|
436
610
|
__WEBPACK_IMPORTED_MODULE_0__Utilities__["a" /* PivotData */].forEachRecord(data, derivedAttributes || {}, function (record) {
|
|
437
|
-
|
|
611
|
+
if (!canReuseInput) {
|
|
612
|
+
materializedInput.push(record);
|
|
613
|
+
}
|
|
438
614
|
var _iteratorNormalCompletion = true;
|
|
439
615
|
var _didIteratorError = false;
|
|
440
616
|
var _iteratorError = undefined;
|
|
@@ -500,14 +676,10 @@ function computePivotState(materialized, config) {
|
|
|
500
676
|
*/
|
|
501
677
|
function serializePivotData(pivotData, materialized) {
|
|
502
678
|
var serializeCell = function serializeCell(cell) {
|
|
503
|
-
|
|
504
|
-
pivotData.aggregations.forEach(function (agg) {
|
|
679
|
+
return pivotData.aggregations.map(function (agg) {
|
|
505
680
|
var instance = cell.getInstance(agg.key);
|
|
506
|
-
|
|
507
|
-
values[agg.key] = instance.value();
|
|
508
|
-
}
|
|
681
|
+
return instance ? instance.value() : null;
|
|
509
682
|
});
|
|
510
|
-
return { values: values };
|
|
511
683
|
};
|
|
512
684
|
|
|
513
685
|
var tree = {};
|
|
@@ -543,11 +715,203 @@ function serializePivotData(pivotData, materialized) {
|
|
|
543
715
|
return Object.assign({}, agg);
|
|
544
716
|
}),
|
|
545
717
|
attrValues: materialized.attrValues,
|
|
546
|
-
materializedInput: materialized.materializedInput,
|
|
547
718
|
totalRecords: materialized.totalRecords
|
|
548
719
|
};
|
|
549
720
|
}
|
|
550
721
|
|
|
722
|
+
function getPivotViewportRowCount(precomputed, columnMode) {
|
|
723
|
+
var aggregations = precomputed.aggregations || [];
|
|
724
|
+
var expandAggregations = aggregations.length > 1 && !columnMode;
|
|
725
|
+
var rowKeyCount = precomputed.rowKeys.length || (expandAggregations ? 1 : 0);
|
|
726
|
+
return rowKeyCount * (expandAggregations ? aggregations.length : 1);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function getPivotViewportColumnCount(precomputed, columnMode) {
|
|
730
|
+
var colKeys = precomputed.colKeys || [];
|
|
731
|
+
if (!columnMode) {
|
|
732
|
+
return colKeys.length;
|
|
733
|
+
}
|
|
734
|
+
var aggregations = precomputed.aggregations || [];
|
|
735
|
+
var baseColumnCount = colKeys.length || 1;
|
|
736
|
+
return baseColumnCount * aggregations.length;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// A high-cardinality field on both axes creates a sparse matrix. Natural row
|
|
740
|
+
// and column sorting can put every populated cell outside the first viewport,
|
|
741
|
+
// making a correctly computed table look empty. For extremely sparse virtual
|
|
742
|
+
// tables, keep every column but order it by the first sorted row that contains
|
|
743
|
+
// a value. Dense pivots keep their normal column order.
|
|
744
|
+
function alignSparseColumnsToRows(precomputed) {
|
|
745
|
+
var rowKeys = precomputed.rowKeys || [];
|
|
746
|
+
var colKeys = precomputed.colKeys || [];
|
|
747
|
+
if (rowKeys.length <= VIRTUAL_ROW_THRESHOLD || colKeys.length <= VIRTUAL_COLUMN_THRESHOLD) {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
var maxSparseCells = Math.max(rowKeys.length, colKeys.length) * SPARSE_CELL_FACTOR;
|
|
752
|
+
var nonEmptyCells = 0;
|
|
753
|
+
var columnIndexByFlatKey = {};
|
|
754
|
+
colKeys.forEach(function (colKey, index) {
|
|
755
|
+
columnIndexByFlatKey[colKey.join(FLAT_KEY_SEPARATOR)] = index;
|
|
756
|
+
});
|
|
757
|
+
var seenColumnIndexes = {};
|
|
758
|
+
var orderedColumnIndexes = [];
|
|
759
|
+
|
|
760
|
+
var _loop = function _loop(rowIndex) {
|
|
761
|
+
var flatRowKey = rowKeys[rowIndex].join(FLAT_KEY_SEPARATOR);
|
|
762
|
+
var rowBranch = (precomputed.tree || {})[flatRowKey] || {};
|
|
763
|
+
var rowColumnIndexes = [];
|
|
764
|
+
var flatColumnKeys = Object.keys(rowBranch);
|
|
765
|
+
nonEmptyCells += flatColumnKeys.length;
|
|
766
|
+
if (nonEmptyCells > maxSparseCells) {
|
|
767
|
+
return {
|
|
768
|
+
v: false
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
flatColumnKeys.forEach(function (flatColumnKey) {
|
|
772
|
+
var columnIndex = columnIndexByFlatKey[flatColumnKey];
|
|
773
|
+
if (typeof columnIndex === 'number' && !seenColumnIndexes[columnIndex]) {
|
|
774
|
+
seenColumnIndexes[columnIndex] = true;
|
|
775
|
+
rowColumnIndexes.push(columnIndex);
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
rowColumnIndexes.sort(function (a, b) {
|
|
779
|
+
return a - b;
|
|
780
|
+
});
|
|
781
|
+
rowColumnIndexes.forEach(function (columnIndex) {
|
|
782
|
+
return orderedColumnIndexes.push(columnIndex);
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
for (var rowIndex = 0; rowIndex < rowKeys.length; rowIndex++) {
|
|
787
|
+
var _ret = _loop(rowIndex);
|
|
788
|
+
|
|
789
|
+
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
if (nonEmptyCells === 0) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
colKeys.forEach(function (colKey, index) {
|
|
796
|
+
if (!seenColumnIndexes[index]) {
|
|
797
|
+
orderedColumnIndexes.push(index);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
precomputed.colKeys = orderedColumnIndexes.map(function (index) {
|
|
801
|
+
return colKeys[index];
|
|
802
|
+
});
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/*
|
|
807
|
+
* Creates the small result kept on the main thread for a virtualized table.
|
|
808
|
+
* Cell and row-total values stay in the worker and are transferred only for
|
|
809
|
+
* the visible viewport. Column totals remain here because the totals footer
|
|
810
|
+
* is always visible.
|
|
811
|
+
*/
|
|
812
|
+
function createVirtualPivotSummary(precomputed, columnMode) {
|
|
813
|
+
return {
|
|
814
|
+
rowKeys: [],
|
|
815
|
+
colKeys: precomputed.colKeys,
|
|
816
|
+
tree: {},
|
|
817
|
+
rowTotals: {},
|
|
818
|
+
colTotals: {},
|
|
819
|
+
allTotal: precomputed.allTotal,
|
|
820
|
+
aggregations: precomputed.aggregations,
|
|
821
|
+
attrValues: precomputed.attrValues,
|
|
822
|
+
totalRecords: precomputed.totalRecords,
|
|
823
|
+
totalRows: getPivotViewportRowCount(precomputed, columnMode),
|
|
824
|
+
totalColumns: getPivotViewportColumnCount(precomputed, columnMode),
|
|
825
|
+
virtualized: true
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Build only the rows requested by a virtualized table. The result contains
|
|
830
|
+
// plain data and can cross the worker boundary without cloning the full pivot.
|
|
831
|
+
function computePivotViewport(precomputed, start, end, columnMode) {
|
|
832
|
+
var columnStart = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
833
|
+
var columnEnd = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : Number.MAX_SAFE_INTEGER;
|
|
834
|
+
|
|
835
|
+
var aggregations = precomputed.aggregations || [];
|
|
836
|
+
var expandAggregations = aggregations.length > 1 && !columnMode;
|
|
837
|
+
var rowKeys = expandAggregations && precomputed.rowKeys.length === 0 ? [[]] : precomputed.rowKeys;
|
|
838
|
+
var totalRows = getPivotViewportRowCount(precomputed, columnMode);
|
|
839
|
+
var first = Math.max(0, Math.min(totalRows, Math.floor(start)));
|
|
840
|
+
var last = Math.max(first, Math.min(totalRows, Math.floor(end)));
|
|
841
|
+
var colKeys = precomputed.colKeys || [];
|
|
842
|
+
var baseColKeys = columnMode && colKeys.length === 0 ? [[]] : colKeys;
|
|
843
|
+
var totalColumns = getPivotViewportColumnCount(precomputed, columnMode);
|
|
844
|
+
var firstColumn = Math.max(0, Math.min(totalColumns, Math.floor(columnStart)));
|
|
845
|
+
var lastColumn = Math.max(firstColumn, Math.min(totalColumns, Math.floor(columnEnd)));
|
|
846
|
+
var visibleFlatColumnKeys = {};
|
|
847
|
+
for (var column = firstColumn; column < lastColumn; column++) {
|
|
848
|
+
var baseColumnIndex = columnMode ? Math.floor(column / aggregations.length) : column;
|
|
849
|
+
var colKey = baseColKeys[baseColumnIndex];
|
|
850
|
+
if (colKey) {
|
|
851
|
+
visibleFlatColumnKeys[colKey.join(FLAT_KEY_SEPARATOR)] = true;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
var selectVisibleCells = function selectVisibleCells(source) {
|
|
855
|
+
if (!source) {
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
var selected = {};
|
|
859
|
+
Object.keys(visibleFlatColumnKeys).forEach(function (flatColKey) {
|
|
860
|
+
if (flatColKey in source) {
|
|
861
|
+
selected[flatColKey] = source[flatColKey];
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
return selected;
|
|
865
|
+
};
|
|
866
|
+
var rows = [];
|
|
867
|
+
|
|
868
|
+
for (var index = first; index < last; index++) {
|
|
869
|
+
var rowIndex = expandAggregations ? Math.floor(index / aggregations.length) : index;
|
|
870
|
+
var rowKey = rowKeys[rowIndex];
|
|
871
|
+
var aggregation = expandAggregations ? aggregations[index % aggregations.length] : aggregations[0];
|
|
872
|
+
var flatRowKey = rowKey.join(FLAT_KEY_SEPARATOR);
|
|
873
|
+
rows.push({
|
|
874
|
+
displayKey: expandAggregations ? rowKey.concat([aggregation.label || aggregation.aggregatorName]) : rowKey,
|
|
875
|
+
actualKey: rowKey,
|
|
876
|
+
aggregationKey: aggregation.key,
|
|
877
|
+
spans: [],
|
|
878
|
+
cells: precomputed.tree ? selectVisibleCells(precomputed.tree[flatRowKey] || {}) : null,
|
|
879
|
+
rowTotal: precomputed.rowTotals ? precomputed.rowTotals[flatRowKey] || null : null
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// Merge repeated row labels inside this window. Doing it here keeps the
|
|
884
|
+
// prefix comparisons off the main thread for worker-backed tables.
|
|
885
|
+
var columns = rows.length > 0 ? rows[0].displayKey.length : 0;
|
|
886
|
+
for (var _column = 0; _column < columns; _column++) {
|
|
887
|
+
var runStart = 0;
|
|
888
|
+
for (var _index = 1; _index <= rows.length; _index++) {
|
|
889
|
+
var samePrefix = _index < rows.length;
|
|
890
|
+
for (var part = 0; samePrefix && part <= _column; part++) {
|
|
891
|
+
samePrefix = rows[_index - 1].displayKey[part] === rows[_index].displayKey[part];
|
|
892
|
+
}
|
|
893
|
+
if (!samePrefix) {
|
|
894
|
+
rows[runStart].spans[_column] = _index - runStart;
|
|
895
|
+
for (var merged = runStart + 1; merged < _index; merged++) {
|
|
896
|
+
rows[merged].spans[_column] = -1;
|
|
897
|
+
}
|
|
898
|
+
runStart = _index;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
return {
|
|
904
|
+
start: first,
|
|
905
|
+
end: last,
|
|
906
|
+
totalRows: totalRows,
|
|
907
|
+
columnStart: firstColumn,
|
|
908
|
+
columnEnd: lastColumn,
|
|
909
|
+
totalColumns: totalColumns,
|
|
910
|
+
colTotals: selectVisibleCells(precomputed.colTotals || {}),
|
|
911
|
+
rows: rows
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
|
|
551
915
|
/*
|
|
552
916
|
* Sorters containing functions cannot be structured-cloned into a worker.
|
|
553
917
|
* Returns true when the sorters prop itself, or any of its entries, is a
|
|
@@ -601,7 +965,11 @@ function createWorkerConfig(props) {
|
|
|
601
965
|
rowOrder: props.rowOrder,
|
|
602
966
|
colOrder: props.colOrder,
|
|
603
967
|
rowSorts: props.rowSorts,
|
|
604
|
-
colSorts: props.colSorts
|
|
968
|
+
colSorts: props.colSorts,
|
|
969
|
+
virtualizeRows: Boolean(props.virtualizeRows),
|
|
970
|
+
rendererName: props.rendererName,
|
|
971
|
+
aggregationDisplayMode: props.tableOptions && props.tableOptions.aggregationDisplayMode,
|
|
972
|
+
sortersRequireMainThread: sortersHaveFunctions(props.sorters)
|
|
605
973
|
};
|
|
606
974
|
}
|
|
607
975
|
|
|
@@ -635,6 +1003,21 @@ function canComputeInWorker(props) {
|
|
|
635
1003
|
return false;
|
|
636
1004
|
}
|
|
637
1005
|
|
|
1006
|
+
if (Object.keys(props.derivedAttributes || {}).length > 0) {
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
var requestedAggregatorNames = Array.isArray(props.aggregations) ? props.aggregations.map(function (aggregation) {
|
|
1011
|
+
return aggregation.aggregatorName;
|
|
1012
|
+
}) : [props.aggregatorName || 'Count'];
|
|
1013
|
+
var aggregatorMap = props.aggregators || __WEBPACK_IMPORTED_MODULE_0__Utilities__["a" /* PivotData */].defaultProps.aggregators;
|
|
1014
|
+
var usesCustomAggregator = requestedAggregatorNames.some(function (name) {
|
|
1015
|
+
return typeof aggregatorMap[name] !== 'undefined' && aggregatorMap[name] !== __WEBPACK_IMPORTED_MODULE_0__Utilities__["a" /* PivotData */].defaultProps.aggregators[name];
|
|
1016
|
+
});
|
|
1017
|
+
if (usesCustomAggregator) {
|
|
1018
|
+
return false;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
638
1021
|
return true;
|
|
639
1022
|
}
|
|
640
1023
|
|
|
@@ -1361,11 +1744,9 @@ var AggregatorCell = function () {
|
|
|
1361
1744
|
_createClass(AggregatorCell, [{
|
|
1362
1745
|
key: 'push',
|
|
1363
1746
|
value: function push(record) {
|
|
1364
|
-
var
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
_this.instances[key].push(record);
|
|
1368
|
-
});
|
|
1747
|
+
for (var key in this.instances) {
|
|
1748
|
+
this.instances[key].push(record);
|
|
1749
|
+
}
|
|
1369
1750
|
}
|
|
1370
1751
|
}, {
|
|
1371
1752
|
key: 'getInstance',
|
|
@@ -1374,8 +1755,13 @@ var AggregatorCell = function () {
|
|
|
1374
1755
|
if (targetKey && this.instances[targetKey]) {
|
|
1375
1756
|
return this.instances[targetKey];
|
|
1376
1757
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1758
|
+
if (this.instances[this.primaryKey]) {
|
|
1759
|
+
return this.instances[this.primaryKey];
|
|
1760
|
+
}
|
|
1761
|
+
for (var _key2 in this.instances) {
|
|
1762
|
+
return this.instances[_key2];
|
|
1763
|
+
}
|
|
1764
|
+
return null;
|
|
1379
1765
|
}
|
|
1380
1766
|
}]);
|
|
1381
1767
|
|
|
@@ -1436,6 +1822,7 @@ var dayNamesEn = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
|
1436
1822
|
var zeroPad = function zeroPad(number) {
|
|
1437
1823
|
return ('0' + number).substr(-2, 2);
|
|
1438
1824
|
}; // eslint-disable-line no-magic-numbers
|
|
1825
|
+
var FLAT_KEY_SEPARATOR = String.fromCharCode(0);
|
|
1439
1826
|
|
|
1440
1827
|
var derivers = {
|
|
1441
1828
|
bin: function bin(col, binWidth) {
|
|
@@ -1488,7 +1875,7 @@ Data Model class
|
|
|
1488
1875
|
|
|
1489
1876
|
var PivotData = function () {
|
|
1490
1877
|
function PivotData() {
|
|
1491
|
-
var
|
|
1878
|
+
var _this = this;
|
|
1492
1879
|
|
|
1493
1880
|
var inputProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1494
1881
|
|
|
@@ -1499,9 +1886,11 @@ var PivotData = function () {
|
|
|
1499
1886
|
|
|
1500
1887
|
this.aggregations = this.normalizeAggregations();
|
|
1501
1888
|
this.aggregationKeyLookup = {};
|
|
1502
|
-
this.
|
|
1503
|
-
|
|
1504
|
-
|
|
1889
|
+
this.aggregationIndexLookup = {};
|
|
1890
|
+
this.aggregations.forEach(function (agg, index) {
|
|
1891
|
+
_this.aggregationIndexLookup[agg.key] = index;
|
|
1892
|
+
if (!(agg.aggregatorName in _this.aggregationKeyLookup)) {
|
|
1893
|
+
_this.aggregationKeyLookup[agg.aggregatorName] = agg.key;
|
|
1505
1894
|
}
|
|
1506
1895
|
});
|
|
1507
1896
|
if (this.aggregations.length === 0) {
|
|
@@ -1527,8 +1916,8 @@ var PivotData = function () {
|
|
|
1527
1916
|
}
|
|
1528
1917
|
|
|
1529
1918
|
PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, function (record) {
|
|
1530
|
-
if (
|
|
1531
|
-
|
|
1919
|
+
if (_this.filter(record)) {
|
|
1920
|
+
_this.processRecord(record);
|
|
1532
1921
|
}
|
|
1533
1922
|
});
|
|
1534
1923
|
}
|
|
@@ -1544,21 +1933,22 @@ var PivotData = function () {
|
|
|
1544
1933
|
_createClass(PivotData, [{
|
|
1545
1934
|
key: 'hydrateFromPrecomputed',
|
|
1546
1935
|
value: function hydrateFromPrecomputed(precomputed) {
|
|
1547
|
-
var
|
|
1936
|
+
var _this2 = this;
|
|
1548
1937
|
|
|
1549
1938
|
// One real aggregator instance per aggregation provides `format()` and
|
|
1550
1939
|
// `numInputs` for every hydrated stub cell.
|
|
1551
1940
|
var formatSources = {};
|
|
1552
1941
|
this.aggregations.forEach(function (agg) {
|
|
1553
|
-
formatSources[agg.key] =
|
|
1942
|
+
formatSources[agg.key] = _this2.aggregatorFactories[agg.key](_this2, [], []);
|
|
1554
1943
|
});
|
|
1944
|
+
this.precomputedFormatSources = formatSources;
|
|
1555
1945
|
|
|
1556
1946
|
var makeCell = function makeCell(serializedCell) {
|
|
1557
|
-
var values = serializedCell && serializedCell.values || {};
|
|
1947
|
+
var values = Array.isArray(serializedCell) ? serializedCell : serializedCell && serializedCell.values || {};
|
|
1558
1948
|
var instances = {};
|
|
1559
|
-
|
|
1949
|
+
_this2.aggregations.forEach(function (agg, index) {
|
|
1560
1950
|
var source = formatSources[agg.key];
|
|
1561
|
-
var _value = values[agg.key];
|
|
1951
|
+
var _value = Array.isArray(values) ? values[index] : values[agg.key];
|
|
1562
1952
|
instances[agg.key] = {
|
|
1563
1953
|
push: function push() {},
|
|
1564
1954
|
value: function value() {
|
|
@@ -1572,7 +1962,7 @@ var PivotData = function () {
|
|
|
1572
1962
|
outlet: source.outlet
|
|
1573
1963
|
};
|
|
1574
1964
|
});
|
|
1575
|
-
return new AggregatorCell(instances,
|
|
1965
|
+
return new AggregatorCell(instances, _this2.primaryAggregation.key);
|
|
1576
1966
|
};
|
|
1577
1967
|
|
|
1578
1968
|
var hydrateTotals = function hydrateTotals(source, target) {
|
|
@@ -1593,8 +1983,8 @@ var PivotData = function () {
|
|
|
1593
1983
|
hydrateTotals(precomputed.colTotals, this.colTotals);
|
|
1594
1984
|
this.tree = {};
|
|
1595
1985
|
Object.keys(precomputed.tree || {}).forEach(function (flatRowKey) {
|
|
1596
|
-
|
|
1597
|
-
hydrateTotals(precomputed.tree[flatRowKey],
|
|
1986
|
+
_this2.tree[flatRowKey] = {};
|
|
1987
|
+
hydrateTotals(precomputed.tree[flatRowKey], _this2.tree[flatRowKey]);
|
|
1598
1988
|
});
|
|
1599
1989
|
this.allTotal = makeCell(precomputed.allTotal);
|
|
1600
1990
|
|
|
@@ -1602,6 +1992,40 @@ var PivotData = function () {
|
|
|
1602
1992
|
// thread when a sorter could not cross the worker boundary (functions).
|
|
1603
1993
|
this.sorted = !sortersHaveFunctions(this.props.sorters);
|
|
1604
1994
|
}
|
|
1995
|
+
|
|
1996
|
+
// Virtualized worker results keep cell values in the worker. Convert one
|
|
1997
|
+
// serialized viewport cell into an aggregator only when that cell is about
|
|
1998
|
+
// to render, instead of hydrating every pivot cell on the main thread.
|
|
1999
|
+
|
|
2000
|
+
}, {
|
|
2001
|
+
key: 'getPrecomputedAggregator',
|
|
2002
|
+
value: function getPrecomputedAggregator(serializedCell, aggregationKey) {
|
|
2003
|
+
if (!serializedCell) {
|
|
2004
|
+
return PivotData.emptyAggregator;
|
|
2005
|
+
}
|
|
2006
|
+
var resolvedKey = aggregationKey;
|
|
2007
|
+
if (resolvedKey && !(resolvedKey in this.aggregatorFactories) && this.aggregationKeyLookup[resolvedKey]) {
|
|
2008
|
+
resolvedKey = this.aggregationKeyLookup[resolvedKey];
|
|
2009
|
+
}
|
|
2010
|
+
var source = this.precomputedFormatSources && this.precomputedFormatSources[resolvedKey];
|
|
2011
|
+
if (!source) {
|
|
2012
|
+
return PivotData.emptyAggregator;
|
|
2013
|
+
}
|
|
2014
|
+
var values = Array.isArray(serializedCell) ? serializedCell : serializedCell.values || {};
|
|
2015
|
+
var _value2 = Array.isArray(values) ? values[this.aggregationIndexLookup[resolvedKey]] : values[resolvedKey];
|
|
2016
|
+
return {
|
|
2017
|
+
push: function push() {},
|
|
2018
|
+
value: function value() {
|
|
2019
|
+
return _value2;
|
|
2020
|
+
},
|
|
2021
|
+
format: function format(x) {
|
|
2022
|
+
return source.format(x);
|
|
2023
|
+
},
|
|
2024
|
+
|
|
2025
|
+
numInputs: source.numInputs,
|
|
2026
|
+
outlet: source.outlet
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
1605
2029
|
}, {
|
|
1606
2030
|
key: 'filter',
|
|
1607
2031
|
value: function filter(record) {
|
|
@@ -1615,10 +2039,10 @@ var PivotData = function () {
|
|
|
1615
2039
|
}, {
|
|
1616
2040
|
key: 'forEachMatchingRecord',
|
|
1617
2041
|
value: function forEachMatchingRecord(criteria, callback) {
|
|
1618
|
-
var
|
|
2042
|
+
var _this3 = this;
|
|
1619
2043
|
|
|
1620
2044
|
return PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, function (record) {
|
|
1621
|
-
if (!
|
|
2045
|
+
if (!_this3.filter(record)) {
|
|
1622
2046
|
return;
|
|
1623
2047
|
}
|
|
1624
2048
|
for (var k in criteria) {
|
|
@@ -1633,7 +2057,7 @@ var PivotData = function () {
|
|
|
1633
2057
|
}, {
|
|
1634
2058
|
key: 'arrSort',
|
|
1635
2059
|
value: function arrSort(attrs) {
|
|
1636
|
-
var
|
|
2060
|
+
var _this4 = this;
|
|
1637
2061
|
|
|
1638
2062
|
var a = void 0;
|
|
1639
2063
|
var sortersArr = function () {
|
|
@@ -1646,7 +2070,7 @@ var PivotData = function () {
|
|
|
1646
2070
|
for (var _iterator2 = Array.from(attrs)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
1647
2071
|
a = _step2.value;
|
|
1648
2072
|
|
|
1649
|
-
result.push(getSort(
|
|
2073
|
+
result.push(getSort(_this4.props.sorters, a));
|
|
1650
2074
|
}
|
|
1651
2075
|
} catch (err) {
|
|
1652
2076
|
_didIteratorError2 = true;
|
|
@@ -1701,12 +2125,12 @@ var PivotData = function () {
|
|
|
1701
2125
|
}, {
|
|
1702
2126
|
key: 'sortKeys',
|
|
1703
2127
|
value: function sortKeys() {
|
|
1704
|
-
var
|
|
2128
|
+
var _this5 = this;
|
|
1705
2129
|
|
|
1706
2130
|
if (!this.sorted) {
|
|
1707
2131
|
this.sorted = true;
|
|
1708
2132
|
var v = function v(r, c) {
|
|
1709
|
-
return
|
|
2133
|
+
return _this5.getAggregator(r, c).value();
|
|
1710
2134
|
};
|
|
1711
2135
|
|
|
1712
2136
|
// Handle per-row sorting
|
|
@@ -1714,11 +2138,11 @@ var PivotData = function () {
|
|
|
1714
2138
|
var rowSorts = this.props.rowSorts;
|
|
1715
2139
|
this.rowKeys.sort(function (a, b) {
|
|
1716
2140
|
// First, check if any sorted attribute has a difference
|
|
1717
|
-
for (var i = 0; i <
|
|
1718
|
-
var attr =
|
|
2141
|
+
for (var i = 0; i < _this5.props.rows.length; i++) {
|
|
2142
|
+
var attr = _this5.props.rows[i];
|
|
1719
2143
|
if (attr && rowSorts[attr]) {
|
|
1720
2144
|
var sortDir = rowSorts[attr] === 'ASC' ? 1 : -1;
|
|
1721
|
-
var sorter = getSort(
|
|
2145
|
+
var sorter = getSort(_this5.props.sorters, attr);
|
|
1722
2146
|
var comparison = sorter(a[i] || '', b[i] || '');
|
|
1723
2147
|
if (comparison !== 0) {
|
|
1724
2148
|
return sortDir * comparison;
|
|
@@ -1726,7 +2150,7 @@ var PivotData = function () {
|
|
|
1726
2150
|
}
|
|
1727
2151
|
}
|
|
1728
2152
|
// If sorted attributes are equal, use default sorting for remaining attributes
|
|
1729
|
-
return
|
|
2153
|
+
return _this5.arrSort(_this5.props.rows)(a, b);
|
|
1730
2154
|
});
|
|
1731
2155
|
} else {
|
|
1732
2156
|
// Use global row order
|
|
@@ -1751,11 +2175,11 @@ var PivotData = function () {
|
|
|
1751
2175
|
var colSorts = this.props.colSorts;
|
|
1752
2176
|
this.colKeys.sort(function (a, b) {
|
|
1753
2177
|
// First, check if any sorted attribute has a difference
|
|
1754
|
-
for (var i = 0; i <
|
|
1755
|
-
var attr =
|
|
2178
|
+
for (var i = 0; i < _this5.props.cols.length; i++) {
|
|
2179
|
+
var attr = _this5.props.cols[i];
|
|
1756
2180
|
if (attr && colSorts[attr]) {
|
|
1757
2181
|
var sortDir = colSorts[attr] === 'ASC' ? 1 : -1;
|
|
1758
|
-
var sorter = getSort(
|
|
2182
|
+
var sorter = getSort(_this5.props.sorters, attr);
|
|
1759
2183
|
var comparison = sorter(a[i] || '', b[i] || '');
|
|
1760
2184
|
if (comparison !== 0) {
|
|
1761
2185
|
return sortDir * comparison;
|
|
@@ -1763,7 +2187,7 @@ var PivotData = function () {
|
|
|
1763
2187
|
}
|
|
1764
2188
|
}
|
|
1765
2189
|
// If sorted attributes are equal, use default sorting for remaining attributes
|
|
1766
|
-
return
|
|
2190
|
+
return _this5.arrSort(_this5.props.cols)(a, b);
|
|
1767
2191
|
});
|
|
1768
2192
|
} else {
|
|
1769
2193
|
// Use global col order
|
|
@@ -1802,58 +2226,16 @@ var PivotData = function () {
|
|
|
1802
2226
|
// this code is called in a tight loop
|
|
1803
2227
|
var colKey = [];
|
|
1804
2228
|
var rowKey = [];
|
|
1805
|
-
var
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
try {
|
|
1810
|
-
for (var _iterator4 = Array.from(this.props.cols)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
1811
|
-
var x = _step4.value;
|
|
1812
|
-
|
|
1813
|
-
colKey.push(x in record ? record[x] : 'null');
|
|
1814
|
-
}
|
|
1815
|
-
} catch (err) {
|
|
1816
|
-
_didIteratorError4 = true;
|
|
1817
|
-
_iteratorError4 = err;
|
|
1818
|
-
} finally {
|
|
1819
|
-
try {
|
|
1820
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
|
1821
|
-
_iterator4.return();
|
|
1822
|
-
}
|
|
1823
|
-
} finally {
|
|
1824
|
-
if (_didIteratorError4) {
|
|
1825
|
-
throw _iteratorError4;
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
2229
|
+
for (var index = 0; index < this.props.cols.length; index += 1) {
|
|
2230
|
+
var x = this.props.cols[index];
|
|
2231
|
+
colKey.push(x in record ? record[x] : 'null');
|
|
1828
2232
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
var _iteratorError5 = undefined;
|
|
1833
|
-
|
|
1834
|
-
try {
|
|
1835
|
-
for (var _iterator5 = Array.from(this.props.rows)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
1836
|
-
var _x17 = _step5.value;
|
|
1837
|
-
|
|
1838
|
-
rowKey.push(_x17 in record ? record[_x17] : 'null');
|
|
1839
|
-
}
|
|
1840
|
-
} catch (err) {
|
|
1841
|
-
_didIteratorError5 = true;
|
|
1842
|
-
_iteratorError5 = err;
|
|
1843
|
-
} finally {
|
|
1844
|
-
try {
|
|
1845
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
|
1846
|
-
_iterator5.return();
|
|
1847
|
-
}
|
|
1848
|
-
} finally {
|
|
1849
|
-
if (_didIteratorError5) {
|
|
1850
|
-
throw _iteratorError5;
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
2233
|
+
for (var _index = 0; _index < this.props.rows.length; _index += 1) {
|
|
2234
|
+
var _x17 = this.props.rows[_index];
|
|
2235
|
+
rowKey.push(_x17 in record ? record[_x17] : 'null');
|
|
1853
2236
|
}
|
|
1854
|
-
|
|
1855
|
-
var
|
|
1856
|
-
var flatColKey = colKey.join(String.fromCharCode(0));
|
|
2237
|
+
var flatRowKey = rowKey.join(FLAT_KEY_SEPARATOR);
|
|
2238
|
+
var flatColKey = colKey.join(FLAT_KEY_SEPARATOR);
|
|
1857
2239
|
|
|
1858
2240
|
this.allTotal.push(record);
|
|
1859
2241
|
|
|
@@ -1902,8 +2284,8 @@ var PivotData = function () {
|
|
|
1902
2284
|
key: 'getAggregatorCell',
|
|
1903
2285
|
value: function getAggregatorCell(rowKey, colKey) {
|
|
1904
2286
|
var cell = void 0;
|
|
1905
|
-
var flatRowKey = rowKey.join(
|
|
1906
|
-
var flatColKey = colKey.join(
|
|
2287
|
+
var flatRowKey = rowKey.join(FLAT_KEY_SEPARATOR);
|
|
2288
|
+
var flatColKey = colKey.join(FLAT_KEY_SEPARATOR);
|
|
1907
2289
|
if (rowKey.length === 0 && colKey.length === 0) {
|
|
1908
2290
|
cell = this.allTotal;
|
|
1909
2291
|
} else if (rowKey.length === 0) {
|
|
@@ -2007,25 +2389,25 @@ var PivotData = function () {
|
|
|
2007
2389
|
}, {
|
|
2008
2390
|
key: 'buildAggregatorFactories',
|
|
2009
2391
|
value: function buildAggregatorFactories() {
|
|
2010
|
-
var
|
|
2392
|
+
var _this6 = this;
|
|
2011
2393
|
|
|
2012
2394
|
var factories = {};
|
|
2013
2395
|
this.aggregations.forEach(function (agg) {
|
|
2014
|
-
if (!(agg.aggregatorName in
|
|
2396
|
+
if (!(agg.aggregatorName in _this6.props.aggregators)) {
|
|
2015
2397
|
throw new Error('unknown aggregator ' + agg.aggregatorName);
|
|
2016
2398
|
}
|
|
2017
|
-
factories[agg.key] =
|
|
2399
|
+
factories[agg.key] = _this6.props.aggregators[agg.aggregatorName](agg.vals);
|
|
2018
2400
|
});
|
|
2019
2401
|
return factories;
|
|
2020
2402
|
}
|
|
2021
2403
|
}, {
|
|
2022
2404
|
key: 'createAggregatorCell',
|
|
2023
2405
|
value: function createAggregatorCell(rowKey, colKey) {
|
|
2024
|
-
var
|
|
2406
|
+
var _this7 = this;
|
|
2025
2407
|
|
|
2026
2408
|
var instances = {};
|
|
2027
2409
|
this.aggregations.forEach(function (agg) {
|
|
2028
|
-
instances[agg.key] =
|
|
2410
|
+
instances[agg.key] = _this7.aggregatorFactories[agg.key](_this7, rowKey, colKey);
|
|
2029
2411
|
});
|
|
2030
2412
|
return new AggregatorCell(instances, this.primaryAggregation.key);
|
|
2031
2413
|
}
|
|
@@ -2068,97 +2450,23 @@ PivotData.forEachRecord = function (input, derivedAttributes, f) {
|
|
|
2068
2450
|
} else if (Array.isArray(input)) {
|
|
2069
2451
|
if (Array.isArray(input[0])) {
|
|
2070
2452
|
// array of arrays
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
var
|
|
2074
|
-
|
|
2075
|
-
var
|
|
2076
|
-
|
|
2077
|
-
try {
|
|
2078
|
-
for (var _iterator6 = Object.keys(input || {})[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
2079
|
-
var i = _step6.value;
|
|
2080
|
-
|
|
2081
|
-
var compactRecord = input[i];
|
|
2082
|
-
if (i > 0) {
|
|
2083
|
-
record = {};
|
|
2084
|
-
var _iteratorNormalCompletion7 = true;
|
|
2085
|
-
var _didIteratorError7 = false;
|
|
2086
|
-
var _iteratorError7 = undefined;
|
|
2087
|
-
|
|
2088
|
-
try {
|
|
2089
|
-
for (var _iterator7 = Object.keys(input[0] || {})[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
|
|
2090
|
-
var j = _step7.value;
|
|
2091
|
-
|
|
2092
|
-
var k = input[0][j];
|
|
2093
|
-
record[k] = compactRecord[j];
|
|
2094
|
-
}
|
|
2095
|
-
} catch (err) {
|
|
2096
|
-
_didIteratorError7 = true;
|
|
2097
|
-
_iteratorError7 = err;
|
|
2098
|
-
} finally {
|
|
2099
|
-
try {
|
|
2100
|
-
if (!_iteratorNormalCompletion7 && _iterator7.return) {
|
|
2101
|
-
_iterator7.return();
|
|
2102
|
-
}
|
|
2103
|
-
} finally {
|
|
2104
|
-
if (_didIteratorError7) {
|
|
2105
|
-
throw _iteratorError7;
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
|
|
2110
|
-
result.push(addRecord(record));
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
} catch (err) {
|
|
2114
|
-
_didIteratorError6 = true;
|
|
2115
|
-
_iteratorError6 = err;
|
|
2116
|
-
} finally {
|
|
2117
|
-
try {
|
|
2118
|
-
if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
|
2119
|
-
_iterator6.return();
|
|
2120
|
-
}
|
|
2121
|
-
} finally {
|
|
2122
|
-
if (_didIteratorError6) {
|
|
2123
|
-
throw _iteratorError6;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2453
|
+
var headers = input[0] || [];
|
|
2454
|
+
for (var i = 1; i < input.length; i += 1) {
|
|
2455
|
+
var compactRecord = input[i];
|
|
2456
|
+
record = {};
|
|
2457
|
+
for (var j = 0; j < headers.length; j += 1) {
|
|
2458
|
+
record[headers[j]] = compactRecord[j];
|
|
2126
2459
|
}
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2460
|
+
addRecord(record);
|
|
2461
|
+
}
|
|
2462
|
+
return null;
|
|
2130
2463
|
}
|
|
2131
2464
|
|
|
2132
2465
|
// array of objects
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
var _iteratorError8 = undefined;
|
|
2138
|
-
|
|
2139
|
-
try {
|
|
2140
|
-
for (var _iterator8 = Array.from(input)[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
|
2141
|
-
record = _step8.value;
|
|
2142
|
-
|
|
2143
|
-
result1.push(addRecord(record));
|
|
2144
|
-
}
|
|
2145
|
-
} catch (err) {
|
|
2146
|
-
_didIteratorError8 = true;
|
|
2147
|
-
_iteratorError8 = err;
|
|
2148
|
-
} finally {
|
|
2149
|
-
try {
|
|
2150
|
-
if (!_iteratorNormalCompletion8 && _iterator8.return) {
|
|
2151
|
-
_iterator8.return();
|
|
2152
|
-
}
|
|
2153
|
-
} finally {
|
|
2154
|
-
if (_didIteratorError8) {
|
|
2155
|
-
throw _iteratorError8;
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
return result1;
|
|
2161
|
-
}();
|
|
2466
|
+
for (var _i = 0; _i < input.length; _i += 1) {
|
|
2467
|
+
addRecord(input[_i]);
|
|
2468
|
+
}
|
|
2469
|
+
return null;
|
|
2162
2470
|
}
|
|
2163
2471
|
throw new Error('unknown input format');
|
|
2164
2472
|
};
|