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