本文整理汇总了C#中Microsoft.Msagl.Drawing.Graph类的典型用法代码示例。如果您正苦于以下问题:C# Graph类的具体用法?C# Graph怎么用?C# Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Graph类属于Microsoft.Msagl.Drawing命名空间,在下文中一共展示了Graph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessLine
static void ProcessLine(Graph graph, string str, StreamReader f) {
if (str.Contains("node"))
ReadNode(graph, f);
else if(str.Contains("edge"))
ReadEdge(graph, f);
}
示例2: SetGraph
private void SetGraph()
{
var graph = new Graph();
graph.AddEdge("a", "b");
graph.AddEdge("e", "b");
graph.AddEdge("d", "b");
graph.AddEdge("b", "c");
graph.AddEdge("a22", "b22");
graph.AddEdge("e22", "b22");
graph.AddEdge("d22", "b22");
graph.AddEdge("b22", "c22");
graph.AddEdge("a0", "b0");
graph.AddEdge("b0", "c0");
graph.AddEdge("a33", "b33");
graph.AddEdge("e33", "b33");
graph.AddEdge("d33", "b33");
graph.AddEdge("b33", "c33");
graph.AddEdge("a11", "b11");
graph.AddEdge("b11", "c11").LabelText = "Test labels!";
graph.CreateGeometryGraph();
foreach (Node node in graph.Nodes)
node.GeometryNode.BoundaryCurve = CreateLabelAndBoundary(node);
foreach (var edge in graph.Edges) {
if (edge.Label != null) {
var geomEdge = edge.GeometryEdge;
double width;
double height;
StringMeasure.MeasureWithFont(edge.LabelText,
new Font(edge.Label.FontName, (float)edge.Label.FontSize), out width, out height);
edge.Label.GeometryLabel=geomEdge.Label = new Label(width, height, geomEdge);
}
}
var geomGraph=graph.GeometryGraph;
var geomGraphComponents = GraphConnectedComponents.CreateComponents(geomGraph.Nodes, geomGraph.Edges);
var settings = new SugiyamaLayoutSettings();
foreach (var subgraph in geomGraphComponents) {
var layout=new LayeredLayout(subgraph, settings);
subgraph.Margins = settings.NodeSeparation/2;
layout.Run();
}
Microsoft.Msagl.Layout.MDS.MdsGraphLayout.PackGraphs(geomGraphComponents, settings);
geomGraph.UpdateBoundingBox();
gViewer1.NeedToCalculateLayout = false;
gViewer1.Graph = graph;
}
示例3: MainWindow_Loaded
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
GraphViewer graphViewer = new GraphViewer();
graphViewer.BindToPanel(Panel);
Graph graph = new Graph();
graph.AddEdge("A", "B");
graph.Attr.LayerDirection = LayerDirection.LR;
graphViewer.Graph = graph; // throws exception
}
示例4: SomeClass
public static void SomeClass()
{
var graph = new MSAGL.Drawing.Graph("");
graph.AddEdge("A", "B");
graph.AddEdge("A", "B");
graph.FindNode("A").Attr.FillColor = MSAGL.Drawing.Color.BlanchedAlmond;
graph.FindNode("B").Attr.FillColor = MSAGL.Drawing.Color.BurlyWood;
var renderer = new MSAGL.GraphViewerGdi.GraphRenderer(graph);
renderer.CalculateLayout();
const int width = 50;
int height = (int)(graph.Height * (width / graph.Width));
const PixelFormat pixfmt = System.Drawing.Imaging.PixelFormat.Format32bppPArgb;
using (var bitmap = new System.Drawing.Bitmap(width, height, pixfmt))
{
using (var gfx = System.Drawing.Graphics.FromImage(bitmap))
{
gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
var rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
renderer.Render(gfx, rect);
bitmap.Save("test.png");
}
}
}
示例5: UpdateGraph
public virtual void UpdateGraph(Graph graph)
{
Node graphNode = graph.AddNode(NodeFile.Id);
graphNode.LabelText = NodeFile.Name;
UpdateGraphNode(graphNode);
UpdateOutEdges(graph);
}
示例6: DrawGraph
void DrawGraph(Automaton automaton)
{
var graph = new Graph();
graph.Attr.LayerDirection = LayerDirection.LR;
int i = 0;
foreach (var s in automaton.States)
{
foreach (var o in s.Output)
{
var index = automaton.States.IndexOf(o.End);
var end = ReferenceEquals(automaton.StartState, o.End) ? "Start" : index.ToString();
if (ReferenceEquals(s, automaton.StartState))
{
graph.AddEdge("Start", o.ToString(), end);
}
else if (o.End.IsFinalState)
{
graph.AddEdge(i.ToString(), o.ToString(), "End");
}
else
{
graph.AddEdge(i.ToString(), o.ToString(), end);
}
}
i++;
}
graphViewer.Graph = graph;
}
示例7: SvgGraphWriter
/// <summary>
/// constructor
/// </summary>
/// <param name="streamPar"></param>
/// <param name="graphP"></param>
public SvgGraphWriter(Stream streamPar, Graph graphP) {
InitColorSet();
stream = streamPar;
graph = graphP;
var xmlWriterSettings = new XmlWriterSettings { Indent = true };
xmlWriter = XmlWriter.Create(stream, xmlWriterSettings);
}
示例8: CreateDrawingGraph
public static Graph CreateDrawingGraph(GeometryGraph gg)
{
counter = 0;
localMap = new Dictionary<GeometryNode,Node>();
dg = new Graph(counter++.ToString()) { GeometryGraph = gg };
foreach (GeometryNode n in gg.Nodes)
{
Node node = new Node(counter++.ToString());
node.Attr.Shape = Shape.Ellipse;
node.GeometryNode = n;
dg.AddNode(node);
localMap[n]=node;
}
Subgraph cluster = new Subgraph(counter++.ToString());
cluster.GeometryNode = gg.RootCluster;
dg.RootSubgraph = cluster;
PopulateClusters(cluster, gg.RootCluster);
foreach (GeometryEdge e in gg.Edges)
{
Edge edge = new Edge(localMap[e.Source], localMap[e.Target], ConnectionToGraph.Disconnected);
edge.Attr.ArrowheadAtSource = e.ArrowheadAtSource ? ArrowStyle.Normal : ArrowStyle.None;
edge.Attr.ArrowheadAtTarget = e.ArrowheadAtTarget ? ArrowStyle.Normal : ArrowStyle.None;
edge.GeometryEdge = e;
dg.AddPrecalculatedEdge(edge);
}
//PopulateClusterEdges(dg.RootSubgraph, gg.RootCluster);
return dg;
}
示例9: GraphWriter
///<summary>
///</summary>
///<param name="streamPar"></param>
///<param name="graphP"></param>
public GraphWriter(Stream streamPar, Graph graphP) {
stream = streamPar;
graph = graphP;
var xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
xmlWriter = XmlWriter.Create(stream, xmlWriterSettings);
}
示例10: CtreateDrawingGraph
static Graph CtreateDrawingGraph(out FastIncrementalLayoutSettings settings)
{
settings = new FastIncrementalLayoutSettings { RouteEdges = true, NodeSeparation = 30};
var drawingGraph = new Graph();
const string id0 = "0";
const string id1 = "1";
AddEdge(drawingGraph, id0, id1);
AddEdge(drawingGraph, "0", "2");
AddEdge(drawingGraph, "1", "3");
AddEdge(drawingGraph, "2", "4");
AddEdge(drawingGraph, "2", "5");
AddEdge(drawingGraph, "2", "6");
AddEdge(drawingGraph, "5", "7");
AddEdge(drawingGraph, "5", "6");
AddEdge(drawingGraph, "7", "8");
AddEdge(drawingGraph, "8", "6");
drawingGraph.CreateGeometryGraph();
foreach (Microsoft.Msagl.Drawing.Node node in drawingGraph.Nodes) {
double w, h;
var label = node.Label;
var font = new Font(label.FontName, (float)label.FontSize);
StringMeasure.MeasureWithFont(label.Text, font, out w, out h);
node.Label.Width = w;
node.Label.Height = h;
node.Attr.Shape = Shape.DrawFromGeometry;
node.GeometryNode.BoundaryCurve=CurveFactory.CreateRectangleWithRoundedCorners(1.2*w,1.2*h,3,3,new Point());
}
return drawingGraph;
}
示例11: ModulesGraph
private void ModulesGraph()
{
Graph g = new Graph();
using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
{
command.CommandText = @"select name from modules";
SQLiteDataReader DataReader = command.ExecuteReader();
while (DataReader.Read())
g.AddNode(DataReader["name"].ToString());
}
using (SQLiteCommand command = new SQLiteCommand(ConnectionManager.connection))
{
command.CommandText = @"select * from moddeps";
SQLiteDataReader DataReader = command.ExecuteReader();
while (DataReader.Read())
{
Microsoft.Msagl.Drawing.Edge e = g.AddEdge(DataReader["used"].ToString(), "", DataReader["uses"].ToString());
e.Attr.LineWidth = int.Parse(DataReader["count"].ToString());
//e.Attr.Color = Microsoft.Msagl.Drawing.Color.Yellow;
e.LabelText = DataReader["rate"].ToString();
}
}
gViewer.Graph = g;
}
示例12: WalkImports
static Node WalkImports(Hashtable nodes, Hashtable edges, XmlSchema s, string uri, Graph g) {
if (nodes.ContainsKey(uri)) {
return (Node) nodes[uri]; // already visited
}
Node b1 = AddSchemaBox(nodes, uri, g);
if (s != null) {
foreach (var o in s.Includes) {
XmlSchema si = null;
var include = o as XmlSchemaInclude;
var baseUri = new Uri(o.SourceUri);
Uri suri = null;
var color = new Color(0, 0, 128); //Colors.Navy;
if (include != null) {
si = include.Schema;
suri = new Uri(baseUri, include.SchemaLocation);
color = new Color(0, 128, 0); //Colors.Green;
} else {
var import = o as XmlSchemaImport;
if (import != null) {
si = import.Schema;
suri = new Uri(baseUri, import.SchemaLocation);
}
}
Node b2 = WalkImports(nodes, edges, si, suri.AbsoluteUri, g);
if (b2 != b1) {
AddEdge(edges, g, b1, b2, color);
}
}
}
return b1;
}
示例13: CopyGraph
/// <summary>
/// Copies a graph and its GeometryGraph.
/// </summary>
/// <param name="parentGraph"></param>
/// <returns></returns>
public static Graph CopyGraph(Graph parentGraph)
{
GeometryGraph geometryCopy = CopyGraph(parentGraph.GeometryGraph);
Graph graph=new Graph();
graph.GeometryGraph = geometryCopy;
Dictionary<Node,int> nodeId=new Dictionary<Node, int>(geometryCopy.Nodes.Count);
for (int i = 0; i < geometryCopy.Nodes.Count; i++) {
nodeId[geometryCopy.Nodes[i]] = i;
String id = i.ToString();
graph.AddNode(id);
var node = graph.FindNode(id);
node.GeometryNode = geometryCopy.Nodes[i];
geometryCopy.Nodes[i].UserData = node;
}
foreach (var edge in geometryCopy.Edges) {
String sourceId = nodeId[edge.Source].ToString();
String targetId = nodeId[edge.Target].ToString();
var edgeCopy=graph.AddEdge(sourceId, "", targetId);
edgeCopy.GeometryEdge = edge;
edge.UserData = edgeCopy;
}
return graph;
}
示例14: RenderGraph
private Graph RenderGraph(LangFile langFile)
{
var graph = new Graph("OpenFoodFacts Category Taxonomy");
var languageComparer = new LanguageByImportanceComparer(langFile.TranslationSets);
var parentsComparer = new ParentsComparer(new AlphabeticalTranslationSetComparer(languageComparer, EvaluateMostImportantTranslation, GetLabel));
foreach (var translationSet in langFile.TranslationSets.OrderBy(ts => ts.Parents, parentsComparer))
{
if (!translationSet.Translations.Any())
{
continue;
}
var translation = EvaluateMostImportantTranslation(translationSet, languageComparer);
var translationLabel = GetLabel(translation);
if (translationSet.Parents.Any())
{
foreach (var parent in translationSet.Parents)
{
var parentTranslation = EvaluateMostImportantTranslation(parent, languageComparer);
var parentTranslationLabel = GetLabel(parentTranslation);
graph.AddEdge(parentTranslationLabel, translationLabel);
}
}
else
{
graph.AddNode(translationLabel);
}
}
return graph;
}
示例15: Generate
public static Graph Generate(IUiPreferencesService uiPreferences, Procedure proc, Graphics g, Font defaultFont)
{
Graph graph = new Graph();
var cfgGen = new CfgGraphGenerator(graph, uiPreferences, g, defaultFont);
cfgGen.Traverse(proc.EntryBlock.Succ[0]);
graph.Attr.LayerDirection = LayerDirection.TB;
return graph;
}