sea-chart 0.0.99 → 0.0.100
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/context.js +2 -2
- package/dist/settings/index.js +9 -4
- package/dist/settings/widgets/data-filter/index.js +6 -1
- package/dist/settings/widgets/select-view/index.js +5 -2
- package/dist/utils/chart-utils/base-utils.js +226 -6
- package/dist/utils/chart-utils/original-data-utils/index.js +7 -3
- package/dist/utils/chart-utils/original-data-utils/pivot-table-calculator.js +10 -27
- package/dist/utils/chart-utils/sql-statistics-utils.js +29 -144
- package/dist/utils/contexts.js +2 -1
- package/dist/utils/row-utils.js +0 -8
- package/dist/utils/sql/chart-data-sql.js +2 -8
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -102,8 +102,8 @@ class Context {
|
|
|
102
102
|
this.getViewRows = (view, table, value) => {
|
|
103
103
|
return this.api.getViewRows(view, table, value);
|
|
104
104
|
};
|
|
105
|
-
this.getTableFormulaResults = (table, rows, value) => {
|
|
106
|
-
return this.api.getTableFormulaResults(table, rows, value);
|
|
105
|
+
this.getTableFormulaResults = (table, rows, value, view_id) => {
|
|
106
|
+
return this.api.getTableFormulaResults(table, rows, value, view_id);
|
|
107
107
|
};
|
|
108
108
|
this.getChartImageUrl = type => {
|
|
109
109
|
const name = CHART_TYPE_IMAGE[type];
|
package/dist/settings/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import React, { useCallback, useMemo, useState, useEffect } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import intl from '../intl';
|
|
5
|
-
import { settingsContext } from '../utils/contexts';
|
|
5
|
+
import { settingsContext, DepartmentsContext } from '../utils/contexts';
|
|
6
6
|
import { eventStopPropagation } from '../utils';
|
|
7
7
|
import { BaseUtils } from '../utils';
|
|
8
8
|
import { CHART_SETTINGS_TYPE, CHART_SETTINGS } from '../constants';
|
|
@@ -18,7 +18,8 @@ const Settings = _ref => {
|
|
|
18
18
|
hideTitleStyleSetting,
|
|
19
19
|
tables,
|
|
20
20
|
onChange,
|
|
21
|
-
children
|
|
21
|
+
children,
|
|
22
|
+
departments
|
|
22
23
|
} = _ref;
|
|
23
24
|
const [type, setType] = useState(CHART_SETTINGS_TYPE.DATA);
|
|
24
25
|
const [labelColorConfigs, setLabelColorConfigs] = useState([]);
|
|
@@ -83,12 +84,16 @@ const Settings = _ref => {
|
|
|
83
84
|
}, /*#__PURE__*/React.createElement("div", {
|
|
84
85
|
id: "sea-chart-settings-content",
|
|
85
86
|
className: "chart-settings-content"
|
|
86
|
-
}, type === CHART_SETTINGS_TYPE.DATA && /*#__PURE__*/React.createElement(
|
|
87
|
+
}, type === CHART_SETTINGS_TYPE.DATA && /*#__PURE__*/React.createElement(DepartmentsContext.Provider, {
|
|
88
|
+
value: {
|
|
89
|
+
departments
|
|
90
|
+
}
|
|
91
|
+
}, /*#__PURE__*/React.createElement(DataSettings, {
|
|
87
92
|
dataSources: dataSources,
|
|
88
93
|
chart: chart,
|
|
89
94
|
tables: tables,
|
|
90
95
|
onChange: modifyStatistic
|
|
91
|
-
}), type === CHART_SETTINGS_TYPE.CHART_STYLE && /*#__PURE__*/React.createElement(StyleSettings, {
|
|
96
|
+
})), type === CHART_SETTINGS_TYPE.CHART_STYLE && /*#__PURE__*/React.createElement(StyleSettings, {
|
|
92
97
|
chart: chart,
|
|
93
98
|
tables: tables,
|
|
94
99
|
labelColorConfigs: labelColorConfigs,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _DTableFiltersPopover from "dtable-ui-component/lib/DTableFiltersPopover";
|
|
2
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useContext, useMemo, useState } from 'react';
|
|
3
3
|
import { Label, FormGroup } from 'reactstrap';
|
|
4
4
|
import { getTableById } from 'dtable-utils';
|
|
5
5
|
import { eventStopPropagation, generatorKey } from '../../../utils';
|
|
6
6
|
import intl from '../../../intl';
|
|
7
7
|
import context from '../../../context';
|
|
8
|
+
import { DepartmentsContext } from '../../../utils/contexts';
|
|
8
9
|
import './index.css';
|
|
9
10
|
const DataFilter = _ref => {
|
|
10
11
|
let {
|
|
@@ -13,6 +14,9 @@ const DataFilter = _ref => {
|
|
|
13
14
|
onChange
|
|
14
15
|
} = _ref;
|
|
15
16
|
const [isFilterSetterShow, setIsFilterSetterShow] = useState(false);
|
|
17
|
+
const {
|
|
18
|
+
departments
|
|
19
|
+
} = useContext(DepartmentsContext);
|
|
16
20
|
const toggleFilterPopover = useCallback(event => {
|
|
17
21
|
eventStopPropagation(event);
|
|
18
22
|
setIsFilterSetterShow(!isFilterSetterShow);
|
|
@@ -77,6 +81,7 @@ const DataFilter = _ref => {
|
|
|
77
81
|
filters: filters,
|
|
78
82
|
filterConjunction: filterConjunction,
|
|
79
83
|
columns: table.columns,
|
|
84
|
+
departments: departments,
|
|
80
85
|
collaborators: collaborators,
|
|
81
86
|
hidePopover: toggleFilterPopover,
|
|
82
87
|
update: updateFilters
|
|
@@ -16,11 +16,14 @@ const SelectView = _ref => {
|
|
|
16
16
|
const table = getTableById(tables, selectedTableId);
|
|
17
17
|
if (!table) return [];
|
|
18
18
|
let views = getNonPrivateViews(table.views);
|
|
19
|
-
|
|
19
|
+
let selectedView = views.find(view => view._id === selectedViewId);
|
|
20
|
+
if (!selectedView) {
|
|
21
|
+
selectedView = views[0];
|
|
22
|
+
}
|
|
20
23
|
|
|
21
24
|
// not support archive view on plugin, do not show archive view
|
|
22
25
|
// but if it is selected, keep it
|
|
23
|
-
if (!isArchiveView(selectedView)) {
|
|
26
|
+
if (selectedView && !isArchiveView(selectedView)) {
|
|
24
27
|
views = views.filter(v => !isArchiveView(v));
|
|
25
28
|
}
|
|
26
29
|
return Array.isArray(views) ? views.map(view => {
|
|
@@ -233,10 +233,6 @@ BaseUtils.getChartGroups = charts => {
|
|
|
233
233
|
};
|
|
234
234
|
BaseUtils.isSameGroup = (isColumnDataAsAnArray, source, target) => {
|
|
235
235
|
if (isColumnDataAsAnArray) {
|
|
236
|
-
// column type is multiple-select
|
|
237
|
-
if (Array.isArray(source) && Array.isArray(target)) {
|
|
238
|
-
return JSON.stringify(source) === JSON.stringify(target);
|
|
239
|
-
}
|
|
240
236
|
return (!Array.isArray(source) || source.length === 0) && !target || (source === null || source === void 0 ? void 0 : source.includes(target));
|
|
241
237
|
}
|
|
242
238
|
return source === null && target === null || source === undefined && target === undefined || source === target;
|
|
@@ -288,7 +284,7 @@ BaseUtils.isDateSummaryColumn = summaryColumn => {
|
|
|
288
284
|
} = summaryColumn;
|
|
289
285
|
return type !== CellType.LINK && isDateColumn(summaryColumn);
|
|
290
286
|
};
|
|
291
|
-
BaseUtils.getSummaryValue = (_ref, currentValue, nextValue) => {
|
|
287
|
+
BaseUtils.getSummaryValue = (_ref, currentValue, nextValue, isPivotCalculator) => {
|
|
292
288
|
let {
|
|
293
289
|
summaryMethod,
|
|
294
290
|
summaryColumn
|
|
@@ -314,7 +310,7 @@ BaseUtils.getSummaryValue = (_ref, currentValue, nextValue) => {
|
|
|
314
310
|
if (currentValue === null && nextValue === null) return null;
|
|
315
311
|
if (currentValue === null) return nextValue;
|
|
316
312
|
if (nextValue === null) return currentValue;
|
|
317
|
-
if (currentValue && nextValue) {
|
|
313
|
+
if (currentValue && nextValue && isPivotCalculator) {
|
|
318
314
|
if (summaryMethod === 'MAX') {
|
|
319
315
|
return Math.max(currentValue, nextValue);
|
|
320
316
|
}
|
|
@@ -1365,6 +1361,188 @@ BaseUtils.summaryDurationResult = (result, duration, summaryType, summaryMethod,
|
|
|
1365
1361
|
comparedValue
|
|
1366
1362
|
};
|
|
1367
1363
|
};
|
|
1364
|
+
BaseUtils.formatedTableSqlRowsByCollaboratorAndMultiple = (chart, sqlRows, chartSQLMap, columnMap) => {
|
|
1365
|
+
const {
|
|
1366
|
+
config
|
|
1367
|
+
} = chart;
|
|
1368
|
+
const {
|
|
1369
|
+
columnGroupbyColumn
|
|
1370
|
+
} = columnMap; // columnMap is selected columns for row grouping and column grouping
|
|
1371
|
+
let {
|
|
1372
|
+
sqlGroupbyColumnKey,
|
|
1373
|
+
sqlSummaryColumnKey,
|
|
1374
|
+
summarySQLColumnName2ColumnKey,
|
|
1375
|
+
sqlColumnGroupbyColumnKey
|
|
1376
|
+
} = chartSQLMap;
|
|
1377
|
+
const newSqlRows = JSON.parse(JSON.stringify(sqlRows));
|
|
1378
|
+
if (config.summary_type === CHART_SUMMARY_TYPE.COUNT) {
|
|
1379
|
+
// has column group
|
|
1380
|
+
if (sqlColumnGroupbyColumnKey) {
|
|
1381
|
+
if ((columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === CellType.COLLABORATOR) {
|
|
1382
|
+
return newSqlRows;
|
|
1383
|
+
}
|
|
1384
|
+
if ((columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === CellType.MULTIPLE_SELECT) {
|
|
1385
|
+
return newSqlRows;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
// no has column group
|
|
1390
|
+
if (!sqlColumnGroupbyColumnKey) {
|
|
1391
|
+
sqlRows.forEach((sqlRow, index) => {
|
|
1392
|
+
const collaborators = sqlRow[sqlGroupbyColumnKey];
|
|
1393
|
+
// Multiple collaborators
|
|
1394
|
+
if ((collaborators === null || collaborators === void 0 ? void 0 : collaborators.length) > 1) {
|
|
1395
|
+
const oldCollaboratorCount = sqlRow[sqlSummaryColumnKey];
|
|
1396
|
+
newSqlRows.splice(index, 1);
|
|
1397
|
+
collaborators.forEach(item => {
|
|
1398
|
+
const rowIndex = newSqlRows.findIndex(rows => {
|
|
1399
|
+
var _rows$sqlGroupbyColum;
|
|
1400
|
+
return ((_rows$sqlGroupbyColum = rows[sqlGroupbyColumnKey]) === null || _rows$sqlGroupbyColum === void 0 ? void 0 : _rows$sqlGroupbyColum[0]) === item;
|
|
1401
|
+
});
|
|
1402
|
+
if (rowIndex !== -1) {
|
|
1403
|
+
if (newSqlRows[rowIndex][sqlSummaryColumnKey] && oldCollaboratorCount) {
|
|
1404
|
+
newSqlRows[rowIndex][sqlSummaryColumnKey] = newSqlRows[rowIndex][sqlSummaryColumnKey] + oldCollaboratorCount;
|
|
1405
|
+
}
|
|
1406
|
+
} else {
|
|
1407
|
+
const obj = {};
|
|
1408
|
+
if (sqlGroupbyColumnKey) {
|
|
1409
|
+
obj[sqlGroupbyColumnKey] = [item];
|
|
1410
|
+
}
|
|
1411
|
+
if (sqlSummaryColumnKey) {
|
|
1412
|
+
obj[sqlSummaryColumnKey] = oldCollaboratorCount;
|
|
1413
|
+
}
|
|
1414
|
+
newSqlRows.push({
|
|
1415
|
+
...sqlRow,
|
|
1416
|
+
...obj
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if (config.summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
1425
|
+
let summarySQLColumnName2ColumnKeys;
|
|
1426
|
+
if (summarySQLColumnName2ColumnKey) {
|
|
1427
|
+
summarySQLColumnName2ColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
|
|
1428
|
+
} else if (sqlColumnGroupbyColumnKey) {
|
|
1429
|
+
summarySQLColumnName2ColumnKeys = [sqlColumnGroupbyColumnKey];
|
|
1430
|
+
} else {
|
|
1431
|
+
console.error('on formatedTableSqlRows: summarySQLColumnName2ColumnKey is null');
|
|
1432
|
+
return [];
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// has column group
|
|
1436
|
+
if (sqlColumnGroupbyColumnKey) {
|
|
1437
|
+
if ((columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === CellType.COLLABORATOR) {
|
|
1438
|
+
return newSqlRows;
|
|
1439
|
+
}
|
|
1440
|
+
if ((columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === CellType.MULTIPLE_SELECT) {
|
|
1441
|
+
return newSqlRows;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// Add a quantity field to calculate the average
|
|
1445
|
+
newSqlRows.forEach(item => {
|
|
1446
|
+
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
1447
|
+
if (key.startsWith('AVG')) {
|
|
1448
|
+
item["COUNT(".concat(key.slice(3), ")")] = item['COUNT(*)'];
|
|
1449
|
+
// Update avg
|
|
1450
|
+
const newKey = 'SUM' + key.slice(3);
|
|
1451
|
+
item[key] = item[newKey] / item["COUNT(".concat(key.slice(3), ")")];
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// no has column group
|
|
1458
|
+
if (!sqlColumnGroupbyColumnKey) {
|
|
1459
|
+
// Add a quantity field to calculate the average
|
|
1460
|
+
newSqlRows.forEach(item => {
|
|
1461
|
+
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
1462
|
+
if (key.startsWith('AVG')) {
|
|
1463
|
+
item["COUNT(".concat(key.slice(3), ")")] = item['COUNT(*)'];
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
sqlRows.forEach((item, index) => {
|
|
1468
|
+
const collaborators = item[sqlGroupbyColumnKey];
|
|
1469
|
+
// Multiple collaborators
|
|
1470
|
+
if ((collaborators === null || collaborators === void 0 ? void 0 : collaborators.length) > 1) {
|
|
1471
|
+
newSqlRows.splice(index, 1);
|
|
1472
|
+
collaborators.forEach(collaborator => {
|
|
1473
|
+
const rowIndex = newSqlRows.findIndex(rows => {
|
|
1474
|
+
var _rows$sqlGroupbyColum2;
|
|
1475
|
+
return ((_rows$sqlGroupbyColum2 = rows[sqlGroupbyColumnKey]) === null || _rows$sqlGroupbyColum2 === void 0 ? void 0 : _rows$sqlGroupbyColum2[0]) === collaborator;
|
|
1476
|
+
});
|
|
1477
|
+
// has same collaborator
|
|
1478
|
+
if (rowIndex !== -1) {
|
|
1479
|
+
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
1480
|
+
let newKey = key;
|
|
1481
|
+
// Avg: The avg is calculated by sum / count
|
|
1482
|
+
if (key.startsWith('AVG')) {
|
|
1483
|
+
newKey = 'SUM' + key.slice(3);
|
|
1484
|
+
newSqlRows[rowIndex]["COUNT(".concat(key.slice(3), ")")] = newSqlRows[rowIndex]["COUNT(".concat(key.slice(3), ")")] + item['COUNT(*)'];
|
|
1485
|
+
}
|
|
1486
|
+
// Sum
|
|
1487
|
+
if (newKey.startsWith('SUM') && newSqlRows[rowIndex][newKey]) {
|
|
1488
|
+
newSqlRows[rowIndex][newKey] = newSqlRows[rowIndex][newKey] + item[newKey];
|
|
1489
|
+
}
|
|
1490
|
+
// Min
|
|
1491
|
+
if (key.startsWith('MIN')) {
|
|
1492
|
+
const oldValue = item[newKey];
|
|
1493
|
+
const newValue = newSqlRows[rowIndex][newKey];
|
|
1494
|
+
newSqlRows[rowIndex][newKey] = Math.min(oldValue, newValue);
|
|
1495
|
+
}
|
|
1496
|
+
// Max
|
|
1497
|
+
if (key.startsWith('MAX')) {
|
|
1498
|
+
const oldValue = item[newKey];
|
|
1499
|
+
const newValue = newSqlRows[rowIndex][newKey];
|
|
1500
|
+
newSqlRows[rowIndex][newKey] = Math.max(oldValue, newValue);
|
|
1501
|
+
}
|
|
1502
|
+
// DISTINCT
|
|
1503
|
+
if (key.includes('DISTINCT')) {
|
|
1504
|
+
newSqlRows[rowIndex][newKey] = newSqlRows[rowIndex][newKey] + item[newKey];
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
} else {
|
|
1508
|
+
// no has same collaborator
|
|
1509
|
+
const obj = {};
|
|
1510
|
+
if (sqlGroupbyColumnKey) {
|
|
1511
|
+
obj[sqlGroupbyColumnKey] = [collaborator];
|
|
1512
|
+
}
|
|
1513
|
+
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
1514
|
+
let newKey = key;
|
|
1515
|
+
// Avg: The avg is calculated by sum / count
|
|
1516
|
+
if (key.startsWith('AVG')) {
|
|
1517
|
+
newKey = 'SUM' + key.slice(3);
|
|
1518
|
+
obj["COUNT(".concat(key.slice(3), ")")] = item['COUNT(*)'];
|
|
1519
|
+
}
|
|
1520
|
+
// Sum
|
|
1521
|
+
if (newKey.startsWith('SUM')) {
|
|
1522
|
+
obj[newKey] = item[newKey];
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
newSqlRows.push({
|
|
1526
|
+
...item,
|
|
1527
|
+
...obj
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
newSqlRows.forEach(item => {
|
|
1534
|
+
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
1535
|
+
// Update avg
|
|
1536
|
+
if (key.startsWith('AVG')) {
|
|
1537
|
+
const newKey = 'SUM' + key.slice(3);
|
|
1538
|
+
item[key] = item[newKey] / item["COUNT(".concat(key.slice(3), ")")];
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
return newSqlRows;
|
|
1545
|
+
};
|
|
1368
1546
|
BaseUtils.mergePivotTableSameCollaborator = pivot_rows => {
|
|
1369
1547
|
const new_pivot_rows = [];
|
|
1370
1548
|
pivot_rows.forEach(item => {
|
|
@@ -1426,4 +1604,46 @@ BaseUtils.recalculateAvg = sqlRows => {
|
|
|
1426
1604
|
});
|
|
1427
1605
|
return sqlRows;
|
|
1428
1606
|
};
|
|
1607
|
+
BaseUtils.updateCollaboratorAndMultipleAvg = (pivot_rows, all) => {
|
|
1608
|
+
const new_pivot_rows = JSON.parse(JSON.stringify(pivot_rows));
|
|
1609
|
+
// All summary field columns
|
|
1610
|
+
all.forEach(item => {
|
|
1611
|
+
if ((item === null || item === void 0 ? void 0 : item.summary_method.toUpperCase()) === 'MEAN') {
|
|
1612
|
+
const avgColumnName = item.column.name;
|
|
1613
|
+
const avgColumnKey = item.column.key;
|
|
1614
|
+
new_pivot_rows.forEach(rows => {
|
|
1615
|
+
Object.values(rows.cells).forEach(cell => {
|
|
1616
|
+
// get all sum and count
|
|
1617
|
+
let allSum = 0;
|
|
1618
|
+
let allCount = 0;
|
|
1619
|
+
cell.rows.forEach(r => {
|
|
1620
|
+
allSum = allSum + r["SUM(".concat(avgColumnName, ")")];
|
|
1621
|
+
allCount = allCount + r["COUNT(*)"];
|
|
1622
|
+
});
|
|
1623
|
+
|
|
1624
|
+
// set avg, avg = sum / count
|
|
1625
|
+
cell.total.forEach((item, index) => {
|
|
1626
|
+
if (Array.isArray(item) && item[2] === avgColumnKey) {
|
|
1627
|
+
cell.total[index][1] = allSum / allCount;
|
|
1628
|
+
}
|
|
1629
|
+
});
|
|
1630
|
+
});
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
return new_pivot_rows;
|
|
1635
|
+
};
|
|
1636
|
+
BaseUtils.isCollaboratorColumnOrMultipleColumn = columnMap => {
|
|
1637
|
+
const {
|
|
1638
|
+
columnGroupbyColumn,
|
|
1639
|
+
groupbyColumn
|
|
1640
|
+
} = columnMap || {};
|
|
1641
|
+
if (columnGroupbyColumn && groupbyColumn && (columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === CellType.COLLABORATOR && (groupbyColumn === null || groupbyColumn === void 0 ? void 0 : groupbyColumn.type) === CellType.COLLABORATOR) {
|
|
1642
|
+
return true;
|
|
1643
|
+
}
|
|
1644
|
+
if (columnGroupbyColumn && groupbyColumn && (columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === CellType.MULTIPLE_SELECT && (groupbyColumn === null || groupbyColumn === void 0 ? void 0 : groupbyColumn.type) === CellType.MULTIPLE_SELECT) {
|
|
1645
|
+
return true;
|
|
1646
|
+
}
|
|
1647
|
+
return false;
|
|
1648
|
+
};
|
|
1429
1649
|
export default BaseUtils;
|
|
@@ -60,16 +60,20 @@ OriginalDataUtils.calculateChart = async (chart, value, callback) => {
|
|
|
60
60
|
} = chart;
|
|
61
61
|
const {
|
|
62
62
|
table_id,
|
|
63
|
+
view_id,
|
|
63
64
|
type
|
|
64
65
|
} = config || {};
|
|
65
66
|
const table = getTableById(value.tables, table_id);
|
|
66
67
|
const calculator = calculatorMap[type] || calculatorMap[BASIC_CHART];
|
|
67
68
|
const result = await calculator(config, value, {
|
|
68
|
-
getViewRows: (view, table) => {
|
|
69
|
-
const rows = context.getViewRows(view, table, value);
|
|
69
|
+
getViewRows: async (view, table) => {
|
|
70
|
+
const rows = await context.getViewRows(view, table, value);
|
|
70
71
|
return rows;
|
|
71
72
|
},
|
|
72
|
-
getTableFormulaResults: (table, rows) =>
|
|
73
|
+
getTableFormulaResults: async (table, rows) => {
|
|
74
|
+
const res = await context.getTableFormulaResults(table, rows, value, view_id);
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
73
77
|
});
|
|
74
78
|
const groupbyColumn = BaseUtils.getGroupColumn(table, chart);
|
|
75
79
|
const columnGroupbyColumn = BaseUtils.getColumnGroupColumn(table, chart);
|
|
@@ -261,16 +261,10 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
|
|
|
261
261
|
let pivotRowIndex = pivot_rows.findIndex(r => !r.name);
|
|
262
262
|
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, null, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn, chart, groupbyColumn, table);
|
|
263
263
|
} else {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
pivotRowIndex
|
|
267
|
-
|
|
268
|
-
} else {
|
|
269
|
-
name.forEach(n => {
|
|
270
|
-
pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
271
|
-
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, n, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn, chart, groupbyColumn, table);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
264
|
+
name.forEach(n => {
|
|
265
|
+
pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
266
|
+
updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, n, row, isRowGroupbyColumnDataAsAnArray, cellValueForColumn, chart, groupbyColumn, table);
|
|
267
|
+
});
|
|
274
268
|
}
|
|
275
269
|
} else {
|
|
276
270
|
pivotRowIndex = pivot_rows.findIndex(pivotRow => {
|
|
@@ -364,26 +358,15 @@ function updateTwoDimensionColumns(value, pivot_columns, column, row, formulaRow
|
|
|
364
358
|
});
|
|
365
359
|
}
|
|
366
360
|
} else {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const pivotColumnIndex = pivot_columns.findIndex(r => JSON.stringify(r.key) === JSON.stringify(key));
|
|
361
|
+
key.forEach(k => {
|
|
362
|
+
pivotColumnIndex = pivot_columns.findIndex(r => r.key === k);
|
|
370
363
|
if (pivotColumnIndex < 0) {
|
|
371
364
|
pivot_columns.push({
|
|
372
|
-
key:
|
|
373
|
-
original_key:
|
|
365
|
+
key: k,
|
|
366
|
+
original_key: k
|
|
374
367
|
});
|
|
375
368
|
}
|
|
376
|
-
}
|
|
377
|
-
key.forEach(k => {
|
|
378
|
-
pivotColumnIndex = pivot_columns.findIndex(r => r.key === k);
|
|
379
|
-
if (pivotColumnIndex < 0) {
|
|
380
|
-
pivot_columns.push({
|
|
381
|
-
key: k,
|
|
382
|
-
original_key: k
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
}
|
|
369
|
+
});
|
|
387
370
|
}
|
|
388
371
|
} else {
|
|
389
372
|
pivotColumnIndex = pivot_columns.findIndex(r => {
|
|
@@ -464,7 +447,7 @@ function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isC
|
|
|
464
447
|
const computedValue = BaseUtils.getSummaryValue({
|
|
465
448
|
summaryMethod: current.summary_method.toUpperCase(),
|
|
466
449
|
summaryColumn: current.column
|
|
467
|
-
}, currentValue, nextValue);
|
|
450
|
+
}, currentValue, nextValue, true);
|
|
468
451
|
const columnName = current.column.name;
|
|
469
452
|
return [columnName, computedValue, columnKey];
|
|
470
453
|
});
|
|
@@ -102,121 +102,6 @@ SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, chart) => {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
SQLStatisticsUtils.formatedTableSqlRows = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
106
|
-
const {
|
|
107
|
-
config
|
|
108
|
-
} = chart;
|
|
109
|
-
let {
|
|
110
|
-
sqlGroupbyColumnKey,
|
|
111
|
-
sqlSummaryColumnKey,
|
|
112
|
-
summarySQLColumnName2ColumnKey,
|
|
113
|
-
sqlColumnGroupbyColumnKey
|
|
114
|
-
} = chartSQLMap;
|
|
115
|
-
const newSqlRows = JSON.parse(JSON.stringify(sqlRows));
|
|
116
|
-
if (config.summary_type === CHART_SUMMARY_TYPE.COUNT) {
|
|
117
|
-
sqlRows.forEach((item, index) => {
|
|
118
|
-
const collaborators = item[sqlGroupbyColumnKey];
|
|
119
|
-
// Multiple collaborators
|
|
120
|
-
if ((collaborators === null || collaborators === void 0 ? void 0 : collaborators.length) > 1) {
|
|
121
|
-
newSqlRows.splice(index, 1);
|
|
122
|
-
collaborators.forEach(item => {
|
|
123
|
-
const rowIndex = newSqlRows.findIndex(rows => {
|
|
124
|
-
var _rows$sqlGroupbyColum;
|
|
125
|
-
return ((_rows$sqlGroupbyColum = rows[sqlGroupbyColumnKey]) === null || _rows$sqlGroupbyColum === void 0 ? void 0 : _rows$sqlGroupbyColum[0]) === item;
|
|
126
|
-
});
|
|
127
|
-
if (rowIndex !== -1) {
|
|
128
|
-
if (newSqlRows[rowIndex][sqlSummaryColumnKey]) {
|
|
129
|
-
newSqlRows[rowIndex][sqlSummaryColumnKey] = newSqlRows[rowIndex][sqlSummaryColumnKey] + 1;
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
const obj = {};
|
|
133
|
-
if (sqlGroupbyColumnKey) {
|
|
134
|
-
obj[sqlGroupbyColumnKey] = [item];
|
|
135
|
-
}
|
|
136
|
-
if (sqlSummaryColumnKey) {
|
|
137
|
-
obj[sqlSummaryColumnKey] = 1;
|
|
138
|
-
}
|
|
139
|
-
newSqlRows.push({
|
|
140
|
-
...item,
|
|
141
|
-
...obj
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (config.summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
|
|
149
|
-
let summarySQLColumnName2ColumnKeys;
|
|
150
|
-
if (summarySQLColumnName2ColumnKey) {
|
|
151
|
-
summarySQLColumnName2ColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
|
|
152
|
-
} else if (sqlColumnGroupbyColumnKey) {
|
|
153
|
-
summarySQLColumnName2ColumnKeys = [sqlColumnGroupbyColumnKey];
|
|
154
|
-
} else {
|
|
155
|
-
console.error('on formatedTableSqlRows: summarySQLColumnName2ColumnKey is null');
|
|
156
|
-
return [];
|
|
157
|
-
}
|
|
158
|
-
sqlRows.forEach((item, index) => {
|
|
159
|
-
const collaborators = item[sqlGroupbyColumnKey];
|
|
160
|
-
// Multiple collaborators
|
|
161
|
-
if ((collaborators === null || collaborators === void 0 ? void 0 : collaborators.length) > 1) {
|
|
162
|
-
newSqlRows.splice(index, 1);
|
|
163
|
-
collaborators.forEach(collaborator => {
|
|
164
|
-
const rowIndex = newSqlRows.findIndex(rows => {
|
|
165
|
-
var _rows$sqlGroupbyColum2;
|
|
166
|
-
return ((_rows$sqlGroupbyColum2 = rows[sqlGroupbyColumnKey]) === null || _rows$sqlGroupbyColum2 === void 0 ? void 0 : _rows$sqlGroupbyColum2[0]) === collaborator;
|
|
167
|
-
});
|
|
168
|
-
if (rowIndex !== -1) {
|
|
169
|
-
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
170
|
-
let newKey = key;
|
|
171
|
-
// The avg is calculated by sum column
|
|
172
|
-
if (key.startsWith('AVG')) {
|
|
173
|
-
newKey = 'SUM' + key.slice(3);
|
|
174
|
-
}
|
|
175
|
-
// Update sum and count
|
|
176
|
-
if (newKey.startsWith('SUM') && newSqlRows[rowIndex][newKey]) {
|
|
177
|
-
newSqlRows[rowIndex][newKey] = newSqlRows[rowIndex][newKey] + item[newKey];
|
|
178
|
-
}
|
|
179
|
-
if (newSqlRows[rowIndex]['COUNT(*)']) {
|
|
180
|
-
newSqlRows[rowIndex]['COUNT(*)'] = newSqlRows[rowIndex]['COUNT(*)'] + 1;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
} else {
|
|
184
|
-
const obj = {};
|
|
185
|
-
if (sqlGroupbyColumnKey) {
|
|
186
|
-
obj[sqlGroupbyColumnKey] = [collaborator];
|
|
187
|
-
}
|
|
188
|
-
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
189
|
-
let newKey = key;
|
|
190
|
-
// The avg is calculated by sum column
|
|
191
|
-
if (key.startsWith('AVG')) {
|
|
192
|
-
newKey = 'SUM' + key.slice(3);
|
|
193
|
-
}
|
|
194
|
-
// Update sum and count
|
|
195
|
-
if (newKey.startsWith('SUM')) {
|
|
196
|
-
obj[newKey] = item[newKey];
|
|
197
|
-
}
|
|
198
|
-
obj['COUNT(*)'] = 1;
|
|
199
|
-
});
|
|
200
|
-
newSqlRows.push({
|
|
201
|
-
...item,
|
|
202
|
-
...obj
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
newSqlRows.forEach(item => {
|
|
209
|
-
summarySQLColumnName2ColumnKeys.forEach(key => {
|
|
210
|
-
// Update avg
|
|
211
|
-
if (key.startsWith('AVG')) {
|
|
212
|
-
const newKey = 'SUM' + key.slice(3);
|
|
213
|
-
item[key] = item[newKey] / item['COUNT(*)'];
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
return newSqlRows;
|
|
219
|
-
};
|
|
220
105
|
SQLStatisticsUtils.getGroupData = (result, groupColumn) => {
|
|
221
106
|
const {
|
|
222
107
|
options = {}
|
|
@@ -252,18 +137,6 @@ SQLStatisticsUtils.updateTwoDimensionColumns = (pivot_columns, key, _ref, column
|
|
|
252
137
|
}
|
|
253
138
|
return;
|
|
254
139
|
}
|
|
255
|
-
|
|
256
|
-
// columnGroupbyColumn is multiple-select use equal
|
|
257
|
-
if ((columnGroupbyColumn === null || columnGroupbyColumn === void 0 ? void 0 : columnGroupbyColumn.type) === 'multiple-select') {
|
|
258
|
-
const pivotColumnIndex = pivot_columns.findIndex(r => JSON.stringify(r.key) === JSON.stringify(key));
|
|
259
|
-
if (pivotColumnIndex < 0) {
|
|
260
|
-
pivot_columns.push({
|
|
261
|
-
key: key,
|
|
262
|
-
original_key: key
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
140
|
key.forEach(k => {
|
|
268
141
|
const pivotColumnIndex = pivot_columns.findIndex(r => r.key === k);
|
|
269
142
|
if (pivotColumnIndex < 0) {
|
|
@@ -288,7 +161,7 @@ SQLStatisticsUtils.updateTwoDimensionColumns = (pivot_columns, key, _ref, column
|
|
|
288
161
|
};
|
|
289
162
|
SQLStatisticsUtils.updateTwoDimensionRows = (chart, pivot_rows, pivot_columns, index, name,
|
|
290
163
|
// count,
|
|
291
|
-
row, isColumnDataAsAnArray, cellValue, _ref2, chartSQLMap) => {
|
|
164
|
+
row, isColumnDataAsAnArray, cellValue, _ref2, chartSQLMap, columnMap) => {
|
|
292
165
|
let {
|
|
293
166
|
singleNumeriColumnWithMethod,
|
|
294
167
|
multipleNumericColumnsWithMethod
|
|
@@ -323,7 +196,11 @@ row, isColumnDataAsAnArray, cellValue, _ref2, chartSQLMap) => {
|
|
|
323
196
|
if (cells[key]) {
|
|
324
197
|
cells[key].rows.push(row);
|
|
325
198
|
if (isCount) {
|
|
326
|
-
|
|
199
|
+
if (BaseUtils.isCollaboratorColumnOrMultipleColumn(columnMap)) {
|
|
200
|
+
cells[key].total = total + row[sqlSummaryColumnKey];
|
|
201
|
+
} else {
|
|
202
|
+
cells[key].total = row[sqlSummaryColumnKey];
|
|
203
|
+
}
|
|
327
204
|
} else {
|
|
328
205
|
cells[key].total = summarySQLColumnKeys.map((columnKey, i) => {
|
|
329
206
|
const current = all.find(item => item.column.key === columnKey);
|
|
@@ -332,9 +209,9 @@ row, isColumnDataAsAnArray, cellValue, _ref2, chartSQLMap) => {
|
|
|
332
209
|
// use columnKey to find current value
|
|
333
210
|
const currentValue = Object.values(cells[key].total).find(item => item[2] === columnKey)[1];
|
|
334
211
|
const computedValue = BaseUtils.getSummaryValue({
|
|
335
|
-
summaryMethod: current.summary_method,
|
|
212
|
+
summaryMethod: current.summary_method.toUpperCase(),
|
|
336
213
|
summaryColumn: current.column
|
|
337
|
-
}, currentValue, nextValue);
|
|
214
|
+
}, currentValue, nextValue, BaseUtils.isCollaboratorColumnOrMultipleColumn(columnMap));
|
|
338
215
|
const columnName = current.column.name;
|
|
339
216
|
|
|
340
217
|
// keep column key to find currentValue on updating
|
|
@@ -478,8 +355,8 @@ SQLStatisticsUtils.oneDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
|
|
|
478
355
|
let pivot_rows = [];
|
|
479
356
|
const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
|
|
480
357
|
let newSqlRows = sqlRows;
|
|
481
|
-
if (
|
|
482
|
-
newSqlRows =
|
|
358
|
+
if ([CellType.COLLABORATOR, CellType.MULTIPLE_SELECT].includes(groupbyColumn.type)) {
|
|
359
|
+
newSqlRows = BaseUtils.formatedTableSqlRowsByCollaboratorAndMultiple(chart, sqlRows, chartSQLMap, columnMap);
|
|
483
360
|
}
|
|
484
361
|
if (isCount) {
|
|
485
362
|
let allTotal = 0;
|
|
@@ -595,8 +472,8 @@ SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
|
|
|
595
472
|
// const summaryMethod = (summary_method || 'sum').toUpperCase();
|
|
596
473
|
|
|
597
474
|
let newSqlRows = sqlRows;
|
|
598
|
-
if (
|
|
599
|
-
newSqlRows =
|
|
475
|
+
if ([CellType.COLLABORATOR, CellType.MULTIPLE_SELECT].includes(groupbyColumn.type)) {
|
|
476
|
+
newSqlRows = BaseUtils.formatedTableSqlRowsByCollaboratorAndMultiple(chart, sqlRows, chartSQLMap, columnMap);
|
|
600
477
|
}
|
|
601
478
|
let pivot_columns = [];
|
|
602
479
|
let pivot_rows = [];
|
|
@@ -636,15 +513,17 @@ SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
|
|
|
636
513
|
row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, {
|
|
637
514
|
singleNumeriColumnWithMethod,
|
|
638
515
|
multipleNumericColumnsWithMethod
|
|
639
|
-
}, chartSQLMap);
|
|
516
|
+
}, chartSQLMap, columnMap);
|
|
640
517
|
} else {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
518
|
+
groupbyColumnCellValueKey.forEach(n => {
|
|
519
|
+
let pivotRowIndex = pivot_rows.findIndex(r => n === r.name);
|
|
520
|
+
_SQLStatisticsUtils.updateTwoDimensionRows(chart, pivot_rows, pivot_columns, pivotRowIndex, n,
|
|
521
|
+
// count,
|
|
522
|
+
row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, {
|
|
523
|
+
singleNumeriColumnWithMethod,
|
|
524
|
+
multipleNumericColumnsWithMethod
|
|
525
|
+
}, chartSQLMap, columnMap);
|
|
526
|
+
});
|
|
648
527
|
}
|
|
649
528
|
} else {
|
|
650
529
|
let pivotRowIndex = pivot_rows.findIndex(r => {
|
|
@@ -656,10 +535,16 @@ SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
|
|
|
656
535
|
row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, {
|
|
657
536
|
singleNumeriColumnWithMethod,
|
|
658
537
|
multipleNumericColumnsWithMethod
|
|
659
|
-
}, chartSQLMap);
|
|
538
|
+
}, chartSQLMap, columnMap);
|
|
660
539
|
}
|
|
661
540
|
}
|
|
662
541
|
});
|
|
542
|
+
|
|
543
|
+
// update Collaborator and Multiple mean value
|
|
544
|
+
if (BaseUtils.isCollaboratorColumnOrMultipleColumn(columnMap)) {
|
|
545
|
+
const new_pivot_rows = BaseUtils.updateCollaboratorAndMultipleAvg(pivot_rows, [singleNumeriColumnWithMethod, ...multipleNumericColumnsWithMethod]);
|
|
546
|
+
pivot_rows = new_pivot_rows;
|
|
547
|
+
}
|
|
663
548
|
[pivot_columns_total, pivot_table_total] = _SQLStatisticsUtils.getAndUpdateTwoDimensionTotal(pivot_columns_total, pivot_columns, pivot_rows,
|
|
664
549
|
// { summaryMethod, summaryColumn }
|
|
665
550
|
pivot_table_total, chart);
|
package/dist/utils/contexts.js
CHANGED
package/dist/utils/row-utils.js
CHANGED
|
@@ -29,7 +29,6 @@ export const isValidRow = (row, formulaRow, column, includeEmpty) => {
|
|
|
29
29
|
}
|
|
30
30
|
return cellValue || cellValue === 0;
|
|
31
31
|
};
|
|
32
|
-
const RETURN_ARRAY_CHART_TYPES = [CHART_TYPE.TABLE];
|
|
33
32
|
export const getFormattedLabel = (column, name, collaborators, chartType) => {
|
|
34
33
|
let {
|
|
35
34
|
type: columnType,
|
|
@@ -51,13 +50,6 @@ export const getFormattedLabel = (column, name, collaborators, chartType) => {
|
|
|
51
50
|
return optionName;
|
|
52
51
|
}
|
|
53
52
|
} else if (columnType === CellType.MULTIPLE_SELECT) {
|
|
54
|
-
// Return the array directly and process it in the rendering, file directly: src/view/wrapper/table/pivot-table-display-name.js
|
|
55
|
-
if (RETURN_ARRAY_CHART_TYPES.includes(chartType)) {
|
|
56
|
-
if (Array.isArray(name)) {
|
|
57
|
-
return name;
|
|
58
|
-
}
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
53
|
const options = getColumnOptions(column);
|
|
62
54
|
let selectedOption = getOption(options, name);
|
|
63
55
|
let {
|
|
@@ -475,8 +475,8 @@ class ChartDataSQL {
|
|
|
475
475
|
}
|
|
476
476
|
});
|
|
477
477
|
|
|
478
|
-
// groupby_column is COLLABORATOR , replace AVG with SUM, and add 'COUNT(*)'
|
|
479
|
-
if (groupby_column.type === CellType.COLLABORATOR) {
|
|
478
|
+
// groupby_column is COLLABORATOR or MULTIPLE_SELECT, replace AVG with SUM, and add 'COUNT(*)'
|
|
479
|
+
if (groupby_column.type === CellType.COLLABORATOR || groupby_column.type === CellType.MULTIPLE_SELECT) {
|
|
480
480
|
summary_column_names.forEach((item, index) => {
|
|
481
481
|
if (item.startsWith('AVG')) {
|
|
482
482
|
summary_column_names[index] = 'SUM' + item.slice(3);
|
|
@@ -484,12 +484,6 @@ class ChartDataSQL {
|
|
|
484
484
|
});
|
|
485
485
|
summary_column_names.push('COUNT(*)');
|
|
486
486
|
}
|
|
487
|
-
summary_column_names.forEach((item, index) => {
|
|
488
|
-
if (item.startsWith('AVG')) {
|
|
489
|
-
const group_column_name = this._summary_column_2_sql('ROW_COUNT', groupby_column);
|
|
490
|
-
summary_column_names[index] = item + ',SUM' + item.slice(3) + ",".concat(group_column_name);
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
487
|
let summary_column_names_str = summary_column_names.join(', ');
|
|
494
488
|
return summary_column_names_str;
|
|
495
489
|
};
|