In the post Fun with Graphs (3): Creating the graph of a database structure, I have presented a small application that creates the graph of a database. We are now going to improve the output by adding the different fields, primary keys, etc.. in the graph.
GraphvizRecordCell
Graphviz supports a type of vertex shape that is drawed as nested tables. This shape is called Record. NGraphviz comes with a class wrapper (GraphvizRecordCell) that lets you easily create such records. Some remarks on cells:
Let's take the formatVertex event handler and adapt it to create records:
private void formatVertex(Object sender, FormatVertexEventArgs e) { TableSchemaVertex v = (TableSchemaVertex)e.Vertex; GraphvizRecord record = new GraphvizRecord(); e.VertexFormatter.Shape = GraphvizVertexShape.Record; e.VertexFormatter.Record = record; GraphvizRecordCell table = new GraphvizRecordCell(); record.Cells.Add(table); GraphvizRecordCell name = new GraphvizRecordCell(); name.Text = v.Table.Name; table.Cells.Add(name); ...
Here's a sample result on the MbUnit database:
Page rendered at Monday, September 08, 2008 6:54:51 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.