class GerbilCharts::SVGDC::SVGElement

SVGElement

Base class for all SVG shapes. Contains rendering, and svg presentation handling code Note : the presentation as passed on as is to the SVG

Attributes

custom_style[RW]
href[R]
presentations[R]

Public Class Methods

new() click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 13
def initialize()
  @presentations=Array.new

      # default fill and stroke (you can override it)
      @custom_attributes||={}

end

Public Instance Methods

add_options(opt) click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 47
def add_options(opt)
  @custom_attributes = {} if not defined? @custom_attributes

  opt.each_pair do |k,v|
    @custom_attributes.store(k,v)
  end
  
  # treat the href custom attribute separately
  if @custom_attributes[:href]
    @href=@custom_attributes[:href]
    @custom_attributes.delete(:href)
  end
end
add_presentation(p) click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 43
def add_presentation(p)
  @presentations << p
end
has_presentations?() click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 21
def has_presentations?
  defined? @presentations
end
render_attributes() click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 25
def render_attributes
  h={}

  if has_presentations?
    @presentations.each do |p|
      h.merge!(p.render)
    end
  end

  if @custom_attributes 
    @custom_attributes.each_pair do |k,v|
      h.store( k, v) 
    end
  end

  return h
end
render_base(xfrag) { || ... } click to toggle source

base render allows for wrapping with a Anchor tag

# File lib/gerbilcharts/svgdc/svg_element.rb, line 74
def render_base(xfrag)
  if @href
    xfrag.a("xlink:href" => @href, :target => "_top") {
      yield
    }
  else
    yield
  end
end
set_class(css_class) click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 65
def set_class(css_class)
  add_options(:class=> css_class)
end
set_href(url) click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 69
def set_href(url)
  @href=url
end
set_id(css_id) click to toggle source
# File lib/gerbilcharts/svgdc/svg_element.rb, line 61
def set_id(css_id)
  add_options(:id=> css_id)
end