lib/rubyvis/mark.rb in rubyvis-0.1.2 vs lib/rubyvis/mark.rb in rubyvis-0.1.3
- old
+ new
@@ -4,11 +4,12 @@
# specific rendering functionality, but together with {@link Panel} establishes
# the core framework.
class Mark
@properties={}
- def self.property_method(name,_def)
+ def self.property_method(name, _def, func=nil)
+
return if Mark.method_defined? name
Mark.send(:define_method, name) do |*arguments|
v,dummy = arguments
if _def and self.scene
if arguments.size>0
@@ -16,24 +17,33 @@
return self
end
return defs[name]
end
if arguments.size>0
- type=(!_def).to_i<<1 | (v.is_a? Proc).to_i
- property_value(name,(type & 1 !=0) ? lambda {|*args| v.js_apply(self, args)} : v)._type=type
+ v=v.to_proc if v.respond_to? :to_proc
+ type=(!_def).to_i<<1 | (v.is_a? Proc).to_i
+
+ property_value(name,(type & 1 !=0) ? lambda {|*args|
+ x=v.js_apply(self, args)
+ (func and x) ? func.call(x) : x
+ } : (func and v) ? func.call(v) : v)._type=type
#@_properties_types[name]=type
return self
end
i=instance()
if i.nil?
raise "No instance for #{self} on #{name}"
else
- #puts "Instancia para #{name}"
- #puts "index:#{self.index}, name:#{name}, val:#{i.send(name)}"
+# puts "index:#{self.index}, name:#{name}, val:#{i.send(name)}"
i.send(name)
end
end
+
+ camel=name.to_s.gsub(/(_.)/) {|v| v[1,1].upcase}
+ if camel!=name
+ Mark.send(:alias_method, camel, name)
+ end
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)
@@ -53,21 +63,30 @@
end
def self.attr_accessor_dsl(*attr)
attr.each do |sym|
- @properties[sym]=true
- sym_w_sm=sym.to_s.gsub(":","")
- self.property_method(sym,false)
- define_method(sym.to_s+"=") {|v|
- self.send(sym,v)
+
+ if sym.is_a? Array
+ name,func=sym
+ else
+ name=sym
+ func=nil
+ end
+
+ @properties[name]=true
+ self.property_method(name,false, func)
+ define_method(name.to_s+"=") {|v|
+ self.send(name,v)
}
end
end
attr_accessor :parent, :root, :index, :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
@@ -153,17 +172,18 @@
s.right = s.top = s.left = s.bottom = 0;
return [s];
end
return scene;
end
-
-
-
-
-
-
-
+ def sibling
+ (self.index==0) ? nil: self.scene[self.index-1]
+ end
+ def cousin
+ par=self.parent
+ s= par ? par.sibling : nil
+ (s and s.children) ? s.children[self.child_index][self.index] : nil
+ end
def add(type)
parent.add(type).extend(self)
end
def anchor(name='center')
mark_anchor(name)
@@ -216,12 +236,10 @@
'top'
else
'bottom'
end
})
-
-
return anchor
end
@@ -540,16 +558,21 @@
end
ss.send((prop.name.to_s+"=").to_sym, v)
end
# p ss
end
+ def event(type,handler)
+ #@_handlers[type]=handler
+ return self
+ end
end
end
require 'rubyvis/mark/anchor'
require 'rubyvis/mark/bar'
require 'rubyvis/mark/panel'
require 'rubyvis/mark/area'
require 'rubyvis/mark/line'
require 'rubyvis/mark/rule'
require 'rubyvis/mark/label'
-
+require 'rubyvis/mark/dot'
+require 'rubyvis/mark/wedge'