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

#area, attr_accessor_dsl, #bar, #build, #build_properties, #context, #context_apply, #context_clear, #cousin, #delete_index, #dot, #event, #execute, #first, #image, index, #index, index=, #index=, #index_defined?, #instance, #instances, #label, #last, #layout_partition, #layout_partition_fill, #layout_stack, #layout_treemap, #line, #margin, #mark_anchor, #mark_bind, #mark_build_implied, #mark_build_instance, #mark_build_properties, #mark_extend, mark_method, #panel, #properties, properties, property_method, #property_value, #render, #rule, scene, scene=, #sibling, stack, stack=, #wedge

Constructor Details

#initializePanel

Returns a new instance of Panel.



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

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

Instance Attribute Details

#_canvasObject (readonly)

Returns the value of attribute _canvas.



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

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



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

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

Instance Method Details

#add(type) ⇒ Object



35
36
37
38
39
40
41
42
# 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) ⇒ Object



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

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

#bindObject



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

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

#build_implied(s) ⇒ Object



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

def build_implied(s)
  panel_build_implied(s)
end

#build_instance(s) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# 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) ⇒ Object



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
117
# File 'lib/rubyvis/mark/panel.rb', line 89

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



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

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