Changeset 9835 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
- Timestamp:
- 08/01/13 13:01:40 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionaryTracking
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking
- Property svn:ignore
-
old new 1 *.suo 2 _ReSharper.HeuristicLab.Tracking 1 _ReSharper.Sliding Window GP 3 2 bin
-
- Property svn:mergeinfo changed
/branches/Sliding Window GP (added) merged: 7820,7837,7845,7850,9047,9126,9145,9162-9165 -
Property
svn:global-ignores
set to
_ReSharper.HeuristicLab.Tracking
- Property svn:ignore
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views (added) merged: 9821
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r9587 r9835 25 25 using System.Drawing.Imaging; 26 26 using System.Windows.Forms; 27 using Point = System.Drawing.Point; 27 28 28 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { … … 48 49 } 49 50 51 #region Public properties 50 52 private int spacing; 51 53 public int Spacing { … … 106 108 set { suspendRepaint = value; } 107 109 } 110 #endregion 108 111 109 112 protected override void OnPaint(PaintEventArgs e) { … … 250 253 251 254 #region methods for painting the symbolic expression tree 255 252 256 private void DrawFunctionTree(ISymbolicExpressionTree tree, Graphics graphics, int x, int y, int width, int height) { 253 DrawFunctionTree(tree.Root, graphics, x, y, width, height, Point.Empty); 257 // DrawFunctionTree(tree.Root, graphics, x, y, width, height, Point.Empty); 258 AlternateDraw(tree, graphics, 70, 46, 20, 50); 259 } 260 261 private void AlternateDraw(ISymbolicExpressionTree tree, Graphics graphics, int preferredWidth, int preferredHeight, int minDistance, int maxDistance) { 262 var tl = new TreeLayout(); 263 tl.Distance = 5; 264 tl.SymbolicExpressionTree = tree; 265 266 var nodePositions = tl.GetNodeCoordinates(); 267 var bounds = tl.Bounds(); 268 269 double sx = Width / bounds.Width; 270 double sy = Height / bounds.Height; 271 272 double dx = tl.Distance * sx; // scaled horizontal distance 273 double dy = tl.Distance * sy; // scaled vertical distance 274 275 int maxWidth = (int)Math.Round(dx); 276 int maxHeight = (int)Math.Round(dy); 277 278 // instead of using the preferred with/height of each node inside the foreach loop below, 279 // we assume the same width/height for all nodes 280 int w = Math.Min(preferredWidth, maxWidth - minDistance / 2); 281 int h = Math.Min(preferredHeight, maxHeight - minDistance / 2); 282 // adjust scaling factor so that nodes will be at most maxDistance far from each other on the horizontal axis 283 double offset = 0; 284 if (maxDistance + w < maxWidth) { 285 sx *= (double)(maxDistance + w) / maxWidth; 286 offset = (Width - (sx * bounds.Width)) / 2; 287 } 288 foreach (var node in visualTreeNodes.Keys) { 289 var visualNode = visualTreeNodes[node]; 290 var pos = nodePositions[node]; 291 visualNode.Width = w; 292 visualNode.Height = h; 293 visualNode.X = (int)Math.Round(pos.X * sx + offset); ; 294 visualNode.Y = (int)Math.Round(pos.Y * sy); 295 DrawTreeNode(graphics, visualNode); 296 } 297 graphics.ResetClip(); // reset clip region 298 foreach (var visualNode in visualTreeNodes.Values) { 299 var node = visualNode.SymbolicExpressionTreeNode; 300 foreach (var subtree in node.Subtrees) { 301 var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree); 302 var visualSubtree = visualTreeNodes[subtree]; 303 var origin = new Point(visualNode.X + visualNode.Width / 2, visualNode.Y + visualNode.Height); 304 var target = new Point(visualSubtree.X + visualSubtree.Width / 2, visualSubtree.Y); 305 using (var linePen = new Pen(visualLine.LineColor)) { 306 linePen.DashStyle = visualLine.DashStyle; 307 graphics.DrawLine(linePen, origin, target); 308 } 309 } 310 } 254 311 } 255 312 … … 257 314 /// 258 315 /// </summary> 259 /// <param name=" functionTree">function tree to draw</param>316 /// <param name="node">the root of the function tree to draw</param> 260 317 /// <param name="graphics">graphics object to draw on</param> 261 318 /// <param name="x">x coordinate of drawing area</param> … … 365 422 } 366 423 #endregion 367 368 424 #region save image 369 425 private void saveImageToolStripMenuItem_Click(object sender, EventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.