Adding a widget that shows issue assignment flow

This commit is contained in:
Brad Beattie 2009-04-24 15:36:37 -07:00
parent 164b0320b5
commit b2c84f3b9f
3 changed files with 81 additions and 0 deletions

View File

@ -9,6 +9,26 @@ class GraphsController < ApplicationController
before_filter :find_optional_project, :only => [:issue_growth, :issue_growth_graph]
helper IssuesHelper
def recent_assigned_to_changes_graph
# Get the top visible projects by issue count
sql = " select u1.id as old_user, u2.id as new_user, count(*) as changes_count"
sql << " from journals as j"
sql << " left join journal_details as jd on j.id = jd.journal_id"
sql << " left join users as u1 on jd.old_value = u1.id"
sql << " left join users as u2 on jd.value = u2.id"
sql << " where journalized_type = 'issue' and prop_key = 'assigned_to_id' and DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY) <= j.created_on"
sql << " and (u1.id = #{User.current.id} or u2.id = #{User.current.id})"
sql << " and u1.id <> 0 and u2.id <> 0"
sql << " group by old_value, value"
@assigned_to_changes = ActiveRecord::Base.connection.select_all(sql)
user_ids = @assigned_to_changes.collect { |change| [change["old_user"].to_i, change["new_user"].to_i] }.flatten.uniq
user_ids.delete(User.current.id)
@users = User.find(:all, :conditions => "id IN ("+user_ids.join(',')+")").index_by { |user| user.id } unless user_ids.empty?
headers["Content-Type"] = "image/svg+xml"
render :layout => false
end
def recent_status_changes_graph
# Get the top visible projects by issue count

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<%
points = Hash.new
points[User.current.id] = { "x" => 140, "y" => 140 }
i = -1
@users.each do |user_id, user|
points[user_id] = {
"x" => Math.sin(2*Math::PI*i/@users.size)*100 + 140,
"y" => Math.cos(2*Math::PI*i/@users.size)*100 + 140
}
i -= 1
end unless @users.nil?
%>
<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="280" height="280">
<g fill-opacity="0.2" stroke-opacity="0.5">
<% @assigned_to_changes.each do |assigned_to_change| %>
<%
changes_count = [assigned_to_change["changes_count"].to_i*3,35].min
old_user = assigned_to_change["old_user"].to_i
new_user = assigned_to_change["new_user"].to_i
x1 = points[old_user]["x"]
y1 = points[old_user]["y"]
x2 = points[new_user]["x"]
y2 = points[new_user]["y"]
atan2 = -Math.atan2(y1-y2,x1-x2)
xdiff = Math.sin(atan2)*changes_count
ydiff = Math.cos(atan2)*changes_count
%>
<polygon
points="
<%= x1-xdiff %>,<%= y1-ydiff %>
<%= x1+xdiff %>,<%= y1+ydiff %>
<%= x2+xdiff/5 %>,<%= y2+ydiff/5 %>
<%= x2-xdiff/5 %>,<%= y2-ydiff/5 %>"
fill="<%= assigned_to_change["old_user"].to_i == User.current.id ? "green" : "red" %>"
stroke="<%= assigned_to_change["old_user"].to_i == User.current.id ? "green" : "red" %>"
/>
<% end %>
</g>
<g fill="#EEEEEE" stroke="black" stroke-width="1" stroke-opacity="0.75">
<% points.each do |user_id, point| %>
<circle cx="<%= point["x"] %>" cy="<%= point["y"] %>" r="35" />
<% end %>
</g>
<g font-family="Helvetica, Arial" font-size="12" text-anchor="middle">
<% points.each do |user_id, point| %>
<text x="<%= point["x"] %>" y="<%= point["y"] + 3 %>"><%= user_id == User.current.id ? User.current : @users[user_id] %></text>
<% end %>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,5 @@
<h3><%= l(:label_graphs_issue_status_flow) %></h3>
<div style="text-align: center">
<%= tag("embed", :width => "280", :height => 280, :type => "image/svg+xml", :src => url_for(:controller => 'graphs', :action => 'recent_assigned_to_changes_graph')) %>
</div>