Skip to content

Commit

Permalink
Fix issues noted in code review by @koschke
Browse files Browse the repository at this point in the history
  • Loading branch information
falko17 committed Oct 28, 2023
1 parent 93c5152 commit 6900a90
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 15 additions & 2 deletions Assets/SEE/DataModel/DG/GraphSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace SEE.DataModel.DG
{
/// <summary>
/// Allows searching for nodes by their string representation.
/// Allows searching for nodes by their source name.
/// The graph associated to this search may be dynamic – that is, when the graph changes
/// (for example, when a node is added), the search index will be updated accordingly.
/// Searches are fuzzy, i.e., they will return results even if the query does not match the
Expand Down Expand Up @@ -40,7 +40,9 @@ public GraphSearch(Graph graph)
}

/// <summary>
/// Performs a fuzzy search for the given <paramref name="query"/> in the graph.
/// Performs a fuzzy search for the given <paramref name="query"/> in the graph,
/// by comparing it to the source name of the nodes.
/// Case will be ignored, and the query may be a substring of the source name (this is a fuzzy search).
/// </summary>
/// <param name="query">The query to be searched for.</param>
/// <returns>A list of nodes which match the query.</returns>
Expand Down Expand Up @@ -108,16 +110,27 @@ private static string ElementToString(Node element)
return element.SourceName.ToLowerInvariant();
}

/// <summary>
/// Called when no more events will be fired from the graph.
/// </summary>
public void OnCompleted()
{
// Nothing to be done.
}

/// <summary>
/// Called when an error occurs in the graph.
/// </summary>
/// <param name="error">The error which occurred.</param>
public void OnError(Exception error)
{
throw error;
}

/// <summary>
/// Called when a new event is fired from the graph.
/// </summary>
/// <param name="changeEvent">The event which was fired.</param>
public void OnNext(ChangeEvent changeEvent)
{
// We want to update our mapping of names to nodes whenever a node is added or removed.
Expand Down
1 change: 0 additions & 1 deletion Assets/SEE/UI/Window/TreeWindow/DesktopTreeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public partial class TreeWindow
/// <param name="orderBelow">The node below which the tree should be ordered.</param>
private void OrderTree(Node orderBelow)
{
Debug.Log("Ordering tree.");
int index = items.Find(CleanupID(orderBelow.ID)).GetSiblingIndex();
OrderTreeRecursive(orderBelow);

Expand Down
9 changes: 7 additions & 2 deletions Assets/SEE/Utils/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Color IdealTextColor(this Color backgroundColor)
{
const int nThreshold = 130;
int bgDelta = Convert.ToInt32((backgroundColor.r * 255 * 0.299) + (backgroundColor.g * 255 * 0.587)
+ (backgroundColor.b * 255 * 0.114));
+ (backgroundColor.b * 255 * 0.114));
return (255 - bgDelta < nThreshold) ? Color.black : Color.white;
}

Expand All @@ -81,7 +81,12 @@ public static Color Invert(this Color color)
/// <returns>The converted colors as gradient color keys.</returns>
public static IEnumerable<GradientColorKey> ToGradientColorKeys(this ICollection<Color> colors)
{
return colors.Select((c, i) => new GradientColorKey(c, (float) i / (colors.Count-1)));
return colors.Count switch
{
0 => new List<GradientColorKey>(),
1 => new List<GradientColorKey> { new(colors.First(), 0f) },
var n => colors.Select((c, i) => new GradientColorKey(c, (float)i / (n - 1)))
};
}

/// <summary>
Expand Down

0 comments on commit 6900a90

Please sign in to comment.