package flare.vis.data {
import flare.data.DataField;
import flare.data.DataSchema;
import flare.data.DataSet;
import flare.util.Property;
import flare.util.Sort;
import flare.util.Vectors;
import flare.vis.events.DataEvent;
import flash.events.EventDispatcher;
[Event(name="add", type="flare.vis.events.DataEvent")]
[Event(name="remove", type="flare.vis.events.DataEvent")]
/**
* Data structure for managing a collection of visual data objects. The
* Data class manages both unstructured data and data organized in a
* general graph (or network structure), maintaining collections of both
* nodes and edges. Collections of data sprites are maintained by
* DataList instances. The individual data lists provide
* methods for accessing, manipulating, sorting, and generating statistics
* about the visual data objects.
*
*
In addition to the required nodes and edges
* lists, clients can add new custom lists (for example, to manage a
* selected subset of the data) by using the addGroup method
* and then accessing the list with the group method.
* Individual data groups can be directly processed by many of the
* visualization operators in the flare.vis.operator package.
*
*
*
While Data objects maintain a collection of visual DataSprites,
* they are not themselves visual object containers. Instead a Data
* instance is used as input to a Visualization that
* is responsible for processing the DataSprite instances and adding
* them to the Flash display list.
*
*
The data class also manages the automatic generation of spanning
* trees over a graph when needed for tree-based operations (such as tree
* layout algorithms). This implemented by a
* flare.analytics.graph.SpanningTree operator which can be
* parameterized using the treePolicy,
* treeEdgeWeight, and root properties of this
* class. Alternatively, clients can create their own spanning trees as
* a Tree
*
* @see flare.vis.data.DataList
* @see flare.analytics.graph.SpanningTree
*/
public class Data extends EventDispatcher
{
/** Constant indicating the nodes in a Data object. */
public static const NODES:String = "nodes";
/** Constant indicating the edges in a Data object. */
public static const EDGES:String = "edges";
/** Internal list of NodeSprites. */
protected var _nodes:DataList = new DataList(NODES);
/** Internal list of EdgeSprites. */
protected var _edges:DataList = new DataList(EDGES);
/** Internal set of data groups. */
protected var _groups:Object;
/** The total number of items (nodes and edges) in the data. */
public function get length():int { return _nodes.length + _edges.length; }
/** The collection of NodeSprites. */
public function get nodes():DataList { return _nodes; }
/** The collection of EdgeSprites. */
public function get edges():DataList { return _edges; }
/** The default directedness of new edges. */
public var directedEdges:Boolean;
// -- Methods ---------------------------------------------------------
/**
* Creates a new Data instance.
* @param directedEdges the default directedness of new edges
*/
public function Data(directedEdges:Boolean=false) {
this.directedEdges = directedEdges;
_groups = { nodes: _nodes, edges: _edges };
// add listeners to enforce type and connectivity constraints
_nodes.addEventListener(DataEvent.ADD, onAddNode);
_nodes.addEventListener(DataEvent.REMOVE, onRemoveNode);
_edges.addEventListener(DataEvent.ADD, onAddEdge);
_edges.addEventListener(DataEvent.REMOVE, onRemoveEdge);
}
/**
* Creates a new Data instance from an array of tuples. The object in
* the vector will become the data objects for NodeSprites.
* @param a an array of data objects
* @return a new Data instance, with NodeSprites populated with the
* input data.
*/
public static function fromArray(a:Array):Data {
var d:Data = new Data();
for each (var tuple:Object in a) {
d.addNode(tuple);
}
return d;
}
/**
* Creates a new Data instance from an object vector of tuples. The object in
* the vector will become the data objects for NodeSprites.
* @param a an Object Vector of data objects
* @return a new Data instance, with NodeSprites populated with the
* input data.
*/
public static function fromVector(a:Vector.