Centering after zooming issue

13 views
Skip to first unread message

flex_plat

unread,
Jun 28, 2009, 4:36:51 AM6/28/09
to BirdEye
Hi all.
It seems that the code is broken when it comes to centering the graph
when the scale is different than 1.

this:

vgraph.scroll(-1 * vgraph.origin.x, -1 * vgraph.origin.y); // center

is supposed to center the graph, because it assumes that the origin is
changed correctly whenever the canvas is scrolled. I believe that for
some reason this method in VisualGraph.as doesn't work as expected:

override public function set scale(s:Number):void
{
const s0:Number = scaleX;
scaleX = s;
scaleY = s;
scroll(center.x * (1 - s / s0) / s, center.y * (1 - s / s0) / s);
refresh();
_scale = s;
}

You can easily see this by zooming the graph , then dragging the
background, then calling

vgraph.scroll(-1 * vgraph.origin.x, -1 * vgraph.origin.y); // center

You will see that the graph will NOT be centered (it will be either a
bit to the left or to the right, depending on the zoom value).

Anyone else encountered this problem?
Any ideas how to fix this?

Frustrated.

RaVIS

unread,
Jun 29, 2009, 4:13:56 AM6/29/09
to BirdEye
Hi,

If origin is properly set, try taking account of scale value when
scrolling :
vgraph.scroll(-1*vgraph.origin.x / vgraphe.scale ,
-1*vgraph.origin.y / vgraphe.scale)

If origin isn't changed correctly, rely on the center of rectangle
bound computed by calcBounds() method of visual graph.

DjiAntika.

flex_plat

unread,
Jun 29, 2009, 7:25:44 AM6/29/09
to BirdEye
Scrolling with division by scale does not work. I just get weird
positions.

No such method calcBounds () in VisualGraph.as.

RaVIS

unread,
Jun 29, 2009, 7:51:25 AM6/29/09
to BirdEye
My fault, the method is : calcNodesBoundingBox()

flex_plat

unread,
Jun 30, 2009, 4:43:13 AM6/30/09
to BirdEye
thanks

For anyone interested, mycode for centering the graph by the root node
is:

var nodeCenter = vgraph.graph.nodeByStringId
("my_root_node_id").vnode.viewCenter.x * vgraph.scale;
vgraph.scroll(0, -1 * vgraph.origin.y); // I overrid scale() to
scroll only the X, hence the 0
var gCenter:Number = vgraph.center.x;
vgraph.scroll((gCenter - nodeCenter) / vgraph.scale, 0);

if I wanted to center according to the (whole) graph i'd go:

var bb:Rectangle = vgraph.calcNodesBoundingBox();
var bCenter:Number = (bb.x - (15 * vgraph.scale) + (bb.width / 2)) *
vgraph.scale; // the center of bounds
vgraph.scroll((gCenter - bCenter) / vgraph.scale, 0);

(not sure what will happen in case the graph exceeds the canvas,
though it should work)

Rico Leuthold

unread,
Jul 2, 2009, 11:33:46 AM7/2/09
to flexviz...@googlegroups.com
Hi,

Thank's for the code. Helped me a lot.

_rico
Reply all
Reply to author
Forward
0 new messages