@hrforte/react-pivottable 2.1.2 → 2.2.1
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/README.md +18 -4
- package/dist/PivotDataWorker.js +11 -16
- package/dist/PivotDataWorker.js.map +1 -1
- package/dist/PivotTableUI.js +63 -74
- package/dist/PivotTableUI.js.map +1 -1
- package/dist/PlotlyRenderers.js +9 -5
- package/dist/PlotlyRenderers.js.map +1 -1
- package/dist/TableRenderers.js +35 -2
- package/dist/TableRenderers.js.map +1 -1
- package/dist/Utilities.js +2 -20
- package/dist/Utilities.js.map +1 -1
- package/dist/__tests__/PivotDataWorker-test.js +7 -8
- package/dist/__tests__/PivotDataWorker-test.js.map +1 -1
- package/dist/__tests__/PivotTableUI-processing-test.js +108 -13
- package/dist/__tests__/PivotTableUI-processing-test.js.map +1 -1
- package/dist/__tests__/TableRenderers-showNumericalOrder-test.js +178 -0
- package/dist/__tests__/TableRenderers-showNumericalOrder-test.js.map +1 -0
- package/dist/__tests__/pivotCompute-test.js +7 -7
- package/dist/__tests__/pivotCompute-test.js.map +1 -1
- package/dist/pivot-worker.js +8 -60
- package/dist/pivotCompute.js +5 -22
- package/dist/pivotCompute.js.map +1 -1
- package/dist/pivotWorker.js +2 -18
- package/dist/pivotWorker.js.map +1 -1
- package/dist/pivottable.css +3 -20
- package/package.json +1 -1
package/dist/pivot-worker.js
CHANGED
|
@@ -346,15 +346,7 @@ self.addEventListener('message', function (event) {
|
|
|
346
346
|
var startedAt = Date.now();
|
|
347
347
|
log('#' + message.id + ' setData received: ' + (message.data || []).length + ' records (dataKey=' + message.dataKey + ')');
|
|
348
348
|
try {
|
|
349
|
-
var dataset = cacheDataset(message.dataKey, Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["b" /* materializeData */])(message.data, {}
|
|
350
|
-
postToMain({
|
|
351
|
-
type: 'pivot:progress',
|
|
352
|
-
id: message.id,
|
|
353
|
-
processed: processed,
|
|
354
|
-
total: total,
|
|
355
|
-
phase: 'materialize'
|
|
356
|
-
});
|
|
357
|
-
}));
|
|
349
|
+
var dataset = cacheDataset(message.dataKey, Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["b" /* materializeData */])(message.data, {}));
|
|
358
350
|
log('#' + message.id + ' materialized ' + dataset.totalRecords + ' records in ' + (Date.now() - startedAt + 'ms (attributes: ' + Object.keys(dataset.attrValues).join(', ') + ')'));
|
|
359
351
|
} catch (error) {
|
|
360
352
|
log('#' + message.id + ' setData failed: ' + toErrorMessage(error));
|
|
@@ -376,15 +368,7 @@ self.addEventListener('message', function (event) {
|
|
|
376
368
|
throw new Error('no dataset staged for key ' + message.dataKey);
|
|
377
369
|
}
|
|
378
370
|
log('#' + message.id + ' compute received (rows=[' + (config.rows || []).join(', ') + '] cols=[' + (config.cols || []).join(', ') + '])');
|
|
379
|
-
var result = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["a" /* computePivotState */])(_dataset, message.config
|
|
380
|
-
postToMain({
|
|
381
|
-
type: 'pivot:progress',
|
|
382
|
-
id: message.id,
|
|
383
|
-
processed: processed,
|
|
384
|
-
total: total,
|
|
385
|
-
phase: phase
|
|
386
|
-
});
|
|
387
|
-
});
|
|
371
|
+
var result = Object(__WEBPACK_IMPORTED_MODULE_0__pivotCompute__["a" /* computePivotState */])(_dataset, message.config);
|
|
388
372
|
log('#' + message.id + ' computed in ' + (Date.now() - _startedAt) + 'ms (rowKeys: ' + result.rowKeys.length + ', colKeys: ' + result.colKeys.length + ', aggregations: ' + result.aggregations.map(function (agg) {
|
|
389
373
|
return agg.key;
|
|
390
374
|
}).join(', ') + ')');
|
|
@@ -405,7 +389,6 @@ self.addEventListener('message', function (event) {
|
|
|
405
389
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
406
390
|
|
|
407
391
|
"use strict";
|
|
408
|
-
/* unused harmony export PROGRESS_BATCH_SIZE */
|
|
409
392
|
/* unused harmony export DEFAULT_WORKER_THRESHOLD */
|
|
410
393
|
/* unused harmony export WORKER_DEBOUNCE_MS */
|
|
411
394
|
/* harmony export (immutable) */ __webpack_exports__["b"] = materializeData;
|
|
@@ -433,30 +416,22 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
|
|
|
433
416
|
*/
|
|
434
417
|
|
|
435
418
|
|
|
436
|
-
// A progress callback fires every N processed records so the UI can render
|
|
437
|
-
// progress without adding measurable overhead to the per-record loop.
|
|
438
|
-
var PROGRESS_BATCH_SIZE = 200;
|
|
439
|
-
|
|
440
419
|
// Datasets smaller than this are computed synchronously on the main thread;
|
|
441
420
|
// larger ones are handed off to the Web Worker.
|
|
442
421
|
var DEFAULT_WORKER_THRESHOLD = 200;
|
|
443
422
|
|
|
444
423
|
// Trailing debounce before a worker computation is dispatched, so rapid
|
|
445
424
|
// interactions do not queue one full computation per single change.
|
|
446
|
-
var WORKER_DEBOUNCE_MS =
|
|
425
|
+
var WORKER_DEBOUNCE_MS = 100;
|
|
447
426
|
|
|
448
427
|
/*
|
|
449
428
|
* Walks the raw input once and computes the attribute-value inventory plus a
|
|
450
429
|
* "materialized" copy of the records (with derived attributes applied).
|
|
451
430
|
* This is an exact extraction of the historical PivotTableUI behavior.
|
|
452
|
-
*
|
|
453
|
-
* onProgress receives (processed, total, phase); total is null when it is
|
|
454
|
-
* unknown upfront (function-based data sources).
|
|
455
431
|
*/
|
|
456
|
-
function materializeData(data, derivedAttributes
|
|
432
|
+
function materializeData(data, derivedAttributes) {
|
|
457
433
|
var attrValues = {};
|
|
458
434
|
var materializedInput = [];
|
|
459
|
-
var total = Array.isArray(data) ? data.length : null;
|
|
460
435
|
var recordsProcessed = 0;
|
|
461
436
|
__WEBPACK_IMPORTED_MODULE_0__Utilities__["a" /* PivotData */].forEachRecord(data, derivedAttributes || {}, function (record) {
|
|
462
437
|
materializedInput.push(record);
|
|
@@ -498,9 +473,6 @@ function materializeData(data, derivedAttributes, onProgress) {
|
|
|
498
473
|
attrValues[_attr][value]++;
|
|
499
474
|
}
|
|
500
475
|
recordsProcessed++;
|
|
501
|
-
if (onProgress && recordsProcessed % PROGRESS_BATCH_SIZE === 0) {
|
|
502
|
-
onProgress(recordsProcessed, total, 'materialize');
|
|
503
|
-
}
|
|
504
476
|
});
|
|
505
477
|
return { attrValues: attrValues, materializedInput: materializedInput, totalRecords: recordsProcessed };
|
|
506
478
|
}
|
|
@@ -510,16 +482,10 @@ function materializeData(data, derivedAttributes, onProgress) {
|
|
|
510
482
|
* serializes the result into a plain (structured-cloneable) object that can
|
|
511
483
|
* cross the worker boundary and later hydrate PivotData on the main thread.
|
|
512
484
|
*/
|
|
513
|
-
function computePivotState(materialized, config
|
|
514
|
-
var total = materialized.totalRecords;
|
|
485
|
+
function computePivotState(materialized, config) {
|
|
515
486
|
var pivotData = new __WEBPACK_IMPORTED_MODULE_0__Utilities__["a" /* PivotData */](Object.assign({}, config, {
|
|
516
487
|
data: materialized.materializedInput,
|
|
517
|
-
derivedAttributes: {}
|
|
518
|
-
onRecordProcessed: function onRecordProcessed(processed) {
|
|
519
|
-
if (onProgress) {
|
|
520
|
-
onProgress(processed, total, 'aggregate');
|
|
521
|
-
}
|
|
522
|
-
}
|
|
488
|
+
derivedAttributes: {}
|
|
523
489
|
}));
|
|
524
490
|
// Force key sorting to happen while we are (possibly) inside the worker.
|
|
525
491
|
pivotData.getRowKeys();
|
|
@@ -1073,10 +1039,6 @@ var usFmtPct = numberFormat({
|
|
|
1073
1039
|
suffix: '%'
|
|
1074
1040
|
});
|
|
1075
1041
|
|
|
1076
|
-
// Emit a progress callback every N processed records without adding
|
|
1077
|
-
// measurable overhead to the per-record loop.
|
|
1078
|
-
var RECORD_PROGRESS_BATCH_SIZE = 200;
|
|
1079
|
-
|
|
1080
1042
|
// Returns true when the sorters prop itself, or any of its entries, is a
|
|
1081
1043
|
// function. Function-based sorters cannot be transferred to a Web Worker, so
|
|
1082
1044
|
// PivotData re-applies them on the main thread after worker hydration.
|
|
@@ -1563,24 +1525,11 @@ var PivotData = function () {
|
|
|
1563
1525
|
return;
|
|
1564
1526
|
}
|
|
1565
1527
|
|
|
1566
|
-
|
|
1567
|
-
var recordHandler = function recordHandler(record) {
|
|
1528
|
+
PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, function (record) {
|
|
1568
1529
|
if (_this2.filter(record)) {
|
|
1569
1530
|
_this2.processRecord(record);
|
|
1570
1531
|
}
|
|
1571
|
-
};
|
|
1572
|
-
if (typeof progressHook === 'function') {
|
|
1573
|
-
var recordsProcessed = 0;
|
|
1574
|
-
PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, function (record) {
|
|
1575
|
-
recordHandler(record);
|
|
1576
|
-
recordsProcessed++;
|
|
1577
|
-
if (recordsProcessed % RECORD_PROGRESS_BATCH_SIZE === 0) {
|
|
1578
|
-
progressHook(recordsProcessed);
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
} else {
|
|
1582
|
-
PivotData.forEachRecord(this.props.data, this.props.derivedAttributes, recordHandler);
|
|
1583
|
-
}
|
|
1532
|
+
});
|
|
1584
1533
|
}
|
|
1585
1534
|
|
|
1586
1535
|
/*
|
|
@@ -2245,7 +2194,6 @@ PivotData.propTypes = {
|
|
|
2245
2194
|
sorters: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.oneOfType([__WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.func, __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.objectOf(__WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.oneOfType([__WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.func, __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.string, __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.array]))]),
|
|
2246
2195
|
derivedAttributes: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.objectOf(__WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.func),
|
|
2247
2196
|
precomputedData: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.object,
|
|
2248
|
-
onRecordProcessed: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.func,
|
|
2249
2197
|
rowOrder: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.oneOf(['key_a_to_z', 'value_a_to_z', 'value_z_to_a']),
|
|
2250
2198
|
colOrder: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.oneOf(['key_a_to_z', 'value_a_to_z', 'value_z_to_a']),
|
|
2251
2199
|
rowSorts: __WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.objectOf(__WEBPACK_IMPORTED_MODULE_0_prop_types___default.a.oneOf(['ASC', 'DESC'])),
|
package/dist/pivotCompute.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.WORKER_DEBOUNCE_MS = exports.DEFAULT_WORKER_THRESHOLD =
|
|
6
|
+
exports.WORKER_DEBOUNCE_MS = exports.DEFAULT_WORKER_THRESHOLD = undefined;
|
|
7
7
|
|
|
8
8
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /* eslint-disable no-console */
|
|
9
9
|
/* eslint-disable valid-jsdoc */
|
|
@@ -30,30 +30,22 @@ exports.canComputeInWorker = canComputeInWorker;
|
|
|
30
30
|
|
|
31
31
|
var _Utilities = require('./Utilities');
|
|
32
32
|
|
|
33
|
-
// A progress callback fires every N processed records so the UI can render
|
|
34
|
-
// progress without adding measurable overhead to the per-record loop.
|
|
35
|
-
var PROGRESS_BATCH_SIZE = exports.PROGRESS_BATCH_SIZE = 200;
|
|
36
|
-
|
|
37
33
|
// Datasets smaller than this are computed synchronously on the main thread;
|
|
38
34
|
// larger ones are handed off to the Web Worker.
|
|
39
35
|
var DEFAULT_WORKER_THRESHOLD = exports.DEFAULT_WORKER_THRESHOLD = 200;
|
|
40
36
|
|
|
41
37
|
// Trailing debounce before a worker computation is dispatched, so rapid
|
|
42
38
|
// interactions do not queue one full computation per single change.
|
|
43
|
-
var WORKER_DEBOUNCE_MS = exports.WORKER_DEBOUNCE_MS =
|
|
39
|
+
var WORKER_DEBOUNCE_MS = exports.WORKER_DEBOUNCE_MS = 100;
|
|
44
40
|
|
|
45
41
|
/*
|
|
46
42
|
* Walks the raw input once and computes the attribute-value inventory plus a
|
|
47
43
|
* "materialized" copy of the records (with derived attributes applied).
|
|
48
44
|
* This is an exact extraction of the historical PivotTableUI behavior.
|
|
49
|
-
*
|
|
50
|
-
* onProgress receives (processed, total, phase); total is null when it is
|
|
51
|
-
* unknown upfront (function-based data sources).
|
|
52
45
|
*/
|
|
53
|
-
function materializeData(data, derivedAttributes
|
|
46
|
+
function materializeData(data, derivedAttributes) {
|
|
54
47
|
var attrValues = {};
|
|
55
48
|
var materializedInput = [];
|
|
56
|
-
var total = Array.isArray(data) ? data.length : null;
|
|
57
49
|
var recordsProcessed = 0;
|
|
58
50
|
_Utilities.PivotData.forEachRecord(data, derivedAttributes || {}, function (record) {
|
|
59
51
|
materializedInput.push(record);
|
|
@@ -95,9 +87,6 @@ function materializeData(data, derivedAttributes, onProgress) {
|
|
|
95
87
|
attrValues[_attr][value]++;
|
|
96
88
|
}
|
|
97
89
|
recordsProcessed++;
|
|
98
|
-
if (onProgress && recordsProcessed % PROGRESS_BATCH_SIZE === 0) {
|
|
99
|
-
onProgress(recordsProcessed, total, 'materialize');
|
|
100
|
-
}
|
|
101
90
|
});
|
|
102
91
|
return { attrValues: attrValues, materializedInput: materializedInput, totalRecords: recordsProcessed };
|
|
103
92
|
}
|
|
@@ -107,16 +96,10 @@ function materializeData(data, derivedAttributes, onProgress) {
|
|
|
107
96
|
* serializes the result into a plain (structured-cloneable) object that can
|
|
108
97
|
* cross the worker boundary and later hydrate PivotData on the main thread.
|
|
109
98
|
*/
|
|
110
|
-
function computePivotState(materialized, config
|
|
111
|
-
var total = materialized.totalRecords;
|
|
99
|
+
function computePivotState(materialized, config) {
|
|
112
100
|
var pivotData = new _Utilities.PivotData(Object.assign({}, config, {
|
|
113
101
|
data: materialized.materializedInput,
|
|
114
|
-
derivedAttributes: {}
|
|
115
|
-
onRecordProcessed: function onRecordProcessed(processed) {
|
|
116
|
-
if (onProgress) {
|
|
117
|
-
onProgress(processed, total, 'aggregate');
|
|
118
|
-
}
|
|
119
|
-
}
|
|
102
|
+
derivedAttributes: {}
|
|
120
103
|
}));
|
|
121
104
|
// Force key sorting to happen while we are (possibly) inside the worker.
|
|
122
105
|
pivotData.getRowKeys();
|
package/dist/pivotCompute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pivotCompute.js"],"names":["materializeData","computePivotState","serializePivotData","sortersHaveFunctions","sanitizeSorters","createWorkerConfig","createComputeSignature","canComputeInWorker","PROGRESS_BATCH_SIZE","DEFAULT_WORKER_THRESHOLD","WORKER_DEBOUNCE_MS","data","derivedAttributes","onProgress","attrValues","materializedInput","total","Array","isArray","length","recordsProcessed","PivotData","forEachRecord","record","push","Object","keys","attr","null","value","totalRecords","materialized","config","pivotData","assign","onRecordProcessed","processed","getRowKeys","getColKeys","serializeCell","values","aggregations","forEach","instance","cell","getInstance","agg","key","tree","rowBranch","flatRowKey","serializedRow","flatColKey","serializeTotals","serialized","totals","flatKey","rowKeys","map","slice","colKeys","rowTotals","colTotals","allTotal","sorters","some","clean","sorter","props","rows","cols","aggregatorName","vals","valueFilter","rowOrder","colOrder","rowSorts","colSorts","JSON","stringify","options","enabled","Worker","threshold"],"mappings":";;;;;;;8QAAA;AACA;AACA;;;;;;;;;;;;QAgCgBA,e,GAAAA,e;QAmCAC,iB,GAAAA,iB;QAwBAC,kB,GAAAA,kB;QAkDAC,oB,GAAAA,oB;QAcAC,e,GAAAA,e;QAuBAC,kB,GAAAA,kB;QAoBAC,sB,GAAAA,sB;QAUAC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;;;AAMO,SAAS7D,kBAAT,CAA4B6D,KAA5B,EAAiD;AAAA,MAAdY,OAAc,uEAAJ,EAAI;;AACtD,MAAIA,QAAQC,OAAR,KAAoB,KAAxB,EAA+B;AAC7B,WAAO,KAAP;AACD;AACD,MAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;AACjC,WAAO,KAAP;AACD;AACD,MAAMC,YACJ,OAAOH,QAAQG,SAAf,KAA6B,QAA7B,GACIH,QAAQG,SADZ,GAEI1E,wBAHN;;AAKA,MAAME,OAAOyD,MAAMzD,IAAnB;AACA,MAAI,CAACM,MAAMC,OAAN,CAAcP,IAAd,CAAD,IAAwBA,KAAKQ,MAAL,GAAcgE,SAA1C,EAAqD;AACnD,WAAO,KAAP;AACD;AACD,SAAO,IAAP;AACD","file":"pivotCompute.js","sourcesContent":["/* eslint-disable no-console */\n/* eslint-disable valid-jsdoc */\n/*\n * Shared pivot-computation logic.\n *\n * This module contains the pure, DOM-free parts of the pivot computation so\n * that the exact same code paths can run:\n * - on the main thread (classic synchronous rendering path), and\n * - inside a Web Worker (src/pivotWorker.js) for large datasets.\n *\n * It must stay free of React and of any `window`/`document` references.\n */\nimport {PivotData} from './Utilities';\n\n// A progress callback fires every N processed records so the UI can render\n// progress without adding measurable overhead to the per-record loop.\nexport const PROGRESS_BATCH_SIZE = 200;\n\n// Datasets smaller than this are computed synchronously on the main thread;\n// larger ones are handed off to the Web Worker.\nexport const DEFAULT_WORKER_THRESHOLD = 200;\n\n// Trailing debounce before a worker computation is dispatched, so rapid\n// interactions do not queue one full computation per single change.\nexport const WORKER_DEBOUNCE_MS = 50;\n\n/*\n * Walks the raw input once and computes the attribute-value inventory plus a\n * \"materialized\" copy of the records (with derived attributes applied).\n * This is an exact extraction of the historical PivotTableUI behavior.\n *\n * onProgress receives (processed, total, phase); total is null when it is\n * unknown upfront (function-based data sources).\n */\nexport function materializeData(data, derivedAttributes, onProgress) {\n const attrValues = {};\n const materializedInput = [];\n const total = Array.isArray(data) ? data.length : null;\n let recordsProcessed = 0;\n PivotData.forEachRecord(data, derivedAttributes || {}, function(record) {\n materializedInput.push(record);\n for (const attr of Object.keys(record)) {\n if (!(attr in attrValues)) {\n attrValues[attr] = {};\n if (recordsProcessed > 0) {\n attrValues[attr].null = recordsProcessed;\n }\n }\n }\n for (const attr in attrValues) {\n const value = attr in record ? record[attr] : 'null';\n if (!(value in attrValues[attr])) {\n attrValues[attr][value] = 0;\n }\n attrValues[attr][value]++;\n }\n recordsProcessed++;\n if (onProgress && recordsProcessed % PROGRESS_BATCH_SIZE === 0) {\n onProgress(recordsProcessed, total, 'materialize');\n }\n });\n return {attrValues, materializedInput, totalRecords: recordsProcessed};\n}\n\n/*\n * Aggregates an already-materialized dataset into a PivotData instance and\n * serializes the result into a plain (structured-cloneable) object that can\n * cross the worker boundary and later hydrate PivotData on the main thread.\n */\nexport function computePivotState(materialized, config, onProgress) {\n const total = materialized.totalRecords;\n const pivotData = new PivotData(\n Object.assign({}, config, {\n data: materialized.materializedInput,\n derivedAttributes: {},\n onRecordProcessed: processed => {\n if (onProgress) {\n onProgress(processed, total, 'aggregate');\n }\n },\n })\n );\n // Force key sorting to happen while we are (possibly) inside the worker.\n pivotData.getRowKeys();\n pivotData.getColKeys();\n return serializePivotData(pivotData, materialized);\n}\n\n/*\n * Serializes a fully-built PivotData instance into plain data. Only the final\n * aggregated value of every cell is kept; `value()` and `format()` behavior\n * are reconstructed on the main thread by the PivotData hydration step.\n */\nexport function serializePivotData(pivotData, materialized) {\n const serializeCell = cell => {\n const values = {};\n pivotData.aggregations.forEach(agg => {\n const instance = cell.getInstance(agg.key);\n if (instance) {\n values[agg.key] = instance.value();\n }\n });\n return {values};\n };\n\n const tree = {};\n Object.keys(pivotData.tree).forEach(flatRowKey => {\n const rowBranch = pivotData.tree[flatRowKey];\n const serializedRow = {};\n Object.keys(rowBranch).forEach(flatColKey => {\n serializedRow[flatColKey] = serializeCell(rowBranch[flatColKey]);\n });\n tree[flatRowKey] = serializedRow;\n });\n\n const serializeTotals = totals => {\n const serialized = {};\n Object.keys(totals).forEach(flatKey => {\n serialized[flatKey] = serializeCell(totals[flatKey]);\n });\n return serialized;\n };\n\n return {\n rowKeys: pivotData.rowKeys.map(key => key.slice()),\n colKeys: pivotData.colKeys.map(key => key.slice()),\n tree,\n rowTotals: serializeTotals(pivotData.rowTotals),\n colTotals: serializeTotals(pivotData.colTotals),\n allTotal: serializeCell(pivotData.allTotal),\n aggregations: pivotData.aggregations.map(agg => Object.assign({}, agg)),\n attrValues: materialized.attrValues,\n materializedInput: materialized.materializedInput,\n totalRecords: materialized.totalRecords,\n };\n}\n\n/*\n * Sorters containing functions cannot be structured-cloned into a worker.\n * Returns true when the sorters prop itself, or any of its entries, is a\n * function. In that case PivotData re-sorts on the main thread after\n * hydration (distinct keys are few, so this stays cheap).\n */\nexport function sortersHaveFunctions(sorters) {\n if (typeof sorters === 'function') {\n return true;\n }\n if (!sorters || typeof sorters !== 'object') {\n return false;\n }\n return Object.keys(sorters).some(attr => typeof sorters[attr] === 'function');\n}\n\n/*\n * Returns a structured-cloneable subset of the sorters prop: data-type names\n * and sample-value arrays survive the worker boundary, functions do not.\n */\nexport function sanitizeSorters(sorters) {\n if (\n !sorters ||\n typeof sorters !== 'object' ||\n typeof sorters === 'function'\n ) {\n return {};\n }\n const clean = {};\n Object.keys(sorters).forEach(attr => {\n const sorter = sorters[attr];\n if (typeof sorter === 'string' || Array.isArray(sorter)) {\n clean[attr] = sorter;\n }\n });\n return clean;\n}\n\n/*\n * Extracts exactly the props PivotData needs to compute results, with\n * everything non-serializable stripped, so the object can be posted to the\n * worker and fed straight into PivotData.\n */\nexport function createWorkerConfig(props) {\n return {\n rows: props.rows,\n cols: props.cols,\n aggregatorName: props.aggregatorName,\n aggregations: props.aggregations,\n vals: props.vals,\n valueFilter: props.valueFilter,\n sorters: sanitizeSorters(props.sorters),\n rowOrder: props.rowOrder,\n colOrder: props.colOrder,\n rowSorts: props.rowSorts,\n colSorts: props.colSorts,\n };\n}\n\n/*\n * Stable string signature of everything that influences a worker computation.\n * Data identity is NOT part of it; callers append their own data version.\n */\nexport function createComputeSignature(props) {\n return JSON.stringify(createWorkerConfig(props));\n}\n\n/*\n * Decides whether the current props can be computed inside the Web Worker.\n * Anything that cannot be structured-cloned (function data sources, custom\n * derivedAttributes, custom aggregator maps) forces the classic path.\n * Function-based sorters are allowed: they are re-applied on the main thread.\n */\nexport function canComputeInWorker(props, options = {}) {\n if (options.enabled === false) {\n return false;\n }\n if (typeof Worker === 'undefined') {\n return false;\n }\n const threshold =\n typeof options.threshold === 'number'\n ? options.threshold\n : DEFAULT_WORKER_THRESHOLD;\n \n const data = props.data;\n if (!Array.isArray(data) || data.length < threshold) {\n return false;\n }\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/pivotCompute.js"],"names":["materializeData","computePivotState","serializePivotData","sortersHaveFunctions","sanitizeSorters","createWorkerConfig","createComputeSignature","canComputeInWorker","DEFAULT_WORKER_THRESHOLD","WORKER_DEBOUNCE_MS","data","derivedAttributes","attrValues","materializedInput","recordsProcessed","PivotData","forEachRecord","record","push","Object","keys","attr","null","value","totalRecords","materialized","config","pivotData","assign","getRowKeys","getColKeys","serializeCell","values","aggregations","forEach","instance","cell","getInstance","agg","key","tree","rowBranch","flatRowKey","serializedRow","flatColKey","serializeTotals","serialized","totals","flatKey","rowKeys","map","slice","colKeys","rowTotals","colTotals","allTotal","sorters","some","clean","sorter","Array","isArray","props","rows","cols","aggregatorName","vals","valueFilter","rowOrder","colOrder","rowSorts","colSorts","JSON","stringify","options","enabled","Worker","threshold","length"],"mappings":";;;;;;;8QAAA;AACA;AACA;;;;;;;;;;;;QAyBgBA,e,GAAAA,e;QA+BAC,iB,GAAAA,iB;QAkBAC,kB,GAAAA,kB;QAkDAC,oB,GAAAA,oB;QAcAC,e,GAAAA,e;QAuBAC,kB,GAAAA,kB;QAoBAC,sB,GAAAA,sB;QAUAC,kB,GAAAA,kB;;AArLhB;;AAEA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ACD","file":"pivotCompute.js","sourcesContent":["/* eslint-disable no-console */\n/* eslint-disable valid-jsdoc */\n/*\n * Shared pivot-computation logic.\n *\n * This module contains the pure, DOM-free parts of the pivot computation so\n * that the exact same code paths can run:\n * - on the main thread (classic synchronous rendering path), and\n * - inside a Web Worker (src/pivotWorker.js) for large datasets.\n *\n * It must stay free of React and of any `window`/`document` references.\n */\nimport {PivotData} from './Utilities';\n\n// Datasets smaller than this are computed synchronously on the main thread;\n// larger ones are handed off to the Web Worker.\nexport const DEFAULT_WORKER_THRESHOLD = 200;\n\n// Trailing debounce before a worker computation is dispatched, so rapid\n// interactions do not queue one full computation per single change.\nexport const WORKER_DEBOUNCE_MS = 100;\n\n/*\n * Walks the raw input once and computes the attribute-value inventory plus a\n * \"materialized\" copy of the records (with derived attributes applied).\n * This is an exact extraction of the historical PivotTableUI behavior.\n */\nexport function materializeData(data, derivedAttributes) {\n const attrValues = {};\n const materializedInput = [];\n let recordsProcessed = 0;\n PivotData.forEachRecord(data, derivedAttributes || {}, function(record) {\n materializedInput.push(record);\n for (const attr of Object.keys(record)) {\n if (!(attr in attrValues)) {\n attrValues[attr] = {};\n if (recordsProcessed > 0) {\n attrValues[attr].null = recordsProcessed;\n }\n }\n }\n for (const attr in attrValues) {\n const value = attr in record ? record[attr] : 'null';\n if (!(value in attrValues[attr])) {\n attrValues[attr][value] = 0;\n }\n attrValues[attr][value]++;\n }\n recordsProcessed++;\n });\n return {attrValues, materializedInput, totalRecords: recordsProcessed};\n}\n\n/*\n * Aggregates an already-materialized dataset into a PivotData instance and\n * serializes the result into a plain (structured-cloneable) object that can\n * cross the worker boundary and later hydrate PivotData on the main thread.\n */\nexport function computePivotState(materialized, config) {\n const pivotData = new PivotData(\n Object.assign({}, config, {\n data: materialized.materializedInput,\n derivedAttributes: {},\n })\n );\n // Force key sorting to happen while we are (possibly) inside the worker.\n pivotData.getRowKeys();\n pivotData.getColKeys();\n return serializePivotData(pivotData, materialized);\n}\n\n/*\n * Serializes a fully-built PivotData instance into plain data. Only the final\n * aggregated value of every cell is kept; `value()` and `format()` behavior\n * are reconstructed on the main thread by the PivotData hydration step.\n */\nexport function serializePivotData(pivotData, materialized) {\n const serializeCell = cell => {\n const values = {};\n pivotData.aggregations.forEach(agg => {\n const instance = cell.getInstance(agg.key);\n if (instance) {\n values[agg.key] = instance.value();\n }\n });\n return {values};\n };\n\n const tree = {};\n Object.keys(pivotData.tree).forEach(flatRowKey => {\n const rowBranch = pivotData.tree[flatRowKey];\n const serializedRow = {};\n Object.keys(rowBranch).forEach(flatColKey => {\n serializedRow[flatColKey] = serializeCell(rowBranch[flatColKey]);\n });\n tree[flatRowKey] = serializedRow;\n });\n\n const serializeTotals = totals => {\n const serialized = {};\n Object.keys(totals).forEach(flatKey => {\n serialized[flatKey] = serializeCell(totals[flatKey]);\n });\n return serialized;\n };\n\n return {\n rowKeys: pivotData.rowKeys.map(key => key.slice()),\n colKeys: pivotData.colKeys.map(key => key.slice()),\n tree,\n rowTotals: serializeTotals(pivotData.rowTotals),\n colTotals: serializeTotals(pivotData.colTotals),\n allTotal: serializeCell(pivotData.allTotal),\n aggregations: pivotData.aggregations.map(agg => Object.assign({}, agg)),\n attrValues: materialized.attrValues,\n materializedInput: materialized.materializedInput,\n totalRecords: materialized.totalRecords,\n };\n}\n\n/*\n * Sorters containing functions cannot be structured-cloned into a worker.\n * Returns true when the sorters prop itself, or any of its entries, is a\n * function. In that case PivotData re-sorts on the main thread after\n * hydration (distinct keys are few, so this stays cheap).\n */\nexport function sortersHaveFunctions(sorters) {\n if (typeof sorters === 'function') {\n return true;\n }\n if (!sorters || typeof sorters !== 'object') {\n return false;\n }\n return Object.keys(sorters).some(attr => typeof sorters[attr] === 'function');\n}\n\n/*\n * Returns a structured-cloneable subset of the sorters prop: data-type names\n * and sample-value arrays survive the worker boundary, functions do not.\n */\nexport function sanitizeSorters(sorters) {\n if (\n !sorters ||\n typeof sorters !== 'object' ||\n typeof sorters === 'function'\n ) {\n return {};\n }\n const clean = {};\n Object.keys(sorters).forEach(attr => {\n const sorter = sorters[attr];\n if (typeof sorter === 'string' || Array.isArray(sorter)) {\n clean[attr] = sorter;\n }\n });\n return clean;\n}\n\n/*\n * Extracts exactly the props PivotData needs to compute results, with\n * everything non-serializable stripped, so the object can be posted to the\n * worker and fed straight into PivotData.\n */\nexport function createWorkerConfig(props) {\n return {\n rows: props.rows,\n cols: props.cols,\n aggregatorName: props.aggregatorName,\n aggregations: props.aggregations,\n vals: props.vals,\n valueFilter: props.valueFilter,\n sorters: sanitizeSorters(props.sorters),\n rowOrder: props.rowOrder,\n colOrder: props.colOrder,\n rowSorts: props.rowSorts,\n colSorts: props.colSorts,\n };\n}\n\n/*\n * Stable string signature of everything that influences a worker computation.\n * Data identity is NOT part of it; callers append their own data version.\n */\nexport function createComputeSignature(props) {\n return JSON.stringify(createWorkerConfig(props));\n}\n\n/*\n * Decides whether the current props can be computed inside the Web Worker.\n * Anything that cannot be structured-cloned (function data sources, custom\n * derivedAttributes, custom aggregator maps) forces the classic path.\n * Function-based sorters are allowed: they are re-applied on the main thread.\n */\nexport function canComputeInWorker(props, options = {}) {\n if (options.enabled === false) {\n return false;\n }\n if (typeof Worker === 'undefined') {\n return false;\n }\n const threshold =\n typeof options.threshold === 'number'\n ? options.threshold\n : DEFAULT_WORKER_THRESHOLD;\n\n const data = props.data;\n if (!Array.isArray(data) || data.length < threshold) {\n return false;\n }\n return true;\n}\n"]}
|
package/dist/pivotWorker.js
CHANGED
|
@@ -45,15 +45,7 @@ self.addEventListener('message', function (event) {
|
|
|
45
45
|
var startedAt = Date.now();
|
|
46
46
|
log('#' + message.id + ' setData received: ' + (message.data || []).length + ' records (dataKey=' + message.dataKey + ')');
|
|
47
47
|
try {
|
|
48
|
-
var dataset = cacheDataset(message.dataKey, (0, _pivotCompute.materializeData)(message.data, {}
|
|
49
|
-
postToMain({
|
|
50
|
-
type: 'pivot:progress',
|
|
51
|
-
id: message.id,
|
|
52
|
-
processed: processed,
|
|
53
|
-
total: total,
|
|
54
|
-
phase: 'materialize'
|
|
55
|
-
});
|
|
56
|
-
}));
|
|
48
|
+
var dataset = cacheDataset(message.dataKey, (0, _pivotCompute.materializeData)(message.data, {}));
|
|
57
49
|
log('#' + message.id + ' materialized ' + dataset.totalRecords + ' records in ' + (Date.now() - startedAt + 'ms (attributes: ' + Object.keys(dataset.attrValues).join(', ') + ')'));
|
|
58
50
|
} catch (error) {
|
|
59
51
|
log('#' + message.id + ' setData failed: ' + toErrorMessage(error));
|
|
@@ -75,15 +67,7 @@ self.addEventListener('message', function (event) {
|
|
|
75
67
|
throw new Error('no dataset staged for key ' + message.dataKey);
|
|
76
68
|
}
|
|
77
69
|
log('#' + message.id + ' compute received (rows=[' + (config.rows || []).join(', ') + '] cols=[' + (config.cols || []).join(', ') + '])');
|
|
78
|
-
var result = (0, _pivotCompute.computePivotState)(_dataset, message.config
|
|
79
|
-
postToMain({
|
|
80
|
-
type: 'pivot:progress',
|
|
81
|
-
id: message.id,
|
|
82
|
-
processed: processed,
|
|
83
|
-
total: total,
|
|
84
|
-
phase: phase
|
|
85
|
-
});
|
|
86
|
-
});
|
|
70
|
+
var result = (0, _pivotCompute.computePivotState)(_dataset, message.config);
|
|
87
71
|
log('#' + message.id + ' computed in ' + (Date.now() - _startedAt) + 'ms (rowKeys: ' + result.rowKeys.length + ', colKeys: ' + result.colKeys.length + ', aggregations: ' + result.aggregations.map(function (agg) {
|
|
88
72
|
return agg.key;
|
|
89
73
|
}).join(', ') + ')');
|
package/dist/pivotWorker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pivotWorker.js"],"names":["MAX_CACHED_DATASETS","datasetCache","Map","debugEnabled","cacheDataset","dataKey","dataset","delete","set","size","oldestKey","keys","next","value","postToMain","self","postMessage","message","log","detail","type","toErrorMessage","String","error","addEventListener","event","data","Boolean","enabled","startedAt","Date","now","id","length","
|
|
1
|
+
{"version":3,"sources":["../src/pivotWorker.js"],"names":["MAX_CACHED_DATASETS","datasetCache","Map","debugEnabled","cacheDataset","dataKey","dataset","delete","set","size","oldestKey","keys","next","value","postToMain","self","postMessage","message","log","detail","type","toErrorMessage","String","error","addEventListener","event","data","Boolean","enabled","startedAt","Date","now","id","length","totalRecords","Object","attrValues","join","config","get","Error","rows","cols","result","rowKeys","colKeys","aggregations","map","agg","key"],"mappings":";;AAAA;;AAEA,IAAMA,sBAAsB,CAA5B;;AAEA,IAAMC,eAAe,IAAIC,GAAJ,EAArB;;AAEA,IAAIC,eAAe,KAAnB;;AAEA,IAAMC,eAAe,SAAfA,YAAe,CAACC,OAAD,EAAUC,OAAV,EAAsB;AACzCL,eAAaM,MAAb,CAAoBF,OAApB;AACAJ,eAAaO,GAAb,CAAiBH,OAAjB,EAA0BC,OAA1B;AACA,SAAOL,aAAaQ,IAAb,GAAoBT,mBAA3B,EAAgD;AAC9C,QAAMU,YAAYT,aAAaU,IAAb,GAAoBC,IAApB,GAA2BC,KAA7C;AACAZ,iBAAaM,MAAb,CAAoBG,SAApB;AACD;AACD,SAAOJ,OAAP;AACD,CARD;;AAUA,IAAMQ,aAAa,SAAbA,UAAa,UAAW;AAC5BC,OAAKC,WAAL,CAAiBC,OAAjB;AACD,CAFD;;AAIA,IAAMC,MAAM,SAANA,GAAM,CAACD,OAAD,EAAUE,MAAV,EAAqB;AAC/B,MAAIhB,YAAJ,EAAkB;AAChBW,eAAW,EAACM,MAAM,WAAP,EAAoBH,gBAApB,EAA6BE,cAA7B,EAAX;AACD;AACF,CAJD;;AAMA,IAAME,iBAAiB,SAAjBA,cAAiB;AAAA,SAASC,OAAQC,SAASA,MAAMN,OAAhB,IAA4BM,KAAnC,CAAT;AAAA,CAAvB;;AAEAR,KAAKS,gBAAL,CAAsB,SAAtB,EAAiC,iBAAS;AACxC,MAAMP,UAAUQ,MAAMC,IAAN,IAAc,EAA9B;;AAEA,MAAIT,QAAQG,IAAR,KAAiB,aAArB,EAAoC;AAClCjB,mBAAewB,QAAQV,QAAQ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AAzB,CAHd;AAKA,UAAMM,SAAS,qCAAkBrC,QAAlB,EAA2BW,QAAQqB,MAAnC,CAAf;AACApB,gBACMD,QAAQe,EADd,sBACgCF,KAAKC,GAAL,KAAaF,UAD7C,sBAEIc,OAAOC,OAAP,CAAeX,MAFnB,mBAIIU,OAAOE,OAAP,CAAeZ,MAJnB,wBAKqBU,OAAOG,YAAP,CAAoBC,GAApB,CAAwB;AAAA,eAAOC,IAAIC,GAAX;AAAA,OAAxB,EAAwCZ,IAAxC,CAA6C,IAA7C,CALrB;AAOAvB,iBAAW,EAACM,MAAM,cAAP,EAAuBY,IAAIf,QAAQe,EAAnC,EAAuCW,cAAvC,EAAX;AACD,KAnBD,CAmBE,OAAOpB,KAAP,EAAc;AACdL,gBAAQD,QAAQe,EAAhB,yBAAsCX,eAAeE,KAAf,CAAtC;AACAT,iBAAW;AACTM,cAAM,aADG;AAETY,YAAIf,QAAQe,EAFH;AAGTf,iBAASI,eAAeE,KAAf;AAHA,OAAX;AAKD;AACF;AACF,CArED","file":"pivotWorker.js","sourcesContent":["import {materializeData, computePivotState} from './pivotCompute';\n\nconst MAX_CACHED_DATASETS = 4;\n\nconst datasetCache = new Map();\n\nlet debugEnabled = false;\n\nconst cacheDataset = (dataKey, dataset) => {\n datasetCache.delete(dataKey);\n datasetCache.set(dataKey, dataset);\n while (datasetCache.size > MAX_CACHED_DATASETS) {\n const oldestKey = datasetCache.keys().next().value;\n datasetCache.delete(oldestKey);\n }\n return dataset;\n};\n\nconst postToMain = message => {\n self.postMessage(message);\n};\n\nconst log = (message, detail) => {\n if (debugEnabled) {\n postToMain({type: 'pivot:log', message, detail});\n }\n};\n\nconst toErrorMessage = error => String((error && error.message) || error);\n\nself.addEventListener('message', event => {\n const message = event.data || {};\n\n if (message.type === 'pivot:debug') {\n debugEnabled = Boolean(message.enabled);\n log(`debug logging ${debugEnabled ? 'enabled' : 'disabled'} in worker`);\n return;\n }\n\n if (message.type === 'pivot:setData') {\n const startedAt = Date.now();\n log(\n `#${message.id} setData received: ${\n (message.data || []).length\n } records (dataKey=${message.dataKey})`\n );\n try {\n const dataset = cacheDataset(\n message.dataKey,\n materializeData(message.data, {})\n );\n log(\n `#${message.id} materialized ${dataset.totalRecords} records in ` +\n `${Date.now() - startedAt}ms (attributes: ${Object.keys(\n dataset.attrValues\n ).join(', ')})`\n );\n } catch (error) {\n log(`#${message.id} setData failed: ${toErrorMessage(error)}`);\n postToMain({\n type: 'pivot:error',\n id: message.id,\n message: toErrorMessage(error),\n });\n }\n return;\n }\n\n if (message.type === 'pivot:compute') {\n const startedAt = Date.now();\n const config = message.config || {};\n try {\n const dataset = datasetCache.get(message.dataKey);\n if (!dataset) {\n throw new Error(`no dataset staged for key ${message.dataKey}`);\n }\n log(\n `#${message.id} compute received (rows=[${(config.rows || []).join(\n ', '\n )}] cols=[${(config.cols || []).join(', ')}])`\n );\n const result = computePivotState(dataset, message.config);\n log(\n `#${message.id} computed in ${Date.now() - startedAt}ms (rowKeys: ${\n result.rowKeys.length\n }, colKeys: ${\n result.colKeys.length\n }, aggregations: ${result.aggregations.map(agg => agg.key).join(', ')})`\n );\n postToMain({type: 'pivot:result', id: message.id, result});\n } catch (error) {\n log(`#${message.id} compute failed: ${toErrorMessage(error)}`);\n postToMain({\n type: 'pivot:error',\n id: message.id,\n message: toErrorMessage(error),\n });\n }\n }\n});\n"]}
|
package/dist/pivottable.css
CHANGED
|
@@ -34,6 +34,9 @@ table.pvtTable tbody tr th {
|
|
|
34
34
|
table.pvtTable .pvtColLabel {
|
|
35
35
|
text-align: center;
|
|
36
36
|
}
|
|
37
|
+
table.pvtTable .pvtRowNumber {
|
|
38
|
+
text-align: center;
|
|
39
|
+
}
|
|
37
40
|
table.pvtTable .pvtTotalLabel {
|
|
38
41
|
text-align: right;
|
|
39
42
|
}
|
|
@@ -424,26 +427,6 @@ table.pvtTable tbody tr td {
|
|
|
424
427
|
color: #333;
|
|
425
428
|
}
|
|
426
429
|
|
|
427
|
-
.pvtLoadingBarWrap {
|
|
428
|
-
width: 240px;
|
|
429
|
-
height: 8px;
|
|
430
|
-
background: #ffeeee;
|
|
431
|
-
border-radius: 4px;
|
|
432
|
-
overflow: hidden;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
.pvtLoadingBar {
|
|
436
|
-
height: 100%;
|
|
437
|
-
background: #ff6600;
|
|
438
|
-
transition: width 0.1s ease;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
.pvtLoadingPercent {
|
|
442
|
-
font-size: 12px;
|
|
443
|
-
font-weight: 600;
|
|
444
|
-
color: #ff6600;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
430
|
.pvtComputeError {
|
|
448
431
|
padding: 20px;
|
|
449
432
|
color: #8b0000;
|