[7779] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Drawing.Drawing2D;
|
---|
| 26 | using System.Linq;
|
---|
| 27 | using System.Windows.Forms;
|
---|
[8213] | 28 | using HeuristicLab.Common;
|
---|
[7779] | 29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 30 | using HeuristicLab.Visualization;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.EvolutionaryTracking.Views {
|
---|
| 33 | public partial class GenealogyGraphChart : ChartControl {
|
---|
[9084] | 34 | private Dictionary<string, VisualGenealogyGraphNode> visualNodeMap; // map the uid of the genealogy graph vertex with a visual node (in this way each node is uniquely determined)
|
---|
[8556] | 35 | private Dictionary<Tuple<VisualGenealogyGraphNode, VisualGenealogyGraphNode>, VisualGenealogyGraphArc> visualArcMap;
|
---|
[8213] | 36 | private const int Diameter = 20; // node diameter
|
---|
| 37 | private int x, y; // coordinates for positioning each node
|
---|
| 38 | private const int Cx = 30, Cy = 30; // position increments
|
---|
[8556] | 39 | private VisualGenealogyGraphNode selectedGenealogyGraphNode;
|
---|
| 40 | public VisualGenealogyGraphNode SelectedGenealogyGraphNode { get { return selectedGenealogyGraphNode; } }
|
---|
| 41 | private Visualization.Rectangle targetRectangle; // provides a rectangle mark of the currently selected genealogy graph node
|
---|
[7779] | 42 |
|
---|
[9420] | 43 | public bool SimpleLineages { get; set; }
|
---|
| 44 | public bool LockGenealogy { get; set; }
|
---|
| 45 |
|
---|
| 46 | private bool drawing;
|
---|
| 47 |
|
---|
[8556] | 48 | private SymbolicExpressionTreeGenealogyGraph graph;
|
---|
[7779] | 49 | public SymbolicExpressionTreeGenealogyGraph Graph {
|
---|
[8556] | 50 | get { return graph; }
|
---|
[7779] | 51 | internal set {
|
---|
[8556] | 52 | graph = value;
|
---|
[9239] | 53 | if (graph == null) return;
|
---|
[9084] | 54 |
|
---|
| 55 | visualNodeMap = new Dictionary<string, VisualGenealogyGraphNode>();
|
---|
[8556] | 56 | visualArcMap = new Dictionary<Tuple<VisualGenealogyGraphNode, VisualGenealogyGraphNode>, VisualGenealogyGraphArc>();
|
---|
[9084] | 57 |
|
---|
| 58 | Chart.Group.Clear();
|
---|
[7779] | 59 | DrawGraph();
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[9084] | 63 | private VisualGenealogyGraphNode GetVisualGenealogyGraphNode(IVertex node) {
|
---|
| 64 | VisualGenealogyGraphNode visualNode;
|
---|
| 65 | visualNodeMap.TryGetValue(node.Id, out visualNode);
|
---|
| 66 | return visualNode;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[9420] | 69 | private VisualGenealogyGraphArc GetVisualGenealogyGraphArc(IVertex source, IVertex target) {
|
---|
| 70 | VisualGenealogyGraphNode visualSource;
|
---|
| 71 | VisualGenealogyGraphNode visualTarget;
|
---|
| 72 | visualNodeMap.TryGetValue(source.Id, out visualSource);
|
---|
| 73 | visualNodeMap.TryGetValue(target.Id, out visualTarget);
|
---|
| 74 | if (visualSource != null && visualTarget != null) {
|
---|
| 75 | VisualGenealogyGraphArc visualArc;
|
---|
| 76 | visualArcMap.TryGetValue(
|
---|
| 77 | new Tuple<VisualGenealogyGraphNode, VisualGenealogyGraphNode>(visualSource, visualTarget), out visualArc);
|
---|
| 78 | if (visualArc != null) return visualArc;
|
---|
| 79 | }
|
---|
| 80 | return null;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[7779] | 83 | public event MouseEventHandler GenealogyGraphNodeClicked;
|
---|
| 84 | private void OnGenealogyGraphNodeClicked(object sender, MouseEventArgs e) {
|
---|
| 85 | var clicked = GenealogyGraphNodeClicked;
|
---|
| 86 | if (clicked != null) clicked(sender, e);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public GenealogyGraphChart() {
|
---|
[9835] | 90 | // InitializeComponent();
|
---|
[7779] | 91 | Chart = new Chart(0, 0, PreferredSize.Width, PreferredSize.Height);
|
---|
| 92 | x = 0;
|
---|
| 93 | y = PreferredSize.Height + Cx + 2 * Diameter;
|
---|
[9835] | 94 | Chart.Mode = ChartMode.Select;
|
---|
[7779] | 95 | }
|
---|
| 96 |
|
---|
| 97 | public void DrawGraph() {
|
---|
[8556] | 98 | if (graph == null) return;
|
---|
[7779] | 99 | Chart.UpdateEnabled = false;
|
---|
[8236] | 100 |
|
---|
[9420] | 101 | drawing = true;
|
---|
| 102 |
|
---|
[9084] | 103 | var layers = Graph.Nodes.GroupBy(n => n.Rank).OrderBy(g => g.Key).Select(g => new { Rank = g.Key, Nodes = g.ToList() }).ToList();
|
---|
| 104 |
|
---|
[9420] | 105 | y = PreferredSize.Height + Cx + 2 * Diameter;
|
---|
| 106 |
|
---|
[8556] | 107 | for (int i = 0; i != layers.Count; ++i) {
|
---|
[9420] | 108 | x = 0;
|
---|
| 109 | layers[i].Nodes.Sort((b, a) => Graph.Compare(a, b));
|
---|
| 110 | double rank = Math.Floor(layers[i].Rank);
|
---|
| 111 | if (layers[i].Rank.IsAlmost(rank)) {
|
---|
| 112 | var visualTextNode = new VisualGenealogyGraphTextLabel(Chart, x, y + 2, x + Diameter, y + Diameter) {
|
---|
[9963] | 113 | FontBrush = new SolidBrush(Color.Black),
|
---|
[9420] | 114 | Font = new Font("Arial", Diameter - 4, FontStyle.Regular, GraphicsUnit.Pixel),
|
---|
| 115 | Text = String.Format("{0:0}", rank)
|
---|
| 116 | };
|
---|
| 117 | Chart.Group.Add(visualTextNode);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[8556] | 120 | // sort descending by quality (using comparison defined in GenealogyGraphNode class)
|
---|
[9420] | 121 | x += (int)Math.Floor(1.5 * Cx); // reset horizontal coordinate
|
---|
| 122 |
|
---|
[8556] | 123 | foreach (var node in layers[i].Nodes) {
|
---|
[7779] | 124 | var pen = new Pen(Color.LightGray);
|
---|
| 125 | var nl = Environment.NewLine;
|
---|
| 126 | var visualNode = new VisualGenealogyGraphNode(Chart, x, y, x + Diameter, y + Diameter, pen, null) {
|
---|
[8213] | 127 | Data = node,
|
---|
[9420] | 128 | ToolTipText = "Rank: " + node.Rank + nl +
|
---|
[8556] | 129 | "Quality: " + String.Format("{0:0.0000}", node.Quality) + nl +
|
---|
| 130 | "IsElite: " + node.IsElite
|
---|
[7779] | 131 | };
|
---|
| 132 | Chart.Group.Add(visualNode);
|
---|
[9084] | 133 | visualNodeMap.Add(node.Id, visualNode);
|
---|
[8236] | 134 |
|
---|
[7779] | 135 | x += Cx; // increment horizontal coordinate
|
---|
| 136 | }
|
---|
[8236] | 137 |
|
---|
[7779] | 138 | y -= Cy; // decrement vertical coordinate (because the origin is upside down)
|
---|
[8556] | 139 |
|
---|
| 140 | // connect elites from successive layers with visual arcs
|
---|
[9084] | 141 | if (i == 0) continue;
|
---|
| 142 | var currLayer = layers[i].Nodes;
|
---|
| 143 | var prevLayer = layers[i - 1].Nodes;
|
---|
| 144 | foreach (var n in currLayer) {
|
---|
| 145 | foreach (var m in prevLayer) {
|
---|
| 146 | if (n.SymbolicExpressionTree != m.SymbolicExpressionTree) continue;
|
---|
| 147 | var v1 = GetVisualGenealogyGraphNode(n);
|
---|
| 148 | var v2 = GetVisualGenealogyGraphNode(m);
|
---|
| 149 |
|
---|
| 150 | var pen = new Pen(Color.LightGray);
|
---|
| 151 | visualArcMap[Tuple.Create(v2, v1)] = AddArc(Chart, v2, v1, pen);
|
---|
| 152 | }
|
---|
[8556] | 153 | }
|
---|
[7779] | 154 | }
|
---|
[8236] | 155 | // add arcs separately (to avoid some ordering problems)
|
---|
[9963] | 156 | foreach (SymbolicExpressionTreeGenealogyGraphNode node in Graph.Nodes) {
|
---|
[9084] | 157 | VisualGenealogyGraphNode visualNode = GetVisualGenealogyGraphNode(node);
|
---|
[8236] | 158 | if (node.InEdges == null) continue;
|
---|
[7779] | 159 |
|
---|
[9084] | 160 | foreach (Arc arc in node.InEdges) {
|
---|
| 161 | var visualParent = GetVisualGenealogyGraphNode(arc.Source);
|
---|
[8236] | 162 | var pen = new Pen(Color.Transparent);
|
---|
[8556] | 163 | visualArcMap[Tuple.Create(visualParent, visualNode)] = AddArc(Chart, visualParent, visualNode, pen);
|
---|
[8236] | 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[9420] | 167 | // highlight the most recent common ancestor ("eve" individual)
|
---|
| 168 | // var eve = graph.MostRecentCommonAncestor();
|
---|
| 169 | // if (eve != null) {
|
---|
| 170 | // var visualGraphNode = GetVisualGenealogyGraphNode(eve);
|
---|
| 171 |
|
---|
| 172 | // var brush = new SolidBrush(Color.BlueViolet);
|
---|
[9963] | 173 | // visualGraphNode.FontBrush = brush;
|
---|
[9420] | 174 | // }
|
---|
| 175 |
|
---|
[7779] | 176 | Chart.UpdateEnabled = true;
|
---|
| 177 | Chart.EnforceUpdate();
|
---|
[9420] | 178 |
|
---|
| 179 | drawing = false;
|
---|
[7779] | 180 | }
|
---|
| 181 |
|
---|
| 182 | // add an arc between the source and the target nodes, using the specified pen color
|
---|
| 183 | // adds the arc to the arc lists of both nodes and to the primitive group of the chart
|
---|
| 184 | private static VisualGenealogyGraphArc AddArc(IChart chart, VisualGenealogyGraphNode source, VisualGenealogyGraphNode target, Pen pen, Brush brush = null) {
|
---|
| 185 | var arc = new VisualGenealogyGraphArc(chart, source, target, pen) { Brush = brush };
|
---|
| 186 | arc.UpdatePosition();
|
---|
| 187 | source.OutgoingArcs.Add(arc);
|
---|
| 188 | target.IncomingArcs.Add(arc);
|
---|
| 189 | chart.Group.Add(arc);
|
---|
| 190 | return arc;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[9420] | 193 | protected override void pictureBox_MouseMove(object sender, MouseEventArgs e) {
|
---|
[9835] | 194 | if (!drawing) {
|
---|
| 195 | switch (e.Button) {
|
---|
| 196 | case MouseButtons.Left:
|
---|
| 197 | Chart.Mode = ChartMode.Select;
|
---|
| 198 | Cursor = Cursors.Default;
|
---|
| 199 | break;
|
---|
| 200 | case MouseButtons.Middle:
|
---|
| 201 | Chart.Mode = ChartMode.Move;
|
---|
| 202 | Cursor = Cursors.Hand;
|
---|
| 203 | break;
|
---|
| 204 | }
|
---|
[9420] | 205 | base.pictureBox_MouseMove(sender, e);
|
---|
[9835] | 206 | }
|
---|
[9420] | 207 | }
|
---|
| 208 |
|
---|
[7779] | 209 | protected override void pictureBox_MouseUp(object sender, MouseEventArgs e) {
|
---|
[9835] | 210 | Cursor = Cursors.Default;
|
---|
| 211 | if (Chart.Mode == ChartMode.Move) {
|
---|
| 212 | Chart.Mode = ChartMode.Select;
|
---|
| 213 | return;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[9084] | 216 | if (Chart.Mode != ChartMode.Select) {
|
---|
[7779] | 217 | base.pictureBox_MouseUp(sender, e);
|
---|
[9084] | 218 | return;
|
---|
[7779] | 219 | }
|
---|
[9835] | 220 |
|
---|
[9084] | 221 | var visualNodes = Chart.GetAllPrimitives(e.Location).Where(p => p is VisualGenealogyGraphNode).ToList();
|
---|
| 222 | if (visualNodes.Count <= 0) {
|
---|
| 223 | selectedGenealogyGraphNode = null;
|
---|
| 224 | return;
|
---|
| 225 | }
|
---|
| 226 | if (selectedGenealogyGraphNode == visualNodes[0]) return;
|
---|
| 227 | selectedGenealogyGraphNode = visualNodes[0] as VisualGenealogyGraphNode;
|
---|
| 228 | if (selectedGenealogyGraphNode == null) return;
|
---|
[9420] | 229 |
|
---|
| 230 | if (!LockGenealogy) {
|
---|
| 231 | // new node has been selected, clean up
|
---|
| 232 | Chart.UpdateEnabled = false;
|
---|
| 233 | if (ModifierKeys != Keys.Shift)
|
---|
| 234 | // clear colors
|
---|
| 235 | ClearAllNodes();
|
---|
| 236 | // use a rectangle to highlight the currently selected genealogy graph node
|
---|
| 237 | var gNode = selectedGenealogyGraphNode.Data;
|
---|
| 238 | var visualNode = GetVisualGenealogyGraphNode(gNode);
|
---|
| 239 |
|
---|
| 240 | DrawLineage(visualNode, n => SimpleLineages ? n.IncomingArcs.Take(1) : n.IncomingArcs, a => a.Source);
|
---|
| 241 | visualNode.Brush = null;
|
---|
| 242 | DrawLineage(visualNode, n => n.OutgoingArcs, a => a.Target);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[9084] | 245 | MarkSelectedNode();
|
---|
| 246 |
|
---|
| 247 | // update
|
---|
| 248 | Chart.UpdateEnabled = true;
|
---|
| 249 | Chart.EnforceUpdate();
|
---|
| 250 |
|
---|
| 251 | if (selectedGenealogyGraphNode != null)
|
---|
| 252 | /* emit clicked event */
|
---|
| 253 | OnGenealogyGraphNodeClicked(selectedGenealogyGraphNode, e);
|
---|
[7779] | 254 | }
|
---|
| 255 |
|
---|
[9420] | 256 | private void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector) {
|
---|
[9239] | 257 | if (node.Brush != null) return;
|
---|
[9084] | 258 | node.Brush = new SolidBrush(node.Data.GetColor());
|
---|
| 259 | var arcs = arcSelector(node);
|
---|
[9239] | 260 | if (arcs == null) return;
|
---|
[9420] | 261 |
|
---|
[9084] | 262 | foreach (var arc in arcs) {
|
---|
| 263 | var source = arc.Source.Data;
|
---|
| 264 | var target = arc.Target.Data;
|
---|
| 265 | var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
|
---|
| 266 | var end = new Point((int)arc.End.X, (int)arc.End.Y);
|
---|
| 267 | arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
|
---|
[9420] | 268 | arc.Pen.Color = Color.Transparent;
|
---|
[9963] | 269 | // arc.Pen.FontBrush = new SolidBrush(Color.DarkGray);
|
---|
[9084] | 270 | DrawLineage(nodeSelector(arc), arcSelector, nodeSelector);
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | void MarkSelectedNode() {
|
---|
| 275 | var center = selectedGenealogyGraphNode.Center;
|
---|
| 276 | var size = selectedGenealogyGraphNode.Size;
|
---|
| 277 | double x1 = center.X - size.Width / 2;
|
---|
| 278 | double x2 = x1 + size.Width;
|
---|
| 279 | double y1 = center.Y - size.Height / 2;
|
---|
| 280 | double y2 = y1 + size.Height;
|
---|
| 281 | if (targetRectangle == null) {
|
---|
| 282 | targetRectangle = new Visualization.Rectangle(Chart, x1, y1, x2, y2, new Pen(Color.Black), null);
|
---|
| 283 | Chart.Group.Add(targetRectangle);
|
---|
| 284 | } else {
|
---|
| 285 | targetRectangle.SetPosition(x1, y1, x2, y2);
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 |
|
---|
[7779] | 289 | public void ClearAllNodes() {
|
---|
[8213] | 290 | foreach (var primitive in Chart.Group.Primitives) {
|
---|
| 291 | if (primitive is VisualGenealogyGraphArc) {
|
---|
| 292 | var arc = primitive as VisualGenealogyGraphArc;
|
---|
[9084] | 293 | var sourceData = arc.Source.Data.SymbolicExpressionTree;
|
---|
| 294 | var targetData = arc.Target.Data.SymbolicExpressionTree;
|
---|
| 295 | primitive.Pen.Brush = sourceData != targetData ? new SolidBrush(Color.Transparent) : new SolidBrush(Color.LightGray);
|
---|
[8556] | 296 | } else {
|
---|
| 297 | primitive.Brush = null;
|
---|
[8213] | 298 | }
|
---|
[7779] | 299 | }
|
---|
| 300 | }
|
---|
| 301 |
|
---|
[9963] | 302 | public void HighlightNodes(IEnumerable<SymbolicExpressionTreeGenealogyGraphNode> nodes) {
|
---|
[9835] | 303 | Chart.UpdateEnabled = false;
|
---|
| 304 | ClearAllNodes();
|
---|
| 305 | foreach (var node in nodes) {
|
---|
| 306 | GetVisualGenealogyGraphNode(node).Brush = new SolidBrush(node.GetColor());
|
---|
| 307 | }
|
---|
| 308 | Chart.UpdateEnabled = true;
|
---|
| 309 | Chart.EnforceUpdate();
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[8556] | 312 | // TODO: optimize and reduce complexity of this method
|
---|
[9420] | 313 | public void HighlightNodes(IEnumerable<ISymbolicExpressionTree> trees) {
|
---|
[9084] | 314 | foreach (var tree in trees) {
|
---|
| 315 | var graphNodes = graph.GetGraphNodes(tree);
|
---|
| 316 | foreach (var graphNode in graphNodes) {
|
---|
[9420] | 317 | GetVisualGenealogyGraphNode(graphNode).Brush = new SolidBrush(graphNode.GetColor());
|
---|
[8556] | 318 | }
|
---|
[9084] | 319 | }
|
---|
[8213] | 320 | }
|
---|
[7779] | 321 |
|
---|
[9420] | 322 | public void HighlightArcs(IEnumerable<IEdge> arcs, Color color) {
|
---|
| 323 | foreach (var a in arcs) {
|
---|
| 324 | var arc = GetVisualGenealogyGraphArc(a.Source, a.Target);
|
---|
| 325 | if (arc != null) {
|
---|
| 326 | var source = arc.Source.Data;
|
---|
| 327 | var target = arc.Target.Data;
|
---|
| 328 | var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
|
---|
| 329 | var end = new Point((int)arc.End.X, (int)arc.End.Y);
|
---|
| 330 | arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
|
---|
| 331 | }
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[9963] | 335 | public void HighlightNode(SymbolicExpressionTreeGenealogyGraphNode graphNode, Color color) {
|
---|
[9084] | 336 | GetVisualGenealogyGraphNode(graphNode).Brush = new SolidBrush(color);
|
---|
[8556] | 337 | }
|
---|
| 338 |
|
---|
[9420] | 339 | public void HighlightAll() {
|
---|
| 340 | Chart.UpdateEnabled = false;
|
---|
| 341 | foreach (var visualNode in visualNodeMap.Values) {
|
---|
| 342 | visualNode.Brush = new SolidBrush(visualNode.Data.GetColor());
|
---|
| 343 | }
|
---|
| 344 | foreach (var arc in visualArcMap.Values) {
|
---|
| 345 | var source = arc.Source.Data;
|
---|
| 346 | var target = arc.Target.Data;
|
---|
| 347 | var start = new Point((int)arc.Start.X, (int)arc.Start.Y);
|
---|
| 348 | var end = new Point((int)arc.End.X, (int)arc.End.Y);
|
---|
| 349 | arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());
|
---|
| 350 | }
|
---|
| 351 | Chart.UpdateEnabled = true;
|
---|
| 352 | Chart.EnforceUpdate();
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[8213] | 355 | public void HighlightInDegree() {
|
---|
| 356 | Chart.UpdateEnabled = false;
|
---|
| 357 | ClearAllNodes();
|
---|
[8556] | 358 | double max = Graph.Nodes.Max(x => x.InEdges == null ? 0 : x.InEdges.Count);
|
---|
| 359 | foreach (var graphNode in Graph.Nodes) {
|
---|
[9084] | 360 | var visualNode = GetVisualGenealogyGraphNode(graphNode);
|
---|
[8213] | 361 | double deg = graphNode.InEdges == null ? 0 : graphNode.InEdges.Count;
|
---|
[8556] | 362 | int index = (int)(deg / max * ColorGradient.Colors.Count);
|
---|
| 363 | if (index == ColorGradient.Colors.Count) --index;
|
---|
| 364 | var color = ColorGradient.Colors[index];
|
---|
[8213] | 365 | visualNode.Brush = new SolidBrush(color);
|
---|
| 366 | }
|
---|
[7779] | 367 | Chart.UpdateEnabled = true;
|
---|
| 368 | Chart.EnforceUpdate();
|
---|
| 369 | }
|
---|
[8213] | 370 |
|
---|
| 371 | public void HighlightOutDegree() {
|
---|
| 372 | Chart.UpdateEnabled = false;
|
---|
| 373 | ClearAllNodes();
|
---|
[8556] | 374 | var graphNodes = Graph.Nodes;
|
---|
[8213] | 375 | double max = graphNodes.Max(x => x.OutEdges == null ? 0 : x.OutEdges.Count);
|
---|
| 376 | foreach (var graphNode in graphNodes) {
|
---|
[9084] | 377 | var visualNode = GetVisualGenealogyGraphNode(graphNode);
|
---|
[8213] | 378 | double deg = graphNode.OutEdges == null ? 0 : graphNode.OutEdges.Count;
|
---|
[8556] | 379 | int index = (int)(deg / max * ColorGradient.Colors.Count);
|
---|
| 380 | if (index == ColorGradient.Colors.Count) --index;
|
---|
| 381 | var color = ColorGradient.Colors[index];
|
---|
| 382 | visualNode.Brush = new SolidBrush(color);
|
---|
[8213] | 383 | }
|
---|
| 384 | Chart.UpdateEnabled = true;
|
---|
| 385 | Chart.EnforceUpdate();
|
---|
| 386 | }
|
---|
[7779] | 387 | }
|
---|
[8248] | 388 |
|
---|
| 389 | internal static class Util {
|
---|
[9963] | 390 | public static Color GetColor(this SymbolicExpressionTreeGenealogyGraphNode node) {
|
---|
[8556] | 391 | var colorIndex = (int)(node.Quality * ColorGradient.Colors.Count);
|
---|
[8248] | 392 | if (colorIndex >= ColorGradient.Colors.Count) --colorIndex;
|
---|
| 393 | return ColorGradient.Colors[colorIndex];
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
[7779] | 396 | }
|
---|