forked from YaccConstructor/QuickGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSetGraphvizAlgorithm.cs
More file actions
87 lines (75 loc) · 2.72 KB
/
Copy pathDataSetGraphvizAlgorithm.cs
File metadata and controls
87 lines (75 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuickGraph.Graphviz;
using QuickGraph.Graphviz.Dot;
using System.Diagnostics.Contracts;
namespace QuickGraph.Data
{
/// <summary>
/// An algorithm that renders a DataSet graph to the Graphviz DOT format.
/// </summary>
public class DataSetGraphvizAlgorithm
: GraphvizAlgorithm<DataTable, DataRelationEdge>
{
public DataSetGraphvizAlgorithm(DataSetGraph visitedGraph)
: base(visitedGraph)
{
this.InitializeFormat();
}
public DataSetGraphvizAlgorithm(
DataSetGraph visitedGraph,
string path,
GraphvizImageType imageType
)
: base(visitedGraph, path, imageType)
{
this.InitializeFormat();
}
private void InitializeFormat()
{
this.FormatVertex += new FormatVertexEventHandler<DataTable>(FormatTable);
this.FormatEdge += new FormatEdgeAction<DataTable, DataRelationEdge>(FormatRelationEdge);
this.CommonVertexFormat.Style = GraphvizVertexStyle.Solid;
this.CommonVertexFormat.Shape = GraphvizVertexShape.Record;
}
protected virtual void FormatTable(object sender, FormatVertexEventArgs<DataTable> e)
{
Contract.Requires(sender != null);
Contract.Requires(e != null);
var v = e.Vertex;
var format = e.VertexFormatter;
format.Shape = GraphvizVertexShape.Record;
// creating a record with a title and a list of columns.
var title = new GraphvizRecordCell() {
Text = v.TableName
};
var sb = new StringBuilder();
bool first = true;
foreach (DataColumn column in v.Columns)
{
if (first) first = false;
else
sb.AppendLine();
sb.AppendFormat("+ {0} : {1}", column.ColumnName, column.DataType.Name);
if (column.Unique) sb.Append(" unique");
}
var columns = new GraphvizRecordCell()
{
Text = sb.ToString().TrimEnd()
};
format.Record.Cells.Add(title);
format.Record.Cells.Add(columns);
}
protected virtual void FormatRelationEdge(object sender, FormatEdgeEventArgs<DataTable, DataRelationEdge> args)
{
Contract.Requires(sender != null);
Contract.Requires(args != null);
var e = args.Edge;
var format = args.EdgeFormatter;
format.Label.Value = e.Relation.RelationName;
}
}
}