Class: Rubyvis::Layout::Hierarchy
- Defined in:
- lib/rubyvis/layout/hierarchy.rb
Overview
Represents an abstract layout for hierarchy diagrams. This class is a specialization of Rubyvis::Layout::Network, providing the basic structure for both hierarchical node-link diagrams (such as Reingold-Tilford trees) and space-filling hierarchy diagrams (such as sunbursts and treemaps).
<p>Unlike general network layouts, the links
property need not be defined explicitly. Instead, the links are computed implicitly from the parent_node
attribute of the node objects, as defined by the nodes
property. This implementation is also available as +Hierarchy.links, for reuse with non-hierarchical layouts; for example, to render a tree using force-directed layout.
<p>Correspondingly, the nodes
property is represented as a union of Rubyvis::Layout::Network::Node} and Rubyvis::Dom::Node. To construct a node hierarchy from a simple JSON map, use the Rubyvis::Dom operator; this operator also provides an easy way to sort nodes before passing them to the layout.
<p>For more details on how to use this layout, see Rubyvis::Layout::Network
Instance Attribute Summary
Attributes inherited from Network
#_id, #link, #node, #node_label
Attributes inherited from Panel
Attributes inherited from Mark
#_properties, #binds, #child_index, #parent, #proto, #root, #scale, #scene, #target
Instance Method Summary collapse
- #build_implied(s) ⇒ Object
- #hierarchy_build_implied(s) ⇒ Object
-
#initialize ⇒ Hierarchy
constructor
A new instance of Hierarchy.
-
#links ⇒ Object
The implied links; computes links using the
parent_node
attribute.
Methods inherited from Network
#_link, #_node, #_node_label, #build_properties, #network_build_implied, #nodes, #reset
Methods inherited from Rubyvis::Layout
Arc, Cluster, Grid, Hierarchy, Horizon, Indent, Matrix, Network, Pack, Partition, Stack, Tree, Treemap, attr_accessor_dsl, #build_properties, #layout_build_implied, #layout_build_properties
Methods inherited from Panel
#add, #anchor, #bind, #build_instance, #children_inspect, defaults, #panel_build_implied, #to_svg, #type
Methods inherited from Bar
Methods inherited from Mark
#add, #anchor, #area, attr_accessor_dsl, #bar, #bind, #build, #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_extend, mark_method, #panel, #properties, properties, property_method, #property_value, #render, #rule, scene, scene=, #sibling, stack, stack=, #type, #wedge
Constructor Details
#initialize ⇒ Hierarchy
Returns a new instance of Hierarchy.
36 37 38 39 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 36 def initialize super @link.stroke_style("#ccc") end |
Instance Method Details
#build_implied(s) ⇒ Object
40 41 42 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 40 def build_implied(s) hierarchy_build_implied(s) end |
#hierarchy_build_implied(s) ⇒ Object
44 45 46 47 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 44 def hierarchy_build_implied(s) s.links=self.links() if !s.links network_build_implied(s) end |
#links ⇒ Object
The implied links; computes links using the parent_node
attribute.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubyvis/layout/hierarchy.rb', line 50 def links l=self.nodes().find_all {|n| n.parent_node} l.map {|n| Network::Link.new({ :source_node=>n, :target_node=>n.parent_node, :link_value=>1 })} end |