UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

67 lines 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAggregationAndCalcFuncByQuery = exports.sortByItems = exports.customFlattenDeep = exports.filterOutDetail = exports.getListBySorted = void 0; const lodash_1 = require("lodash"); const field_1 = require("../common/constant/field"); 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; }); }; exports.getListBySorted = getListBySorted; const filterOutDetail = (values = []) => { return values.filter((v) => v !== field_1.TOTAL_VALUE && v !== field_1.EMPTY_EXTRA_FIELD_PLACEHOLDER); }; exports.filterOutDetail = filterOutDetail; const customFlattenDeep = (data) => { if (!(0, lodash_1.isArray)(data)) { return [data]; } return (0, lodash_1.flattenDeep)(data); }; exports.customFlattenDeep = customFlattenDeep; /** * arr1包含arr2,将arr2排到最后 * */ 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); }; exports.sortByItems = sortByItems; 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)); } exports.getAggregationAndCalcFuncByQuery = getAggregationAndCalcFuncByQuery; //# sourceMappingURL=data-set-operate.js.map