Skip to content

Commit

Permalink
Better color choice for graphs with many different quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Becker committed Oct 22, 2018
1 parent a1fca4f commit f688bd9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions source/DAGView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public partial class DAGView : UserControl
private readonly List<Color> colors = new List<Color> {Color.Purple, Color.Blue,
Color.Green, Color.LawnGreen, Color.Orange, Color.DarkKhaki, Color.DarkGray, Color.Moccasin,
Color.DarkSeaGreen, Color.Silver, Color.Salmon, Color.LemonChiffon, Color.Fuchsia,
Color.ForestGreen, Color.Beige, Color.AliceBlue, Color.MediumTurquoise, Color.Tomato
Color.ForestGreen, Color.Beige, Color.AliceBlue, Color.MediumTurquoise, Color.Tomato,
Color.Black
};

private static readonly Color selectionColor = Color.Red;
Expand Down Expand Up @@ -112,7 +113,11 @@ private void drawGraphWithInstantiations(List<Instantiation> newNodeInsts)

if (checkNumNodesWithDialog(ref newNodeInsts)) return;

foreach (var node in newNodeInsts.Select(connectToVisibleNodes))
// Sorting helps ensure that the most common quantifiers end up with different colors
var prioritySortedNewNodeInsts = newNodeInsts.GroupBy(inst => inst.Quant)
.OrderByDescending(group => group.Count())
.SelectMany(group => group);
foreach (var node in prioritySortedNewNodeInsts.Select(connectToVisibleNodes))
{
formatNode(node);
}
Expand Down Expand Up @@ -146,12 +151,7 @@ private Color getColor(Quantifier quant)
{
if (!colorMap.TryGetValue(quant, out var color))
{
color = colors.FirstOrDefault(c => !colorMap.Values.Contains(c));
if (color == default(Color))
{
color = Color.Black;
}

color = colors.OrderBy(c => colorMap.Values.Count(used => used == c)).First();
colorMap[quant] = color;
}

Expand Down

0 comments on commit f688bd9

Please sign in to comment.