UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

48 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addTotals = void 0; const lodash_1 = require("lodash"); const constant_1 = require("../../common/constant"); const total_class_1 = require("../../facet/layout/total-class"); const addTotals = (params) => { var _a; const { isFirstField, currentField, fieldValues, spreadsheet, lastField } = params; const totalsConfig = spreadsheet.getTotalsConfig(isFirstField ? currentField : lastField); let action; let totalValue; if (isFirstField) { // check to see if grand total is added if (totalsConfig === null || totalsConfig === void 0 ? void 0 : totalsConfig.showGrandTotals) { action = totalsConfig.reverseGrandTotalsLayout ? 'unshift' : 'push'; totalValue = new total_class_1.TotalClass({ label: totalsConfig.grandTotalsLabel, isSubTotals: false, isGrandTotals: true, isTotalRoot: true, }); } } else if ( /** * 是否需要展示小计项 * 1. showSubTotals 属性为真 * 2. 子维度个数 > 1 或 showSubTotals.always 不为 false(undefined 认为是 true) */ (totalsConfig === null || totalsConfig === void 0 ? void 0 : totalsConfig.showSubTotals) && ((0, lodash_1.size)(fieldValues) > 1 || (0, lodash_1.get)(totalsConfig, 'showSubTotals.always') !== false) && currentField !== constant_1.EXTRA_FIELD) { action = totalsConfig.reverseSubTotalsLayout ? 'unshift' : 'push'; totalValue = new total_class_1.TotalClass({ label: totalsConfig.subTotalsLabel, isSubTotals: true, isGrandTotals: false, isTotalRoot: true, }); } if (action) { (_a = fieldValues[action]) === null || _a === void 0 ? void 0 : _a.call(fieldValues, totalValue); } }; exports.addTotals = addTotals; //# sourceMappingURL=add-totals.js.map