[reportlab-users] Graphic objects now know their size (was Size of LinePlot)

Andy Robinson reportlab-users@reportlab.com
Sun, 3 Aug 2003 14:05:30 +0100

I just checked this in.  Every object in the graphics framework
now responds to a getBounds() method with a 4-tuple of 
(x1,y1,x2,y2).  There are tests in test_graphics_layout.py.
This should make it easy to iteratively position charts.

For charts, x,y,width and height refer to the plot rectangle,
which is usually the thing to fix on the page.  But getBounds()
will show you where the extreme points (e.g. axis labels) end

For text labels, we assume a boundary whose top is FONTSIZE up
from the baseline, and whose bottom is 0.2* FONTSIZE down.
This is what we do in our paragraph layout.  The actual ascent/descent
published in font files are not always reliable, and this
convention means you always get a consistent baseline when
mixing fonts of the same font size.

>>> from reportlab.graphics.shapes import String
>>> s = String(0,0,'Hello World',fontName='Courier',fontSize=10)
>>> s.getBounds()
(0, -2.0, 66.0, 10)

Best Regards,

Andy Robinson

> -----Original Message-----
> From: reportlab-users-admin@reportlab.com
> [mailto:reportlab-users-admin@reportlab.com]On Behalf Of Andy Robinson
> Sent: 01 August 2003 15:57
> To: reportlab-users@reportlab.com
> Subject: RE: [reportlab-users] Size of LinePlot
> > Hello,
> > 
> > Is there a way to calculate the size of a LinePlot including the axis
> > labels? LinePlot.[width,height] only give the size of the drawing
> > without the labels.
> > 
> Robin's right, what I wrote should logically be moved into
> the framework now - it seems stable enough and I think is
> broadly right. I am working on this now and will try to check in 
> tomorrow morning.
> I did a recursive function getBounds(object) to avoid touching
> existing code; I will change this to a getBounds method on
> every shapes or widget.   For a visible check, there's a
> Sizer object you can create around a chart which will draw
> some vile purple borders and show whether it is correct or not.
> - Andy
> _______________________________________________
> reportlab-users mailing list
> reportlab-users@reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users