public MainWindow() { InitializeComponent(); Graph = new WebGraph.Logic.Graph(); Layouter = new WebGraph.Logic.GraphLayouter(Graph); FileName = string.Empty; CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); }
private void OnFileNew(object sender, ExecutedRoutedEventArgs e) { // throw away internal data Graph = new WebGraph.Logic.Graph(); Layouter = new WebGraph.Logic.GraphLayouter(Graph); FileName = string.Empty; // and update display to show nothing graphCanvas.Children.Clear(); }
private void OnFileOpen(object sender, ExecutedRoutedEventArgs e) { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.RestoreDirectory = true; ofd.DefaultExt = ".sgx"; ofd.Filter = "GraphXML (.sgx)|*.sgx|All Files|*.*"; if (ofd.ShowDialog() == true) { graphCanvas.Children.Clear(); try { FileName = ofd.FileName; Graph = WebGraph.Logic.GraphXmlSerializer.Deserialize(FileName); Layouter = new WebGraph.Logic.GraphLayouter(Graph); Brush nodeFg = new SolidColorBrush(Properties.Settings.Default.NodeForeground); Brush nodeBg = new SolidColorBrush(Properties.Settings.Default.NodeBackground); Graph.ForAllEdges(edge => { Line line = new Line(); line.Stroke = nodeBg; edge.Tag = line; graphCanvas.Children.Add(line); }); Graph.ForAllNodes(node => { TextBlock text = new TextBlock(); text.Text = node.Label; text.Foreground = nodeFg; text.Background = nodeBg; text.Padding = new Thickness(4, 0, 4, 0); text.FontSize = 12; text.MouseLeftButtonDown += new MouseButtonEventHandler(OnNodeMouseLeftButtonDown); node.Tag = text; graphCanvas.Children.Add(text); }); } catch (Exception exc) { OnFileNew(this, null); // force a complete reset MessageBox.Show(exc.Message, exc.GetType().FullName); } graphCanvas.UpdateLayout(); Graph.ForAllNodes(new WebGraph.Logic.NodeCallback(CenterNodes)); Graph.ForAllNodes(new WebGraph.Logic.NodeCallback(UpdateNodeSize)); Layouter.ResetDamper(); } }
/// <summary>Loads a new graph for a given root</summary> /// <param name="sender">Sender</param> /// <param name="e">Arguments</param> private void ButtonGoClick(object sender, RoutedEventArgs e) { if (textBoxSearch.Text.Length == 0) return; // nothing to search if (comboBoxPlugins.SelectedIndex == -1 || comboBoxPlugins.Items.Count == 0) return; // no data source try { // tabula rasa Graph = new WebGraph.Logic.Graph(); Layouter = new WebGraph.Logic.GraphLayouter(Graph); graphCanvas.Children.Clear(); // lets go LoadSubGraph(textBoxSearch.Text, 0); } catch (Exception exc) { MessageBox.Show(exc.Message, exc.GetType().FullName); } }