Feature #1432 » issueRelationFollows_r2924.patch
| app/models/issue_relation.rb (kopia robocza) | ||
|---|---|---|
|
TYPE_DUPLICATES = "duplicates"
|
||
|
TYPE_BLOCKS = "blocks"
|
||
|
TYPE_PRECEDES = "precedes"
|
||
|
TYPE_FOLLOWS = "follows"
|
||
|
|
||
|
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 },
|
||
|
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
|
||
|
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
|
||
|
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
|
||
|
}.freeze
|
||
|
|
||
|
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 },
|
||
|
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
|
||
|
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
|
||
|
TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 5 },
|
||
|
}.freeze
|
||
|
validates_presence_of :issue_from, :issue_to, :relation_type
|
||
|
validates_inclusion_of :relation_type, :in => TYPES.keys
|
||
|
validates_numericality_of :delay, :allow_nil => true
|
||
|
validates_uniqueness_of :issue_to_id, :scope => :issue_from_id
|
||
|
|
||
|
attr_protected :issue_from_id, :issue_to_id
|
||
|
|
||
|
def before_validation
|
||
|
convert_to_precedes if TYPE_FOLLOWS == relation_type
|
||
|
end
|
||
|
def validate
|
||
|
if issue_from && issue_to
|
||
|
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id
|
||
| ... | ... | |
|
def <=>(relation)
|
||
|
TYPES[self.relation_type][:order] <=> TYPES[relation.relation_type][:order]
|
||
|
end
|
||
|
private
|
||
|
def convert_to_precedes
|
||
|
if (TYPE_FOLLOWS == self.relation_type)
|
||
|
issue_tmp = self.issue_to
|
||
|
self.issue_to = self.issue_from
|
||
|
self.issue_from = issue_tmp
|
||
|
self.relation_type = TYPE_PRECEDES
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| db/migrate/001_setup.rb (kopia robocza) | ||
|---|---|---|
|
# model removed
|
||
|
class Permission < ActiveRecord::Base; end
|
||
|
|
||
|
def self.up
|
||
|
create_table "attachments", :force => true do |t|
|
||
|
t.column "container_id", :integer, :default => 0, :null => false
|
||
|
t.column "container_type", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "filename", :string, :default => "", :null => false
|
||
|
t.column "disk_filename", :string, :default => "", :null => false
|
||
|
t.column "filesize", :integer, :default => 0, :null => false
|
||
|
t.column "content_type", :string, :limit => 60, :default => ""
|
||
|
t.column "digest", :string, :limit => 40, :default => "", :null => false
|
||
|
t.column "downloads", :integer, :default => 0, :null => false
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
def self.up
|
||
|
create_table "attachments", :force => true do |t|
|
||
|
t.column "container_id", :integer, :default => 0, :null => false
|
||
|
t.column "container_type", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "filename", :string, :default => "", :null => false
|
||
|
t.column "disk_filename", :string, :default => "", :null => false
|
||
|
t.column "filesize", :integer, :default => 0, :null => false
|
||
|
t.column "content_type", :string, :limit => 60, :default => ""
|
||
|
t.column "digest", :string, :limit => 40, :default => "", :null => false
|
||
|
t.column "downloads", :integer, :default => 0, :null => false
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
create_table "auth_sources", :force => true do |t|
|
||
|
t.column "type", :string, :limit => 30, :default => "", :null => false
|
||
| ... | ... | |
|
t.column "attr_mail", :string, :limit => 30
|
||
|
t.column "onthefly_register", :boolean, :default => false, :null => false
|
||
|
end
|
||
|
|
||
|
|
||
|
create_table "custom_fields", :force => true do |t|
|
||
|
t.column "type", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "field_format", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "possible_values", :text
|
||
|
t.column "regexp", :string, :default => ""
|
||
|
t.column "min_length", :integer, :default => 0, :null => false
|
||
|
t.column "max_length", :integer, :default => 0, :null => false
|
||
|
t.column "type", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "field_format", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "possible_values", :text
|
||
|
t.column "regexp", :string, :default => ""
|
||
|
t.column "min_length", :integer, :default => 0, :null => false
|
||
|
t.column "max_length", :integer, :default => 0, :null => false
|
||
|
t.column "is_required", :boolean, :default => false, :null => false
|
||
|
t.column "is_for_all", :boolean, :default => false, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "custom_fields_projects", :id => false, :force => true do |t|
|
||
|
t.column "custom_field_id", :integer, :default => 0, :null => false
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
end
|
||
|
|
||
|
create_table "custom_fields_projects", :id => false, :force => true do |t|
|
||
|
t.column "custom_field_id", :integer, :default => 0, :null => false
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
create_table "custom_fields_trackers", :id => false, :force => true do |t|
|
||
|
t.column "custom_field_id", :integer, :default => 0, :null => false
|
||
|
t.column "tracker_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "custom_values", :force => true do |t|
|
||
|
create_table "custom_values", :force => true do |t|
|
||
|
t.column "customized_type", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "customized_id", :integer, :default => 0, :null => false
|
||
|
t.column "custom_field_id", :integer, :default => 0, :null => false
|
||
|
t.column "value", :text
|
||
|
end
|
||
|
|
||
|
create_table "documents", :force => true do |t|
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "category_id", :integer, :default => 0, :null => false
|
||
|
t.column "title", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "description", :text
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "custom_field_id", :integer, :default => 0, :null => false
|
||
|
t.column "value", :text
|
||
|
end
|
||
|
|
||
|
create_table "documents", :force => true do |t|
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "category_id", :integer, :default => 0, :null => false
|
||
|
t.column "title", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "description", :text
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "documents", ["project_id"], :name => "documents_project_id"
|
||
|
|
||
|
create_table "enumerations", :force => true do |t|
|
||
|
t.column "opt", :string, :limit => 4, :default => "", :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
end
|
||
|
|
||
|
create_table "issue_categories", :force => true do |t|
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
add_index "documents", ["project_id"], :name => "documents_project_id"
|
||
|
|
||
|
create_table "enumerations", :force => true do |t|
|
||
|
t.column "opt", :string, :limit => 4, :default => "", :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
end
|
||
|
|
||
|
create_table "issue_categories", :force => true do |t|
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
end
|
||
|
|
||
|
add_index "issue_categories", ["project_id"], :name => "issue_categories_project_id"
|
||
|
|
||
|
create_table "issue_histories", :force => true do |t|
|
||
|
t.column "issue_id", :integer, :default => 0, :null => false
|
||
|
t.column "status_id", :integer, :default => 0, :null => false
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "notes", :text
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "issue_histories", ["issue_id"], :name => "issue_histories_issue_id"
|
||
|
|
||
|
create_table "issue_statuses", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "is_closed", :boolean, :default => false, :null => false
|
||
|
t.column "is_default", :boolean, :default => false, :null => false
|
||
|
t.column "html_color", :string, :limit => 6, :default => "FFFFFF", :null => false
|
||
|
end
|
||
|
|
||
|
create_table "issues", :force => true do |t|
|
||
|
t.column "tracker_id", :integer, :default => 0, :null => false
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "subject", :string, :default => "", :null => false
|
||
|
add_index "issue_categories", ["project_id"], :name => "issue_categories_project_id"
|
||
|
|
||
|
create_table "issue_histories", :force => true do |t|
|
||
|
t.column "issue_id", :integer, :default => 0, :null => false
|
||
|
t.column "status_id", :integer, :default => 0, :null => false
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "notes", :text
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "issue_histories", ["issue_id"], :name => "issue_histories_issue_id"
|
||
|
create_table "issue_statuses", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "is_closed", :boolean, :default => false, :null => false
|
||
|
t.column "is_default", :boolean, :default => false, :null => false
|
||
|
t.column "html_color", :string, :limit => 6, :default => "FFFFFF", :null => false
|
||
|
end
|
||
|
|
||
|
create_table "issues", :force => true do |t|
|
||
|
t.column "tracker_id", :integer, :default => 0, :null => false
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "subject", :string, :default => "", :null => false
|
||
|
t.column "description", :text
|
||
|
t.column "due_date", :date
|
||
|
t.column "category_id", :integer
|
||
|
t.column "status_id", :integer, :default => 0, :null => false
|
||
|
t.column "assigned_to_id", :integer
|
||
|
t.column "priority_id", :integer, :default => 0, :null => false
|
||
|
t.column "fixed_version_id", :integer
|
||
|
t.column "due_date", :date
|
||
|
t.column "category_id", :integer
|
||
|
t.column "status_id", :integer, :default => 0, :null => false
|
||
|
t.column "assigned_to_id", :integer
|
||
|
t.column "priority_id", :integer, :default => 0, :null => false
|
||
|
t.column "fixed_version_id", :integer
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "lock_version", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "issues", ["project_id"], :name => "issues_project_id"
|
||
|
|
||
|
create_table "members", :force => true do |t|
|
||
|
t.column "user_id", :integer, :default => 0, :null => false
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "role_id", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
|
||
|
create_table "news", :force => true do |t|
|
||
|
t.column "project_id", :integer
|
||
|
t.column "title", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "summary", :string, :limit => 255, :default => ""
|
||
|
t.column "description", :text
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "lock_version", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "issues", ["project_id"], :name => "issues_project_id"
|
||
|
|
||
|
create_table "members", :force => true do |t|
|
||
|
t.column "user_id", :integer, :default => 0, :null => false
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "role_id", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
|
||
|
create_table "news", :force => true do |t|
|
||
|
t.column "project_id", :integer
|
||
|
t.column "title", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "summary", :string, :limit => 255, :default => ""
|
||
|
t.column "description", :text
|
||
|
t.column "author_id", :integer, :default => 0, :null => false
|
||
|
t.column "created_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "news", ["project_id"], :name => "news_project_id"
|
||
|
|
||
|
create_table "permissions", :force => true do |t|
|
||
|
t.column "controller", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "action", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "description", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "is_public", :boolean, :default => false, :null => false
|
||
|
t.column "sort", :integer, :default => 0, :null => false
|
||
|
t.column "mail_option", :boolean, :default => false, :null => false
|
||
|
t.column "mail_enabled", :boolean, :default => false, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "permissions_roles", :id => false, :force => true do |t|
|
||
|
t.column "permission_id", :integer, :default => 0, :null => false
|
||
|
t.column "role_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
|
||
|
add_index "permissions_roles", ["role_id"], :name => "permissions_roles_role_id"
|
||
|
|
||
|
create_table "projects", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "description", :string, :default => "", :null => false
|
||
|
t.column "homepage", :string, :limit => 60, :default => ""
|
||
|
add_index "news", ["project_id"], :name => "news_project_id"
|
||
|
|
||
|
create_table "permissions", :force => true do |t|
|
||
|
t.column "controller", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "action", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "description", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "is_public", :boolean, :default => false, :null => false
|
||
|
t.column "sort", :integer, :default => 0, :null => false
|
||
|
t.column "mail_option", :boolean, :default => false, :null => false
|
||
|
t.column "mail_enabled", :boolean, :default => false, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "permissions_roles", :id => false, :force => true do |t|
|
||
|
t.column "permission_id", :integer, :default => 0, :null => false
|
||
|
t.column "role_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
|
||
|
add_index "permissions_roles", ["role_id"], :name => "permissions_roles_role_id"
|
||
|
|
||
|
create_table "projects", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "description", :string, :default => "", :null => false
|
||
|
t.column "homepage", :string, :limit => 60, :default => ""
|
||
|
t.column "is_public", :boolean, :default => true, :null => false
|
||
|
t.column "parent_id", :integer
|
||
|
t.column "projects_count", :integer, :default => 0
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
create_table "roles", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
end
|
||
|
t.column "projects_count", :integer, :default => 0
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
create_table "roles", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
end
|
||
|
create_table "tokens", :force => true do |t|
|
||
|
t.column "user_id", :integer, :default => 0, :null => false
|
||
| ... | ... | |
|
t.column "value", :string, :limit => 40, :default => "", :null => false
|
||
|
t.column "created_on", :datetime, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "trackers", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "is_in_chlog", :boolean, :default => false, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "users", :force => true do |t|
|
||
|
t.column "login", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "hashed_password", :string, :limit => 40, :default => "", :null => false
|
||
|
t.column "firstname", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "lastname", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "mail", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "mail_notification", :boolean, :default => true, :null => false
|
||
|
t.column "admin", :boolean, :default => false, :null => false
|
||
|
t.column "status", :integer, :default => 1, :null => false
|
||
|
t.column "last_login_on", :datetime
|
||
|
|
||
|
create_table "trackers", :force => true do |t|
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "is_in_chlog", :boolean, :default => false, :null => false
|
||
|
end
|
||
|
|
||
|
create_table "users", :force => true do |t|
|
||
|
t.column "login", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "hashed_password", :string, :limit => 40, :default => "", :null => false
|
||
|
t.column "firstname", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "lastname", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "mail", :string, :limit => 60, :default => "", :null => false
|
||
|
t.column "mail_notification", :boolean, :default => true, :null => false
|
||
|
t.column "admin", :boolean, :default => false, :null => false
|
||
|
t.column "status", :integer, :default => 1, :null => false
|
||
|
t.column "last_login_on", :datetime
|
||
|
t.column "language", :string, :limit => 2, :default => ""
|
||
|
t.column "auth_source_id", :integer
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
create_table "versions", :force => true do |t|
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "description", :string, :default => ""
|
||
|
t.column "effective_date", :date
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
t.column "auth_source_id", :integer
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
create_table "versions", :force => true do |t|
|
||
|
t.column "project_id", :integer, :default => 0, :null => false
|
||
|
t.column "name", :string, :limit => 30, :default => "", :null => false
|
||
|
t.column "description", :string, :default => ""
|
||
|
t.column "effective_date", :date
|
||
|
t.column "created_on", :timestamp
|
||
|
t.column "updated_on", :timestamp
|
||
|
end
|
||
|
|
||
|
add_index "versions", ["project_id"], :name => "versions_project_id"
|
||
|
|
||
|
create_table "workflows", :force => true do |t|
|
||
|
t.column "tracker_id", :integer, :default => 0, :null => false
|
||
|
t.column "old_status_id", :integer, :default => 0, :null => false
|
||
|
t.column "new_status_id", :integer, :default => 0, :null => false
|
||
|
t.column "role_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
|
||
|
# project
|
||
|
Permission.create :controller => "projects", :action => "show", :description => "label_overview", :sort => 100, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "changelog", :description => "label_change_log", :sort => 105, :is_public => true
|
||
|
Permission.create :controller => "reports", :action => "issue_report", :description => "label_report_plural", :sort => 110, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "settings", :description => "label_settings", :sort => 150
|
||
|
Permission.create :controller => "projects", :action => "edit", :description => "button_edit", :sort => 151
|
||
|
# members
|
||
|
Permission.create :controller => "projects", :action => "list_members", :description => "button_list", :sort => 200, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_member", :description => "button_add", :sort => 220
|
||
|
Permission.create :controller => "members", :action => "edit", :description => "button_edit", :sort => 221
|
||
|
Permission.create :controller => "members", :action => "destroy", :description => "button_delete", :sort => 222
|
||
|
# versions
|
||
|
Permission.create :controller => "projects", :action => "add_version", :description => "button_add", :sort => 320
|
||
|
Permission.create :controller => "versions", :action => "edit", :description => "button_edit", :sort => 321
|
||
|
Permission.create :controller => "versions", :action => "destroy", :description => "button_delete", :sort => 322
|
||
|
# issue categories
|
||
|
Permission.create :controller => "projects", :action => "add_issue_category", :description => "button_add", :sort => 420
|
||
|
Permission.create :controller => "issue_categories", :action => "edit", :description => "button_edit", :sort => 421
|
||
|
Permission.create :controller => "issue_categories", :action => "destroy", :description => "button_delete", :sort => 422
|
||
|
# issues
|
||
|
Permission.create :controller => "projects", :action => "list_issues", :description => "button_list", :sort => 1000, :is_public => true
|
||
|
add_index "versions", ["project_id"], :name => "versions_project_id"
|
||
|
|
||
|
create_table "workflows", :force => true do |t|
|
||
|
t.column "tracker_id", :integer, :default => 0, :null => false
|
||
|
t.column "old_status_id", :integer, :default => 0, :null => false
|
||
|
t.column "new_status_id", :integer, :default => 0, :null => false
|
||
|
t.column "role_id", :integer, :default => 0, :null => false
|
||
|
end
|
||
|
|
||
|
# project
|
||
|
Permission.create :controller => "projects", :action => "show", :description => "label_overview", :sort => 100, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "changelog", :description => "label_change_log", :sort => 105, :is_public => true
|
||
|
Permission.create :controller => "reports", :action => "issue_report", :description => "label_report_plural", :sort => 110, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "settings", :description => "label_settings", :sort => 150
|
||
|
Permission.create :controller => "projects", :action => "edit", :description => "button_edit", :sort => 151
|
||
|
# members
|
||
|
Permission.create :controller => "projects", :action => "list_members", :description => "button_list", :sort => 200, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_member", :description => "button_add", :sort => 220
|
||
|
Permission.create :controller => "members", :action => "edit", :description => "button_edit", :sort => 221
|
||
|
Permission.create :controller => "members", :action => "destroy", :description => "button_delete", :sort => 222
|
||
|
# versions
|
||
|
Permission.create :controller => "projects", :action => "add_version", :description => "button_add", :sort => 320
|
||
|
Permission.create :controller => "versions", :action => "edit", :description => "button_edit", :sort => 321
|
||
|
Permission.create :controller => "versions", :action => "destroy", :description => "button_delete", :sort => 322
|
||
|
# issue categories
|
||
|
Permission.create :controller => "projects", :action => "add_issue_category", :description => "button_add", :sort => 420
|
||
|
Permission.create :controller => "issue_categories", :action => "edit", :description => "button_edit", :sort => 421
|
||
|
Permission.create :controller => "issue_categories", :action => "destroy", :description => "button_delete", :sort => 422
|
||
|
# issues
|
||
|
Permission.create :controller => "projects", :action => "list_issues", :description => "button_list", :sort => 1000, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "export_issues_csv", :description => "label_export_csv", :sort => 1001, :is_public => true
|
||
|
Permission.create :controller => "issues", :action => "show", :description => "button_view", :sort => 1005, :is_public => true
|
||
|
Permission.create :controller => "issues", :action => "download", :description => "button_download", :sort => 1010, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_issue", :description => "button_add", :sort => 1050, :mail_option => 1, :mail_enabled => 1
|
||
|
Permission.create :controller => "issues", :action => "edit", :description => "button_edit", :sort => 1055
|
||
|
Permission.create :controller => "issues", :action => "change_status", :description => "label_change_status", :sort => 1060, :mail_option => 1, :mail_enabled => 1
|
||
|
Permission.create :controller => "issues", :action => "destroy", :description => "button_delete", :sort => 1065
|
||
|
Permission.create :controller => "issues", :action => "add_attachment", :description => "label_attachment_new", :sort => 1070
|
||
|
Permission.create :controller => "issues", :action => "destroy_attachment", :description => "label_attachment_delete", :sort => 1075
|
||
|
# news
|
||
|
Permission.create :controller => "projects", :action => "list_news", :description => "button_list", :sort => 1100, :is_public => true
|
||
|
Permission.create :controller => "news", :action => "show", :description => "button_view", :sort => 1101, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_news", :description => "button_add", :sort => 1120
|
||
|
Permission.create :controller => "news", :action => "edit", :description => "button_edit", :sort => 1121
|
||
|
Permission.create :controller => "news", :action => "destroy", :description => "button_delete", :sort => 1122
|
||
|
Permission.create :controller => "issues", :action => "show", :description => "button_view", :sort => 1005, :is_public => true
|
||
|
Permission.create :controller => "issues", :action => "download", :description => "button_download", :sort => 1010, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_issue", :description => "button_add", :sort => 1050, :mail_option => 1, :mail_enabled => 1
|
||
|
Permission.create :controller => "issues", :action => "edit", :description => "button_edit", :sort => 1055
|
||
|
Permission.create :controller => "issues", :action => "change_status", :description => "label_change_status", :sort => 1060, :mail_option => 1, :mail_enabled => 1
|
||
|
Permission.create :controller => "issues", :action => "destroy", :description => "button_delete", :sort => 1065
|
||
|
Permission.create :controller => "issues", :action => "add_attachment", :description => "label_attachment_new", :sort => 1070
|
||
|
Permission.create :controller => "issues", :action => "destroy_attachment", :description => "label_attachment_delete", :sort => 1075
|
||
|
# news
|
||
|
Permission.create :controller => "projects", :action => "list_news", :description => "button_list", :sort => 1100, :is_public => true
|
||
|
Permission.create :controller => "news", :action => "show", :description => "button_view", :sort => 1101, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_news", :description => "button_add", :sort => 1120
|
||
|
Permission.create :controller => "news", :action => "edit", :description => "button_edit", :sort => 1121
|
||
|
Permission.create :controller => "news", :action => "destroy", :description => "button_delete", :sort => 1122
|
||
|
# documents
|
||
|
Permission.create :controller => "projects", :action => "list_documents", :description => "button_list", :sort => 1200, :is_public => true
|
||
|
Permission.create :controller => "documents", :action => "show", :description => "button_view", :sort => 1201, :is_public => true
|
||
|
Permission.create :controller => "documents", :action => "download", :description => "button_download", :sort => 1202, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_document", :description => "button_add", :sort => 1220
|
||
|
Permission.create :controller => "documents", :action => "edit", :description => "button_edit", :sort => 1221
|
||
|
Permission.create :controller => "documents", :action => "destroy", :description => "button_delete", :sort => 1222
|
||
|
Permission.create :controller => "documents", :action => "add_attachment", :description => "label_attachment_new", :sort => 1223
|
||
|
Permission.create :controller => "documents", :action => "destroy_attachment", :description => "label_attachment_delete", :sort => 1224
|
||
|
# files
|
||
|
Permission.create :controller => "projects", :action => "list_files", :description => "button_list", :sort => 1300, :is_public => true
|
||
|
Permission.create :controller => "versions", :action => "download", :description => "button_download", :sort => 1301, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_file", :description => "button_add", :sort => 1320
|
||
|
Permission.create :controller => "versions", :action => "destroy_file", :description => "button_delete", :sort => 1322
|
||
|
|
||
|
# create default administrator account
|
||
|
Permission.create :controller => "projects", :action => "list_documents", :description => "button_list", :sort => 1200, :is_public => true
|
||
|
Permission.create :controller => "documents", :action => "show", :description => "button_view", :sort => 1201, :is_public => true
|
||
|
Permission.create :controller => "documents", :action => "download", :description => "button_download", :sort => 1202, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_document", :description => "button_add", :sort => 1220
|
||
|
Permission.create :controller => "documents", :action => "edit", :description => "button_edit", :sort => 1221
|
||
|
Permission.create :controller => "documents", :action => "destroy", :description => "button_delete", :sort => 1222
|
||
|
Permission.create :controller => "documents", :action => "add_attachment", :description => "label_attachment_new", :sort => 1223
|
||
|
Permission.create :controller => "documents", :action => "destroy_attachment", :description => "label_attachment_delete", :sort => 1224
|
||
|
# files
|
||
|
Permission.create :controller => "projects", :action => "list_files", :description => "button_list", :sort => 1300, :is_public => true
|
||
|
Permission.create :controller => "versions", :action => "download", :description => "button_download", :sort => 1301, :is_public => true
|
||
|
Permission.create :controller => "projects", :action => "add_file", :description => "button_add", :sort => 1320
|
||
|
Permission.create :controller => "versions", :action => "destroy_file", :description => "button_delete", :sort => 1322
|
||
|
|
||
|
# create default administrator account
|
||
|
user = User.create :login => "admin",
|
||
|
:hashed_password => "d033e22ae348aeb5660fc2140aec35850c4da997",
|
||
|
:admin => true,
|
||
| ... | ... | |
|
:status => 1
|
||
|
end
|
||
|
def self.down
|
||
|
def self.down
|
||
|
drop_table :attachments
|
||
|
drop_table :auth_sources
|
||
|
drop_table :custom_fields
|
||
|
drop_table :auth_sources
|
||
|
drop_table :custom_fields
|
||
|
drop_table :custom_fields_projects
|
||
|
drop_table :custom_fields_trackers
|
||
|
drop_table :custom_values
|
||
|
drop_table :documents
|
||
|
drop_table :enumerations
|
||
|
drop_table :issue_categories
|
||
|
drop_table :issue_histories
|
||
|
drop_table :issue_statuses
|
||
|
drop_table :issues
|
||
|
drop_table :members
|
||
|
drop_table :news
|
||
|
drop_table :permissions
|
||
|
drop_table :permissions_roles
|
||
|
drop_table :projects
|
||
|
drop_table :roles
|
||
|
drop_table :trackers
|
||
|
drop_table :custom_fields_trackers
|
||
|
drop_table :custom_values
|
||
|
drop_table :documents
|
||
|
drop_table :enumerations
|
||
|
drop_table :issue_categories
|
||
|
drop_table :issue_histories
|
||
|
drop_table :issue_statuses
|
||
|
drop_table :issues
|
||
|
drop_table :members
|
||
|
drop_table :news
|
||
|
drop_table :permissions
|
||
|
drop_table :permissions_roles
|
||
|
drop_table :projects
|
||
|
drop_table :roles
|
||
|
drop_table :trackers
|
||
|
drop_table :tokens
|
||
|
drop_table :users
|
||
|
drop_table :versions
|
||
|
drop_table :users
|
||
|
drop_table :versions
|
||
|
drop_table :workflows
|
||
|
end
|
||
|
end
|
||
| lib/SVG/Graph/Pie.rb (kopia robocza) | ||
|---|---|---|
|
require 'SVG/Graph/Graph'
|
||
|
|
||
|
module SVG
|
||
|
module Graph
|
||
|
# === Create presentation quality SVG pie graphs easily
|
||
|
#
|
||
|
# == Synopsis
|
||
|
#
|
||
|
# require 'SVG/Graph/Pie'
|
||
|
#
|
||
|
# fields = %w(Jan Feb Mar)
|
||
|
# data_sales_02 = [12, 45, 21]
|
||
|
#
|
||
|
# graph = SVG::Graph::Pie.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 pie 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, display percent on pie chart,
|
||
|
# title, subtitle etc.
|
||
|
#
|
||
|
# = Examples
|
||
|
#
|
||
|
# http://www.germane-software/repositories/public/SVG/test/single.rb
|
||
|
#
|
||
|
# == See also
|
||
|
#
|
||
|
# * SVG::Graph::Graph
|
||
|
# * SVG::Graph::BarHorizontal
|
||
|
# * SVG::Graph::Bar
|
||
|
# * SVG::Graph::Line
|
||
|
# * SVG::Graph::Plot
|
||
|
# * SVG::Graph::TimeSeries
|
||
|
#
|
||
|
# == Author
|
||
|
#
|
||
|
# Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
|
||
|
#
|
||
|
# Copyright 2004 Sean E. Russell
|
||
|
# This software is available under the Ruby license[LICENSE.txt]
|
||
|
#
|
||
|
class Pie < Graph
|
||
|
# Defaults are those set by Graph::initialize, and
|
||
|
# [show_shadow] true
|
||
|
# [shadow_offset] 10
|
||
|
# [show_data_labels] false
|
||
|
# [show_actual_values] false
|
||
|
# [show_percent] true
|
||
|
# [show_key_data_labels] true
|
||
|
# [show_key_actual_values] true
|
||
|
# [show_key_percent] false
|
||
|
# [expanded] false
|
||
|
# [expand_greatest] false
|
||
|
# [expand_gap] 10
|
||
|
# [show_x_labels] false
|
||
|
# [show_y_labels] false
|
||
|
# [datapoint_font_size] 12
|
||
|
def set_defaults
|
||
|
init_with(
|
||
|
:show_shadow => true,
|
||
|
:shadow_offset => 10,
|
||
|
|
||
|
:show_data_labels => false,
|
||
|
:show_actual_values => false,
|
||
|
:show_percent => true,
|
||
|
|
||
|
:show_key_data_labels => true,
|
||
|
:show_key_actual_values => true,
|
||
|
:show_key_percent => false,
|
||
|
|
||
|
:expanded => false,
|
||
|
:expand_greatest => false,
|
||
|
:expand_gap => 10,
|
||
|
|
||
|
:show_x_labels => false,
|
||
|
:show_y_labels => false,
|
||
|
:datapoint_font_size => 12
|
||
|
)
|
||
|
@data = []
|
||
|
end
|
||
|
|
||
|
# Adds a data set to the graph.
|
||
|
#
|
||
|
# graph.add_data( { :data => [1,2,3,4] } )
|
||
|
#
|
||
|
# Note that the :title is not necessary. If multiple
|
||
|
# data sets are added to the graph, the pie chart will
|
||
|
# display the +sums+ of the data. EG:
|
||
|
#
|
||
|
# graph.add_data( { :data => [1,2,3,4] } )
|
||
|
# graph.add_data( { :data => [2,3,5,9] } )
|
||
|
#
|
||
|
# is the same as:
|
||
|
#
|
||
|
# graph.add_data( { :data => [3,5,8,13] } )
|
||
|
def add_data arg
|
||
|
arg[:data].each_index {|idx|
|
||
|
@data[idx] = 0 unless @data[idx]
|
||
|
@data[idx] += arg[:data][idx]
|
||
|
}
|
||
|
end
|
||
|
|
||
|
# If true, displays a drop shadow for the chart
|
||
|
attr_accessor :show_shadow
|
||
|
# Sets the offset of the shadow from the pie chart
|
||
|
attr_accessor :shadow_offset
|
||
|
# If true, display the data labels on the chart
|
||
|
attr_accessor :show_data_labels
|
||
|
# If true, display the actual field values in the data labels
|
||
|
attr_accessor :show_actual_values
|
||
|
# If true, display the percentage value of each pie wedge in the data
|
||
|
# labels
|
||
|
attr_accessor :show_percent
|
||
|
# If true, display the labels in the key
|
||
|
attr_accessor :show_key_data_labels
|
||
|
# If true, display the actual value of the field in the key
|
||
|
attr_accessor :show_key_actual_values
|
||
|
# If true, display the percentage value of the wedges in the key
|
||
|
attr_accessor :show_key_percent
|
||
|
# If true, "explode" the pie (put space between the wedges)
|
||
|
attr_accessor :expanded
|
||
|
# If true, expand the largest pie wedge
|
||
|
attr_accessor :expand_greatest
|
||
|
# The amount of space between expanded wedges
|
||
|
attr_accessor :expand_gap
|
||
|
# The font size of the data point labels
|
||
|
attr_accessor :datapoint_font_size
|
||
|
|
||
|
|
||
|
protected
|
||
|
|
||
|
def add_defs defs
|
||
|
gradient = defs.add_element( "filter", {
|
||
|
"id"=>"dropshadow",
|
||
|
"width" => "1.2",
|
||
|
"height" => "1.2",
|
||
|
} )
|
||
|
gradient.add_element( "feGaussianBlur", {
|
||
|
"stdDeviation" => "4",
|
||
|
"result" => "blur"
|
||
|
})
|
||
|
end
|
||
|
|
||
|
# We don't need the graph
|
||
|
def draw_graph
|
||
|
end
|
||
|
|
||
|
def get_y_labels
|
||
|
[""]
|
||
|
end
|
||
|
|
||
|
def get_x_labels
|
||
|
[""]
|
||
|
end
|
||
|
|
||
|
def keys
|
||
|
total = 0
|
||
|
max_value = 0
|
||
|
@data.each {|x| total += x }
|
||
|
percent_scale = 100.0 / total
|
||
|
count = -1
|
||
|
a = @config[:fields].collect{ |x|
|
||
|
count += 1
|
||
|
v = @data[count]
|
||
|
perc = show_key_percent ? " "+(v * percent_scale).round.to_s+"%" : ""
|
||
|
x + " [" + v.to_s + "]" + perc
|
||
|
}
|
||
|
end
|
||
|
|
||
|
RADIANS = Math::PI/180
|
||
|
|
||
|
def draw_data
|
||
|
@graph = @root.add_element( "g" )
|
||
|
background = @graph.add_element("g")
|
||
|
midground = @graph.add_element("g")
|
||
|
|
||
|
diameter = @graph_height > @graph_width ? @graph_width : @graph_height
|
||
|
diameter -= expand_gap if expanded or expand_greatest
|
||
|
diameter -= datapoint_font_size if show_data_labels
|
||
|
diameter -= 10 if show_shadow
|
||
|
radius = diameter / 2.0
|
||
|
|
||
|
xoff = (width - diameter) / 2
|
||
|
yoff = (height - @border_bottom - diameter)
|
||
|
yoff -= 10 if show_shadow
|
||
|
@graph.attributes['transform'] = "translate( #{xoff} #{yoff} )"
|
||
|
|
||
|
wedge_text_pad = 5
|
||
|
wedge_text_pad = 20 if show_percent and show_data_labels
|
||
|
|
||
|
total = 0
|
||
|
max_value = 0
|
||
|
@data.each {|x|
|
||
|
max_value = max_value < x ? x : max_value
|
||
|
total += x
|
||
|
}
|
||
|
percent_scale = 100.0 / total
|
||
|
|
||
|
prev_percent = 0
|
||
|
rad_mult = 3.6 * RADIANS
|
||
|
@config[:fields].each_index { |count|
|
||
|
value = @data[count]
|
||
|
percent = percent_scale * value
|
||
|
|
||
|
radians = prev_percent * rad_mult
|
||
|
x_start = radius+(Math.sin(radians) * radius)
|
||
|
y_start = radius-(Math.cos(radians) * radius)
|
||
|
radians = (prev_percent+percent) * rad_mult
|
||
|
x_end = radius+(Math.sin(radians) * radius)
|
||
|
x_end -= 0.00001 if @data.length == 1
|
||
|
y_end = radius-(Math.cos(radians) * radius)
|
||
|
path = "M#{radius},#{radius} L#{x_start},#{y_start} "+
|
||
|
"A#{radius},#{radius} "+
|
||
|
"0, #{percent >= 50 ? '1' : '0'},1, "+
|
||
|
"#{x_end} #{y_end} Z"
|
||
|
|
||
|
|
||
|
wedge = @foreground.add_element( "path", {
|
||
|
"d" => path,
|
||
|
"class" => "fill#{count+1}"
|
||
|
})
|
||
|
|
||
|
translate = nil
|
||
|
tx = 0
|
||
|
ty = 0
|
||
|
half_percent = prev_percent + percent / 2
|
||
|
radians = half_percent * rad_mult
|
||
|
|
||
|
if show_shadow
|
||
|
shadow = background.add_element( "path", {
|
||
|
"d" => path,
|
||
|
"filter" => "url(#dropshadow)",
|
||
|
"style" => "fill: #ccc; stroke: none;"
|
||
|
})
|
||
|
clear = midground.add_element( "path", {
|
||
|
"d" => path,
|
||
|
"style" => "fill: #fff; stroke: none;"
|
||
|
})
|
||
|
end
|
||
|
|
||
|
if expanded or (expand_greatest && value == max_value)
|
||
|
tx = (Math.sin(radians) * expand_gap)
|
||
|
ty = -(Math.cos(radians) * expand_gap)
|
||
|
translate = "translate( #{tx} #{ty} )"
|
||
|
wedge.attributes["transform"] = translate
|
||
|
clear.attributes["transform"] = translate if clear
|
||
|
end
|
||
|
|
||
|
if show_shadow
|
||
|
shadow.attributes["transform"] =
|
||
|
"translate( #{tx+shadow_offset} #{ty+shadow_offset} )"
|
||
|
end
|
||
|
|
||
|
if show_data_labels and value != 0
|
||
|
label = ""
|
||
|
label += @config[:fields][count] if show_key_data_labels
|
||
|
label += " ["+value.to_s+"]" if show_actual_values
|
||
|
label += " "+percent.round.to_s+"%" if show_percent
|
||
|
|
||
|
msr = Math.sin(radians)
|
||
|
mcr = Math.cos(radians)
|
||
|
tx = radius + (msr * radius)
|
||
|
ty = radius -(mcr * radius)
|
||
|
|
||
|
if expanded or (expand_greatest && value == max_value)
|
||
|
tx += (msr * expand_gap)
|
||
|
ty -= (mcr * expand_gap)
|
||
|
end
|
||
|
@foreground.add_element( "text", {
|
||
|
"x" => tx.to_s,
|
||
|
"y" => ty.to_s,
|
||
|
"class" => "dataPointLabel",
|
||
|
"style" => "stroke: #fff; stroke-width: 2;"
|
||
|
}).text = label.to_s
|
||
|
@foreground.add_element( "text", {
|
||
|
"x" => tx.to_s,
|
||
|
"y" => ty.to_s,
|
||
|
"class" => "dataPointLabel",
|
||
|
}).text = label.to_s
|
||
|
end
|
||
|
|
||
|
prev_percent += percent
|
||
|
}
|
||
|
end
|
||
|
|
||
|
|
||
|
def round val, to
|
||
|
up = 10**to.to_f
|
||
|
(val * up).to_i / up
|
||
|
end
|
||
|
|
||
|
|
||
|
def get_css
|
||
|
return <<EOL
|
||
|
.dataPointLabel{
|
||
|
fill: #000000;
|
||
|
text-anchor:middle;
|
||
|
font-size: #{datapoint_font_size}px;
|
||
|
font-family: "Arial", sans-serif;
|
||
|
font-weight: normal;
|
||
|
}
|
||
|
|
||
|
/* key - MUST match fill styles */
|
||
|
.key1,.fill1{
|
||
|
fill: #ff0000;
|
||
|
fill-opacity: 0.7;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key2,.fill2{
|
||
|
fill: #0000ff;
|
||
|
fill-opacity: 0.7;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key3,.fill3{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #00ff00;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key4,.fill4{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #ffcc00;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key5,.fill5{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #00ccff;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key6,.fill6{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #ff00ff;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key7,.fill7{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #00ff99;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key8,.fill8{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #ffff00;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key9,.fill9{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #cc6666;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key10,.fill10{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #663399;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key11,.fill11{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #339900;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key12,.fill12{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #9966FF;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
EOL
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
require 'SVG/Graph/Graph'
|
||
|
module SVG
|
||
|
module Graph
|
||
|
# === Create presentation quality SVG pie graphs easily
|
||
|
#
|
||
|
# == Synopsis
|
||
|
#
|
||
|
# require 'SVG/Graph/Pie'
|
||
|
#
|
||
|
# fields = %w(Jan Feb Mar)
|
||
|
# data_sales_02 = [12, 45, 21]
|
||
|
#
|
||
|
# graph = SVG::Graph::Pie.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 pie 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, display percent on pie chart,
|
||
|
# title, subtitle etc.
|
||
|
#
|
||
|
# = Examples
|
||
|
#
|
||
|
# http://www.germane-software/repositories/public/SVG/test/single.rb
|
||
|
#
|
||
|
# == See also
|
||
|
#
|
||
|
# * SVG::Graph::Graph
|
||
|
# * SVG::Graph::BarHorizontal
|
||
|
# * SVG::Graph::Bar
|
||
|
# * SVG::Graph::Line
|
||
|
# * SVG::Graph::Plot
|
||
|
# * SVG::Graph::TimeSeries
|
||
|
#
|
||
|
# == Author
|
||
|
#
|
||
|
# Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
|
||
|
#
|
||
|
# Copyright 2004 Sean E. Russell
|
||
|
# This software is available under the Ruby license[LICENSE.txt]
|
||
|
#
|
||
|
class Pie < Graph
|
||
|
# Defaults are those set by Graph::initialize, and
|
||
|
# [show_shadow] true
|
||
|
# [shadow_offset] 10
|
||
|
# [show_data_labels] false
|
||
|
# [show_actual_values] false
|
||
|
# [show_percent] true
|
||
|
# [show_key_data_labels] true
|
||
|
# [show_key_actual_values] true
|
||
|
# [show_key_percent] false
|
||
|
# [expanded] false
|
||
|
# [expand_greatest] false
|
||
|
# [expand_gap] 10
|
||
|
# [show_x_labels] false
|
||
|
# [show_y_labels] false
|
||
|
# [datapoint_font_size] 12
|
||
|
def set_defaults
|
||
|
init_with(
|
||
|
:show_shadow => true,
|
||
|
:shadow_offset => 10,
|
||
|
|
||
|
:show_data_labels => false,
|
||
|
:show_actual_values => false,
|
||
|
:show_percent => true,
|
||
|
:show_key_data_labels => true,
|
||
|
:show_key_actual_values => true,
|
||
|
:show_key_percent => false,
|
||
|
|
||
|
:expanded => false,
|
||
|
:expand_greatest => false,
|
||
|
:expand_gap => 10,
|
||
|
|
||
|
:show_x_labels => false,
|
||
|
:show_y_labels => false,
|
||
|
:datapoint_font_size => 12
|
||
|
)
|
||
|
@data = []
|
||
|
end
|
||
|
# Adds a data set to the graph.
|
||
|
#
|
||
|
# graph.add_data( { :data => [1,2,3,4] } )
|
||
|
#
|
||
|
# Note that the :title is not necessary. If multiple
|
||
|
# data sets are added to the graph, the pie chart will
|
||
|
# display the +sums+ of the data. EG:
|
||
|
#
|
||
|
# graph.add_data( { :data => [1,2,3,4] } )
|
||
|
# graph.add_data( { :data => [2,3,5,9] } )
|
||
|
#
|
||
|
# is the same as:
|
||
|
#
|
||
|
# graph.add_data( { :data => [3,5,8,13] } )
|
||
|
def add_data arg
|
||
|
arg[:data].each_index {|idx|
|
||
|
@data[idx] = 0 unless @data[idx]
|
||
|
@data[idx] += arg[:data][idx]
|
||
|
}
|
||
|
end
|
||
|
# If true, displays a drop shadow for the chart
|
||
|
attr_accessor :show_shadow
|
||
|
# Sets the offset of the shadow from the pie chart
|
||
|
attr_accessor :shadow_offset
|
||
|
# If true, display the data labels on the chart
|
||
|
attr_accessor :show_data_labels
|
||
|
# If true, display the actual field values in the data labels
|
||
|
attr_accessor :show_actual_values
|
||
|
# If true, display the percentage value of each pie wedge in the data
|
||
|
# labels
|
||
|
attr_accessor :show_percent
|
||
|
# If true, display the labels in the key
|
||
|
attr_accessor :show_key_data_labels
|
||
|
# If true, display the actual value of the field in the key
|
||
|
attr_accessor :show_key_actual_values
|
||
|
# If true, display the percentage value of the wedges in the key
|
||
|
attr_accessor :show_key_percent
|
||
|
# If true, "explode" the pie (put space between the wedges)
|
||
|
attr_accessor :expanded
|
||
|
# If true, expand the largest pie wedge
|
||
|
attr_accessor :expand_greatest
|
||
|
# The amount of space between expanded wedges
|
||
|
attr_accessor :expand_gap
|
||
|
# The font size of the data point labels
|
||
|
attr_accessor :datapoint_font_size
|
||
|
protected
|
||
|
def add_defs defs
|
||
|
gradient = defs.add_element( "filter", {
|
||
|
"id"=>"dropshadow",
|
||
|
"width" => "1.2",
|
||
|
"height" => "1.2",
|
||
|
} )
|
||
|
gradient.add_element( "feGaussianBlur", {
|
||
|
"stdDeviation" => "4",
|
||
|
"result" => "blur"
|
||
|
})
|
||
|
end
|
||
|
# We don't need the graph
|
||
|
def draw_graph
|
||
|
end
|
||
|
def get_y_labels
|
||
|
[""]
|
||
|
end
|
||
|
def get_x_labels
|
||
|
[""]
|
||
|
end
|
||
|
def keys
|
||
|
total = 0
|
||
|
max_value = 0
|
||
|
@data.each {|x| total += x }
|
||
|
percent_scale = 100.0 / total
|
||
|
count = -1
|
||
|
a = @config[:fields].collect{ |x|
|
||
|
count += 1
|
||
|
v = @data[count]
|
||
|
perc = show_key_percent ? " "+(v * percent_scale).round.to_s+"%" : ""
|
||
|
x + " [" + v.to_s + "]" + perc
|
||
|
}
|
||
|
end
|
||
|
RADIANS = Math::PI/180
|
||
|
def draw_data
|
||
|
@graph = @root.add_element( "g" )
|
||
|
background = @graph.add_element("g")
|
||
|
midground = @graph.add_element("g")
|
||
|
diameter = @graph_height > @graph_width ? @graph_width : @graph_height
|
||
|
diameter -= expand_gap if expanded or expand_greatest
|
||
|
diameter -= datapoint_font_size if show_data_labels
|
||
|
diameter -= 10 if show_shadow
|
||
|
radius = diameter / 2.0
|
||
|
xoff = (width - diameter) / 2
|
||
|
yoff = (height - @border_bottom - diameter)
|
||
|
yoff -= 10 if show_shadow
|
||
|
@graph.attributes['transform'] = "translate( #{xoff} #{yoff} )"
|
||
|
wedge_text_pad = 5
|
||
|
wedge_text_pad = 20 if show_percent and show_data_labels
|
||
|
total = 0
|
||
|
max_value = 0
|
||
|
@data.each {|x|
|
||
|
max_value = max_value < x ? x : max_value
|
||
|
total += x
|
||
|
}
|
||
|
percent_scale = 100.0 / total
|
||
|
prev_percent = 0
|
||
|
rad_mult = 3.6 * RADIANS
|
||
|
@config[:fields].each_index { |count|
|
||
|
value = @data[count]
|
||
|
percent = percent_scale * value
|
||
|
radians = prev_percent * rad_mult
|
||
|
x_start = radius+(Math.sin(radians) * radius)
|
||
|
y_start = radius-(Math.cos(radians) * radius)
|
||
|
radians = (prev_percent+percent) * rad_mult
|
||
|
x_end = radius+(Math.sin(radians) * radius)
|
||
|
x_end -= 0.00001 if @data.length == 1
|
||
|
y_end = radius-(Math.cos(radians) * radius)
|
||
|
path = "M#{radius},#{radius} L#{x_start},#{y_start} "+
|
||
|
"A#{radius},#{radius} "+
|
||
|
"0, #{percent >= 50 ? '1' : '0'},1, "+
|
||
|
"#{x_end} #{y_end} Z"
|
||
|
wedge = @foreground.add_element( "path", {
|
||
|
"d" => path,
|
||
|
"class" => "fill#{count+1}"
|
||
|
})
|
||
|
translate = nil
|
||
|
tx = 0
|
||
|
ty = 0
|
||
|
half_percent = prev_percent + percent / 2
|
||
|
radians = half_percent * rad_mult
|
||
|
if show_shadow
|
||
|
shadow = background.add_element( "path", {
|
||
|
"d" => path,
|
||
|
"filter" => "url(#dropshadow)",
|
||
|
"style" => "fill: #ccc; stroke: none;"
|
||
|
})
|
||
|
clear = midground.add_element( "path", {
|
||
|
"d" => path,
|
||
|
"style" => "fill: #fff; stroke: none;"
|
||
|
})
|
||
|
end
|
||
|
if expanded or (expand_greatest && value == max_value)
|
||
|
tx = (Math.sin(radians) * expand_gap)
|
||
|
ty = -(Math.cos(radians) * expand_gap)
|
||
|
translate = "translate( #{tx} #{ty} )"
|
||
|
wedge.attributes["transform"] = translate
|
||
|
clear.attributes["transform"] = translate if clear
|
||
|
end
|
||
|
if show_shadow
|
||
|
shadow.attributes["transform"] =
|
||
|
"translate( #{tx+shadow_offset} #{ty+shadow_offset} )"
|
||
|
end
|
||
|
|
||
|
if show_data_labels and value != 0
|
||
|
label = ""
|
||
|
label += @config[:fields][count] if show_key_data_labels
|
||
|
label += " ["+value.to_s+"]" if show_actual_values
|
||
|
label += " "+percent.round.to_s+"%" if show_percent
|
||
|
msr = Math.sin(radians)
|
||
|
mcr = Math.cos(radians)
|
||
|
tx = radius + (msr * radius)
|
||
|
ty = radius -(mcr * radius)
|
||
|
if expanded or (expand_greatest && value == max_value)
|
||
|
tx += (msr * expand_gap)
|
||
|
ty -= (mcr * expand_gap)
|
||
|
end
|
||
|
@foreground.add_element( "text", {
|
||
|
"x" => tx.to_s,
|
||
|
"y" => ty.to_s,
|
||
|
"class" => "dataPointLabel",
|
||
|
"style" => "stroke: #fff; stroke-width: 2;"
|
||
|
}).text = label.to_s
|
||
|
@foreground.add_element( "text", {
|
||
|
"x" => tx.to_s,
|
||
|
"y" => ty.to_s,
|
||
|
"class" => "dataPointLabel",
|
||
|
}).text = label.to_s
|
||
|
end
|
||
|
prev_percent += percent
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def round val, to
|
||
|
up = 10**to.to_f
|
||
|
(val * up).to_i / up
|
||
|
end
|
||
|
def get_css
|
||
|
return <<EOL
|
||
|
.dataPointLabel{
|
||
|
fill: #000000;
|
||
|
text-anchor:middle;
|
||
|
font-size: #{datapoint_font_size}px;
|
||
|
font-family: "Arial", sans-serif;
|
||
|
font-weight: normal;
|
||
|
}
|
||
|
/* key - MUST match fill styles */
|
||
|
.key1,.fill1{
|
||
|
fill: #ff0000;
|
||
|
fill-opacity: 0.7;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key2,.fill2{
|
||
|
fill: #0000ff;
|
||
|
fill-opacity: 0.7;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key3,.fill3{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #00ff00;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key4,.fill4{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #ffcc00;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key5,.fill5{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #00ccff;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key6,.fill6{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #ff00ff;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key7,.fill7{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #00ff99;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key8,.fill8{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #ffff00;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key9,.fill9{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #cc6666;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key10,.fill10{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #663399;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key11,.fill11{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #339900;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
.key12,.fill12{
|
||
|
fill-opacity: 0.7;
|
||
|
fill: #9966FF;
|
||
|
stroke: none;
|
||
|
stroke-width: 1px;
|
||
|
}
|
||
|
EOL
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| lib/SVG/Graph/BarHorizontal.rb (kopia robocza) | ||
|---|---|---|
|
require 'rexml/document'
|
||
|
require 'SVG/Graph/BarBase'
|
||
|
|
||
|
module SVG
|
||
|
module Graph
|
||
|
# === Create presentation quality SVG horitonzal bar graphs easily
|
||
|
#
|
||
|
# = Synopsis
|
||
|
#
|
||
|
# require 'SVG/Graph/BarHorizontal'
|
||
|
#
|
||
|
# fields = %w(Jan Feb Mar)
|
||
|
# data_sales_02 = [12, 45, 21]
|
||
|
#
|
||
|
# graph = SVG::Graph::BarHorizontal.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 horitonzal 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.
|
||
|
#
|
||
|
# = Examples
|
||
|
#
|
||
|
# * http://germane-software.com/repositories/public/SVG/test/test.rb
|
||
|
#
|
||
|
# = See also
|
||
|
#
|
||
|
# * SVG::Graph::Graph
|
||
|
# * SVG::Graph::Bar
|
||
|
# * SVG::Graph::Line
|
||
|
# * SVG::Graph::Pie
|
||
|
# * SVG::Graph::Plot
|
||
|
# * SVG::Graph::TimeSeries
|
||
|
#
|
||
|
# == Author
|
||
|
#
|
||
|
# Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
|
||
|
#
|
||
|
# Copyright 2004 Sean E. Russell
|
||
|
# This software is available under the Ruby license[LICENSE.txt]
|
||
|
#
|
||
|
class BarHorizontal < BarBase
|
||
|
# In addition to the defaults set in BarBase::set_defaults, sets
|
||
|
# [rotate_y_labels] true
|
||
|
# [show_x_guidelines] true
|
||
|
# [show_y_guidelines] false
|
||
|
def set_defaults
|
||
|
super
|
||
|
init_with(
|
||
|
:rotate_y_labels => true,
|
||
|
:show_x_guidelines => true,
|
||
|
:show_y_guidelines => false
|
||
|
)
|
||
|
self.right_align = self.right_font = 1
|
||
|
end
|
||
|
|
||
|
protected
|
||
|
|
||
|
def get_x_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 get_y_labels
|
||
|
@config[:fields]
|
||
|
end
|
||
|
|
||
|
def y_label_offset( height )
|
||
|
height / -2.0
|
||
|
end
|
||
|
|
||
|
def draw_data
|
||
|
minvalue = min_value
|
||
|
fieldheight = field_height
|
||
|
|
||
|
unit_size = (@graph_width.to_f - font_size*2*right_font ) /
|
||
|
(get_x_labels.max - get_x_labels.min )
|
||
|
bargap = bar_gap ? (fieldheight < 10 ? fieldheight / 2 : 10) : 0
|
||
|
|
||
|
bar_height = fieldheight - bargap
|
||
|
bar_height /= @data.length if stack == :side
|
||