Setting margins of a diagram, for example after a graph layout

Article ID: 2235
Last updated: 29 May, 2018
Article ID: 2235
Last updated: 29 May, 2018
Revision: 3
Views: 666
Posted: 17 Sep, 2003
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How can I set margins of a diagram, after a graph layout?

Answer

If you want to enforce a visual margin only on the left and top side of a diagram, you need to apply a translation

to the IlvTransformer of the IlvManagerView, so that the margin becomes visible.

If you want to make sure that the top/left margin is *at least* the specified margin, you can use IlvManagerView.ensureVisible(IlvPoint) for this purpose:

IlvRect bbox = grapher.boundingBox(grapher.getDrawingTransformer(mgrView)); 

mgrView.ensureVisible(new IlvPoint(bbox.x-leftMargin, bbox.y-topMargin));

If you want to make sure that the top/left margin is *exactly* the specified margin, you use:

IlvRect bbox = grapher.boundingBox(grapher.getDrawingTransformer(mgrView));

float dx = leftMargin - bbox.x;   

float dy = topMargin - bbox.y;    

mgrView.translate(dx, dy, true);

Note that this does not change the current zoom level of the view; it affects only the top and left margin.

The right and bottom margin may become 0, and the right and bottom border may be shifted outside

the visible area of the view.

If you want to enforce all four left, right, top and bottom margins, you must change the zoom level so that these four margins are visible. You can use

Insets insets = new Insets(topMargin, leftMargin, bottomMargin, rightMargin); 

mgrView.fitTransformerToContent(insets);

Notice that in all cases, the margins are given in view coordinates.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2235
Last updated: 29 May, 2018
Revision: 3
Views: 666
Posted: 17 Sep, 2003 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category