class SVG::Graph::BarBase
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
Attributes
bar_gap[RW]
Whether to have a gap between the bars or not, default is true, set to false if you don't want gaps.
stack[RW]
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.
Public Class Methods
new(config)
click to toggle source
Ensures that :fields are provided in the configuration.
Calls superclass method
SVG::Graph::Graph::new
# File lib/SVG/Graph/BarBase.rb 20 def initialize config 21 raise "fields was not supplied or is empty" unless config[:fields] && 22 config[:fields].kind_of?(Array) && 23 config[:fields].length > 0 24 super 25 end
Public Instance Methods
set_defaults()
click to toggle source
In addition to the defaults set in Graph::initialize, sets
bar_gap
-
true
- stack
-
:overlap
# File lib/SVG/Graph/BarBase.rb 30 def set_defaults 31 init_with( :bar_gap => true, :stack => :overlap ) 32 end
Protected Instance Methods
get_css()
click to toggle source
# File lib/SVG/Graph/BarBase.rb 58 def get_css 59 return <<EOL 60 /* default fill styles for multiple datasets (probably only use a single dataset on this graph though) */ 61 .key1,.fill1{ 62 fill: #ff0000; 63 fill-opacity: 0.5; 64 stroke: none; 65 stroke-width: 0.5px; 66 } 67 .key2,.fill2{ 68 fill: #0000ff; 69 fill-opacity: 0.5; 70 stroke: none; 71 stroke-width: 1px; 72 } 73 .key3,.fill3{ 74 fill: #00ff00; 75 fill-opacity: 0.5; 76 stroke: none; 77 stroke-width: 1px; 78 } 79 .key4,.fill4{ 80 fill: #ffcc00; 81 fill-opacity: 0.5; 82 stroke: none; 83 stroke-width: 1px; 84 } 85 .key5,.fill5{ 86 fill: #00ccff; 87 fill-opacity: 0.5; 88 stroke: none; 89 stroke-width: 1px; 90 } 91 .key6,.fill6{ 92 fill: #ff00ff; 93 fill-opacity: 0.5; 94 stroke: none; 95 stroke-width: 1px; 96 } 97 .key7,.fill7{ 98 fill: #00ffff; 99 fill-opacity: 0.5; 100 stroke: none; 101 stroke-width: 1px; 102 } 103 .key8,.fill8{ 104 fill: #ffff00; 105 fill-opacity: 0.5; 106 stroke: none; 107 stroke-width: 1px; 108 } 109 .key9,.fill9{ 110 fill: #cc6666; 111 fill-opacity: 0.5; 112 stroke: none; 113 stroke-width: 1px; 114 } 115 .key10,.fill10{ 116 fill: #663399; 117 fill-opacity: 0.5; 118 stroke: none; 119 stroke-width: 1px; 120 } 121 .key11,.fill11{ 122 fill: #339900; 123 fill-opacity: 0.5; 124 stroke: none; 125 stroke-width: 1px; 126 } 127 .key12,.fill12{ 128 fill: #9966FF; 129 fill-opacity: 0.5; 130 stroke: none; 131 stroke-width: 1px; 132 } 133 EOL 134 end
max_value()
click to toggle source
# File lib/SVG/Graph/BarBase.rb 43 def max_value 44 @data.collect{|x| x[:data].max}.max 45 end
min_value()
click to toggle source
# File lib/SVG/Graph/BarBase.rb 47 def min_value 48 min = 0 49 if min_scale_value.nil? 50 min = @data.collect{|x| x[:data].min}.min 51 min = min > 0 ? 0 : min 52 else 53 min = min_scale_value 54 end 55 return min 56 end