diff --git a/packages/s2-core/__tests__/bugs/issue-1668-spec.ts b/packages/s2-core/__tests__/bugs/issue-1668-spec.ts index 70a264dcd4..95cd6b24f3 100644 --- a/packages/s2-core/__tests__/bugs/issue-1668-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-1668-spec.ts @@ -16,15 +16,15 @@ const s2Options: S2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, diff --git a/packages/s2-core/__tests__/bugs/issue-1715-spec.ts b/packages/s2-core/__tests__/bugs/issue-1715-spec.ts index 66284677b0..682d3f62d6 100644 --- a/packages/s2-core/__tests__/bugs/issue-1715-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-1715-spec.ts @@ -21,14 +21,14 @@ const s2Options: S2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, }, }, }; diff --git a/packages/s2-core/__tests__/bugs/issue-2164-spec.ts b/packages/s2-core/__tests__/bugs/issue-2164-spec.ts index 8a0b08ba4e..394da2dc35 100644 --- a/packages/s2-core/__tests__/bugs/issue-2164-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-2164-spec.ts @@ -19,7 +19,7 @@ const s2Options: S2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, + reverseGrandTotalsLayout: true, }, }, }; diff --git a/packages/s2-core/__tests__/bugs/issue-368-spec.ts b/packages/s2-core/__tests__/bugs/issue-368-spec.ts index ab6950b527..13811f313c 100644 --- a/packages/s2-core/__tests__/bugs/issue-368-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-368-spec.ts @@ -15,15 +15,15 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['row0', 'row1'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['col0', 'col1'], }, }, diff --git a/packages/s2-core/__tests__/bugs/issue-372-spec.ts b/packages/s2-core/__tests__/bugs/issue-372-spec.ts index abf1d28e56..9daa59634e 100644 --- a/packages/s2-core/__tests__/bugs/issue-372-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-372-spec.ts @@ -18,8 +18,8 @@ const s2Options: S2Options = { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['col0', 'col1'], }, }, diff --git a/packages/s2-core/__tests__/bugs/issue-836-spec.ts b/packages/s2-core/__tests__/bugs/issue-836-spec.ts index 2eacab3b07..1a3493816c 100644 --- a/packages/s2-core/__tests__/bugs/issue-836-spec.ts +++ b/packages/s2-core/__tests__/bugs/issue-836-spec.ts @@ -18,8 +18,8 @@ const s2Options: S2Options = { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['col0', 'col1'], }, }, diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index c7642b81bc..091737f76d 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -376,15 +376,15 @@ describe('SpreadSheet Hidden Columns Tests', () => { col: { showGrandTotals: true, showSubTotals: false, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, }, @@ -465,15 +465,15 @@ describe('SpreadSheet Hidden Columns Tests', () => { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, }, diff --git a/packages/s2-core/__tests__/spreadsheet/row-link-spec.ts b/packages/s2-core/__tests__/spreadsheet/row-link-spec.ts index 1dde291dc6..8318c46d5b 100644 --- a/packages/s2-core/__tests__/spreadsheet/row-link-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/row-link-spec.ts @@ -11,7 +11,7 @@ const s2Options: S2Options = { row: { showSubTotals: true, subTotalsDimensions: ['province'], - reverseSubLayout: true, + reverseSubTotalsLayout: true, }, }, interaction: { diff --git a/packages/s2-core/__tests__/spreadsheet/spread-sheet-facet-layout-api-spec.ts b/packages/s2-core/__tests__/spreadsheet/spread-sheet-facet-layout-api-spec.ts index 8d10c3bb5d..d711058a39 100644 --- a/packages/s2-core/__tests__/spreadsheet/spread-sheet-facet-layout-api-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/spread-sheet-facet-layout-api-spec.ts @@ -663,8 +663,8 @@ describe('Facet Layout API Tests', () => { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, }, }, }, @@ -851,8 +851,8 @@ describe('Facet Layout API Tests', () => { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, }, }, }, diff --git a/packages/s2-core/__tests__/spreadsheet/theme-spec.ts b/packages/s2-core/__tests__/spreadsheet/theme-spec.ts index f1a30b13ec..c2f85d459c 100644 --- a/packages/s2-core/__tests__/spreadsheet/theme-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/theme-spec.ts @@ -345,14 +345,14 @@ describe('SpreadSheet Theme Tests', () => { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: false, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: false, }, row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: false, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: false, }, }, }); diff --git a/packages/s2-core/__tests__/unit/data-set/pivot-data-set-total-spec.ts b/packages/s2-core/__tests__/unit/data-set/pivot-data-set-total-spec.ts index 5fdb31c0a9..2f741230e1 100644 --- a/packages/s2-core/__tests__/unit/data-set/pivot-data-set-total-spec.ts +++ b/packages/s2-core/__tests__/unit/data-set/pivot-data-set-total-spec.ts @@ -240,7 +240,7 @@ describe('Pivot Dataset Total Test', () => { totals: { row: { ...TOTALS_OPTIONS?.row, - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { @@ -249,7 +249,7 @@ describe('Pivot Dataset Total Test', () => { }, col: { ...TOTALS_OPTIONS?.col, - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { @@ -359,7 +359,7 @@ describe('Pivot Dataset Total Test', () => { showGrandTotals: true, showSubTotals: true, subTotalsDimensions: ['city'], - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { @@ -370,7 +370,7 @@ describe('Pivot Dataset Total Test', () => { showGrandTotals: true, showSubTotals: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { @@ -447,7 +447,7 @@ describe('Pivot Dataset Total Test', () => { totals: { row: { ...TOTALS_OPTIONS?.row, - calcTotals: { + calcGrandTotals: { calcFunc: calcFunc1, }, calcSubTotals: { @@ -456,7 +456,7 @@ describe('Pivot Dataset Total Test', () => { }, col: { ...TOTALS_OPTIONS?.col, - calcTotals: { + calcGrandTotals: { calcFunc: calcFunc2, }, calcSubTotals: { diff --git a/packages/s2-core/__tests__/unit/utils/data-set-operate-spec.tsx b/packages/s2-core/__tests__/unit/utils/data-set-operate-spec.tsx index 638fa2b83a..5fd2938768 100644 --- a/packages/s2-core/__tests__/unit/utils/data-set-operate-spec.tsx +++ b/packages/s2-core/__tests__/unit/utils/data-set-operate-spec.tsx @@ -73,7 +73,7 @@ describe('Data Set Operate Test', () => { beforeEach(() => { totalsOptions = { row: { - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { @@ -81,7 +81,7 @@ describe('Data Set Operate Test', () => { }, }, col: { - calcTotals: { + calcGrandTotals: { calcFunc: () => 'colTotals', }, calcSubTotals: { diff --git a/packages/s2-core/__tests__/unit/utils/export/copy-spec.ts b/packages/s2-core/__tests__/unit/utils/export/copy-spec.ts index e478424ed1..4687639bf2 100644 --- a/packages/s2-core/__tests__/unit/utils/export/copy-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/export/copy-spec.ts @@ -586,10 +586,10 @@ describe('Pivot Table Core Data Process', () => { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { @@ -599,10 +599,10 @@ describe('Pivot Table Core Data Process', () => { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { aggregation: Aggregation.SUM, }, calcSubTotals: { diff --git a/packages/s2-core/__tests__/unit/utils/sort-action-spec.tsx b/packages/s2-core/__tests__/unit/utils/sort-action-spec.tsx index d0b47d1b57..3f0c6bc0e5 100644 --- a/packages/s2-core/__tests__/unit/utils/sort-action-spec.tsx +++ b/packages/s2-core/__tests__/unit/utils/sort-action-spec.tsx @@ -484,7 +484,7 @@ describe('GetSortByMeasureValues Total Fallback Tests', () => { calcSubTotals: { aggregation: 'SUM', }, - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, }, @@ -492,7 +492,7 @@ describe('GetSortByMeasureValues Total Fallback Tests', () => { showSubTotals: true, showGrandTotals: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { diff --git a/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts b/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts index 77957440d4..8a8f52025c 100644 --- a/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/tooltip-spec.ts @@ -401,16 +401,16 @@ describe('Tooltip Utils Tests', () => { const rowTotalOptions: Total = { showGrandTotals: true, showSubTotals: true, - reverseLayout: false, - reverseSubLayout: false, + reverseGrandTotalsLayout: false, + reverseSubTotalsLayout: false, subTotalsDimensions: ['province'], }; const colTotalOptions: Total = { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }; diff --git a/packages/s2-core/src/common/constant/basic.ts b/packages/s2-core/src/common/constant/basic.ts index b034df2c79..fed224ae21 100644 --- a/packages/s2-core/src/common/constant/basic.ts +++ b/packages/s2-core/src/common/constant/basic.ts @@ -96,5 +96,6 @@ export const getDefaultSeriesNumberText = (defaultText?: string) => defaultText ?? i18n('序号'); export const getDefaultCornerText = () => i18n('指标'); + // 省略号 export const ELLIPSIS_SYMBOL = '...'; diff --git a/packages/s2-core/src/common/constant/options.ts b/packages/s2-core/src/common/constant/options.ts index 946b4b00bb..e8ac966ad8 100644 --- a/packages/s2-core/src/common/constant/options.ts +++ b/packages/s2-core/src/common/constant/options.ts @@ -20,7 +20,7 @@ export const SPLIT_LINE_WIDTH = 1; export const DEFAULT_TREE_ROW_WIDTH = 120; -export const DEFAULT_STYLE: Readonly = { +export const DEFAULT_STYLE: S2Style = { layoutWidthType: LayoutWidthTypes.Adaptive, dataCell: { width: 96, @@ -38,7 +38,7 @@ export const DEFAULT_STYLE: Readonly = { }, }; -export const DEFAULT_OPTIONS: Readonly = { +export const DEFAULT_OPTIONS: S2Options = { width: 600, height: 480, debug: false, @@ -108,7 +108,7 @@ export const DEFAULT_OPTIONS: Readonly = { const mobileWidth = document.documentElement.clientWidth; -export const DEFAULT_MOBILE_OPTIONS: Readonly = { +export const DEFAULT_MOBILE_OPTIONS: S2Options = { width: mobileWidth - 40, height: 380, style: { diff --git a/packages/s2-core/src/common/interface/basic.ts b/packages/s2-core/src/common/interface/basic.ts index 2618198ea4..633d905bfd 100644 --- a/packages/s2-core/src/common/interface/basic.ts +++ b/packages/s2-core/src/common/interface/basic.ts @@ -139,38 +139,67 @@ export enum Aggregation { export interface CalcTotals { /** 聚合方式 */ aggregation?: Aggregation; - /** 自定义计算 */ - calcFunc?: (query: Query, arr: CellData[]) => number; + + /** + * 自定义计算汇总 + * @see https://s2.antv.antgroup.com/examples/analysis/totals/#custom + */ + calcFunc?: (query: Query, data: CellData[]) => number; } export interface Total { - /** 是否显示总计 */ - showGrandTotals: boolean; + /** + * 是否显示总计 + */ + showGrandTotals?: boolean; - /** 是否显示小计 */ - showSubTotals: + /** + *是否显示小计 + */ + showSubTotals?: | boolean | { /** 当子维度个数 <=1 时,仍然展示小计:默认 true */ always: boolean; }; - // 前端计算总计 - calcTotals?: CalcTotals; - // 前端计算小计 + + /** + * 自定义计算总计 + */ + calcGrandTotals?: CalcTotals; + + /** + * 自定义计算小计 + */ calcSubTotals?: CalcTotals; - /** 小计的汇总维度 */ - subTotalsDimensions: string[]; + /** + * 小计的汇总维度 + * @example subTotalsDimensions: ['province'] + */ + subTotalsDimensions?: string[]; - /** 总计布局位置,默认是下或右 */ - reverseLayout: boolean; + /** + * 总计布局位置,默认是下或右 + */ + reverseGrandTotalsLayout?: boolean; - /** 小计布局位置,默认下或者右 */ - reverseSubLayout: boolean; - // total's display name default = '总计' - label?: string; - // sub label's display name, default = '小计' - subLabel?: string; + /** + * 小计布局位置,默认是下或右 + */ + reverseSubTotalsLayout?: boolean; + + /** + * 总计展示名 + * @default "总计" + */ + grandTotalsLabel?: string; + + /** + * 小计展示名 + * @default "小计" + */ + subTotalsLabel?: string; } /** @@ -179,8 +208,8 @@ export interface Total { * 但是内部配置我倾向于仍然按照字段所属维度区,即配置的row,代表的是行维度而不是行小计 */ export interface Totals { - row?: Partial; - col?: Partial; + row?: Total; + col?: Total; } export interface Sort { diff --git a/packages/s2-core/src/facet/layout/build-row-tree-hierarchy.ts b/packages/s2-core/src/facet/layout/build-row-tree-hierarchy.ts index 3dbd216dac..a779f5d286 100644 --- a/packages/s2-core/src/facet/layout/build-row-tree-hierarchy.ts +++ b/packages/s2-core/src/facet/layout/build-row-tree-hierarchy.ts @@ -22,9 +22,11 @@ const addTotals = ( * TODO valueInCol = false and one or more values */ if (totalsConfig?.showGrandTotals) { - const func = totalsConfig.reverseLayout ? 'unshift' : 'push'; + const func = totalsConfig.reverseGrandTotalsLayout ? 'unshift' : 'push'; - fieldValues[func](new TotalClass(totalsConfig.label!, false, true)); + fieldValues[func]( + new TotalClass(totalsConfig.grandTotalsLabel!, false, true), + ); } }; diff --git a/packages/s2-core/src/sheet-type/spread-sheet.ts b/packages/s2-core/src/sheet-type/spread-sheet.ts index cc16a34ab1..70b6742c87 100644 --- a/packages/s2-core/src/sheet-type/spread-sheet.ts +++ b/packages/s2-core/src/sheet-type/spread-sheet.ts @@ -19,7 +19,6 @@ import { some, values, } from 'lodash'; -import { injectThemeVars } from '../utils/theme'; import { BaseCell } from '../cell'; import { MIN_DEVICE_PIXEL_RATIO, S2Event } from '../common/constant'; import { DebuggerUtil } from '../common/debug'; @@ -48,7 +47,6 @@ import type { TooltipOptions, TooltipShowOptions, Total, - Totals, } from '../common/interface'; import { Store } from '../common/store'; import type { BaseDataSet } from '../data-set'; @@ -67,6 +65,7 @@ import { getSafetyDataConfig, getSafetyOptions, } from '../utils/merge'; +import { injectThemeVars } from '../utils/theme'; import { getTooltipData, getTooltipOptions } from '../utils/tooltip'; /** @@ -77,28 +76,20 @@ import { getTooltipData, getTooltipOptions } from '../utils/tooltip'; runtime.enableCSSParsing = false; export abstract class SpreadSheet extends EE { - // theme config public theme: InternalFullyTheme; - // store some temporary data public store = new Store(); - // the original data config public dataCfg: S2DataConfig; - // Spreadsheet's configurations public options: S2Options; public dataSet: BaseDataSet; - /** - * Facet: determine how to render headers/cell - */ public facet: BaseFacet; public tooltip: BaseTooltip; - // the base container, contains all groups public container: Canvas; public interaction: RootInteraction; @@ -240,36 +231,18 @@ export abstract class SpreadSheet extends EE { public abstract getDataSet(): BaseDataSet; - /** - * 是否开启冻结行列头效果 - */ public abstract enableFrozenHeaders(): boolean; - /** - * Check if is pivot mode - */ public abstract isPivotMode(): boolean; public abstract isCustomRowFields(): boolean; - /** - * tree type must be in strategy mode - */ public abstract isHierarchyTreeType(): boolean; - /** - * Scroll Freeze Row Header - */ public abstract isFrozenRowHeader(): boolean; - /** - * Check if is pivot mode - */ public abstract isTableMode(): boolean; - /** - * Check if the value is in the columns - */ public abstract isValueInCols(): boolean; protected abstract buildFacet(): void; @@ -558,16 +531,16 @@ export abstract class SpreadSheet extends EE { ); } - // 获取当前cell实例 + // 获取当前 cell 实例 public getCell( target: CellEventTarget, ): T | null { let parent = target; - // 一直索引到g顶层的canvas来检查是否在指定的cell中 + // 一直索引到 g 顶层的 canvas 来检查是否在指定的cell中 while (parent && !(parent instanceof Canvas)) { if (parent instanceof BaseCell) { - // 在单元格中,返回true + // 在单元格中,返回 true return parent as T; } @@ -577,7 +550,7 @@ export abstract class SpreadSheet extends EE { return null; } - // 获取当前cell类型 + // 获取当前 cell 类型 public getCellType(target: CellEventTarget) { const cell = this.getCell(target); @@ -585,10 +558,9 @@ export abstract class SpreadSheet extends EE { } /** - * get total's config by dimension id - * @param dimension unique dimension id + * 获取当前维度对应的汇总配置 */ - public getTotalsConfig(dimension: string): Partial { + public getTotalsConfig(dimension: string): Total { const { totals } = this.options; const { rows } = this.dataSet.fields; @@ -597,6 +569,7 @@ export abstract class SpreadSheet extends EE { includes(rows, dimension) ? 'row' : 'col', {}, ) as Total; + const showSubTotals = totalConfig.showSubTotals && includes(totalConfig.subTotalsDimensions, dimension) @@ -606,10 +579,10 @@ export abstract class SpreadSheet extends EE { return { showSubTotals, showGrandTotals: totalConfig.showGrandTotals, - reverseLayout: totalConfig.reverseLayout, - reverseSubLayout: totalConfig.reverseSubLayout, - label: totalConfig.label || i18n('总计'), - subLabel: totalConfig.subLabel || i18n('小计'), + reverseGrandTotalsLayout: totalConfig.reverseGrandTotalsLayout, + reverseSubTotalsLayout: totalConfig.reverseSubTotalsLayout, + grandTotalsLabel: totalConfig.grandTotalsLabel || i18n('总计'), + subTotalsLabel: totalConfig.subTotalsLabel || i18n('小计'), }; } diff --git a/packages/s2-core/src/utils/data-set-operate.ts b/packages/s2-core/src/utils/data-set-operate.ts index 7d1c4ba802..7717d76fad 100644 --- a/packages/s2-core/src/utils/data-set-operate.ts +++ b/packages/s2-core/src/utils/data-set-operate.ts @@ -79,11 +79,11 @@ export function getAggregationAndCalcFuncByQuery( const { isRowTotal, isRowSubTotal, isColTotal, isColSubTotal } = totalsStatus; const { row, col } = totalsOptions || {}; const { - calcTotals: rowCalcTotals = {}, + calcGrandTotals: rowCalcTotals = {}, calcSubTotals: rowCalcSubTotals = {}, } = row || {}; const { - calcTotals: colCalcTotals = {}, + calcGrandTotals: colCalcTotals = {}, calcSubTotals: colCalcSubTotals = {}, } = col || {}; diff --git a/packages/s2-core/src/utils/layout/add-totals.ts b/packages/s2-core/src/utils/layout/add-totals.ts index 8a41263439..e268699275 100644 --- a/packages/s2-core/src/utils/layout/add-totals.ts +++ b/packages/s2-core/src/utils/layout/add-totals.ts @@ -15,8 +15,8 @@ export const addTotals = (params: TotalParams) => { if (isFirstField) { // check to see if grand total is added if (totalsConfig?.showGrandTotals) { - action = totalsConfig.reverseLayout ? 'unshift' : 'push'; - totalValue = new TotalClass(totalsConfig.label!, false, true); + action = totalsConfig.reverseGrandTotalsLayout ? 'unshift' : 'push'; + totalValue = new TotalClass(totalsConfig.grandTotalsLabel!, false, true); } } else if ( /** @@ -29,8 +29,8 @@ export const addTotals = (params: TotalParams) => { get(totalsConfig, 'showSubTotals.always') !== false) && currentField !== EXTRA_FIELD ) { - action = totalsConfig.reverseSubLayout ? 'unshift' : 'push'; - totalValue = new TotalClass(totalsConfig.subLabel!, true); + action = totalsConfig.reverseSubTotalsLayout ? 'unshift' : 'push'; + totalValue = new TotalClass(totalsConfig.subTotalsLabel!, true); } if (action) { diff --git a/packages/s2-react/__tests__/bugs/issue-522-spec.tsx b/packages/s2-react/__tests__/bugs/issue-522-spec.tsx index ff4425ff5d..de46bd5a3c 100644 --- a/packages/s2-react/__tests__/bugs/issue-522-spec.tsx +++ b/packages/s2-react/__tests__/bugs/issue-522-spec.tsx @@ -23,15 +23,15 @@ function MainLayout() { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['company', 'grade'], }, col: { showGrandTotals: false, showSubTotals: false, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: [], }, }, diff --git a/packages/s2-react/__tests__/spreadsheet/data-accuracy-one-measure-spec.tsx b/packages/s2-react/__tests__/spreadsheet/data-accuracy-one-measure-spec.tsx index 453326cadb..a9ada0e681 100644 --- a/packages/s2-react/__tests__/spreadsheet/data-accuracy-one-measure-spec.tsx +++ b/packages/s2-react/__tests__/spreadsheet/data-accuracy-one-measure-spec.tsx @@ -124,15 +124,15 @@ const getOptions = (): SheetComponentOptions => { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province', 'city'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['subCategory', 'category'], }, }, diff --git a/packages/s2-react/__tests__/spreadsheet/data-accuracy-two-measures-spec.tsx b/packages/s2-react/__tests__/spreadsheet/data-accuracy-two-measures-spec.tsx index 3df4d1d12e..958ff0b839 100644 --- a/packages/s2-react/__tests__/spreadsheet/data-accuracy-two-measures-spec.tsx +++ b/packages/s2-react/__tests__/spreadsheet/data-accuracy-two-measures-spec.tsx @@ -115,15 +115,15 @@ const getOptions = (): SheetComponentsProps['options'] => { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province', 'city'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['subCategory', 'category'], }, }, diff --git a/packages/s2-react/__tests__/spreadsheet/pressure-test-spec.tsx b/packages/s2-react/__tests__/spreadsheet/pressure-test-spec.tsx index ec998ebbf4..5820a2c92f 100644 --- a/packages/s2-react/__tests__/spreadsheet/pressure-test-spec.tsx +++ b/packages/s2-react/__tests__/spreadsheet/pressure-test-spec.tsx @@ -65,15 +65,15 @@ const getOptions = (): SheetComponentsProps['options'] => { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province', 'city'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['subCategory', 'category'], }, }, diff --git a/packages/s2-react/playground/index.tsx b/packages/s2-react/playground/index.tsx index 211807fcb9..dd80f4c788 100644 --- a/packages/s2-react/playground/index.tsx +++ b/packages/s2-react/playground/index.tsx @@ -455,8 +455,8 @@ function MainLayout() { row: { showGrandTotals: checked, showSubTotals: checked, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, }, @@ -476,8 +476,8 @@ function MainLayout() { col: { showGrandTotals: checked, showSubTotals: checked, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, diff --git a/s2-site/docs/common/totals.en.md b/s2-site/docs/common/totals.en.md index 3f9d1fba2e..6062d0fd20 100644 --- a/s2-site/docs/common/totals.en.md +++ b/s2-site/docs/common/totals.en.md @@ -21,11 +21,11 @@ object is **required** , *default: null* Function description: subtotal total co | showGrandTotals | Whether to display the total | `boolean` | `false` | | | showSubTotals | Whether to display subtotals. When configured as an object, always controls whether to always display subtotals when there are less than 2 subdimensions, and does not display by default | `boolean \| { always: boolean }` | `false` | | | subTotalsDimensions | Summary Dimensions for Subtotals | `string[]` | `[]` | | -| reverseLayout | total layout position, default bottom or right | `boolean` | `false` | | -| reverseSubLayout | Subtotal layout position, default bottom or right | `boolean` | `false` | | +| reverseGrandTotalsLayout | total layout position, default bottom or right | `boolean` | `false` | | +| reverseSubTotalsLayout | Subtotal layout position, default bottom or right | `boolean` | `false` | | | label | total alias | `string` | | | | subLabel | subtotal alias | `string` | | | -| calcTotals | Custom Calculated Totals | [CalcTotals](#calctotals) | | | +| calcGrandTotals | Custom Calculated Totals | [CalcTotals](#calctotals) | | | | calcSubTotals | Custom Calculated Subtotals | [CalcTotals](#calctotals) | | | ## CalcTotals diff --git a/s2-site/docs/common/totals.zh.md b/s2-site/docs/common/totals.zh.md index 6c27917856..ea6876cdae 100644 --- a/s2-site/docs/common/totals.zh.md +++ b/s2-site/docs/common/totals.zh.md @@ -21,11 +21,11 @@ object **必选**,_default:null_ 功能描述: 小计总计配置 | showGrandTotals | 是否显示总计 | `boolean` | `false` | | | showSubTotals | 是否显示小计。当配置为对象时,always 控制是否在子维度不足 2 个时始终展示小计,默认不展示 | `boolean \| { always: boolean }` | `false` | | | subTotalsDimensions | 小计的汇总维度 | `string[]` | `[]` | | -| reverseLayout | 总计布局位置,默认下或右 | `boolean` | `false` | | -| reverseSubLayout | 小计布局位置,默认下或右 | `boolean` | `false` | | +| reverseGrandTotalsLayout | 总计布局位置,默认下或右 | `boolean` | `false` | | +| reverseSubTotalsLayout | 小计布局位置,默认下或右 | `boolean` | `false` | | | label | 总计别名 | `string` | | | | subLabel | 小计别名 | `string` | | | -| calcTotals | 自定义计算总计 | [CalcTotals](#calctotals) | | | +| calcGrandTotals | 自定义计算总计 | [CalcTotals](#calctotals) | | | | calcSubTotals | 自定义计算小计 | [CalcTotals](#calctotals) | | | ## CalcTotals diff --git a/s2-site/docs/manual/basic/totals.en.md b/s2-site/docs/manual/basic/totals.en.md index 90a3f2466d..238fcdd24c 100644 --- a/s2-site/docs/manual/basic/totals.en.md +++ b/s2-site/docs/manual/basic/totals.en.md @@ -71,11 +71,11 @@ object is **required** , *default: null* Function description: Subtotal calculat | showGrandTotals | Whether to display the total | `boolean` | false | ✓ | | showSubTotals | Whether to display subtotals. When configured as an object, always controls whether to always display subtotals when there are less than 2 subdimensions, and does not display by default. | \`boolean | { always: boolean }\` | false | | subTotalsDimensions | Summary Dimensions for Subtotals | `string[]` | \[] | ✓ | -| reverseLayout | total layout position, default bottom or right | `boolean` | false | ✓ | -| reverseSubLayout | Subtotal layout position, default bottom or right | `boolean` | false | ✓ | +| reverseGrandTotalsLayout | total layout position, default bottom or right | `boolean` | false | ✓ | +| reverseSubTotalsLayout | Subtotal layout position, default bottom or right | `boolean` | false | ✓ | | label | total alias | `string` | | | | subLabel | subtotal alias | `string` | | | -| calcTotals | calculate the total | `CalcTotals` | | | +| calcGrandTotals | calculate the total | `CalcTotals` | | | | calcSubTotals | calculate subtotal | `CalcTotals` | | | ```ts @@ -84,15 +84,15 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, @@ -158,7 +158,7 @@ const s2DataConfig = { #### 2. Calculate the data -You can configure attributes `calcTotals` and `calcSubTotals` for `row` and `col` under `totals` respectively to realize the calculation of summary data +You can configure attributes `calcGrandTotals` and `calcSubTotals` for `row` and `col` under `totals` respectively to realize the calculation of summary data ##### 1. Configure aggregation mode @@ -170,10 +170,10 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { @@ -183,10 +183,10 @@ const s2Options = { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { @@ -207,10 +207,10 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { calcFunc: (query, data) => {}, }, calcSubTotals: { @@ -220,10 +220,10 @@ const s2Options = { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { calcFunc: (query, data) => {}, }, calcSubTotals: { diff --git a/s2-site/docs/manual/basic/totals.zh.md b/s2-site/docs/manual/basic/totals.zh.md index bbfbdcc739..de1c0c1be4 100644 --- a/s2-site/docs/manual/basic/totals.zh.md +++ b/s2-site/docs/manual/basic/totals.zh.md @@ -71,11 +71,11 @@ object **必选**,_default:null_ 功能描述: 小计总计算配置 | showGrandTotals | 是否显示总计 | `boolean` | false | ✓ | | showSubTotals | 是否显示小计。当配置为对象时,always 控制是否在子维度不足 2 个时始终展示小计,默认不展示。 | `boolean | { always: boolean }` | false | ✓ | | subTotalsDimensions | 小计的汇总维度 | `string[]` | [] | ✓ | -| reverseLayout | 总计布局位置,默认下或右 | `boolean` | false | ✓ | -| reverseSubLayout | 小计布局位置,默认下或右 | `boolean` | false | ✓ | +| reverseGrandTotalsLayout | 总计布局位置,默认下或右 | `boolean` | false | ✓ | +| reverseSubTotalsLayout | 小计布局位置,默认下或右 | `boolean` | false | ✓ | | label | 总计别名 | `string` | | | | subLabel | 小计别名 | `string` | | | -| calcTotals | 计算总计 | `CalcTotals` | | | +| calcGrandTotals | 计算总计 | `CalcTotals` | | | | calcSubTotals | 计算小计 | `CalcTotals` | | | ```ts @@ -84,15 +84,15 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, @@ -159,7 +159,7 @@ const s2DataConfig = { #### 2. 计算出数据 -可以给 `totals` 下的 `row` 、 `col` 分别配置属性 `calcTotals` 、 `calcSubTotals` 来实现计算汇总数据 +可以给 `totals` 下的 `row` 、 `col` 分别配置属性 `calcGrandTotals` 、 `calcSubTotals` 来实现计算汇总数据 ##### 1. 配置聚合方式 @@ -171,10 +171,10 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { @@ -184,10 +184,10 @@ const s2Options = { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { @@ -208,10 +208,10 @@ const s2Options = { row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { calcFunc: (query, data) => {}, }, calcSubTotals: { @@ -221,10 +221,10 @@ const s2Options = { col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { calcFunc: (query, data) => {}, }, calcSubTotals: { diff --git a/s2-site/examples/analysis/sort/demo/custom-totals.ts b/s2-site/examples/analysis/sort/demo/custom-totals.ts index bde777d498..fe8d1f5602 100644 --- a/s2-site/examples/analysis/sort/demo/custom-totals.ts +++ b/s2-site/examples/analysis/sort/demo/custom-totals.ts @@ -61,15 +61,15 @@ fetch( row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, diff --git a/s2-site/examples/analysis/totals/demo/basic.ts b/s2-site/examples/analysis/totals/demo/basic.ts index d0a1752e21..a95a2e33f2 100644 --- a/s2-site/examples/analysis/totals/demo/basic.ts +++ b/s2-site/examples/analysis/totals/demo/basic.ts @@ -49,15 +49,15 @@ fetch( row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, diff --git a/s2-site/examples/analysis/totals/demo/calculate.ts b/s2-site/examples/analysis/totals/demo/calculate.ts index 17dd734411..f76e0b1495 100644 --- a/s2-site/examples/analysis/totals/demo/calculate.ts +++ b/s2-site/examples/analysis/totals/demo/calculate.ts @@ -39,10 +39,10 @@ fetch('https://assets.antv.antgroup.com/s2/basic.json') row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { @@ -52,10 +52,10 @@ fetch('https://assets.antv.antgroup.com/s2/basic.json') col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { aggregation: 'SUM', }, calcSubTotals: { diff --git a/s2-site/examples/analysis/totals/demo/custom.ts b/s2-site/examples/analysis/totals/demo/custom.ts index 6cb319b1f1..b65ab5ace4 100644 --- a/s2-site/examples/analysis/totals/demo/custom.ts +++ b/s2-site/examples/analysis/totals/demo/custom.ts @@ -35,6 +35,7 @@ fetch('https://assets.antv.antgroup.com/s2/basic.json') const sum = data.reduce((pre, next) => { return pre + next[next[EXTRA_FIELD]]; }, 0); + return sum * 2; }; @@ -46,10 +47,10 @@ fetch('https://assets.antv.antgroup.com/s2/basic.json') row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], - calcTotals: { + calcGrandTotals: { calcFunc, }, calcSubTotals: { @@ -59,10 +60,10 @@ fetch('https://assets.antv.antgroup.com/s2/basic.json') col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], - calcTotals: { + calcGrandTotals: { calcFunc, }, calcSubTotals: { diff --git a/s2-site/examples/analysis/totals/demo/multiple-values.ts b/s2-site/examples/analysis/totals/demo/multiple-values.ts index 23b15bb0bc..3162452b82 100644 --- a/s2-site/examples/analysis/totals/demo/multiple-values.ts +++ b/s2-site/examples/analysis/totals/demo/multiple-values.ts @@ -53,15 +53,15 @@ fetch( row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, diff --git a/s2-site/examples/analysis/totals/demo/tree.ts b/s2-site/examples/analysis/totals/demo/tree.ts index deae23eff1..daeaa19521 100644 --- a/s2-site/examples/analysis/totals/demo/tree.ts +++ b/s2-site/examples/analysis/totals/demo/tree.ts @@ -49,15 +49,15 @@ fetch( row: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['province'], }, col: { showGrandTotals: true, showSubTotals: true, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: ['type'], }, }, diff --git a/s2-site/playground/sheet-component/index.tsx b/s2-site/playground/sheet-component/index.tsx index d0e4d9fbb3..7b7c6a00df 100644 --- a/s2-site/playground/sheet-component/index.tsx +++ b/s2-site/playground/sheet-component/index.tsx @@ -122,15 +122,15 @@ export const CustomSheet: React.FC = (props) => { row: { showGrandTotals: rowGrandTotals, showSubTotals: rowSubTotals, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: subTotalsDimensions.rowSubTotalsDimensions, }, col: { showGrandTotals: columnGrandTotals, showSubTotals: columnSubTotals, - reverseLayout: true, - reverseSubLayout: true, + reverseGrandTotalsLayout: true, + reverseSubTotalsLayout: true, subTotalsDimensions: subTotalsDimensions.colSubTotalsDimensions, }, },