Skip to content

Commit

Permalink
fix(#2495): fix layout error after render twice (#2496)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed May 26, 2020
1 parent f8262a2 commit 4abb893
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/chart/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ export default function defaultLayout(view: View): void {
const padding = calculatePadding(view);
// 2. 计算出新的 coordinateBBox
const newCoordinateBBox = view.viewBBox.shrink(padding);
// 3. 如果 coordinateBBox 前后未发生变化则不需要进行组件的重布局
if (view.coordinateBBox.isEqual(newCoordinateBBox)) {
if (annotation) {
// 因为 Annotation 不参与布局,但是渲染的位置依赖于坐标系,所以可以将绘制阶段延迟到 layout() 进行
annotation.layout();
}
return;
}

view.coordinateBBox = newCoordinateBBox;
view.adjustCoordinate();

Expand Down
33 changes: 33 additions & 0 deletions tests/bugs/2495-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Chart } from '../../src/';
import { createDiv } from '../util/dom';
import { COMPONENT_TYPE } from '../../src/constant';

describe('2495', () => {
it('layout after render twice', () => {
const data = [
{ x: 'a', y: 1, z: 'z1' },
{ x: 'b', y: 2, z: 'z1' },
{ x: 'c', y: 3, z: 'z1' },
{ x: 'a', y: 4, z: 'z2' },
{ x: 'b', y: 5, z: 'z2' },
{ x: 'c', y: 6, z: 'z2' },
];
const chart = new Chart({
container: createDiv(),
width: 600,
height: 500
});

chart.data(data);
chart
.line()
.position('x*y')
.color('z');

chart.render();
chart.render();

// legend 布局到下方
expect(chart.getComponents().filter((co) => co.type === COMPONENT_TYPE.LEGEND)[0].component.get('y')).toBeGreaterThan(400);
});
});

0 comments on commit 4abb893

Please sign in to comment.