Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(offscreen): sync clip style in offscreen group #2795

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/geometry/element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ export default class Element extends Base {
animateCfg,
index: number = 0
) {
// 所有的 shape 都需要同步 clip
const clip = sourceShape.get('clipShape');
const newClip = targetShape.get('clipShape');

if (clip && newClip) {
this.syncShapeStyle(clip, newClip, state, animateCfg);
}

if (sourceShape.isGroup()) {
const children = sourceShape.get('children');
const newChildren = targetShape.get('children');
Expand Down
61 changes: 61 additions & 0 deletions tests/bugs/2798-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Chart, registerShape } from '../../src';
import { createDiv } from '../util/dom';

registerShape('interval', '2798-shape', {
draw(cfg, container) {
const center = this.parsePoint({ x: 0.5, y: 0.5 });
container.setClip({
type: 'circle',
attrs: {
x: center.x,
y: center.y,
r: 50,
},
});

container.addShape('rect', {
name: 'rect',
attrs: {
x: 0,
y: 0,
width: 400,
height: 300,
fill: 'red',
},
});

return container;
}
})

describe('2798', () => {
it('2798', () => {
const data = [
{ type: '一线城市', value: 0.19 },
];
const chart = new Chart({
container: createDiv(),
width: 400,
height: 300,
autoFit: false,
});
chart.data(data);
chart
.interval()
.position('type*value')
.shape('2798-shape')

chart.legend(false);
chart.axis(false);
chart.tooltip(false);
chart.animate(false);

chart.render();

expect(chart.middleGroup.getChildren()[0].get('clipShape').attr('x')).toBe(200);

chart.changeSize(600, 300);

expect(chart.middleGroup.getChildren()[0].get('clipShape').attr('x')).toBe(300);
});
});