graph_analysis
Public Member Functions | List of all members
graph_analysis::io::GraphvizWriter Class Reference

graphviz based graph renderer More...

#include <GraphvizWriter.hpp>

Inheritance diagram for graph_analysis::io::GraphvizWriter:
Inheritance graph
[legend]
Collaboration diagram for graph_analysis::io::GraphvizWriter:
Collaboration graph
[legend]

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
 

Detailed Description

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);

Constructor & Destructor Documentation

◆ GraphvizWriter()

graph_analysis::io::GraphvizWriter::GraphvizWriter ( const std::string &  layout = "dot",
const std::string &  renderer = "dot" 
)

constructor

◆ ~GraphvizWriter()

graph_analysis::io::GraphvizWriter::~GraphvizWriter ( )

destructor

Member Function Documentation

◆ setStyle()

void graph_analysis::io::GraphvizWriter::setStyle ( const GraphvizStyle::Ptr &  style)
inline

Allow to set a style sheet

◆ write() [1/2]

void graph_analysis::io::GraphvizWriter::write ( const std::string &  filename,
const BaseGraph &  graph 
) const

outputs the given graph to the given file

Parameters
filenamerequested output filename
graphrequested graph to be printed

◆ write() [2/2]

void graph_analysis::io::GraphvizWriter::write ( const std::string &  filename,
const BaseGraph::Ptr &  graph 
) const
virtual

outputs the given graph to the given file

Parameters
filenamerequested output filename
graphsmart pointer to the requested graph to be printed

Reimplemented from graph_analysis::io::Writer.


The documentation for this class was generated from the following files: