Skip to content

Commit

Permalink
feat: add chart type source in container (#2108)
Browse files Browse the repository at this point in the history
* feat: add chart type source in container

* fix: cr
  • Loading branch information
hustcc authored Dec 17, 2020
1 parent 48547f8 commit c26eb37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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';

/**
* 所有 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

0 comments on commit c26eb37

Please sign in to comment.