Skip to content

Commit

Permalink
Edges to reachable nodes are now highlighted
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Mar 6, 2012
1 parent 6c54d6b commit 52ae7d1
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SeeGitApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<zoom:ZoomControl Grid.Row="1" Zoom="0.2" ZoomBoxOpacity="0.5" Background="#ff656565">
<local:RepositoryGraphLayout x:Name="graphLayout" Margin="10" Graph="{Binding Graph}"
LayoutAlgorithmType="{Binding LayoutAlgorithmType, Mode=OneWay}" OverlapRemovalAlgorithmType="FSA"
FlowDirection="LeftToRight" HighlightAlgorithmType="Simple" />
FlowDirection="LeftToRight" />
</zoom:ZoomControl>
</Grid>
</Window>
98 changes: 98 additions & 0 deletions SeeGitApp/Models/ReachableHighlightAlgorithm.cs
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();
}
}
}
53 changes: 53 additions & 0 deletions SeeGitApp/Models/ReachableHighlightAlgorithmFactory.cs
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; }
}
}
}
6 changes: 6 additions & 0 deletions SeeGitApp/Models/RepositoryGraphLayout.cs
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>();
}
}
}
6 changes: 2 additions & 4 deletions SeeGitApp/SeeGitApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\GraphSharp.dll</HintPath>
</Reference>
<Reference Include="GraphSharp.Contracts, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\GraphSharp.Contracts.dll</HintPath>
</Reference>
<Reference Include="GraphSharp.Controls, Version=1.0.4115.29430, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\GraphSharp.Controls.dll</HintPath>
Expand Down Expand Up @@ -103,6 +99,8 @@
<Compile Include="Extensions\ReactiveExtensions.cs" />
<Compile Include="Extensions\WindowsExtensions.cs" />
<Compile Include="Models\IRepositoryGraphBuilder.cs" />
<Compile Include="Models\ReachableHighlightAlgorithm.cs" />
<Compile Include="Models\ReachableHighlightAlgorithmFactory.cs" />
<Compile Include="Models\RepositoryGraphBuilder.cs" />
<Compile Include="Models\RepositoryGraphLayout.cs" />
<Compile Include="ViewModels\DesignTimeMainWindowViewModel.cs" />
Expand Down

0 comments on commit 52ae7d1

Please sign in to comment.