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

Allows the alignment of nodes into a grid, i.e. perform some kind of prealignment using the pos attribute However, this will only work when: (a) using the 'canon' renderer and (b) using fdp for later layouting. For example: More...

#include <GraphvizGridStyle.hpp>

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

Public Types

typedef shared_ptr< GraphvizGridStyle > Ptr
 
- Public Types inherited from graph_analysis::io::GraphvizStyle
typedef shared_ptr< GraphvizStyle > Ptr
 

Public Member Functions

 GraphvizGridStyle (size_t rows, size_t columns, VertexRowMapper rowMapperFunction, VertexColumnMapper columnMapperFunction)
 
virtual ~GraphvizGridStyle ()
 
void setColumnScalingFactor (double f)
 
double getColumnScalingFactor () const
 
void setRowScalingFactor (double f)
 
double getRowScalingFactor () const
 
virtual void apply (const Edge::Ptr &edge, GVGraph *gvGraph, const BaseGraph::Ptr &graph) const
 
virtual void apply (const Vertex::Ptr &vertex, GVGraph *gvGraph, const BaseGraph::Ptr &graph) const
 
- Public Member Functions inherited from graph_analysis::io::GraphvizStyle
 GraphvizStyle ()
 
virtual ~GraphvizStyle ()
 

Detailed Description

Allows the alignment of nodes into a grid, i.e. perform some kind of prealignment using the pos attribute However, this will only work when: (a) using the 'canon' renderer and (b) using fdp for later layouting. For example:

class RowColumnVertex : public graph_analysis::Vertex
{
public:
    typedef shared_ptr<RowColumnVertex> Ptr;

    RowColumnVertex(const std::string& name, size_t row, size_t column)
        : graph_analysis::Vertex(name)
        , row(row)
        , column(column)
    {}

    virtual std::string getClassName() const{ return "RowColumnVertex"; }

    size_t row;
    size_t column;

    static size_t getRow(const graph_analysis::Vertex::Ptr& vertex)
    {
        return dynamic_pointer_cast<RowColumnVertex>(vertex)->row;
    }

    static size_t getColumn(const graph_analysis::Vertex::Ptr& vertex)
    {
        return dynamic_pointer_cast<RowColumnVertex>(vertex)->column;
    }

protected:
    virtual graph_analysis::Vertex* getClone() const { return new RowColumnVertex(getLabel(), row, column); }

};
    io::GraphvizWriter gvWriter("dot","canon");
    io::GraphvizGridStyle::Ptr style(new io::GraphvizGridStyle(3,3,
                &RowColumnVertex::getRow,
                &RowColumnVertex::getColumn
                ));
    style->setColumnScalingFactor(2.0);
    style->setRowScalingFactor(2.0);
    gvWriter.setStyle(style);

    gvWriter.write("graphviz_grid_layout.dot", graph);

Eventually render with:

 xdot -f fdp graphviz_grid_layout.dot

or

 dot -s -Kfdp -Tpng graphviz_grid_layout.dot > layouted_grid.png

TODO: alternatively one could use an approach using rankdir and {rank=same; ...}

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ GraphvizGridStyle()

graph_analysis::io::GraphvizGridStyle::GraphvizGridStyle ( size_t  rows,
size_t  columns,
VertexRowMapper  rowMapperFunction,
VertexColumnMapper  columnMapperFunction 
)

◆ ~GraphvizGridStyle()

graph_analysis::io::GraphvizGridStyle::~GraphvizGridStyle ( )
virtual

Member Function Documentation

◆ apply() [1/2]

virtual void graph_analysis::io::GraphvizGridStyle::apply ( const Edge::Ptr &  edge,
GVGraph *  gvGraph,
const BaseGraph::Ptr &  graph 
) const
inlinevirtual

Apply style to an edge, e.g. by implementing the style

gvGraph->setAttribute(edge,"color","red");

Reimplemented from graph_analysis::io::GraphvizStyle.

◆ apply() [2/2]

void graph_analysis::io::GraphvizGridStyle::apply ( const Vertex::Ptr &  vertex,
GVGraph *  gvGraph,
const BaseGraph::Ptr &  graph 
) const
virtual

Apply style to a vertex

gvGraph->setAttribute(vertex,"color","blue");

Reimplemented from graph_analysis::io::GraphvizStyle.

◆ getColumnScalingFactor()

double graph_analysis::io::GraphvizGridStyle::getColumnScalingFactor ( ) const
inline

◆ getRowScalingFactor()

double graph_analysis::io::GraphvizGridStyle::getRowScalingFactor ( ) const
inline

◆ setColumnScalingFactor()

void graph_analysis::io::GraphvizGridStyle::setColumnScalingFactor ( double  f)
inline

◆ setRowScalingFactor()

void graph_analysis::io::GraphvizGridStyle::setRowScalingFactor ( double  f)
inline

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