Class: GerbilCharts::Models::GraphModelGroup
- Inherits:
-
Object
- Object
- GerbilCharts::Models::GraphModelGroup
- Defined in:
- lib/gerbilcharts/models/graph_model_group.rb
Overview
GraphModelGroup - a bunch of related models that are targeted at a single output surface
Direct Known Subclasses
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#emptycaption ⇒ Object
Returns the value of attribute emptycaption.
-
#href ⇒ Object
Returns the value of attribute href.
-
#models ⇒ Object
Returns the value of attribute models.
-
#name ⇒ Object
Returns the value of attribute name.
-
#range_bands ⇒ Object
Returns the value of attribute range_bands.
-
#ref_models ⇒ Object
Returns the value of attribute ref_models.
-
#units ⇒ Object
Returns the value of attribute units.
-
#x_markers ⇒ Object
Returns the value of attribute x_markers.
Instance Method Summary collapse
- #<<(m) ⇒ Object
- #add(m) ⇒ Object
- #clear_models ⇒ Object
- #compact_models ⇒ Object
- #contentKey(sessid, extension) ⇒ Object
- #count ⇒ Object
- #cumulative_round_range ⇒ Object
-
#cumulative_round_range_y ⇒ Object
sum of model ranges.
-
#cumulative_round_range_y0 ⇒ Object
sum of model ranges with min y being 0.
-
#cumulative_sweep_round_range_y0 ⇒ Object
sweep for an interval with y scale.
- #delete(m) ⇒ Object
- #delete_by_index(i) ⇒ Object
- #each_model ⇒ Object
-
#each_model_with_index ⇒ Object
each model, index over code block.
-
#each_user_data ⇒ Object
each user data over code block.
-
#effective_range_x(rangeopts = nil) ⇒ Object
rangeoptions [
:auto] automatic rounded max and min range [:auto_0] automatic rounded max and 0 min [+[min,max+] manual scaling. -
#effective_range_y(rangeopts = nil) ⇒ Object
rangeoptions [
:auto] automatic rounded max and min range [:auto_0] automatic rounded max and 0 min [+[min,max+] manual scaling. -
#effective_round_range ⇒ Object
effective round range rounds both x and y scales, returns two ranges.
-
#effective_round_range_x ⇒ Object
round the x ranges of all models.
- #effective_round_range_y ⇒ Object
-
#effective_round_range_y0 ⇒ Object
round the y ranges of all models but minimum fixed at 0.
-
#empty? ⇒ Boolean
empty ?.
-
#empty_caption ⇒ Object
empty string.
- #find_model(name) ⇒ Object
- #has_x_markers? ⇒ Boolean
- #hasHref? ⇒ Boolean
-
#initialize(n = "Untitled-Group", opts = {}) ⇒ GraphModelGroup
constructor
A new instance of GraphModelGroup.
- #models_digest ⇒ Object
- #randomizeModels(mode = :latest_value) ⇒ Object
-
#recreateModels(new_opts) ⇒ Object
recreate all models with new params.
- #set_null(i) ⇒ Object
- #setHref(h) ⇒ Object
- #setSessionKey(k) ⇒ Object
-
#sort(opts = {}) ⇒ Object
sort options :dir => (:ascending or :descending) :mode => (:latest, :total ).
- #sweep_interval ⇒ Object
Constructor Details
#initialize(n = "Untitled-Group", opts = {}) ⇒ GraphModelGroup
Returns a new instance of GraphModelGroup.
18 19 20 21 22 23 24 25 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 18 def initialize(n="Untitled-Group",opts={}) @models=[] @name=n @units=opts[:units] || "" @ref_models=[] @annotations=[] # array of [{:x, :y, :label}] @range_bands=[] # array of models [{:upper=>nil,:lower=>nil} ] end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
15 16 17 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 15 def annotations @annotations end |
#emptycaption ⇒ Object
Returns the value of attribute emptycaption.
11 12 13 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 11 def emptycaption @emptycaption end |
#href ⇒ Object
Returns the value of attribute href.
10 11 12 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 10 def href @href end |
#models ⇒ Object
Returns the value of attribute models.
8 9 10 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 8 def models @models end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 9 def name @name end |
#range_bands ⇒ Object
Returns the value of attribute range_bands.
16 17 18 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 16 def range_bands @range_bands end |
#ref_models ⇒ Object
Returns the value of attribute ref_models.
14 15 16 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 14 def ref_models @ref_models end |
#units ⇒ Object
Returns the value of attribute units.
12 13 14 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 12 def units @units end |
#x_markers ⇒ Object
Returns the value of attribute x_markers.
13 14 15 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 13 def x_markers @x_markers end |
Instance Method Details
#<<(m) ⇒ Object
27 28 29 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 27 def <<(m) @models << m end |
#add(m) ⇒ Object
31 32 33 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 31 def add(m) @models << m end |
#clear_models ⇒ Object
70 71 72 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 70 def clear_models @models.clear end |
#compact_models ⇒ Object
47 48 49 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 47 def compact_models @models.compact! end |
#contentKey(sessid, extension) ⇒ Object
291 292 293 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 291 def contentKey(sessid,extension) return sessid + @sessionKey + "." + extension end |
#count ⇒ Object
51 52 53 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 51 def count return @models.size end |
#cumulative_round_range ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 263 def cumulative_round_range return 0,0 if @models.empty? reffx = RawRange.new reffy = RawRange.new @models.each do |m| reffx.update_r(m.xrange) reffy.update(m.yrange.rmax+reffy.rmax) end return models[0].rounderx.round_given(reffx), models[0].roundery.round_given(reffy) end |
#cumulative_round_range_y ⇒ Object
sum of model ranges
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 228 def cumulative_round_range_y reffy = RawRange.new @models.each do |m| reffy.update(m.yrange.rmax+reffy.rmax) end @ref_models.each do |ref_model| reffy.update(ref_model.yrange.rmax) end @range_bands.each do |range_band| reffy.update(range_band[:upper].yrange.rmax) reffy.update(range_band[:lower].yrange.rmax) end return models[0].round_given_y(reffy) end |
#cumulative_round_range_y0 ⇒ Object
sum of model ranges with min y being 0
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 204 def cumulative_round_range_y0 return 0,100 if models.empty? reffy = RawRange.new reffy.update(0) @models.each do |m| reffy.update(m.yrange.rmax+reffy.rmax) if m.yrange.rmax end @ref_models.each do |ref_model| reffy.update(ref_model.yrange.rmax) end @range_bands.each do |range_band| reffy.update(range_band[:upper].yrange.rmax) reffy.update(range_band[:lower].yrange.rmax) end return models[0].round_given_y(reffy) end |
#cumulative_sweep_round_range_y0 ⇒ Object
sweep for an interval with y scale
250 251 252 253 254 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 250 def cumulative_sweep_round_range_y0 reffy=RawRange.new reffy.zeromin return cumulative_sweep_round_range_y_generic(reffy) end |
#delete(m) ⇒ Object
35 36 37 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 35 def delete(m) @models.delete(m) end |
#delete_by_index(i) ⇒ Object
39 40 41 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 39 def delete_by_index(i) @models.delete_at(i) end |
#each_model ⇒ Object
55 56 57 58 59 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 55 def each_model @models.each do |m| yield m end end |
#each_model_with_index ⇒ Object
each model, index over code block
89 90 91 92 93 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 89 def each_model_with_index @models.each_with_index do |m,i| yield m,i end end |
#each_user_data ⇒ Object
each user data over code block
96 97 98 99 100 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 96 def each_user_data each_model do |mod| yield mod.userdata if mod.hasUserData? end end |
#effective_range_x(rangeopts = nil) ⇒ Object
rangeoptions [:auto] automatic rounded max and min range
:auto_0-
automatic rounded max and 0 min
- [min,max
-
manual scaling
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 107 def effective_range_x(rangeopts=nil) return effective_round_range_x if rangeopts.nil? if rangeopts.is_a?(Array) and rangeopts.size == 2 reffx = RawRange.new reffx.update(rangeopts[0]) reffx.update(rangeopts[1]) return reffx else case rangeopts.to_sym when :auto ;return effective_round_range_x when :auto_0 ;return effective_round_range_x else ;raise "Unknown range option" end end end |
#effective_range_y(rangeopts = nil) ⇒ Object
rangeoptions [:auto] automatic rounded max and min range
:auto_0-
automatic rounded max and 0 min
- [min,max
-
manual scaling
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 166 def effective_range_y(rangeopts=nil) if rangeopts.nil? return effective_round_range_y0 end if rangeopts == :auto return effective_round_range_y elsif rangeopts == :auto_0 or rangeopts == :auto_y0 return effective_round_range_y0 elsif rangeopts.respond_to?('size') and rangeopts.size == 2 reffy = RawRange.new reffy.update(rangeopts[0]) reffy.update(rangeopts[1]) return reffy end end |
#effective_round_range ⇒ Object
effective round range rounds both x and y scales, returns two ranges
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 127 def effective_round_range return 0,0 if @models.empty? reffx = RawRange.new reffy = RawRange.new @models.each do |m| reffx.update_r(m.xrange) reffy.update_r(m.yrange) end # todo : need to convert the round_given method to a class method return models[0].rounderx.round_given(reffx), models[0].roundery.round_given(reffy) end |
#effective_round_range_x ⇒ Object
round the x ranges of all models
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 144 def effective_round_range_x return 0,0 if @models.empty? reffx = RawRange.new @models.each do |m| reffx.update_r(m.xrange) end if reffx.invalid? reffx.update 10 end return models[0].round_given_x(reffx) end |
#effective_round_range_y ⇒ Object
193 194 195 196 197 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 193 def effective_round_range_y reffy = RawRange.new @models.each { |m| reffy.update_r(m.yrange) } return @models[0].round_given_y(reffy) end |
#effective_round_range_y0 ⇒ Object
round the y ranges of all models but minimum fixed at 0
184 185 186 187 188 189 190 191 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 184 def effective_round_range_y0 reffy = RawRange.new reffy.zeromin @models.each do |m| reffy.update_r(m.yrange) end return @models[0].round_given_y(reffy) end |
#empty? ⇒ Boolean
empty ?
322 323 324 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 322 def empty? return @models.empty? end |
#empty_caption ⇒ Object
empty string
327 328 329 330 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 327 def empty_caption return "No activity" if @emptycaption.nil? return @emptycaption end |
#find_model(name) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 61 def find_model(name) @models.each do |m| if m.name==name return m end end return nil end |
#has_x_markers? ⇒ Boolean
332 333 334 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 332 def has_x_markers? not x_markers.nil? end |
#hasHref? ⇒ Boolean
300 301 302 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 300 def hasHref? return @href != nil end |
#models_digest ⇒ Object
278 279 280 281 282 283 284 285 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 278 def models_digest mnames = "" @models.each do |m| mnames << m.name end dig=Digest::MD5.hexdigest(mnames) return dig end |
#randomizeModels(mode = :latest_value) ⇒ Object
304 305 306 307 308 309 310 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 304 def randomizeModels(mode=:latest_value) @models.each do |m| if mode==:latest_value m.randomizeLastValue end end end |
#recreateModels(new_opts) ⇒ Object
recreate all models with new params
313 314 315 316 317 318 319 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 313 def recreateModels(new_opts) @models.each do |m| m.updateOptions(new_opts) m.recreate end end |
#set_null(i) ⇒ Object
43 44 45 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 43 def set_null(i) @models[i]=nil end |
#setHref(h) ⇒ Object
295 296 297 298 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 295 def setHref(h) h1=h.gsub("{","%7B") @href=h1.gsub("}","%7D") end |
#setSessionKey(k) ⇒ Object
287 288 289 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 287 def setSessionKey(k) @sessionKey=k end |
#sort(opts = {}) ⇒ Object
sort options
:dir => (:ascending or :descending)
:mode => (:latest, :total )
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 77 def sort(opts={}) raise "Missing sort direction" if not defined? opts[:dir] raise "Missing sort mode" if not defined? opts[:mode] @models.sort! { |m1,m2| m1.latest_val <=> m2.latest_val } @models.reverse! if opts[:dir] == :descending end |
#sweep_interval ⇒ Object
199 200 201 |
# File 'lib/gerbilcharts/models/graph_model_group.rb', line 199 def sweep_interval return @models[0].sweep_interval end |