prawnpdf/prawn — Issue #326: min_width calculation in cells.rb wrong
Author: AngeloMichel
Created: 2012-02-17 11:05:04+00:00
State: open

I cannot fully explain why, but I can show (by logging results how) "def min_width" (which basically calls "aggregate_cell_values(:column, :avg_spanned_min_width, :max)") gives false returns in the following case.

Lets say I have a table which is 400 in width.
Column_widths are: [ 90, 160, 44, 53, 53 ] (aka 400)

In my data table I say something like
[
["a", {content: "b", colspan:2}, "d","e"],
["f","g","h","i",j"]
]

If you log every Cell.rb -> avg_spanned_min_width, you get the following results:
Cell.rb#avg_spanned_min_width -> min_width / colspan (90 / 1) = 90.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (204 / 2) = 102.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (204 / 2) = 102.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (53 / 1) = 53.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (53 / 1) = 53.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (90 / 1) = 90.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (160 / 1) = 160.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (44 / 1) = 44.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (53 / 1) = 53.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (53 / 1) = 53.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (90 / 1) = 90.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (160 / 1) = 160.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (44 / 1) = 44.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (53 / 1) = 53.0
Cell.rb#avg_spanned_min_width -> min_width / colspan (53 / 1) = 53.0

this is from cell.rb (not cell s .rb) (and sorry for the text above, it's from my log)

The returning value in aggregate is:
Cells.rb#aggregate_cell_values values -> [90.0, 160.0, 102.0, 53.0, 53.0]

And here is the error. the 2nd and 3rd value should match 102.0, 102.0 beause of the colspan OR should match 160.0, 44.0 without the colspan.

This has to do with the :max (102.0 is higher than 44.0 so it takes 102.0 at the 3rd position, while 160.0 is higher than 102.0, so it takes that).

I am not sure how to fix it, but is must be some solution which accounts for colspan columns (or makes an average instead of max).

This is, to me a real issue, because I cannot use colspan in my case. If anyone knows a quickfix (or even better full fix), please submit :)