forked from haacked/seegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edges to reachable nodes are now highlighted
- Loading branch information
Showing
5 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using GraphSharp.Algorithms.Highlight; | ||
using QuickGraph; | ||
|
||
namespace SeeGit.Models | ||
{ | ||
public class ReachableHighlightAlgorithm<TVertex, TEdge, TGraph> : | ||
HighlightAlgorithmBase<TVertex, TEdge, TGraph, IHighlightParameters> where TVertex : class | ||
where TEdge : IEdge<TVertex> | ||
where TGraph : class, | ||
IBidirectionalGraph<TVertex, TEdge> | ||
{ | ||
// Methods | ||
public ReachableHighlightAlgorithm(IHighlightController<TVertex, TEdge, TGraph> controller, | ||
IHighlightParameters parameters) : base(controller, parameters) | ||
{ | ||
} | ||
|
||
private void ClearAllHighlights() | ||
{ | ||
ClearSemiHighlights(); | ||
foreach (TVertex local in Controller.HighlightedVertices) | ||
{ | ||
Controller.RemoveHighlightFromVertex(local); | ||
} | ||
foreach (TEdge local2 in Controller.HighlightedEdges) | ||
{ | ||
Controller.RemoveHighlightFromEdge(local2); | ||
} | ||
} | ||
|
||
private void ClearSemiHighlights() | ||
{ | ||
foreach (var vertex in Controller.SemiHighlightedVertices) | ||
{ | ||
Controller.RemoveSemiHighlightFromVertex(vertex); | ||
} | ||
foreach (var edge in Controller.SemiHighlightedEdges) | ||
{ | ||
Controller.RemoveSemiHighlightFromEdge(edge); | ||
} | ||
} | ||
|
||
public override bool OnEdgeHighlighting(TEdge edge) | ||
{ | ||
this.ClearAllHighlights(); | ||
if (!(!object.Equals(edge, default(TEdge)) && base.Controller.Graph.ContainsEdge(edge))) | ||
{ | ||
return false; | ||
} | ||
Controller.HighlightEdge(edge, null); | ||
Controller.SemiHighlightVertex(edge.Source, "Source"); | ||
Controller.SemiHighlightVertex(edge.Target, "Target"); | ||
return true; | ||
} | ||
|
||
public override bool OnEdgeHighlightRemoving(TEdge edge) | ||
{ | ||
ClearAllHighlights(); | ||
return true; | ||
} | ||
|
||
public override bool OnVertexHighlighting(TVertex vertex) | ||
{ | ||
if (!Controller.Graph.IsDirected) return false; | ||
ClearAllHighlights(); | ||
|
||
if (vertex == null || !Controller.Graph.ContainsVertex(vertex)) return false; | ||
|
||
Controller.HighlightVertex(vertex, "Source"); | ||
return HighlightChildren(vertex); | ||
} | ||
|
||
private bool HighlightChildren(TVertex vertex) | ||
{ | ||
if (vertex == null) return false; | ||
|
||
foreach (var outEdge in Controller.Graph.OutEdges(vertex)) | ||
{ | ||
Controller.SemiHighlightEdge(outEdge, "OutEdge"); | ||
if (Controller.IsHighlightedVertex(outEdge.Target)) continue; | ||
Controller.SemiHighlightVertex(outEdge.Target, "Target"); | ||
HighlightChildren(outEdge.Target); | ||
} | ||
return true; | ||
} | ||
|
||
public override bool OnVertexHighlightRemoving(TVertex vertex) | ||
{ | ||
ClearAllHighlights(); | ||
return true; | ||
} | ||
|
||
public override void ResetHighlight() | ||
{ | ||
ClearAllHighlights(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using GraphSharp.Algorithms.Highlight; | ||
using QuickGraph; | ||
|
||
namespace SeeGit.Models | ||
{ | ||
public class ReachableHighlightAlgorithmFactory<TVertex, TEdge, TGraph> : | ||
IHighlightAlgorithmFactory<TVertex, TEdge, TGraph> where TVertex : class | ||
where TEdge : IEdge<TVertex> | ||
where TGraph : class, IBidirectionalGraph<TVertex, TEdge> | ||
{ | ||
private const string HighlightModeName = "Reachable"; | ||
|
||
public IHighlightAlgorithm<TVertex, TEdge, TGraph> CreateAlgorithm(string highlightMode, | ||
IHighlightContext<TVertex, TEdge, TGraph> | ||
context, | ||
IHighlightController<TVertex, TEdge, TGraph> | ||
controller, | ||
IHighlightParameters parameters) | ||
{ | ||
if (string.IsNullOrEmpty(highlightMode) || highlightMode == HighlightModeName) | ||
{ | ||
return new ReachableHighlightAlgorithm<TVertex, TEdge, TGraph>(controller, parameters); | ||
} | ||
return null; | ||
} | ||
|
||
public IHighlightParameters CreateParameters(string highlightMode, IHighlightParameters oldParameters) | ||
{ | ||
return new HighlightParameterBase(); | ||
} | ||
|
||
public string GetHighlightMode(IHighlightAlgorithm<TVertex, TEdge, TGraph> algorithm) | ||
{ | ||
if (algorithm is ReachableHighlightAlgorithm<TVertex, TEdge, TGraph>) | ||
{ | ||
return HighlightModeName; | ||
} | ||
return null; | ||
} | ||
|
||
public bool IsValidMode(string mode) | ||
{ | ||
return string.IsNullOrEmpty(mode) || mode == HighlightModeName; | ||
} | ||
|
||
// Properties | ||
public IEnumerable<string> HighlightModes | ||
{ | ||
get { yield return HighlightModeName; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
using GraphSharp.Controls; | ||
using SeeGit.Models; | ||
|
||
namespace SeeGit | ||
{ | ||
public class RepositoryGraphLayout : GraphLayout<CommitVertex, CommitEdge, RepositoryGraph> | ||
{ | ||
public RepositoryGraphLayout() | ||
{ | ||
HighlightAlgorithmFactory = | ||
new ReachableHighlightAlgorithmFactory<CommitVertex, CommitEdge, RepositoryGraph>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters