class Rubyvis::Layout::Network

Represents an abstract layout for network diagrams. This class provides the basic structure for both node-link diagrams (such as force-directed graph layout) and space-filling network diagrams (such as sunbursts and treemaps). Note that “network” here is a general term that includes hierarchical structures; a tree is represented using links from child to parent.

Network layouts require the graph data structure to be defined using two properties:<ul>

<li>nodes - an array of objects representing nodes. Objects in this array must conform to the Rubyvis::Layout::Network::Node interface; which is to say, be careful to avoid naming collisions with automatic attributes such as index and link_degree. If the nodes property is defined as an array of primitives, such as numbers or strings, these primitives are automatically wrapped in an object; the resulting object’s node_value attribute points to the original primitive value.

<p><li>links - an array of objects representing links. Objects in this array must conform to the Rubyvis::Layout::Network::Link interface; at a minimum, either source and target indexes or source_node and target_node references must be set. Note that if the links property is defined after the nodes property, the links can be defined in terms of this.nodes().

</ul>

<p>Three standard mark prototypes are provided:<ul>

<li>node - for rendering nodes; typically a Rubyvis::Dot. The node mark is added directly to the layout, with the data property defined via the layout’s nodes property. Properties such as stroke_style and fillStyle can be overridden to compute properties from node data dynamically.

<p><li>link - for rendering links; typically a Rubyvis::Line. The link mark is added to a child panel, whose data property is defined as layout’s links property. The link’s data property is then a two-element array of the source node and target node. Thus, poperties such as stroke_style and fill_style can be overridden to compute properties from either the node data (the first argument) or the link data (the second argument; the parent panel data) dynamically.

<p><li>node_label - for rendering node labels; typically a Rubyvis::Label. The label mark is added directly to the layout, with the data property defined via the layout’s nodes property. Properties such as strokeStyle and fillStyle can be overridden to compute properties from node data dynamically.

</ul>Note that some network implementations may not support all three standard mark prototypes; for example, space-filling hierarchical layouts typically do not use a link prototype, as the parent-child links are implied by the structure of the space-filling node marks. Check the specific network layout for implementation details.

<p>Network layout properties, including nodes and links, are typically cached rather than re-evaluated with every call to render. This is a performance optimization, as network layout algorithms can be expensive. If the network structure changes, call {@link reset} to clear the cache before rendering. Note that although the network layout properties are cached, child mark properties, such as the marks used to render the nodes and links, are not. Therefore, non-structural changes to the network layout, such as changing the color of a mark on mouseover, do not need to reset the layout.

@see Rubyvis::Layout::Hierarchy @see Rubyvis::Layout::Force @see Rubyvis::Layout::Matrix @see Rubyvis::Layout::Arc @see Rubyvis::Layout::Rollup

Attributes

_id[RW]
node[RW]

The node prototype. This prototype is intended to be used with a Dot mark in conjunction with the link prototype.

node_label[RW]

The node label prototype, which renders the node name adjacent to the node. This prototype is provided as an alternative to using the anchor on the node mark; it is primarily intended to be used with radial node-link layouts, since it provides a convenient mechanism to set the text angle.

NOTE FOR PROTOVIS USERS: The original name of method was label but it was replaced to not conflict with rubyvis shortcut method Mark.label()

nodes[RW]

an array of objects representing nodes. Objects in this array must conform to the Rubyvis::Layout::Network::Node interface; which is to say, be careful to avoid naming collisions with automatic attributes such as index and link_degree. If the nodes property is defined as an array of ‘primitives’ (objects which doesn’t respond to node_value) these primitives are automatically wrapped in an OpenStruct object; the resulting object’s node_value attribute points to the original primitive value.

Public Class Methods

new() click to toggle source
# File lib/rubyvis/layout/network.rb, line 91
def initialize
  super
  @_id=Rubyvis.id()
  @node=_node
  @link=_link
  @node_label=_node_label
end

Public Instance Methods

reset() click to toggle source

Resets the cache, such that changes to layout property definitions will be visible on subsequent render. Unlike normal marks (and normal layouts), properties associated with network layouts are not automatically re-evaluated on render; the properties are cached, and any expensive layout algorithms are only run after the layout is explicitly reset.

(@returns Rubyvis::Layout::Network) self

# File lib/rubyvis/layout/network.rb, line 204
def reset
  self._id=Rubyvis.id()
  self
end