annotate .svn/pristine/b0/b0838b1ff24739b68e1da2f2b478a763beb38975.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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