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

Performance improvements for pan & zoom #302

Merged
merged 15 commits into from
Jul 15, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more improvements to d3 tranform with requestanimationframe
  • Loading branch information
zakandrewking committed Jul 15, 2019
commit 4efd4275577bb4329c6581153afb042ae90404f1
33 changes: 21 additions & 12 deletions src/ZoomContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export default class ZoomContainer {
// redraw the svg
this._zoomTimeout = _.delay(() => {
// redraw the svg
this._requestedFrame = false
this._goToSvg(scale, translate)
}, 100) // between 100 and 600 seems to be usable
} else { // no 3d transform
Expand All @@ -281,13 +282,17 @@ export default class ZoomContainer {
requestAnimationFrame(() => {
this._requestedFrame = false
const transform = this._3dTransform
this.css3TransformContainer.style('transform', transform)
this.css3TransformContainer.style('-webkit-transform', transform)
this.css3TransformContainer.style('transform-origin', '0 0')
this.css3TransformContainer.style('-webkit-transform-origin', '0 0')
if (transform) {
this.css3TransformContainer.style('transform', transform)
this.css3TransformContainer.style('-webkit-transform', transform)
this.css3TransformContainer.style('transform-origin', '0 0')
this.css3TransformContainer.style('-webkit-transform-origin', '0 0')
} else {
console.warn('No _3dTransform defined')
}
})
}
}
}

/**
* Zoom & pan the CSS 3D transform container
Expand All @@ -303,17 +308,24 @@ export default class ZoomContainer {
}

_clear3d () {
this.css3TransformContainer.style('transform', null)
this.css3TransformContainer.style('-webkit-transform', null)
this.css3TransformContainer.style('transform-origin', null)
this.css3TransformContainer.style('-webkit-transform-origin', null)
if (this._3dTransform) {
this._3dTransform = null
this.css3TransformContainer.style('transform', null)
this.css3TransformContainer.style('-webkit-transform', null)
this.css3TransformContainer.style('transform-origin', null)
this.css3TransformContainer.style('-webkit-transform-origin', null)
}
}

_goToSvgFrame (callback = null) {
if (!this._requestedFrame || callback) {
this._requestedFrame = true
requestAnimationFrame(() => {
this._requestedFrame = false

// reset the 3d transform
this._clear3d()

const scale = this._svgScale
const translate = this._svgTranslate
this.zoomedSel
Expand All @@ -332,9 +344,6 @@ export default class ZoomContainer {
* @param {Function} callback - (optional) A callback to run after scaling.
*/
_goToSvg (scale, translate, callback = null) {
// reset the 3d transform
this._clear3d()

// redraw the svg
// save svg location
this._svgScale = scale
Expand Down