Skip to content

Commit

Permalink
Merge pull request #555 from VisActor/fix/animation-of-wordcloud
Browse files Browse the repository at this point in the history
Fix/animation of wordcloud
  • Loading branch information
xile611 authored Sep 26, 2024
2 parents 423678c + be2e4f8 commit 894f506
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix animation state of wordcloud\n\n",
"type": "none",
"packageName": "@visactor/vgrammar-core"
}
],
"packageName": "@visactor/vgrammar-core",
"email": "dingling112@gmail.com"
}
10 changes: 7 additions & 3 deletions docs/site/assets/examples/en/animate/arrange-animate.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ const vGrammarView = new View({
container: document.getElementById(CONTAINER_ID),
hover: true
});
vGrammarView.parseSpec(spec);

vGrammarView.run().then(() => {
const handleAfterRun = () => {
const title = vGrammarView.getMarkById('title');
const leftAxis = vGrammarView.getMarkById('leftAxis');
const bottomAxis = vGrammarView.getMarkById('bottomAxis');
Expand Down Expand Up @@ -404,7 +403,12 @@ vGrammarView.run().then(() => {
options: { overall: viewBox.getValue().y2, orient: 'negative' }
})
.after(animation2);
});
};
vGrammarView.parseSpec(spec);

vGrammarView.run();

handleAfterRun();

// 只为了方便控制太调试用,不要拷贝
window.vGrammarView = vGrammarView;
Expand Down
4 changes: 2 additions & 2 deletions docs/site/assets/examples/en/animate/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const spec = {
return 0;
},
to: (datum, element, params) => {
const xScale = params.view.getScaleById('xscale').output();
const xScale = params.xscale;
const bandWidth = xScale.bandwidth();
const range = xScale.range();
return -Math.abs(range[1] - range[0]);
Expand Down Expand Up @@ -377,7 +377,7 @@ const spec = {
channel: {
dx: {
from: (datum, element, params) => {
const xScale = params.view.getScaleById('xscale').output();
const xScale = params.xscale;
const bandWidth = xScale.bandwidth();
const range = xScale.range();
return Math.abs(range[1] - range[0]);
Expand Down
10 changes: 7 additions & 3 deletions docs/site/assets/examples/zh/animate/arrange-animate.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ const vGrammarView = new View({
container: document.getElementById(CONTAINER_ID),
hover: true
});
vGrammarView.parseSpec(spec);

vGrammarView.run().then(() => {
const handleAfterRun = () => {
const title = vGrammarView.getMarkById('title');
const leftAxis = vGrammarView.getMarkById('leftAxis');
const bottomAxis = vGrammarView.getMarkById('bottomAxis');
Expand Down Expand Up @@ -404,7 +403,12 @@ vGrammarView.run().then(() => {
options: { overall: viewBox.getValue().y2, orient: 'negative' }
})
.after(animation2);
});
};
vGrammarView.parseSpec(spec);

vGrammarView.run();

handleAfterRun();

// 只为了方便控制太调试用,不要拷贝
window.vGrammarView = vGrammarView;
Expand Down
6 changes: 3 additions & 3 deletions docs/site/assets/examples/zh/animate/loop-animate.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ const vGrammarView = new View({
});
vGrammarView.parseSpec(spec);

vGrammarView.run().then(() => {
vGrammarView.getMarkById('bar').animate.runAnimationByState('loop');
});
vGrammarView.run();

vGrammarView.getMarkById('bar').animate.runAnimationByState('loop');

// 只为了方便控制太调试用,不要拷贝
window.vGrammarView = vGrammarView;
Expand Down
4 changes: 2 additions & 2 deletions docs/site/assets/examples/zh/animate/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const spec = {
return 0;
},
to: (datum, element, params) => {
const xScale = params.view.getScaleById('xscale').output();
const xScale = params.xscale;
const bandWidth = xScale.bandwidth();
const range = xScale.range();
return -Math.abs(range[1] - range[0]);
Expand Down Expand Up @@ -377,7 +377,7 @@ const spec = {
channel: {
dx: {
from: (datum, element, params) => {
const xScale = params.view.getScaleById('xscale').output();
const xScale = params.xscale;
const bandWidth = xScale.bandwidth();
const range = xScale.range();
return Math.abs(range[1] - range[0]);
Expand Down
2 changes: 1 addition & 1 deletion docs/site/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
`../../packages/${pkgName.replace('@visactor/vgrammar', 'vgrammar')}/src/index.ts`
)
};
}, {})
}, {}),
}
},
plugins: [react()]
Expand Down
2 changes: 2 additions & 0 deletions packages/vgrammar-core/src/view/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ export default class View extends EventEmitter implements IView {
if (!this._progressiveMarks && this.animate) {
this.animate.animate();
} else {
// 清理没有动画的离场元素
this.traverseMarkTree(
mark => {
mark.cleanExitElements();
Expand All @@ -816,6 +817,7 @@ export default class View extends EventEmitter implements IView {
}
// 绘图 =>
this.renderer.render(immediately);
//
this.handleRenderEnd();
}
this.emit(HOOK_EVENT.AFTER_DO_RENDER);
Expand Down
Loading

0 comments on commit 894f506

Please sign in to comment.