- Timestamp:
- 06/08/17 11:43:26 (8 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs
r10565 r15029 40 40 SecondWalk(layoutRoot, -layoutRoot.Prelim); 41 41 NormalizeCoordinates(layoutNodeMap.Values); 42 if ( height != 0 && width !=0) {42 if (width > 0 && height > 0) { 43 43 FitToBounds(width, height, layoutNodeMap.Values); 44 44 Center(width, height, layoutNodeMap.Values); … … 158 158 if (ymax < y) ymax = y; 159 159 } 160 return new RectangleF(xmin, ymin, xmax + minHorizontalSpacing + NodeWidth, ymax + minVerticalSpacing+ NodeHeight);160 return new RectangleF(xmin, ymin, xmax + NodeWidth, ymax + NodeHeight); 161 161 } 162 162 -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r14185 r15029 287 287 actualRoot = tree.Root.GetSubtree(0); 288 288 } 289 290 var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width, Height).ToList(); 289 var paddingX = 20; // add 10px padding on each side (left and right) 290 var paddingY = 20; // add 10px padding on top and bottom 291 var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width - paddingX, Height - paddingY).ToList(); 292 // add the padding 293 foreach (var vn in visualNodes) { 294 vn.X += paddingX / 2; 295 vn.Y += paddingY / 2; 296 } 297 291 298 visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x); 292 299 visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>(); … … 321 328 } 322 329 330 private Action<Brush, int, int, int, int> fill; 331 private Action<Pen, int, int, int, int> draw; 323 332 protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) { 324 333 graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1)); … … 328 337 using (var nodeLinePen = new Pen(visualTreeNode.LineColor)) 329 338 using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) { 330 //draw terminal node 331 if (node.SubtreeCount == 0) { 332 graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 333 graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 339 var x = visualTreeNode.X; 340 var y = visualTreeNode.Y; 341 var w = visualTreeNode.Width - 1; // allow 1px for the drawing of the line 342 var h = visualTreeNode.Height - 1; // allow 1px for the drawing of the line 343 // draw leaf nodes as rectangles and internal nodes as ellipses 344 if (node.SubtreeCount > 0) { 345 fill = graphics.FillEllipse; draw = graphics.DrawEllipse; 334 346 } else { 335 graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 336 graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 337 } 347 fill = graphics.FillRectangle; draw = graphics.DrawRectangle; 348 } 349 fill(nodeFillBrush, x, y, w, h); 350 draw(nodeLinePen, x, y, w, h); 338 351 //draw name of symbol 339 var text = node.ToString(); 340 graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat); 352 graphics.DrawString(node.ToString(), textFont, textBrush, new RectangleF(x, y, w, h), stringFormat); 341 353 } 342 354 }
Note: See TracChangeset
for help on using the changeset viewer.