Changeset 15561 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs
- Timestamp:
- 12/29/17 16:43:29 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/GenealogyGraphChart.cs
r13877 r15561 32 32 public partial class GenealogyGraphChart : ChartControl { 33 33 private IGenealogyGraph genealogyGraph; 34 private const double XIncrement = 30;35 private const double YIncrement = 30;34 private const double XIncrement = 25; 35 private const double YIncrement = 25; 36 36 private const double Diameter = 20; 37 37 private readonly Brush defaultBrush; … … 44 44 public bool SimpleLineages { get; set; } 45 45 public bool LockGenealogy { get; set; } 46 public bool TraceFragments{ get; set; }46 public Func<IGenealogyGraphNode, Color> ColorSelector { get; set; } 47 47 #endregion 48 48 … … 98 98 } 99 99 100 public GenealogyGraphChart() : base(new Chart(0, 0, 800, 600)) {100 public GenealogyGraphChart() : base(new GridlessChart(0, 0, 800, 600)) { 101 101 InitializeComponent(); 102 102 AddChartModes(new PanChartMode(this), new ZoomInChartMode(this), new ZoomOutChartMode(this), new SelectChartMode(this)); 103 103 defaultBrush = new SolidBrush(Color.Transparent); 104 104 defaultPen = new Pen(Color.DarkGray); 105 106 ColorSelector = node => ColorGradient.Colors[(int)Math.Round(node.Quality * 255)]; 105 107 } 106 108 … … 114 116 115 117 foreach (var rank in ranks) { 118 var rect = new Visualization.Rectangle(Chart, new PointD(x, y), new PointD(x + diameter, y + diameter)); 119 var font = new Font(FontFamily.GenericSansSerif, 12); 120 var genLabel = new LabeledPrimitive(rect, rank.Rank.ToString(), font); 121 Chart.Group.Add(genLabel); 122 123 x += xIncrement; 124 116 125 var nodes = rank.Nodes.ToList(); 117 126 nodes.Sort((a, b) => b.CompareTo(a)); // sort descending by quality … … 119 128 120 129 foreach (var node in nodes) { 121 var brush = new SolidBrush( node.GetColor());130 var brush = new SolidBrush(ColorSelector(node)); 122 131 var visualNode = new VisualGenealogyGraphNode(Chart, x, y, x + diameter, y + diameter, defaultPen, brush) { 123 132 Data = node, … … 199 208 var visualNode = GetMappedNode(graphNode); 200 209 201 DrawLineage(visualNode, n => SimpleLineages ? n.IncomingArcs.Take(1) : n.IncomingArcs, a => a.Source );210 DrawLineage(visualNode, n => SimpleLineages ? n.IncomingArcs.Take(1) : n.IncomingArcs, a => a.Source, ColorSelector); 202 211 ((SolidBrush)visualNode.Brush).Color = Color.Transparent; 203 DrawLineage(visualNode, n => n.OutgoingArcs, a => a.Target );212 DrawLineage(visualNode, n => n.OutgoingArcs, a => a.Target, ColorSelector); 204 213 } 205 214 … … 212 221 213 222 #region drawing routines 214 private static void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector ) {223 private static void DrawLineage(VisualGenealogyGraphNode node, Func<VisualGenealogyGraphNode, IEnumerable<VisualGenealogyGraphArc>> arcSelector, Func<VisualGenealogyGraphArc, VisualGenealogyGraphNode> nodeSelector, Func<IGenealogyGraphNode, Color> getNodeColor) { 215 224 var brush = (SolidBrush)node.Brush; 216 225 if (brush.Color != Color.Transparent) return; // this lineage was already drawn (avoid redrawing common ancestors) 217 brush.Color = node.Data.GetColor();226 brush.Color = getNodeColor(node.Data); 218 227 var arcs = arcSelector(node); 219 228 var pen = new Pen(Color.Transparent); … … 224 233 var end = new Point((int)arc.End.X, (int)arc.End.Y); 225 234 arc.Pen = pen; 226 arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor());227 DrawLineage(nodeSelector(arc), arcSelector, nodeSelector );235 arc.Pen.Brush = new LinearGradientBrush(start, end, getNodeColor(source), getNodeColor(target)); 236 DrawLineage(nodeSelector(arc), arcSelector, nodeSelector, getNodeColor); 228 237 } 229 238 } … … 287 296 foreach (var node in nodes) { 288 297 var graphNode = GetMappedNode(node); 289 graphNode.Brush = new SolidBrush( node.GetColor());298 graphNode.Brush = new SolidBrush(ColorSelector(node)); 290 299 } 291 300 } … … 302 311 public void HighlightAll() { 303 312 foreach (var visualNode in nodeMap.Values) { 304 visualNode.Brush = new SolidBrush(visualNode.Data.GetColor()); 305 } 313 visualNode.Brush = new SolidBrush(ColorSelector(visualNode.Data)); 314 Chart.IntoForeground(visualNode); 315 } 316 // draw arcs first and then nodes 306 317 foreach (var arc in arcMap.Values) { 307 318 var source = arc.Source.Data; … … 309 320 var start = new Point((int)arc.Start.X, (int)arc.Start.Y); 310 321 var end = new Point((int)arc.End.X, (int)arc.End.Y); 311 arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor()); 322 arc.Pen = new Pen(new LinearGradientBrush(start, end, ColorSelector(source), ColorSelector(target))); 323 Chart.IntoBackground(arc); 312 324 } 313 325 } … … 319 331 var end = new Point((int)arc.End.X, (int)arc.End.Y); 320 332 arc.Pen = new Pen(Color.Transparent); 321 arc.Pen.Brush = new LinearGradientBrush(start, end, source.GetColor(), target.GetColor()); 333 arc.Pen = new Pen(new LinearGradientBrush(start, end, ColorSelector(source), ColorSelector(target))); 334 Chart.IntoBackground(arc); 322 335 } 323 336 #endregion 324 } 325 326 internal static class Util { 327 public static Color GetColor(this IGenealogyGraphNode node) { 328 if (double.IsNaN(node.Quality)) 329 return ColorGradient.Colors[0]; 330 var colorIndex = (int)Math.Round(node.Quality * ColorGradient.Colors.Count); 331 if (colorIndex >= ColorGradient.Colors.Count) return ColorGradient.Colors.Last(); 332 return ColorGradient.Colors[colorIndex]; 337 338 // workaround to disable the chart grid 339 private class GridlessChart : Chart { 340 public GridlessChart(PointD lowerLeft, PointD upperRight) : base(lowerLeft, upperRight) { 341 Grid = null; 342 } 343 344 public GridlessChart(double x1, double y1, double x2, double y2) : this(new PointD(x1, y1), new PointD(x2, y2)) { } 333 345 } 334 346 }
Note: See TracChangeset
for help on using the changeset viewer.