Skip to content

Commit f46b4a2

Browse files
author
酥云
committed
fix(padding): 兼容非法padding
1 parent f9433c0 commit f46b4a2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

__tests__/unit/plots/venn/padding-spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,36 @@ describe('venn padding', () => {
125125
});
126126
});
127127

128+
it('兼容非法 padding', () => {
129+
plot.changeSize(400, 400);
130+
plot.update({
131+
legend: false,
132+
appendPadding: 0,
133+
padding: 250,
134+
});
135+
plot.chart.geometries[0].data.forEach((datum) => {
136+
if (datum.sets.length === 1) {
137+
expect(datum.radius).toBe(0);
138+
}
139+
expect(datum.x).toBe(0);
140+
expect(datum.y).toBe(0);
141+
});
142+
143+
plot.changeSize(800, 400);
144+
plot.update({
145+
legend: false,
146+
appendPadding: 0,
147+
padding: 200,
148+
});
149+
plot.chart.geometries[0].data.forEach((datum) => {
150+
if (datum.sets.length === 1) {
151+
expect(datum.radius).toBe(0);
152+
}
153+
expect(datum.x).toBe(200);
154+
expect(datum.y).toBe(0);
155+
});
156+
});
157+
128158
afterAll(() => {
129159
plot.destroy();
130160
});

src/plots/venn/adaptor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ function geometry(params: Params<VennOptions>): Params<VennOptions> {
6464
const customInfo: CustomInfo = { offsetX: l, offsetY: t, label };
6565
// coordinateBBox + appendPadding = viewBBox, 不需要再计算 appendPadding 部分,因此直接使用 viewBBox
6666
const { width, height } = chart.viewBBox;
67-
68-
const vennData: VennData = layoutVennData(options, width - (r + l), height - (t + b), 0);
67+
// 处理padding输入不合理的情况, w 和 h 不能为负数
68+
const vennData: VennData = layoutVennData(options, Math.max(width - (r + l), 0), Math.max(height - (t + b), 0), 0);
6969
chart.data(vennData);
7070

7171
const { ext } = schemaGeometry(

0 commit comments

Comments
 (0)