Class: Rubyvis::Panel

Inherits:
Bar show all
Defined in:
lib/rubyvis/mark/panel.rb

Direct Known Subclasses

Layout

Instance Attribute Summary collapse

Attributes inherited from Mark

#_properties, #binds, #child_index, #parent, #proto, #scale, #scene, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Bar

#width

Methods inherited from Mark

attr_accessor_dsl, #build, #build_properties, #context, #context_apply, #context_clear, #cousin, #delete_index, #event, #extend, #index, index, #index=, index=, #index_defined?, #instance, #instances, #margin, #mark_anchor, #mark_bind, #mark_build_implied, #mark_build_instance, #properties, properties, property_method, #property_value, #render, scene, scene=, #sibling, stack, stack=

Constructor Details

#initializePanel

Returns a new instance of Panel.



14
15
16
17
18
# File 'lib/rubyvis/mark/panel.rb', line 14

def initialize
  super
  @children=[]
  @root=self
end

Instance Attribute Details

#_canvasObject (readonly)

Returns the value of attribute _canvas.



43
44
45
# File 'lib/rubyvis/mark/panel.rb', line 43

def _canvas
  @_canvas
end

#childrenObject

Returns the value of attribute children.



13
14
15
# File 'lib/rubyvis/mark/panel.rb', line 13

def children
  @children
end

#rootObject

Returns the value of attribute root.



13
14
15
# File 'lib/rubyvis/mark/panel.rb', line 13

def root
  @root
end

Class Method Details

.defaultsObject



31
32
33
# File 'lib/rubyvis/mark/panel.rb', line 31

def self.defaults
  Panel.new.extend(Bar.defaults).fill_style(nil).overflow('visible')
end

Instance Method Details

#add(type) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/rubyvis/mark/panel.rb', line 34

def add(type)
  child=type.new
  child.parent=self
  child.root=root
  child.child_index=children.size
  children.push(child)
  child
end

#anchor(name) ⇒ Object



50
51
52
53
54
# File 'lib/rubyvis/mark/panel.rb', line 50

def anchor(name)
  anchor=mark_anchor(name)
  anchor.parent=self
  anchor
end

#bindObject



44
45
46
47
48
49
# File 'lib/rubyvis/mark/panel.rb', line 44

def bind
  super
  children.each {|c|
    c.bind()
  }
end

#build_implied(s) ⇒ Object



85
86
87
# File 'lib/rubyvis/mark/panel.rb', line 85

def build_implied(s)
  panel_build_implied(s)
end

#build_instance(s) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rubyvis/mark/panel.rb', line 55

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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubyvis/mark/panel.rb', line 19

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) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rubyvis/mark/panel.rb', line 88

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]))
        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_svgObject



78
79
80
81
82
83
84
# File 'lib/rubyvis/mark/panel.rb', line 78

def to_svg
  @_canvas.sort.map {|v|
    bar = REXML::Formatters::Default.new
    out = String.new
    bar.write(v[1].elements[1], out)
  }.join
end

#typeObject



7
8
9
# File 'lib/rubyvis/mark/panel.rb', line 7

def type
  "panel"
end