[reportlab-users] Problem with row&column spanning code not calculating table heights

Oliver Bleutgen reportlab-users@reportlab.com
Thu, 16 Oct 2003 18:21:08 +0200


Second try ...

Robin Becker wrote:

> 
> Your approach sounds more feasible. I think it boils down to
> 1) Find the minimum distance from the top of each cell bottom based only
> on cells above it; append this to a list cb[r].
> 
> 2) Find the maximum value over the elements of cb[r]. That gives a
> feasible bottom of row r.
> 
> The only problem here is that when we have bothe spanned columns and
> rows the idea of a column is slightly harder to establish. I'm guessing
> that we really need to search over cells establishing the minimum stuff
> above us. 

I don't think column spanning cells change the problem, you just
virtually split them when setting up the dicts. So if you have
(c0010,c01,c11), where c0010 spans the first row, you'll get
[{0:c0010.height,1:c01.height},{0:c0010.height,1:c11.height}].

If you set up the same dict, now with indexed with cols instead of rows,
you can do the complete calculation for table witdh and height in one
pass. But maybe tuning should come after a correct solution is
established ;).

> My only other gripe with this is that wne rows are not in the
> maximum path we don't adjust them in proportion to their desires so in
> the first case below the cells in column 1 both require height 0.5, but
> in the computed solution the row heights are 0.5 and 1.5. Although
> completely feasible this may not look nice.

No it doesn't. But I didn't go into that, because have no idea how
platypus does or should react to that. If you want to really follow the
adjustment idea, this should also not be too hard:
If you have calculated the maximum height mrh[n] for row n, you stretch
out every column which has a cell at row n, or a spanning cell which
ends at row n, by the factor mrh[n]/height_of_this_column. This should
fit quite well in the algorithm.

> My version of the code is slightly more efficient 

Because of this snippet?

>         nr = -1                 # find the number of rows
>         for c in crh:
>                 nr = max(nr, max(c.keys()))
>         nr += 1



cheers,
oliver