Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working for next Redmine version V4.0.0 #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Primary developer: Brad Beattie

== How to use

Only tested on Redmine 2.0.3 and Ruby 1.9.3.
Tested on Redmine 4.0.0 and Ruby 2.3.1.
NOTE: Redmine 2.0.3 has compatibility issue with Ruby 1.9.x. Please see {Defect #11290: ParseDate missing in Ruby 1.9x - Redmine}[http://www.redmine.org/issues/11290].

$ cd /path/to/redmine/plugins
$ git clone git://github.com/bradbeattie/redmine-graphs-plugin.git redmine_graphs
$ rake redmine:plugins:migrate RAILS_ENV=production
$ rake redmine:plugins:migrate RAILS_ENV=production

Then restart redmine.
12 changes: 6 additions & 6 deletions app/controllers/graphs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class GraphsController < ApplicationController

menu_item :issues, :only => [:issue_growth, :old_issues, :bug_growth]

before_filter :find_version, :only => [:target_version_graph]
before_filter :confirm_issues_exist, :only => [:issue_growth]
before_filter :find_optional_project, :only => [:issue_growth_graph]
before_filter :find_open_issues, :only => [:old_issues, :issue_age_graph]
before_filter :find_bug_issues, :only => [:issue_growth, :bug_growth, :bug_growth_graph]
before_action :find_version, :only => [:target_version_graph]
before_action :confirm_issues_exist, :only => [:issue_growth]
before_action :find_optional_project, :only => [:issue_growth_graph]
before_action :find_open_issues, :only => [:old_issues, :issue_age_graph]
before_action :find_bug_issues, :only => [:issue_growth, :bug_growth, :bug_growth_graph]

helper IssuesHelper
helper QueriesHelper
Expand All @@ -37,7 +37,7 @@ def recent_assigned_to_changes_graph
@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?
@users = User.where(id: user_ids).to_a.index_by { |user| user.id } unless user_ids.empty?
headers["Content-Type"] = "image/svg+xml"
render :layout => false
end
Expand Down
29 changes: 29 additions & 0 deletions app/views/issues/_list_simple.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<% if issues && issues.any? %>
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
<table class="list list-simple issues">
<thead><tr>
<th class="id">#</th>
<th class="project"><%=l(:field_project)%></th>
<th class="status"><%=l(:field_status)%></th>
<th class="subject"><%=l(:field_subject)%></th>
</tr></thead>
<tbody>
<% for issue in issues %>
<tr id="issue-<%= h(issue.id) %>" class="hascontextmenu <%= issue.css_classes %>">
<td class="id">
<%= check_box_tag("ids[]", issue.id, false, :style => 'display:none;', :id => nil) %>
<%= link_to("#{issue.tracker} ##{issue.id}", issue_path(issue)) %>
</td>
<td class="project"><%= link_to_project(issue.project) %></td>
<td class="status"><%= issue.status %></td>
<td class="subject">
<span><%= link_to(issue.subject, issue_path(issue)) %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
2 changes: 1 addition & 1 deletion config/locales/ko.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
en:
ko:
label_graphs: Graphs
label_graphs_total_vs_closed_issues: Total issues vs. Closed issues
label_graphs_old_issues: Open aging issues
Expand Down
340 changes: 340 additions & 0 deletions lib/SVG/GPL.txt

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions lib/SVG/Graph/Bar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
require 'rexml/document'
require 'SVG/Graph/Graph'
require 'SVG/Graph/BarBase'

module SVG
module Graph
# === Create presentation quality SVG bar graphs easily
#
# = Synopsis
#
# require 'SVG/Graph/Bar'
#
# fields = %w(Jan Feb Mar);
# data_sales_02 = [12, 45, 21]
#
# graph = SVG::Graph::Bar.new(
# :height => 500,
# :width => 300,
# :fields => fields
# )
#
# graph.add_data(
# :data => data_sales_02,
# :title => 'Sales 2002'
# )
#
# print "Content-type: image/svg+xml\r\n\r\n"
# print graph.burn
#
# = Description
#
# This object aims to allow you to easily create high quality
# SVG[http://www.w3c.org/tr/svg bar graphs. You can either use the default
# style sheet or supply your own. Either way there are many options which
# can be configured to give you control over how the graph is generated -
# with or without a key, data elements at each point, title, subtitle etc.
#
# = Notes
#
# The default stylesheet handles upto 12 data sets, if you
# use more you must create your own stylesheet and add the
# additional settings for the extra data sets. You will know
# if you go over 12 data sets as they will have no style and
# be in black.
#
# = Examples
#
# * http://germane-software.com/repositories/public/SVG/test/test.rb
#
# = See also
#
# * SVG::Graph::Graph
# * SVG::Graph::BarHorizontal
# * SVG::Graph::Line
# * SVG::Graph::Pie
# * SVG::Graph::Plot
# * SVG::Graph::TimeSeries
class Bar < BarBase
include REXML

# See Graph::initialize and BarBase::set_defaults
def set_defaults
super
self.top_align = self.top_font = 1
end

protected

def get_x_labels
@config[:fields]
end

def get_y_labels
maxvalue = max_value
minvalue = min_value
range = maxvalue - minvalue

top_pad = range == 0 ? 10 : range / 20.0
scale_range = (maxvalue + top_pad) - minvalue

scale_division = scale_divisions || (scale_range / 10.0)

if scale_integers
scale_division = scale_division < 1 ? 1 : scale_division.round
end

rv = []
maxvalue = maxvalue%scale_division == 0 ?
maxvalue : maxvalue + scale_division
minvalue.step( maxvalue, scale_division ) {|v| rv << v}
return rv
end

def x_label_offset( width )
width / 2.0
end

def draw_data
minvalue = min_value
fieldwidth = field_width

unit_size = (@graph_height.to_f - font_size*2*top_font) /
(get_y_labels.max - get_y_labels.min)
bargap = bar_gap ? (fieldwidth < 10 ? fieldwidth / 2 : 10) : 0

bar_width = fieldwidth - bargap
bar_width /= @data.length if stack == :side
x_mod = (@graph_width-bargap)/2 - (stack==:side ? bar_width/2 : 0)

bottom = @graph_height

field_count = 0
@config[:fields].each_index { |i|
dataset_count = 0
for dataset in @data

# cases (assume 0 = +ve):
# value min length
# +ve +ve value - min
# +ve -ve value - 0
# -ve -ve value.abs - 0

value = dataset[:data][i]

left = (fieldwidth * field_count)

length = (value.abs - (minvalue > 0 ? minvalue : 0)) * unit_size
# top is 0 if value is negative
top = bottom - (((value < 0 ? 0 : value) - minvalue) * unit_size)
left += bar_width * dataset_count if stack == :side

@graph.add_element( "rect", {
"x" => left.to_s,
"y" => top.to_s,
"width" => bar_width.to_s,
"height" => length.to_s,
"class" => "fill#{dataset_count+1}"
})

make_datapoint_text(left + bar_width/2.0, top - 6, value.to_s)
dataset_count += 1
end
field_count += 1
}
end
end
end
end
139 changes: 139 additions & 0 deletions lib/SVG/Graph/BarBase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
require 'rexml/document'
require 'SVG/Graph/Graph'

module SVG
module Graph
# = Synopsis
#
# A superclass for bar-style graphs. Do not attempt to instantiate
# directly; use one of the subclasses instead.
#
# = Author
#
# Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
#
# Copyright 2004 Sean E. Russell
# This software is available under the Ruby license[LICENSE.txt]
#
class BarBase < SVG::Graph::Graph
# Ensures that :fields are provided in the configuration.
def initialize config
raise "fields was not supplied or is empty" unless config[:fields] &&
config[:fields].kind_of?(Array) &&
config[:fields].length > 0
super
end

# In addition to the defaults set in Graph::initialize, sets
# [bar_gap] true
# [stack] :overlap
def set_defaults
init_with( :bar_gap => true, :stack => :overlap )
end

# Whether to have a gap between the bars or not, default
# is true, set to false if you don't want gaps.
attr_accessor :bar_gap
# How to stack data sets. :overlap overlaps bars with
# transparent colors, :top stacks bars on top of one another,
# :side stacks the bars side-by-side. Defaults to :overlap.
attr_accessor :stack


protected

def max_value
@data.collect{|x| x[:data].max}.max
end

def min_value
min = 0
if min_scale_value.nil?
min = @data.collect{|x| x[:data].min}.min
min = min > 0 ? 0 : min
else
min = min_scale_value
end
return min
end

def get_css
return <<EOL
/* default fill styles for multiple datasets (probably only use a single dataset on this graph though) */
.key1,.fill1{
fill: #ff0000;
fill-opacity: 0.5;
stroke: none;
stroke-width: 0.5px;
}
.key2,.fill2{
fill: #0000ff;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key3,.fill3{
fill: #00ff00;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key4,.fill4{
fill: #ffcc00;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key5,.fill5{
fill: #00ccff;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key6,.fill6{
fill: #ff00ff;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key7,.fill7{
fill: #00ffff;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key8,.fill8{
fill: #ffff00;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key9,.fill9{
fill: #cc6666;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key10,.fill10{
fill: #663399;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key11,.fill11{
fill: #339900;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
.key12,.fill12{
fill: #9966FF;
fill-opacity: 0.5;
stroke: none;
stroke-width: 1px;
}
EOL
end
end
end
end
Loading