|
graph_analysis
|
graphviz based graph renderer More...
#include <GraphvizWriter.hpp>


Public Member Functions | |
| GraphvizWriter (const std::string &layout="dot", const std::string &renderer="dot") | |
| constructor More... | |
| ~GraphvizWriter () | |
| destructor More... | |
| void | setStyle (const GraphvizStyle::Ptr &style) |
| void | write (const std::string &filename, const BaseGraph &graph) const |
| outputs the given graph to the given file More... | |
| void | write (const std::string &filename, const BaseGraph::Ptr &graph) const |
| outputs the given graph to the given file More... | |
Public Member Functions inherited from graph_analysis::io::Writer | |
| virtual | ~Writer () |
| void | write (const std::string &filename, const BaseGraph &graph) const |
Additional Inherited Members | |
Public Types inherited from graph_analysis::io::Writer | |
| typedef shared_ptr< Writer > | Ptr |
graphviz based graph renderer
Exports a given base graph to a given dot file using GraphViz renderToFile() interface Vertex and Edges are rendered using their toString() methods For details check GVGraph::getUniqueName
In order to apply a certain style to the graph output, the GraphvizWriter provides a GraphvizStyle to implement some hooks
#include "io/GVGraph.hpp"
using namespace graph_analysis;
class SimpleStyle : public io::GraphvizStyle
{
public:
void apply(const Edge::Ptr& edge, io::GVGraph* gvGraph, const BaseGraph::Ptr& graph) const
{
gvGraph->setAttribute(edge, "color", "red");
gvGraph->setAttribute(edge, "weight", "10");
gvGraph->setAttribute(edge, "arrowsize", "2");
gvGraph->setAttribute(edge, "penwidth", "3");
}
void apply(const Vertex::Ptr& vertex, io::GVGraph* gvGraph, const BaseGraph::Ptr& graph) const
{
gvGraph->setAttribute(vertex, "color", "blue");
gvGraph->setAttribute(vertex, "shape", "diamond");
gvGraph->setAttribute(vertex, "penwidth", "3");
}
};
You need to register the style with the GraphvizWriter before writing. Note, that the default writer used by GraphIO::write will not have any style associated.
BaseGraph::Ptr graph = BaseGraph::getInstance();
Vertex::Ptr v0(new Vertex("v0"));
Vertex::Ptr v1(new Vertex("v1"));
Vertex::Ptr v2(new Vertex("v2"));
Edge::Ptr e0(new Edge(v0,v1,"e0"));
Edge::Ptr e1(new Edge(v1,v2,"e1"));
Edge::Ptr e2(new Edge(v2,v0,"e2"));
graph->addEdge(e0);
graph->addEdge(e1);
graph->addEdge(e2);
io::GraphvizWriter gvWriter;
io::GraphvizStyle::Ptr style(new SimpleStyle());
gvWriter.setStyle(style);
gvWriter.write("styled-graph.dot",graph);
| graph_analysis::io::GraphvizWriter::GraphvizWriter | ( | const std::string & | layout = "dot", |
| const std::string & | renderer = "dot" |
||
| ) |
constructor
| graph_analysis::io::GraphvizWriter::~GraphvizWriter | ( | ) |
destructor
|
inline |
Allow to set a style sheet
| void graph_analysis::io::GraphvizWriter::write | ( | const std::string & | filename, |
| const BaseGraph & | graph | ||
| ) | const |
outputs the given graph to the given file
| filename | requested output filename |
| graph | requested graph to be printed |
|
virtual |
outputs the given graph to the given file
| filename | requested output filename |
| graph | smart pointer to the requested graph to be printed |
Reimplemented from graph_analysis::io::Writer.
1.8.17