Package com.adobe.flex.extras.controls.springgraph
Class public class Graph
Inheritance Graph Inheritance flash.events.EventDispatcher

A Graph is a collection of items that can be linked to each other.



Public Properties
  Property Defined by
    distinguishedItem : Item
Sometimes it's handy for the graph to remember one particular item.
Graph
    edges : Array
[read-only] An array of all the links in the graph.
Graph
    hasNodes : Boolean
[read-only] True if this graph has any nodes at all.
Graph
    nodeCount : int
[read-only] How many items are in this graph.
Graph
    nodes : Object
[read-only] An associative array of all the items in the graph.
Graph
Public Methods
  Method Defined by
   
Graph()
Graph
   
add(item:Item):void
Add an item to the graph.
Graph
   
empty():void
Remove all items from the graph.
Graph
   
find(id:String):Item
Find an item in the graph by id.
Graph
   
fromXML(xml:XML, strings:Array):Graph
[static] Creates a graph from XML.
Graph
   
getLinkData(item1:Item, item2:Item):Object
retrieve the data that is associated with a link.
Graph
   
hasNode(id:String):Boolean
Find out if an item with a given id exists in the graph.
Graph
   
link(item1:Item, item2:Item, data:Object = null):void
Link 2 items.
Graph
   
linked(item1:Item, item2:Item):Boolean
Find out if two items are linked.
Graph
   
neighbors(id:String):Object
Get an array of all the items that a given item is linked to.
Graph
   
numLinks(item:Item):int
Find out how many items are linked to a given item.
Graph
   
remove(item:Item):void
Removes an item from the graph.
Graph
   
unlink(item1:Item, item2:Item):void
Remove the link between 2 items.
Graph
Events
  Event Summary Defined by
    Dispatched when there is any change to the nodes and/or links of this graph. Graph
Public Constants
  Constant Defined by
    CHANGE : String = "change"
[static]
Graph
Property detail
distinguishedItem property
distinguishedItem:Item  [read-write]

Sometimes it's handy for the graph to remember one particular item. You can use this for any purpose you like, it's not used internally by the Graph. By default, the distinguished item is the first item that was added to this graph.

Implementation
    public function get distinguishedItem():Item
    public function set distinguishedItem(value:Item):void
edges property  
edges:Array  [read-only]

An array of all the links in the graph. Each array element is an array of 2 strings, which are the ids of two items that are linked.

Implementation
    public function get edges():Array
hasNodes property  
hasNodes:Boolean  [read-only]

True if this graph has any nodes at all.

Implementation
    public function get hasNodes():Boolean
nodeCount property  
nodeCount:int  [read-only]

How many items are in this graph.

Implementation
    public function get nodeCount():int
nodes property  
nodes:Object  [read-only]

An associative array of all the items in the graph. The key is the id, the value is the Item.

Implementation
    public function get nodes():Object
Constructor detail
Graph () constructor
public function Graph()
Method detail
add () method
public function add(item:Item):void

Add an item to the graph.

Parameters
item:Item — an item to add to the graph
empty () method  
public function empty():void

Remove all items from the graph.

find () method  
public function find(id:String):Item

Find an item in the graph by id.

Parameters
id:String — any String

Returns
Item — the item in the graph that has the given id, or null if there is no such item.
fromXML () method  
public static function fromXML(xml:XML, strings:Array):Graph

Creates a graph from XML. The XML you provide should contain 2 kinds of elements
<Node id="xxx" anything-else..../>
and
<Edge fromID="xxx" toID="yyy"/>

You can have additional tags, and/or nest the tags any way you like; this will not have any effect. We create a graph where each Item corresponds to a single node. The item's id will come from the Node's id attribute (make sure this is unique). The item's data will be the Node, and will be of type XML. The <Edge> elements must come fterthe corresponding <Node> elements have appeared. Edges are not directional, you can interchange fromID and toID with no effect. Parameters

xml:XML — an XML document containing Node and Edge elements
 
strings:Array — the XML element and attribute names to use when parsing an XML dataProvider. The array must have 4 elements:
  • the element name that defines nodes
  • the element name that defines edges
  • the edge attribute name that defines the 'from' node
  • the edge attribute name that defines the 'to' node

Returns
Graph — a graph that corresponds to the Node and Edge elements in the input
getLinkData () method  
public function getLinkData(item1:Item, item2:Item):Object

retrieve the data that is associated with a link.

Parameters
item1:Item — an item in the graph
 
item2:Item — an item in the graph

Returns
Object — Object the data that was associated with the link between the two items. If no data, or null, was associated with the link, we return 0. If there is no link between the items, we return null.
hasNode () method  
public function hasNode(id:String):Boolean

Find out if an item with a given id exists in the graph.

Parameters
id:String — any String

Returns
Boolean — true if there is an item in the graph with the given id, false otherwise.
link () method  
public function link(item1:Item, item2:Item, data:Object = null):void

Link 2 items. This has no effect if the 2 items are already linked. Links are not directional: link(a,b) is equivalent to link(b,a).

Parameters
item1:Item — an item in the graph
 
item2:Item — an item in the graph
 
data:Object (default = null) — any data you like, or null. The Graph doesn't ever look at this, but you may find it convenient to store here. You can use getLinkData to retrieve this data later.
linked () method  
public function linked(item1:Item, item2:Item):Boolean

Find out if two items are linked.

Parameters
item1:Item — an item in the graph
 
item2:Item — an item in the graph

Returns
Boolean — true if the two items are linked to each other.
neighbors () method  
public function neighbors(id:String):Object

Get an array of all the items that a given item is linked to.

Parameters
id:String — any String

Returns
Object — an array of Items
numLinks () method  
public function numLinks(item:Item):int

Find out how many items are linked to a given item.

Parameters
item:Item — an item in the graph

Returns
int — thes number of items to which this item is linked.
remove () method  
public function remove(item:Item):void

Removes an item from the graph.

Parameters
item:Item — The item that you want to remove from the graph.
unlink () method  
public function unlink(item1:Item, item2:Item):void

Remove the link between 2 items.

Parameters
item1:Item — an item in the graph that is linked to item2
 
item2:Item — an item in the graph that is linked to item1
Event detail
changed event 
Event object type: flash.events.Event

Dispatched when there is any change to the nodes and/or links of this graph.

Constant detail
CHANGE constant
public static const CHANGE:String = "change"