OSDN Git Service

add Redmine trunk rev 3089
[redminele/redminele.git] / redmine / lib / SVG / Graph / BarBase.rb
1 require 'rexml/document'\r
2 require 'SVG/Graph/Graph'\r
3 \r
4 module SVG\r
5   module Graph\r
6                 # = Synopsis\r
7                 #\r
8                 # A superclass for bar-style graphs.  Do not attempt to instantiate\r
9                 # directly; use one of the subclasses instead.\r
10                 #\r
11     # = Author\r
12     #\r
13     # Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>\r
14                 #\r
15     # Copyright 2004 Sean E. Russell\r
16                 # This software is available under the Ruby license[LICENSE.txt]\r
17     #\r
18     class BarBase < SVG::Graph::Graph\r
19                         # Ensures that :fields are provided in the configuration.\r
20       def initialize config\r
21         raise "fields was not supplied or is empty" unless config[:fields] &&\r
22         config[:fields].kind_of?(Array) &&\r
23         config[:fields].length > 0\r
24                                 super\r
25                         end\r
26 \r
27                         # In addition to the defaults set in Graph::initialize, sets\r
28                         # [bar_gap] true\r
29                         # [stack] :overlap\r
30                         def set_defaults\r
31         init_with( :bar_gap => true, :stack => :overlap )\r
32       end\r
33 \r
34       #   Whether to have a gap between the bars or not, default\r
35       #   is true, set to false if you don't want gaps.\r
36       attr_accessor :bar_gap\r
37       #   How to stack data sets.  :overlap overlaps bars with\r
38       #   transparent colors, :top stacks bars on top of one another,\r
39       #   :side stacks the bars side-by-side. Defaults to :overlap.\r
40       attr_accessor :stack\r
41 \r
42 \r
43                         protected\r
44 \r
45       def max_value\r
46         @data.collect{|x| x[:data].max}.max\r
47       end\r
48 \r
49       def min_value\r
50         min = 0\r
51         if min_scale_value.nil? \r
52           min = @data.collect{|x| x[:data].min}.min\r
53           min = min > 0 ? 0 : min\r
54         else\r
55           min = min_scale_value\r
56         end\r
57         return min\r
58       end\r
59 \r
60       def get_css\r
61         return <<EOL\r
62 /* default fill styles for multiple datasets (probably only use a single dataset on this graph though) */\r
63 .key1,.fill1{\r
64         fill: #ff0000;\r
65         fill-opacity: 0.5;\r
66         stroke: none;\r
67         stroke-width: 0.5px;    \r
68 }\r
69 .key2,.fill2{\r
70         fill: #0000ff;\r
71         fill-opacity: 0.5;\r
72         stroke: none;\r
73         stroke-width: 1px;      \r
74 }\r
75 .key3,.fill3{\r
76         fill: #00ff00;\r
77         fill-opacity: 0.5;\r
78         stroke: none;\r
79         stroke-width: 1px;      \r
80 }\r
81 .key4,.fill4{\r
82         fill: #ffcc00;\r
83         fill-opacity: 0.5;\r
84         stroke: none;\r
85         stroke-width: 1px;      \r
86 }\r
87 .key5,.fill5{\r
88         fill: #00ccff;\r
89         fill-opacity: 0.5;\r
90         stroke: none;\r
91         stroke-width: 1px;      \r
92 }\r
93 .key6,.fill6{\r
94         fill: #ff00ff;\r
95         fill-opacity: 0.5;\r
96         stroke: none;\r
97         stroke-width: 1px;      \r
98 }\r
99 .key7,.fill7{\r
100         fill: #00ffff;\r
101         fill-opacity: 0.5;\r
102         stroke: none;\r
103         stroke-width: 1px;      \r
104 }\r
105 .key8,.fill8{\r
106         fill: #ffff00;\r
107         fill-opacity: 0.5;\r
108         stroke: none;\r
109         stroke-width: 1px;      \r
110 }\r
111 .key9,.fill9{\r
112         fill: #cc6666;\r
113         fill-opacity: 0.5;\r
114         stroke: none;\r
115         stroke-width: 1px;      \r
116 }\r
117 .key10,.fill10{\r
118         fill: #663399;\r
119         fill-opacity: 0.5;\r
120         stroke: none;\r
121         stroke-width: 1px;      \r
122 }\r
123 .key11,.fill11{\r
124         fill: #339900;\r
125         fill-opacity: 0.5;\r
126         stroke: none;\r
127         stroke-width: 1px;      \r
128 }\r
129 .key12,.fill12{\r
130         fill: #9966FF;\r
131         fill-opacity: 0.5;\r
132         stroke: none;\r
133         stroke-width: 1px;      \r
134 }\r
135 EOL\r
136       end\r
137     end\r
138   end\r
139 end\r