Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

Zoom animation calculations for zoomToRect

$
0
0

@Charles wrote:

So after some looking around, it seems that there is no current zoomToRect functionality that handles animation.

The diagram has a zoomToRect that does not animate, and commandHandler has a zoom in and a scrollToRect which both animate, but no zoomToRect, so I’m just rolling my own using the animation system:

var animation = new go.Animation();
animation.add(myDiagram, "scale", myDiagram.scale, scale);
animation.add(myDiagram, "position", myDiagram.position, new go.Point(rect.x, rect.y));
animation.start();

However, I’m having some trouble getting the correct values for scale and position.

Right now I get the position and scale in a doubleClick handler that does the subGraph expansion:

cmd.expandSubGraph(group);
var rect = group.actualBounds;
var scale = Math.min(myDiagram.viewportBounds.width/rect.width, 
myDiagram.viewportBounds.height/rect.height);

However, these values don’t see to be quite right, and my spatial geometry brain apparently isn’t quite up to the task of figuring out what the right calculation is. I tried looking at the zoomToRect function in diagram, but the minified code makes parsing the logic a bit difficult.

It looks like it’s checking for a NaN height/width and if it finds one, the logic is just scale = <viewport.height/width>*/<new rect height/width>, however I can’t figure out what the calculation is when the rect has both a height and a width.

What would be the correct way to calculate the position and scale to create a “zoomToRect” animation for an arbitrary rectangle +/- a margin?

basically this but an animation:

myDiagram.zoomToRect(group.actualBounds.addMargin(new go.Margin(ZOOM_MARGIN)));
myDiagram.centerRect(group.actualBounds);

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles