Skip to content

Commit

Permalink
fix: 兼容开启汇总和隐藏节点的场景
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Nov 8, 2023
1 parent 1847aba commit 29ac885
Show file tree
Hide file tree
Showing 20 changed files with 1,047 additions and 723 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ Object {
"fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif",
"fontSize": 12,
"fontWeight": 700,
"maxLines": 1,
"opacity": 1,
"textAlign": "center",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"cell": Object {
"backgroundColor": "#E0E9FD",
Expand Down Expand Up @@ -75,18 +78,24 @@ Object {
"fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif",
"fontSize": 12,
"fontWeight": "normal",
"maxLines": 1,
"opacity": 1,
"textAlign": "right",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"text": Object {
"fill": "#000000",
"fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif",
"fontSize": 12,
"fontWeight": "normal",
"maxLines": 1,
"opacity": 1,
"textAlign": "center",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
},
"cornerCell": Object {
Expand All @@ -95,9 +104,12 @@ Object {
"fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif",
"fontSize": 12,
"fontWeight": 700,
"maxLines": 1,
"opacity": 1,
"textAlign": "left",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"cell": Object {
"backgroundColor": "#E0E9FD",
Expand Down Expand Up @@ -128,9 +140,12 @@ Object {
"fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif",
"fontSize": 12,
"fontWeight": 700,
"maxLines": 1,
"opacity": 1,
"textAlign": "right",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
},
"dataCell": Object {
Expand All @@ -140,9 +155,12 @@ Object {
"fontSize": 12,
"fontWeight": 700,
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "right",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"cell": Object {
"backgroundColor": "#FFFFFF",
Expand Down Expand Up @@ -252,9 +270,12 @@ Object {
"fontSize": 12,
"fontWeight": "normal",
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "right",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
},
"mergedCell": Object {
Expand All @@ -264,9 +285,12 @@ Object {
"fontSize": 12,
"fontWeight": 700,
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "right",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"cell": Object {
"backgroundColor": "#FFFFFF",
Expand Down Expand Up @@ -376,9 +400,12 @@ Object {
"fontSize": 12,
"fontWeight": "normal",
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "right",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
},
"prepareSelectMask": Object {
Expand All @@ -400,6 +427,8 @@ Object {
"backgroundOpacity": 1,
},
},
"minCellHeight": 40,
"minCellWidth": 42,
"size": 3,
},
"rowCell": Object {
Expand All @@ -409,9 +438,12 @@ Object {
"fontSize": 12,
"fontWeight": 700,
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "left",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"cell": Object {
"backgroundColor": "#F5F8FE",
Expand Down Expand Up @@ -471,9 +503,12 @@ Object {
"fontSize": 12,
"fontWeight": "normal",
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "left",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"seriesNumberWidth": 80,
"seriesText": Object {
Expand All @@ -482,19 +517,25 @@ Object {
"fontSize": 12,
"fontWeight": "normal",
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "center",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
"text": Object {
"fill": "#000000",
"fontFamily": "Roboto, PingFangSC, Microsoft YaHei, Arial, sans-serif",
"fontSize": 12,
"fontWeight": "normal",
"linkTextFill": "#326EF4",
"maxLines": 1,
"opacity": 1,
"textAlign": "left",
"textBaseline": "middle",
"textOverflow": "ellipsis",
"wordWrap": true,
},
},
"scrollBar": Object {
Expand Down
76 changes: 41 additions & 35 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { difference, pick } from 'lodash';
import * as mockDataConfig from 'tests/data/mock-dataset.json';
import * as mockPivotDataConfig from 'tests/data/simple-data.json';
import * as mockTableDataConfig from 'tests/data/simple-table-data.json';
import { getContainer } from 'tests/util/helpers';
import { waitForRender } from 'tests/util';
import { customColMultipleColumns } from '../data/custom-table-col-fields';
import { getContainer } from 'tests/util/helpers';
import { customColGridSimpleFields } from '../data/custom-grid-simple-fields';
import { customColMultipleColumns } from '../data/custom-table-col-fields';
import { PivotSheet, TableSheet } from '@/sheet-type';
import type { HiddenColumnsInfo, S2Options } from '@/common';

Expand Down Expand Up @@ -46,8 +46,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
test('should hide column correctly', async () => {
const hiddenColumns = ['cost'];

await waitForRender(tableSheet, () => {
tableSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(tableSheet, async () => {
await tableSheet.interaction.hideColumns(hiddenColumns);
});

const hiddenColumnsDetail = tableSheet.store.get(
Expand All @@ -72,8 +72,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
test('should hide multiple columns correctly', async () => {
const hiddenColumns = ['price', 'city'];

await waitForRender(tableSheet, () => {
tableSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(tableSheet, async () => {
await tableSheet.interaction.hideColumns(hiddenColumns);
});

const hiddenColumnsDetail = tableSheet.store.get(
Expand Down Expand Up @@ -110,8 +110,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
test('should hide closer group columns correctly', async () => {
const hiddenColumns = ['cost', 'province'];

await waitForRender(tableSheet, () => {
tableSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(tableSheet, async () => {
await tableSheet.interaction.hideColumns(hiddenColumns);
});

const hiddenColumnsDetail = tableSheet.store.get(
Expand Down Expand Up @@ -161,6 +161,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(costDetail.displaySiblingNode.next?.field).toEqual('province');
expect(costDetail.hideColumnNodes).toHaveLength(1);
expect(costDetail.hideColumnNodes[0].field).toEqual('cost');

sheet.destroy();
});

test('should hide columns for multiple columns', async () => {
Expand All @@ -175,8 +177,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
},
});
await tableSheet.render();
await waitForRender(tableSheet, () => {
tableSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(tableSheet, async () => {
await tableSheet.interaction.hideColumns(hiddenColumns);
});

const hiddenColumnsDetail = tableSheet.store.get(
Expand Down Expand Up @@ -240,8 +242,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
test('should hide column correctly', async () => {
const hiddenColumns = [typePriceColumnId];

await waitForRender(pivotSheet, () => {
pivotSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(pivotSheet, async () => {
await pivotSheet.interaction.hideColumns(hiddenColumns);
});

const hiddenColumnsDetail = pivotSheet.store.get(
Expand All @@ -268,8 +270,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
test('should hide multiple columns correctly', async () => {
const hiddenColumns = [typePriceColumnId, cityPriceColumnId];

await waitForRender(pivotSheet, () => {
pivotSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(pivotSheet, async () => {
await pivotSheet.interaction.hideColumns(hiddenColumns);
});
const hiddenColumnsDetail = pivotSheet.store.get(
'hiddenColumnsDetail',
Expand Down Expand Up @@ -360,6 +362,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
);
expect(priceDetail.hideColumnNodes).toHaveLength(1);
expect(priceDetail.hideColumnNodes[0].id).toEqual(typePriceColumnId);

sheet.destroy();
});

// https://github.com/antvis/S2/issues/1993
Expand Down Expand Up @@ -390,8 +394,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
},
});
await pivotSheet.render();
await waitForRender(pivotSheet, () => {
pivotSheet.interaction.hideColumns([nodeId]);
await waitForRender(pivotSheet, async () => {
await pivotSheet.interaction.hideColumns([nodeId]);
});

const grandTotalsNode = pivotSheet.facet
Expand Down Expand Up @@ -426,8 +430,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
fields: customColGridSimpleFields,
});
await pivotSheet.render();
await waitForRender(pivotSheet, () => {
pivotSheet.interaction.hideColumns(hiddenColumns);
await waitForRender(pivotSheet, async () => {
await pivotSheet.interaction.hideColumns(hiddenColumns);
});

const hiddenColumnsDetail = pivotSheet.store.get(
Expand Down Expand Up @@ -504,8 +508,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
{ id: 'root[&]总计', x: 0, width: 288 },
{ id: 'root[&]家具[&]小计', x: 96, width: 192 },
])('should hide totals node for %o', async ({ id, x, width }) => {
await waitForRender(sheet, () => {
sheet.interaction.hideColumns([id]);
await waitForRender(sheet, async () => {
await sheet.interaction.hideColumns([id]);
});

const totalsSiblingNode = sheet.facet
Expand All @@ -526,8 +530,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
'root[&]办公用品[&]笔[&]number',
];

await waitForRender(sheet, () => {
sheet.interaction.hideColumns(nodeIds);
await waitForRender(sheet, async () => {
await sheet.interaction.hideColumns(nodeIds);
});

expect(
Expand All @@ -540,13 +544,13 @@ describe('SpreadSheet Hidden Columns Tests', () => {
test('should render correct row corner after hide measure node', async () => {
const nodeIds = [
'root[&]总计',
'root[&]小计',
'root[&]家具[&]小计',
'root[&]家具[&]桌子[&]number',
'root[&]办公用品[&]笔[&]number',
];

await waitForRender(sheet, () => {
sheet.interaction.hideColumns(nodeIds);
await waitForRender(sheet, async () => {
await sheet.interaction.hideColumns(nodeIds);
});

const cornerNodes = sheet.facet.getCornerNodes();
Expand All @@ -555,32 +559,34 @@ describe('SpreadSheet Hidden Columns Tests', () => {
);

// 避免采样的节点被隐藏后, 影响角头坐标计算
expect(
sheet.facet.getLayoutResult().colsHierarchy.sampleNodeForLastLevel?.y,
).toStrictEqual(60);
const { colsHierarchy } = sheet.facet.getLayoutResult();

expect(colsHierarchy.sampleNodeForLastLevel?.height).toStrictEqual(30);
expect(colsHierarchy.sampleNodeForLastLevel?.y).toStrictEqual(60);
expect(colsHierarchy.height).toStrictEqual(90);
expect(colCornerNodesMeta).toMatchInlineSnapshot(`
Array [
Object {
"height": 30,
"width": 99,
"width": 119,
"x": 0,
"y": 60,
},
Object {
"height": 30,
"width": 99,
"x": 99,
"width": 119,
"x": 119,
"y": 60,
},
Object {
"height": 30,
"width": 198,
"width": 238,
"x": 0,
"y": 0,
},
Object {
"height": 30,
"width": 198,
"width": 238,
"x": 0,
"y": 30,
},
Expand All @@ -602,8 +608,8 @@ describe('SpreadSheet Hidden Columns Tests', () => {
},
});
await sheet.render();
await waitForRender(sheet, () => {
sheet.interaction.hideColumns([nodeId]);
await waitForRender(sheet, async () => {
await sheet.interaction.hideColumns([nodeId]);
});

const leafNodes = sheet.facet.getColLeafNodes();
Expand Down
Loading

0 comments on commit 29ac885

Please sign in to comment.