sea-chart 0.0.69 → 0.0.70
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/utils/chart-utils/original-data-utils/pivot-table-calculator.js +156 -31
- package/dist/view/wrapper/index.js +1 -0
- package/dist/view/wrapper/table/index.js +2 -2
- package/dist/view/wrapper/table/pivot-table-display-name.js +4 -1
- package/dist/view/wrapper/table/two-dimension-table.js +16 -21
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { FORMULA_COLUMN_TYPES_MAP, isNumber, isDateColumn, isNumericColumn, getTableById, getViewById, getTableColumnByKey } from 'dtable-utils';
|
|
2
|
+
import { isObject } from 'lodash';
|
|
2
3
|
import { CHART_SUMMARY_TYPE, TABLE_DIMENSIONS } from '../../../constants';
|
|
3
4
|
import { isArrayCellValue } from '../../cell-value-utils';
|
|
4
5
|
import { getFormattedLabel, isValidRow } from '../../row-utils';
|
|
5
6
|
import BaseUtils from '../base-utils';
|
|
7
|
+
import { summaryMethodColumn2SqlColumn } from '../../sql/column-2-sql-column';
|
|
6
8
|
async function calculateOneDimensionTable(chart, value, _ref) {
|
|
7
9
|
let {
|
|
8
10
|
getViewRows,
|
|
@@ -167,7 +169,7 @@ function getOneDimensionTotal(columns, summary_type, formula_rows) {
|
|
|
167
169
|
key,
|
|
168
170
|
method
|
|
169
171
|
} = column;
|
|
170
|
-
const totalKey = key
|
|
172
|
+
const totalKey = key;
|
|
171
173
|
const total = getTotal(column, summary_type, method, rows, formula_rows);
|
|
172
174
|
if (column && isDateColumn(column)) {
|
|
173
175
|
if (method === CHART_SUMMARY_TYPE.Distinct_values) {
|
|
@@ -281,18 +283,18 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
|
|
|
281
283
|
if (isGroupbyColumnDataAsAnArray) {
|
|
282
284
|
if (name.length === 0 && include_empty) {
|
|
283
285
|
let pivotRowIndex = pivot_rows.findIndex(r => !r.name);
|
|
284
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, null, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
|
|
286
|
+
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, null, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn, chart, groupbyColumn, table);
|
|
285
287
|
} else {
|
|
286
288
|
name.forEach(n => {
|
|
287
289
|
pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
288
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, n, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
|
|
290
|
+
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, n, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn, chart, groupbyColumn, table);
|
|
289
291
|
});
|
|
290
292
|
}
|
|
291
293
|
} else {
|
|
292
294
|
pivotRowIndex = pivot_rows.findIndex(pivotRow => {
|
|
293
295
|
return isSameName(pivotRow.name, name);
|
|
294
296
|
});
|
|
295
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, name, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn);
|
|
297
|
+
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, name, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn, chart, groupbyColumn, table);
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
300
|
});
|
|
@@ -368,7 +370,48 @@ function updateTwoDimensionColumns(value, pivot_columns, column, row, formulaRow
|
|
|
368
370
|
}
|
|
369
371
|
}
|
|
370
372
|
}
|
|
371
|
-
function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isColumnDataAsAnArray, cellValue) {
|
|
373
|
+
function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isColumnDataAsAnArray, cellValue, chart, groupbyColumn, table) {
|
|
374
|
+
const {
|
|
375
|
+
summary_type,
|
|
376
|
+
summary_columns,
|
|
377
|
+
summary_column_key,
|
|
378
|
+
summary_method
|
|
379
|
+
} = chart;
|
|
380
|
+
const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
|
|
381
|
+
let summarySQLColumnName2ColumnKey = {};
|
|
382
|
+
const numericColumns = [{
|
|
383
|
+
column_key: summary_column_key,
|
|
384
|
+
summary_method: summary_method
|
|
385
|
+
}, ...summary_columns];
|
|
386
|
+
numericColumns.forEach(item => {
|
|
387
|
+
const {
|
|
388
|
+
column_key,
|
|
389
|
+
summary_method: item_summary_method
|
|
390
|
+
} = item;
|
|
391
|
+
const summaryMethod = item_summary_method.toUpperCase();
|
|
392
|
+
const column = getTableColumnByKey(table, column_key);
|
|
393
|
+
if (column && (BaseUtils.isDateSummaryColumn(column) || BaseUtils.isNumericSummaryColumn(column))) {
|
|
394
|
+
const {
|
|
395
|
+
key: sqlNumericColumnKey
|
|
396
|
+
} = summaryMethodColumn2SqlColumn(summaryMethod, column);
|
|
397
|
+
const {
|
|
398
|
+
key: summaryColumnKey
|
|
399
|
+
} = column;
|
|
400
|
+
summarySQLColumnName2ColumnKey[sqlNumericColumnKey] = summaryColumnKey;
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
const summarySQLnames = Object.keys(summarySQLColumnName2ColumnKey);
|
|
404
|
+
const summarySQLColumnKeys = Object.values(summarySQLColumnName2ColumnKey);
|
|
405
|
+
const summaryColumn = getTableColumnByKey(table, summary_column_key) || {};
|
|
406
|
+
const singleNumeriColumnWithMethod = {
|
|
407
|
+
column: summaryColumn,
|
|
408
|
+
summary_method
|
|
409
|
+
};
|
|
410
|
+
const summaryColumnsWithMethod = BaseUtils.getSummaryColumnsWithMethod(table, {
|
|
411
|
+
config: chart
|
|
412
|
+
});
|
|
413
|
+
const multipleNumericColumnsWithMethod = summaryColumnsWithMethod;
|
|
414
|
+
const all = [singleNumeriColumnWithMethod, ...multipleNumericColumnsWithMethod];
|
|
372
415
|
if (index > -1) {
|
|
373
416
|
let updatedPivotRow = pivot_rows[index];
|
|
374
417
|
let {
|
|
@@ -378,36 +421,110 @@ function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isC
|
|
|
378
421
|
let {
|
|
379
422
|
key
|
|
380
423
|
} = c;
|
|
381
|
-
if (isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
424
|
+
if (BaseUtils.isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
382
425
|
if (cells[key]) {
|
|
383
426
|
cells[key].rows.push(row);
|
|
427
|
+
if (isCount) {
|
|
428
|
+
cells[key].total = row[groupbyColumn.key];
|
|
429
|
+
} else {
|
|
430
|
+
cells[key].total = summarySQLColumnKeys.map((columnKey, i) => {
|
|
431
|
+
const current = all.find(item => item.column.key === columnKey);
|
|
432
|
+
const nextValue = row[current === null || current === void 0 ? void 0 : current.column.key];
|
|
433
|
+
const currentValue = Object.values(cells[key].total).find(item => item[2] === columnKey)[1];
|
|
434
|
+
const computedValue = BaseUtils.getSummaryValue({
|
|
435
|
+
summaryMethod: current.summary_method,
|
|
436
|
+
summaryColumn: current.column
|
|
437
|
+
}, currentValue, nextValue);
|
|
438
|
+
const columnName = current.column.name;
|
|
439
|
+
return [columnName, computedValue, columnKey];
|
|
440
|
+
});
|
|
441
|
+
}
|
|
384
442
|
} else {
|
|
443
|
+
let total;
|
|
444
|
+
if (isCount) {
|
|
445
|
+
total = row[groupbyColumn.key];
|
|
446
|
+
} else {
|
|
447
|
+
total = summarySQLColumnKeys.map((columnKey, i) => {
|
|
448
|
+
var _current$column;
|
|
449
|
+
const current = all.find(item => item.column.key === columnKey);
|
|
450
|
+
const value = row[current === null || current === void 0 ? void 0 : (_current$column = current.column) === null || _current$column === void 0 ? void 0 : _current$column.key];
|
|
451
|
+
const columnName = current.column.name;
|
|
452
|
+
// keep column key to find currentValue on updating
|
|
453
|
+
return [columnName, value, columnKey];
|
|
454
|
+
});
|
|
455
|
+
}
|
|
385
456
|
cells[key] = {
|
|
386
|
-
rows: [row]
|
|
457
|
+
rows: [row],
|
|
458
|
+
total
|
|
387
459
|
};
|
|
388
460
|
}
|
|
389
461
|
}
|
|
390
462
|
});
|
|
391
463
|
updatedPivotRow.cells = cells;
|
|
464
|
+
// sum up
|
|
465
|
+
if (isCount) {
|
|
466
|
+
updatedPivotRow.total = Object.values(cells).reduce((acc, item) => {
|
|
467
|
+
acc += item.total;
|
|
468
|
+
return acc;
|
|
469
|
+
}, 0);
|
|
470
|
+
} else {
|
|
471
|
+
updatedPivotRow.total = Object.values(cells).reduce((acc, item) => {
|
|
472
|
+
item.total.forEach(t => {
|
|
473
|
+
isNumber(t[1]) && (acc += t[1]);
|
|
474
|
+
});
|
|
475
|
+
return acc;
|
|
476
|
+
}, 0);
|
|
477
|
+
}
|
|
392
478
|
pivot_rows[index] = updatedPivotRow;
|
|
393
|
-
|
|
394
|
-
let cells = {};
|
|
395
|
-
pivot_columns.forEach(c => {
|
|
396
|
-
let {
|
|
397
|
-
key
|
|
398
|
-
} = c;
|
|
399
|
-
if (isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
400
|
-
cells[key] = {
|
|
401
|
-
rows: [row]
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
pivot_rows.push({
|
|
406
|
-
name,
|
|
407
|
-
original_name: name,
|
|
408
|
-
cells
|
|
409
|
-
});
|
|
479
|
+
return;
|
|
410
480
|
}
|
|
481
|
+
|
|
482
|
+
// add a new row
|
|
483
|
+
let cells = {};
|
|
484
|
+
let total = 0;
|
|
485
|
+
pivot_columns.forEach(c => {
|
|
486
|
+
let {
|
|
487
|
+
key
|
|
488
|
+
} = c;
|
|
489
|
+
if (BaseUtils.isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
490
|
+
let total;
|
|
491
|
+
if (isCount) {
|
|
492
|
+
total = row[groupbyColumn.key];
|
|
493
|
+
} else {
|
|
494
|
+
total = summarySQLColumnKeys.map((columnKey, i) => {
|
|
495
|
+
var _current$column2;
|
|
496
|
+
const current = all.find(item => item.column.key === columnKey);
|
|
497
|
+
const value = row[current === null || current === void 0 ? void 0 : (_current$column2 = current.column) === null || _current$column2 === void 0 ? void 0 : _current$column2.key];
|
|
498
|
+
const columnName = current.column.name;
|
|
499
|
+
return [columnName, value, columnKey];
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
cells[key] = {
|
|
503
|
+
rows: [row],
|
|
504
|
+
total
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
const cellList = Object.values(cells);
|
|
509
|
+
total = cellList.reduce((acc, item) => {
|
|
510
|
+
let num;
|
|
511
|
+
if (isObject(item.total)) {
|
|
512
|
+
num = item.total.reduce((acc, item) => {
|
|
513
|
+
isNumber(item[1]) && (acc += item[1]);
|
|
514
|
+
return acc;
|
|
515
|
+
}, 0);
|
|
516
|
+
} else {
|
|
517
|
+
num = item.total;
|
|
518
|
+
}
|
|
519
|
+
acc += num;
|
|
520
|
+
return acc;
|
|
521
|
+
}, 0);
|
|
522
|
+
pivot_rows.push({
|
|
523
|
+
name,
|
|
524
|
+
original_name: name,
|
|
525
|
+
cells,
|
|
526
|
+
total
|
|
527
|
+
});
|
|
411
528
|
}
|
|
412
529
|
function isSameName(prevName, currName) {
|
|
413
530
|
if (isNumber(prevName) && isNumber(currName)) {
|
|
@@ -445,10 +562,11 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
|
|
|
445
562
|
key
|
|
446
563
|
} = pivotColumn;
|
|
447
564
|
if (cells[key]) {
|
|
565
|
+
var _cells$key;
|
|
448
566
|
let {
|
|
449
567
|
rows
|
|
450
568
|
} = cells[key];
|
|
451
|
-
let subTotal = getTotal(summaryColumn, summary_type, summary_method, rows, formula_rows);
|
|
569
|
+
let subTotal = getTotal(summaryColumn, summary_type, summary_method, rows, formula_rows, (_cells$key = cells[key]) === null || _cells$key === void 0 ? void 0 : _cells$key.total);
|
|
452
570
|
if (isSummaryDateColumn) {
|
|
453
571
|
if (subTotal === 0) {
|
|
454
572
|
cells[key].total = 0;
|
|
@@ -456,13 +574,13 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
|
|
|
456
574
|
subTotal.key = key;
|
|
457
575
|
subTotal.name = pivotRow.name;
|
|
458
576
|
dateColumnsTotalArr.push(subTotal);
|
|
459
|
-
cells[key].total = subTotal.date;
|
|
577
|
+
// cells[key].total = subTotal.date;
|
|
460
578
|
}
|
|
461
579
|
} else {
|
|
462
580
|
cells[key].total = subTotal;
|
|
463
|
-
total += subTotal ? subTotal - 0 : 0;
|
|
581
|
+
total += subTotal[0][1] ? subTotal[0][1] - 0 : 0;
|
|
464
582
|
let columnTotal = pivot_columns_total[key] ? pivot_columns_total[key] : 0;
|
|
465
|
-
columnTotal += subTotal ? subTotal - 0 : 0;
|
|
583
|
+
columnTotal += subTotal[0][1] ? subTotal[0][1] - 0 : 0;
|
|
466
584
|
pivot_columns_total[key] = columnTotal;
|
|
467
585
|
}
|
|
468
586
|
}
|
|
@@ -494,6 +612,7 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
|
|
|
494
612
|
function getTotal(summary_column, summary_type, summary_method) {
|
|
495
613
|
let rows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
496
614
|
let formula_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
615
|
+
let oldTotal = arguments.length > 5 ? arguments[5] : undefined;
|
|
497
616
|
const summary_column_key = summary_column ? summary_column.key : '';
|
|
498
617
|
const summary_column_type = summary_column ? summary_column.type : '';
|
|
499
618
|
const rowsLength = rows.length;
|
|
@@ -536,7 +655,8 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
536
655
|
let value = r[summary_column_key];
|
|
537
656
|
if (FORMULA_COLUMN_TYPES_MAP[summary_column_type]) {
|
|
538
657
|
let formulaRow = formula_rows[r._id] || {};
|
|
539
|
-
value = formulaRow[summary_column_key];
|
|
658
|
+
value = formulaRow[summary_column_key] || '';
|
|
659
|
+
value = Array.isArray(value) && value.length !== 0 ? value[0] : '';
|
|
540
660
|
}
|
|
541
661
|
if (!value) return;
|
|
542
662
|
if (value.indexOf('T') !== -1) {
|
|
@@ -581,9 +701,14 @@ function getTotal(summary_column, summary_type, summary_method) {
|
|
|
581
701
|
}
|
|
582
702
|
});
|
|
583
703
|
if (summary_method === 'Sum') {
|
|
584
|
-
|
|
704
|
+
const newTotal = JSON.parse(JSON.stringify(oldTotal));
|
|
705
|
+
newTotal[0][1] = Number.parseFloat(sum.toFixed(8));
|
|
706
|
+
total = newTotal;
|
|
585
707
|
} else if (summary_method === 'Mean') {
|
|
586
|
-
|
|
708
|
+
const newTotal = JSON.parse(JSON.stringify(oldTotal));
|
|
709
|
+
const val = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
|
|
710
|
+
newTotal[0][1] = val;
|
|
711
|
+
total = newTotal;
|
|
587
712
|
}
|
|
588
713
|
break;
|
|
589
714
|
}
|
|
@@ -83,6 +83,7 @@ const Wrapper = _ref => {
|
|
|
83
83
|
if (!result) return null;
|
|
84
84
|
return /*#__PURE__*/React.createElement(Table, Object.assign({}, baseProps, {
|
|
85
85
|
summaryColumns: summary_columns,
|
|
86
|
+
columnGroupbyColumn: columnGroupbyColumn,
|
|
86
87
|
summaryMethod: summary_method,
|
|
87
88
|
chartTableColumns: chartTableColumns,
|
|
88
89
|
isCalculateByView: isCalculateByView
|
|
@@ -107,7 +107,10 @@ class PivotTableDisplayName extends React.Component {
|
|
|
107
107
|
case CellType.SINGLE_SELECT:
|
|
108
108
|
{
|
|
109
109
|
const options = getColumnOptions(column);
|
|
110
|
-
|
|
110
|
+
let option = getOption(options, value) || {};
|
|
111
|
+
if (Object.keys(option).length === 0) {
|
|
112
|
+
option = options.find(item => item.name === value) || {};
|
|
113
|
+
}
|
|
111
114
|
displayName = /*#__PURE__*/React.createElement(React.Fragment, null, this.renderSelectOption(option));
|
|
112
115
|
break;
|
|
113
116
|
}
|
|
@@ -126,21 +126,23 @@ class TwoDimensionTable extends PureComponent {
|
|
|
126
126
|
total
|
|
127
127
|
}, selectedCell);
|
|
128
128
|
};
|
|
129
|
-
this.
|
|
130
|
-
|
|
129
|
+
this.renderEmpty = (summaryColumns, cellIdx) => {
|
|
130
|
+
if (summaryColumns && (summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.length) !== 0) {
|
|
131
|
+
return summaryColumns.map(() => {
|
|
132
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
133
|
+
key: "table-cell-".concat(cellIdx),
|
|
134
|
+
className: classnames('pivot-cell', {
|
|
135
|
+
'pivot-empty-cell': true
|
|
136
|
+
})
|
|
137
|
+
}, /*#__PURE__*/React.createElement("i", null));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
131
140
|
return /*#__PURE__*/React.createElement("div", {
|
|
132
141
|
key: "table-cell-".concat(cellIdx),
|
|
133
142
|
className: classnames('pivot-cell', {
|
|
134
|
-
'pivot-empty-cell':
|
|
135
|
-
'selected-pivot-cell': isSelectedCell,
|
|
136
|
-
'selected-pivot-cell-top': isSelectedCellTop,
|
|
137
|
-
'selected-pivot-cell-left': isSelectedCellLeft
|
|
138
|
-
})
|
|
139
|
-
}, isValidDisplayValue ? total : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
|
|
140
|
-
className: classnames({
|
|
141
|
-
'selected-pivot-cell-border': isSelectedCell
|
|
143
|
+
'pivot-empty-cell': true
|
|
142
144
|
})
|
|
143
|
-
}));
|
|
145
|
+
}, /*#__PURE__*/React.createElement("i", null));
|
|
144
146
|
};
|
|
145
147
|
this.renderRows = () => {
|
|
146
148
|
const {
|
|
@@ -250,9 +252,9 @@ class TwoDimensionTable extends PureComponent {
|
|
|
250
252
|
key: "table-cell-".concat(cellIdx)
|
|
251
253
|
}, /*#__PURE__*/React.createElement("div", {
|
|
252
254
|
className: classnames('pivot-cells-container')
|
|
253
|
-
},
|
|
255
|
+
}, total && total.map && total.map((summaryCell, idx) => {
|
|
254
256
|
const summaryCellColumnKey = summaryCell[2];
|
|
255
|
-
const summaryCellColumn = summaryColumns.find(item => item.key === summaryCellColumnKey);
|
|
257
|
+
const summaryCellColumn = summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.find(item => item.key === summaryCellColumnKey);
|
|
256
258
|
const displayValue = BaseUtils.getSummaryValueDisplayString(summaryCellColumn, summaryCell[1], summaryMethod);
|
|
257
259
|
const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
|
|
258
260
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -268,14 +270,7 @@ class TwoDimensionTable extends PureComponent {
|
|
|
268
270
|
'selected-pivot-cell-border': isSelectedCell
|
|
269
271
|
})
|
|
270
272
|
}));
|
|
271
|
-
}), !
|
|
272
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
273
|
-
key: "table-cell-".concat(cellIdx),
|
|
274
|
-
className: classnames('pivot-cell', {
|
|
275
|
-
'pivot-empty-cell': true
|
|
276
|
-
})
|
|
277
|
-
}, /*#__PURE__*/React.createElement("i", null));
|
|
278
|
-
})), isCalculateByView && this.renderByView(total, display_empty, cellIdx, isSelectedCell, isSelectedCellTop, isSelectedCellLeft)));
|
|
273
|
+
}), !total && this.renderEmpty(summaryColumns, cellIdx)));
|
|
279
274
|
}), display_total && /*#__PURE__*/React.createElement("td", {
|
|
280
275
|
className: classnames('pivot-cell', {
|
|
281
276
|
'pivot-empty-cell': !isValidSummaryDisplayValue,
|