Class Index | File Index

Classes


Class pv.Anchor


Extends pv.Mark.
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,

bar.anchor("top").add(pv.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 (textAlign and textBaseline).

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 pv.Mark#extend before adding. For example:

bar.anchor("top").extend(bar).add(pv.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.
Defined in: Anchor.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
pv.Anchor(target)
Constructs a new mark anchor with default properties.
Field Summary
Field Attributes Field Name and Description
 
The anchor name.
Fields borrowed from class pv.Mark:
bottom, childIndex, cursor, data, defaults, events, index, left, parent, proto, reverse, right, root, scale, title, top, type, visible
Method Summary
Method Attributes Method Name and Description
 
Returns the anchor target of this mark, if it is derived from an anchor; otherwise returns null.
Methods borrowed from class pv.Mark:
add, anchor, def, event, extend, margin, mouse, render
Class Detail
pv.Anchor(target)
Constructs a new mark anchor with default properties.
Parameters:
{pv.Mark} target
the anchor target.
Field Detail
{string} name
The anchor name. The set of supported anchor names is dependent on the concrete mark type; see the mark type for details. For example, bars support left, right, top and bottom anchors.

While anchor names are typically constants, the anchor name is a true property, which means you can specify a function to compute the anchor name dynamically. For instance, if you wanted to alternate top and bottom anchors, saying

m.anchor(function() (this.index % 2) ? "top" : "bottom").add(pv.Dot);
would have the desired effect.
Method Detail
{pv.Mark} anchorTarget()
Returns the anchor target of this mark, if it is derived from an anchor; otherwise returns null. For example, if a label is derived from a bar anchor,
bar.anchor("top").add(pv.Label);
then property functions on the label can refer to the bar via the anchorTarget method. This method is also useful for mark types defining properties on custom anchors.
Returns:
{pv.Mark} the anchor target of this mark; possibly null.

Documentation generated by JsDoc Toolkit 2.3.2 on Sun May 30 2010 18:10:23 GMT-0700 (PDT)