From c26eb37aae691247bd8c42f78b86158b9ead1566 Mon Sep 17 00:00:00 2001 From: hustcc Date: Thu, 17 Dec 2020 13:34:27 +0800 Subject: [PATCH] feat: add chart type source in container (#2108) * feat: add chart type source in container * fix: cr --- __tests__/unit/core/index-spec.ts | 16 ++++++++++++++++ src/core/plot.ts | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/__tests__/unit/core/index-spec.ts b/__tests__/unit/core/index-spec.ts index 5b35eb6007..28b17f4d12 100644 --- a/__tests__/unit/core/index-spec.ts +++ b/__tests__/unit/core/index-spec.ts @@ -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); + }); }); diff --git a/src/core/plot.ts b/src/core/plot.ts index 5ef7600d11..5d0c25c7ad 100644 --- a/src/core/plot.ts +++ b/src/core/plot.ts @@ -22,6 +22,8 @@ export type PickOptions = Pick< | 'limitInPlot' >; +const SOURCE_ATTRIBUTE_NAME = 'data-chart-source-type'; + /** * 所有 plot 的基类 */ @@ -77,6 +79,9 @@ export abstract class Plot extends EE { supportCSSTransform, limitInPlot, }); + + // 给容器增加标识,知道图表的来源区别于 G2 + this.container.setAttribute(SOURCE_ATTRIBUTE_NAME, 'G2Plot'); } /** @@ -229,6 +234,8 @@ export abstract class Plot extends EE { this.chart.destroy(); // 清空已经绑定的事件 this.off(); + + this.container.removeAttribute(SOURCE_ATTRIBUTE_NAME); } /**