Skip to content

Commit c26eb37

Browse files
authored
feat: add chart type source in container (#2108)
* feat: add chart type source in container * fix: cr
1 parent 48547f8 commit c26eb37

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

__tests__/unit/core/index-spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,20 @@ describe('core', () => {
203203
expect(line.chart.limitInPlot).toBe(true);
204204
line.destroy();
205205
});
206+
207+
it('plot dataset sourceType', () => {
208+
const container = createDiv('');
209+
const line = new Line(container, {
210+
data: partySupport.filter((o) => o.type === 'FF'),
211+
xField: 'date',
212+
yField: 'value',
213+
});
214+
215+
line.render();
216+
217+
expect(container.dataset.chartSourceType).toBe('G2Plot');
218+
line.destroy();
219+
220+
expect(container.dataset.chartSourceType).toBe(undefined);
221+
});
206222
});

src/core/plot.ts

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export type PickOptions = Pick<
2222
| 'limitInPlot'
2323
>;
2424

25+
const SOURCE_ATTRIBUTE_NAME = 'data-chart-source-type';
26+
2527
/**
2628
* 所有 plot 的基类
2729
*/
@@ -77,6 +79,9 @@ export abstract class Plot<O extends PickOptions> extends EE {
7779
supportCSSTransform,
7880
limitInPlot,
7981
});
82+
83+
// 给容器增加标识,知道图表的来源区别于 G2
84+
this.container.setAttribute(SOURCE_ATTRIBUTE_NAME, 'G2Plot');
8085
}
8186

8287
/**
@@ -229,6 +234,8 @@ export abstract class Plot<O extends PickOptions> extends EE {
229234
this.chart.destroy();
230235
// 清空已经绑定的事件
231236
this.off();
237+
238+
this.container.removeAttribute(SOURCE_ATTRIBUTE_NAME);
232239
}
233240

234241
/**

0 commit comments

Comments
 (0)