mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-18 01:31:47 +00:00
Synchronize transition animations
This commit is contained in:
@@ -121,6 +121,10 @@ export interface ChartProps {
|
|||||||
/** Component showing the genealogy chart and handling transition animations. */
|
/** Component showing the genealogy chart and handling transition animations. */
|
||||||
export class Chart extends React.PureComponent<ChartProps, {}> {
|
export class Chart extends React.PureComponent<ChartProps, {}> {
|
||||||
private chart?: ChartHandle;
|
private chart?: ChartHandle;
|
||||||
|
/** Animation is in progress. */
|
||||||
|
private animating = false;
|
||||||
|
/** Rendering is required after the current animation finishes. */
|
||||||
|
private rerenderRequired = false;
|
||||||
|
|
||||||
private getChartType() {
|
private getChartType() {
|
||||||
switch (this.props.chartType) {
|
switch (this.props.chartType) {
|
||||||
@@ -152,6 +156,12 @@ export class Chart extends React.PureComponent<ChartProps, {}> {
|
|||||||
* animation is performed.
|
* animation is performed.
|
||||||
*/
|
*/
|
||||||
private renderChart(args: {initialRender: boolean} = {initialRender: false}) {
|
private renderChart(args: {initialRender: boolean} = {initialRender: false}) {
|
||||||
|
// Wait for animation to finish if animation is in progress.
|
||||||
|
if (!args.initialRender && this.animating) {
|
||||||
|
this.rerenderRequired = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.initialRender) {
|
if (args.initialRender) {
|
||||||
(d3.select('#chart').node() as HTMLElement).innerHTML = '';
|
(d3.select('#chart').node() as HTMLElement).innerHTML = '';
|
||||||
this.chart = createChart({
|
this.chart = createChart({
|
||||||
@@ -222,6 +232,16 @@ export class Chart extends React.PureComponent<ChartProps, {}> {
|
|||||||
.tween('scrollLeft', scrollLeftTween(-dx))
|
.tween('scrollLeft', scrollLeftTween(-dx))
|
||||||
.tween('scrollTop', scrollTopTween(-dy));
|
.tween('scrollTop', scrollTopTween(-dy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After the animation is finished, rerender the chart if required.
|
||||||
|
this.animating = true;
|
||||||
|
chartInfo.animationPromise.then(() => {
|
||||||
|
this.animating = false;
|
||||||
|
if (this.rerenderRequired) {
|
||||||
|
this.rerenderRequired = false;
|
||||||
|
this.renderChart({initialRender: false});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
|||||||
Reference in New Issue
Block a user