Skip to content

Commit

Permalink
fix: 🐛 auto zoom minimap graph to fit content (antvis#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored May 16, 2022
1 parent cde1337 commit 12e3e89
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/x6/src/addon/minimap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export class MiniMap extends View {
} else {
this.sourceGraph.on('translate', this.onSourceGraphTransform, this)
this.sourceGraph.on('scale', this.onSourceGraphTransform, this)
this.sourceGraph.on('cell:added', this.zoomToFit, this)
this.sourceGraph.on('cell:removed', this.zoomToFit, this)
this.sourceGraph.on('reseted', this.zoomToFit, this)
}
this.sourceGraph.on('resize', this.updatePaper, this)
this.delegateEvents({
Expand All @@ -147,6 +150,9 @@ export class MiniMap extends View {
} else {
this.sourceGraph.off('translate', this.onSourceGraphTransform, this)
this.sourceGraph.off('scale', this.onSourceGraphTransform, this)
this.sourceGraph.off('cell:added', this.zoomToFit, this)
this.sourceGraph.off('cell:removed', this.zoomToFit, this)
this.sourceGraph.off('reseted', this.zoomToFit, this)
}
this.sourceGraph.off('resize', this.updatePaper, this)
this.undelegateEvents()
Expand All @@ -169,6 +175,10 @@ export class MiniMap extends View {
}
}

protected zoomToFit() {
this.targetGraph.zoomToFit()
}

protected updatePaper(width: number, height: number): this
protected updatePaper({ width, height }: EventArgs['resize']): this
protected updatePaper(w: number | EventArgs['resize'], h?: number) {
Expand Down

0 comments on commit 12e3e89

Please sign in to comment.