-
Notifications
You must be signed in to change notification settings - Fork 293
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
Smooth zooming and moveing to a bounding box in svg #219
Comments
Try |
the zooming only happens after the next zoom/pan interaction with the canvas. I think the problem is the missing call to Line 418 in ecc4855
So I would suggest adding triggerEvent('pan');
triggerEvent('zoom');
makeDirty(); to the end of Also for my use case I would need something like An implementation could be function smoothShowRectangle(rect) {
// getCurrentRect gets the rect which represents the current viewBox of the svg
var currentRect = getCurrentRect();
var from ={
top: currentRect.top,
right: currentRect.right,
bottom: currentRect.bottom,
left: currentRect.left
};
var to = {
top: rect.top,
right: rect.right,
bottom: rect.bottom,
left: rect.left
};
smoothScroll.cancel();
cancelShowRectangleAnimation();
showRectangleAnimation = animate(from, to, {
step: function (r) {
showRectangle(r);
},
done: triggerZoomEnd
});
} I just don't know how |
I think I have found a good implementation for function smoothShowRectangle(rect, duration = undefined) {
cancelAllAnimations();
var to = rect
var from = transformToClientRect(transform);
// default duration is 600ms
var dur = 600;
if (typeof duration === 'function') {
// let consumer calculate a duration based on the new and current transform
dur = duration(from, to);
}
var p = new Promise((resolve, _) => {
showRectangleAnimation = animate(from, to, {
duration: dur,
step: function (nextTransform) {
showRectangle(nextTransform);
},
done: () => {
triggerZoomEnd();
triggerPanEnd();
resolve(true);
}
});
})
return p;
} where function transformToClientRect(transform) {
var clientRect = owner.getBoundingClientRect();
var size = transformToScreen(clientRect.width, clientRect.height);
var w = size.x / transform.scale;
var h = size.y / transform.scale;
var l = transform.x / -transform.scale;
var t = transform.y / -transform.scale;
return {
top: t,
left: l,
bottom: t + h,
right: l + w,
};
} the argument (from, to) => {
var distance = Math.sqrt(
Math.pow(from.top - to.top, 2)
+ Math.pow(from.right - to.right, 2)
+ Math.pow(from.bottom - to.bottom, 2)
+ Math.pow(from.left - to.left, 2)
);
var exp_diff = Math.exp(distance / 1000);
var sigmoid = (exp_diff * 1000) / (exp_diff + 1);
return sigmoid;
} it used the euclidien distance to determine the "distance" between the two rects and then used a scaled sigmoid function to cap the duration at 1 second. I also added a Promise as a return value so that the consumer can act after the animation is over The corisponding typescript binding is smoothShowRectangle: (rect: ClientRect, duration: (from:ClientRect, to:ClientRect) => number) => Promise<boolean>; It might also be worth considering to add a promise to the other smooth function. Should I fork or create a branch, implement it and create a pull request for the changes? |
It would maybe also worth considering to make |
I also need to zoom to a specific rect, and came here because |
@attilam I will try to commit my changes into a fork or new branch this weekend. But I can't promise it. But besides the call to |
Thanks! I take it |
@attilam I implemented the function in a fork https://github.com/Timo-Weike/panzoom and @anvaka I also made a pull-request for my changes #221 |
@Timo-Weike Thank you!! |
Can we exepect that the #221 will be merged into the master branch? :) |
I have a svg graphic and upon an event I want to move and zoom smoothly to a specific bounding box.
Lets say we have this circle
upon an event I want to move and zoom the scene to the bounding box
but the functions
smoothZoomAbs
andsmoothMoveTo
seam ill fit since they do not operate together andsmoothZoomAbs
does zoom according to screen coordinates.How could I accomplish this?
The text was updated successfully, but these errors were encountered: