@antv/s2
Version:
effective spreadsheet render core lib
59 lines • 2.27 kB
JavaScript
import { flattenDeep, isArray } from 'lodash';
import { EMPTY_EXTRA_FIELD_PLACEHOLDER, TOTAL_VALUE, } from '../common/constant/field';
export const getListBySorted = (list, sorted, mapValue) => {
return list.sort((a, b) => {
if (mapValue) {
a = mapValue(a);
b = mapValue(b);
}
const ia = sorted.indexOf(a);
const ib = sorted.indexOf(b);
if (ia === -1 && ib === -1) {
return 0;
}
if (ia === -1) {
return 1;
}
if (ib === -1) {
return -1;
}
return ia - ib;
});
};
export const filterOutDetail = (values = []) => {
return values.filter((v) => v !== TOTAL_VALUE && v !== EMPTY_EXTRA_FIELD_PLACEHOLDER);
};
export const customFlattenDeep = (data) => {
if (!isArray(data)) {
return [data];
}
return flattenDeep(data);
};
/**
* arr1包含arr2,将arr2排到最后
*
*/
export const sortByItems = (arr1, arr2) => {
var _a;
return (_a = arr1 === null || arr1 === void 0 ? void 0 : arr1.filter((item) => !(arr2 === null || arr2 === void 0 ? void 0 : arr2.includes(item)))) === null || _a === void 0 ? void 0 : _a.concat(arr2);
};
export function getAggregationAndCalcFuncByQuery(totalsStatus, totalsOptions) {
const { isRowGrandTotal, isRowSubTotal, isColGrandTotal, isColSubTotal } = totalsStatus;
const { row, col } = totalsOptions || {};
const { calcGrandTotals: rowCalcTotals = {}, calcSubTotals: rowCalcSubTotals = {}, } = row || {};
const { calcGrandTotals: colCalcTotals = {}, calcSubTotals: colCalcSubTotals = {}, } = col || {};
const getCalcTotals = (dimensionTotals, isTotal) => {
if ((dimensionTotals.aggregation || dimensionTotals.calcFunc) && isTotal) {
return {
aggregation: dimensionTotals.aggregation,
calcFunc: dimensionTotals.calcFunc,
};
}
};
// 优先级: 列总计/小计 > 行总计/小计
return (getCalcTotals(colCalcTotals, isColGrandTotal) ||
getCalcTotals(colCalcSubTotals, isColSubTotal) ||
getCalcTotals(rowCalcTotals, isRowGrandTotal) ||
getCalcTotals(rowCalcSubTotals, isRowSubTotal));
}
//# sourceMappingURL=data-set-operate.js.map