Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 在行列头配置为空时,趋势分析表和customTree 模式不渲染框架 #2216

Merged
merged 5 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Custom Tree Dataset Test', () => {

describe('test base dataset structure', () => {
test('should get correct field data', () => {
expect(dataCfg.fields.rows).toEqual([]);
expect(dataSet.fields.rows).toEqual([EXTRA_FIELD]);
expect(dataSet.fields.columns).toEqual(['type', 'sub_type']);
expect(dataSet.fields.values).toEqual(values);
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/__tests__/unit/facet/pivot-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('Pivot Mode Facet Test', () => {
height: 100,
container: document.body,
});
// 所以我需要重置 Spreadsheet 中的 dataCfg.fields todo: 然后调用 render 看是否会进入后续的方法
// 所以我需要重置 Spreadsheet 中的 dataCfg.fields
const spreadsheet = Object.assign({}, s2, {
dataCfg: { fields },
panelGroup: container.addGroup(),
Expand Down
3 changes: 1 addition & 2 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ export abstract class BaseDataSet {
}

public processMeta(meta: Meta[] = [], defaultExtraFieldText: string) {
const newMeta: Meta[] = [
return [
...meta,
generateExtraFieldMeta(
meta,
this.spreadsheet?.options?.cornerExtraFieldText,
defaultExtraFieldText,
),
];
return newMeta;
}

public getDisplayDataSet() {
Expand Down
7 changes: 5 additions & 2 deletions packages/s2-core/src/data-set/custom-tree-pivot-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export class CustomTreePivotDataSet extends PivotDataSet {

processDataCfg(dataCfg: S2DataConfig): S2DataConfig {
// 自定义行头有如下几个特点
// 1、rows配置必须是空,需要额外添加 $$extra$$ 定位数据(标记指标的id)
// 2、要有配置 fields.rowCustomTree(行头结构)
// 3、values 不需要参与计算,默认就在行头结构中
dataCfg.fields.rows = [EXTRA_FIELD];
dataCfg.fields.valueInCols = false;
const { data, meta, ...restCfg } = dataCfg;
const { values } = dataCfg.fields;
Expand Down Expand Up @@ -94,6 +92,11 @@ export class CustomTreePivotDataSet extends PivotDataSet {
...restCfg,
meta: newMeta,
data: uniq(transformedData),
fields: {
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
...dataCfg.fields,
// 1、rows配置必须是空,需要额外添加 $$extra$$ 定位数据(标记指标的id)
rows: [EXTRA_FIELD],
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@ import type { Event as GEvent } from '@antv/g-canvas';
import {
CellTypes,
copyData,
CornerNodeType,
customMerge,
EXTRA_FIELD,
getCellMeta,
InteractionStateName,
SpreadSheet,
type S2DataConfig,
SpreadSheet,
} from '@antv/s2';
import React from 'react';
import ReactDOM from 'react-dom';
import { act } from 'react-dom/test-utils';
import { merge } from 'lodash';
import {
SheetComponent,
SheetComponentOptions,
} from '../../../../../src/components';
import { getContainer } from '../../../../util/helpers';
import {
StrategySheetDataConfig,
StrategyOptions,
StrategySheetDataConfig,
} from '../../../../data/strategy-data';

describe('<StrategySheet/> Tests', () => {
let s2: SpreadSheet;
let container: HTMLDivElement;

beforeAll(() => {
beforeEach(() => {
container = getContainer();
});

afterAll(() => {
afterEach(() => {
ReactDOM.unmountComponentAtNode(container);
container.remove();
});

const renderStrategySheet = (
options: SheetComponentOptions | null,
dataCfg?: S2DataConfig,
Expand Down Expand Up @@ -181,6 +183,35 @@ describe('<StrategySheet/> Tests', () => {
]);
});

test('should get custom corner extra field text', () => {
const cornerExtraFieldText = '自定义';
const s2DataCfg = {
fields: {
...StrategySheetDataConfig.fields,
valueInCols: false,
},
};
const s2Options = {
cornerExtraFieldText,
};

renderStrategySheet(s2Options, {
...StrategySheetDataConfig,
...s2DataCfg,
});

const cornerNode = s2.facet
.getCornerNodes()
.find((node) => node.cornerType === CornerNodeType.Row);
const textList = s2.facet.cornerHeader
.getChildren()
.map((element) => (element as any).actualText);

expect(textList).toEqual([cornerExtraFieldText, '日期']);

expect(cornerNode.label).toEqual(cornerExtraFieldText);
});

test('should format corner date field', () => {
renderStrategySheet(
{
Expand All @@ -201,7 +232,9 @@ describe('<StrategySheet/> Tests', () => {
const textList = s2.facet.cornerHeader
.getChildren()
.map((element) => (element as any).actualText);
const dataSetFields = s2.dataSet.fields;

expect(dataSetFields.rows).toEqual([EXTRA_FIELD]);
expect(textList).toEqual(['数值', '日期']);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {

export class StrategyDataSet extends CustomTreePivotDataSet {
processDataCfg(dataCfg: S2DataConfig): S2DataConfig {
dataCfg.fields.rows = [EXTRA_FIELD];
dataCfg.fields.valueInCols = false;
const { data, meta, ...restCfg } = dataCfg;
const transformedData = [];
Expand All @@ -31,19 +30,16 @@ export class StrategyDataSet extends CustomTreePivotDataSet {
}
});

const extraFieldName =
this.spreadsheet?.options?.cornerExtraFieldText || i18n('数值');

const extraFieldMeta: Meta = {
field: EXTRA_FIELD,
name: extraFieldName,
};
const newMeta: Meta[] = [...meta, extraFieldMeta];
const newMeta: Meta[] = this.processMeta(meta, i18n('数值'));

return {
data: uniq(transformedData),
meta: newMeta,
...restCfg,
fields: {
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
...dataCfg.fields,
rows: [EXTRA_FIELD],
},
};
}
}