Browse Source

Object graph - zoom using Ctrl+mouse wheel. Fixed edge labels.

pull/15/head
mkonicek 15 years ago
parent
commit
5121434f13
  1. 12
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Controls/DragScrollViewer.cs
  2. 13
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs
  3. 9
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/GraphEdgeRouter.cs
  4. 18
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedEdge.cs
  5. 19
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/SplineRouting/EdgeRouter.cs
  6. 6
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml
  7. 9
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs

12
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Controls/DragScrollViewer.cs

@ -22,9 +22,15 @@ namespace Debugger.AddIn.Visualizers.Controls
this.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; this.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
this.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; this.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
this.PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(DragScrollViewer_PreviewMouseDown); this.PreviewMouseDown += DragScrollViewer_PreviewMouseDown;
this.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(DragScrollViewer_PreviewMouseMove); this.PreviewMouseMove += DragScrollViewer_PreviewMouseMove;
this.PreviewMouseUp += new System.Windows.Input.MouseButtonEventHandler(DragScrollViewer_PreviewMouseUp); this.PreviewMouseUp += DragScrollViewer_PreviewMouseUp;
this.MouseWheel += DragScrollViewer_MouseWheel;
}
void DragScrollViewer_MouseWheel(object sender, MouseWheelEventArgs e)
{
MessageBox.Show("w");
} }
void DragScrollViewer_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) void DragScrollViewer_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

13
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs

@ -137,8 +137,7 @@ namespace Debugger.AddIn.Visualizers.Graph
Path AddEdgeToCanvas(PositionedEdge edge) Path AddEdgeToCanvas(PositionedEdge edge)
{ {
PathFigure edgeSplineFigure = CreateEdgeSpline(edge); var edgeSplineFigure = CreateEdgeSpline(edge);
PathGeometry geometryVisible = new PathGeometry(); PathGeometry geometryVisible = new PathGeometry();
geometryVisible.Figures.Add(edgeSplineFigure); geometryVisible.Figures.Add(edgeSplineFigure);
geometryVisible.Figures.Add(CreateEdgeArrow(edge)); geometryVisible.Figures.Add(CreateEdgeArrow(edge));
@ -149,6 +148,11 @@ namespace Debugger.AddIn.Visualizers.Graph
pathVisible.StrokeThickness = 1; pathVisible.StrokeThickness = 1;
pathVisible.Data = geometryVisible; pathVisible.Data = geometryVisible;
// remember this spline Path at PositionedEdge to be able to highlight edge from PositionedNodeProperty
edge.Spline = pathVisible;
// and remember the the edge for the spline, so that we can get edge name on spline mouse-over
pathVisible.Tag = edge;
PathGeometry geometryInVisible = new PathGeometry(); PathGeometry geometryInVisible = new PathGeometry();
geometryInVisible.Figures.Add(edgeSplineFigure); geometryInVisible.Figures.Add(edgeSplineFigure);
@ -179,12 +183,9 @@ namespace Debugger.AddIn.Visualizers.Graph
Canvas.SetTop(this.edgeTooltip, mousePos.Y - 20); Canvas.SetTop(this.edgeTooltip, mousePos.Y - 20);
}; };
// remember this spline Path at PositionedEdge to be able to highlight edge from PositionedNodeProperty
edge.Spline = pathVisible;
canvas.Children.Add(pathVisible); canvas.Children.Add(pathVisible);
canvas.Children.Add(pathInVisible); canvas.Children.Add(pathInVisible);
pathVisible.Tag = edge;
return pathVisible; return pathVisible;
} }

9
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/GraphEdgeRouter.cs

@ -23,12 +23,9 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout
public void RouteEdges(PositionedGraph posGraph) public void RouteEdges(PositionedGraph posGraph)
{ {
List<RoutedEdge> routedEdges = router.RouteEdges(posGraph.Nodes, posGraph.Edges); Dictionary<PositionedEdge, RoutedEdge> routedEdges = router.RouteEdges(posGraph.Nodes, posGraph.Edges);
int i = 0; foreach (var edgePair in routedEdges) {
// assume routedEdges come in the same order as posGraph.Edges SetEdgeSplinePoints(edgePair.Key, edgePair.Value);
foreach (var edge in posGraph.Edges) {
SetEdgeSplinePoints(edge, routedEdges[i]);
i++;
} }
} }

18
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedEdge.cs

@ -19,14 +19,8 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout
/// </summary> /// </summary>
public IList<Point> SplinePoints public IList<Point> SplinePoints
{ {
get get { return splinePoints; }
{ set { splinePoints = value; }
return splinePoints;
}
set
{
splinePoints = value;
}
} }
/// <summary> /// <summary>
@ -35,15 +29,11 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout
public System.Windows.Shapes.Path Spline { get; set; } public System.Windows.Shapes.Path Spline { get; set; }
public SplineRouting.IRect From { public SplineRouting.IRect From {
get { get { return this.Source.ContainingNode; }
return this.Source.ContainingNode;
}
} }
public SplineRouting.IRect To { public SplineRouting.IRect To {
get { get { return this.Target; }
return this.Target;
}
} }
} }
} }

19
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/SplineRouting/EdgeRouter.cs

@ -16,24 +16,25 @@ namespace Debugger.AddIn.Visualizers.Graph.SplineRouting
{ {
} }
public List<RoutedEdge> RouteEdges(IEnumerable<IRect> nodes, IEnumerable<IEdge> edges) public Dictionary<TEdge, RoutedEdge> RouteEdges<TEdge>(IEnumerable<IRect> nodes, IEnumerable<TEdge> edges) where TEdge : class, IEdge
{ {
var routeGraph = RouteGraph.InitializeVertices(nodes, edges); var routeGraph = RouteGraph.InitializeVertices(nodes, edges);
List<RoutedEdge> routedEdges = new List<RoutedEdge>(); var routedEdges = new Dictionary<TEdge, RoutedEdge>();
var occludedEdges = new List<IEdge>(); var occludedEdges = new List<TEdge>();
foreach (IEdge edge in edges) { foreach (var edge in edges) {
var straightEdge = routeGraph.TryRouteEdgeStraight(edge); var straightEdge = routeGraph.TryRouteEdgeStraight(edge);
if (straightEdge != null) if (straightEdge != null) {
routedEdges.Add(straightEdge); routedEdges[edge] = straightEdge;
else } else {
occludedEdges.Add(edge); occludedEdges.Add(edge);
} }
}
if (occludedEdges.Count > 0) { if (occludedEdges.Count > 0) {
// there are some edges that couldn't be routed as straight lines // there are some edges that couldn't be routed as straight lines
routeGraph.ComputeVisibilityGraph(); routeGraph.ComputeVisibilityGraph();
foreach (IEdge edge in occludedEdges) { foreach (var edge in occludedEdges) {
RoutedEdge routedEdge = routeGraph.RouteEdge(edge); RoutedEdge routedEdge = routeGraph.RouteEdge(edge);
routedEdges.Add(routedEdge); routedEdges[edge] = routedEdge;
} }
} }
return routedEdges; return routedEdges;

6
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml

@ -39,8 +39,10 @@
</Border> </Border>
</StackPanel> </StackPanel>
<controls:DragScrollViewer x:Name="scroller" Margin="0 4 0 0" Grid.Row="1" Grid.Column="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <controls:DragScrollViewer x:Name="scroller" Margin="0 4 0 0" Grid.Row="1" Grid.Column="0" Background="White" PreviewMouseWheel="Canvas_MouseWheel"
<Canvas HorizontalAlignment="Left" VerticalAlignment="Top" Name="canvas" Margin="4"> HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Canvas x:Name="canvas" Margin="4"
HorizontalAlignment="Left" VerticalAlignment="Top">
<Canvas.LayoutTransform> <Canvas.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=Value, ElementName=zoomSlider}" <ScaleTransform ScaleX="{Binding Path=Value, ElementName=zoomSlider}"
ScaleY="{Binding Path=Value, ElementName=zoomSlider}"/> ScaleY="{Binding Path=Value, ElementName=zoomSlider}"/>

9
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs

@ -36,6 +36,8 @@ namespace Debugger.AddIn.Visualizers.Graph
private PositionedGraph currentPosGraph; private PositionedGraph currentPosGraph;
private GraphDrawer graphDrawer; private GraphDrawer graphDrawer;
static double mouseWheelZoomSpeed = 0.05;
/// <summary> Long-lived map telling which graph nodes and content nodes the user expanded. </summary> /// <summary> Long-lived map telling which graph nodes and content nodes the user expanded. </summary>
private Expanded expanded = new Expanded(); private Expanded expanded = new Expanded();
@ -220,5 +222,12 @@ namespace Debugger.AddIn.Visualizers.Graph
e.Property.ObjectGraphProperty.TargetNode = null; e.Property.ObjectGraphProperty.TargetNode = null;
LayoutGraph(this.objectGraph); LayoutGraph(this.objectGraph);
} }
void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) {
zoomSlider.Value += e.Delta > 0 ? mouseWheelZoomSpeed : -mouseWheelZoomSpeed;
}
}
} }
} }

Loading…
Cancel
Save