Skip to content

Commit

Permalink
Added validator, autolayout to stresstest
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouterdek committed Oct 1, 2019
1 parent 91ec62b commit b777003
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions StressTest/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<Button Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="GenerateNodes">Generate 100 nodes</Button>
<Button Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="GenerateConnections">Generate connections</Button>
<Button Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="AutoLayout">AutoLayout</Button>
<Button Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="Clear">Clear</Button>
<CheckBox Name="ShowOutputChecky"></CheckBox>
</StackPanel>
Expand Down
34 changes: 30 additions & 4 deletions StressTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -14,6 +15,10 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using DynamicData;
using NodeNetwork;
using NodeNetwork.Toolkit;
using NodeNetwork.Toolkit.Layout.ForceDirected;
using NodeNetwork.Toolkit.ValueNode;
using NodeNetwork.ViewModels;
using NodeNetwork.Views;
using ReactiveUI;
Expand All @@ -32,7 +37,17 @@ public MainWindow()
InitializeComponent();

_network = new NetworkViewModel();
_network.Nodes.Add(CreateNode());
_network.Validator = network =>
{
bool containsLoops = GraphAlgorithms.FindLoops(network).Any();
if (containsLoops)
{
return new NetworkValidationResult(false, false, new ErrorMessageViewModel("Network contains loops!"));
}
return new NetworkValidationResult(true, true, null);
};
_network.Nodes.Add(CreateNode());
NetworkView.ViewModel = _network;
this.WhenAnyValue(v => v.ShowOutputChecky.IsChecked).Subscribe(isChecked =>
{
Expand All @@ -43,19 +58,21 @@ public MainWindow()

public NodeViewModel CreateNode()
{
NodeInputViewModel input = new NodeInputViewModel
var input = new ValueNodeInputViewModel<int?>
{
Name = "A"
};

NodeOutputViewModel output = new NodeOutputViewModel
var output = new ValueNodeOutputViewModel<int?>
{
Name = "B"
Name = "B",
Value = Observable.CombineLatest(input.ValueChanged, Observable.Return(-1), (i1, i2) => (int?)(i1 ?? i2)+1)
};

NodeViewModel node = new NodeViewModel();
node.Inputs.Add(input);
node.Outputs.Add(output);
output.Value.Subscribe(v => node.Name = v.ToString());

return node;
}
Expand Down Expand Up @@ -90,5 +107,14 @@ private void Clear(object sender, RoutedEventArgs e)
_network.Nodes.Clear();
_network.Connections.Clear();
}

private void AutoLayout(object sender, RoutedEventArgs e)
{
var layout = new ForceDirectedLayouter();
layout.Layout(new Configuration
{
Network = _network
}, 1000);
}
}
}

0 comments on commit b777003

Please sign in to comment.