Skip to content

Commit

Permalink
fix(state-style): 修复存在状态时,动画丢失
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Sep 28, 2021
1 parent 9299079 commit 2619645
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/geometry/element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export default class Element extends Base {
toAttrs: newAttrs,
shapeModel: this.model,
});
} else if (isEmpty(states)) {
} else if (!isEmpty(states)) {
sourceShape.stopAnimate();
sourceShape.animate(newAttrs, {
duration: 300,
Expand Down
42 changes: 42 additions & 0 deletions tests/bugs/element-state-animation-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';

describe('Element with states failed to animate', () => {
const data = [
{ type: '一线城市', value: 0.19 },
{ type: '二线城市', value: 0.21 },
{ type: '三线城市', value: 0.27 },
{ type: '四线及以下', value: 0.33 },
];
const chart = new Chart({
container: createDiv(),
autoFit: true,
height: 500,
});
chart.data(data);
chart.coordinate('theta', {
radius: 0.75,
});
const interval = chart
.interval()
.adjust('stack')
.position('value')
.state({
active: {
style: {
stroke: '#000',
},
},
})
chart.render();

it('normal', () => {
interval.elements[1].setState('active', true);
// 动画中,状态样式没变化
expect(interval.elements[1].shape.attr('stroke')).not.toEqual('#000');
// 2s 动画结束了,状态样式变化了
setTimeout(() => {
expect(interval.elements[1].shape.attr('stroke')).toEqual('#000');
}, 2000)
});
});

0 comments on commit 2619645

Please sign in to comment.