- Defined in:
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,
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:
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
, , , , , , , ,
Instance Method Summary collapse
#initialize(target) ⇒ Anchor
Create a new Anchor.
#mark_extend(proto) ⇒ Object
Sets the prototype of this anchor to the specified mark.
Methods inherited from
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
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
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