Class: Rubyvis::Anchor
Overview
Represents an anchor on a given mark. An anchor is itself a mark, but without a visual representation. It serves only to provide useful default properties that can be inherited by other marks. Each type of mark can define any number of named anchors for convenience. If the concrete mark type does not define an anchor implementation specifically, one will be inherited from the mark’s parent class.
For example, the bar mark provides anchors for its four sides: left, right, top and bottom. Adding a label to the top anchor of a bar,
.anchor("top").add(Rubyvis::Label)
will render a text label on the top edge of the bar; the top anchor defines the appropriate position properties (top and left), as well as text-rendering properties for convenience (text_align and text_baseline).
<p>Note that anchors do not inherit from their targets; the positional properties are copied from the scene graph, which guarantees that the anchors are positioned correctly, even if the positional properties are not defined deterministically. (In addition, it also improves performance by avoiding re-evaluating expensive properties.) If you want the anchor to inherit from the target, use Mark#extend before adding. For example:
.anchor("top").extend().add(Rubyvis::Label)
The anchor defines it’s own positional properties, but other properties (such as the title property, say) can be inherited using the above idiom. Also note that you can override positional properties in the anchor for custom behavior.
Instance Attribute Summary
Attributes inherited from Mark
#_properties, #binds, #child_index, #parent, #proto, #root, #scale, #scene, #target
Instance Method Summary collapse
-
#initialize(target) ⇒ Anchor
constructor
Create a new Anchor.
-
#mark_extend(proto) ⇒ Object
Sets the prototype of this anchor to the specified mark.
Methods inherited from Mark
#add, #anchor, #area, attr_accessor_dsl, #bar, #bind, #build, #build_implied, #build_instance, #build_properties, #context, #context_apply, #context_clear, #cousin, defaults, #delete_index, #dot, #event, #execute, #first, #image, index, #index, index=, #index=, #index_defined?, #instance, #instances, #label, #last, #layout_arc, #layout_cluster, #layout_grid, #layout_horizon, #layout_indent, #layout_matrix, #layout_pack, #layout_partition, #layout_partition_fill, #layout_stack, #layout_tree, #layout_treemap, #line, #margin, #mark_anchor, #mark_bind, #mark_build_implied, #mark_build_instance, #mark_build_properties, mark_method, #panel, #properties, properties, property_method, #property_value, #render, #rule, scene, scene=, #sibling, stack, stack=, #type, #wedge
Constructor Details
#initialize(target) ⇒ Anchor
Create a new Anchor. Use Mark.add instead.
58 59 60 61 62 63 |
# File 'lib/rubyvis/mark/anchor.rb', line 58 def initialize(target) self.target=target self.parent=target.parent super() end |
Instance Method Details
#mark_extend(proto) ⇒ Object
Sets the prototype of this anchor to the specified mark. Any properties not defined on this mark may be inherited from the specified prototype mark, or its prototype, and so on. The prototype mark need not be the same type of mark as this mark. (Note that for inheritance to be useful, properties with the same name on different mark types should have equivalent meaning.)
<p>This method differs slightly from the normal mark behavior in that the anchor’s target is preserved.
78 79 80 81 |
# File 'lib/rubyvis/mark/anchor.rb', line 78 def mark_extend(proto) @proto=proto self end |