--- gantt_org.rb Mon Mar 7 20:41:58 2011 +++ gantt.rb Wed May 25 20:45:05 2011 @@ -257,9 +257,31 @@ case options[:format] when :pdf options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) + vertical_line_pdf(options) end end + def vertical_line_pdf(options) + left = options[:subject_width] + day = 0 + options[:pdf].SetFontStyle('B',7) + width = options[:zoom] + options[:pdf].SetDrawColor(200,200,200) + (self.date_to - self.date_from).to_i.times do + options[:pdf].SetY(options[:top_start]) + options[:pdf].SetX(left) + options[:pdf].Cell(width, options[:top] - options[:top_start], "", "R", 0, "C") + if Time.now.beginning_of_day == self.date_from.since(day.days) + options[:pdf].SetDrawColor(255, 0, 0) + options[:pdf].Line(left + width / 2, options[:top_start], left + width / 2, options[:top]) + options[:pdf].SetDrawColor(200,200,200) + end + left = left + width + day = day + 1 + end + options[:pdf].SetDrawColor(0, 0, 0) + end + def subject_for_project(project, options) case options[:format] when :html @@ -436,23 +458,23 @@ # Weeks headers if show_weeks - left = subject_width - height = header_heigth - if @date_from.cwday == 1 - # date_from is monday + left = subject_width + height = header_heigth + if @date_from.cwday == 1 + # date_from is monday week_f = date_from - else - # find next monday after date_from - week_f = @date_from + (7 - @date_from.cwday + 1) - width = (7 - @date_from.cwday + 1) * zoom + else + # find next monday after date_from + week_f = @date_from + (7 - @date_from.cwday + 1) + width = (7 - @date_from.cwday + 1) * zoom gc.fill('white') gc.stroke('grey') gc.stroke_width(1) gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1) - left = left + width - end - while week_f <= date_to - width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom + left = left + width + end + while week_f <= date_to + width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom gc.fill('white') gc.stroke('grey') gc.stroke_width(1) @@ -461,17 +483,17 @@ gc.stroke('transparent') gc.stroke_width(1) gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s) - left = left + width - week_f = week_f+7 - end + left = left + width + week_f = week_f+7 + end end # Days details (week-end in grey) if show_days - left = subject_width - height = g_height + header_heigth - 1 - wday = @date_from.cwday - (date_to - @date_from + 1).to_i.times do + left = subject_width + height = g_height + header_heigth - 1 + wday = @date_from.cwday + (date_to - @date_from + 1).to_i.times do width = zoom gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white') gc.stroke('#ddd') @@ -480,7 +502,7 @@ left = left + width wday = wday + 1 wday = 1 if wday > 7 - end + end end # border @@ -519,7 +541,7 @@ pdf.SetX(15) pdf.Cell(PDF::LeftPaneWidth, 20, project.to_s) pdf.Ln - pdf.SetFontStyle('B',9) + pdf.SetFontStyle('B',8) subject_width = PDF::LeftPaneWidth header_heigth = 5 @@ -527,13 +549,15 @@ headers_heigth = header_heigth show_weeks = false show_days = false + show_day_num = false if self.months < 7 show_weeks = true headers_heigth = 2*header_heigth if self.months < 3 show_days = true - headers_heigth = 3*header_heigth + show_day_num = true + headers_heigth = 4*header_heigth end end @@ -583,20 +607,58 @@ end end + # Day num headers + if show_day_num + left = subject_width + height = header_heigth + wday = self.date_from.cwday + pdf.SetFontStyle('B',7) + day_num = self.date_from + (self.date_to - self.date_from + 1).to_i.times do + width = zoom + pdf.SetY(y_start + 2 * header_heigth) + pdf.SetX(left) + case(wday) + when 6 + pdf.SetTextColor(0, 0, 255) + when 7 + pdf.SetTextColor(255, 0, 0) + else + pdf.SetTextColor(0, 0, 0) + end + pdf.Cell(width, height, day_num.day.to_s, "LTR", 0, "C") + left = left + width + day_num = day_num + 1 + wday = wday + 1 + wday = 1 if wday > 7 + end + end + # Days headers if show_days left = subject_width height = header_heigth wday = self.date_from.cwday - pdf.SetFontStyle('B',7) + day_num = self.date_from + pdf.SetFontStyle('B',6) (self.date_to - self.date_from + 1).to_i.times do width = zoom - pdf.SetY(y_start + 2 * header_heigth) + case(wday) + when 6 + pdf.SetTextColor(0, 0, 255) + when 7 + pdf.SetTextColor(255, 0, 0) + else + pdf.SetTextColor(0, 0, 0) + end + pdf.SetY(y_start + 3 * header_heigth) pdf.SetX(left) pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C") left = left + width + day_num = day_num + 1 wday = wday + 1 wday = 1 if wday > 7 + pdf.SetTextColor(0,0,0) end end @@ -608,6 +670,7 @@ top = headers_heigth + y_start options = { :top => top, + :top_start => top, :zoom => zoom, :subject_width => subject_width, :g_width => g_width, @@ -679,9 +742,9 @@ # TODO: top level issues should be sorted by start date def gantt_issue_compare(x, y, issues) if x.root_id == y.root_id - x.lft <=> y.lft + x.lft <=> y.lft else - x.root_id <=> y.root_id + x.root_id <=> y.root_id end end @@ -701,9 +764,10 @@ def pdf_new_page?(options) if options[:top] > 180 + vertical_line_pdf(options) options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) options[:pdf].AddPage("L") - options[:top] = 15 + options[:top] = options[:top_start] = 15 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) end end