@@ -1,882 +1,837 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine |
|
18 | module Redmine | |
19 | module Helpers |
|
19 | module Helpers | |
20 | # Simple class to handle gantt chart data |
|
20 | # Simple class to handle gantt chart data | |
21 | class Gantt |
|
21 | class Gantt | |
22 | include ERB::Util |
|
22 | include ERB::Util | |
23 | include Redmine::I18n |
|
23 | include Redmine::I18n | |
24 |
|
24 | |||
25 | # :nodoc: |
|
25 | # :nodoc: | |
26 | # Some utility methods for the PDF export |
|
26 | # Some utility methods for the PDF export | |
27 | class PDF |
|
27 | class PDF | |
28 | MaxCharactorsForSubject = 45 |
|
28 | MaxCharactorsForSubject = 45 | |
29 | TotalWidth = 280 |
|
29 | TotalWidth = 280 | |
30 | LeftPaneWidth = 100 |
|
30 | LeftPaneWidth = 100 | |
31 |
|
31 | |||
32 | def self.right_pane_width |
|
32 | def self.right_pane_width | |
33 | TotalWidth - LeftPaneWidth |
|
33 | TotalWidth - LeftPaneWidth | |
34 | end |
|
34 | end | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows |
|
37 | attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows | |
38 | attr_accessor :query |
|
38 | attr_accessor :query | |
39 | attr_accessor :project |
|
39 | attr_accessor :project | |
40 | attr_accessor :view |
|
40 | attr_accessor :view | |
41 |
|
41 | |||
42 | def initialize(options={}) |
|
42 | def initialize(options={}) | |
43 | options = options.dup |
|
43 | options = options.dup | |
44 |
|
44 | |||
45 | if options[:year] && options[:year].to_i >0 |
|
45 | if options[:year] && options[:year].to_i >0 | |
46 | @year_from = options[:year].to_i |
|
46 | @year_from = options[:year].to_i | |
47 | if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12 |
|
47 | if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12 | |
48 | @month_from = options[:month].to_i |
|
48 | @month_from = options[:month].to_i | |
49 | else |
|
49 | else | |
50 | @month_from = 1 |
|
50 | @month_from = 1 | |
51 | end |
|
51 | end | |
52 | else |
|
52 | else | |
53 | @month_from ||= Date.today.month |
|
53 | @month_from ||= Date.today.month | |
54 | @year_from ||= Date.today.year |
|
54 | @year_from ||= Date.today.year | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i |
|
57 | zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i | |
58 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
|
58 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 | |
59 | months = (options[:months] || User.current.pref[:gantt_months]).to_i |
|
59 | months = (options[:months] || User.current.pref[:gantt_months]).to_i | |
60 | @months = (months > 0 && months < 25) ? months : 6 |
|
60 | @months = (months > 0 && months < 25) ? months : 6 | |
61 |
|
61 | |||
62 | # Save gantt parameters as user preference (zoom and months count) |
|
62 | # Save gantt parameters as user preference (zoom and months count) | |
63 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) |
|
63 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) | |
64 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
|
64 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months | |
65 | User.current.preference.save |
|
65 | User.current.preference.save | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
68 | @date_from = Date.civil(@year_from, @month_from, 1) | |
69 | @date_to = (@date_from >> @months) - 1 |
|
69 | @date_to = (@date_from >> @months) - 1 | |
70 |
|
70 | |||
71 | @subjects = '' |
|
71 | @subjects = '' | |
72 | @lines = '' |
|
72 | @lines = '' | |
73 | @number_of_rows = nil |
|
73 | @number_of_rows = nil | |
74 |
|
74 | |||
75 | @truncated = false |
|
75 | @truncated = false | |
76 | if options.has_key?(:max_rows) |
|
76 | if options.has_key?(:max_rows) | |
77 | @max_rows = options[:max_rows] |
|
77 | @max_rows = options[:max_rows] | |
78 | else |
|
78 | else | |
79 | @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i |
|
79 | @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def common_params |
|
83 | def common_params | |
84 | { :controller => 'gantts', :action => 'show', :project_id => @project } |
|
84 | { :controller => 'gantts', :action => 'show', :project_id => @project } | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def params |
|
87 | def params | |
88 | common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months }) |
|
88 | common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months }) | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def params_previous |
|
91 | def params_previous | |
92 | common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months }) |
|
92 | common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months }) | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def params_next |
|
95 | def params_next | |
96 | common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months }) |
|
96 | common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months }) | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | ### Extracted from the HTML view/helpers |
|
99 | ### Extracted from the HTML view/helpers | |
100 | # Returns the number of rows that will be rendered on the Gantt chart |
|
100 | # Returns the number of rows that will be rendered on the Gantt chart | |
101 | def number_of_rows |
|
101 | def number_of_rows | |
102 | return @number_of_rows if @number_of_rows |
|
102 | return @number_of_rows if @number_of_rows | |
103 |
|
103 | |||
104 | rows = if @project |
|
104 | rows = if @project | |
105 | number_of_rows_on_project(@project) |
|
105 | number_of_rows_on_project(@project) | |
106 | else |
|
106 | else | |
107 | Project.roots.visible.has_module('issue_tracking').inject(0) do |total, project| |
|
107 | Project.roots.visible.has_module('issue_tracking').inject(0) do |total, project| | |
108 | total += number_of_rows_on_project(project) |
|
108 | total += number_of_rows_on_project(project) | |
109 | end |
|
109 | end | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
112 | rows > @max_rows ? @max_rows : rows |
|
112 | rows > @max_rows ? @max_rows : rows | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | # Returns the number of rows that will be used to list a project on |
|
115 | # Returns the number of rows that will be used to list a project on | |
116 | # the Gantt chart. This will recurse for each subproject. |
|
116 | # the Gantt chart. This will recurse for each subproject. | |
117 | def number_of_rows_on_project(project) |
|
117 | def number_of_rows_on_project(project) | |
118 | # Remove the project requirement for Versions because it will |
|
118 | # Remove the project requirement for Versions because it will | |
119 | # restrict issues to only be on the current project. This |
|
119 | # restrict issues to only be on the current project. This | |
120 | # ends up missing issues which are assigned to shared versions. |
|
120 | # ends up missing issues which are assigned to shared versions. | |
121 | @query.project = nil if @query.project |
|
121 | @query.project = nil if @query.project | |
122 |
|
122 | |||
123 | # One Root project |
|
123 | # One Root project | |
124 | count = 1 |
|
124 | count = 1 | |
125 | # Issues without a Version |
|
125 | # Issues without a Version | |
126 | count += project.issues.for_gantt.without_version.with_query(@query).count |
|
126 | count += project.issues.for_gantt.without_version.with_query(@query).count | |
127 |
|
127 | |||
128 | # Versions |
|
128 | # Versions | |
129 | count += project.versions.count |
|
129 | count += project.versions.count | |
130 |
|
130 | |||
131 | # Issues on the Versions |
|
131 | # Issues on the Versions | |
132 | project.versions.each do |version| |
|
132 | project.versions.each do |version| | |
133 | count += version.fixed_issues.for_gantt.with_query(@query).count |
|
133 | count += version.fixed_issues.for_gantt.with_query(@query).count | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | # Subprojects |
|
136 | # Subprojects | |
137 | project.children.visible.has_module('issue_tracking').each do |subproject| |
|
137 | project.children.visible.has_module('issue_tracking').each do |subproject| | |
138 | count += number_of_rows_on_project(subproject) |
|
138 | count += number_of_rows_on_project(subproject) | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | count |
|
141 | count | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | # Renders the subjects of the Gantt chart, the left side. |
|
144 | # Renders the subjects of the Gantt chart, the left side. | |
145 | def subjects(options={}) |
|
145 | def subjects(options={}) | |
146 | render(options.merge(:only => :subjects)) unless @subjects_rendered |
|
146 | render(options.merge(:only => :subjects)) unless @subjects_rendered | |
147 | @subjects |
|
147 | @subjects | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | # Renders the lines of the Gantt chart, the right side |
|
150 | # Renders the lines of the Gantt chart, the right side | |
151 | def lines(options={}) |
|
151 | def lines(options={}) | |
152 | render(options.merge(:only => :lines)) unless @lines_rendered |
|
152 | render(options.merge(:only => :lines)) unless @lines_rendered | |
153 | @lines |
|
153 | @lines | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def render(options={}) |
|
156 | def render(options={}) | |
157 | options = {:indent => 4, :render => :subject, :format => :html}.merge(options) |
|
157 | options = {:indent => 4, :render => :subject, :format => :html}.merge(options) | |
158 |
|
158 | |||
159 | @subjects = '' unless options[:only] == :lines |
|
159 | @subjects = '' unless options[:only] == :lines | |
160 | @lines = '' unless options[:only] == :subjects |
|
160 | @lines = '' unless options[:only] == :subjects | |
161 | @number_of_rows = 0 |
|
161 | @number_of_rows = 0 | |
162 |
|
162 | |||
163 | if @project |
|
163 | if @project | |
164 | render_project(@project, options) |
|
164 | render_project(@project, options) | |
165 | else |
|
165 | else | |
166 | Project.roots.visible.has_module('issue_tracking').each do |project| |
|
166 | Project.roots.visible.has_module('issue_tracking').each do |project| | |
167 | render_project(project, options) |
|
167 | render_project(project, options) | |
168 | break if abort? |
|
168 | break if abort? | |
169 | end |
|
169 | end | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | @subjects_rendered = true unless options[:only] == :lines |
|
172 | @subjects_rendered = true unless options[:only] == :lines | |
173 | @lines_rendered = true unless options[:only] == :subjects |
|
173 | @lines_rendered = true unless options[:only] == :subjects | |
174 |
|
174 | |||
175 | render_end(options) |
|
175 | render_end(options) | |
176 | end |
|
176 | end | |
177 |
|
177 | |||
178 | def render_project(project, options={}) |
|
178 | def render_project(project, options={}) | |
179 | options[:top] = 0 unless options.key? :top |
|
179 | options[:top] = 0 unless options.key? :top | |
180 | options[:indent_increment] = 20 unless options.key? :indent_increment |
|
180 | options[:indent_increment] = 20 unless options.key? :indent_increment | |
181 | options[:top_increment] = 20 unless options.key? :top_increment |
|
181 | options[:top_increment] = 20 unless options.key? :top_increment | |
182 |
|
182 | |||
183 | subject_for_project(project, options) unless options[:only] == :lines |
|
183 | subject_for_project(project, options) unless options[:only] == :lines | |
184 | line_for_project(project, options) unless options[:only] == :subjects |
|
184 | line_for_project(project, options) unless options[:only] == :subjects | |
185 |
|
185 | |||
186 | options[:top] += options[:top_increment] |
|
186 | options[:top] += options[:top_increment] | |
187 | options[:indent] += options[:indent_increment] |
|
187 | options[:indent] += options[:indent_increment] | |
188 | @number_of_rows += 1 |
|
188 | @number_of_rows += 1 | |
189 | return if abort? |
|
189 | return if abort? | |
190 |
|
190 | |||
191 | # Second, Issues without a version |
|
191 | # Second, Issues without a version | |
192 | issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit) |
|
192 | issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit) | |
193 | sort_issues!(issues) |
|
193 | sort_issues!(issues) | |
194 | if issues |
|
194 | if issues | |
195 | render_issues(issues, options) |
|
195 | render_issues(issues, options) | |
196 | return if abort? |
|
196 | return if abort? | |
197 | end |
|
197 | end | |
198 |
|
198 | |||
199 | # Third, Versions |
|
199 | # Third, Versions | |
200 | project.versions.sort.each do |version| |
|
200 | project.versions.sort.each do |version| | |
201 | render_version(version, options) |
|
201 | render_version(version, options) | |
202 | return if abort? |
|
202 | return if abort? | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | # Fourth, subprojects |
|
205 | # Fourth, subprojects | |
206 | project.children.visible.has_module('issue_tracking').each do |project| |
|
206 | project.children.visible.has_module('issue_tracking').each do |project| | |
207 | render_project(project, options) |
|
207 | render_project(project, options) | |
208 | return if abort? |
|
208 | return if abort? | |
209 | end unless project.leaf? |
|
209 | end unless project.leaf? | |
210 |
|
210 | |||
211 | # Remove indent to hit the next sibling |
|
211 | # Remove indent to hit the next sibling | |
212 | options[:indent] -= options[:indent_increment] |
|
212 | options[:indent] -= options[:indent_increment] | |
213 | end |
|
213 | end | |
214 |
|
214 | |||
215 | def render_issues(issues, options={}) |
|
215 | def render_issues(issues, options={}) | |
216 | issues.each do |i| |
|
216 | issues.each do |i| | |
217 | subject_for_issue(i, options) unless options[:only] == :lines |
|
217 | subject_for_issue(i, options) unless options[:only] == :lines | |
218 | line_for_issue(i, options) unless options[:only] == :subjects |
|
218 | line_for_issue(i, options) unless options[:only] == :subjects | |
219 |
|
219 | |||
220 | options[:top] += options[:top_increment] |
|
220 | options[:top] += options[:top_increment] | |
221 | @number_of_rows += 1 |
|
221 | @number_of_rows += 1 | |
222 | return if abort? |
|
222 | return if abort? | |
223 | end |
|
223 | end | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | def render_version(version, options={}) |
|
226 | def render_version(version, options={}) | |
227 | # Version header |
|
227 | # Version header | |
228 | subject_for_version(version, options) unless options[:only] == :lines |
|
228 | subject_for_version(version, options) unless options[:only] == :lines | |
229 | line_for_version(version, options) unless options[:only] == :subjects |
|
229 | line_for_version(version, options) unless options[:only] == :subjects | |
230 |
|
230 | |||
231 | options[:top] += options[:top_increment] |
|
231 | options[:top] += options[:top_increment] | |
232 | @number_of_rows += 1 |
|
232 | @number_of_rows += 1 | |
233 | return if abort? |
|
233 | return if abort? | |
234 |
|
234 | |||
235 | # Remove the project requirement for Versions because it will |
|
235 | # Remove the project requirement for Versions because it will | |
236 | # restrict issues to only be on the current project. This |
|
236 | # restrict issues to only be on the current project. This | |
237 | # ends up missing issues which are assigned to shared versions. |
|
237 | # ends up missing issues which are assigned to shared versions. | |
238 | @query.project = nil if @query.project |
|
238 | @query.project = nil if @query.project | |
239 |
|
239 | |||
240 | issues = version.fixed_issues.for_gantt.with_query(@query).all(:limit => current_limit) |
|
240 | issues = version.fixed_issues.for_gantt.with_query(@query).all(:limit => current_limit) | |
241 | if issues |
|
241 | if issues | |
242 | sort_issues!(issues) |
|
242 | sort_issues!(issues) | |
243 | # Indent issues |
|
243 | # Indent issues | |
244 | options[:indent] += options[:indent_increment] |
|
244 | options[:indent] += options[:indent_increment] | |
245 | render_issues(issues, options) |
|
245 | render_issues(issues, options) | |
246 | options[:indent] -= options[:indent_increment] |
|
246 | options[:indent] -= options[:indent_increment] | |
247 | end |
|
247 | end | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | def render_end(options={}) |
|
250 | def render_end(options={}) | |
251 | case options[:format] |
|
251 | case options[:format] | |
252 | when :pdf |
|
252 | when :pdf | |
253 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
|
253 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) | |
254 | end |
|
254 | end | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | def subject_for_project(project, options) |
|
257 | def subject_for_project(project, options) | |
258 | case options[:format] |
|
258 | case options[:format] | |
259 | when :html |
|
259 | when :html | |
260 | output = '' |
|
260 | subject = "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>" | |
261 |
|
261 | subject << view.link_to_project(project) | ||
262 | output << "<div class='project-name' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> " |
|
262 | subject << '</span>' | |
263 | if project.is_a? Project |
|
263 | html_subject(options, subject, :css => "project-name") | |
264 | output << "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>" |
|
|||
265 | output << view.link_to_project(project) |
|
|||
266 | output << '</span>' |
|
|||
267 | else |
|
|||
268 | ActiveRecord::Base.logger.debug "Gantt#subject_for_project was not given a project" |
|
|||
269 | '' |
|
|||
270 | end |
|
|||
271 | output << "</small></div>" |
|
|||
272 | @subjects << output |
|
|||
273 | output |
|
|||
274 | when :image |
|
264 | when :image | |
275 |
|
265 | image_subject(options, project.name) | ||
276 | options[:image].fill('black') |
|
|||
277 | options[:image].stroke('transparent') |
|
|||
278 | options[:image].stroke_width(1) |
|
|||
279 | options[:image].text(options[:indent], options[:top] + 2, project.name) |
|
|||
280 | when :pdf |
|
266 | when :pdf | |
281 | pdf_new_page?(options) |
|
267 | pdf_new_page?(options) | |
282 | options[:pdf].SetY(options[:top]) |
|
268 | pdf_subject(options, project.name) | |
283 | options[:pdf].SetX(15) |
|
|||
284 |
|
||||
285 | char_limit = PDF::MaxCharactorsForSubject - options[:indent] |
|
|||
286 | options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{project.name}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") |
|
|||
287 |
|
||||
288 | options[:pdf].SetY(options[:top]) |
|
|||
289 | options[:pdf].SetX(options[:subject_width]) |
|
|||
290 | options[:pdf].Cell(options[:g_width], 5, "", "LR") |
|
|||
291 | end |
|
269 | end | |
292 | end |
|
270 | end | |
293 |
|
271 | |||
294 | def line_for_project(project, options) |
|
272 | def line_for_project(project, options) | |
295 | # Skip versions that don't have a start_date or due date |
|
273 | # Skip versions that don't have a start_date or due date | |
296 | if project.is_a?(Project) && project.start_date && project.due_date |
|
274 | if project.is_a?(Project) && project.start_date && project.due_date | |
297 | options[:zoom] ||= 1 |
|
275 | options[:zoom] ||= 1 | |
298 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
|
276 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] | |
299 |
|
277 | |||
300 | coords = coordinates(project.start_date, project.due_date, project.completed_percent(:include_subprojects => true), options[:zoom]) |
|
278 | coords = coordinates(project.start_date, project.due_date, project.completed_percent(:include_subprojects => true), options[:zoom]) | |
301 | label = "#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%" |
|
279 | label = "#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%" | |
302 |
|
280 | |||
303 | case options[:format] |
|
281 | case options[:format] | |
304 | when :html |
|
282 | when :html | |
305 | html_task(options, coords, :css => "project task", :label => label, :markers => true) |
|
283 | html_task(options, coords, :css => "project task", :label => label, :markers => true) | |
306 | when :image |
|
284 | when :image | |
307 | image_task(options, coords, :label => label, :markers => true, :height => 3) |
|
285 | image_task(options, coords, :label => label, :markers => true, :height => 3) | |
308 | when :pdf |
|
286 | when :pdf | |
309 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
|
287 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) | |
310 | end |
|
288 | end | |
311 | else |
|
289 | else | |
312 | ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date" |
|
290 | ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date" | |
313 | '' |
|
291 | '' | |
314 | end |
|
292 | end | |
315 | end |
|
293 | end | |
316 |
|
294 | |||
317 | def subject_for_version(version, options) |
|
295 | def subject_for_version(version, options) | |
318 | case options[:format] |
|
296 | case options[:format] | |
319 | when :html |
|
297 | when :html | |
320 | output = '' |
|
298 | subject = "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>" | |
321 | output << "<div class='version-name' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> " |
|
299 | subject << view.link_to_version(version) | |
322 | if version.is_a? Version |
|
300 | subject << '</span>' | |
323 | output << "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>" |
|
301 | html_subject(options, subject, :css => "version-name") | |
324 | output << view.link_to_version(version) |
|
|||
325 | output << '</span>' |
|
|||
326 | else |
|
|||
327 | ActiveRecord::Base.logger.debug "Gantt#subject_for_version was not given a version" |
|
|||
328 | '' |
|
|||
329 | end |
|
|||
330 | output << "</small></div>" |
|
|||
331 | @subjects << output |
|
|||
332 | output |
|
|||
333 | when :image |
|
302 | when :image | |
334 | options[:image].fill('black') |
|
303 | image_subject(options, version.to_s_with_project) | |
335 | options[:image].stroke('transparent') |
|
|||
336 | options[:image].stroke_width(1) |
|
|||
337 | options[:image].text(options[:indent], options[:top] + 2, version.to_s_with_project) |
|
|||
338 | when :pdf |
|
304 | when :pdf | |
339 | pdf_new_page?(options) |
|
305 | pdf_new_page?(options) | |
340 | options[:pdf].SetY(options[:top]) |
|
306 | pdf_subject(options, version.to_s_with_project) | |
341 | options[:pdf].SetX(15) |
|
|||
342 |
|
||||
343 | char_limit = PDF::MaxCharactorsForSubject - options[:indent] |
|
|||
344 | options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{version.to_s_with_project}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") |
|
|||
345 |
|
||||
346 | options[:pdf].SetY(options[:top]) |
|
|||
347 | options[:pdf].SetX(options[:subject_width]) |
|
|||
348 | options[:pdf].Cell(options[:g_width], 5, "", "LR") |
|
|||
349 | end |
|
307 | end | |
350 | end |
|
308 | end | |
351 |
|
309 | |||
352 | def line_for_version(version, options) |
|
310 | def line_for_version(version, options) | |
353 | # Skip versions that don't have a start_date |
|
311 | # Skip versions that don't have a start_date | |
354 | if version.is_a?(Version) && version.start_date && version.due_date |
|
312 | if version.is_a?(Version) && version.start_date && version.due_date | |
355 | options[:zoom] ||= 1 |
|
313 | options[:zoom] ||= 1 | |
356 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
|
314 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] | |
357 |
|
315 | |||
358 | coords = coordinates(version.fixed_issues.minimum('start_date'), version.due_date, version.completed_pourcent, options[:zoom]) |
|
316 | coords = coordinates(version.fixed_issues.minimum('start_date'), version.due_date, version.completed_pourcent, options[:zoom]) | |
359 | label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%" |
|
317 | label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%" | |
360 | label = h("#{version.project} -") + label unless @project && @project == version.project |
|
318 | label = h("#{version.project} -") + label unless @project && @project == version.project | |
361 |
|
319 | |||
362 | case options[:format] |
|
320 | case options[:format] | |
363 | when :html |
|
321 | when :html | |
364 | html_task(options, coords, :css => "version task", :label => label, :markers => true) |
|
322 | html_task(options, coords, :css => "version task", :label => label, :markers => true) | |
365 | when :image |
|
323 | when :image | |
366 | image_task(options, coords, :label => label, :markers => true, :height => 3) |
|
324 | image_task(options, coords, :label => label, :markers => true, :height => 3) | |
367 | when :pdf |
|
325 | when :pdf | |
368 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
|
326 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) | |
369 | end |
|
327 | end | |
370 | else |
|
328 | else | |
371 | ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date" |
|
329 | ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date" | |
372 | '' |
|
330 | '' | |
373 | end |
|
331 | end | |
374 | end |
|
332 | end | |
375 |
|
333 | |||
376 | def subject_for_issue(issue, options) |
|
334 | def subject_for_issue(issue, options) | |
377 | case options[:format] |
|
335 | case options[:format] | |
378 | when :html |
|
336 | when :html | |
379 |
|
|
337 | css_classes = '' | |
380 | output << "<div class='tooltip'>" |
|
338 | css_classes << ' issue-overdue' if issue.overdue? | |
381 | output << "<div class='issue-subject' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> " |
|
339 | css_classes << ' issue-behind-schedule' if issue.behind_schedule? | |
382 | if issue.is_a? Issue |
|
340 | css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to | |
383 | css_classes = [] |
|
341 | ||
384 | css_classes << 'issue-overdue' if issue.overdue? |
|
342 | subject = "<span class='#{css_classes}'>" | |
385 | css_classes << 'issue-behind-schedule' if issue.behind_schedule? |
|
343 | if issue.assigned_to.present? | |
386 | css_classes << 'icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to |
|
344 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name | |
387 |
|
345 | subject << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string) | ||
388 | if issue.assigned_to.present? |
|
|||
389 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name |
|
|||
390 | output << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string) |
|
|||
391 | end |
|
|||
392 | output << "<span class='#{css_classes.join(' ')}'>" |
|
|||
393 | output << view.link_to_issue(issue) |
|
|||
394 | output << '</span>' |
|
|||
395 | else |
|
|||
396 | ActiveRecord::Base.logger.debug "Gantt#subject_for_issue was not given an issue" |
|
|||
397 | '' |
|
|||
398 | end |
|
|||
399 | output << "</small></div>" |
|
|||
400 |
|
||||
401 | # Tooltip |
|
|||
402 | if issue.is_a? Issue |
|
|||
403 | output << "<span class='tip' style='position: absolute;top:#{ options[:top].to_i + 16 }px;left:#{ options[:indent].to_i + 20 }px;'>" |
|
|||
404 | output << view.render_issue_tooltip(issue) |
|
|||
405 | output << "</span>" |
|
|||
406 | end |
|
346 | end | |
407 |
|
347 | subject << view.link_to_issue(issue) | ||
408 |
|
|
348 | subject << '</span>' | |
409 | @subjects << output |
|
349 | html_subject(options, subject, :css => "issue-subject") | |
410 | output |
|
|||
411 | when :image |
|
350 | when :image | |
412 | options[:image].fill('black') |
|
351 | image_subject(options, issue.subject) | |
413 | options[:image].stroke('transparent') |
|
|||
414 | options[:image].stroke_width(1) |
|
|||
415 | options[:image].text(options[:indent], options[:top] + 2, issue.subject) |
|
|||
416 | when :pdf |
|
352 | when :pdf | |
417 | pdf_new_page?(options) |
|
353 | pdf_new_page?(options) | |
418 | options[:pdf].SetY(options[:top]) |
|
354 | pdf_subject(options, issue.subject) | |
419 | options[:pdf].SetX(15) |
|
|||
420 |
|
||||
421 | char_limit = PDF::MaxCharactorsForSubject - options[:indent] |
|
|||
422 | options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{issue.tracker} #{issue.id}: #{issue.subject}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") |
|
|||
423 |
|
||||
424 | options[:pdf].SetY(options[:top]) |
|
|||
425 | options[:pdf].SetX(options[:subject_width]) |
|
|||
426 | options[:pdf].Cell(options[:g_width], 5, "", "LR") |
|
|||
427 | end |
|
355 | end | |
428 | end |
|
356 | end | |
429 |
|
357 | |||
430 | def line_for_issue(issue, options) |
|
358 | def line_for_issue(issue, options) | |
431 | # Skip issues that don't have a due_before (due_date or version's due_date) |
|
359 | # Skip issues that don't have a due_before (due_date or version's due_date) | |
432 | if issue.is_a?(Issue) && issue.due_before |
|
360 | if issue.is_a?(Issue) && issue.due_before | |
433 | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) |
|
361 | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) | |
434 | label = "#{ issue.status.name } #{ issue.done_ratio }%" |
|
362 | label = "#{ issue.status.name } #{ issue.done_ratio }%" | |
435 |
|
363 | |||
436 | case options[:format] |
|
364 | case options[:format] | |
437 | when :html |
|
365 | when :html | |
438 | html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue) |
|
366 | html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue) | |
439 | when :image |
|
367 | when :image | |
440 | image_task(options, coords, :label => label) |
|
368 | image_task(options, coords, :label => label) | |
441 | when :pdf |
|
369 | when :pdf | |
442 | pdf_task(options, coords, :label => label) |
|
370 | pdf_task(options, coords, :label => label) | |
443 | end |
|
371 | end | |
444 | else |
|
372 | else | |
445 | ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" |
|
373 | ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" | |
446 | '' |
|
374 | '' | |
447 | end |
|
375 | end | |
448 | end |
|
376 | end | |
449 |
|
377 | |||
450 | # Generates a gantt image |
|
378 | # Generates a gantt image | |
451 | # Only defined if RMagick is avalaible |
|
379 | # Only defined if RMagick is avalaible | |
452 | def to_image(format='PNG') |
|
380 | def to_image(format='PNG') | |
453 | date_to = (@date_from >> @months)-1 |
|
381 | date_to = (@date_from >> @months)-1 | |
454 | show_weeks = @zoom > 1 |
|
382 | show_weeks = @zoom > 1 | |
455 | show_days = @zoom > 2 |
|
383 | show_days = @zoom > 2 | |
456 |
|
384 | |||
457 | subject_width = 400 |
|
385 | subject_width = 400 | |
458 | header_heigth = 18 |
|
386 | header_heigth = 18 | |
459 | # width of one day in pixels |
|
387 | # width of one day in pixels | |
460 | zoom = @zoom*2 |
|
388 | zoom = @zoom*2 | |
461 | g_width = (@date_to - @date_from + 1)*zoom |
|
389 | g_width = (@date_to - @date_from + 1)*zoom | |
462 | g_height = 20 * number_of_rows + 30 |
|
390 | g_height = 20 * number_of_rows + 30 | |
463 | headers_heigth = (show_weeks ? 2*header_heigth : header_heigth) |
|
391 | headers_heigth = (show_weeks ? 2*header_heigth : header_heigth) | |
464 | height = g_height + headers_heigth |
|
392 | height = g_height + headers_heigth | |
465 |
|
393 | |||
466 | imgl = Magick::ImageList.new |
|
394 | imgl = Magick::ImageList.new | |
467 | imgl.new_image(subject_width+g_width+1, height) |
|
395 | imgl.new_image(subject_width+g_width+1, height) | |
468 | gc = Magick::Draw.new |
|
396 | gc = Magick::Draw.new | |
469 |
|
397 | |||
470 | # Subjects |
|
398 | # Subjects | |
471 | gc.stroke('transparent') |
|
399 | gc.stroke('transparent') | |
472 | subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image) |
|
400 | subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image) | |
473 |
|
401 | |||
474 | # Months headers |
|
402 | # Months headers | |
475 | month_f = @date_from |
|
403 | month_f = @date_from | |
476 | left = subject_width |
|
404 | left = subject_width | |
477 | @months.times do |
|
405 | @months.times do | |
478 | width = ((month_f >> 1) - month_f) * zoom |
|
406 | width = ((month_f >> 1) - month_f) * zoom | |
479 | gc.fill('white') |
|
407 | gc.fill('white') | |
480 | gc.stroke('grey') |
|
408 | gc.stroke('grey') | |
481 | gc.stroke_width(1) |
|
409 | gc.stroke_width(1) | |
482 | gc.rectangle(left, 0, left + width, height) |
|
410 | gc.rectangle(left, 0, left + width, height) | |
483 | gc.fill('black') |
|
411 | gc.fill('black') | |
484 | gc.stroke('transparent') |
|
412 | gc.stroke('transparent') | |
485 | gc.stroke_width(1) |
|
413 | gc.stroke_width(1) | |
486 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") |
|
414 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") | |
487 | left = left + width |
|
415 | left = left + width | |
488 | month_f = month_f >> 1 |
|
416 | month_f = month_f >> 1 | |
489 | end |
|
417 | end | |
490 |
|
418 | |||
491 | # Weeks headers |
|
419 | # Weeks headers | |
492 | if show_weeks |
|
420 | if show_weeks | |
493 | left = subject_width |
|
421 | left = subject_width | |
494 | height = header_heigth |
|
422 | height = header_heigth | |
495 | if @date_from.cwday == 1 |
|
423 | if @date_from.cwday == 1 | |
496 | # date_from is monday |
|
424 | # date_from is monday | |
497 | week_f = date_from |
|
425 | week_f = date_from | |
498 | else |
|
426 | else | |
499 | # find next monday after date_from |
|
427 | # find next monday after date_from | |
500 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
428 | week_f = @date_from + (7 - @date_from.cwday + 1) | |
501 | width = (7 - @date_from.cwday + 1) * zoom |
|
429 | width = (7 - @date_from.cwday + 1) * zoom | |
502 | gc.fill('white') |
|
430 | gc.fill('white') | |
503 | gc.stroke('grey') |
|
431 | gc.stroke('grey') | |
504 | gc.stroke_width(1) |
|
432 | gc.stroke_width(1) | |
505 | gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1) |
|
433 | gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1) | |
506 | left = left + width |
|
434 | left = left + width | |
507 | end |
|
435 | end | |
508 | while week_f <= date_to |
|
436 | while week_f <= date_to | |
509 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom |
|
437 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom | |
510 | gc.fill('white') |
|
438 | gc.fill('white') | |
511 | gc.stroke('grey') |
|
439 | gc.stroke('grey') | |
512 | gc.stroke_width(1) |
|
440 | gc.stroke_width(1) | |
513 | gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1) |
|
441 | gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1) | |
514 | gc.fill('black') |
|
442 | gc.fill('black') | |
515 | gc.stroke('transparent') |
|
443 | gc.stroke('transparent') | |
516 | gc.stroke_width(1) |
|
444 | gc.stroke_width(1) | |
517 | gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s) |
|
445 | gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s) | |
518 | left = left + width |
|
446 | left = left + width | |
519 | week_f = week_f+7 |
|
447 | week_f = week_f+7 | |
520 | end |
|
448 | end | |
521 | end |
|
449 | end | |
522 |
|
450 | |||
523 | # Days details (week-end in grey) |
|
451 | # Days details (week-end in grey) | |
524 | if show_days |
|
452 | if show_days | |
525 | left = subject_width |
|
453 | left = subject_width | |
526 | height = g_height + header_heigth - 1 |
|
454 | height = g_height + header_heigth - 1 | |
527 | wday = @date_from.cwday |
|
455 | wday = @date_from.cwday | |
528 | (date_to - @date_from + 1).to_i.times do |
|
456 | (date_to - @date_from + 1).to_i.times do | |
529 | width = zoom |
|
457 | width = zoom | |
530 | gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white') |
|
458 | gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white') | |
531 | gc.stroke('grey') |
|
459 | gc.stroke('grey') | |
532 | gc.stroke_width(1) |
|
460 | gc.stroke_width(1) | |
533 | gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1) |
|
461 | gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1) | |
534 | left = left + width |
|
462 | left = left + width | |
535 | wday = wday + 1 |
|
463 | wday = wday + 1 | |
536 | wday = 1 if wday > 7 |
|
464 | wday = 1 if wday > 7 | |
537 | end |
|
465 | end | |
538 | end |
|
466 | end | |
539 |
|
467 | |||
540 | # border |
|
468 | # border | |
541 | gc.fill('transparent') |
|
469 | gc.fill('transparent') | |
542 | gc.stroke('grey') |
|
470 | gc.stroke('grey') | |
543 | gc.stroke_width(1) |
|
471 | gc.stroke_width(1) | |
544 | gc.rectangle(0, 0, subject_width+g_width, headers_heigth) |
|
472 | gc.rectangle(0, 0, subject_width+g_width, headers_heigth) | |
545 | gc.stroke('black') |
|
473 | gc.stroke('black') | |
546 | gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1) |
|
474 | gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1) | |
547 |
|
475 | |||
548 | # content |
|
476 | # content | |
549 | top = headers_heigth + 20 |
|
477 | top = headers_heigth + 20 | |
550 |
|
478 | |||
551 | gc.stroke('transparent') |
|
479 | gc.stroke('transparent') | |
552 | lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image) |
|
480 | lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image) | |
553 |
|
481 | |||
554 | # today red line |
|
482 | # today red line | |
555 | if Date.today >= @date_from and Date.today <= date_to |
|
483 | if Date.today >= @date_from and Date.today <= date_to | |
556 | gc.stroke('red') |
|
484 | gc.stroke('red') | |
557 | x = (Date.today-@date_from+1)*zoom + subject_width |
|
485 | x = (Date.today-@date_from+1)*zoom + subject_width | |
558 | gc.line(x, headers_heigth, x, headers_heigth + g_height-1) |
|
486 | gc.line(x, headers_heigth, x, headers_heigth + g_height-1) | |
559 | end |
|
487 | end | |
560 |
|
488 | |||
561 | gc.draw(imgl) |
|
489 | gc.draw(imgl) | |
562 | imgl.format = format |
|
490 | imgl.format = format | |
563 | imgl.to_blob |
|
491 | imgl.to_blob | |
564 | end if Object.const_defined?(:Magick) |
|
492 | end if Object.const_defined?(:Magick) | |
565 |
|
493 | |||
566 | def to_pdf |
|
494 | def to_pdf | |
567 | pdf = ::Redmine::Export::PDF::IFPDF.new(current_language) |
|
495 | pdf = ::Redmine::Export::PDF::IFPDF.new(current_language) | |
568 | pdf.SetTitle("#{l(:label_gantt)} #{project}") |
|
496 | pdf.SetTitle("#{l(:label_gantt)} #{project}") | |
569 | pdf.AliasNbPages |
|
497 | pdf.AliasNbPages | |
570 | pdf.footer_date = format_date(Date.today) |
|
498 | pdf.footer_date = format_date(Date.today) | |
571 | pdf.AddPage("L") |
|
499 | pdf.AddPage("L") | |
572 | pdf.SetFontStyle('B',12) |
|
500 | pdf.SetFontStyle('B',12) | |
573 | pdf.SetX(15) |
|
501 | pdf.SetX(15) | |
574 | pdf.Cell(PDF::LeftPaneWidth, 20, project.to_s) |
|
502 | pdf.Cell(PDF::LeftPaneWidth, 20, project.to_s) | |
575 | pdf.Ln |
|
503 | pdf.Ln | |
576 | pdf.SetFontStyle('B',9) |
|
504 | pdf.SetFontStyle('B',9) | |
577 |
|
505 | |||
578 | subject_width = PDF::LeftPaneWidth |
|
506 | subject_width = PDF::LeftPaneWidth | |
579 | header_heigth = 5 |
|
507 | header_heigth = 5 | |
580 |
|
508 | |||
581 | headers_heigth = header_heigth |
|
509 | headers_heigth = header_heigth | |
582 | show_weeks = false |
|
510 | show_weeks = false | |
583 | show_days = false |
|
511 | show_days = false | |
584 |
|
512 | |||
585 | if self.months < 7 |
|
513 | if self.months < 7 | |
586 | show_weeks = true |
|
514 | show_weeks = true | |
587 | headers_heigth = 2*header_heigth |
|
515 | headers_heigth = 2*header_heigth | |
588 | if self.months < 3 |
|
516 | if self.months < 3 | |
589 | show_days = true |
|
517 | show_days = true | |
590 | headers_heigth = 3*header_heigth |
|
518 | headers_heigth = 3*header_heigth | |
591 | end |
|
519 | end | |
592 | end |
|
520 | end | |
593 |
|
521 | |||
594 | g_width = PDF.right_pane_width |
|
522 | g_width = PDF.right_pane_width | |
595 | zoom = (g_width) / (self.date_to - self.date_from + 1) |
|
523 | zoom = (g_width) / (self.date_to - self.date_from + 1) | |
596 | g_height = 120 |
|
524 | g_height = 120 | |
597 | t_height = g_height + headers_heigth |
|
525 | t_height = g_height + headers_heigth | |
598 |
|
526 | |||
599 | y_start = pdf.GetY |
|
527 | y_start = pdf.GetY | |
600 |
|
528 | |||
601 | # Months headers |
|
529 | # Months headers | |
602 | month_f = self.date_from |
|
530 | month_f = self.date_from | |
603 | left = subject_width |
|
531 | left = subject_width | |
604 | height = header_heigth |
|
532 | height = header_heigth | |
605 | self.months.times do |
|
533 | self.months.times do | |
606 | width = ((month_f >> 1) - month_f) * zoom |
|
534 | width = ((month_f >> 1) - month_f) * zoom | |
607 | pdf.SetY(y_start) |
|
535 | pdf.SetY(y_start) | |
608 | pdf.SetX(left) |
|
536 | pdf.SetX(left) | |
609 | pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") |
|
537 | pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") | |
610 | left = left + width |
|
538 | left = left + width | |
611 | month_f = month_f >> 1 |
|
539 | month_f = month_f >> 1 | |
612 | end |
|
540 | end | |
613 |
|
541 | |||
614 | # Weeks headers |
|
542 | # Weeks headers | |
615 | if show_weeks |
|
543 | if show_weeks | |
616 | left = subject_width |
|
544 | left = subject_width | |
617 | height = header_heigth |
|
545 | height = header_heigth | |
618 | if self.date_from.cwday == 1 |
|
546 | if self.date_from.cwday == 1 | |
619 | # self.date_from is monday |
|
547 | # self.date_from is monday | |
620 | week_f = self.date_from |
|
548 | week_f = self.date_from | |
621 | else |
|
549 | else | |
622 | # find next monday after self.date_from |
|
550 | # find next monday after self.date_from | |
623 | week_f = self.date_from + (7 - self.date_from.cwday + 1) |
|
551 | week_f = self.date_from + (7 - self.date_from.cwday + 1) | |
624 | width = (7 - self.date_from.cwday + 1) * zoom-1 |
|
552 | width = (7 - self.date_from.cwday + 1) * zoom-1 | |
625 | pdf.SetY(y_start + header_heigth) |
|
553 | pdf.SetY(y_start + header_heigth) | |
626 | pdf.SetX(left) |
|
554 | pdf.SetX(left) | |
627 | pdf.Cell(width + 1, height, "", "LTR") |
|
555 | pdf.Cell(width + 1, height, "", "LTR") | |
628 | left = left + width+1 |
|
556 | left = left + width+1 | |
629 | end |
|
557 | end | |
630 | while week_f <= self.date_to |
|
558 | while week_f <= self.date_to | |
631 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom |
|
559 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom | |
632 | pdf.SetY(y_start + header_heigth) |
|
560 | pdf.SetY(y_start + header_heigth) | |
633 | pdf.SetX(left) |
|
561 | pdf.SetX(left) | |
634 | pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") |
|
562 | pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") | |
635 | left = left + width |
|
563 | left = left + width | |
636 | week_f = week_f+7 |
|
564 | week_f = week_f+7 | |
637 | end |
|
565 | end | |
638 | end |
|
566 | end | |
639 |
|
567 | |||
640 | # Days headers |
|
568 | # Days headers | |
641 | if show_days |
|
569 | if show_days | |
642 | left = subject_width |
|
570 | left = subject_width | |
643 | height = header_heigth |
|
571 | height = header_heigth | |
644 | wday = self.date_from.cwday |
|
572 | wday = self.date_from.cwday | |
645 | pdf.SetFontStyle('B',7) |
|
573 | pdf.SetFontStyle('B',7) | |
646 | (self.date_to - self.date_from + 1).to_i.times do |
|
574 | (self.date_to - self.date_from + 1).to_i.times do | |
647 | width = zoom |
|
575 | width = zoom | |
648 | pdf.SetY(y_start + 2 * header_heigth) |
|
576 | pdf.SetY(y_start + 2 * header_heigth) | |
649 | pdf.SetX(left) |
|
577 | pdf.SetX(left) | |
650 | pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C") |
|
578 | pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C") | |
651 | left = left + width |
|
579 | left = left + width | |
652 | wday = wday + 1 |
|
580 | wday = wday + 1 | |
653 | wday = 1 if wday > 7 |
|
581 | wday = 1 if wday > 7 | |
654 | end |
|
582 | end | |
655 | end |
|
583 | end | |
656 |
|
584 | |||
657 | pdf.SetY(y_start) |
|
585 | pdf.SetY(y_start) | |
658 | pdf.SetX(15) |
|
586 | pdf.SetX(15) | |
659 | pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) |
|
587 | pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) | |
660 |
|
588 | |||
661 | # Tasks |
|
589 | # Tasks | |
662 | top = headers_heigth + y_start |
|
590 | top = headers_heigth + y_start | |
663 | options = { |
|
591 | options = { | |
664 | :top => top, |
|
592 | :top => top, | |
665 | :zoom => zoom, |
|
593 | :zoom => zoom, | |
666 | :subject_width => subject_width, |
|
594 | :subject_width => subject_width, | |
667 | :g_width => g_width, |
|
595 | :g_width => g_width, | |
668 | :indent => 0, |
|
596 | :indent => 0, | |
669 | :indent_increment => 5, |
|
597 | :indent_increment => 5, | |
670 | :top_increment => 5, |
|
598 | :top_increment => 5, | |
671 | :format => :pdf, |
|
599 | :format => :pdf, | |
672 | :pdf => pdf |
|
600 | :pdf => pdf | |
673 | } |
|
601 | } | |
674 | render(options) |
|
602 | render(options) | |
675 | pdf.Output |
|
603 | pdf.Output | |
676 | end |
|
604 | end | |
677 |
|
605 | |||
678 | private |
|
606 | private | |
679 |
|
607 | |||
680 | def coordinates(start_date, end_date, progress, zoom=nil) |
|
608 | def coordinates(start_date, end_date, progress, zoom=nil) | |
681 | zoom ||= @zoom |
|
609 | zoom ||= @zoom | |
682 |
|
610 | |||
683 | coords = {} |
|
611 | coords = {} | |
684 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from |
|
612 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from | |
685 | if start_date > self.date_from |
|
613 | if start_date > self.date_from | |
686 | coords[:start] = start_date - self.date_from |
|
614 | coords[:start] = start_date - self.date_from | |
687 | coords[:bar_start] = start_date - self.date_from |
|
615 | coords[:bar_start] = start_date - self.date_from | |
688 | else |
|
616 | else | |
689 | coords[:bar_start] = 0 |
|
617 | coords[:bar_start] = 0 | |
690 | end |
|
618 | end | |
691 | if end_date < self.date_to |
|
619 | if end_date < self.date_to | |
692 | coords[:end] = end_date - self.date_from |
|
620 | coords[:end] = end_date - self.date_from | |
693 | coords[:bar_end] = end_date - self.date_from + 1 |
|
621 | coords[:bar_end] = end_date - self.date_from + 1 | |
694 | else |
|
622 | else | |
695 | coords[:bar_end] = self.date_to - self.date_from + 1 |
|
623 | coords[:bar_end] = self.date_to - self.date_from + 1 | |
696 | end |
|
624 | end | |
697 |
|
625 | |||
698 | if progress |
|
626 | if progress | |
699 | progress_date = start_date + (end_date - start_date) * (progress / 100.0) |
|
627 | progress_date = start_date + (end_date - start_date) * (progress / 100.0) | |
700 | if progress_date > self.date_from && progress_date > start_date |
|
628 | if progress_date > self.date_from && progress_date > start_date | |
701 | if progress_date < self.date_to |
|
629 | if progress_date < self.date_to | |
702 | coords[:bar_progress_end] = progress_date - self.date_from + 1 |
|
630 | coords[:bar_progress_end] = progress_date - self.date_from + 1 | |
703 | else |
|
631 | else | |
704 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 |
|
632 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 | |
705 | end |
|
633 | end | |
706 | end |
|
634 | end | |
707 |
|
635 | |||
708 | if progress_date < Date.today |
|
636 | if progress_date < Date.today | |
709 | late_date = [Date.today, end_date].min |
|
637 | late_date = [Date.today, end_date].min | |
710 | if late_date > self.date_from && late_date > start_date |
|
638 | if late_date > self.date_from && late_date > start_date | |
711 | if late_date < self.date_to |
|
639 | if late_date < self.date_to | |
712 | coords[:bar_late_end] = late_date - self.date_from + 1 |
|
640 | coords[:bar_late_end] = late_date - self.date_from + 1 | |
713 | else |
|
641 | else | |
714 | coords[:bar_late_end] = self.date_to - self.date_from + 1 |
|
642 | coords[:bar_late_end] = self.date_to - self.date_from + 1 | |
715 | end |
|
643 | end | |
716 | end |
|
644 | end | |
717 | end |
|
645 | end | |
718 | end |
|
646 | end | |
719 | end |
|
647 | end | |
720 |
|
648 | |||
721 | # Transforms dates into pixels witdh |
|
649 | # Transforms dates into pixels witdh | |
722 | coords.keys.each do |key| |
|
650 | coords.keys.each do |key| | |
723 | coords[key] = (coords[key] * zoom).floor |
|
651 | coords[key] = (coords[key] * zoom).floor | |
724 | end |
|
652 | end | |
725 | coords |
|
653 | coords | |
726 | end |
|
654 | end | |
727 |
|
655 | |||
728 | # Sorts a collection of issues by start_date, due_date, id for gantt rendering |
|
656 | # Sorts a collection of issues by start_date, due_date, id for gantt rendering | |
729 | def sort_issues!(issues) |
|
657 | def sort_issues!(issues) | |
730 | issues.sort! do |a, b| |
|
658 | issues.sort! do |a, b| | |
731 | cmp = 0 |
|
659 | cmp = 0 | |
732 | cmp = (a.start_date <=> b.start_date) if a.start_date? && b.start_date? |
|
660 | cmp = (a.start_date <=> b.start_date) if a.start_date? && b.start_date? | |
733 | cmp = (a.due_date <=> b.due_date) if cmp == 0 && a.due_date? && b.due_date? |
|
661 | cmp = (a.due_date <=> b.due_date) if cmp == 0 && a.due_date? && b.due_date? | |
734 | cmp = (a.id <=> b.id) if cmp == 0 |
|
662 | cmp = (a.id <=> b.id) if cmp == 0 | |
735 | cmp |
|
663 | cmp | |
736 | end |
|
664 | end | |
737 | end |
|
665 | end | |
738 |
|
666 | |||
739 | def current_limit |
|
667 | def current_limit | |
740 | if @max_rows |
|
668 | if @max_rows | |
741 | @max_rows - @number_of_rows |
|
669 | @max_rows - @number_of_rows | |
742 | else |
|
670 | else | |
743 | nil |
|
671 | nil | |
744 | end |
|
672 | end | |
745 | end |
|
673 | end | |
746 |
|
674 | |||
747 | def abort? |
|
675 | def abort? | |
748 | if @max_rows && @number_of_rows >= @max_rows |
|
676 | if @max_rows && @number_of_rows >= @max_rows | |
749 | @truncated = true |
|
677 | @truncated = true | |
750 | end |
|
678 | end | |
751 | end |
|
679 | end | |
752 |
|
680 | |||
753 | def pdf_new_page?(options) |
|
681 | def pdf_new_page?(options) | |
754 | if options[:top] > 180 |
|
682 | if options[:top] > 180 | |
755 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
|
683 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) | |
756 | options[:pdf].AddPage("L") |
|
684 | options[:pdf].AddPage("L") | |
757 | options[:top] = 15 |
|
685 | options[:top] = 15 | |
758 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) |
|
686 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) | |
759 | end |
|
687 | end | |
760 | end |
|
688 | end | |
761 |
|
689 | |||
|
690 | def html_subject(params, subject, options={}) | |||
|
691 | output = "<div class=' #{options[:css] }' style='position: absolute;line-height:1.2em;height:16px;top:#{params[:top]}px;left:#{params[:indent]}px;overflow:hidden;'>" | |||
|
692 | output << subject | |||
|
693 | output << "</div>" | |||
|
694 | @subjects << output | |||
|
695 | output | |||
|
696 | end | |||
|
697 | ||||
|
698 | def pdf_subject(params, subject, options={}) | |||
|
699 | params[:pdf].SetY(params[:top]) | |||
|
700 | params[:pdf].SetX(15) | |||
|
701 | ||||
|
702 | char_limit = PDF::MaxCharactorsForSubject - params[:indent] | |||
|
703 | params[:pdf].Cell(params[:subject_width]-15, 5, (" " * params[:indent]) + subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") | |||
|
704 | ||||
|
705 | params[:pdf].SetY(params[:top]) | |||
|
706 | params[:pdf].SetX(params[:subject_width]) | |||
|
707 | params[:pdf].Cell(params[:g_width], 5, "", "LR") | |||
|
708 | end | |||
|
709 | ||||
|
710 | def image_subject(params, subject, options={}) | |||
|
711 | params[:image].fill('black') | |||
|
712 | params[:image].stroke('transparent') | |||
|
713 | params[:image].stroke_width(1) | |||
|
714 | params[:image].text(params[:indent], params[:top] + 2, subject) | |||
|
715 | end | |||
|
716 | ||||
762 | def html_task(params, coords, options={}) |
|
717 | def html_task(params, coords, options={}) | |
763 | output = '' |
|
718 | output = '' | |
764 | # Renders the task bar, with progress and late |
|
719 | # Renders the task bar, with progress and late | |
765 | if coords[:bar_start] && coords[:bar_end] |
|
720 | if coords[:bar_start] && coords[:bar_end] | |
766 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'> </div>" |
|
721 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'> </div>" | |
767 |
|
722 | |||
768 | if coords[:bar_late_end] |
|
723 | if coords[:bar_late_end] | |
769 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'> </div>" |
|
724 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'> </div>" | |
770 | end |
|
725 | end | |
771 | if coords[:bar_progress_end] |
|
726 | if coords[:bar_progress_end] | |
772 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'> </div>" |
|
727 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'> </div>" | |
773 | end |
|
728 | end | |
774 | end |
|
729 | end | |
775 | # Renders the markers |
|
730 | # Renders the markers | |
776 | if options[:markers] |
|
731 | if options[:markers] | |
777 | if coords[:start] |
|
732 | if coords[:start] | |
778 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>" |
|
733 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>" | |
779 | end |
|
734 | end | |
780 | if coords[:end] |
|
735 | if coords[:end] | |
781 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] }px;width:15px;' class='#{options[:css]} marker ending'> </div>" |
|
736 | output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] }px;width:15px;' class='#{options[:css]} marker ending'> </div>" | |
782 | end |
|
737 | end | |
783 | end |
|
738 | end | |
784 | # Renders the label on the right |
|
739 | # Renders the label on the right | |
785 | if options[:label] |
|
740 | if options[:label] | |
786 | output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 5 }px;' class='#{options[:css]} label'>" |
|
741 | output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 5 }px;' class='#{options[:css]} label'>" | |
787 | output << options[:label] |
|
742 | output << options[:label] | |
788 | output << "</div>" |
|
743 | output << "</div>" | |
789 | end |
|
744 | end | |
790 | # Renders the tooltip |
|
745 | # Renders the tooltip | |
791 | if options[:issue] && coords[:bar_start] && coords[:bar_end] |
|
746 | if options[:issue] && coords[:bar_start] && coords[:bar_end] | |
792 | output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>" |
|
747 | output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>" | |
793 | output << '<span class="tip">' |
|
748 | output << '<span class="tip">' | |
794 | output << view.render_issue_tooltip(options[:issue]) |
|
749 | output << view.render_issue_tooltip(options[:issue]) | |
795 | output << "</span></div>" |
|
750 | output << "</span></div>" | |
796 | end |
|
751 | end | |
797 | @lines << output |
|
752 | @lines << output | |
798 | output |
|
753 | output | |
799 | end |
|
754 | end | |
800 |
|
755 | |||
801 | def pdf_task(params, coords, options={}) |
|
756 | def pdf_task(params, coords, options={}) | |
802 | height = options[:height] || 2 |
|
757 | height = options[:height] || 2 | |
803 |
|
758 | |||
804 | # Renders the task bar, with progress and late |
|
759 | # Renders the task bar, with progress and late | |
805 | if coords[:bar_start] && coords[:bar_end] |
|
760 | if coords[:bar_start] && coords[:bar_end] | |
806 | params[:pdf].SetY(params[:top]+1.5) |
|
761 | params[:pdf].SetY(params[:top]+1.5) | |
807 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
762 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
808 | params[:pdf].SetFillColor(200,200,200) |
|
763 | params[:pdf].SetFillColor(200,200,200) | |
809 | params[:pdf].Cell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
764 | params[:pdf].Cell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
810 |
|
765 | |||
811 | if coords[:bar_late_end] |
|
766 | if coords[:bar_late_end] | |
812 | params[:pdf].SetY(params[:top]+1.5) |
|
767 | params[:pdf].SetY(params[:top]+1.5) | |
813 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
768 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
814 | params[:pdf].SetFillColor(255,100,100) |
|
769 | params[:pdf].SetFillColor(255,100,100) | |
815 | params[:pdf].Cell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
770 | params[:pdf].Cell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
816 | end |
|
771 | end | |
817 | if coords[:bar_progress_end] |
|
772 | if coords[:bar_progress_end] | |
818 | params[:pdf].SetY(params[:top]+1.5) |
|
773 | params[:pdf].SetY(params[:top]+1.5) | |
819 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
774 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
820 | params[:pdf].SetFillColor(90,200,90) |
|
775 | params[:pdf].SetFillColor(90,200,90) | |
821 | params[:pdf].Cell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
776 | params[:pdf].Cell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
822 | end |
|
777 | end | |
823 | end |
|
778 | end | |
824 | # Renders the markers |
|
779 | # Renders the markers | |
825 | if options[:markers] |
|
780 | if options[:markers] | |
826 | if coords[:start] |
|
781 | if coords[:start] | |
827 | params[:pdf].SetY(params[:top] + 1) |
|
782 | params[:pdf].SetY(params[:top] + 1) | |
828 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) |
|
783 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) | |
829 | params[:pdf].SetFillColor(50,50,200) |
|
784 | params[:pdf].SetFillColor(50,50,200) | |
830 | params[:pdf].Cell(2, 2, "", 0, 0, "", 1) |
|
785 | params[:pdf].Cell(2, 2, "", 0, 0, "", 1) | |
831 | end |
|
786 | end | |
832 | if coords[:end] |
|
787 | if coords[:end] | |
833 | params[:pdf].SetY(params[:top] + 1) |
|
788 | params[:pdf].SetY(params[:top] + 1) | |
834 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) |
|
789 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) | |
835 | params[:pdf].SetFillColor(50,50,200) |
|
790 | params[:pdf].SetFillColor(50,50,200) | |
836 | params[:pdf].Cell(2, 2, "", 0, 0, "", 1) |
|
791 | params[:pdf].Cell(2, 2, "", 0, 0, "", 1) | |
837 | end |
|
792 | end | |
838 | end |
|
793 | end | |
839 | # Renders the label on the right |
|
794 | # Renders the label on the right | |
840 | if options[:label] |
|
795 | if options[:label] | |
841 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) |
|
796 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) | |
842 | params[:pdf].Cell(30, 2, options[:label]) |
|
797 | params[:pdf].Cell(30, 2, options[:label]) | |
843 | end |
|
798 | end | |
844 | end |
|
799 | end | |
845 |
|
800 | |||
846 | def image_task(params, coords, options={}) |
|
801 | def image_task(params, coords, options={}) | |
847 | height = options[:height] || 6 |
|
802 | height = options[:height] || 6 | |
848 |
|
803 | |||
849 | # Renders the task bar, with progress and late |
|
804 | # Renders the task bar, with progress and late | |
850 | if coords[:bar_start] && coords[:bar_end] |
|
805 | if coords[:bar_start] && coords[:bar_end] | |
851 | params[:image].fill('grey') |
|
806 | params[:image].fill('grey') | |
852 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height) |
|
807 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height) | |
853 |
|
808 | |||
854 | if coords[:bar_late_end] |
|
809 | if coords[:bar_late_end] | |
855 | params[:image].fill('red') |
|
810 | params[:image].fill('red') | |
856 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height) |
|
811 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height) | |
857 | end |
|
812 | end | |
858 | if coords[:bar_progress_end] |
|
813 | if coords[:bar_progress_end] | |
859 | params[:image].fill('green') |
|
814 | params[:image].fill('green') | |
860 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_progress_end], params[:top] - height) |
|
815 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_progress_end], params[:top] - height) | |
861 | end |
|
816 | end | |
862 | end |
|
817 | end | |
863 | # Renders the markers |
|
818 | # Renders the markers | |
864 | if options[:markers] |
|
819 | if options[:markers] | |
865 | if coords[:start] |
|
820 | if coords[:start] | |
866 | params[:image].fill('blue') |
|
821 | params[:image].fill('blue') | |
867 | params[:image].rectangle(params[:subject_width] + coords[:start], params[:top] + 1, params[:subject_width] + coords[:start] + 4, params[:top] - 4) |
|
822 | params[:image].rectangle(params[:subject_width] + coords[:start], params[:top] + 1, params[:subject_width] + coords[:start] + 4, params[:top] - 4) | |
868 | end |
|
823 | end | |
869 | if coords[:end] |
|
824 | if coords[:end] | |
870 | params[:image].fill('blue') |
|
825 | params[:image].fill('blue') | |
871 | params[:image].rectangle(params[:subject_width] + coords[:end], params[:top] + 1, params[:subject_width] + coords[:end] + 4, params[:top] - 4) |
|
826 | params[:image].rectangle(params[:subject_width] + coords[:end], params[:top] + 1, params[:subject_width] + coords[:end] + 4, params[:top] - 4) | |
872 | end |
|
827 | end | |
873 | end |
|
828 | end | |
874 | # Renders the label on the right |
|
829 | # Renders the label on the right | |
875 | if options[:label] |
|
830 | if options[:label] | |
876 | params[:image].fill('black') |
|
831 | params[:image].fill('black') | |
877 | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label]) |
|
832 | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label]) | |
878 | end |
|
833 | end | |
879 | end |
|
834 | end | |
880 | end |
|
835 | end | |
881 | end |
|
836 | end | |
882 | end |
|
837 | end |
General Comments 0
You need to be logged in to leave comments.
Login now