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: add chart type source in container #2108

Merged
merged 2 commits into from
Dec 17, 2020
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
16 changes: 16 additions & 0 deletions __tests__/unit/core/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,20 @@ describe('core', () => {
expect(line.chart.limitInPlot).toBe(true);
line.destroy();
});

it('plot dataset sourceType', () => {
const container = createDiv('');
const line = new Line(container, {
data: partySupport.filter((o) => o.type === 'FF'),
xField: 'date',
yField: 'value',
});

line.render();

expect(container.dataset.chartSourceType).toBe('G2Plot');
line.destroy();

expect(container.dataset.chartSourceType).toBe(undefined);
});
});
7 changes: 7 additions & 0 deletions src/core/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export type PickOptions = Pick<
| 'limitInPlot'
>;

const SOURCE_ATTRIBUTE_NAME = 'data-chart-source-type';

hustcc marked this conversation as resolved.
Show resolved Hide resolved
/**
* 所有 plot 的基类
*/
Expand Down Expand Up @@ -77,6 +79,9 @@ export abstract class Plot<O extends PickOptions> extends EE {
supportCSSTransform,
limitInPlot,
});

// 给容器增加标识,知道图表的来源区别于 G2
this.container.setAttribute(SOURCE_ATTRIBUTE_NAME, 'G2Plot');
}

/**
Expand Down Expand Up @@ -229,6 +234,8 @@ export abstract class Plot<O extends PickOptions> extends EE {
this.chart.destroy();
// 清空已经绑定的事件
this.off();

this.container.removeAttribute(SOURCE_ATTRIBUTE_NAME);
}

/**
Expand Down