class Rubyvis::Panel

Attributes

_canvas[R]
children[RW]
root[RW]

Public Class Methods

defaults() click to toggle source
# File lib/rubyvis/mark/panel.rb, line 32
def self.defaults
  Panel.new.mark_extend(Bar.defaults).fill_style(nil).overflow('visible')
end
new() click to toggle source
# File lib/rubyvis/mark/panel.rb, line 14
def initialize
  @children=[]
  @root=self
  super
  
end

Public Instance Methods

add(type) click to toggle source
# File lib/rubyvis/mark/panel.rb, line 35
def add(type)
  child=type.new
  child.parent=self
  child.root=root
  child.child_index=children.size
  children.push(child)
  child
end
anchor(name) click to toggle source
# File lib/rubyvis/mark/panel.rb, line 51
def anchor(name)
  anchor=mark_anchor(name)
  anchor.parent=self
  anchor
end
bind() click to toggle source
# File lib/rubyvis/mark/panel.rb, line 45
def bind
  super
  children.each {|c|
    c.bind()
  }
end
build_implied(s) click to toggle source
# File lib/rubyvis/mark/panel.rb, line 92
def build_implied(s)
  panel_build_implied(s)
end
build_instance(s) click to toggle source
# File lib/rubyvis/mark/panel.rb, line 56
def build_instance(s)
  super(s)
  return if !s.visible
  s.children=[] if !s.children
  scale=self.scale * s.transform.k
  n=self.children.size
  Mark.index=-1
  n.times {|i|
    child=children[i]
    child.scene=s.children[i]
    child.scale=scale
    child.build
  }
  n.times {|i|
    child=children[i]
    s.children[i]=child.scene
    child.scene=nil
    child.scale=nil
  }
  s.children=s.children[0,n]

end
children_inspect(level=0) click to toggle source
# File lib/rubyvis/mark/panel.rb, line 20
def children_inspect(level=0)
  out=[]
  @children.each do |c|
    out << ("  "*level)+"- #{c.type} (#{c.object_id}) proto:#{c.proto.object_id} target:#{c.target.object_id}"
    if c.respond_to? :children and c.children
      out << c.children_inspect(level+1)
    end
  end
  out

end
panel_build_implied(s) click to toggle source
# File lib/rubyvis/mark/panel.rb, line 95
def panel_build_implied(s)
  if(!self.parent)
    c=s.canvas
    if(c)
      if(c._panel!=self)
        c._panel=self
        c.delete_if? {true}
      end
      if s.width.nil?
        w=Rubyvis.css(c,'width')
        s.width=w - s.left - s.right
      end
      if s.height.nil?
        w=Rubyvis.css(c,'height')
        s.height=h - s.top - s.bottom
      end

    else
      @_canvas||={}
      cache=@_canvas
      if(!(c=cache[self.index]))
      
      if Rubyvis.xml_engine==:nokogiri
        document=Nokogiri::XML::Document.new
        document.root=document.create_element('document')
        Rubyvis.nokogiri_document(document)
      else
        document=REXML::Document.new
        document.add_element("document")            
      end
        cache[self.index]=document.root
        c=cache[self.index]
        
        #c=cache[self.index]=Rubyvis.document.add_element('span')
      end
    end
    s.canvas=c
  end
  s.transform=Rubyvis.Transform.identity if (s.transform.nil?)
  mark_build_implied(s)
end
to_svg() click to toggle source
# File lib/rubyvis/mark/panel.rb, line 79
def to_svg
  if Rubyvis.xml_engine==:nokogiri
    @_canvas.sort.map {|v|
      v[1].get_element(1).to_xml(:indent => 5, :encoding => 'UTF-8')
    }.join
  else
    @_canvas.sort.map {|v|
      bar = REXML::Formatters::Default.new
      out = String.new
      bar.write(v[1].elements[1], out)
    }.join
  end
end
type() click to toggle source
# File lib/rubyvis/mark/panel.rb, line 7
def type
  "panel"
end