Method: Rubyvis::Mark#build

Defined in:
lib/rubyvis/mark.rb

#buildObject

Evaluates properties and computes implied properties. Properties are stored in the Mark.scene array for each instance of this mark.

As marks are built recursively, the Mark.index property is updated to match the current index into the data array for each mark. Note that the index property is only set for the mark currently being built and its enclosing parent panels. The index property for other marks is unset, but is inherited from the global Mark class prototype. This allows mark properties to refer to properties on other marks in the same panel conveniently; however, in general it is better to reference mark instances specifically through the scene graph rather than depending on the magical behavior of Mark#index.

The root scene array has a special property, data, which stores the current data stack. The first element in this stack is the current datum, followed by the datum of the enclosing parent panel, and so on. The data stack should not be accessed directly; instead, property functions are passed the current data stack as arguments.

<p>The evaluation of the data and visible properties is special. The data property is evaluated first; unlike the other properties, the data stack is from the parent panel, rather than the current mark, since the data is not defined until the data property is evaluated. The visible property is subsequently evaluated for each instance; only if true will the #buildInstance method be called, evaluating other properties and recursively building the scene graph.

<p>If this mark is being re-built, any old instances of this mark that no longer exist (because the new data array contains fewer elements) will be cleared using #clearInstance.

Parameters:

  • parent

    the instance of the parent panel from the scene graph.



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/rubyvis/mark.rb', line 997

def build
  scene=self.scene
  stack=Mark.stack
  if(!scene)
    self.scene=SceneElement.new
    scene=self.scene
    scene.mark=self
    scene.type=self.type
    scene.child_index=self.child_index
    if(self.parent)
      scene.parent=self.parent.scene
      scene.parent_index=self.parent.index
    end
  end
  # Resolve anchor target
  #puts "Resolve target"
  if(self.target)
    scene.target=self.target.instances(scene)
  end
  #pp self.binds
  data=self.binds.data
  #puts "stack:#{stack}"
  #puts "data_value:#{data.value}"

  data=(data._type & 1)>0 ? data.value.js_apply(self, stack) : data.value
  #puts "data:#{data}"

  stack.unshift(nil)
  scene.size=data.size
  data.each_with_index {|d, 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
  delete_index
  stack.shift()
  self
end