Skip to content

Commit

Permalink
Adjust compact mode so that if a parent line has all children line of…
Browse files Browse the repository at this point in the history
… only +1

depth, then all of those children are entered and accumulated for display,
instead of only working if the parent only has one child line.
  • Loading branch information
Kinematics committed Jun 11, 2017
1 parent c600c45 commit a825c50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions NetTally.Core/Output/Utility/VoteInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ public static IEnumerable<VoteNode> GetVoteNodes(IGrouping<string, KeyValuePair<
{
parent.AddVoters(vote.Value);
}
else if (lines.Skip(1).All(a => VoteString.GetVotePrefix(a).Length == 1))
{
foreach (var line in lines.Skip(1))
{
parent.AddChild(line, vote.Value);
}
}
else if (lines.Count == 2 && !string.IsNullOrEmpty(VoteString.GetVotePrefix(lines[1])))
{
parent.AddChild(lines[1], vote.Value);
Expand Down
14 changes: 12 additions & 2 deletions NetTally.Core/Output/Utility/VoteNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,18 @@ public void AddVoters(HashSet<string> voters)
/// <param name="voters">Voters for the child node.</param>
public void AddChild(string text, HashSet<string> voters)
{
VoteNode child = new VoteNode(text, voters, this);
Children.Add(child);
VoteNode child = Children.FirstOrDefault(c => Agnostic.StringComparer.Equals(c.Text, text));

if (child == null)
{
child = new VoteNode(text, voters, this);
Children.Add(child);
}
else
{
child.AddVoters(voters);
}

AllVoters.UnionWith(child.Voters);
}

Expand Down

0 comments on commit a825c50

Please sign in to comment.