lib/rubyvis/mark.rb in rubyvis-0.1.4 vs lib/rubyvis/mark.rb in rubyvis-0.1.5

- old
+ new

@@ -57,12 +57,29 @@ define_method(name.to_s+"=") {|v| self.send(name,v) } end end - + def delete_index + @index=nil + @index_defined=false + end + def index + @index + end + + def index_defined? + @index_defined + end + def index=(v) + @index_defined=true + @index=v + v + end + + def property_value(name,v) prop=Property.new({:name=>name, :id=>Rubyvis.id, :value=>v}) @_properties.delete_if{|v1| v1.name==name} @_properties.push(prop) #@_properties_values[name]=v @@ -72,27 +89,28 @@ self.left(n).right(n).top(n).bottom(n) end def instance(default_index=nil) scene=self.scene scene||=self.parent.instance(-1).children[self.child_index] - - index = self.respond_to?(:index) ? self.index : default_index - #puts "type: #{type}, self.index: #{self.index}, index:#{index}" - scene[index<0 ? scene.length-1: index] + + index = index_defined? ? self.index : default_index + # "defined?: #{index_defined?} : type: #{type}, self.index: #{self.index}, index:#{index}" + scene[index<0 ? scene.size-1: index] end - attr_accessor :parent, :root, :index, :child_index, :scene, :proto, :target, :scale + attr_accessor :parent, :root, :child_index, :scene, :proto, :target, :scale attr_reader :_properties attr_accessor_dsl :data,:visible, :left, :right, :top, :bottom, :cursor, :title, :reverse, :antialias, :events, :id @scene=nil @stack=[] @index=nil + def self.properties @properties end def Mark.index @index @@ -125,10 +143,11 @@ self.send("#{k}=",v) if self.respond_to? k } @defs={} @child_index=-1 @index=-1 + @index_defined = true @scale=1 @scene=nil end def type @@ -142,31 +161,31 @@ @target=proto.target self end def instances(source) - mark = self - index = [] + _index = [] scene=nil + while (!(scene = mark.scene)) do source = source.parent; - index.push(OpenStruct.new({:index=>source.index, :child_index=>mark.child_index})) + _index.push(OpenStruct.new({:index=>source.index, :child_index=>mark.child_index})) mark = mark.parent end - while (index.size>0) do - i = index.pop() + while (_index.size>0) do + i = _index.pop() scene = scene[i.index].children[i.child_index] end # # When the anchor target is also an ancestor, as in the case of adding # to a panel anchor, only generate one instance per panel. Also, set # the margins to zero, since they are offset by the enclosing panel. # / - if (self.respond_to? :index and self.index) - + + if (index_defined?) s = scene[self.index].dup s.right = s.top = s.left = s.bottom = 0; return [s]; end return scene; @@ -184,13 +203,16 @@ end def anchor(name='center') mark_anchor(name) end def mark_anchor(name="center") - anchor=Rubyvis::Anchor.new(self).name(name).data(lambda { - self.scene.target.map {|s| s.data} }).visible(lambda { + pp self.scene.target if $DEBUG + a=self.scene.target.map {|s| puts "s:#{s.data}" if $DEBUG; s.data} + p a if $DEBUG + a + }).visible(lambda { self.scene.target[self.index].visible }).id(lambda {self.scene.target[self.index].id}).left(lambda { s = self.scene.target[self.index] w = s.width w||=0 @@ -331,27 +353,29 @@ def render_render(mark,depth,scale) mark.scale=scale if (depth < @indexes.size) @stack.unshift(nil) - if (mark.respond_to? :index and mark.index) + if (mark.index_defined?) render_instance(mark, depth, scale); else mark.scene.size.times {|i| mark.index = i; render_instance(mark, depth, scale); } - mark.index=nil + mark.delete_index end stack.shift else mark.build pv.Scene.scale = scale; pv.Scene.update_all(mark.scene); end mark.scale=nil end + + def render_instance(mark,depth,scale) s=mark.scene[mark.index] if s.visible child_index=@indexes[depth] child=mark.children[child_index] @@ -469,11 +493,11 @@ end mark=that begin Mark.stack.pop - if(mark.parent) + if(mark.parent) mark.scene=nil mark.scale=nil end mark.index=nil end while(mark=mark.parent) @@ -522,23 +546,25 @@ #puts "data:#{data}" stack.unshift(nil) scene.size=data.size data.each_with_index {|d, i| - Mark.index=self.index=i + Mark.index=i + self.index=i s=scene[i] if !s scene[i]=s=SceneElement.new end stack[0]=data[i] s.data=data[i] build_instance(s) } Mark.index=-1 - self.index=nil + delete_index stack.shift() - return self + self end + def build_instance(s) mark_build_instance(s) end def mark_build_instance(s1) build_properties(s1, self.binds.required)