11 #include "AdjacencyList.h"
12 #include "ForceLayout.h"
13 #include "bubble_tree_layout.h"
14 #include "tree_layout.h"
16 #include "graph_filter_list.h"
17 #include "graph_properties.h"
30 template<
typename V_type,
typename E_type,
typename V_CompareFunctor,
typename E_CompareFunctor = CompareSWUDependency >
class Grapher {
39 if(g.position_map_ != 0)
44 if(position_map_ != 0)
67 typedef std::map<V_type, index_type_t, V_CompareFunctor>
node_map_t;
73 typedef std::map< std::pair< index_type_t, index_type_t> , E_type>
edge_map_t;
90 typedef typename node_data_t::const_iterator const_node_iterator;
96 typedef typename edge_map_t::const_iterator const_edge_iterator;
105 if(position_map_ != 0)
106 delete position_map_;
112 position_map_ = Layout::layout(g_, 100, width, height);
115 position_map_ = Layout::bubble_tree_layout(g_);
119 position_map_ = Layout::tree_layout(g_);
128 if(v == 0 || l == FORCE) {
133 if(position_map_ != 0)
134 delete position_map_;
140 position_map_ = Layout::bubble_tree_layout(g_,
vertex(v));
144 position_map_ = Layout::tree_layout(g_,
vertex(v));
151 return (position_map_ != 0);
159 return node_map_.size();
164 return edge_data_.size();
169 return node_data_.size();
173 position_map_t::value_type
position(
const V_type v) {
174 if(position_map_ != 0) {
175 if(position_map_->size() > node_map_[v])
176 return position_map_->at(node_map_[v]);
178 return std::make_pair(0,0);
180 return std::make_pair(0,0);
185 typename node_map_t::iterator it = node_map_.find(v);
188 return (it != node_map_.end()) ;
206 node_data_[node] = v;
209 incoming_map_[node] = std::set<index_type_t>();
219 bool add_edge(V_type from, V_type to, E_type edge_data) {
223 if (filter_ != NULL) {
224 if (!(*filter_)(edge_data)) {
234 edge_data_[std::make_pair(u,v)] = edge_data;
237 incoming_map_[v].insert(u);
248 return node_map_[node];
255 typename node_data_t::iterator it = node_data_.find(index);
257 if (it != node_data_.end()) {
258 return node_data_[index];
266 std::vector<E_type>*
edges(V_type v){
267 std::vector<E_type>* return_edges =
new std::vector<E_type>();
269 std::set<index_type_t>&
edges = *g_.adjacent_vertices(node_map_[v]);
271 std::set<index_type_t>::iterator it = edges.begin();
272 for (; it != edges.end(); it++) {
273 return_edges->push_back(edge_data_[std::make_pair(node_map_[v], *it)]);
282 std::vector<E_type>* return_edges =
new std::vector<E_type>();
286 std::set<index_type_t>::iterator it = incoming_map_[ni].begin();
288 for (; it != incoming_map_[ni].end(); it++) {
289 return_edges->push_back(edge_data_[std::make_pair(*it, ni)]);
unsigned int num_edges()
Returns the current number of edges in the graph.
Definition: grapher.h:163
index_type_t vertex(V_type node)
Definition: grapher.h:245
V_CompareFunctor comparator
Accessor for the type of comparator used.
Definition: grapher.h:61
GraphProperties< GraphType > & properties()
Fetch the properties.
Definition: grapher.h:155
position_map_t::value_type position(const V_type v)
Fetches the position in a std::pair<int, int> of a specific vertex data.
Definition: grapher.h:173
Definition: AdjacencyList.h:9
bool add_node(V_type v)
Definition: grapher.h:196
node_data_t::iterator node_iterator
Type used to iterate over nodes.
Definition: grapher.h:89
unsigned int num_nodes()
Returns the current number of nodes in the graph.
Definition: grapher.h:158
std::vector< std::pair< int, int > > position_map_t
Definition: grapher.h:77
void set_filter(GraphFilterList< GraphType > *filter)
Definition: grapher.h:306
std::map< index_type_t, std::set< index_type_t > > incoming_map_t
Type for datastructure that holds all in-edges for every node.
Definition: grapher.h:64
bool exists(V_type v)
Check a specific vertex exists in the graph.
Definition: grapher.h:184
std::map< std::pair< index_type_t, index_type_t >, E_type > edge_map_t
Type used to map between an edge (pairs of index types) and data stored in that edge.
Definition: grapher.h:73
Definition: graph_filter_list.h:16
void Layout(double width, double height, LayoutType l=HIERARCHY)
Runs a layout on the graph.
Definition: grapher.h:104
std::vector< E_type > * edges(V_type v)
Definition: grapher.h:266
E_type edge_value_type
Accessor for the type of value stored in the edges.
Definition: grapher.h:58
std::map< index_type_t, V_type > node_data_t
Type for the map between nodes and indexes (used to find the node given a node index) ...
Definition: grapher.h:70
Definition: graph_properties.h:7
V_type node_value_type
Accessor for the type of value stored in the nodes.
Definition: grapher.h:55
const GraphFilterList< GraphType > * filter()
Definition: grapher.h:297
std::map< E_type, property_map_t *, E_CompareFunctor > edge_property_map_t
Type used to map an edge type to its propertymap.
Definition: grapher.h:86
std::map< V_type, property_map_t *, V_CompareFunctor > node_property_map_t
Type used to map a node type to its propertymap.
Definition: grapher.h:83
std::map< std::string, std::string > property_map_t
Type used to map a property (as string) to a value (as string)
Definition: grapher.h:80
std::vector< E_type > * incoming_edges(V_type v)
Definition: grapher.h:281
unsigned int num_nodedata()
Returns the size of the node data (1 edge has 2 data entries)
Definition: grapher.h:168
bool has_layout()
Returns true if there is a layout.
Definition: grapher.h:150
LayoutType
Layout types available to use.
Definition: grapher.h:101
V_type vertex(index_type_t index)
Definition: grapher.h:254
std::map< V_type, index_type_t, V_CompareFunctor > node_map_t
Type for the map between node values and index types (used to find an index given a node) ...
Definition: grapher.h:67
Grapher(const Grapher &g)
Copy-constructor, required to ensure the position_map_ is appropriately copied.
Definition: grapher.h:38
unsigned int index_type_t
The type of index used for the nodes in the graph.
Definition: grapher.h:52
Grapher< V_type, E_type, V_CompareFunctor, E_CompareFunctor > GraphType
This type of graph.
Definition: grapher.h:49
edge_map_t::iterator edge_iterator
Type used to iterate over edges.
Definition: grapher.h:95
bool add_edge(V_type from, V_type to, E_type edge_data)
Definition: grapher.h:219
void Layout(V_type v, double width, double height, LayoutType l=HIERARCHY)
Definition: grapher.h:127