Defect #32916

Bar length is wrong when exporting gantt chart to PDF

Added by taca tadocolo 9 months ago. Updated 5 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Gantt
Target version:-
Resolution:Duplicate Affected version:4.1.0

Description

When exporting a gantt chart to PDF, short (1 or 2 days) tasks are sometimes correct and sometimes incorrect, depending on the time period.
(The attached image is modified.)
Export gantt to PDF

Calculation error of start and end points?
Or error due to Windows environment?

Same for Redmine 4.0.4 and earlier.

gc2pdf.png - Export gantt to PDF (80.9 KB) taca tadocolo, 2020-01-29 06:11


Related issues

Duplicates Redmine - Defect #23645: Gantt bars for single-day tasks may be rendered wrongly i... Closed

History

#1 Updated by taca tadocolo 9 months ago

Improved bar length calculation accuracy for exporting to PDF (and png).
(modified patch code)

--- a/lib/redmine/helpers/gantt.rb
+++ b/lib/redmine/helpers/gantt.rb
@@ -632,7 +632,7 @@
           end
           if end_date < self.date_to
             coords[:end] = end_date - self.date_from
-            coords[:bar_end] = end_date - self.date_from + 1
+            coords[:bar_end] = calc_bar_end(coords[:bar_start], end_date, zoom)
           else
             coords[:bar_end] = self.date_to - self.date_from + 1
           end
@@ -640,16 +640,16 @@
             progress_date = calc_progress_date(start_date, end_date, progress)
             if progress_date > self.date_from && progress_date > start_date
               if progress_date < self.date_to
-                coords[:bar_progress_end] = progress_date - self.date_from
+                coords[:bar_progress_end] = calc_bar_end(coords[:bar_start], progress_date, zoom)
               else
                 coords[:bar_progress_end] = self.date_to - self.date_from + 1
               end
             end
             if progress_date <= User.current.today
-              late_date = [User.current.today, end_date].min + 1
+              late_date = [User.current.today, end_date].min
               if late_date > self.date_from && late_date > start_date
                 if late_date < self.date_to
-                  coords[:bar_late_end] = late_date - self.date_from
+                  coords[:bar_late_end] = calc_bar_end(coords[:bar_start], late_date, zoom)
                 else
                   coords[:bar_late_end] = self.date_to - self.date_from + 1
                 end
@@ -665,7 +665,16 @@
       end

       def calc_progress_date(start_date, end_date, progress)
-        start_date + (end_date - start_date + 1) * (progress / 100.0)
+        start_date + (end_date - start_date) * (progress / 100.0)
+      end
+
+      def calc_bar_end(start_date, end_date, zoom)
+        end_of_bar = end_date - self.date_from + 1
+        start_zoom = (start_date * zoom).floor
+        if (end_of_bar * zoom).floor <= start_zoom
+          end_of_bar = (start_zoom + 1) / zoom
+        end
+        end_of_bar
       end

       # Singleton class method is public

#2 Updated by taca tadocolo 5 months ago

  • Status changed from New to Resolved

Related to #23645 (Gantt bars for single-day tasks may be rendered wrongly in PDF)

#3 Updated by Mischa The Evil 5 months ago

  • Status changed from Resolved to Needs feedback
  • Assignee set to taca tadocolo

taca tadocolo wrote:

Related to #23645 (Gantt bars for single-day tasks may be rendered wrongly in PDF)

So the issue reported in this issue is solved by the changes for #23645? Can you confirm that is the case (also the png version of the gantt)?

#4 Updated by taca tadocolo 5 months ago

Mischa The Evil wrote:

taca tadocolo wrote:

Related to #23645 (Gantt bars for single-day tasks may be rendered wrongly in PDF)

So the issue reported in this issue is solved by the changes for #23645? Can you confirm that is the case (also the png version of the gantt)?

Yes, I confirmed this issue has been resolved in Redmine 4.1.1.

#5 Updated by Mischa The Evil 5 months ago

  • Duplicates Defect #23645: Gantt bars for single-day tasks may be rendered wrongly in PDF added

#6 Updated by Mischa The Evil 5 months ago

  • Status changed from Needs feedback to Closed
  • Assignee deleted (taca tadocolo)
  • Resolution set to Duplicate

Thanks for the feedback. Closing as such.

Also available in: Atom PDF