Skip to content

Commit

Permalink
Adding a graph to show total issues over time
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbeattie committed Mar 10, 2009
1 parent 8c66891 commit 2220eb2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 13 deletions.
59 changes: 57 additions & 2 deletions app/controllers/graphs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,56 @@
class GraphsController < ApplicationController

before_filter :find_version, :only => [:target_version_graph]
before_filter :find_issues, :only => [:old_issues, :issue_age_graph]
before_filter :find_open_issues, :only => [:old_issues, :issue_age_graph]
before_filter :find_all_issues, :only => [:issue_growth_graph, :issue_growth]

helper IssuesHelper

def issue_growth
end

# Displays projects by total issues over time
def issue_growth_graph

# Initialize the graph
graph = SVG::Graph::TimeSeries.new({
:height => 300,
:min_y_value => 0,
:no_css => true,
:show_x_guidelines => true,
:scale_x_integers => true,
:scale_y_integers => true,
:show_data_points => false,
:show_data_values => false,
:stagger_x_labels => true,
:style_sheet => "/plugin_assets/redmine_graphs/stylesheets/issue_growth.css",
:timescale_divisions => "1 weeks",
:width => 800,
:x_label_format => "%b %d"
})

# Group issues
issues_by_project = @issues.group_by {|issue| issue.project }
projects_by_size = issues_by_project.collect { |project, issues| [project, issues.size] }.sort { |a,b| b[1]<=>a[1] }[0..5]

# Generate the created_on line
projects_by_size.each do |project, size|
issues_by_created_on = issues_by_project[project].group_by {|issue| issue.created_on.to_date }.sort
created_count = 0
created_on_line = Hash.new
issues_by_created_on.each { |created_on, issues| created_on_line[(created_on-1).to_s] = created_count; created_count += issues.size; created_on_line[created_on.to_s] = created_count }
created_on_line[Date.today.to_s] = created_count
graph.add_data({
:data => created_on_line.sort.flatten,
:title => project.name
})
end

# Compile the graph
headers["Content-Type"] = "image/svg+xml"
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
end

def old_issues
@issues_by_created_on = @issues.sort {|a,b| a.created_on<=>b.created_on}
@issues_by_updated_on = @issues.sort {|a,b| a.updated_on<=>b.updated_on}
Expand Down Expand Up @@ -128,14 +174,23 @@ def target_version_graph

private

def find_issues
def find_open_issues
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
deny_access unless User.current.allowed_to?(:view_issues, @project, :global => true)
@issues = Issue.visible.find(:all, :include => [:status], :conditions => ["#{IssueStatus.table_name}.is_closed=?", false]) if @project.nil?
@issues = @project.issues.collect { |issue| issue unless issue.closed? }.compact unless @project.nil?
rescue ActiveRecord::RecordNotFound
render_404
end

def find_all_issues
@project = Project.find(params[:project_id]) unless params[:project_id].blank?
deny_access unless User.current.allowed_to?(:view_issues, @project, :global => true) if @project.nil?
@issues = Issue.visible.find(:all, :include => [:project])
@issues = @project.issues unless @project.nil?
rescue ActiveRecord::RecordNotFound
render_404
end

def find_version
@version = Version.find(params[:id])
Expand Down
3 changes: 3 additions & 0 deletions app/views/graphs/issue_growth.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2><%= l(:label_graphs_issue_growth) %></h2>
<%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_growth_graph')) if @project.nil? %>
<%= tag("embed", :width => "100%", :height => 300, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'issue_growth_graph', :project_id => @project.id)) unless @project.nil? %>
6 changes: 6 additions & 0 deletions assets/stylesheets/issue_growth.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
en:
label_graphs_total_vs_closed_issues: Total issues vs. Closed issues
label_graphs_old_issues: Old issues
label_graphs_old_issues: Open aging issues
label_graphs_issue_growth: Total issues over time

2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'redmine'

require_dependency 'target_version_graph_hook'
require_dependency 'old_issues_graph_hook'
require_dependency 'issues_sidebar_graph_hook'

Redmine::Plugin.register :redmine_graphs do
name 'Redmine Graphs plugin'
Expand Down
13 changes: 13 additions & 0 deletions lib/issues_sidebar_graph_hook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Provides a link to the issue age graph on the issue index page
class IssuesSidebarGraphHook < Redmine::Hook::ViewListener
def view_issues_sidebar_issues_bottom(context = { })
output = "<h3>Graphs</h3>"
output << link_to(l(:label_graphs_old_issues), {:controller => 'graphs', :action => 'old_issues'}) if context[:project].nil?
output << link_to(l(:label_graphs_old_issues), {:controller => 'graphs', :action => 'old_issues', :project_id => context[:project]}) unless context[:project].nil?
output << "<br/>"
output << link_to(l(:label_graphs_issue_growth), {:controller => 'graphs', :action => 'issue_growth'}) if context[:project].nil?
output << link_to(l(:label_graphs_issue_growth), {:controller => 'graphs', :action => 'issue_growth', :project_id => context[:project]}) unless context[:project].nil?
output << "<br/>"
return output
end
end
9 changes: 0 additions & 9 deletions lib/old_issues_graph_hook.rb

This file was deleted.

0 comments on commit 2220eb2

Please sign in to comment.