Node BoundaryCurve has no effect
Opened this issue · 1 comments
bbenami commented
I'm trying to define the size of a node explicitly. I've tried setting the label width/height as well as setting the node's boundarycurve. Both does to seem to make any effect of the node size.
Below is my sample code.
What am I missing?
Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("");
graph.AddEdge("A", "B");
graph.AddEdge("B", "C");
int nwidth = 100;
int nheight = 100;
var geometryGraph = graph.CreateGeometryGraph();
var n = graph.FindNode("A");
n.Label.GeometryLabel = new Microsoft.Msagl.Core.Layout.Label();
n.Label.GeometryLabel.Width = nwidth;
n.Label.GeometryLabel.Height = nwidth;
n.Label.Width = nwidth;
n.Label.Height = nheight;
int r = n.Attr.LabelMargin;
n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(nwidth + r * 2, nheight + r * 2, r, r, new Point());
graph.Attr.LayerDirection = LayerDirection.LR;
geometryGraph.UpdateBoundingBox();
Microsoft.Msagl.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Msagl.GraphViewerGdi.GraphRenderer(graph);
renderer.CalculateLayout();
int width = 1500;
Bitmap bitmap = new Bitmap(width, (int)(graph.Height * (width / graph.Width)), PixelFormat.Format32bppPArgb);
renderer.Render(bitmap);
bitmap.Save("c:\\temp\\test.png");
levnach commented
It seems GraphRenderer creates new geometry blindly, even when the drawing graph already has the geometry associated with it. The way to control the shape of the nodes is to use a delegate for the geometry node boundary curve: the code below demonstrates it:
` Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("");
graph.AddEdge("A", "B");
graph.AddEdge("B", "C");
int nwidth = 100;
int nheight = 100;
var n = graph.FindNode("A");
int r = n.Attr.LabelMargin;
n.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(p => CurveFactory.CreateRectangleWithRoundedCorners(nwidth + r * 2, nheight + r * 2, r, r, new Microsoft.Msagl.Core.Geometry.Point()));
graph.Attr.LayerDirection = LayerDirection.LR;
Microsoft.Msagl.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Msagl.GraphViewerGdi.GraphRenderer(graph);
renderer.CalculateLayout();
int lwidth = 1500;
Bitmap bitmap = new Bitmap(lwidth, (int)(graph.Height * (lwidth / graph.Width)), PixelFormat.Format32bppPArgb);
renderer.Render(bitmap);
bitmap.Save("c:\\tmp\\test.png");`