Skip to content

Commit

Permalink
+ Enhanced parallel edges mini showcase
Browse files Browse the repository at this point in the history
+ Further fixes to parallel edges logic related to labels and performance
  • Loading branch information
panthernet committed Jun 28, 2015
1 parent 1a444ca commit 771aab2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
27 changes: 17 additions & 10 deletions Examples/ShowcaseApp.WPF/Pages/Mini/EdgesParallel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,25 @@ private void GenerateGraph()
{
var logicCore = new LogicCoreExample()
{
Graph = ShowcaseHelper.GenerateDataGraph(4, false)
Graph = ShowcaseHelper.GenerateDataGraph(3, false)
};
var vList = logicCore.Graph.Vertices.ToList();

//add edges
ShowcaseHelper.AddEdge(logicCore.Graph, vList[1], vList[0]);
ShowcaseHelper.AddEdge(logicCore.Graph, vList[0], vList[1]);
ShowcaseHelper.AddEdge(logicCore.Graph, vList[2], vList[3]);
ShowcaseHelper.AddEdge(logicCore.Graph, vList[1], vList[0]);

ShowcaseHelper.AddEdge(logicCore.Graph, vList[1], vList[2]);
ShowcaseHelper.AddEdge(logicCore.Graph, vList[1], vList[2]);
ShowcaseHelper.AddEdge(logicCore.Graph, vList[2], vList[1]);

graphArea.LogicCore = logicCore;
//set positions
var posList = new Dictionary<DataVertex, Point>()
{
{vList[0], new Point(0, 0)},
{vList[0], new Point(0, -150)},
{vList[1], new Point(300, 0)},
{vList[2], new Point(0, 300)},
{vList[3], new Point(300, 300)},
{vList[2], new Point(600, -150)},
};

//settings
Expand All @@ -80,15 +82,20 @@ private void GenerateGraph()
//preload graph
graphArea.PreloadGraph(posList);
//behaviors
graphArea.SetVerticesDrag(true, true);
graphArea.ShowAllEdgesLabels();
graphArea.AlignAllEdgesLabels();
zoomControl.MaxZoom = 50;
//manual edge corrections
var eList = graphArea.EdgesList.Values.ToList();
eList[0].LabelVerticalOffset = 12;
eList[1].LabelVerticalOffset = 12;
eList[2].LabelVerticalOffset = 12;

graphArea.SetVerticesDrag(true, true);
graphArea.ShowAllEdgesLabels();
graphArea.AlignAllEdgesLabels();
eList[2].ShowLabel = false;
eList[3].LabelVerticalOffset = 12;
eList[4].LabelVerticalOffset = 12;

//PS: to see how parallel edges logic works go to GraphArea::UpdateParallelEdgesData() method

zoomControl.ZoomToFill();
}
Expand Down
10 changes: 5 additions & 5 deletions GraphX.Controls/Controls/EdgeControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ internal virtual void UpdateEdgeRendering(bool updateLabel = true)
}


internal int SourceOffset;
internal int TargetOffset;
internal int ParallelEdgeOffset;
//internal int TargetOffset;

/// <summary>
/// Gets the offset point for edge parallelization
Expand Down Expand Up @@ -685,10 +685,10 @@ public virtual void PrepareEdgePath(bool useCurrentCoords = false, Measure.Point
var hasRouteInfo = routeInformation != null && routeInformation.Length > 1;

//calculate source and target edge attach points
if (RootArea != null && !hasRouteInfo && RootArea.EnableParallelEdges)
if (RootArea != null && !hasRouteInfo && RootArea.EnableParallelEdges && ParallelEdgeOffset != 0)
{
if (SourceOffset != 0) sourcePos = GetParallelOffset(Source, Target, SourceOffset);
if (TargetOffset != 0) targetPos = GetParallelOffset(Target, Source, TargetOffset);
sourcePos = GetParallelOffset(Source, Target, ParallelEdgeOffset);
targetPos = GetParallelOffset(Target, Source, -ParallelEdgeOffset);
}

/* Rectangular shapes implementation by bleibold */
Expand Down
11 changes: 4 additions & 7 deletions GraphX.Controls/Controls/GraphArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,19 +1152,16 @@ public void UpdateParallelEdgesData()
//leave first edge intact if we have not even edges count
for (int i = even ? 0 : 1; i < list.Count; i++)
{
//var dist = ParallelEdgeDistance;
//if (chet && i < 2) dist = distance;
//if (cList[i] && ((!chet && !prevc) || list.Count == 2)) viceversa = !viceversa;
//if source to target edge
if (!cList[i])
{
list[i].SourceOffset = (viceversa ? -distance : distance) * (1 + ((even ? i : i - 1) / 2));
list[i].TargetOffset = -list[i].SourceOffset;
list[i].ParallelEdgeOffset = (viceversa ? -distance : distance) * (1 + ((even ? i : i - 1) / 2));
//list[i].TargetOffset = -list[i].ParallelEdgeOffset;
}
else //if target to source edge - just switch offsets
{
list[i].TargetOffset = (viceversa ? -distance : distance) * (1 + ((even ? i : i - 1) / 2));
list[i].SourceOffset = -list[i].TargetOffset;
list[i].ParallelEdgeOffset = -((viceversa ? -distance : distance) * (1 + ((even ? i : i - 1) / 2)));
//list[i].ParallelEdgeOffset = -list[i].TargetOffset;
}
//change trigger to opposite
viceversa = !viceversa;
Expand Down
8 changes: 4 additions & 4 deletions GraphX.METRO.Controls/Controls/GraphArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,13 @@ public void UpdateParallelEdgesData()
//if source to target edge
if (!cList[i])
{
list[i].SourceOffset = (viceversa ? distance : -distance) * (1 + ((even ? i : i - 1) / 2));
list[i].TargetOffset = -list[i].SourceOffset;
list[i].ParallelEdgeOffset = (viceversa ? distance : -distance) * (1 + ((even ? i : i - 1) / 2));
// list[i].TargetOffset = -list[i].SourceOffset;
}
else //if target to source edge - just switch offsets
{
list[i].TargetOffset = (viceversa ? distance : -distance) * (1 + ((even ? i : i - 1) / 2));
list[i].SourceOffset = -list[i].TargetOffset;
list[i].ParallelEdgeOffset = -((viceversa ? distance : -distance) * (1 + ((even ? i : i - 1) / 2)));
//list[i].SourceOffset = -list[i].TargetOffset;
}
//change trigger to opposite
viceversa = !viceversa;
Expand Down

0 comments on commit 771aab2

Please sign in to comment.