@hrforte/react-pivottable 2.2.1 → 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 +145 -48
- package/dist/PivotTableUI.js.map +1 -1
- package/dist/TableRenderers.js +629 -118
- 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 +42 -3
- package/dist/__tests__/PivotTableUI-processing-test.js.map +1 -1
- package/dist/__tests__/PivotTableUI-rerender-test.js +314 -0
- package/dist/__tests__/PivotTableUI-rerender-test.js.map +1 -0
- 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 +510 -201
- package/dist/pivotCompute.js +238 -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 +277 -235
- 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
|
|
|
@@ -634,6 +1002,22 @@ function canComputeInWorker(props) {
|
|
|
634
1002
|
if (!Array.isArray(data) || data.length < threshold) {
|
|
635
1003
|
return false;
|
|
636
1004
|
}
|
|
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
|
+
|
|
637
1021
|
return true;
|
|
638
1022
|
}
|
|
639
1023
|
|
|
@@ -1360,11 +1744,9 @@ var AggregatorCell = function () {
|
|
|
1360
1744
|
_createClass(AggregatorCell, [{
|
|
1361
1745
|
key: 'push',
|
|
1362
1746
|
value: function push(record) {
|
|
1363
|
-
var
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
_this.instances[key].push(record);
|
|
1367
|
-
});
|
|
1747
|
+
for (var key in this.instances) {
|
|
1748
|
+
this.instances[key].push(record);
|
|
1749
|
+
}
|
|
1368
1750
|
}
|
|
1369
1751
|
}, {
|
|
1370
1752
|
key: 'getInstance',
|
|
@@ -1373,8 +1755,13 @@ var AggregatorCell = function () {
|
|
|
1373
1755
|
if (targetKey && this.instances[targetKey]) {
|
|
1374
1756
|
return this.instances[targetKey];
|
|
1375
1757
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
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;
|
|
1378
1765
|
}
|
|
1379
1766
|
}]);
|
|
1380
1767
|
|
|
@@ -1435,6 +1822,7 @@ var dayNamesEn = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
|
1435
1822
|
var zeroPad = function zeroPad(number) {
|
|
1436
1823
|
return ('0' + number).substr(-2, 2);
|
|
1437
1824
|
}; // eslint-disable-line no-magic-numbers
|
|
1825
|
+
var FLAT_KEY_SEPARATOR = String.fromCharCode(0);
|
|
1438
1826
|
|
|
1439
1827
|
var derivers = {
|
|
1440
1828
|
bin: function bin(col, binWidth) {
|
|
@@ -1487,7 +1875,7 @@ Data Model class
|
|
|
1487
1875
|
|
|
1488
1876
|
var PivotData = function () {
|
|
1489
1877
|
function PivotData() {
|
|
1490
|
-
var
|
|
1878
|
+
var _this = this;
|
|
1491
1879
|
|
|
1492
1880
|
var inputProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1493
1881
|
|
|
@@ -1498,9 +1886,11 @@ var PivotData = function () {
|
|
|
1498
1886
|
|
|
1499
1887
|
this.aggregations = this.normalizeAggregations();
|
|
1500
1888
|
this.aggregationKeyLookup = {};
|
|
1501
|
-
this.
|
|
1502
|
-
|
|
1503
|
-
|
|
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;
|
|
1504
1894
|
}
|
|
1505
1895
|
});
|
|
1506
1896
|
if (this.aggregations.length === 0) {
|
|
@@ -1526,8 +1916,8 @@ var PivotData = function () {
|
|
|
1526
1916
|
}
|
|
1527
1917
|
|
|
1528
1918
|
PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, function (record) {
|
|
1529
|
-
if (
|
|
1530
|
-
|
|
1919
|
+
if (_this.filter(record)) {
|
|
1920
|
+
_this.processRecord(record);
|
|
1531
1921
|
}
|
|
1532
1922
|
});
|
|
1533
1923
|
}
|
|
@@ -1543,21 +1933,22 @@ var PivotData = function () {
|
|
|
1543
1933
|
_createClass(PivotData, [{
|
|
1544
1934
|
key: 'hydrateFromPrecomputed',
|
|
1545
1935
|
value: function hydrateFromPrecomputed(precomputed) {
|
|
1546
|
-
var
|
|
1936
|
+
var _this2 = this;
|
|
1547
1937
|
|
|
1548
1938
|
// One real aggregator instance per aggregation provides `format()` and
|
|
1549
1939
|
// `numInputs` for every hydrated stub cell.
|
|
1550
1940
|
var formatSources = {};
|
|
1551
1941
|
this.aggregations.forEach(function (agg) {
|
|
1552
|
-
formatSources[agg.key] =
|
|
1942
|
+
formatSources[agg.key] = _this2.aggregatorFactories[agg.key](_this2, [], []);
|
|
1553
1943
|
});
|
|
1944
|
+
this.precomputedFormatSources = formatSources;
|
|
1554
1945
|
|
|
1555
1946
|
var makeCell = function makeCell(serializedCell) {
|
|
1556
|
-
var values = serializedCell && serializedCell.values || {};
|
|
1947
|
+
var values = Array.isArray(serializedCell) ? serializedCell : serializedCell && serializedCell.values || {};
|
|
1557
1948
|
var instances = {};
|
|
1558
|
-
|
|
1949
|
+
_this2.aggregations.forEach(function (agg, index) {
|
|
1559
1950
|
var source = formatSources[agg.key];
|
|
1560
|
-
var _value = values[agg.key];
|
|
1951
|
+
var _value = Array.isArray(values) ? values[index] : values[agg.key];
|
|
1561
1952
|
instances[agg.key] = {
|
|
1562
1953
|
push: function push() {},
|
|
1563
1954
|
value: function value() {
|
|
@@ -1571,7 +1962,7 @@ var PivotData = function () {
|
|
|
1571
1962
|
outlet: source.outlet
|
|
1572
1963
|
};
|
|
1573
1964
|
});
|
|
1574
|
-
return new AggregatorCell(instances,
|
|
1965
|
+
return new AggregatorCell(instances, _this2.primaryAggregation.key);
|
|
1575
1966
|
};
|
|
1576
1967
|
|
|
1577
1968
|
var hydrateTotals = function hydrateTotals(source, target) {
|
|
@@ -1592,8 +1983,8 @@ var PivotData = function () {
|
|
|
1592
1983
|
hydrateTotals(precomputed.colTotals, this.colTotals);
|
|
1593
1984
|
this.tree = {};
|
|
1594
1985
|
Object.keys(precomputed.tree || {}).forEach(function (flatRowKey) {
|
|
1595
|
-
|
|
1596
|
-
hydrateTotals(precomputed.tree[flatRowKey],
|
|
1986
|
+
_this2.tree[flatRowKey] = {};
|
|
1987
|
+
hydrateTotals(precomputed.tree[flatRowKey], _this2.tree[flatRowKey]);
|
|
1597
1988
|
});
|
|
1598
1989
|
this.allTotal = makeCell(precomputed.allTotal);
|
|
1599
1990
|
|
|
@@ -1601,6 +1992,40 @@ var PivotData = function () {
|
|
|
1601
1992
|
// thread when a sorter could not cross the worker boundary (functions).
|
|
1602
1993
|
this.sorted = !sortersHaveFunctions(this.props.sorters);
|
|
1603
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
|
+
}
|
|
1604
2029
|
}, {
|
|
1605
2030
|
key: 'filter',
|
|
1606
2031
|
value: function filter(record) {
|
|
@@ -1614,10 +2039,10 @@ var PivotData = function () {
|
|
|
1614
2039
|
}, {
|
|
1615
2040
|
key: 'forEachMatchingRecord',
|
|
1616
2041
|
value: function forEachMatchingRecord(criteria, callback) {
|
|
1617
|
-
var
|
|
2042
|
+
var _this3 = this;
|
|
1618
2043
|
|
|
1619
2044
|
return PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, function (record) {
|
|
1620
|
-
if (!
|
|
2045
|
+
if (!_this3.filter(record)) {
|
|
1621
2046
|
return;
|
|
1622
2047
|
}
|
|
1623
2048
|
for (var k in criteria) {
|
|
@@ -1632,7 +2057,7 @@ var PivotData = function () {
|
|
|
1632
2057
|
}, {
|
|
1633
2058
|
key: 'arrSort',
|
|
1634
2059
|
value: function arrSort(attrs) {
|
|
1635
|
-
var
|
|
2060
|
+
var _this4 = this;
|
|
1636
2061
|
|
|
1637
2062
|
var a = void 0;
|
|
1638
2063
|
var sortersArr = function () {
|
|
@@ -1645,7 +2070,7 @@ var PivotData = function () {
|
|
|
1645
2070
|
for (var _iterator2 = Array.from(attrs)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
1646
2071
|
a = _step2.value;
|
|
1647
2072
|
|
|
1648
|
-
result.push(getSort(
|
|
2073
|
+
result.push(getSort(_this4.props.sorters, a));
|
|
1649
2074
|
}
|
|
1650
2075
|
} catch (err) {
|
|
1651
2076
|
_didIteratorError2 = true;
|
|
@@ -1700,12 +2125,12 @@ var PivotData = function () {
|
|
|
1700
2125
|
}, {
|
|
1701
2126
|
key: 'sortKeys',
|
|
1702
2127
|
value: function sortKeys() {
|
|
1703
|
-
var
|
|
2128
|
+
var _this5 = this;
|
|
1704
2129
|
|
|
1705
2130
|
if (!this.sorted) {
|
|
1706
2131
|
this.sorted = true;
|
|
1707
2132
|
var v = function v(r, c) {
|
|
1708
|
-
return
|
|
2133
|
+
return _this5.getAggregator(r, c).value();
|
|
1709
2134
|
};
|
|
1710
2135
|
|
|
1711
2136
|
// Handle per-row sorting
|
|
@@ -1713,11 +2138,11 @@ var PivotData = function () {
|
|
|
1713
2138
|
var rowSorts = this.props.rowSorts;
|
|
1714
2139
|
this.rowKeys.sort(function (a, b) {
|
|
1715
2140
|
// First, check if any sorted attribute has a difference
|
|
1716
|
-
for (var i = 0; i <
|
|
1717
|
-
var attr =
|
|
2141
|
+
for (var i = 0; i < _this5.props.rows.length; i++) {
|
|
2142
|
+
var attr = _this5.props.rows[i];
|
|
1718
2143
|
if (attr && rowSorts[attr]) {
|
|
1719
2144
|
var sortDir = rowSorts[attr] === 'ASC' ? 1 : -1;
|
|
1720
|
-
var sorter = getSort(
|
|
2145
|
+
var sorter = getSort(_this5.props.sorters, attr);
|
|
1721
2146
|
var comparison = sorter(a[i] || '', b[i] || '');
|
|
1722
2147
|
if (comparison !== 0) {
|
|
1723
2148
|
return sortDir * comparison;
|
|
@@ -1725,7 +2150,7 @@ var PivotData = function () {
|
|
|
1725
2150
|
}
|
|
1726
2151
|
}
|
|
1727
2152
|
// If sorted attributes are equal, use default sorting for remaining attributes
|
|
1728
|
-
return
|
|
2153
|
+
return _this5.arrSort(_this5.props.rows)(a, b);
|
|
1729
2154
|
});
|
|
1730
2155
|
} else {
|
|
1731
2156
|
// Use global row order
|
|
@@ -1750,11 +2175,11 @@ var PivotData = function () {
|
|
|
1750
2175
|
var colSorts = this.props.colSorts;
|
|
1751
2176
|
this.colKeys.sort(function (a, b) {
|
|
1752
2177
|
// First, check if any sorted attribute has a difference
|
|
1753
|
-
for (var i = 0; i <
|
|
1754
|
-
var attr =
|
|
2178
|
+
for (var i = 0; i < _this5.props.cols.length; i++) {
|
|
2179
|
+
var attr = _this5.props.cols[i];
|
|
1755
2180
|
if (attr && colSorts[attr]) {
|
|
1756
2181
|
var sortDir = colSorts[attr] === 'ASC' ? 1 : -1;
|
|
1757
|
-
var sorter = getSort(
|
|
2182
|
+
var sorter = getSort(_this5.props.sorters, attr);
|
|
1758
2183
|
var comparison = sorter(a[i] || '', b[i] || '');
|
|
1759
2184
|
if (comparison !== 0) {
|
|
1760
2185
|
return sortDir * comparison;
|
|
@@ -1762,7 +2187,7 @@ var PivotData = function () {
|
|
|
1762
2187
|
}
|
|
1763
2188
|
}
|
|
1764
2189
|
// If sorted attributes are equal, use default sorting for remaining attributes
|
|
1765
|
-
return
|
|
2190
|
+
return _this5.arrSort(_this5.props.cols)(a, b);
|
|
1766
2191
|
});
|
|
1767
2192
|
} else {
|
|
1768
2193
|
// Use global col order
|
|
@@ -1801,58 +2226,16 @@ var PivotData = function () {
|
|
|
1801
2226
|
// this code is called in a tight loop
|
|
1802
2227
|
var colKey = [];
|
|
1803
2228
|
var rowKey = [];
|
|
1804
|
-
var
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
try {
|
|
1809
|
-
for (var _iterator4 = Array.from(this.props.cols)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
1810
|
-
var x = _step4.value;
|
|
1811
|
-
|
|
1812
|
-
colKey.push(x in record ? record[x] : 'null');
|
|
1813
|
-
}
|
|
1814
|
-
} catch (err) {
|
|
1815
|
-
_didIteratorError4 = true;
|
|
1816
|
-
_iteratorError4 = err;
|
|
1817
|
-
} finally {
|
|
1818
|
-
try {
|
|
1819
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
|
1820
|
-
_iterator4.return();
|
|
1821
|
-
}
|
|
1822
|
-
} finally {
|
|
1823
|
-
if (_didIteratorError4) {
|
|
1824
|
-
throw _iteratorError4;
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
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');
|
|
1827
2232
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
var _iteratorError5 = undefined;
|
|
1832
|
-
|
|
1833
|
-
try {
|
|
1834
|
-
for (var _iterator5 = Array.from(this.props.rows)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
1835
|
-
var _x17 = _step5.value;
|
|
1836
|
-
|
|
1837
|
-
rowKey.push(_x17 in record ? record[_x17] : 'null');
|
|
1838
|
-
}
|
|
1839
|
-
} catch (err) {
|
|
1840
|
-
_didIteratorError5 = true;
|
|
1841
|
-
_iteratorError5 = err;
|
|
1842
|
-
} finally {
|
|
1843
|
-
try {
|
|
1844
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
|
1845
|
-
_iterator5.return();
|
|
1846
|
-
}
|
|
1847
|
-
} finally {
|
|
1848
|
-
if (_didIteratorError5) {
|
|
1849
|
-
throw _iteratorError5;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
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');
|
|
1852
2236
|
}
|
|
1853
|
-
|
|
1854
|
-
var
|
|
1855
|
-
var flatColKey = colKey.join(String.fromCharCode(0));
|
|
2237
|
+
var flatRowKey = rowKey.join(FLAT_KEY_SEPARATOR);
|
|
2238
|
+
var flatColKey = colKey.join(FLAT_KEY_SEPARATOR);
|
|
1856
2239
|
|
|
1857
2240
|
this.allTotal.push(record);
|
|
1858
2241
|
|
|
@@ -1901,8 +2284,8 @@ var PivotData = function () {
|
|
|
1901
2284
|
key: 'getAggregatorCell',
|
|
1902
2285
|
value: function getAggregatorCell(rowKey, colKey) {
|
|
1903
2286
|
var cell = void 0;
|
|
1904
|
-
var flatRowKey = rowKey.join(
|
|
1905
|
-
var flatColKey = colKey.join(
|
|
2287
|
+
var flatRowKey = rowKey.join(FLAT_KEY_SEPARATOR);
|
|
2288
|
+
var flatColKey = colKey.join(FLAT_KEY_SEPARATOR);
|
|
1906
2289
|
if (rowKey.length === 0 && colKey.length === 0) {
|
|
1907
2290
|
cell = this.allTotal;
|
|
1908
2291
|
} else if (rowKey.length === 0) {
|
|
@@ -2006,25 +2389,25 @@ var PivotData = function () {
|
|
|
2006
2389
|
}, {
|
|
2007
2390
|
key: 'buildAggregatorFactories',
|
|
2008
2391
|
value: function buildAggregatorFactories() {
|
|
2009
|
-
var
|
|
2392
|
+
var _this6 = this;
|
|
2010
2393
|
|
|
2011
2394
|
var factories = {};
|
|
2012
2395
|
this.aggregations.forEach(function (agg) {
|
|
2013
|
-
if (!(agg.aggregatorName in
|
|
2396
|
+
if (!(agg.aggregatorName in _this6.props.aggregators)) {
|
|
2014
2397
|
throw new Error('unknown aggregator ' + agg.aggregatorName);
|
|
2015
2398
|
}
|
|
2016
|
-
factories[agg.key] =
|
|
2399
|
+
factories[agg.key] = _this6.props.aggregators[agg.aggregatorName](agg.vals);
|
|
2017
2400
|
});
|
|
2018
2401
|
return factories;
|
|
2019
2402
|
}
|
|
2020
2403
|
}, {
|
|
2021
2404
|
key: 'createAggregatorCell',
|
|
2022
2405
|
value: function createAggregatorCell(rowKey, colKey) {
|
|
2023
|
-
var
|
|
2406
|
+
var _this7 = this;
|
|
2024
2407
|
|
|
2025
2408
|
var instances = {};
|
|
2026
2409
|
this.aggregations.forEach(function (agg) {
|
|
2027
|
-
instances[agg.key] =
|
|
2410
|
+
instances[agg.key] = _this7.aggregatorFactories[agg.key](_this7, rowKey, colKey);
|
|
2028
2411
|
});
|
|
2029
2412
|
return new AggregatorCell(instances, this.primaryAggregation.key);
|
|
2030
2413
|
}
|
|
@@ -2067,97 +2450,23 @@ PivotData.forEachRecord = function (input, derivedAttributes, f) {
|
|
|
2067
2450
|
} else if (Array.isArray(input)) {
|
|
2068
2451
|
if (Array.isArray(input[0])) {
|
|
2069
2452
|
// array of arrays
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
var
|
|
2073
|
-
|
|
2074
|
-
var
|
|
2075
|
-
|
|
2076
|
-
try {
|
|
2077
|
-
for (var _iterator6 = Object.keys(input || {})[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
2078
|
-
var i = _step6.value;
|
|
2079
|
-
|
|
2080
|
-
var compactRecord = input[i];
|
|
2081
|
-
if (i > 0) {
|
|
2082
|
-
record = {};
|
|
2083
|
-
var _iteratorNormalCompletion7 = true;
|
|
2084
|
-
var _didIteratorError7 = false;
|
|
2085
|
-
var _iteratorError7 = undefined;
|
|
2086
|
-
|
|
2087
|
-
try {
|
|
2088
|
-
for (var _iterator7 = Object.keys(input[0] || {})[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
|
|
2089
|
-
var j = _step7.value;
|
|
2090
|
-
|
|
2091
|
-
var k = input[0][j];
|
|
2092
|
-
record[k] = compactRecord[j];
|
|
2093
|
-
}
|
|
2094
|
-
} catch (err) {
|
|
2095
|
-
_didIteratorError7 = true;
|
|
2096
|
-
_iteratorError7 = err;
|
|
2097
|
-
} finally {
|
|
2098
|
-
try {
|
|
2099
|
-
if (!_iteratorNormalCompletion7 && _iterator7.return) {
|
|
2100
|
-
_iterator7.return();
|
|
2101
|
-
}
|
|
2102
|
-
} finally {
|
|
2103
|
-
if (_didIteratorError7) {
|
|
2104
|
-
throw _iteratorError7;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
result.push(addRecord(record));
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
} catch (err) {
|
|
2113
|
-
_didIteratorError6 = true;
|
|
2114
|
-
_iteratorError6 = err;
|
|
2115
|
-
} finally {
|
|
2116
|
-
try {
|
|
2117
|
-
if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
|
2118
|
-
_iterator6.return();
|
|
2119
|
-
}
|
|
2120
|
-
} finally {
|
|
2121
|
-
if (_didIteratorError6) {
|
|
2122
|
-
throw _iteratorError6;
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
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];
|
|
2125
2459
|
}
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2460
|
+
addRecord(record);
|
|
2461
|
+
}
|
|
2462
|
+
return null;
|
|
2129
2463
|
}
|
|
2130
2464
|
|
|
2131
2465
|
// array of objects
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
var _iteratorError8 = undefined;
|
|
2137
|
-
|
|
2138
|
-
try {
|
|
2139
|
-
for (var _iterator8 = Array.from(input)[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
|
2140
|
-
record = _step8.value;
|
|
2141
|
-
|
|
2142
|
-
result1.push(addRecord(record));
|
|
2143
|
-
}
|
|
2144
|
-
} catch (err) {
|
|
2145
|
-
_didIteratorError8 = true;
|
|
2146
|
-
_iteratorError8 = err;
|
|
2147
|
-
} finally {
|
|
2148
|
-
try {
|
|
2149
|
-
if (!_iteratorNormalCompletion8 && _iterator8.return) {
|
|
2150
|
-
_iterator8.return();
|
|
2151
|
-
}
|
|
2152
|
-
} finally {
|
|
2153
|
-
if (_didIteratorError8) {
|
|
2154
|
-
throw _iteratorError8;
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
|
|
2159
|
-
return result1;
|
|
2160
|
-
}();
|
|
2466
|
+
for (var _i = 0; _i < input.length; _i += 1) {
|
|
2467
|
+
addRecord(input[_i]);
|
|
2468
|
+
}
|
|
2469
|
+
return null;
|
|
2161
2470
|
}
|
|
2162
2471
|
throw new Error('unknown input format');
|
|
2163
2472
|
};
|