class GerbilCharts::Surfaces::Chart
Chart
- container class¶ ↑
Base from which all chart are derived
Attributes
ajaxContext[R]
ajaxOptions[R]
anchor[R]
elements[R]
filters[R]
href[R]
javascripts[R]
modelgroup[R]
needslayout[R]
stylesheets[R]
Public Class Methods
new( opt={})
click to toggle source
Calls superclass method
# File lib/gerbilcharts/surfaces/chart.rb, line 18 def initialize( opt={}) super(opt) set_defaults @children = [] @filters = [] @stylesheets = [opt[:style]] || [] @stylesheets.flatten! @javascripts = [opt[:javascripts]] || [] @javascripts.flatten! @needslayout=false end
Public Instance Methods
add_child(e,opts={})
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 61 def add_child(e,opts={}) @children << e @needslayout=true e.setparent(self) set_anchor(e) if opts[:anchor] end
create_filter(f)
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 101 def create_filter(f) @filters << f end
getmodelgroup()
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 97 def getmodelgroup return @modelgroup end
render(ropts={})
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 68 def render(ropts={}) svgdc = GerbilCharts::SVGDC::SVGDC.new(@bounds.width, @bounds.height) svgdc.enable_tooltips get_global_option(:auto_tooltips,false) dolayout if @needslayout # bail out of empty models quickly if @modelgroup.empty? svgdc.textout(@bounds.left + @bounds.width/2, @bounds.height/2, @modelgroup.empty_caption,{"text-anchor" => "middle", :class => "titletext"}) else @children.each { |ch| ch.render(svgdc) } end # filters, javascripts, stylesheets @filters.each { |f| svgdc.add_filter(f) } @javascripts.each { |scr| svgdc.add_javascriptfile(scr) } @stylesheets.each { |css| svgdc.add_stylesheetfile(css) } # set model hash, and other template contexts @ajaxContext.store(:axdigest,@modelgroup.models_digest) if @ajaxOptions svgdc.set_ajaxOptions(@ajaxOptions) if @ajaxOptions svgdc.set_ajaxContext(@ajaxContext) if @ajaxContext svgdc.render(ropts) end
set_ajaxContext(h)
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 55 def set_ajaxContext(h) @ajaxContext={} if @ajaxContext == nil @ajaxContext.merge!(h) end
set_ajaxOptions(h)
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 50 def set_ajaxOptions(h) @ajaxOptions={} if @ajaxOptions == nil @ajaxOptions.merge!(h) end
set_defaults()
click to toggle source
We search for the javascript code in the javascripts directory If you want to inline the javascript, pass “inline:gerbil.js” default is linked
# File lib/gerbilcharts/surfaces/chart.rb, line 34 def set_defaults @javascripts = [ "gerbil.js" ] end
set_modelgroup(g)
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 38 def set_modelgroup(g) @modelgroup=g end
sethref(h)
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 105 def sethref(h) @href=h end
usesAjax?()
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 42 def usesAjax? if @ajaxOptions return true else return false end end
Protected Instance Methods
dolayout()
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 110 def dolayout spare = Rect.new spare.from_wh @bounds.width,@bounds.height @children.each do |ch| spare=ch.munch spare end @anchor.setbounds spare @children.each do |ch| ch.align_to_anchor @anchor end @needslayout=false end
Private Instance Methods
set_anchor(a)
click to toggle source
# File lib/gerbilcharts/surfaces/chart.rb, line 128 def set_anchor(a) raise "Only one anchor element supported" if @anchor @anchor =a end