lib/rubyvis/mark.rb in rubyvis-0.1.7 vs lib/rubyvis/mark.rb in rubyvis-0.2.0
- old
+ new
@@ -1,5 +1,6 @@
+
module Rubyvis
# Constructs a new mark with default properties. Marks, with the exception of
# the root panel, are not typically constructed directly; instead, they are
# added to a panel or an existing mark via Mark#add
#
@@ -67,11 +68,11 @@
# created for inheritance purposes only.
#
# @attr [Panel]
attr_accessor :root
- # The child index. -1 if the enclosing parent panel is null; otherwise, the
+ # The child index. -1 if the enclosing parent panel is nil; otherwise, the
# zero-based index of this mark into the parent panel's <tt>children</tt>
# array.
# @attr [Number]
attr_accessor :child_index
@@ -116,30 +117,35 @@
# Defines a setter-getter for the specified property.
#
# If a cast function has been assigned to the specified property name, the
# property function is wrapped by the cast function, or, if a constant is
# specified, the constant is immediately cast. Note, however, that if the
- # property value is null, the cast function is not invoked.
+ # property value is nil, the cast function is not invoked.
#
# Parameters:
# * @param [String] name the property name.
# * @param [Boolean] +def+ whether is a property or a def.
# * @param [Proc] +cast+ the cast function for this property.
# * @param [Class] +klass+ the klass on which property will be added
def self.property_method(name, _def, func=nil, klass=nil)
return if klass.method_defined? name
- klass.send(:define_method, name) do |*arguments|
+ klass.send(:define_method, name) do |*arguments,&block|
+
v,dummy = arguments
+ if block
+ v=block
+ end
if _def and self.scene
if arguments.size>0
defs[name]=OpenStruct.new({:id=>(v.nil?) ? 0 : Rubyvis.id, :value=> v})
return self
end
return defs[name]
end
- if arguments.size>0
+
+ if arguments.size>0 or block
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)
@@ -377,24 +383,33 @@
def Mark.stack=(v)
@stack=v
end
# Create a new Mark
- def initialize(opts=Hash.new)
+ def initialize(opts=Hash.new, &block)
@_properties=[]
opts.each {|k,v|
self.send("#{k}=",v) if self.respond_to? k
}
@defs={}
@child_index=-1
@index=-1
@index_defined = true
@scale=1
@scene=nil
+ if block
+ block.arity<1 ? self.instance_eval(&block) : block.call(self)
+ end
end
+
+
+
+
+
+
# The mark type; a lower name. The type name controls rendering
# behavior, and unless the rendering engine is extended, must be one of the
# built-in concrete mark types: area, bar, dot, image, label, line, panel,
# rule, or wedge.
def type
@@ -452,23 +467,23 @@
scene
end
#Returns the previous instance of this mark in the scene graph, or
- # null if this is the first instance.
+ # nil if this is the first instance.
#
- # @return a node in the scene graph, or null.
+ # @return a node in the scene graph, or nil.
def sibling
(self.index==0) ? nil: self.scene[self.index-1]
end
# Returns the current instance in the scene graph of this mark,
# in the previous instance of the enclosing parent panel.
- # May return null if this instance could not be found.
+ # May return nil if this instance could not be found.
#
- # @return a node in the scene graph, or null.
+ # @return a node in the scene graph, or nil.
def cousin
par=self.parent
s= par ? par.sibling : nil
(s and s.children) ? s.children[self.child_index][self.index] : nil
end
@@ -967,5 +982,7 @@
require 'rubyvis/mark/line'
require 'rubyvis/mark/rule'
require 'rubyvis/mark/label'
require 'rubyvis/mark/dot'
require 'rubyvis/mark/wedge'
+require 'rubyvis/mark/shorcut_methods'
+