A Graph is a collection of items that can be linked to each other.
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: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:Boolean
[read-only]
True if this graph has any nodes at all.
Implementation
public function get hasNodes():Boolean
nodeCount:int
[read-only]
How many items are in this graph.
Implementation
public function get nodeCount():int
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
public function Graph()
public function add(item:Item):void
Add an item to the graph.
Parameters
|
item:Item — an item to add to the graph |
public function empty():void
Remove all items from the graph.
public function find(id:String):Item
Find an item in the graph by id.
Parameters
Returns
|
Item — the item in the graph that has the given id, or null if there is no such item. |
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 |
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. |
public function hasNode(id:String):Boolean
Find out if an item with a given id exists in the graph.
Parameters
Returns
|
Boolean — true if there is an item in the graph with the given id, false otherwise. |
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. |
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. |
public function neighbors(id:String):Object
Get an array of all the items that a given item is linked to.
Parameters
Returns
|
Object — an array of Items |
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. |
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. |
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 object type: flash.events.Event
Dispatched when there is any change to the nodes and/or links of this graph.
public static const CHANGE:String = "change"