Skip to content

Commit

Permalink
feat: 小计/总计功能,支持按维度分组汇总 (#2346)
Browse files Browse the repository at this point in the history
* feat(Api): 添加 totalDimensionGroup/subTotalDimensionGroup api,以及一些临时的开发函数

* feat(Hierarchy): 总计小计结点下添加Hierarchy

* feat(Render): getMultipleMap 实现,计算总计小计下的布局信息

* feat(Render): 按维度分组的小计总计下表头位置的调整和渲染

* feat(DataSet): 存在维度分组时的汇总值获取

* feat(DataSet): 存在维度分组时的汇总值获取

* feat(DataSet): 存在维度分组时的汇总值获取

* feat: 补充注释

* feat: 单测快照更新,添加isTotalRoot属性

* fix: 有多个 Value 时不允许隐藏度量列

* fix: 有多个 Value 时不允许隐藏度量列

* fix: 删除了一个莫名其妙的函数

* test: 按维度分组汇总能力单测

* docs: 按维度分组汇总能力文档

* test: 更新,多度量指标不允许隐藏指标头

* docs: 图片示例

* test: 更新 snap 数据文件

* chore: 版本号更新

* chore: 版本号更新

* chore: 版本号更新

* chore: 版本号更新

* chore: 版本号更新

* chore: 版本号更新

* chore: 版本号更新

* Merge remote-tracking branch 'origin/Juze_TotalsDimGroup' into Juze_TotalsDimGroup

* test: 更新快照

* chore: 删除开发测试文件

* fix: 汇总指标节点也是汇总节点

* chore: 删除无用文件

* fix: isTotalRoot 替换 isTotals

* fix: isTotalRoot 替换 isTotals

* fix: isTotalRoot 替换 isTotals

* test: 更新 React 包快照

* fix: 修复树状模式下总计节点的指标节点没有被格式化数据

* refactor: 修改代码风格和编码规范

* test: 修改代码风格和编码规范

* test: 修改代码风格和编码规范

* test: 修改代码风格和编码规范

* chore: 更改 interface 命名规范

---------

Co-authored-by: JuZe <[email protected]>
Co-authored-by: Wenjun Xu <[email protected]>
Co-authored-by: Jinke Li <[email protected]>
  • Loading branch information
4 people authored Sep 22, 2023
1 parent 12f2d02 commit 20e608f
Show file tree
Hide file tree
Showing 40 changed files with 1,410 additions and 387 deletions.
7 changes: 4 additions & 3 deletions packages/s2-core/__tests__/bugs/issue-1715-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ describe('Multi Values GrandTotal Height Test', () => {

const grandTotalsNode = s2
.getColumnNodes()
.find((node) => node.isGrandTotals);
.find((node) => node.isGrandTotals && node.isTotalRoot);

expect(s2.facet.layoutResult.colsHierarchy.height).toBe(60);
expect(grandTotalsNode.height).toEqual(30);
// 有多个 Value 时不允许隐藏度量列
expect(s2.facet.layoutResult.colsHierarchy.height).toBe(90);
expect(grandTotalsNode.height).toEqual(60);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "province",
"label": "province",
Expand Down Expand Up @@ -47,6 +48,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "city",
"label": "city",
Expand Down Expand Up @@ -81,6 +83,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "series-number-node",
"label": "序号",
Expand Down Expand Up @@ -110,6 +113,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "province",
"label": "province",
Expand Down Expand Up @@ -139,6 +143,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "city",
"label": "city",
Expand Down Expand Up @@ -173,6 +178,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "",
"label": "province/city/数值",
Expand Down Expand Up @@ -207,6 +213,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "series-number-node",
"label": "序号",
Expand Down Expand Up @@ -236,6 +243,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "",
"label": "province/city/数值",
Expand Down Expand Up @@ -270,6 +278,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "province",
"label": "province",
Expand Down Expand Up @@ -299,6 +308,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "city",
"label": "city",
Expand Down Expand Up @@ -333,6 +343,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "series-number-node",
"label": "序号",
Expand Down Expand Up @@ -362,6 +373,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "province",
"label": "province",
Expand Down Expand Up @@ -391,6 +403,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "city",
"label": "city",
Expand Down Expand Up @@ -425,6 +438,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "",
"label": "province/city",
Expand Down Expand Up @@ -459,6 +473,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "series-number-node",
"label": "序号",
Expand Down Expand Up @@ -488,6 +503,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "",
"label": "province/city",
Expand Down Expand Up @@ -522,6 +538,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "province",
"label": "province",
Expand Down Expand Up @@ -551,6 +568,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "city",
"label": "city",
Expand Down Expand Up @@ -585,6 +603,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "series-number-node",
"label": "序号",
Expand Down Expand Up @@ -614,6 +633,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "province",
"label": "province",
Expand Down Expand Up @@ -643,6 +663,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "city",
"label": "city",
Expand Down Expand Up @@ -677,6 +698,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "",
"label": "province/city",
Expand Down Expand Up @@ -711,6 +733,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "series-number-node",
"label": "序号",
Expand Down Expand Up @@ -740,6 +763,7 @@ Array [
"isPivotMode": true,
"isSubTotals": undefined,
"isTotalMeasure": undefined,
"isTotalRoot": undefined,
"isTotals": undefined,
"key": "",
"label": "province/city",
Expand Down
8 changes: 8 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/corner-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('PivotSheet Corner Tests', () => {
fields: {
...simpleDataConfig.fields,
columns: [],
values: ['price'],
},
});
s2.setOptions({
Expand Down Expand Up @@ -88,6 +89,13 @@ describe('PivotSheet Corner Tests', () => {
},
},
});
s2.setDataCfg({
...simpleDataConfig,
fields: {
...simpleDataConfig.fields,
values: ['price'],
},
});
s2.render();

const cornerNodes = s2.facet.getCornerNodes();
Expand Down
11 changes: 11 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/sort-by-order-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,15 @@ describe('Manual Sort Tests', () => {
}),
).toEqual(['整体访问', '小程序访问', '支付宝访问']);
});

test('getTotalDimensionValues should include correct values', () => {
const sortedType1 = s2.dataSet.getTotalDimensionValues('type1', {});
expect(sortedType1).toEqual(['整体访问', '小程序访问', '支付宝访问']);

expect(s2.dataSet.getTotalDimensionValues('type2', {})).toEqual([
'整体访问',
'小程序访问',
'支付宝访问',
]);
});
});
5 changes: 3 additions & 2 deletions packages/s2-core/__tests__/unit/cell/header-cell-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ describe('header cell formatter test', () => {
value: '总计',
parent: root,
label: '总计',
isTotals: true,
isTotalRoot: true,
});
const rowNode = new Node({
id: `root[&]杭州[&]小计`,
key: '',
value: '小计',
parent: root,
label: '小计',
isTotals: true,
isTotalRoot: true,
});

const formatter: Formatter = (value) => {
Expand All @@ -92,6 +92,7 @@ describe('header cell formatter test', () => {
label: '总计',
isTotals: true,
isGrandTotals: true,
isTotalRoot: true,
});

const rowSubTotalNode = new Node({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Pivot Dataset Total Test test for total with dimension group get correct MultiData when query need to be processed 1`] = `
Array [
Object {
"$$extra$$": "number",
"$$value$$": 7789,
"city": "杭州市",
"number": 7789,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 2367,
"city": "绍兴市",
"number": 2367,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 3877,
"city": "宁波市",
"number": 3877,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 4342,
"city": "舟山市",
"number": 4342,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
]
`;

exports[`Pivot Dataset Total Test test for total with dimension group get correct MultiData when query need to be processed 2`] = `Array []`;

exports[`Pivot Dataset Total Test test for total with dimension group get correct MultiData when query need to be processed 3`] = `
Array [
Object {
"$$extra$$": "number",
"$$value$$": 7789,
"city": "杭州市",
"number": 7789,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 2367,
"city": "绍兴市",
"number": 2367,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 3877,
"city": "宁波市",
"number": 3877,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 4342,
"city": "舟山市",
"number": 4342,
"province": "浙江省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 1723,
"city": "成都市",
"number": 1723,
"province": "四川省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 1822,
"city": "绵阳市",
"number": 1822,
"province": "四川省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 1943,
"city": "南充市",
"number": 1943,
"province": "四川省",
"sub_type": "桌子",
"type": "家具",
},
Object {
"$$extra$$": "number",
"$$value$$": 2330,
"city": "乐山市",
"number": 2330,
"province": "四川省",
"sub_type": "桌子",
"type": "家具",
},
]
`;
Loading

1 comment on commit 20e608f

@vercel
Copy link

@vercel vercel bot commented on 20e608f Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2-antv-s2.vercel.app
antvis-s2-git-master-antv-s2.vercel.app
antvis-s2.vercel.app

Please sign in to comment.