Skip to content
This repository was archived by the owner on Nov 29, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ src/Graphviz4Net.v12.suo
.vs/slnx.sqlite
src/.vs/Graphviz4Net/v15/.suo
src/.vs/Graphviz4Net/v15/sqlite3/storage.ide
.vs
*.bak
Binary file added src/Graphviz4Net.WPF.Example/Assets/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/Graphviz4Net.WPF.Example/Graphviz4Net.WPF.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<Resource Include="Avatars\avatar3.jpg" />
<Resource Include="Avatars\avatarAnon.gif" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\error.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
8 changes: 8 additions & 0 deletions src/Graphviz4Net.WPF.Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
<Path Data="{Binding Data}" Stroke="Black" StrokeThickness="1" ToolTip="{Binding Edge.Label}"/>
</DataTemplate>

<DataTemplate x:Key="ErrorTemplate">
<StackPanel Orientation="Horizontal">
<Image Source="pack://application:,,,/Graphviz4Net.WPF.Example;component/Assets/error.png"/>
<TextBlock Text="{Binding ErrorMessage}" TextWrapping="Wrap" Width="300"/>
</StackPanel>
</DataTemplate>

<ObjectDataProvider x:Key="dataFromLayoutEngineEnum" MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
Expand Down Expand Up @@ -144,6 +151,7 @@
<WPF:GraphLayout
UseContentPresenterForAllElements="True"
LogGraphvizOutput="True"
ErrorTemplate="{StaticResource ErrorTemplate}"
Graph="{Binding Graph}"
Engine="{Binding LayoutEngine}"
x:Name="GraphLayout">
Expand Down
4 changes: 4 additions & 0 deletions src/Graphviz4Net.WPF.Example/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public LayoutEngine LayoutEngine
public string UpdatePersonName { get; set; }

public string UpdatePersonNewName { get; set; }
public string DotExecutablePath
{
get { return @"C:\Program Files (x86)\Graphviz2.38\bin"; }
}

public IEnumerable<string> PersonNames
{
Expand Down
43 changes: 27 additions & 16 deletions src/Graphviz4Net.WPF/GraphLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Graphviz4Net.WPF
using Graphs;
#if !SILVERLIGHT
using System.Threading.Tasks;
using System.Windows.Data;
#endif

[TemplatePart(Name = "PART_Canvas", Type = typeof(Canvas))]
Expand Down Expand Up @@ -53,6 +54,13 @@ public class GraphLayout : Control
typeof(GraphLayout),
new PropertyMetadata(string.Empty));

public static readonly DependencyProperty ErrorTemplateProperty =
DependencyProperty.Register(
"ErrorTemplate",
typeof(DataTemplate),
typeof(GraphLayout),
new PropertyMetadata());

private LayoutDirector director;

private Exception backgroundException = null;
Expand All @@ -64,7 +72,7 @@ static GraphLayout()
{
DefaultStyleKeyProperty.OverrideMetadata(
typeof(GraphLayout),
new FrameworkPropertyMetadata(typeof(GraphLayout)));
new FrameworkPropertyMetadata(typeof(GraphLayout)));
}
#endif

Expand Down Expand Up @@ -135,6 +143,12 @@ public string DotExecutablePath
set { this.SetValue(DotExecutablePathProperty, value); }
}

public DataTemplate ErrorTemplate
{
get { return (DataTemplate)this.GetValue(ErrorTemplateProperty); }
set { this.SetValue(ErrorTemplateProperty, value); }
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Expand All @@ -143,7 +157,7 @@ public override void OnApplyTemplate()
}

private static void OnUseContentPresenterForAllElementsChanged(
DependencyObject dependencyObject,
DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs args)
{
var graphLayout = (GraphLayout)dependencyObject;
Expand All @@ -153,7 +167,7 @@ private static void OnUseContentPresenterForAllElementsChanged(
}
else
{
graphLayout.elementsFactory = new DefaultLayoutElementsFactory();
graphLayout.elementsFactory = new DefaultLayoutElementsFactory();
}
}

Expand All @@ -175,7 +189,7 @@ private void GraphChanged(object sender, GraphChangedArgs e)
private void UpdateVerticesLayout()
{
if (this.canvas == null ||
this.Graph == null ||
this.Graph == null ||
DesignerProperties.GetIsInDesignMode(this))
{
return;
Expand Down Expand Up @@ -217,13 +231,7 @@ private void UpdateVerticesLayout()
}
catch (Exception ex)
{
var textBlock = new TextBlock { Width = 300, TextWrapping = TextWrapping.Wrap };
textBlock.Text =
string.Format(
"Graphviz4Net: an exception was thrown during layouting." +
"Exception message: {0}.",
ex.Message);
this.canvas.Children.Add(textBlock);
ShowError(ex);
}
}

Expand Down Expand Up @@ -255,14 +263,17 @@ private void BuildGraph()

private void ShowError(Exception ex)
{
var textBlock = new TextBlock { Width = 300, TextWrapping = TextWrapping.Wrap };
textBlock.Text =
string.Format(
var content = new ContentControl { ContentTemplate = ErrorTemplate, Width = 300 };
content.Content = new
{
ErrorMessage = string.Format(
"Graphviz4Net: an exception was thrown during layouting." +
"Exception message: {0}.",
ex.Message);
ex.Message),
Error = ex
};
this.canvas.Children.Clear();
this.canvas.Children.Add(textBlock);
this.canvas.Children.Add(content);
}

private delegate void VoidDelegate();
Expand Down
5 changes: 5 additions & 0 deletions src/Graphviz4Net.WPF/Themes/Generic.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:GraphvizWPF="clr-namespace:Graphviz4Net.WPF">

<DataTemplate x:Key="ErrorTemplateKey">
<TextBlock Text="{Binding ErrorMessage}" Width="300" TextWrapping="Wrap"/>
</DataTemplate>
<Style TargetType="{x:Type GraphvizWPF:GraphLayout}">
<Setter Property="ErrorTemplate" Value="{StaticResource ErrorTemplateKey}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GraphvizWPF:GraphLayout}">
Expand Down