Fix Gantt PDF rendering for single-day tasks
When a task starts and ends on the same day, it can happen that the bar in the PDF is rendered wrong, i.e. it's rendered from the start day to the right end of the page.
The problem is in
#pdf_task is called,
coords[:bar_end] - coords[:bar_start] happens to be 0. The cause for this is the zoom factor applied in
#coordindates and the subsequent
#floor. By adding some
Rails.logger statements I got this:
coords[start]: 92/1, zoom: 36/73 coords[start]: 45 coords[bar_start]: 92/1, zoom: 36/73 coords[bar_start]: 45 coords[end]: 92/1, zoom: 36/73 coords[end]: 45 coords[bar_end]: 93/1, zoom: 36/73 coords[bar_end]: 45
Each value shown before/after applying zoom. While before zoom, the values where 92/93, the became 45/45 afterwards.
The attached patch fixes the PDF rendering problem by making sure, the with used in the
RDMCell() call is at least 0.
#3 Updated by Daniel Ritz about 1 year ago
- File pdf-vs-png.png added
Sorry, I have no easy reproducer. I used a dump of our productive DB while working on the fix...
Attached is a screenshot with comparing the Gantt rendered correctly as PNG and incorrectly as PDF. After the fix, the PDF looks correct too (no screenshot taken).
Tasks 3-7 shown on the screenshot are single-day tasks and should all render the same.