Index: app/models/issue_relation.rb
===================================================================
--- app/models/issue_relation.rb	(wersja 2924)
+++ app/models/issue_relation.rb	(kopia robocza)
@@ -23,20 +23,26 @@
   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
@@ -78,4 +84,16 @@
   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
Index: db/migrate/001_setup.rb
===================================================================
--- db/migrate/001_setup.rb	(wersja 2924)
+++ db/migrate/001_setup.rb	(kopia robocza)
@@ -21,19 +21,19 @@
   # 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
@@ -49,143 +49,143 @@
       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
@@ -193,98 +193,98 @@
       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,
@@ -296,29 +296,29 @@
                        :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
Index: lib/SVG/Graph/Pie.rb
===================================================================
--- lib/SVG/Graph/Pie.rb	(wersja 2924)
+++ lib/SVG/Graph/Pie.rb	(kopia robocza)
@@ -1,395 +1,395 @@
-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
Index: lib/SVG/Graph/BarHorizontal.rb
===================================================================
--- lib/SVG/Graph/BarHorizontal.rb	(wersja 2924)
+++ lib/SVG/Graph/BarHorizontal.rb	(kopia robocza)
@@ -1,149 +1,149 @@
-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
-        y_mod = (bar_height / 2) + (font_size / 2)
-        
-        field_count = 1
-        @config[:fields].each_index { |i|
-          dataset_count = 0
-          for dataset in @data
-            value = dataset[:data][i]
-            
-            top = @graph_height - (fieldheight * field_count)
-            top += (bar_height * dataset_count) if stack == :side
-            # cases (assume 0 = +ve):
-            #   value  min  length          left
-            #    +ve   +ve  value.abs - min minvalue.abs
-            #    +ve   -ve  value.abs - 0   minvalue.abs
-            #    -ve   -ve  value.abs - 0   minvalue.abs + value
-            length = (value.abs - (minvalue > 0 ? minvalue : 0)) * unit_size
-            left = (minvalue.abs + (value < 0 ? value : 0)) * unit_size
-
-            @graph.add_element( "rect", {
-              "x" => left.to_s,
-              "y" => top.to_s,
-              "width" => length.to_s,
-              "height" => bar_height.to_s,
-              "class" => "fill#{dataset_count+1}"
-            })
-
-            make_datapoint_text( 
-              left+length+5, top+y_mod, value, "text-anchor: start; "
-              )
-            dataset_count += 1
-          end
-          field_count += 1
-        }
-      end
-    end
-  end
-end
+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
+        y_mod = (bar_height / 2) + (font_size / 2)
+        
+        field_count = 1
+        @config[:fields].each_index { |i|
+          dataset_count = 0
+          for dataset in @data
+            value = dataset[:data][i]
+            
+            top = @graph_height - (fieldheight * field_count)
+            top += (bar_height * dataset_count) if stack == :side
+            # cases (assume 0 = +ve):
+            #   value  min  length          left
+            #    +ve   +ve  value.abs - min minvalue.abs
+            #    +ve   -ve  value.abs - 0   minvalue.abs
+            #    -ve   -ve  value.abs - 0   minvalue.abs + value
+            length = (value.abs - (minvalue > 0 ? minvalue : 0)) * unit_size
+            left = (minvalue.abs + (value < 0 ? value : 0)) * unit_size
+
+            @graph.add_element( "rect", {
+              "x" => left.to_s,
+              "y" => top.to_s,
+              "width" => length.to_s,
+              "height" => bar_height.to_s,
+              "class" => "fill#{dataset_count+1}"
+            })
+
+            make_datapoint_text( 
+              left+length+5, top+y_mod, value, "text-anchor: start; "
+              )
+            dataset_count += 1
+          end
+          field_count += 1
+        }
+      end
+    end
+  end
+end
Index: lib/SVG/Graph/Plot.rb
===================================================================
--- lib/SVG/Graph/Plot.rb	(wersja 2924)
+++ lib/SVG/Graph/Plot.rb	(kopia robocza)
@@ -1,500 +1,500 @@
-require 'SVG/Graph/Graph'
-
-module SVG
-  module Graph
-    # === For creating SVG plots of scalar data
-    # 
-    # = Synopsis
-    # 
-    #   require 'SVG/Graph/Plot'
-    # 
-    #   # Data sets are x,y pairs
-    #   # Note that multiple data sets can differ in length, and that the
-    #   # data in the datasets needn't be in order; they will be ordered
-    #   # by the plot along the X-axis.
-    #   projection = [
-    #     6, 11,    0, 5,   18, 7,   1, 11,   13, 9,   1, 2,   19, 0,   3, 13,
-    #     7, 9 
-    #   ]
-    #   actual = [
-    #     0, 18,    8, 15,    9, 4,   18, 14,   10, 2,   11, 6,  14, 12,   
-    #     15, 6,   4, 17,   2, 12
-    #   ]
-    #   
-    #   graph = SVG::Graph::Plot.new({
-    #   	:height => 500,
-    #    	:width => 300,
-    #     :key => true,
-    #     :scale_x_integers => true,
-    #     :scale_y_integerrs => true,
-    #   })
-    #   
-    #   graph.add_data({
-    #   	:data => projection
-    # 	  :title => 'Projected',
-    #   })
-    # 
-    #   graph.add_data({
-    #   	:data => actual,
-    # 	  :title => 'Actual',
-    #   })
-    #   
-    #   print graph.burn()
-    # 
-    # = Description
-    # 
-    # Produces a graph of scalar data.
-    # 
-    # This object aims to allow you to easily create high quality
-    # SVG[http://www.w3c.org/tr/svg] scalar plots. 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://www.germane-software/repositories/public/SVG/test/plot.rb
-    # 
-    # = Notes
-    # 
-    # The default stylesheet handles upto 10 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 10 data sets as they will have no style and
-    # be in black.
-    #
-    # Unlike the other types of charts, data sets must contain x,y pairs:
-    #
-    #   [ 1, 2 ]    # A data set with 1 point: (1,2)
-    #   [ 1,2, 5,6] # A data set with 2 points: (1,2) and (5,6)  
-    # 
-    # = See also
-    # 
-    # * SVG::Graph::Graph
-    # * SVG::Graph::BarHorizontal
-    # * SVG::Graph::Bar
-    # * SVG::Graph::Line
-    # * SVG::Graph::Pie
-    # * SVG::Graph::TimeSeries
-    #
-    # == Author
-    #
-    # Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
-    #
-    # Copyright 2004 Sean E. Russell
-    # This software is available under the Ruby license[LICENSE.txt]
-    #
-    class Plot < Graph
-
-      # In addition to the defaults set by Graph::initialize, sets
-      # [show_data_values] true
-      # [show_data_points] true
-      # [area_fill] false
-      # [stacked] false
-      def set_defaults
-        init_with(
-                  :show_data_values  => true,
-                  :show_data_points  => true,
-                  :area_fill         => false,
-                  :stacked           => false
-                 )
-                 self.top_align = self.right_align = self.top_font = self.right_font = 1
-      end
-
-      # Determines the scaling for the X axis divisions.
-      #
-      #   graph.scale_x_divisions = 2
-      #
-      # would cause the graph to attempt to generate labels stepped by 2; EG:
-      # 0,2,4,6,8...
-      attr_accessor :scale_x_divisions
-      # Determines the scaling for the Y axis divisions.
-      #
-      #   graph.scale_y_divisions = 0.5
-      #
-      # would cause the graph to attempt to generate labels stepped by 0.5; EG:
-      # 0, 0.5, 1, 1.5, 2, ...
-      attr_accessor :scale_y_divisions 
-      # Make the X axis labels integers
-      attr_accessor :scale_x_integers 
-      # Make the Y axis labels integers
-      attr_accessor :scale_y_integers 
-      # Fill the area under the line
-      attr_accessor :area_fill 
-      # Show a small circle on the graph where the line
-      # goes from one point to the next.
-      attr_accessor :show_data_points
-      # Set the minimum value of the X axis
-      attr_accessor :min_x_value 
-      # Set the minimum value of the Y axis
-      attr_accessor :min_y_value
-
-
-      # Adds data to the plot.  The data must be in X,Y pairs; EG
-      #   [ 1, 2 ]    # A data set with 1 point: (1,2)
-      #   [ 1,2, 5,6] # A data set with 2 points: (1,2) and (5,6)  
-      def add_data data
-        @data = [] unless @data
-
-        raise "No data provided by #{conf.inspect}" unless data[:data] and
-        data[:data].kind_of? Array
-        raise "Data supplied must be x,y pairs!  "+
-          "The data provided contained an odd set of "+
-          "data points" unless data[:data].length % 2 == 0
-        return if data[:data].length == 0
-
-        x = []
-        y = []
-        data[:data].each_index {|i|
-          (i%2 == 0 ? x : y) << data[:data][i]
-        }
-        sort( x, y )
-        data[:data] = [x,y]
-        @data << data
-      end
-
-
-      protected
-
-      def keys
-        @data.collect{ |x| x[:title] }
-      end
-
-      def calculate_left_margin
-        super
-        label_left = get_x_labels[0].to_s.length / 2 * font_size * 0.6
-        @border_left = label_left if label_left > @border_left
-      end
-
-      def calculate_right_margin
-        super
-        label_right = get_x_labels[-1].to_s.length / 2 * font_size * 0.6
-        @border_right = label_right if label_right > @border_right
-      end
-
-
-      X = 0
-      Y = 1
-      def x_range
-        max_value = @data.collect{|x| x[:data][X][-1] }.max
-        min_value = @data.collect{|x| x[:data][X][0] }.min
-        min_value = min_value<min_x_value ? min_value : min_x_value if min_x_value
-
-        range = max_value - min_value
-        right_pad = range == 0 ? 10 : range / 20.0
-        scale_range = (max_value + right_pad) - min_value
-
-        scale_division = scale_x_divisions || (scale_range / 10.0)
-
-        if scale_x_integers
-          scale_division = scale_division < 1 ? 1 : scale_division.round
-        end
-
-        [min_value, max_value, scale_division]
-      end
-
-      def get_x_values
-        min_value, max_value, scale_division = x_range
-        rv = []
-        min_value.step( max_value, scale_division ) {|v| rv << v}
-        return rv
-      end
-      alias :get_x_labels :get_x_values
-
-      def field_width
-        values = get_x_values
-        max = @data.collect{|x| x[:data][X][-1]}.max
-        dx = (max - values[-1]).to_f / (values[-1] - values[-2])
-        (@graph_width.to_f - font_size*2*right_font) /
-          (values.length + dx - right_align)
-      end
-
-
-      def y_range
-        max_value = @data.collect{|x| x[:data][Y].max }.max
-        min_value = @data.collect{|x| x[:data][Y].min }.min
-        min_value = min_value<min_y_value ? min_value : min_y_value if min_y_value
-
-        range = max_value - min_value
-        top_pad = range == 0 ? 10 : range / 20.0
-        scale_range = (max_value + top_pad) - min_value
-
-        scale_division = scale_y_divisions || (scale_range / 10.0)
-
-        if scale_y_integers
-          scale_division = scale_division < 1 ? 1 : scale_division.round
-        end
-
-        return [min_value, max_value, scale_division]
-      end
-
-      def get_y_values
-        min_value, max_value, scale_division = y_range
-        rv = []
-        min_value.step( max_value, scale_division ) {|v| rv << v}
-        return rv
-      end
-      alias :get_y_labels :get_y_values
-
-      def field_height
-        values = get_y_values
-        max = @data.collect{|x| x[:data][Y].max }.max
-        if values.length == 1
-          dx = values[-1]
-        else
-          dx = (max - values[-1]).to_f / (values[-1] - values[-2])
-        end
-        (@graph_height.to_f - font_size*2*top_font) /
-          (values.length + dx - top_align)
-      end
-
-      def draw_data
-        line = 1
-
-        x_min, x_max, x_div = x_range
-        y_min, y_max, y_div = y_range
-        x_step = (@graph_width.to_f - font_size*2) / (x_max-x_min)
-        y_step = (@graph_height.to_f -  font_size*2) / (y_max-y_min)
-
-        for data in @data
-          x_points = data[:data][X]
-          y_points = data[:data][Y]
-
-          lpath = "L"
-          x_start = 0
-          y_start = 0
-          x_points.each_index { |idx|
-            x = (x_points[idx] -  x_min) * x_step
-            y = @graph_height - (y_points[idx] -  y_min) * y_step
-            x_start, y_start = x,y if idx == 0
-            lpath << "#{x} #{y} "
-          }
-
-          if area_fill
-            @graph.add_element( "path", {
-              "d" => "M#{x_start} #@graph_height #{lpath} V#@graph_height Z",
-              "class" => "fill#{line}"
-            })
-          end
-
-          @graph.add_element( "path", {
-            "d" => "M#{x_start} #{y_start} #{lpath}",
-            "class" => "line#{line}"
-          })
-
-          if show_data_points || show_data_values
-            x_points.each_index { |idx|
-              x = (x_points[idx] -  x_min) * x_step
-              y = @graph_height - (y_points[idx] -  y_min) * y_step
-              if show_data_points
-                @graph.add_element( "circle", {
-                  "cx" => x.to_s,
-                  "cy" => y.to_s,
-                  "r" => "2.5",
-                  "class" => "dataPoint#{line}"
-                })
-                add_popup(x, y, format( x_points[idx], y_points[idx] )) if add_popups
-              end
-              make_datapoint_text( x, y-6, y_points[idx] ) if show_data_values
-            }
-          end
-          line += 1
-        end
-      end
-
-      def format x, y
-        "(#{(x * 100).to_i / 100}, #{(y * 100).to_i / 100})"
-      end
-      
-      def get_css
-        return <<EOL
-/* default line styles */
-.line1{
-	fill: none;
-	stroke: #ff0000;
-	stroke-width: 1px;	
-}
-.line2{
-	fill: none;
-	stroke: #0000ff;
-	stroke-width: 1px;	
-}
-.line3{
-	fill: none;
-	stroke: #00ff00;
-	stroke-width: 1px;	
-}
-.line4{
-	fill: none;
-	stroke: #ffcc00;
-	stroke-width: 1px;	
-}
-.line5{
-	fill: none;
-	stroke: #00ccff;
-	stroke-width: 1px;	
-}
-.line6{
-	fill: none;
-	stroke: #ff00ff;
-	stroke-width: 1px;	
-}
-.line7{
-	fill: none;
-	stroke: #00ffff;
-	stroke-width: 1px;	
-}
-.line8{
-	fill: none;
-	stroke: #ffff00;
-	stroke-width: 1px;	
-}
-.line9{
-	fill: none;
-	stroke: #ccc6666;
-	stroke-width: 1px;	
-}
-.line10{
-	fill: none;
-	stroke: #663399;
-	stroke-width: 1px;	
-}
-.line11{
-	fill: none;
-	stroke: #339900;
-	stroke-width: 1px;	
-}
-.line12{
-	fill: none;
-	stroke: #9966FF;
-	stroke-width: 1px;	
-}
-/* default fill styles */
-.fill1{
-	fill: #cc0000;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill2{
-	fill: #0000cc;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill3{
-	fill: #00cc00;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill4{
-	fill: #ffcc00;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill5{
-	fill: #00ccff;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill6{
-	fill: #ff00ff;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill7{
-	fill: #00ffff;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill8{
-	fill: #ffff00;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill9{
-	fill: #cc6666;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill10{
-	fill: #663399;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill11{
-	fill: #339900;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-.fill12{
-	fill: #9966FF;
-	fill-opacity: 0.2;
-	stroke: none;
-}
-/* default line styles */
-.key1,.dataPoint1{
-	fill: #ff0000;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key2,.dataPoint2{
-	fill: #0000ff;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key3,.dataPoint3{
-	fill: #00ff00;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key4,.dataPoint4{
-	fill: #ffcc00;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key5,.dataPoint5{
-	fill: #00ccff;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key6,.dataPoint6{
-	fill: #ff00ff;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key7,.dataPoint7{
-	fill: #00ffff;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key8,.dataPoint8{
-	fill: #ffff00;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key9,.dataPoint9{
-	fill: #cc6666;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key10,.dataPoint10{
-	fill: #663399;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key11,.dataPoint11{
-	fill: #339900;
-	stroke: none;
-	stroke-width: 1px;	
-}
-.key12,.dataPoint12{
-	fill: #9966FF;
-	stroke: none;
-	stroke-width: 1px;	
-}
-EOL
-      end
-
-    end
-  end
-end
+require 'SVG/Graph/Graph'
+
+module SVG
+  module Graph
+    # === For creating SVG plots of scalar data
+    # 
+    # = Synopsis
+    # 
+    #   require 'SVG/Graph/Plot'
+    # 
+    #   # Data sets are x,y pairs
+    #   # Note that multiple data sets can differ in length, and that the
+    #   # data in the datasets needn't be in order; they will be ordered
+    #   # by the plot along the X-axis.
+    #   projection = [
+    #     6, 11,    0, 5,   18, 7,   1, 11,   13, 9,   1, 2,   19, 0,   3, 13,
+    #     7, 9 
+    #   ]
+    #   actual = [
+    #     0, 18,    8, 15,    9, 4,   18, 14,   10, 2,   11, 6,  14, 12,   
+    #     15, 6,   4, 17,   2, 12
+    #   ]
+    #   
+    #   graph = SVG::Graph::Plot.new({
+    #   	:height => 500,
+    #    	:width => 300,
+    #     :key => true,
+    #     :scale_x_integers => true,
+    #     :scale_y_integerrs => true,
+    #   })
+    #   
+    #   graph.add_data({
+    #   	:data => projection
+    # 	  :title => 'Projected',
+    #   })
+    # 
+    #   graph.add_data({
+    #   	:data => actual,
+    # 	  :title => 'Actual',
+    #   })
+    #   
+    #   print graph.burn()
+    # 
+    # = Description
+    # 
+    # Produces a graph of scalar data.
+    # 
+    # This object aims to allow you to easily create high quality
+    # SVG[http://www.w3c.org/tr/svg] scalar plots. 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://www.germane-software/repositories/public/SVG/test/plot.rb
+    # 
+    # = Notes
+    # 
+    # The default stylesheet handles upto 10 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 10 data sets as they will have no style and
+    # be in black.
+    #
+    # Unlike the other types of charts, data sets must contain x,y pairs:
+    #
+    #   [ 1, 2 ]    # A data set with 1 point: (1,2)
+    #   [ 1,2, 5,6] # A data set with 2 points: (1,2) and (5,6)  
+    # 
+    # = See also
+    # 
+    # * SVG::Graph::Graph
+    # * SVG::Graph::BarHorizontal
+    # * SVG::Graph::Bar
+    # * SVG::Graph::Line
+    # * SVG::Graph::Pie
+    # * SVG::Graph::TimeSeries
+    #
+    # == Author
+    #
+    # Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
+    #
+    # Copyright 2004 Sean E. Russell
+    # This software is available under the Ruby license[LICENSE.txt]
+    #
+    class Plot < Graph
+
+      # In addition to the defaults set by Graph::initialize, sets
+      # [show_data_values] true
+      # [show_data_points] true
+      # [area_fill] false
+      # [stacked] false
+      def set_defaults
+        init_with(
+                  :show_data_values  => true,
+                  :show_data_points  => true,
+                  :area_fill         => false,
+                  :stacked           => false
+                 )
+                 self.top_align = self.right_align = self.top_font = self.right_font = 1
+      end
+
+      # Determines the scaling for the X axis divisions.
+      #
+      #   graph.scale_x_divisions = 2
+      #
+      # would cause the graph to attempt to generate labels stepped by 2; EG:
+      # 0,2,4,6,8...
+      attr_accessor :scale_x_divisions
+      # Determines the scaling for the Y axis divisions.
+      #
+      #   graph.scale_y_divisions = 0.5
+      #
+      # would cause the graph to attempt to generate labels stepped by 0.5; EG:
+      # 0, 0.5, 1, 1.5, 2, ...
+      attr_accessor :scale_y_divisions 
+      # Make the X axis labels integers
+      attr_accessor :scale_x_integers 
+      # Make the Y axis labels integers
+      attr_accessor :scale_y_integers 
+      # Fill the area under the line
+      attr_accessor :area_fill 
+      # Show a small circle on the graph where the line
+      # goes from one point to the next.
+      attr_accessor :show_data_points
+      # Set the minimum value of the X axis
+      attr_accessor :min_x_value 
+      # Set the minimum value of the Y axis
+      attr_accessor :min_y_value
+
+
+      # Adds data to the plot.  The data must be in X,Y pairs; EG
+      #   [ 1, 2 ]    # A data set with 1 point: (1,2)
+      #   [ 1,2, 5,6] # A data set with 2 points: (1,2) and (5,6)  
+      def add_data data
+        @data = [] unless @data
+
+        raise "No data provided by #{conf.inspect}" unless data[:data] and
+        data[:data].kind_of? Array
+        raise "Data supplied must be x,y pairs!  "+
+          "The data provided contained an odd set of "+
+          "data points" unless data[:data].length % 2 == 0
+        return if data[:data].length == 0
+
+        x = []
+        y = []
+        data[:data].each_index {|i|
+          (i%2 == 0 ? x : y) << data[:data][i]
+        }
+        sort( x, y )
+        data[:data] = [x,y]
+        @data << data
+      end
+
+
+      protected
+
+      def keys
+        @data.collect{ |x| x[:title] }
+      end
+
+      def calculate_left_margin
+        super
+        label_left = get_x_labels[0].to_s.length / 2 * font_size * 0.6
+        @border_left = label_left if label_left > @border_left
+      end
+
+      def calculate_right_margin
+        super
+        label_right = get_x_labels[-1].to_s.length / 2 * font_size * 0.6
+        @border_right = label_right if label_right > @border_right
+      end
+
+
+      X = 0
+      Y = 1
+      def x_range
+        max_value = @data.collect{|x| x[:data][X][-1] }.max
+        min_value = @data.collect{|x| x[:data][X][0] }.min
+        min_value = min_value<min_x_value ? min_value : min_x_value if min_x_value
+
+        range = max_value - min_value
+        right_pad = range == 0 ? 10 : range / 20.0
+        scale_range = (max_value + right_pad) - min_value
+
+        scale_division = scale_x_divisions || (scale_range / 10.0)
+
+        if scale_x_integers
+          scale_division = scale_division < 1 ? 1 : scale_division.round
+        end
+
+        [min_value, max_value, scale_division]
+      end
+
+      def get_x_values
+        min_value, max_value, scale_division = x_range
+        rv = []
+        min_value.step( max_value, scale_division ) {|v| rv << v}
+        return rv
+      end
+      alias :get_x_labels :get_x_values
+
+      def field_width
+        values = get_x_values
+        max = @data.collect{|x| x[:data][X][-1]}.max
+        dx = (max - values[-1]).to_f / (values[-1] - values[-2])
+        (@graph_width.to_f - font_size*2*right_font) /
+          (values.length + dx - right_align)
+      end
+
+
+      def y_range
+        max_value = @data.collect{|x| x[:data][Y].max }.max
+        min_value = @data.collect{|x| x[:data][Y].min }.min
+        min_value = min_value<min_y_value ? min_value : min_y_value if min_y_value
+
+        range = max_value - min_value
+        top_pad = range == 0 ? 10 : range / 20.0
+        scale_range = (max_value + top_pad) - min_value
+
+        scale_division = scale_y_divisions || (scale_range / 10.0)
+
+        if scale_y_integers
+          scale_division = scale_division < 1 ? 1 : scale_division.round
+        end
+
+        return [min_value, max_value, scale_division]
+      end
+
+      def get_y_values
+        min_value, max_value, scale_division = y_range
+        rv = []
+        min_value.step( max_value, scale_division ) {|v| rv << v}
+        return rv
+      end
+      alias :get_y_labels :get_y_values
+
+      def field_height
+        values = get_y_values
+        max = @data.collect{|x| x[:data][Y].max }.max
+        if values.length == 1
+          dx = values[-1]
+        else
+          dx = (max - values[-1]).to_f / (values[-1] - values[-2])
+        end
+        (@graph_height.to_f - font_size*2*top_font) /
+          (values.length + dx - top_align)
+      end
+
+      def draw_data
+        line = 1
+
+        x_min, x_max, x_div = x_range
+        y_min, y_max, y_div = y_range
+        x_step = (@graph_width.to_f - font_size*2) / (x_max-x_min)
+        y_step = (@graph_height.to_f -  font_size*2) / (y_max-y_min)
+
+        for data in @data
+          x_points = data[:data][X]
+          y_points = data[:data][Y]
+
+          lpath = "L"
+          x_start = 0
+          y_start = 0
+          x_points.each_index { |idx|
+            x = (x_points[idx] -  x_min) * x_step
+            y = @graph_height - (y_points[idx] -  y_min) * y_step
+            x_start, y_start = x,y if idx == 0
+            lpath << "#{x} #{y} "
+          }
+
+          if area_fill
+            @graph.add_element( "path", {
+              "d" => "M#{x_start} #@graph_height #{lpath} V#@graph_height Z",
+              "class" => "fill#{line}"
+            })
+          end
+
+          @graph.add_element( "path", {
+            "d" => "M#{x_start} #{y_start} #{lpath}",
+            "class" => "line#{line}"
+          })
+
+          if show_data_points || show_data_values
+            x_points.each_index { |idx|
+              x = (x_points[idx] -  x_min) * x_step
+              y = @graph_height - (y_points[idx] -  y_min) * y_step
+              if show_data_points
+                @graph.add_element( "circle", {
+                  "cx" => x.to_s,
+                  "cy" => y.to_s,
+                  "r" => "2.5",
+                  "class" => "dataPoint#{line}"
+                })
+                add_popup(x, y, format( x_points[idx], y_points[idx] )) if add_popups
+              end
+              make_datapoint_text( x, y-6, y_points[idx] ) if show_data_values
+            }
+          end
+          line += 1
+        end
+      end
+
+      def format x, y
+        "(#{(x * 100).to_i / 100}, #{(y * 100).to_i / 100})"
+      end
+      
+      def get_css
+        return <<EOL
+/* default line styles */
+.line1{
+	fill: none;
+	stroke: #ff0000;
+	stroke-width: 1px;	
+}
+.line2{
+	fill: none;
+	stroke: #0000ff;
+	stroke-width: 1px;	
+}
+.line3{
+	fill: none;
+	stroke: #00ff00;
+	stroke-width: 1px;	
+}
+.line4{
+	fill: none;
+	stroke: #ffcc00;
+	stroke-width: 1px;	
+}
+.line5{
+	fill: none;
+	stroke: #00ccff;
+	stroke-width: 1px;	
+}
+.line6{
+	fill: none;
+	stroke: #ff00ff;
+	stroke-width: 1px;	
+}
+.line7{
+	fill: none;
+	stroke: #00ffff;
+	stroke-width: 1px;	
+}
+.line8{
+	fill: none;
+	stroke: #ffff00;
+	stroke-width: 1px;	
+}
+.line9{
+	fill: none;
+	stroke: #ccc6666;
+	stroke-width: 1px;	
+}
+.line10{
+	fill: none;
+	stroke: #663399;
+	stroke-width: 1px;	
+}
+.line11{
+	fill: none;
+	stroke: #339900;
+	stroke-width: 1px;	
+}
+.line12{
+	fill: none;
+	stroke: #9966FF;
+	stroke-width: 1px;	
+}
+/* default fill styles */
+.fill1{
+	fill: #cc0000;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill2{
+	fill: #0000cc;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill3{
+	fill: #00cc00;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill4{
+	fill: #ffcc00;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill5{
+	fill: #00ccff;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill6{
+	fill: #ff00ff;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill7{
+	fill: #00ffff;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill8{
+	fill: #ffff00;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill9{
+	fill: #cc6666;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill10{
+	fill: #663399;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill11{
+	fill: #339900;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+.fill12{
+	fill: #9966FF;
+	fill-opacity: 0.2;
+	stroke: none;
+}
+/* default line styles */
+.key1,.dataPoint1{
+	fill: #ff0000;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key2,.dataPoint2{
+	fill: #0000ff;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key3,.dataPoint3{
+	fill: #00ff00;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key4,.dataPoint4{
+	fill: #ffcc00;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key5,.dataPoint5{
+	fill: #00ccff;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key6,.dataPoint6{
+	fill: #ff00ff;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key7,.dataPoint7{
+	fill: #00ffff;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key8,.dataPoint8{
+	fill: #ffff00;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key9,.dataPoint9{
+	fill: #cc6666;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key10,.dataPoint10{
+	fill: #663399;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key11,.dataPoint11{
+	fill: #339900;
+	stroke: none;
+	stroke-width: 1px;	
+}
+.key12,.dataPoint12{
+	fill: #9966FF;
+	stroke: none;
+	stroke-width: 1px;	
+}
+EOL
+      end
+
+    end
+  end
+end
Index: lib/SVG/Graph/BarBase.rb
===================================================================
--- lib/SVG/Graph/BarBase.rb	(wersja 2924)
+++ lib/SVG/Graph/BarBase.rb	(kopia robocza)
@@ -1,139 +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
+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
Index: lib/SVG/Graph/Graph.rb
===================================================================
--- lib/SVG/Graph/Graph.rb	(wersja 2924)
+++ lib/SVG/Graph/Graph.rb	(kopia robocza)
@@ -1,978 +1,978 @@
-begin
-  require 'zlib'
-  @@__have_zlib = true
-rescue
-  @@__have_zlib = false
-end
-
-require 'rexml/document'
-
-module SVG
-  module Graph
-    VERSION = '@ANT_VERSION@'
-
-    # === Base object for generating SVG Graphs
-    # 
-    # == Synopsis
-    #
-    # This class is only used as a superclass of specialized charts.  Do not
-    # attempt to use this class directly, unless creating a new chart type.
-    #
-    # For examples of how to subclass this class, see the existing specific
-    # subclasses, such as SVG::Graph::Pie.
-    #
-    # == Examples
-    #
-    # For examples of how to use this package, see either the test files, or
-    # the documentation for the specific class you want to use.
-    #
-    # * file:test/plot.rb
-    # * file:test/single.rb
-    # * file:test/test.rb
-    # * file:test/timeseries.rb
-    # 
-    # == Description
-    # 
-    # This package should be used as a base for creating SVG graphs.
-    #
-    # == Acknowledgements
-    #
-    # Leo Lapworth for creating the SVG::TT::Graph package which this Ruby
-    # port is based on.
-    #
-    # Stephen Morgan for creating the TT template and SVG.
-    # 
-    # == See
-    #
-    # * SVG::Graph::BarHorizontal
-    # * 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 Graph
-      include REXML
-
-      # Initialize the graph object with the graph settings.  You won't
-      # instantiate this class directly; see the subclass for options.
-      # [width] 500
-      # [height] 300
-      # [show_x_guidelines] false
-      # [show_y_guidelines] true
-      # [show_data_values] true
-      # [min_scale_value] 0
-      # [show_x_labels] true
-      # [stagger_x_labels] false
-      # [rotate_x_labels] false
-      # [step_x_labels] 1
-      # [step_include_first_x_label] true
-      # [show_y_labels] true
-      # [rotate_y_labels] false
-      # [scale_integers] false
-      # [show_x_title] false
-      # [x_title] 'X Field names'
-      # [show_y_title] false
-      # [y_title_text_direction] :bt
-      # [y_title] 'Y Scale'
-      # [show_graph_title] false
-      # [graph_title] 'Graph Title'
-      # [show_graph_subtitle] false
-      # [graph_subtitle] 'Graph Sub Title'
-      # [key] true,
-      # [key_position] :right, # bottom or righ
-      # [font_size] 12
-      # [title_font_size] 16
-      # [subtitle_font_size] 14
-      # [x_label_font_size] 12
-      # [x_title_font_size] 14
-      # [y_label_font_size] 12
-      # [y_title_font_size] 14
-      # [key_font_size] 10
-      # [no_css] false
-      # [add_popups] false
-      def initialize( config )
-        @config = config
-
-        self.top_align = self.top_font = self.right_align = self.right_font = 0
-
-        init_with({
-          :width                => 500,
-          :height                => 300,
-          :show_x_guidelines    => false,
-          :show_y_guidelines    => true,
-          :show_data_values     => true,
-
-#          :min_scale_value      => 0,
-
-          :show_x_labels        => true,
-          :stagger_x_labels     => false,
-          :rotate_x_labels      => false,
-          :step_x_labels        => 1,
-          :step_include_first_x_label => true,
-
-          :show_y_labels        => true,
-          :rotate_y_labels      => false,
-          :stagger_y_labels     => false,
-          :scale_integers       => false,
-
-          :show_x_title         => false,
-          :x_title              => 'X Field names',
-
-          :show_y_title         => false,
-          :y_title_text_direction => :bt,
-          :y_title              => 'Y Scale',
-
-          :show_graph_title      => false,
-          :graph_title          => 'Graph Title',
-          :show_graph_subtitle  => false,
-          :graph_subtitle        => 'Graph Sub Title',
-          :key                  => true, 
-          :key_position          => :right, # bottom or right
-
-          :font_size            =>12,
-          :title_font_size      =>16,
-          :subtitle_font_size   =>14,
-          :x_label_font_size    =>12,
-          :x_title_font_size    =>14,
-          :y_label_font_size    =>12,
-          :y_title_font_size    =>14,
-          :key_font_size        =>10,
-          
-          :no_css               =>false,
-          :add_popups           =>false,
-        })
-
-				set_defaults if methods.include? "set_defaults"
-
-        init_with config
-      end
-
-      
-      # This method allows you do add data to the graph object.
-      # It can be called several times to add more data sets in.
-      #
-      #   data_sales_02 = [12, 45, 21];
-      #   
-      #   graph.add_data({
-      #     :data => data_sales_02,
-      #     :title => 'Sales 2002'
-      #   })
-      def add_data conf
-        @data = [] unless defined? @data
-
-        if conf[:data] and conf[:data].kind_of? Array
-          @data << conf
-        else
-          raise "No data provided by #{conf.inspect}"
-        end
-      end
-
-
-      # This method removes all data from the object so that you can
-      # reuse it to create a new graph but with the same config options.
-      #
-      #   graph.clear_data
-      def clear_data 
-        @data = []
-      end
-
-
-      # This method processes the template with the data and
-      # config which has been set and returns the resulting SVG.
-      #
-      # This method will croak unless at least one data set has
-      # been added to the graph object.
-      #
-      #   print graph.burn
-      def burn
-        raise "No data available" unless @data.size > 0
-        
-        calculations if methods.include? 'calculations'
-
-        start_svg
-        calculate_graph_dimensions
-        @foreground = Element.new( "g" )
-        draw_graph
-        draw_titles
-        draw_legend
-        draw_data
-        @graph.add_element( @foreground )
-        style
-
-        data = ""
-        @doc.write( data, 0 )
-
-        if @config[:compress]
-          if @@__have_zlib
-            inp, out = IO.pipe
-            gz = Zlib::GzipWriter.new( out )
-            gz.write data
-            gz.close
-            data = inp.read
-          else
-            data << "<!-- Ruby Zlib not available for SVGZ -->";
-          end
-        end
-        
-        return data
-      end
-
-
-      #   Set the height of the graph box, this is the total height
-      #   of the SVG box created - not the graph it self which auto
-      #   scales to fix the space.
-      attr_accessor :height
-      #   Set the width of the graph box, this is the total width
-      #   of the SVG box created - not the graph it self which auto
-      #   scales to fix the space.
-      attr_accessor :width
-      #   Set the path to an external stylesheet, set to '' if
-      #   you want to revert back to using the defaut internal version.
-      #
-      #   To create an external stylesheet create a graph using the
-      #   default internal version and copy the stylesheet section to
-      #   an external file and edit from there.
-      attr_accessor :style_sheet
-      #   (Bool) Show the value of each element of data on the graph
-      attr_accessor :show_data_values
-      #   The point at which the Y axis starts, defaults to '0',
-      #   if set to nil it will default to the minimum data value.
-      attr_accessor :min_scale_value
-      #   Whether to show labels on the X axis or not, defaults
-      #   to true, set to false if you want to turn them off.
-      attr_accessor :show_x_labels
-      #   This puts the X labels at alternative levels so if they
-      #   are long field names they will not overlap so easily.
-      #   Default it false, to turn on set to true.
-      attr_accessor :stagger_x_labels
-      #   This puts the Y labels at alternative levels so if they
-      #   are long field names they will not overlap so easily.
-      #   Default it false, to turn on set to true.
-      attr_accessor :stagger_y_labels
-      #   This turns the X axis labels by 90 degrees.
-      #   Default it false, to turn on set to true.
-      attr_accessor :rotate_x_labels
-      #   This turns the Y axis labels by 90 degrees.
-      #   Default it false, to turn on set to true.
-      attr_accessor :rotate_y_labels
-      #   How many "steps" to use between displayed X axis labels,
-      #   a step of one means display every label, a step of two results
-      #   in every other label being displayed (label <gap> label <gap> label),
-      #   a step of three results in every third label being displayed
-      #   (label <gap> <gap> label <gap> <gap> label) and so on.
-      attr_accessor :step_x_labels
-      #   Whether to (when taking "steps" between X axis labels) step from 
-      #   the first label (i.e. always include the first label) or step from
-      #   the X axis origin (i.e. start with a gap if step_x_labels is greater
-      #   than one).
-      attr_accessor :step_include_first_x_label
-      #   Whether to show labels on the Y axis or not, defaults
-      #   to true, set to false if you want to turn them off.
-      attr_accessor :show_y_labels
-      #   Ensures only whole numbers are used as the scale divisions.
-      #   Default it false, to turn on set to true. This has no effect if 
-      #   scale divisions are less than 1.
-      attr_accessor :scale_integers
-      #   This defines the gap between markers on the Y axis,
-      #   default is a 10th of the max_value, e.g. you will have
-      #   10 markers on the Y axis. NOTE: do not set this too
-      #   low - you are limited to 999 markers, after that the
-      #   graph won't generate.
-      attr_accessor :scale_divisions
-      #   Whether to show the title under the X axis labels,
-      #   default is false, set to true to show.
-      attr_accessor :show_x_title
-      #   What the title under X axis should be, e.g. 'Months'.
-      attr_accessor :x_title
-      #   Whether to show the title under the Y axis labels,
-      #   default is false, set to true to show.
-      attr_accessor :show_y_title
-      #   Aligns writing mode for Y axis label. 
-      #   Defaults to :bt (Bottom to Top).
-      #   Change to :tb (Top to Bottom) to reverse.
-      attr_accessor :y_title_text_direction
-      #   What the title under Y axis should be, e.g. 'Sales in thousands'.
-      attr_accessor :y_title
-      #   Whether to show a title on the graph, defaults
-      #   to false, set to true to show.
-      attr_accessor :show_graph_title
-      #   What the title on the graph should be.
-      attr_accessor :graph_title
-      #   Whether to show a subtitle on the graph, defaults
-      #   to false, set to true to show.
-      attr_accessor :show_graph_subtitle
-      #   What the subtitle on the graph should be.
-      attr_accessor :graph_subtitle
-      #   Whether to show a key, defaults to false, set to
-      #   true if you want to show it.
-      attr_accessor :key
-      #   Where the key should be positioned, defaults to
-      #   :right, set to :bottom if you want to move it.
-      attr_accessor :key_position
-      # Set the font size (in points) of the data point labels
-      attr_accessor :font_size
-      # Set the font size of the X axis labels
-      attr_accessor :x_label_font_size
-      # Set the font size of the X axis title
-      attr_accessor :x_title_font_size
-      # Set the font size of the Y axis labels
-      attr_accessor :y_label_font_size
-      # Set the font size of the Y axis title
-      attr_accessor :y_title_font_size
-      # Set the title font size
-      attr_accessor :title_font_size
-      # Set the subtitle font size
-      attr_accessor :subtitle_font_size
-      # Set the key font size
-      attr_accessor :key_font_size
-      # Show guidelines for the X axis
-      attr_accessor :show_x_guidelines
-      # Show guidelines for the Y axis
-      attr_accessor :show_y_guidelines
-      # Do not use CSS if set to true.  Many SVG viewers do not support CSS, but
-      # not using CSS can result in larger SVGs as well as making it impossible to
-      # change colors after the chart is generated.  Defaults to false.
-      attr_accessor :no_css
-      # Add popups for the data points on some graphs
-      attr_accessor :add_popups
-
-
-      protected
-
-      def sort( *arrys )
-        sort_multiple( arrys )
-      end
-
-      # Overwrite configuration options with supplied options.  Used
-      # by subclasses.
-      def init_with config
-        config.each { |key, value|
-          self.send( key.to_s+"=", value ) if methods.include? key.to_s
-        }
-      end
-
-      attr_accessor :top_align, :top_font, :right_align, :right_font
-
-      KEY_BOX_SIZE = 12
-
-      # Override this (and call super) to change the margin to the left
-      # of the plot area.  Results in @border_left being set.
-      def calculate_left_margin
-        @border_left = 7
-        # Check for Y labels
-        max_y_label_height_px = rotate_y_labels ? 
-          y_label_font_size :
-          get_y_labels.max{|a,b| 
-            a.to_s.length<=>b.to_s.length
-          }.to_s.length * y_label_font_size * 0.6
-        @border_left += max_y_label_height_px if show_y_labels
-        @border_left += max_y_label_height_px + 10 if stagger_y_labels
-        @border_left += y_title_font_size + 5 if show_y_title
-      end
-
-
-      # Calculates the width of the widest Y label.  This will be the
-      # character height if the Y labels are rotated
-      def max_y_label_width_px
-        return font_size if rotate_y_labels
-      end
-
-
-      # Override this (and call super) to change the margin to the right
-      # of the plot area.  Results in @border_right being set.
-      def calculate_right_margin
-        @border_right = 7
-        if key and key_position == :right
-          val = keys.max { |a,b| a.length <=> b.length }
-          @border_right += val.length * key_font_size * 0.6 
-          @border_right += KEY_BOX_SIZE
-          @border_right += 10    # Some padding around the box
-        end
-      end
-
-
-      # Override this (and call super) to change the margin to the top
-      # of the plot area.  Results in @border_top being set.
-      def calculate_top_margin
-        @border_top = 5
-        @border_top += title_font_size if show_graph_title
-        @border_top += 5
-        @border_top += subtitle_font_size if show_graph_subtitle
-      end
-
-
-      # Adds pop-up point information to a graph.
-      def add_popup( x, y, label )
-        txt_width = label.length * font_size * 0.6 + 10
-        tx = (x+txt_width > width ? x-5 : x+5)
-        t = @foreground.add_element( "text", {
-          "x" => tx.to_s,
-          "y" => (y - font_size).to_s,
-          "visibility" => "hidden",
-        })
-        t.attributes["style"] = "fill: #000; "+
-          (x+txt_width > width ? "text-anchor: end;" : "text-anchor: start;")
-        t.text = label.to_s
-        t.attributes["id"] = t.object_id.to_s
-
-        @foreground.add_element( "circle", {
-          "cx" => x.to_s,
-          "cy" => y.to_s,
-          "r" => "10",
-          "style" => "opacity: 0",
-          "onmouseover" => 
-            "document.getElementById(#{t.object_id}).setAttribute('visibility', 'visible' )",
-          "onmouseout" => 
-            "document.getElementById(#{t.object_id}).setAttribute('visibility', 'hidden' )",
-        })
-
-      end
-
-      
-      # Override this (and call super) to change the margin to the bottom
-      # of the plot area.  Results in @border_bottom being set.
-      def calculate_bottom_margin
-        @border_bottom = 7
-        if key and key_position == :bottom
-          @border_bottom += @data.size * (font_size + 5)
-          @border_bottom += 10
-        end
-        if show_x_labels
-		  max_x_label_height_px = (not rotate_x_labels) ? 
-            x_label_font_size :
-            get_x_labels.max{|a,b| 
-              a.to_s.length<=>b.to_s.length
-            }.to_s.length * x_label_font_size * 0.6
-          @border_bottom += max_x_label_height_px
-          @border_bottom += max_x_label_height_px + 10 if stagger_x_labels
-        end
-        @border_bottom += x_title_font_size + 5 if show_x_title
-      end
-
-
-      # Draws the background, axis, and labels.
-      def draw_graph
-        @graph = @root.add_element( "g", {
-          "transform" => "translate( #@border_left #@border_top )"
-        })
-
-        # Background
-        @graph.add_element( "rect", {
-          "x" => "0",
-          "y" => "0",
-          "width" => @graph_width.to_s,
-          "height" => @graph_height.to_s,
-          "class" => "graphBackground"
-        })
-
-        # Axis
-        @graph.add_element( "path", {
-          "d" => "M 0 0 v#@graph_height",
-          "class" => "axis",
-          "id" => "xAxis"
-        })
-        @graph.add_element( "path", {
-          "d" => "M 0 #@graph_height h#@graph_width",
-          "class" => "axis",
-          "id" => "yAxis"
-        })
-
-        draw_x_labels
-        draw_y_labels
-      end
-
-
-      # Where in the X area the label is drawn
-      # Centered in the field, should be width/2.  Start, 0.
-      def x_label_offset( width )
-        0
-      end
-
-      def make_datapoint_text( x, y, value, style="" )
-        if show_data_values
-          @foreground.add_element( "text", {
-            "x" => x.to_s,
-            "y" => y.to_s,
-            "class" => "dataPointLabel",
-            "style" => "#{style} stroke: #fff; stroke-width: 2;"
-          }).text = value.to_s
-          text = @foreground.add_element( "text", {
-            "x" => x.to_s,
-            "y" => y.to_s,
-            "class" => "dataPointLabel"
-          })
-          text.text = value.to_s
-          text.attributes["style"] = style if style.length > 0
-        end
-      end
-
-
-      # Draws the X axis labels
-      def draw_x_labels
-        stagger = x_label_font_size + 5
-        if show_x_labels
-          label_width = field_width
-
-          count = 0
-          for label in get_x_labels
-            if step_include_first_x_label == true then
-              step = count % step_x_labels
-            else
-              step = (count + 1) % step_x_labels
-            end
-
-            if step == 0 then
-              text = @graph.add_element( "text" )
-              text.attributes["class"] = "xAxisLabels"
-              text.text = label.to_s
-
-              x = count * label_width + x_label_offset( label_width )
-              y = @graph_height + x_label_font_size + 3
-              t = 0 - (font_size / 2)
-
-              if stagger_x_labels and count % 2 == 1
-                y += stagger
-                @graph.add_element( "path", {
-                  "d" => "M#{x} #@graph_height v#{stagger}",
-                  "class" => "staggerGuideLine"
-                })
-              end
-
-              text.attributes["x"] = x.to_s
-              text.attributes["y"] = y.to_s
-              if rotate_x_labels
-                text.attributes["transform"] = 
-                  "rotate( 90 #{x} #{y-x_label_font_size} )"+
-                  " translate( 0 -#{x_label_font_size/4} )"
-                text.attributes["style"] = "text-anchor: start"
-              else
-                text.attributes["style"] = "text-anchor: middle"
-              end
-            end
-
-            draw_x_guidelines( label_width, count ) if show_x_guidelines
-            count += 1
-          end
-        end
-      end
-
-
-      # Where in the Y area the label is drawn
-      # Centered in the field, should be width/2.  Start, 0.
-      def y_label_offset( height )
-        0
-      end
-
-
-      def field_width
-        (@graph_width.to_f - font_size*2*right_font) /
-           (get_x_labels.length - right_align)
-      end
-
-
-      def field_height
-        (@graph_height.to_f - font_size*2*top_font) /
-           (get_y_labels.length - top_align)
-      end
-
-
-      # Draws the Y axis labels
-      def draw_y_labels
-        stagger = y_label_font_size + 5
-        if show_y_labels
-          label_height = field_height
-
-          count = 0
-          y_offset = @graph_height + y_label_offset( label_height )
-          y_offset += font_size/1.2 unless rotate_y_labels
-          for label in get_y_labels
-            y = y_offset - (label_height * count)
-            x = rotate_y_labels ? 0 : -3
-
-            if stagger_y_labels and count % 2 == 1
-              x -= stagger
-              @graph.add_element( "path", {
-                "d" => "M#{x} #{y} h#{stagger}",
-                "class" => "staggerGuideLine"
-              })
-            end
-
-            text = @graph.add_element( "text", {
-              "x" => x.to_s,
-              "y" => y.to_s,
-              "class" => "yAxisLabels"
-            })
-            text.text = label.to_s
-            if rotate_y_labels
-              text.attributes["transform"] = "translate( -#{font_size} 0 ) "+
-                "rotate( 90 #{x} #{y} ) "
-              text.attributes["style"] = "text-anchor: middle"
-            else
-              text.attributes["y"] = (y - (y_label_font_size/2)).to_s
-              text.attributes["style"] = "text-anchor: end"
-            end
-            draw_y_guidelines( label_height, count ) if show_y_guidelines
-            count += 1
-          end
-        end
-      end
-
-
-      # Draws the X axis guidelines
-      def draw_x_guidelines( label_height, count )
-        if count != 0
-          @graph.add_element( "path", {
-            "d" => "M#{label_height*count} 0 v#@graph_height",
-            "class" => "guideLines"
-          })
-        end
-      end
-
-
-      # Draws the Y axis guidelines
-      def draw_y_guidelines( label_height, count )
-        if count != 0
-          @graph.add_element( "path", {
-            "d" => "M0 #{@graph_height-(label_height*count)} h#@graph_width",
-            "class" => "guideLines"
-          })
-        end
-      end
-
-
-      # Draws the graph title and subtitle
-      def draw_titles
-        if show_graph_title
-          @root.add_element( "text", {
-            "x" => (width / 2).to_s,
-            "y" => (title_font_size).to_s,
-            "class" => "mainTitle"
-          }).text = graph_title.to_s
-        end
-
-        if show_graph_subtitle
-          y_subtitle = show_graph_title ? 
-            title_font_size + 10 :
-            subtitle_font_size
-          @root.add_element("text", {
-            "x" => (width / 2).to_s,
-            "y" => (y_subtitle).to_s,
-            "class" => "subTitle"
-          }).text = graph_subtitle.to_s
-        end
-
-        if show_x_title
-          y = @graph_height + @border_top + x_title_font_size
-          if show_x_labels
-            y += x_label_font_size + 5 if stagger_x_labels
-            y += x_label_font_size + 5
-          end
-          x = width / 2
-
-          @root.add_element("text", {
-            "x" => x.to_s,
-            "y" => y.to_s,
-            "class" => "xAxisTitle",
-          }).text = x_title.to_s
-        end
-
-        if show_y_title
-          x = y_title_font_size + (y_title_text_direction==:bt ? 3 : -3)
-          y = height / 2
-
-          text = @root.add_element("text", {
-            "x" => x.to_s,
-            "y" => y.to_s,
-            "class" => "yAxisTitle",
-          })
-          text.text = y_title.to_s
-          if y_title_text_direction == :bt
-            text.attributes["transform"] = "rotate( -90, #{x}, #{y} )"
-          else
-            text.attributes["transform"] = "rotate( 90, #{x}, #{y} )"
-          end
-        end
-      end
-
-      def keys 
-        return @data.collect{ |d| d[:title] }
-      end
-
-      # Draws the legend on the graph
-      def draw_legend
-        if key
-          group = @root.add_element( "g" )
-
-          key_count = 0
-          for key_name in keys
-            y_offset = (KEY_BOX_SIZE * key_count) + (key_count * 5)
-            group.add_element( "rect", {
-              "x" => 0.to_s,
-              "y" => y_offset.to_s,
-              "width" => KEY_BOX_SIZE.to_s,
-              "height" => KEY_BOX_SIZE.to_s,
-              "class" => "key#{key_count+1}"
-            })
-            group.add_element( "text", {
-              "x" => (KEY_BOX_SIZE + 5).to_s,
-              "y" => (y_offset + KEY_BOX_SIZE).to_s,
-              "class" => "keyText"
-            }).text = key_name.to_s
-            key_count += 1
-          end
-
-          case key_position
-          when :right
-            x_offset = @graph_width + @border_left + 10
-            y_offset = @border_top + 20
-          when :bottom
-            x_offset = @border_left + 20
-            y_offset = @border_top + @graph_height + 5
-            if show_x_labels
-			  max_x_label_height_px = (not rotate_x_labels) ? 
-				x_label_font_size :
-				get_x_labels.max{|a,b| 
-				  a.to_s.length<=>b.to_s.length
-				}.to_s.length * x_label_font_size * 0.6
-                x_label_font_size
-              y_offset += max_x_label_height_px
-              y_offset += max_x_label_height_px + 5 if stagger_x_labels
-            end
-            y_offset += x_title_font_size + 5 if show_x_title
-          end
-          group.attributes["transform"] = "translate(#{x_offset} #{y_offset})"
-        end
-      end
-
-
-      private
-
-      def sort_multiple( arrys, lo=0, hi=arrys[0].length-1 )
-        if lo < hi
-          p = partition(arrys,lo,hi)
-          sort_multiple(arrys, lo, p-1)
-          sort_multiple(arrys, p+1, hi)
-        end
-        arrys 
-      end
-
-      def partition( arrys, lo, hi )
-        p = arrys[0][lo]
-        l = lo
-        z = lo+1
-        while z <= hi
-          if arrys[0][z] < p
-            l += 1
-            arrys.each { |arry| arry[z], arry[l] = arry[l], arry[z] }
-          end
-          z += 1
-        end
-        arrys.each { |arry| arry[lo], arry[l] = arry[l], arry[lo] }
-        l
-      end
-
-      def style
-        if no_css
-          styles = parse_css
-          @root.elements.each("//*[@class]") { |el|
-            cl = el.attributes["class"]
-            style = styles[cl]
-            style += el.attributes["style"] if el.attributes["style"]
-            el.attributes["style"] = style
-          }
-        end
-      end
-
-      def parse_css
-        css = get_style
-        rv = {}
-        while css =~ /^(\.(\w+)(?:\s*,\s*\.\w+)*)\s*\{/m
-          names_orig = names = $1
-          css = $'
-          css =~ /([^}]+)\}/m
-          content = $1
-          css = $'
-
-          nms = []
-          while names =~ /^\s*,?\s*\.(\w+)/
-            nms << $1
-            names = $'
-          end
-
-          content = content.tr( "\n\t", " ")
-          for name in nms
-            current = rv[name]
-            current = current ? current+"; "+content : content
-            rv[name] = current.strip.squeeze(" ")
-          end
-        end
-        return rv
-      end
-
-
-      # Override and place code to add defs here
-      def add_defs defs
-      end
-
-
-      def start_svg
-        # Base document
-        @doc = Document.new
-        @doc << XMLDecl.new
-        @doc << DocType.new( %q{svg PUBLIC "-//W3C//DTD SVG 1.0//EN" } +
-          %q{"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"} )
-        if style_sheet && style_sheet != ''
-          @doc << Instruction.new( "xml-stylesheet",
-            %Q{href="#{style_sheet}" type="text/css"} )
-        end
-        @root = @doc.add_element( "svg", {
-          "width" => width.to_s,
-          "height" => height.to_s,
-          "viewBox" => "0 0 #{width} #{height}",
-          "xmlns" => "http://www.w3.org/2000/svg",
-          "xmlns:xlink" => "http://www.w3.org/1999/xlink",
-          "xmlns:a3" => "http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/",
-          "a3:scriptImplementation" => "Adobe"
-        })
-        @root << Comment.new( " "+"\\"*66 )
-        @root << Comment.new( " Created with SVG::Graph " )
-        @root << Comment.new( " SVG::Graph by Sean E. Russell " )
-        @root << Comment.new( " Losely based on SVG::TT::Graph for Perl by"+
-        " Leo Lapworth & Stephan Morgan " )
-        @root << Comment.new( " "+"/"*66 )
-
-        defs = @root.add_element( "defs" )
-        add_defs defs
-        if not(style_sheet && style_sheet != '') and !no_css
-          @root << Comment.new(" include default stylesheet if none specified ")
-          style = defs.add_element( "style", {"type"=>"text/css"} )
-          style << CData.new( get_style )
-        end
-
-        @root << Comment.new( "SVG Background" )
-        @root.add_element( "rect", {
-          "width" => width.to_s,
-          "height" => height.to_s,
-          "x" => "0",
-          "y" => "0",
-          "class" => "svgBackground"
-        })
-      end
-
-
-      def calculate_graph_dimensions
-        calculate_left_margin
-        calculate_right_margin
-        calculate_bottom_margin
-        calculate_top_margin
-        @graph_width = width - @border_left - @border_right
-        @graph_height = height - @border_top - @border_bottom
-      end
-
-      def get_style
-        return <<EOL
-/* Copy from here for external style sheet */
-.svgBackground{
-  fill:#ffffff;
-}
-.graphBackground{
-  fill:#f0f0f0;
-}
-
-/* graphs titles */
-.mainTitle{
-  text-anchor: middle;
-  fill: #000000;
-  font-size: #{title_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-.subTitle{
-  text-anchor: middle;
-  fill: #999999;
-  font-size: #{subtitle_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-
-.axis{
-  stroke: #000000;
-  stroke-width: 1px;
-}
-
-.guideLines{
-  stroke: #666666;
-  stroke-width: 1px;
-  stroke-dasharray: 5 5;
-}
-
-.xAxisLabels{
-  text-anchor: middle;
-  fill: #000000;
-  font-size: #{x_label_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-
-.yAxisLabels{
-  text-anchor: end;
-  fill: #000000;
-  font-size: #{y_label_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-
-.xAxisTitle{
-  text-anchor: middle;
-  fill: #ff0000;
-  font-size: #{x_title_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-
-.yAxisTitle{
-  fill: #ff0000;
-  text-anchor: middle;
-  font-size: #{y_title_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-
-.dataPointLabel{
-  fill: #000000;
-  text-anchor:middle;
-  font-size: 10px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-
-.staggerGuideLine{
-  fill: none;
-  stroke: #000000;
-  stroke-width: 0.5px;  
-}
-
-#{get_css}
-
-.keyText{
-  fill: #000000;
-  text-anchor:start;
-  font-size: #{key_font_size}px;
-  font-family: "Arial", sans-serif;
-  font-weight: normal;
-}
-/* End copy for external style sheet */
-EOL
-      end
-
-    end
-  end
-end
+begin
+  require 'zlib'
+  @@__have_zlib = true
+rescue
+  @@__have_zlib = false
+end
+
+require 'rexml/document'
+
+module SVG
+  module Graph
+    VERSION = '@ANT_VERSION@'
+
+    # === Base object for generating SVG Graphs
+    # 
+    # == Synopsis
+    #
+    # This class is only used as a superclass of specialized charts.  Do not
+    # attempt to use this class directly, unless creating a new chart type.
+    #
+    # For examples of how to subclass this class, see the existing specific
+    # subclasses, such as SVG::Graph::Pie.
+    #
+    # == Examples
+    #
+    # For examples of how to use this package, see either the test files, or
+    # the documentation for the specific class you want to use.
+    #
+    # * file:test/plot.rb
+    # * file:test/single.rb
+    # * file:test/test.rb
+    # * file:test/timeseries.rb
+    # 
+    # == Description
+    # 
+    # This package should be used as a base for creating SVG graphs.
+    #
+    # == Acknowledgements
+    #
+    # Leo Lapworth for creating the SVG::TT::Graph package which this Ruby
+    # port is based on.
+    #
+    # Stephen Morgan for creating the TT template and SVG.
+    # 
+    # == See
+    #
+    # * SVG::Graph::BarHorizontal
+    # * 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 Graph
+      include REXML
+
+      # Initialize the graph object with the graph settings.  You won't
+      # instantiate this class directly; see the subclass for options.
+      # [width] 500
+      # [height] 300
+      # [show_x_guidelines] false
+      # [show_y_guidelines] true
+      # [show_data_values] true
+      # [min_scale_value] 0
+      # [show_x_labels] true
+      # [stagger_x_labels] false
+      # [rotate_x_labels] false
+      # [step_x_labels] 1
+      # [step_include_first_x_label] true
+      # [show_y_labels] true
+      # [rotate_y_labels] false
+      # [scale_integers] false
+      # [show_x_title] false
+      # [x_title] 'X Field names'
+      # [show_y_title] false
+      # [y_title_text_direction] :bt
+      # [y_title] 'Y Scale'
+      # [show_graph_title] false
+      # [graph_title] 'Graph Title'
+      # [show_graph_subtitle] false
+      # [graph_subtitle] 'Graph Sub Title'
+      # [key] true,
+      # [key_position] :right, # bottom or righ
+      # [font_size] 12
+      # [title_font_size] 16
+      # [subtitle_font_size] 14
+      # [x_label_font_size] 12
+      # [x_title_font_size] 14
+      # [y_label_font_size] 12
+      # [y_title_font_size] 14
+      # [key_font_size] 10
+      # [no_css] false
+      # [add_popups] false
+      def initialize( config )
+        @config = config
+
+        self.top_align = self.top_font = self.right_align = self.right_font = 0
+
+        init_with({
+          :width                => 500,
+          :height                => 300,
+          :show_x_guidelines    => false,
+          :show_y_guidelines    => true,
+          :show_data_values     => true,
+
+#          :min_scale_value      => 0,
+
+          :show_x_labels        => true,
+          :stagger_x_labels     => false,
+          :rotate_x_labels      => false,
+          :step_x_labels        => 1,
+          :step_include_first_x_label => true,
+
+          :show_y_labels        => true,
+          :rotate_y_labels      => false,
+          :stagger_y_labels     => false,
+          :scale_integers       => false,
+
+          :show_x_title         => false,
+          :x_title              => 'X Field names',
+
+          :show_y_title         => false,
+          :y_title_text_direction => :bt,
+          :y_title              => 'Y Scale',
+
+          :show_graph_title      => false,
+          :graph_title          => 'Graph Title',
+          :show_graph_subtitle  => false,
+          :graph_subtitle        => 'Graph Sub Title',
+          :key                  => true, 
+          :key_position          => :right, # bottom or right
+
+          :font_size            =>12,
+          :title_font_size      =>16,
+          :subtitle_font_size   =>14,
+          :x_label_font_size    =>12,
+          :x_title_font_size    =>14,
+          :y_label_font_size    =>12,
+          :y_title_font_size    =>14,
+          :key_font_size        =>10,
+          
+          :no_css               =>false,
+          :add_popups           =>false,
+        })
+
+				set_defaults if methods.include? "set_defaults"
+
+        init_with config
+      end
+
+      
+      # This method allows you do add data to the graph object.
+      # It can be called several times to add more data sets in.
+      #
+      #   data_sales_02 = [12, 45, 21];
+      #   
+      #   graph.add_data({
+      #     :data => data_sales_02,
+      #     :title => 'Sales 2002'
+      #   })
+      def add_data conf
+        @data = [] unless defined? @data
+
+        if conf[:data] and conf[:data].kind_of? Array
+          @data << conf
+        else
+          raise "No data provided by #{conf.inspect}"
+        end
+      end
+
+
+      # This method removes all data from the object so that you can
+      # reuse it to create a new graph but with the same config options.
+      #
+      #   graph.clear_data
+      def clear_data 
+        @data = []
+      end
+
+
+      # This method processes the template with the data and
+      # config which has been set and returns the resulting SVG.
+      #
+      # This method will croak unless at least one data set has
+      # been added to the graph object.
+      #
+      #   print graph.burn
+      def burn
+        raise "No data available" unless @data.size > 0
+        
+        calculations if methods.include? 'calculations'
+
+        start_svg
+        calculate_graph_dimensions
+        @foreground = Element.new( "g" )
+        draw_graph
+        draw_titles
+        draw_legend
+        draw_data
+        @graph.add_element( @foreground )
+        style
+
+        data = ""
+        @doc.write( data, 0 )
+
+        if @config[:compress]
+          if @@__have_zlib
+            inp, out = IO.pipe
+            gz = Zlib::GzipWriter.new( out )
+            gz.write data
+            gz.close
+            data = inp.read
+          else
+            data << "<!-- Ruby Zlib not available for SVGZ -->";
+          end
+        end
+        
+        return data
+      end
+
+
+      #   Set the height of the graph box, this is the total height
+      #   of the SVG box created - not the graph it self which auto
+      #   scales to fix the space.
+      attr_accessor :height
+      #   Set the width of the graph box, this is the total width
+      #   of the SVG box created - not the graph it self which auto
+      #   scales to fix the space.
+      attr_accessor :width
+      #   Set the path to an external stylesheet, set to '' if
+      #   you want to revert back to using the defaut internal version.
+      #
+      #   To create an external stylesheet create a graph using the
+      #   default internal version and copy the stylesheet section to
+      #   an external file and edit from there.
+      attr_accessor :style_sheet
+      #   (Bool) Show the value of each element of data on the graph
+      attr_accessor :show_data_values
+      #   The point at which the Y axis starts, defaults to '0',
+      #   if set to nil it will default to the minimum data value.
+      attr_accessor :min_scale_value
+      #   Whether to show labels on the X axis or not, defaults
+      #   to true, set to false if you want to turn them off.
+      attr_accessor :show_x_labels
+      #   This puts the X labels at alternative levels so if they
+      #   are long field names they will not overlap so easily.
+      #   Default it false, to turn on set to true.
+      attr_accessor :stagger_x_labels
+      #   This puts the Y labels at alternative levels so if they
+      #   are long field names they will not overlap so easily.
+      #   Default it false, to turn on set to true.
+      attr_accessor :stagger_y_labels
+      #   This turns the X axis labels by 90 degrees.
+      #   Default it false, to turn on set to true.
+      attr_accessor :rotate_x_labels
+      #   This turns the Y axis labels by 90 degrees.
+      #   Default it false, to turn on set to true.
+      attr_accessor :rotate_y_labels
+      #   How many "steps" to use between displayed X axis labels,
+      #   a step of one means display every label, a step of two results
+      #   in every other label being displayed (label <gap> label <gap> label),
+      #   a step of three results in every third label being displayed
+      #   (label <gap> <gap> label <gap> <gap> label) and so on.
+      attr_accessor :step_x_labels
+      #   Whether to (when taking "steps" between X axis labels) step from 
+      #   the first label (i.e. always include the first label) or step from
+      #   the X axis origin (i.e. start with a gap if step_x_labels is greater
+      #   than one).
+      attr_accessor :step_include_first_x_label
+      #   Whether to show labels on the Y axis or not, defaults
+      #   to true, set to false if you want to turn them off.
+      attr_accessor :show_y_labels
+      #   Ensures only whole numbers are used as the scale divisions.
+      #   Default it false, to turn on set to true. This has no effect if 
+      #   scale divisions are less than 1.
+      attr_accessor :scale_integers
+      #   This defines the gap between markers on the Y axis,
+      #   default is a 10th of the max_value, e.g. you will have
+      #   10 markers on the Y axis. NOTE: do not set this too
+      #   low - you are limited to 999 markers, after that the
+      #   graph won't generate.
+      attr_accessor :scale_divisions
+      #   Whether to show the title under the X axis labels,
+      #   default is false, set to true to show.
+      attr_accessor :show_x_title
+      #   What the title under X axis should be, e.g. 'Months'.
+      attr_accessor :x_title
+      #   Whether to show the title under the Y axis labels,
+      #   default is false, set to true to show.
+      attr_accessor :show_y_title
+      #   Aligns writing mode for Y axis label. 
+      #   Defaults to :bt (Bottom to Top).
+      #   Change to :tb (Top to Bottom) to reverse.
+      attr_accessor :y_title_text_direction
+      #   What the title under Y axis should be, e.g. 'Sales in thousands'.
+      attr_accessor :y_title
+      #   Whether to show a title on the graph, defaults
+      #   to false, set to true to show.
+      attr_accessor :show_graph_title
+      #   What the title on the graph should be.
+      attr_accessor :graph_title
+      #   Whether to show a subtitle on the graph, defaults
+      #   to false, set to true to show.
+      attr_accessor :show_graph_subtitle
+      #   What the subtitle on the graph should be.
+      attr_accessor :graph_subtitle
+      #   Whether to show a key, defaults to false, set to
+      #   true if you want to show it.
+      attr_accessor :key
+      #   Where the key should be positioned, defaults to
+      #   :right, set to :bottom if you want to move it.
+      attr_accessor :key_position
+      # Set the font size (in points) of the data point labels
+      attr_accessor :font_size
+      # Set the font size of the X axis labels
+      attr_accessor :x_label_font_size
+      # Set the font size of the X axis title
+      attr_accessor :x_title_font_size
+      # Set the font size of the Y axis labels
+      attr_accessor :y_label_font_size
+      # Set the font size of the Y axis title
+      attr_accessor :y_title_font_size
+      # Set the title font size
+      attr_accessor :title_font_size
+      # Set the subtitle font size
+      attr_accessor :subtitle_font_size
+      # Set the key font size
+      attr_accessor :key_font_size
+      # Show guidelines for the X axis
+      attr_accessor :show_x_guidelines
+      # Show guidelines for the Y axis
+      attr_accessor :show_y_guidelines
+      # Do not use CSS if set to true.  Many SVG viewers do not support CSS, but
+      # not using CSS can result in larger SVGs as well as making it impossible to
+      # change colors after the chart is generated.  Defaults to false.
+      attr_accessor :no_css
+      # Add popups for the data points on some graphs
+      attr_accessor :add_popups
+
+
+      protected
+
+      def sort( *arrys )
+        sort_multiple( arrys )
+      end
+
+      # Overwrite configuration options with supplied options.  Used
+      # by subclasses.
+      def init_with config
+        config.each { |key, value|
+          self.send( key.to_s+"=", value ) if methods.include? key.to_s
+        }
+      end
+
+      attr_accessor :top_align, :top_font, :right_align, :right_font
+
+      KEY_BOX_SIZE = 12
+
+      # Override this (and call super) to change the margin to the left
+      # of the plot area.  Results in @border_left being set.
+      def calculate_left_margin
+        @border_left = 7
+        # Check for Y labels
+        max_y_label_height_px = rotate_y_labels ? 
+          y_label_font_size :
+          get_y_labels.max{|a,b| 
+            a.to_s.length<=>b.to_s.length
+          }.to_s.length * y_label_font_size * 0.6
+        @border_left += max_y_label_height_px if show_y_labels
+        @border_left += max_y_label_height_px + 10 if stagger_y_labels
+        @border_left += y_title_font_size + 5 if show_y_title
+      end
+
+
+      # Calculates the width of the widest Y label.  This will be the
+      # character height if the Y labels are rotated
+      def max_y_label_width_px
+        return font_size if rotate_y_labels
+      end
+
+
+      # Override this (and call super) to change the margin to the right
+      # of the plot area.  Results in @border_right being set.
+      def calculate_right_margin
+        @border_right = 7
+        if key and key_position == :right
+          val = keys.max { |a,b| a.length <=> b.length }
+          @border_right += val.length * key_font_size * 0.6 
+          @border_right += KEY_BOX_SIZE
+          @border_right += 10    # Some padding around the box
+        end
+      end
+
+
+      # Override this (and call super) to change the margin to the top
+      # of the plot area.  Results in @border_top being set.
+      def calculate_top_margin
+        @border_top = 5
+        @border_top += title_font_size if show_graph_title
+        @border_top += 5
+        @border_top += subtitle_font_size if show_graph_subtitle
+      end
+
+
+      # Adds pop-up point information to a graph.
+      def add_popup( x, y, label )
+        txt_width = label.length * font_size * 0.6 + 10
+        tx = (x+txt_width > width ? x-5 : x+5)
+        t = @foreground.add_element( "text", {
+          "x" => tx.to_s,
+          "y" => (y - font_size).to_s,
+          "visibility" => "hidden",
+        })
+        t.attributes["style"] = "fill: #000; "+
+          (x+txt_width > width ? "text-anchor: end;" : "text-anchor: start;")
+        t.text = label.to_s
+        t.attributes["id"] = t.object_id.to_s
+
+        @foreground.add_element( "circle", {
+          "cx" => x.to_s,
+          "cy" => y.to_s,
+          "r" => "10",
+          "style" => "opacity: 0",
+          "onmouseover" => 
+            "document.getElementById(#{t.object_id}).setAttribute('visibility', 'visible' )",
+          "onmouseout" => 
+            "document.getElementById(#{t.object_id}).setAttribute('visibility', 'hidden' )",
+        })
+
+      end
+
+      
+      # Override this (and call super) to change the margin to the bottom
+      # of the plot area.  Results in @border_bottom being set.
+      def calculate_bottom_margin
+        @border_bottom = 7
+        if key and key_position == :bottom
+          @border_bottom += @data.size * (font_size + 5)
+          @border_bottom += 10
+        end
+        if show_x_labels
+		  max_x_label_height_px = (not rotate_x_labels) ? 
+            x_label_font_size :
+            get_x_labels.max{|a,b| 
+              a.to_s.length<=>b.to_s.length
+            }.to_s.length * x_label_font_size * 0.6
+          @border_bottom += max_x_label_height_px
+          @border_bottom += max_x_label_height_px + 10 if stagger_x_labels
+        end
+        @border_bottom += x_title_font_size + 5 if show_x_title
+      end
+
+
+      # Draws the background, axis, and labels.
+      def draw_graph
+        @graph = @root.add_element( "g", {
+          "transform" => "translate( #@border_left #@border_top )"
+        })
+
+        # Background
+        @graph.add_element( "rect", {
+          "x" => "0",
+          "y" => "0",
+          "width" => @graph_width.to_s,
+          "height" => @graph_height.to_s,
+          "class" => "graphBackground"
+        })
+
+        # Axis
+        @graph.add_element( "path", {
+          "d" => "M 0 0 v#@graph_height",
+          "class" => "axis",
+          "id" => "xAxis"
+        })
+        @graph.add_element( "path", {
+          "d" => "M 0 #@graph_height h#@graph_width",
+          "class" => "axis",
+          "id" => "yAxis"
+        })
+
+        draw_x_labels
+        draw_y_labels
+      end
+
+
+      # Where in the X area the label is drawn
+      # Centered in the field, should be width/2.  Start, 0.
+      def x_label_offset( width )
+        0
+      end
+
+      def make_datapoint_text( x, y, value, style="" )
+        if show_data_values
+          @foreground.add_element( "text", {
+            "x" => x.to_s,
+            "y" => y.to_s,
+            "class" => "dataPointLabel",
+            "style" => "#{style} stroke: #fff; stroke-width: 2;"
+          }).text = value.to_s
+          text = @foreground.add_element( "text", {
+            "x" => x.to_s,
+            "y" => y.to_s,
+            "class" => "dataPointLabel"
+          })
+          text.text = value.to_s
+          text.attributes["style"] = style if style.length > 0
+        end
+      end
+
+
+      # Draws the X axis labels
+      def draw_x_labels
+        stagger = x_label_font_size + 5
+        if show_x_labels
+          label_width = field_width
+
+          count = 0
+          for label in get_x_labels
+            if step_include_first_x_label == true then
+              step = count % step_x_labels
+            else
+              step = (count + 1) % step_x_labels
+            end
+
+            if step == 0 then
+              text = @graph.add_element( "text" )
+              text.attributes["class"] = "xAxisLabels"
+              text.text = label.to_s
+
+              x = count * label_width + x_label_offset( label_width )
+              y = @graph_height + x_label_font_size + 3
+              t = 0 - (font_size / 2)
+
+              if stagger_x_labels and count % 2 == 1
+                y += stagger
+                @graph.add_element( "path", {
+                  "d" => "M#{x} #@graph_height v#{stagger}",
+                  "class" => "staggerGuideLine"
+                })
+              end
+
+              text.attributes["x"] = x.to_s
+              text.attributes["y"] = y.to_s
+              if rotate_x_labels
+                text.attributes["transform"] = 
+                  "rotate( 90 #{x} #{y-x_label_font_size} )"+
+                  " translate( 0 -#{x_label_font_size/4} )"
+                text.attributes["style"] = "text-anchor: start"
+              else
+                text.attributes["style"] = "text-anchor: middle"
+              end
+            end
+
+            draw_x_guidelines( label_width, count ) if show_x_guidelines
+            count += 1
+          end
+        end
+      end
+
+
+      # Where in the Y area the label is drawn
+      # Centered in the field, should be width/2.  Start, 0.
+      def y_label_offset( height )
+        0
+      end
+
+
+      def field_width
+        (@graph_width.to_f - font_size*2*right_font) /
+           (get_x_labels.length - right_align)
+      end
+
+
+      def field_height
+        (@graph_height.to_f - font_size*2*top_font) /
+           (get_y_labels.length - top_align)
+      end
+
+
+      # Draws the Y axis labels
+      def draw_y_labels
+        stagger = y_label_font_size + 5
+        if show_y_labels
+          label_height = field_height
+
+          count = 0
+          y_offset = @graph_height + y_label_offset( label_height )
+          y_offset += font_size/1.2 unless rotate_y_labels
+          for label in get_y_labels
+            y = y_offset - (label_height * count)
+            x = rotate_y_labels ? 0 : -3
+
+            if stagger_y_labels and count % 2 == 1
+              x -= stagger
+              @graph.add_element( "path", {
+                "d" => "M#{x} #{y} h#{stagger}",
+                "class" => "staggerGuideLine"
+              })
+            end
+
+            text = @graph.add_element( "text", {
+              "x" => x.to_s,
+              "y" => y.to_s,
+              "class" => "yAxisLabels"
+            })
+            text.text = label.to_s
+            if rotate_y_labels
+              text.attributes["transform"] = "translate( -#{font_size} 0 ) "+
+                "rotate( 90 #{x} #{y} ) "
+              text.attributes["style"] = "text-anchor: middle"
+            else
+              text.attributes["y"] = (y - (y_label_font_size/2)).to_s
+              text.attributes["style"] = "text-anchor: end"
+            end
+            draw_y_guidelines( label_height, count ) if show_y_guidelines
+            count += 1
+          end
+        end
+      end
+
+
+      # Draws the X axis guidelines
+      def draw_x_guidelines( label_height, count )
+        if count != 0
+          @graph.add_element( "path", {
+            "d" => "M#{label_height*count} 0 v#@graph_height",
+            "class" => "guideLines"
+          })
+        end
+      end
+
+
+      # Draws the Y axis guidelines
+      def draw_y_guidelines( label_height, count )
+        if count != 0
+          @graph.add_element( "path", {
+            "d" => "M0 #{@graph_height-(label_height*count)} h#@graph_width",
+            "class" => "guideLines"
+          })
+        end
+      end
+
+
+      # Draws the graph title and subtitle
+      def draw_titles
+        if show_graph_title
+          @root.add_element( "text", {
+            "x" => (width / 2).to_s,
+            "y" => (title_font_size).to_s,
+            "class" => "mainTitle"
+          }).text = graph_title.to_s
+        end
+
+        if show_graph_subtitle
+          y_subtitle = show_graph_title ? 
+            title_font_size + 10 :
+            subtitle_font_size
+          @root.add_element("text", {
+            "x" => (width / 2).to_s,
+            "y" => (y_subtitle).to_s,
+            "class" => "subTitle"
+          }).text = graph_subtitle.to_s
+        end
+
+        if show_x_title
+          y = @graph_height + @border_top + x_title_font_size
+          if show_x_labels
+            y += x_label_font_size + 5 if stagger_x_labels
+            y += x_label_font_size + 5
+          end
+          x = width / 2
+
+          @root.add_element("text", {
+            "x" => x.to_s,
+            "y" => y.to_s,
+            "class" => "xAxisTitle",
+          }).text = x_title.to_s
+        end
+
+        if show_y_title
+          x = y_title_font_size + (y_title_text_direction==:bt ? 3 : -3)
+          y = height / 2
+
+          text = @root.add_element("text", {
+            "x" => x.to_s,
+            "y" => y.to_s,
+            "class" => "yAxisTitle",
+          })
+          text.text = y_title.to_s
+          if y_title_text_direction == :bt
+            text.attributes["transform"] = "rotate( -90, #{x}, #{y} )"
+          else
+            text.attributes["transform"] = "rotate( 90, #{x}, #{y} )"
+          end
+        end
+      end
+
+      def keys 
+        return @data.collect{ |d| d[:title] }
+      end
+
+      # Draws the legend on the graph
+      def draw_legend
+        if key
+          group = @root.add_element( "g" )
+
+          key_count = 0
+          for key_name in keys
+            y_offset = (KEY_BOX_SIZE * key_count) + (key_count * 5)
+            group.add_element( "rect", {
+              "x" => 0.to_s,
+              "y" => y_offset.to_s,
+              "width" => KEY_BOX_SIZE.to_s,
+              "height" => KEY_BOX_SIZE.to_s,
+              "class" => "key#{key_count+1}"
+            })
+            group.add_element( "text", {
+              "x" => (KEY_BOX_SIZE + 5).to_s,
+              "y" => (y_offset + KEY_BOX_SIZE).to_s,
+              "class" => "keyText"
+            }).text = key_name.to_s
+            key_count += 1
+          end
+
+          case key_position
+          when :right
+            x_offset = @graph_width + @border_left + 10
+            y_offset = @border_top + 20
+          when :bottom
+            x_offset = @border_left + 20
+            y_offset = @border_top + @graph_height + 5
+            if show_x_labels
+			  max_x_label_height_px = (not rotate_x_labels) ? 
+				x_label_font_size :
+				get_x_labels.max{|a,b| 
+				  a.to_s.length<=>b.to_s.length
+				}.to_s.length * x_label_font_size * 0.6
+                x_label_font_size
+              y_offset += max_x_label_height_px
+              y_offset += max_x_label_height_px + 5 if stagger_x_labels
+            end
+            y_offset += x_title_font_size + 5 if show_x_title
+          end
+          group.attributes["transform"] = "translate(#{x_offset} #{y_offset})"
+        end
+      end
+
+
+      private
+
+      def sort_multiple( arrys, lo=0, hi=arrys[0].length-1 )
+        if lo < hi
+          p = partition(arrys,lo,hi)
+          sort_multiple(arrys, lo, p-1)
+          sort_multiple(arrys, p+1, hi)
+        end
+        arrys 
+      end
+
+      def partition( arrys, lo, hi )
+        p = arrys[0][lo]
+        l = lo
+        z = lo+1
+        while z <= hi
+          if arrys[0][z] < p
+            l += 1
+            arrys.each { |arry| arry[z], arry[l] = arry[l], arry[z] }
+          end
+          z += 1
+        end
+        arrys.each { |arry| arry[lo], arry[l] = arry[l], arry[lo] }
+        l
+      end
+
+      def style
+        if no_css
+          styles = parse_css
+          @root.elements.each("//*[@class]") { |el|
+            cl = el.attributes["class"]
+            style = styles[cl]
+            style += el.attributes["style"] if el.attributes["style"]
+            el.attributes["style"] = style
+          }
+        end
+      end
+
+      def parse_css
+        css = get_style
+        rv = {}
+        while css =~ /^(\.(\w+)(?:\s*,\s*\.\w+)*)\s*\{/m
+          names_orig = names = $1
+          css = $'
+          css =~ /([^}]+)\}/m
+          content = $1
+          css = $'
+
+          nms = []
+          while names =~ /^\s*,?\s*\.(\w+)/
+            nms << $1
+            names = $'
+          end
+
+          content = content.tr( "\n\t", " ")
+          for name in nms
+            current = rv[name]
+            current = current ? current+"; "+content : content
+            rv[name] = current.strip.squeeze(" ")
+          end
+        end
+        return rv
+      end
+
+
+      # Override and place code to add defs here
+      def add_defs defs
+      end
+
+
+      def start_svg
+        # Base document
+        @doc = Document.new
+        @doc << XMLDecl.new
+        @doc << DocType.new( %q{svg PUBLIC "-//W3C//DTD SVG 1.0//EN" } +
+          %q{"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"} )
+        if style_sheet && style_sheet != ''
+          @doc << Instruction.new( "xml-stylesheet",
+            %Q{href="#{style_sheet}" type="text/css"} )
+        end
+        @root = @doc.add_element( "svg", {
+          "width" => width.to_s,
+          "height" => height.to_s,
+          "viewBox" => "0 0 #{width} #{height}",
+          "xmlns" => "http://www.w3.org/2000/svg",
+          "xmlns:xlink" => "http://www.w3.org/1999/xlink",
+          "xmlns:a3" => "http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/",
+          "a3:scriptImplementation" => "Adobe"
+        })
+        @root << Comment.new( " "+"\\"*66 )
+        @root << Comment.new( " Created with SVG::Graph " )
+        @root << Comment.new( " SVG::Graph by Sean E. Russell " )
+        @root << Comment.new( " Losely based on SVG::TT::Graph for Perl by"+
+        " Leo Lapworth & Stephan Morgan " )
+        @root << Comment.new( " "+"/"*66 )
+
+        defs = @root.add_element( "defs" )
+        add_defs defs
+        if not(style_sheet && style_sheet != '') and !no_css
+          @root << Comment.new(" include default stylesheet if none specified ")
+          style = defs.add_element( "style", {"type"=>"text/css"} )
+          style << CData.new( get_style )
+        end
+
+        @root << Comment.new( "SVG Background" )
+        @root.add_element( "rect", {
+          "width" => width.to_s,
+          "height" => height.to_s,
+          "x" => "0",
+          "y" => "0",
+          "class" => "svgBackground"
+        })
+      end
+
+
+      def calculate_graph_dimensions
+        calculate_left_margin
+        calculate_right_margin
+        calculate_bottom_margin
+        calculate_top_margin
+        @graph_width = width - @border_left - @border_right
+        @graph_height = height - @border_top - @border_bottom
+      end
+
+      def get_style
+        return <<EOL
+/* Copy from here for external style sheet */
+.svgBackground{
+  fill:#ffffff;
+}
+.graphBackground{
+  fill:#f0f0f0;
+}
+
+/* graphs titles */
+.mainTitle{
+  text-anchor: middle;
+  fill: #000000;
+  font-size: #{title_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+.subTitle{
+  text-anchor: middle;
+  fill: #999999;
+  font-size: #{subtitle_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+
+.axis{
+  stroke: #000000;
+  stroke-width: 1px;
+}
+
+.guideLines{
+  stroke: #666666;
+  stroke-width: 1px;
+  stroke-dasharray: 5 5;
+}
+
+.xAxisLabels{
+  text-anchor: middle;
+  fill: #000000;
+  font-size: #{x_label_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+
+.yAxisLabels{
+  text-anchor: end;
+  fill: #000000;
+  font-size: #{y_label_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+
+.xAxisTitle{
+  text-anchor: middle;
+  fill: #ff0000;
+  font-size: #{x_title_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+
+.yAxisTitle{
+  fill: #ff0000;
+  text-anchor: middle;
+  font-size: #{y_title_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+
+.dataPointLabel{
+  fill: #000000;
+  text-anchor:middle;
+  font-size: 10px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+
+.staggerGuideLine{
+  fill: none;
+  stroke: #000000;
+  stroke-width: 0.5px;  
+}
+
+#{get_css}
+
+.keyText{
+  fill: #000000;
+  text-anchor:start;
+  font-size: #{key_font_size}px;
+  font-family: "Arial", sans-serif;
+  font-weight: normal;
+}
+/* End copy for external style sheet */
+EOL
+      end
+
+    end
+  end
+end
Index: lib/SVG/Graph/Bar.rb
===================================================================
--- lib/SVG/Graph/Bar.rb	(wersja 2924)
+++ lib/SVG/Graph/Bar.rb	(kopia robocza)
@@ -1,148 +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
+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
Index: lib/SVG/Graph/TimeSeries.rb
===================================================================
--- lib/SVG/Graph/TimeSeries.rb	(wersja 2924)
+++ lib/SVG/Graph/TimeSeries.rb	(kopia robocza)
@@ -1,241 +1,241 @@
-require 'SVG/Graph/Plot'
-require 'parsedate'
-
-module SVG
-  module Graph
-    # === For creating SVG plots of scalar temporal data
-    # 
-    # = Synopsis
-    # 
-    #   require 'SVG/Graph/TimeSeriess'
-    # 
-    #   # Data sets are x,y pairs
-    #   data1 = ["6/17/72", 11,    "1/11/72", 7,    "4/13/04 17:31", 11, 
-    #           "9/11/01", 9,    "9/1/85", 2,    "9/1/88", 1,    "1/15/95", 13]
-    #   data2 = ["8/1/73", 18,    "3/1/77", 15,    "10/1/98", 4, 
-    #           "5/1/02", 14,    "3/1/95", 6,    "8/1/91", 12,    "12/1/87", 6, 
-    #           "5/1/84", 17,    "10/1/80", 12]
-    #
-    #   graph = SVG::Graph::TimeSeries.new( {
-    #     :width => 640,
-    #     :height => 480,
-    #     :graph_title => title,
-    #     :show_graph_title => true,
-    #     :no_css => true,
-    #     :key => true,
-    #     :scale_x_integers => true,
-    #     :scale_y_integers => true,
-    #     :min_x_value => 0,
-    #     :min_y_value => 0,
-    #     :show_data_labels => true,
-    #     :show_x_guidelines => true,
-    #     :show_x_title => true,
-    #     :x_title => "Time",
-    #     :show_y_title => true,
-    #     :y_title => "Ice Cream Cones",
-    #     :y_title_text_direction => :bt,
-    #     :stagger_x_labels => true,
-    #     :x_label_format => "%m/%d/%y",
-    #   })
-    #   
-    #   graph.add_data({
-    #   	:data => projection
-    # 	  :title => 'Projected',
-    #   })
-    # 
-    #   graph.add_data({
-    #   	:data => actual,
-    # 	  :title => 'Actual',
-    #   })
-    #   
-    #   print graph.burn()
-    #
-    # = Description
-    # 
-    # Produces a graph of temporal scalar data.
-    # 
-    # = Examples
-    #
-    # http://www.germane-software/repositories/public/SVG/test/timeseries.rb
-    # 
-    # = Notes
-    # 
-    # The default stylesheet handles upto 10 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 10 data sets as they will have no style and
-    # be in black.
-    #
-    # Unlike the other types of charts, data sets must contain x,y pairs:
-    #
-    #   [ "12:30", 2 ]          # A data set with 1 point: ("12:30",2)
-    #   [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and 
-    #                           #                           ("14:20",6)  
-    #
-    # Note that multiple data sets within the same chart can differ in length, 
-    # and that the data in the datasets needn't be in order; they will be ordered
-    # by the plot along the X-axis.
-    # 
-    # The dates must be parseable by ParseDate, but otherwise can be
-    # any order of magnitude (seconds within the hour, or years)
-    # 
-    # = See also
-    # 
-    # * SVG::Graph::Graph
-    # * SVG::Graph::BarHorizontal
-    # * SVG::Graph::Bar
-    # * SVG::Graph::Line
-    # * SVG::Graph::Pie
-    # * SVG::Graph::Plot
-    #
-    # == Author
-    #
-    # Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
-    #
-    # Copyright 2004 Sean E. Russell
-    # This software is available under the Ruby license[LICENSE.txt]
-    #
-    class TimeSeries < Plot
-      # In addition to the defaults set by Graph::initialize and
-      # Plot::set_defaults, sets:
-      # [x_label_format] '%Y-%m-%d %H:%M:%S'
-      # [popup_format]  '%Y-%m-%d %H:%M:%S'
-      def set_defaults
-        super
-        init_with(
-          #:max_time_span     => '',
-          :x_label_format     => '%Y-%m-%d %H:%M:%S',
-          :popup_format       => '%Y-%m-%d %H:%M:%S'
-        )
-      end
-
-      # The format string use do format the X axis labels.
-      # See Time::strformat
-      attr_accessor :x_label_format
-      # Use this to set the spacing between dates on the axis.  The value
-      # must be of the form 
-      # "\d+ ?(days|weeks|months|years|hours|minutes|seconds)?"
-      # 
-      # EG:
-      #
-      #   graph.timescale_divisions = "2 weeks"
-      #
-      # will cause the chart to try to divide the X axis up into segments of
-      # two week periods.
-      attr_accessor :timescale_divisions
-      # The formatting used for the popups.  See x_label_format
-      attr_accessor :popup_format
-
-      # Add data to the plot.
-      #
-      #   d1 = [ "12:30", 2 ]          # A data set with 1 point: ("12:30",2)
-      #   d2 = [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and 
-      #                                #                           ("14:20",6)  
-      #   graph.add_data( 
-      #     :data => d1,
-      #     :title => 'One'
-      #   )
-      #   graph.add_data(
-      #     :data => d2,
-      #     :title => 'Two'
-      #   )
-      #
-      # Note that the data must be in time,value pairs, and that the date format
-      # may be any date that is parseable by ParseDate.
-      def add_data data
-        @data = [] unless @data
-       
-        raise "No data provided by #{@data.inspect}" unless data[:data] and
-                                                    data[:data].kind_of? Array
-        raise "Data supplied must be x,y pairs!  "+
-          "The data provided contained an odd set of "+
-          "data points" unless data[:data].length % 2 == 0
-        return if data[:data].length == 0
-
-
-        x = []
-        y = []
-        data[:data].each_index {|i|
-          if i%2 == 0
-            arr = ParseDate.parsedate( data[:data][i] )
-            t = Time.local( *arr[0,6].compact )
-            x << t.to_i
-          else
-            y << data[:data][i]
-          end
-        }
-        sort( x, y )
-        data[:data] = [x,y]
-        @data << data
-      end
-
-
-      protected
-
-      def min_x_value=(value)
-        arr = ParseDate.parsedate( value )
-        @min_x_value = Time.local( *arr[0,6].compact ).to_i
-      end
-
-
-      def format x, y
-        Time.at( x ).strftime( popup_format )
-      end
-
-      def get_x_labels
-        get_x_values.collect { |v| Time.at(v).strftime( x_label_format ) }
-      end
-      
-      private
-      def get_x_values
-        rv = []
-        min, max, scale_division = x_range
-        if timescale_divisions
-          timescale_divisions =~ /(\d+) ?(day|week|month|year|hour|minute|second)?/
-          division_units = $2 ? $2 : "day"
-          amount = $1.to_i
-          if amount
-            step =  nil
-            case division_units
-            when "month"
-              cur = min
-              while cur < max
-                rv << cur
-                arr = Time.at( cur ).to_a
-                arr[4] += amount
-                if arr[4] > 12
-                  arr[5] += (arr[4] / 12).to_i
-                  arr[4] = (arr[4] % 12)
-                end
-                cur = Time.local(*arr).to_i
-              end
-            when "year"
-              cur = min
-              while cur < max
-                rv << cur
-                arr = Time.at( cur ).to_a
-                arr[5] += amount
-                cur = Time.local(*arr).to_i
-              end
-            when "week"
-              step = 7 * 24 * 60 * 60 * amount
-            when "day"
-              step = 24 * 60 * 60 * amount
-            when "hour"
-              step = 60 * 60 * amount
-            when "minute"
-              step = 60 * amount
-            when "second"
-              step = amount
-            end
-            min.step( max, step ) {|v| rv << v} if step
-
-            return rv
-          end
-        end
-        min.step( max, scale_division ) {|v| rv << v}
-        return rv
-      end
-    end
-  end
-end
+require 'SVG/Graph/Plot'
+require 'parsedate'
+
+module SVG
+  module Graph
+    # === For creating SVG plots of scalar temporal data
+    # 
+    # = Synopsis
+    # 
+    #   require 'SVG/Graph/TimeSeriess'
+    # 
+    #   # Data sets are x,y pairs
+    #   data1 = ["6/17/72", 11,    "1/11/72", 7,    "4/13/04 17:31", 11, 
+    #           "9/11/01", 9,    "9/1/85", 2,    "9/1/88", 1,    "1/15/95", 13]
+    #   data2 = ["8/1/73", 18,    "3/1/77", 15,    "10/1/98", 4, 
+    #           "5/1/02", 14,    "3/1/95", 6,    "8/1/91", 12,    "12/1/87", 6, 
+    #           "5/1/84", 17,    "10/1/80", 12]
+    #
+    #   graph = SVG::Graph::TimeSeries.new( {
+    #     :width => 640,
+    #     :height => 480,
+    #     :graph_title => title,
+    #     :show_graph_title => true,
+    #     :no_css => true,
+    #     :key => true,
+    #     :scale_x_integers => true,
+    #     :scale_y_integers => true,
+    #     :min_x_value => 0,
+    #     :min_y_value => 0,
+    #     :show_data_labels => true,
+    #     :show_x_guidelines => true,
+    #     :show_x_title => true,
+    #     :x_title => "Time",
+    #     :show_y_title => true,
+    #     :y_title => "Ice Cream Cones",
+    #     :y_title_text_direction => :bt,
+    #     :stagger_x_labels => true,
+    #     :x_label_format => "%m/%d/%y",
+    #   })
+    #   
+    #   graph.add_data({
+    #   	:data => projection
+    # 	  :title => 'Projected',
+    #   })
+    # 
+    #   graph.add_data({
+    #   	:data => actual,
+    # 	  :title => 'Actual',
+    #   })
+    #   
+    #   print graph.burn()
+    #
+    # = Description
+    # 
+    # Produces a graph of temporal scalar data.
+    # 
+    # = Examples
+    #
+    # http://www.germane-software/repositories/public/SVG/test/timeseries.rb
+    # 
+    # = Notes
+    # 
+    # The default stylesheet handles upto 10 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 10 data sets as they will have no style and
+    # be in black.
+    #
+    # Unlike the other types of charts, data sets must contain x,y pairs:
+    #
+    #   [ "12:30", 2 ]          # A data set with 1 point: ("12:30",2)
+    #   [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and 
+    #                           #                           ("14:20",6)  
+    #
+    # Note that multiple data sets within the same chart can differ in length, 
+    # and that the data in the datasets needn't be in order; they will be ordered
+    # by the plot along the X-axis.
+    # 
+    # The dates must be parseable by ParseDate, but otherwise can be
+    # any order of magnitude (seconds within the hour, or years)
+    # 
+    # = See also
+    # 
+    # * SVG::Graph::Graph
+    # * SVG::Graph::BarHorizontal
+    # * SVG::Graph::Bar
+    # * SVG::Graph::Line
+    # * SVG::Graph::Pie
+    # * SVG::Graph::Plot
+    #
+    # == Author
+    #
+    # Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
+    #
+    # Copyright 2004 Sean E. Russell
+    # This software is available under the Ruby license[LICENSE.txt]
+    #
+    class TimeSeries < Plot
+      # In addition to the defaults set by Graph::initialize and
+      # Plot::set_defaults, sets:
+      # [x_label_format] '%Y-%m-%d %H:%M:%S'
+      # [popup_format]  '%Y-%m-%d %H:%M:%S'
+      def set_defaults
+        super
+        init_with(
+          #:max_time_span     => '',
+          :x_label_format     => '%Y-%m-%d %H:%M:%S',
+          :popup_format       => '%Y-%m-%d %H:%M:%S'
+        )
+      end
+
+      # The format string use do format the X axis labels.
+      # See Time::strformat
+      attr_accessor :x_label_format
+      # Use this to set the spacing between dates on the axis.  The value
+      # must be of the form 
+      # "\d+ ?(days|weeks|months|years|hours|minutes|seconds)?"
+      # 
+      # EG:
+      #
+      #   graph.timescale_divisions = "2 weeks"
+      #
+      # will cause the chart to try to divide the X axis up into segments of
+      # two week periods.
+      attr_accessor :timescale_divisions
+      # The formatting used for the popups.  See x_label_format
+      attr_accessor :popup_format
+
+      # Add data to the plot.
+      #
+      #   d1 = [ "12:30", 2 ]          # A data set with 1 point: ("12:30",2)
+      #   d2 = [ "01:00",2, "14:20",6] # A data set with 2 points: ("01:00",2) and 
+      #                                #                           ("14:20",6)  
+      #   graph.add_data( 
+      #     :data => d1,
+      #     :title => 'One'
+      #   )
+      #   graph.add_data(
+      #     :data => d2,
+      #     :title => 'Two'
+      #   )
+      #
+      # Note that the data must be in time,value pairs, and that the date format
+      # may be any date that is parseable by ParseDate.
+      def add_data data
+        @data = [] unless @data
+       
+        raise "No data provided by #{@data.inspect}" unless data[:data] and
+                                                    data[:data].kind_of? Array
+        raise "Data supplied must be x,y pairs!  "+
+          "The data provided contained an odd set of "+
+          "data points" unless data[:data].length % 2 == 0
+        return if data[:data].length == 0
+
+
+        x = []
+        y = []
+        data[:data].each_index {|i|
+          if i%2 == 0
+            arr = ParseDate.parsedate( data[:data][i] )
+            t = Time.local( *arr[0,6].compact )
+            x << t.to_i
+          else
+            y << data[:data][i]
+          end
+        }
+        sort( x, y )
+        data[:data] = [x,y]
+        @data << data
+      end
+
+
+      protected
+
+      def min_x_value=(value)
+        arr = ParseDate.parsedate( value )
+        @min_x_value = Time.local( *arr[0,6].compact ).to_i
+      end
+
+
+      def format x, y
+        Time.at( x ).strftime( popup_format )
+      end
+
+      def get_x_labels
+        get_x_values.collect { |v| Time.at(v).strftime( x_label_format ) }
+      end
+      
+      private
+      def get_x_values
+        rv = []
+        min, max, scale_division = x_range
+        if timescale_divisions
+          timescale_divisions =~ /(\d+) ?(day|week|month|year|hour|minute|second)?/
+          division_units = $2 ? $2 : "day"
+          amount = $1.to_i
+          if amount
+            step =  nil
+            case division_units
+            when "month"
+              cur = min
+              while cur < max
+                rv << cur
+                arr = Time.at( cur ).to_a
+                arr[4] += amount
+                if arr[4] > 12
+                  arr[5] += (arr[4] / 12).to_i
+                  arr[4] = (arr[4] % 12)
+                end
+                cur = Time.local(*arr).to_i
+              end
+            when "year"
+              cur = min
+              while cur < max
+                rv << cur
+                arr = Time.at( cur ).to_a
+                arr[5] += amount
+                cur = Time.local(*arr).to_i
+              end
+            when "week"
+              step = 7 * 24 * 60 * 60 * amount
+            when "day"
+              step = 24 * 60 * 60 * amount
+            when "hour"
+              step = 60 * 60 * amount
+            when "minute"
+              step = 60 * amount
+            when "second"
+              step = amount
+            end
+            min.step( max, step ) {|v| rv << v} if step
+
+            return rv
+          end
+        end
+        min.step( max, scale_division ) {|v| rv << v}
+        return rv
+      end
+    end
+  end
+end
Index: lib/redmine/scm/adapters/subversion_adapter.rb
===================================================================
--- lib/redmine/scm/adapters/subversion_adapter.rb	(wersja 2924)
+++ lib/redmine/scm/adapters/subversion_adapter.rb	(kopia robocza)
@@ -1,234 +1,234 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-require 'redmine/scm/adapters/abstract_adapter'
-require 'rexml/document'
-require 'uri'
-
-module Redmine
-  module Scm
-    module Adapters    
-      class SubversionAdapter < AbstractAdapter
-      
-        # SVN executable name
-        SVN_BIN = "svn"
-        
-        class << self
-          def client_version
-            @@client_version ||= (svn_binary_version || [])
-          end
-          
-          def svn_binary_version
-            cmd = "#{SVN_BIN} --version"
-            version = nil
-            shellout(cmd) do |io|
-              # Read svn version in first returned line
-              if m = io.gets.to_s.match(%r{((\d+\.)+\d+)})
-                version = m[0].scan(%r{\d+}).collect(&:to_i)
-              end
-            end
-            return nil if $? && $?.exitstatus != 0
-            version
-          end
-        end
-        
-        # Get info about the svn repository
-        def info
-          cmd = "#{SVN_BIN} info --xml #{target('')}"
-          cmd << credentials_string
-          info = nil
-          shellout(cmd) do |io|
-            begin
-              doc = REXML::Document.new(io)
-              #root_url = doc.elements["info/entry/repository/root"].text          
-              info = Info.new({:root_url => doc.elements["info/entry/repository/root"].text,
-                               :lastrev => Revision.new({
-                                 :identifier => doc.elements["info/entry/commit"].attributes['revision'],
-                                 :time => Time.parse(doc.elements["info/entry/commit/date"].text).localtime,
-                                 :author => (doc.elements["info/entry/commit/author"] ? doc.elements["info/entry/commit/author"].text : "")
-                               })
-                             })
-            rescue
-            end
-          end
-          return nil if $? && $?.exitstatus != 0
-          info
-        rescue CommandFailed
-          return nil
-        end
-        
-        # Returns an Entries collection
-        # or nil if the given path doesn't exist in the repository
-        def entries(path=nil, identifier=nil)
-          path ||= ''
-          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          entries = Entries.new
-          cmd = "#{SVN_BIN} list --xml #{target(URI.escape(path))}@#{identifier}"
-          cmd << credentials_string
-          shellout(cmd) do |io|
-            output = io.read
-            begin
-              doc = REXML::Document.new(output)
-              doc.elements.each("lists/list/entry") do |entry|
-                commit = entry.elements['commit']
-                commit_date = commit.elements['date']
-                # Skip directory if there is no commit date (usually that
-                # means that we don't have read access to it)
-                next if entry.attributes['kind'] == 'dir' && commit_date.nil?
-                name = entry.elements['name'].text
-                entries << Entry.new({:name => URI.unescape(name),
-                            :path => ((path.empty? ? "" : "#{path}/") + name),
-                            :kind => entry.attributes['kind'],
-                            :size => ((s = entry.elements['size']) ? s.text.to_i : nil),
-                            :lastrev => Revision.new({
-                              :identifier => commit.attributes['revision'],
-                              :time => Time.parse(commit_date.text).localtime,
-                              :author => ((a = commit.elements['author']) ? a.text : nil)
-                              })
-                            })
-              end
-            rescue Exception => e
-              logger.error("Error parsing svn output: #{e.message}")
-              logger.error("Output was:\n #{output}")
-            end
-          end
-          return nil if $? && $?.exitstatus != 0
-          logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug?
-          entries.sort_by_name
-        end
-        
-        def properties(path, identifier=nil)
-          # proplist xml output supported in svn 1.5.0 and higher
-          return nil unless self.class.client_version_above?([1, 5, 0])
-          
-          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(URI.escape(path))}@#{identifier}"
-          cmd << credentials_string
-          properties = {}
-          shellout(cmd) do |io|
-            output = io.read
-            begin
-              doc = REXML::Document.new(output)
-              doc.elements.each("properties/target/property") do |property|
-                properties[ property.attributes['name'] ] = property.text
-              end
-            rescue
-            end
-          end
-          return nil if $? && $?.exitstatus != 0
-          properties
-        end
-        
-        def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
-          path ||= ''
-          identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : "HEAD"
-          identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1
-          revisions = Revisions.new
-          cmd = "#{SVN_BIN} log --xml -r #{identifier_from}:#{identifier_to}"
-          cmd << credentials_string
-          cmd << " --verbose " if  options[:with_paths]
-          cmd << " --limit #{options[:limit].to_i}" if options[:limit]
-          cmd << ' ' + target(URI.escape(path))
-          shellout(cmd) do |io|
-            begin
-              doc = REXML::Document.new(io)
-              doc.elements.each("log/logentry") do |logentry|
-                paths = []
-                logentry.elements.each("paths/path") do |path|
-                  paths << {:action => path.attributes['action'],
-                            :path => path.text,
-                            :from_path => path.attributes['copyfrom-path'],
-                            :from_revision => path.attributes['copyfrom-rev']
-                            }
-                end
-                paths.sort! { |x,y| x[:path] <=> y[:path] }
-                
-                revisions << Revision.new({:identifier => logentry.attributes['revision'],
-                              :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
-                              :time => Time.parse(logentry.elements['date'].text).localtime,
-                              :message => logentry.elements['msg'].text,
-                              :paths => paths
-                            })
-              end
-            rescue
-            end
-          end
-          return nil if $? && $?.exitstatus != 0
-          revisions
-        end
-        
-        def diff(path, identifier_from, identifier_to=nil, type="inline")
-          path ||= ''
-          identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : ''
-          identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : (identifier_from.to_i - 1)
-          
-          cmd = "#{SVN_BIN} diff -r "
-          cmd << "#{identifier_to}:"
-          cmd << "#{identifier_from}"
-          cmd << " #{target(URI.escape(path))}@#{identifier_from}"
-          cmd << credentials_string
-          diff = []
-          shellout(cmd) do |io|
-            io.each_line do |line|
-              diff << line
-            end
-          end
-          return nil if $? && $?.exitstatus != 0
-          diff
-        end
-        
-        def cat(path, identifier=nil)
-          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          cmd = "#{SVN_BIN} cat #{target(URI.escape(path))}@#{identifier}"
-          cmd << credentials_string
-          cat = nil
-          shellout(cmd) do |io|
-            io.binmode
-            cat = io.read
-          end
-          return nil if $? && $?.exitstatus != 0
-          cat
-        end
-        
-        def annotate(path, identifier=nil)
-          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          cmd = "#{SVN_BIN} blame #{target(URI.escape(path))}@#{identifier}"
-          cmd << credentials_string
-          blame = Annotate.new
-          shellout(cmd) do |io|
-            io.each_line do |line|
-              next unless line =~ %r{^\s*(\d+)\s*(\S+)\s(.*)$}
-              blame.add_line($3.rstrip, Revision.new(:identifier => $1.to_i, :author => $2.strip))
-            end
-          end
-          return nil if $? && $?.exitstatus != 0
-          blame
-        end
-        
-        private
-        
-        def credentials_string
-          str = ''
-          str << " --username #{shell_quote(@login)}" unless @login.blank?
-          str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank?
-          str << " --no-auth-cache --non-interactive"
-          str
-        end
-      end
-    end
-  end
-end
+# redMine - project management software
+# Copyright (C) 2006-2007  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require 'redmine/scm/adapters/abstract_adapter'
+require 'rexml/document'
+require 'uri'
+
+module Redmine
+  module Scm
+    module Adapters    
+      class SubversionAdapter < AbstractAdapter
+      
+        # SVN executable name
+        SVN_BIN = "svn"
+        
+        class << self
+          def client_version
+            @@client_version ||= (svn_binary_version || [])
+          end
+          
+          def svn_binary_version
+            cmd = "#{SVN_BIN} --version"
+            version = nil
+            shellout(cmd) do |io|
+              # Read svn version in first returned line
+              if m = io.gets.to_s.match(%r{((\d+\.)+\d+)})
+                version = m[0].scan(%r{\d+}).collect(&:to_i)
+              end
+            end
+            return nil if $? && $?.exitstatus != 0
+            version
+          end
+        end
+        
+        # Get info about the svn repository
+        def info
+          cmd = "#{SVN_BIN} info --xml #{target('')}"
+          cmd << credentials_string
+          info = nil
+          shellout(cmd) do |io|
+            begin
+              doc = REXML::Document.new(io)
+              #root_url = doc.elements["info/entry/repository/root"].text          
+              info = Info.new({:root_url => doc.elements["info/entry/repository/root"].text,
+                               :lastrev => Revision.new({
+                                 :identifier => doc.elements["info/entry/commit"].attributes['revision'],
+                                 :time => Time.parse(doc.elements["info/entry/commit/date"].text).localtime,
+                                 :author => (doc.elements["info/entry/commit/author"] ? doc.elements["info/entry/commit/author"].text : "")
+                               })
+                             })
+            rescue
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          info
+        rescue CommandFailed
+          return nil
+        end
+        
+        # Returns an Entries collection
+        # or nil if the given path doesn't exist in the repository
+        def entries(path=nil, identifier=nil)
+          path ||= ''
+          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
+          entries = Entries.new
+          cmd = "#{SVN_BIN} list --xml #{target(URI.escape(path))}@#{identifier}"
+          cmd << credentials_string
+          shellout(cmd) do |io|
+            output = io.read
+            begin
+              doc = REXML::Document.new(output)
+              doc.elements.each("lists/list/entry") do |entry|
+                commit = entry.elements['commit']
+                commit_date = commit.elements['date']
+                # Skip directory if there is no commit date (usually that
+                # means that we don't have read access to it)
+                next if entry.attributes['kind'] == 'dir' && commit_date.nil?
+                name = entry.elements['name'].text
+                entries << Entry.new({:name => URI.unescape(name),
+                            :path => ((path.empty? ? "" : "#{path}/") + name),
+                            :kind => entry.attributes['kind'],
+                            :size => ((s = entry.elements['size']) ? s.text.to_i : nil),
+                            :lastrev => Revision.new({
+                              :identifier => commit.attributes['revision'],
+                              :time => Time.parse(commit_date.text).localtime,
+                              :author => ((a = commit.elements['author']) ? a.text : nil)
+                              })
+                            })
+              end
+            rescue Exception => e
+              logger.error("Error parsing svn output: #{e.message}")
+              logger.error("Output was:\n #{output}")
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug?
+          entries.sort_by_name
+        end
+        
+        def properties(path, identifier=nil)
+          # proplist xml output supported in svn 1.5.0 and higher
+          return nil unless self.class.client_version_above?([1, 5, 0])
+          
+          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
+          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(URI.escape(path))}@#{identifier}"
+          cmd << credentials_string
+          properties = {}
+          shellout(cmd) do |io|
+            output = io.read
+            begin
+              doc = REXML::Document.new(output)
+              doc.elements.each("properties/target/property") do |property|
+                properties[ property.attributes['name'] ] = property.text
+              end
+            rescue
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          properties
+        end
+        
+        def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
+          path ||= ''
+          identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : "HEAD"
+          identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1
+          revisions = Revisions.new
+          cmd = "#{SVN_BIN} log --xml -r #{identifier_from}:#{identifier_to}"
+          cmd << credentials_string
+          cmd << " --verbose " if  options[:with_paths]
+          cmd << " --limit #{options[:limit].to_i}" if options[:limit]
+          cmd << ' ' + target(URI.escape(path))
+          shellout(cmd) do |io|
+            begin
+              doc = REXML::Document.new(io)
+              doc.elements.each("log/logentry") do |logentry|
+                paths = []
+                logentry.elements.each("paths/path") do |path|
+                  paths << {:action => path.attributes['action'],
+                            :path => path.text,
+                            :from_path => path.attributes['copyfrom-path'],
+                            :from_revision => path.attributes['copyfrom-rev']
+                            }
+                end
+                paths.sort! { |x,y| x[:path] <=> y[:path] }
+                
+                revisions << Revision.new({:identifier => logentry.attributes['revision'],
+                              :author => (logentry.elements['author'] ? logentry.elements['author'].text : ""),
+                              :time => Time.parse(logentry.elements['date'].text).localtime,
+                              :message => logentry.elements['msg'].text,
+                              :paths => paths
+                            })
+              end
+            rescue
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          revisions
+        end
+        
+        def diff(path, identifier_from, identifier_to=nil, type="inline")
+          path ||= ''
+          identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : ''
+          identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : (identifier_from.to_i - 1)
+          
+          cmd = "#{SVN_BIN} diff -r "
+          cmd << "#{identifier_to}:"
+          cmd << "#{identifier_from}"
+          cmd << " #{target(URI.escape(path))}@#{identifier_from}"
+          cmd << credentials_string
+          diff = []
+          shellout(cmd) do |io|
+            io.each_line do |line|
+              diff << line
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          diff
+        end
+        
+        def cat(path, identifier=nil)
+          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
+          cmd = "#{SVN_BIN} cat #{target(URI.escape(path))}@#{identifier}"
+          cmd << credentials_string
+          cat = nil
+          shellout(cmd) do |io|
+            io.binmode
+            cat = io.read
+          end
+          return nil if $? && $?.exitstatus != 0
+          cat
+        end
+        
+        def annotate(path, identifier=nil)
+          identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
+          cmd = "#{SVN_BIN} blame #{target(URI.escape(path))}@#{identifier}"
+          cmd << credentials_string
+          blame = Annotate.new
+          shellout(cmd) do |io|
+            io.each_line do |line|
+              next unless line =~ %r{^\s*(\d+)\s*(\S+)\s(.*)$}
+              blame.add_line($3.rstrip, Revision.new(:identifier => $1.to_i, :author => $2.strip))
+            end
+          end
+          return nil if $? && $?.exitstatus != 0
+          blame
+        end
+        
+        private
+        
+        def credentials_string
+          str = ''
+          str << " --username #{shell_quote(@login)}" unless @login.blank?
+          str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank?
+          str << " --no-auth-cache --non-interactive"
+          str
+        end
+      end
+    end
+  end
+end
Index: lib/tasks/extract_fixtures.rake
===================================================================
--- lib/tasks/extract_fixtures.rake	(wersja 2924)
+++ lib/tasks/extract_fixtures.rake	(kopia robocza)
@@ -1,24 +1,24 @@
-desc 'Create YAML test fixtures from data in an existing database.
-Defaults to development database. Set RAILS_ENV to override.'
-
-task :extract_fixtures => :environment do
-  sql = "SELECT * FROM %s"
-  skip_tables = ["schema_info"]
-  ActiveRecord::Base.establish_connection
-  (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
-    i = "000"
-    File.open("#{RAILS_ROOT}/#{table_name}.yml", 'w' ) do |file|
-      data = ActiveRecord::Base.connection.select_all(sql % table_name)
-      file.write data.inject({}) { |hash, record|
-      
-      # cast extracted values
-      ActiveRecord::Base.connection.columns(table_name).each { |col|
-        record[col.name] = col.type_cast(record[col.name]) if record[col.name]      
-      }      
-      
-      hash["#{table_name}_#{i.succ!}"] = record
-      hash
-      }.to_yaml
-    end
-  end
+desc 'Create YAML test fixtures from data in an existing database.
+Defaults to development database. Set RAILS_ENV to override.'
+
+task :extract_fixtures => :environment do
+  sql = "SELECT * FROM %s"
+  skip_tables = ["schema_info"]
+  ActiveRecord::Base.establish_connection
+  (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
+    i = "000"
+    File.open("#{RAILS_ROOT}/#{table_name}.yml", 'w' ) do |file|
+      data = ActiveRecord::Base.connection.select_all(sql % table_name)
+      file.write data.inject({}) { |hash, record|
+      
+      # cast extracted values
+      ActiveRecord::Base.connection.columns(table_name).each { |col|
+        record[col.name] = col.type_cast(record[col.name]) if record[col.name]      
+      }      
+      
+      hash["#{table_name}_#{i.succ!}"] = record
+      hash
+      }.to_yaml
+    end
+  end
 end
\ No newline at end of file
Index: lib/tasks/migrate_from_mantis.rake
===================================================================
--- lib/tasks/migrate_from_mantis.rake	(wersja 2924)
+++ lib/tasks/migrate_from_mantis.rake	(kopia robocza)
@@ -1,513 +1,513 @@
-# redMine - project management software
-# Copyright (C) 2006-2007  Jean-Philippe Lang
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-desc 'Mantis migration script'
-
-require 'active_record'
-require 'iconv'
-require 'pp'
-
-namespace :redmine do
-task :migrate_from_mantis => :environment do
-  
-  module MantisMigrate
-   
-      DEFAULT_STATUS = IssueStatus.default
-      assigned_status = IssueStatus.find_by_position(2)
-      resolved_status = IssueStatus.find_by_position(3)
-      feedback_status = IssueStatus.find_by_position(4)
-      closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
-      STATUS_MAPPING = {10 => DEFAULT_STATUS,  # new
-                        20 => feedback_status, # feedback
-                        30 => DEFAULT_STATUS,  # acknowledged
-                        40 => DEFAULT_STATUS,  # confirmed
-                        50 => assigned_status, # assigned
-                        80 => resolved_status, # resolved
-                        90 => closed_status    # closed
-                        }
-                        
-      priorities = Enumeration.priorities
-      DEFAULT_PRIORITY = priorities[2]
-      PRIORITY_MAPPING = {10 => priorities[1], # none
-                          20 => priorities[1], # low
-                          30 => priorities[2], # normal
-                          40 => priorities[3], # high
-                          50 => priorities[4], # urgent
-                          60 => priorities[5]  # immediate
-                          }
-    
-      TRACKER_BUG = Tracker.find_by_position(1)
-      TRACKER_FEATURE = Tracker.find_by_position(2)
-      
-      roles = Role.find(:all, :conditions => {:builtin => 0}, :order => 'position ASC')
-      manager_role = roles[0]
-      developer_role = roles[1]
-      DEFAULT_ROLE = roles.last
-      ROLE_MAPPING = {10 => DEFAULT_ROLE,   # viewer
-                      25 => DEFAULT_ROLE,   # reporter
-                      40 => DEFAULT_ROLE,   # updater
-                      55 => developer_role, # developer
-                      70 => manager_role,   # manager
-                      90 => manager_role    # administrator
-                      }
-      
-      CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String
-                                   1 => 'int',    # Numeric
-                                   2 => 'int',    # Float
-                                   3 => 'list',   # Enumeration
-                                   4 => 'string', # Email
-                                   5 => 'bool',   # Checkbox
-                                   6 => 'list',   # List
-                                   7 => 'list',   # Multiselection list
-                                   8 => 'date',   # Date
-                                   }
-                                   
-      RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES,    # related to
-                               2 => IssueRelation::TYPE_RELATES,    # parent of
-                               3 => IssueRelation::TYPE_RELATES,    # child of
-                               0 => IssueRelation::TYPE_DUPLICATES, # duplicate of
-                               4 => IssueRelation::TYPE_DUPLICATES  # has duplicate
-                               }
-                                                                   
-    class MantisUser < ActiveRecord::Base
-      set_table_name :mantis_user_table
-      
-      def firstname
-        @firstname = realname.blank? ? username : realname.split.first[0..29]
-        @firstname.gsub!(/[^\w\s\'\-]/i, '')
-        @firstname
-      end
-      
-      def lastname
-        @lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
-        @lastname.gsub!(/[^\w\s\'\-]/i, '')
-        @lastname = '-' if @lastname.blank?
-        @lastname
-      end
-      
-      def email
-        if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) &&
-             !User.find_by_mail(read_attribute(:email))
-          @email = read_attribute(:email)
-        else
-          @email = "#{username}@foo.bar"
-        end
-      end
-      
-      def username
-        read_attribute(:username)[0..29].gsub(/[^a-zA-Z0-9_\-@\.]/, '-')
-      end
-    end
-    
-    class MantisProject < ActiveRecord::Base
-      set_table_name :mantis_project_table
-      has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id
-      has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id
-      has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
-      has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
-      
-      def name
-        read_attribute(:name)[0..29]
-      end
-      
-      def identifier
-        read_attribute(:name).underscore[0..19].gsub(/[^a-z0-9\-]/, '-')
-      end
-    end
-    
-    class MantisVersion < ActiveRecord::Base
-      set_table_name :mantis_project_version_table
-      
-      def version
-        read_attribute(:version)[0..29]
-      end
-      
-      def description
-        read_attribute(:description)[0..254]
-      end
-    end
-    
-    class MantisCategory < ActiveRecord::Base
-      set_table_name :mantis_project_category_table
-    end
-    
-    class MantisProjectUser < ActiveRecord::Base
-      set_table_name :mantis_project_user_list_table
-    end
-    
-    class MantisBug < ActiveRecord::Base
-      set_table_name :mantis_bug_table
-      belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id
-      has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id
-      has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id
-      has_many :bug_monitors, :class_name => "MantisBugMonitor", :foreign_key => :bug_id
-    end
-    
-    class MantisBugText < ActiveRecord::Base
-      set_table_name :mantis_bug_text_table
-      
-      # Adds Mantis steps_to_reproduce and additional_information fields
-      # to description if any
-      def full_description
-        full_description = description
-        full_description += "\n\n*Steps to reproduce:*\n\n#{steps_to_reproduce}" unless steps_to_reproduce.blank?
-        full_description += "\n\n*Additional information:*\n\n#{additional_information}" unless additional_information.blank?
-        full_description
-      end
-    end
-    
-    class MantisBugNote < ActiveRecord::Base
-      set_table_name :mantis_bugnote_table
-      belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id
-      belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id
-    end
-    
-    class MantisBugNoteText < ActiveRecord::Base
-      set_table_name :mantis_bugnote_text_table
-    end
-    
-    class MantisBugFile < ActiveRecord::Base
-      set_table_name :mantis_bug_file_table
-      
-      def size
-        filesize
-      end
-      
-      def original_filename
-        MantisMigrate.encode(filename)
-      end
-      
-      def content_type
-        file_type
-      end
-      
-      def read(*args)
-      	if @read_finished
-      		nil
-      	else
-      		@read_finished = true
-      		content
-      	end
-      end
-    end
-    
-    class MantisBugRelationship < ActiveRecord::Base
-      set_table_name :mantis_bug_relationship_table
-    end
-    
-    class MantisBugMonitor < ActiveRecord::Base
-      set_table_name :mantis_bug_monitor_table
-    end
-    
-    class MantisNews < ActiveRecord::Base
-      set_table_name :mantis_news_table
-    end
-    
-    class MantisCustomField < ActiveRecord::Base
-      set_table_name :mantis_custom_field_table
-      set_inheritance_column :none  
-      has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id
-      has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id
-      
-      def format
-        read_attribute :type
-      end
-      
-      def name
-        read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-')
-      end
-    end
-    
-    class MantisCustomFieldProject < ActiveRecord::Base
-      set_table_name :mantis_custom_field_project_table  
-    end
-    
-    class MantisCustomFieldString < ActiveRecord::Base
-      set_table_name :mantis_custom_field_string_table  
-    end
-  
-  
-    def self.migrate
-          
-      # Users
-      print "Migrating users"
-      User.delete_all "login <> 'admin'"
-      users_map = {}
-      users_migrated = 0
-      MantisUser.find(:all).each do |user|
-    	u = User.new :firstname => encode(user.firstname), 
-    				 :lastname => encode(user.lastname),
-    				 :mail => user.email,
-    				 :last_login_on => user.last_visit
-    	u.login = user.username
-    	u.password = 'mantis'
-    	u.status = User::STATUS_LOCKED if user.enabled != 1
-    	u.admin = true if user.access_level == 90
-    	next unless u.save!
-    	users_migrated += 1
-    	users_map[user.id] = u.id
-    	print '.'
-      end
-      puts
-    
-      # Projects
-      print "Migrating projects"
-      Project.destroy_all
-      projects_map = {}
-      versions_map = {}
-      categories_map = {}
-      MantisProject.find(:all).each do |project|
-    	p = Project.new :name => encode(project.name), 
-                        :description => encode(project.description)
-    	p.identifier = project.identifier
-    	next unless p.save
-    	projects_map[project.id] = p.id
-    	p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
-        p.trackers << TRACKER_BUG
-        p.trackers << TRACKER_FEATURE
-    	print '.'
-    	
-    	# Project members
-    	project.members.each do |member|
-          m = Member.new :user => User.find_by_id(users_map[member.user_id]),
-    	                   :roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
-    	  m.project = p
-    	  m.save
-    	end	
-    	
-    	# Project versions
-    	project.versions.each do |version|
-          v = Version.new :name => encode(version.version),
-                          :description => encode(version.description),
-                          :effective_date => version.date_order.to_date
-          v.project = p
-          v.save
-          versions_map[version.id] = v.id
-    	end
-    	
-    	# Project categories
-    	project.categories.each do |category|
-          g = IssueCategory.new :name => category.category[0,30]
-          g.project = p
-          g.save
-          categories_map[category.category] = g.id
-    	end
-      end	
-      puts	
-    
-      # Bugs
-      print "Migrating bugs"
-      Issue.destroy_all
-      issues_map = {}
-      keep_bug_ids = (Issue.count == 0)
-      MantisBug.find_each(:batch_size => 200) do |bug|
-        next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
-    	i = Issue.new :project_id => projects_map[bug.project_id], 
-                      :subject => encode(bug.summary),
-                      :description => encode(bug.bug_text.full_description),
-                      :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
-                      :created_on => bug.date_submitted,
-                      :updated_on => bug.last_updated
-    	i.author = User.find_by_id(users_map[bug.reporter_id])
-    	i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
-    	i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
-    	i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
-    	i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
-    	i.id = bug.id if keep_bug_ids
-    	next unless i.save
-    	issues_map[bug.id] = i.id
-    	print '.'
-
-        # Assignee
-        # Redmine checks that the assignee is a project member
-        if (bug.handler_id && users_map[bug.handler_id])
-          i.assigned_to = User.find_by_id(users_map[bug.handler_id])
-          i.save_with_validation(false)
-        end        
-    	
-    	# Bug notes
-    	bug.bug_notes.each do |note|
-    	  next unless users_map[note.reporter_id]
-          n = Journal.new :notes => encode(note.bug_note_text.note),
-                          :created_on => note.date_submitted
-          n.user = User.find_by_id(users_map[note.reporter_id])
-          n.journalized = i
-          n.save
-    	end
-    	
-        # Bug files
-        bug.bug_files.each do |file|
-          a = Attachment.new :created_on => file.date_added
-          a.file = file
-          a.author = User.find :first
-          a.container = i
-          a.save
-        end
-        
-        # Bug monitors
-        bug.bug_monitors.each do |monitor|
-          next unless users_map[monitor.user_id]
-          i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
-        end
-      end
-      
-      # update issue id sequence if needed (postgresql)
-      Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')
-      puts
-      
-      # Bug relationships
-      print "Migrating bug relations"
-      MantisBugRelationship.find(:all).each do |relation|
-        next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id]
-        r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type]
-        r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id])
-        r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id])
-        pp r unless r.save
-        print '.'
-      end
-      puts
-      
-      # News
-      print "Migrating news"
-      News.destroy_all
-      MantisNews.find(:all, :conditions => 'project_id > 0').each do |news|
-        next unless projects_map[news.project_id]
-        n = News.new :project_id => projects_map[news.project_id],
-                     :title => encode(news.headline[0..59]),
-                     :description => encode(news.body),
-                     :created_on => news.date_posted
-        n.author = User.find_by_id(users_map[news.poster_id])
-        n.save
-        print '.'
-      end
-      puts
-      
-      # Custom fields
-      print "Migrating custom fields"
-      IssueCustomField.destroy_all
-      MantisCustomField.find(:all).each do |field|
-        f = IssueCustomField.new :name => field.name[0..29],
-                                 :field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format],
-                                 :min_length => field.length_min,
-                                 :max_length => field.length_max,
-                                 :regexp => field.valid_regexp,
-                                 :possible_values => field.possible_values.split('|'),
-                                 :is_required => field.require_report?
-        next unless f.save
-        print '.'
-        
-        # Trackers association
-        f.trackers = Tracker.find :all
-        
-        # Projects association
-        field.projects.each do |project|
-          f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id]
-        end
-        
-        # Values
-        field.values.each do |value|
-          v = CustomValue.new :custom_field_id => f.id,
-                              :value => value.value
-          v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id]
-          v.save
-        end unless f.new_record?
-      end
-      puts
-    
-      puts
-      puts "Users:           #{users_migrated}/#{MantisUser.count}"
-      puts "Projects:        #{Project.count}/#{MantisProject.count}"
-      puts "Memberships:     #{Member.count}/#{MantisProjectUser.count}"
-      puts "Versions:        #{Version.count}/#{MantisVersion.count}"
-      puts "Categories:      #{IssueCategory.count}/#{MantisCategory.count}"
-      puts "Bugs:            #{Issue.count}/#{MantisBug.count}"
-      puts "Bug notes:       #{Journal.count}/#{MantisBugNote.count}"
-      puts "Bug files:       #{Attachment.count}/#{MantisBugFile.count}"
-      puts "Bug relations:   #{IssueRelation.count}/#{MantisBugRelationship.count}"
-      puts "Bug monitors:    #{Watcher.count}/#{MantisBugMonitor.count}"
-      puts "News:            #{News.count}/#{MantisNews.count}"
-      puts "Custom fields:   #{IssueCustomField.count}/#{MantisCustomField.count}"
-    end
-  
-    def self.encoding(charset)
-      @ic = Iconv.new('UTF-8', charset)
-    rescue Iconv::InvalidEncoding
-      return false      
-    end
-    
-    def self.establish_connection(params)
-      constants.each do |const|
-        klass = const_get(const)
-        next unless klass.respond_to? 'establish_connection'
-        klass.establish_connection params
-      end
-    end
-    
-    def self.encode(text)
-      @ic.iconv text
-    rescue
-      text
-    end
-  end
-  
-  puts
-  if Redmine::DefaultData::Loader.no_data?
-    puts "Redmine configuration need to be loaded before importing data."
-    puts "Please, run this first:"
-    puts
-    puts "  rake redmine:load_default_data RAILS_ENV=\"#{ENV['RAILS_ENV']}\""
-    exit
-  end
-  
-  puts "WARNING: Your Redmine data will be deleted during this process."
-  print "Are you sure you want to continue ? [y/N] "
-  break unless STDIN.gets.match(/^y$/i)
-  
-  # Default Mantis database settings
-  db_params = {:adapter => 'mysql', 
-               :database => 'bugtracker', 
-               :host => 'localhost', 
-               :username => 'root', 
-               :password => '' }
-
-  puts				
-  puts "Please enter settings for your Mantis database"  
-  [:adapter, :host, :database, :username, :password].each do |param|
-    print "#{param} [#{db_params[param]}]: "
-    value = STDIN.gets.chomp!
-    db_params[param] = value unless value.blank?
-  end
-    
-  while true
-    print "encoding [UTF-8]: "
-    encoding = STDIN.gets.chomp!
-    encoding = 'UTF-8' if encoding.blank?
-    break if MantisMigrate.encoding encoding
-    puts "Invalid encoding!"
-  end
-  puts
-  
-  # Make sure bugs can refer bugs in other projects
-  Setting.cross_project_issue_relations = 1 if Setting.respond_to? 'cross_project_issue_relations'
-  
-  # Turn off email notifications
-  Setting.notified_events = []
-  
-  MantisMigrate.establish_connection db_params
-  MantisMigrate.migrate
-end
-end
+# redMine - project management software
+# Copyright (C) 2006-2007  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+desc 'Mantis migration script'
+
+require 'active_record'
+require 'iconv'
+require 'pp'
+
+namespace :redmine do
+task :migrate_from_mantis => :environment do
+  
+  module MantisMigrate
+   
+      DEFAULT_STATUS = IssueStatus.default
+      assigned_status = IssueStatus.find_by_position(2)
+      resolved_status = IssueStatus.find_by_position(3)
+      feedback_status = IssueStatus.find_by_position(4)
+      closed_status = IssueStatus.find :first, :conditions => { :is_closed => true }
+      STATUS_MAPPING = {10 => DEFAULT_STATUS,  # new
+                        20 => feedback_status, # feedback
+                        30 => DEFAULT_STATUS,  # acknowledged
+                        40 => DEFAULT_STATUS,  # confirmed
+                        50 => assigned_status, # assigned
+                        80 => resolved_status, # resolved
+                        90 => closed_status    # closed
+                        }
+                        
+      priorities = Enumeration.priorities
+      DEFAULT_PRIORITY = priorities[2]
+      PRIORITY_MAPPING = {10 => priorities[1], # none
+                          20 => priorities[1], # low
+                          30 => priorities[2], # normal
+                          40 => priorities[3], # high
+                          50 => priorities[4], # urgent
+                          60 => priorities[5]  # immediate
+                          }
+    
+      TRACKER_BUG = Tracker.find_by_position(1)
+      TRACKER_FEATURE = Tracker.find_by_position(2)
+      
+      roles = Role.find(:all, :conditions => {:builtin => 0}, :order => 'position ASC')
+      manager_role = roles[0]
+      developer_role = roles[1]
+      DEFAULT_ROLE = roles.last
+      ROLE_MAPPING = {10 => DEFAULT_ROLE,   # viewer
+                      25 => DEFAULT_ROLE,   # reporter
+                      40 => DEFAULT_ROLE,   # updater
+                      55 => developer_role, # developer
+                      70 => manager_role,   # manager
+                      90 => manager_role    # administrator
+                      }
+      
+      CUSTOM_FIELD_TYPE_MAPPING = {0 => 'string', # String
+                                   1 => 'int',    # Numeric
+                                   2 => 'int',    # Float
+                                   3 => 'list',   # Enumeration
+                                   4 => 'string', # Email
+                                   5 => 'bool',   # Checkbox
+                                   6 => 'list',   # List
+                                   7 => 'list',   # Multiselection list
+                                   8 => 'date',   # Date
+                                   }
+                                   
+      RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES,    # related to
+                               2 => IssueRelation::TYPE_RELATES,    # parent of
+                               3 => IssueRelation::TYPE_RELATES,    # child of
+                               0 => IssueRelation::TYPE_DUPLICATES, # duplicate of
+                               4 => IssueRelation::TYPE_DUPLICATES  # has duplicate
+                               }
+                                                                   
+    class MantisUser < ActiveRecord::Base
+      set_table_name :mantis_user_table
+      
+      def firstname
+        @firstname = realname.blank? ? username : realname.split.first[0..29]
+        @firstname.gsub!(/[^\w\s\'\-]/i, '')
+        @firstname
+      end
+      
+      def lastname
+        @lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
+        @lastname.gsub!(/[^\w\s\'\-]/i, '')
+        @lastname = '-' if @lastname.blank?
+        @lastname
+      end
+      
+      def email
+        if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) &&
+             !User.find_by_mail(read_attribute(:email))
+          @email = read_attribute(:email)
+        else
+          @email = "#{username}@foo.bar"
+        end
+      end
+      
+      def username
+        read_attribute(:username)[0..29].gsub(/[^a-zA-Z0-9_\-@\.]/, '-')
+      end
+    end
+    
+    class MantisProject < ActiveRecord::Base
+      set_table_name :mantis_project_table
+      has_many :versions, :class_name => "MantisVersion", :foreign_key => :project_id
+      has_many :categories, :class_name => "MantisCategory", :foreign_key => :project_id
+      has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
+      has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
+      
+      def name
+        read_attribute(:name)[0..29]
+      end
+      
+      def identifier
+        read_attribute(:name).underscore[0..19].gsub(/[^a-z0-9\-]/, '-')
+      end
+    end
+    
+    class MantisVersion < ActiveRecord::Base
+      set_table_name :mantis_project_version_table
+      
+      def version
+        read_attribute(:version)[0..29]
+      end
+      
+      def description
+        read_attribute(:description)[0..254]
+      end
+    end
+    
+    class MantisCategory < ActiveRecord::Base
+      set_table_name :mantis_project_category_table
+    end
+    
+    class MantisProjectUser < ActiveRecord::Base
+      set_table_name :mantis_project_user_list_table
+    end
+    
+    class MantisBug < ActiveRecord::Base
+      set_table_name :mantis_bug_table
+      belongs_to :bug_text, :class_name => "MantisBugText", :foreign_key => :bug_text_id
+      has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id
+      has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id
+      has_many :bug_monitors, :class_name => "MantisBugMonitor", :foreign_key => :bug_id
+    end
+    
+    class MantisBugText < ActiveRecord::Base
+      set_table_name :mantis_bug_text_table
+      
+      # Adds Mantis steps_to_reproduce and additional_information fields
+      # to description if any
+      def full_description
+        full_description = description
+        full_description += "\n\n*Steps to reproduce:*\n\n#{steps_to_reproduce}" unless steps_to_reproduce.blank?
+        full_description += "\n\n*Additional information:*\n\n#{additional_information}" unless additional_information.blank?
+        full_description
+      end
+    end
+    
+    class MantisBugNote < ActiveRecord::Base
+      set_table_name :mantis_bugnote_table
+      belongs_to :bug, :class_name => "MantisBug", :foreign_key => :bug_id
+      belongs_to :bug_note_text, :class_name => "MantisBugNoteText", :foreign_key => :bugnote_text_id
+    end
+    
+    class MantisBugNoteText < ActiveRecord::Base
+      set_table_name :mantis_bugnote_text_table
+    end
+    
+    class MantisBugFile < ActiveRecord::Base
+      set_table_name :mantis_bug_file_table
+      
+      def size
+        filesize
+      end
+      
+      def original_filename
+        MantisMigrate.encode(filename)
+      end
+      
+      def content_type
+        file_type
+      end
+      
+      def read(*args)
+      	if @read_finished
+      		nil
+      	else
+      		@read_finished = true
+      		content
+      	end
+      end
+    end
+    
+    class MantisBugRelationship < ActiveRecord::Base
+      set_table_name :mantis_bug_relationship_table
+    end
+    
+    class MantisBugMonitor < ActiveRecord::Base
+      set_table_name :mantis_bug_monitor_table
+    end
+    
+    class MantisNews < ActiveRecord::Base
+      set_table_name :mantis_news_table
+    end
+    
+    class MantisCustomField < ActiveRecord::Base
+      set_table_name :mantis_custom_field_table
+      set_inheritance_column :none  
+      has_many :values, :class_name => "MantisCustomFieldString", :foreign_key => :field_id
+      has_many :projects, :class_name => "MantisCustomFieldProject", :foreign_key => :field_id
+      
+      def format
+        read_attribute :type
+      end
+      
+      def name
+        read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-')
+      end
+    end
+    
+    class MantisCustomFieldProject < ActiveRecord::Base
+      set_table_name :mantis_custom_field_project_table  
+    end
+    
+    class MantisCustomFieldString < ActiveRecord::Base
+      set_table_name :mantis_custom_field_string_table  
+    end
+  
+  
+    def self.migrate
+          
+      # Users
+      print "Migrating users"
+      User.delete_all "login <> 'admin'"
+      users_map = {}
+      users_migrated = 0
+      MantisUser.find(:all).each do |user|
+    	u = User.new :firstname => encode(user.firstname), 
+    				 :lastname => encode(user.lastname),
+    				 :mail => user.email,
+    				 :last_login_on => user.last_visit
+    	u.login = user.username
+    	u.password = 'mantis'
+    	u.status = User::STATUS_LOCKED if user.enabled != 1
+    	u.admin = true if user.access_level == 90
+    	next unless u.save!
+    	users_migrated += 1
+    	users_map[user.id] = u.id
+    	print '.'
+      end
+      puts
+    
+      # Projects
+      print "Migrating projects"
+      Project.destroy_all
+      projects_map = {}
+      versions_map = {}
+      categories_map = {}
+      MantisProject.find(:all).each do |project|
+    	p = Project.new :name => encode(project.name), 
+                        :description => encode(project.description)
+    	p.identifier = project.identifier
+    	next unless p.save
+    	projects_map[project.id] = p.id
+    	p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
+        p.trackers << TRACKER_BUG
+        p.trackers << TRACKER_FEATURE
+    	print '.'
+    	
+    	# Project members
+    	project.members.each do |member|
+          m = Member.new :user => User.find_by_id(users_map[member.user_id]),
+    	                   :roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
+    	  m.project = p
+    	  m.save
+    	end	
+    	
+    	# Project versions
+    	project.versions.each do |version|
+          v = Version.new :name => encode(version.version),
+                          :description => encode(version.description),
+                          :effective_date => version.date_order.to_date
+          v.project = p
+          v.save
+          versions_map[version.id] = v.id
+    	end
+    	
+    	# Project categories
+    	project.categories.each do |category|
+          g = IssueCategory.new :name => category.category[0,30]
+          g.project = p
+          g.save
+          categories_map[category.category] = g.id
+    	end
+      end	
+      puts	
+    
+      # Bugs
+      print "Migrating bugs"
+      Issue.destroy_all
+      issues_map = {}
+      keep_bug_ids = (Issue.count == 0)
+      MantisBug.find_each(:batch_size => 200) do |bug|
+        next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
+    	i = Issue.new :project_id => projects_map[bug.project_id], 
+                      :subject => encode(bug.summary),
+                      :description => encode(bug.bug_text.full_description),
+                      :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
+                      :created_on => bug.date_submitted,
+                      :updated_on => bug.last_updated
+    	i.author = User.find_by_id(users_map[bug.reporter_id])
+    	i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
+    	i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
+    	i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
+    	i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
+    	i.id = bug.id if keep_bug_ids
+    	next unless i.save
+    	issues_map[bug.id] = i.id
+    	print '.'
+
+        # Assignee
+        # Redmine checks that the assignee is a project member
+        if (bug.handler_id && users_map[bug.handler_id])
+          i.assigned_to = User.find_by_id(users_map[bug.handler_id])
+          i.save_with_validation(false)
+        end        
+    	
+    	# Bug notes
+    	bug.bug_notes.each do |note|
+    	  next unless users_map[note.reporter_id]
+          n = Journal.new :notes => encode(note.bug_note_text.note),
+                          :created_on => note.date_submitted
+          n.user = User.find_by_id(users_map[note.reporter_id])
+          n.journalized = i
+          n.save
+    	end
+    	
+        # Bug files
+        bug.bug_files.each do |file|
+          a = Attachment.new :created_on => file.date_added
+          a.file = file
+          a.author = User.find :first
+          a.container = i
+          a.save
+        end
+        
+        # Bug monitors
+        bug.bug_monitors.each do |monitor|
+          next unless users_map[monitor.user_id]
+          i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
+        end
+      end
+      
+      # update issue id sequence if needed (postgresql)
+      Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')
+      puts
+      
+      # Bug relationships
+      print "Migrating bug relations"
+      MantisBugRelationship.find(:all).each do |relation|
+        next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id]
+        r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type]
+        r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id])
+        r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id])
+        pp r unless r.save
+        print '.'
+      end
+      puts
+      
+      # News
+      print "Migrating news"
+      News.destroy_all
+      MantisNews.find(:all, :conditions => 'project_id > 0').each do |news|
+        next unless projects_map[news.project_id]
+        n = News.new :project_id => projects_map[news.project_id],
+                     :title => encode(news.headline[0..59]),
+                     :description => encode(news.body),
+                     :created_on => news.date_posted
+        n.author = User.find_by_id(users_map[news.poster_id])
+        n.save
+        print '.'
+      end
+      puts
+      
+      # Custom fields
+      print "Migrating custom fields"
+      IssueCustomField.destroy_all
+      MantisCustomField.find(:all).each do |field|
+        f = IssueCustomField.new :name => field.name[0..29],
+                                 :field_format => CUSTOM_FIELD_TYPE_MAPPING[field.format],
+                                 :min_length => field.length_min,
+                                 :max_length => field.length_max,
+                                 :regexp => field.valid_regexp,
+                                 :possible_values => field.possible_values.split('|'),
+                                 :is_required => field.require_report?
+        next unless f.save
+        print '.'
+        
+        # Trackers association
+        f.trackers = Tracker.find :all
+        
+        # Projects association
+        field.projects.each do |project|
+          f.projects << Project.find_by_id(projects_map[project.project_id]) if projects_map[project.project_id]
+        end
+        
+        # Values
+        field.values.each do |value|
+          v = CustomValue.new :custom_field_id => f.id,
+                              :value => value.value
+          v.customized = Issue.find_by_id(issues_map[value.bug_id]) if issues_map[value.bug_id]
+          v.save
+        end unless f.new_record?
+      end
+      puts
+    
+      puts
+      puts "Users:           #{users_migrated}/#{MantisUser.count}"
+      puts "Projects:        #{Project.count}/#{MantisProject.count}"
+      puts "Memberships:     #{Member.count}/#{MantisProjectUser.count}"
+      puts "Versions:        #{Version.count}/#{MantisVersion.count}"
+      puts "Categories:      #{IssueCategory.count}/#{MantisCategory.count}"
+      puts "Bugs:            #{Issue.count}/#{MantisBug.count}"
+      puts "Bug notes:       #{Journal.count}/#{MantisBugNote.count}"
+      puts "Bug files:       #{Attachment.count}/#{MantisBugFile.count}"
+      puts "Bug relations:   #{IssueRelation.count}/#{MantisBugRelationship.count}"
+      puts "Bug monitors:    #{Watcher.count}/#{MantisBugMonitor.count}"
+      puts "News:            #{News.count}/#{MantisNews.count}"
+      puts "Custom fields:   #{IssueCustomField.count}/#{MantisCustomField.count}"
+    end
+  
+    def self.encoding(charset)
+      @ic = Iconv.new('UTF-8', charset)
+    rescue Iconv::InvalidEncoding
+      return false      
+    end
+    
+    def self.establish_connection(params)
+      constants.each do |const|
+        klass = const_get(const)
+        next unless klass.respond_to? 'establish_connection'
+        klass.establish_connection params
+      end
+    end
+    
+    def self.encode(text)
+      @ic.iconv text
+    rescue
+      text
+    end
+  end
+  
+  puts
+  if Redmine::DefaultData::Loader.no_data?
+    puts "Redmine configuration need to be loaded before importing data."
+    puts "Please, run this first:"
+    puts
+    puts "  rake redmine:load_default_data RAILS_ENV=\"#{ENV['RAILS_ENV']}\""
+    exit
+  end
+  
+  puts "WARNING: Your Redmine data will be deleted during this process."
+  print "Are you sure you want to continue ? [y/N] "
+  break unless STDIN.gets.match(/^y$/i)
+  
+  # Default Mantis database settings
+  db_params = {:adapter => 'mysql', 
+               :database => 'bugtracker', 
+               :host => 'localhost', 
+               :username => 'root', 
+               :password => '' }
+
+  puts				
+  puts "Please enter settings for your Mantis database"  
+  [:adapter, :host, :database, :username, :password].each do |param|
+    print "#{param} [#{db_params[param]}]: "
+    value = STDIN.gets.chomp!
+    db_params[param] = value unless value.blank?
+  end
+    
+  while true
+    print "encoding [UTF-8]: "
+    encoding = STDIN.gets.chomp!
+    encoding = 'UTF-8' if encoding.blank?
+    break if MantisMigrate.encoding encoding
+    puts "Invalid encoding!"
+  end
+  puts
+  
+  # Make sure bugs can refer bugs in other projects
+  Setting.cross_project_issue_relations = 1 if Setting.respond_to? 'cross_project_issue_relations'
+  
+  # Turn off email notifications
+  Setting.notified_events = []
+  
+  MantisMigrate.establish_connection db_params
+  MantisMigrate.migrate
+end
+end
Index: lib/tasks/email.rake
===================================================================
--- lib/tasks/email.rake	(wersja 2924)
+++ lib/tasks/email.rake	(kopia robocza)
@@ -1,130 +1,130 @@
-# Redmine - project management software
-# Copyright (C) 2006-2008  Jean-Philippe Lang
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-namespace :redmine do
-  namespace :email do
-
-    desc <<-END_DESC
-Read an email from standard input.
-
-General options:
-  unknown_user=ACTION      how to handle emails from an unknown user
-                           ACTION can be one of the following values:
-                           ignore: email is ignored (default)
-                           accept: accept as anonymous user
-                           create: create a user account
-  
-Issue attributes control options:
-  project=PROJECT          identifier of the target project
-  status=STATUS            name of the target status
-  tracker=TRACKER          name of the target tracker
-  category=CATEGORY        name of the target category
-  priority=PRIORITY        name of the target priority
-  allow_override=ATTRS     allow email content to override attributes
-                           specified by previous options
-                           ATTRS is a comma separated list of attributes
-
-Examples:
-  # No project specified. Emails MUST contain the 'Project' keyword:
-  rake redmine:email:read RAILS_ENV="production" < raw_email
-
-  # Fixed project and default tracker specified, but emails can override
-  # both tracker and priority attributes:
-  rake redmine:email:read RAILS_ENV="production" \\
-                  project=foo \\
-                  tracker=bug \\
-                  allow_override=tracker,priority < raw_email
-END_DESC
-
-    task :read => :environment do
-      options = { :issue => {} }
-      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
-      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
-      options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
-      
-      MailHandler.receive(STDIN.read, options)
-    end
-    
-    desc <<-END_DESC
-Read emails from an IMAP server.
-
-General options:
-  unknown_user=ACTION      how to handle emails from an unknown user
-                           ACTION can be one of the following values:
-                           ignore: email is ignored (default)
-                           accept: accept as anonymous user
-                           create: create a user account
-  
-Available IMAP options:
-  host=HOST                IMAP server host (default: 127.0.0.1)
-  port=PORT                IMAP server port (default: 143)
-  ssl=SSL                  Use SSL? (default: false)
-  username=USERNAME        IMAP account
-  password=PASSWORD        IMAP password
-  folder=FOLDER            IMAP folder to read (default: INBOX)
-  
-Issue attributes control options:
-  project=PROJECT          identifier of the target project
-  status=STATUS            name of the target status
-  tracker=TRACKER          name of the target tracker
-  category=CATEGORY        name of the target category
-  priority=PRIORITY        name of the target priority
-  allow_override=ATTRS     allow email content to override attributes
-                           specified by previous options
-                           ATTRS is a comma separated list of attributes
-                           
-Processed emails control options:
-  move_on_success=MAILBOX  move emails that were successfully received
-                           to MAILBOX instead of deleting them
-  move_on_failure=MAILBOX  move emails that were ignored to MAILBOX
-  
-Examples:
-  # No project specified. Emails MUST contain the 'Project' keyword:
-  
-  rake redmine:email:receive_iamp RAILS_ENV="production" \\
-    host=imap.foo.bar username=redmine@example.net password=xxx
-
-
-  # Fixed project and default tracker specified, but emails can override
-  # both tracker and priority attributes:
-  
-  rake redmine:email:receive_iamp RAILS_ENV="production" \\
-    host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
-    project=foo \\
-    tracker=bug \\
-    allow_override=tracker,priority
-END_DESC
-
-    task :receive_imap => :environment do
-      imap_options = {:host => ENV['host'],
-                      :port => ENV['port'],
-                      :ssl => ENV['ssl'],
-                      :username => ENV['username'],
-                      :password => ENV['password'],
-                      :folder => ENV['folder'],
-                      :move_on_success => ENV['move_on_success'],
-                      :move_on_failure => ENV['move_on_failure']}
-                      
-      options = { :issue => {} }
-      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
-      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
-      options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
-
-      Redmine::IMAP.check(imap_options, options)
-    end
-  end
-end
+# Redmine - project management software
+# Copyright (C) 2006-2008  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+namespace :redmine do
+  namespace :email do
+
+    desc <<-END_DESC
+Read an email from standard input.
+
+General options:
+  unknown_user=ACTION      how to handle emails from an unknown user
+                           ACTION can be one of the following values:
+                           ignore: email is ignored (default)
+                           accept: accept as anonymous user
+                           create: create a user account
+  
+Issue attributes control options:
+  project=PROJECT          identifier of the target project
+  status=STATUS            name of the target status
+  tracker=TRACKER          name of the target tracker
+  category=CATEGORY        name of the target category
+  priority=PRIORITY        name of the target priority
+  allow_override=ATTRS     allow email content to override attributes
+                           specified by previous options
+                           ATTRS is a comma separated list of attributes
+
+Examples:
+  # No project specified. Emails MUST contain the 'Project' keyword:
+  rake redmine:email:read RAILS_ENV="production" < raw_email
+
+  # Fixed project and default tracker specified, but emails can override
+  # both tracker and priority attributes:
+  rake redmine:email:read RAILS_ENV="production" \\
+                  project=foo \\
+                  tracker=bug \\
+                  allow_override=tracker,priority < raw_email
+END_DESC
+
+    task :read => :environment do
+      options = { :issue => {} }
+      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
+      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
+      options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
+      
+      MailHandler.receive(STDIN.read, options)
+    end
+    
+    desc <<-END_DESC
+Read emails from an IMAP server.
+
+General options:
+  unknown_user=ACTION      how to handle emails from an unknown user
+                           ACTION can be one of the following values:
+                           ignore: email is ignored (default)
+                           accept: accept as anonymous user
+                           create: create a user account
+  
+Available IMAP options:
+  host=HOST                IMAP server host (default: 127.0.0.1)
+  port=PORT                IMAP server port (default: 143)
+  ssl=SSL                  Use SSL? (default: false)
+  username=USERNAME        IMAP account
+  password=PASSWORD        IMAP password
+  folder=FOLDER            IMAP folder to read (default: INBOX)
+  
+Issue attributes control options:
+  project=PROJECT          identifier of the target project
+  status=STATUS            name of the target status
+  tracker=TRACKER          name of the target tracker
+  category=CATEGORY        name of the target category
+  priority=PRIORITY        name of the target priority
+  allow_override=ATTRS     allow email content to override attributes
+                           specified by previous options
+                           ATTRS is a comma separated list of attributes
+                           
+Processed emails control options:
+  move_on_success=MAILBOX  move emails that were successfully received
+                           to MAILBOX instead of deleting them
+  move_on_failure=MAILBOX  move emails that were ignored to MAILBOX
+  
+Examples:
+  # No project specified. Emails MUST contain the 'Project' keyword:
+  
+  rake redmine:email:receive_iamp RAILS_ENV="production" \\
+    host=imap.foo.bar username=redmine@example.net password=xxx
+
+
+  # Fixed project and default tracker specified, but emails can override
+  # both tracker and priority attributes:
+  
+  rake redmine:email:receive_iamp RAILS_ENV="production" \\
+    host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
+    project=foo \\
+    tracker=bug \\
+    allow_override=tracker,priority
+END_DESC
+
+    task :receive_imap => :environment do
+      imap_options = {:host => ENV['host'],
+                      :port => ENV['port'],
+                      :ssl => ENV['ssl'],
+                      :username => ENV['username'],
+                      :password => ENV['password'],
+                      :folder => ENV['folder'],
+                      :move_on_success => ENV['move_on_success'],
+                      :move_on_failure => ENV['move_on_failure']}
+                      
+      options = { :issue => {} }
+      %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
+      options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
+      options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
+
+      Redmine::IMAP.check(imap_options, options)
+    end
+  end
+end
Index: lib/tasks/migrate_plugins.rake
===================================================================
--- lib/tasks/migrate_plugins.rake	(wersja 2924)
+++ lib/tasks/migrate_plugins.rake	(kopia robocza)
@@ -1,15 +1,15 @@
-namespace :db do
-  desc 'Migrates installed plugins.'
-  task :migrate_plugins => :environment do
-    if Rails.respond_to?('plugins')
-      Rails.plugins.each do |plugin|
-        next unless plugin.respond_to?('migrate')
-        puts "Migrating #{plugin.name}..."
-        plugin.migrate
-      end
-    else
-      puts "Undefined method plugins for Rails!"
-      puts "Make sure engines plugin is installed."
-    end
-  end
-end
+namespace :db do
+  desc 'Migrates installed plugins.'
+  task :migrate_plugins => :environment do
+    if Rails.respond_to?('plugins')
+      Rails.plugins.each do |plugin|
+        next unless plugin.respond_to?('migrate')
+        puts "Migrating #{plugin.name}..."
+        plugin.migrate
+      end
+    else
+      puts "Undefined method plugins for Rails!"
+      puts "Make sure engines plugin is installed."
+    end
+  end
+end
Index: lib/tasks/load_default_data.rake
===================================================================
--- lib/tasks/load_default_data.rake	(wersja 2924)
+++ lib/tasks/load_default_data.rake	(kopia robocza)
@@ -1,35 +1,35 @@
-desc 'Load Redmine default configuration data. Language is chosen interactively or by setting REDMINE_LANG environment variable.'
-
-namespace :redmine do
-  task :load_default_data => :environment do
-    include Redmine::I18n
-    set_language_if_valid('en')
-    
-    envlang = ENV['REDMINE_LANG']
-    if !envlang || !set_language_if_valid(envlang)
-      puts
-      while true
-        print "Select language: "
-        print valid_languages.collect(&:to_s).sort.join(", ")
-        print " [#{current_language}] "
-        STDOUT.flush
-        lang = STDIN.gets.chomp!
-        break if lang.empty?
-        break if set_language_if_valid(lang)
-        puts "Unknown language!"
-      end
-      STDOUT.flush
-      puts "===================================="
-    end
-    
-    begin
-      Redmine::DefaultData::Loader.load(current_language)
-      puts "Default configuration data loaded."
-    rescue Redmine::DefaultData::DataAlreadyLoaded => error
-      puts error
-    rescue => error
-      puts "Error: " + error
-      puts "Default configuration data was not loaded."
-    end
-  end
-end
+desc 'Load Redmine default configuration data. Language is chosen interactively or by setting REDMINE_LANG environment variable.'
+
+namespace :redmine do
+  task :load_default_data => :environment do
+    include Redmine::I18n
+    set_language_if_valid('en')
+    
+    envlang = ENV['REDMINE_LANG']
+    if !envlang || !set_language_if_valid(envlang)
+      puts
+      while true
+        print "Select language: "
+        print valid_languages.collect(&:to_s).sort.join(", ")
+        print " [#{current_language}] "
+        STDOUT.flush
+        lang = STDIN.gets.chomp!
+        break if lang.empty?
+        break if set_language_if_valid(lang)
+        puts "Unknown language!"
+      end
+      STDOUT.flush
+      puts "===================================="
+    end
+    
+    begin
+      Redmine::DefaultData::Loader.load(current_language)
+      puts "Default configuration data loaded."
+    rescue Redmine::DefaultData::DataAlreadyLoaded => error
+      puts error
+    rescue => error
+      puts "Error: " + error
+      puts "Default configuration data was not loaded."
+    end
+  end
+end
Index: lib/tasks/fetch_changesets.rake
===================================================================
--- lib/tasks/fetch_changesets.rake	(wersja 2924)
+++ lib/tasks/fetch_changesets.rake	(kopia robocza)
@@ -1,24 +1,24 @@
-# redMine - project management software
-# Copyright (C) 2006-2008  Jean-Philippe Lang
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-
-desc 'Fetch changesets from the repositories'
-
-namespace :redmine do
-  task :fetch_changesets => :environment do
-    Repository.fetch_changesets
-  end
-end
+# redMine - project management software
+# Copyright (C) 2006-2008  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+desc 'Fetch changesets from the repositories'
+
+namespace :redmine do
+  task :fetch_changesets => :environment do
+    Repository.fetch_changesets
+  end
+end
Index: public/javascripts/application.js
===================================================================
--- public/javascripts/application.js	(wersja 2924)
+++ public/javascripts/application.js	(kopia robocza)
@@ -75,7 +75,7 @@
 
 function setPredecessorFieldsVisibility() {
     relationType = $('relation_relation_type');
-    if (relationType && relationType.value == "precedes") {
+    if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
         Element.show('predecessor_fields');
     } else {
         Element.hide('predecessor_fields');
