/// <summary> /// Interpret the text content of the text field as graphml /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ApplyGraphMLButton_Click(object sender, EventArgs e) { try { using (StringReader reader = new StringReader(graphMLText.Text)) { graphmlIoHandler.Read(Graph, reader); GraphControl.FitGraphBounds(); } } catch (Exception exc) { new ExceptionDialog(exc).ShowDialog(); } }
/// <summary> /// Reads the graph from a file with given file name. /// </summary> virtual protected void ReadGraph(string filename) { GraphMLIOHandler ioh = new GraphMLIOHandler(); ioh.Read(GraphControl.Graph, new StreamReader(filename)); GraphControl.UpdateContentRect(); GraphControl.FitContent(); }
/// <summary> /// Asynchronously loads a compressed graphmlz file. /// </summary> private static async Task <IGraph> LoadGraphMlz(string filepath) { return(await Task.Run(() => { var graph = new DefaultGraph(); var ioh = new GraphMLIOHandler(); using (var stream = new GZipStream(File.OpenRead(filepath), CompressionMode.Decompress)) { ioh.Read(graph, stream); } return graph; })); }
/// <summary> /// Populates the palette with the graphs stored in the resources folder. /// </summary> private void PopulatePalette() { var ioHandler = new GraphMLIOHandler(); foreach (var file in Directory.GetFiles("Resources")) { var graph = new DefaultGraph(); ioHandler.Read(graph, file); PaletteListBox.Items.Add(graph); } }
private void ReadSampleGraph() { string fileName = string.Format("Resources" + Path.DirectorySeparatorChar + "{0}.graphml", graphChooserBox.SelectedItem.ToString()); DictionaryMapper <IGraph, string> descriptionMapper = new DictionaryMapper <IGraph, string>(); graphControl.Graph.Clear(); var ioHandler = new GraphMLIOHandler(); ioHandler.AddRegistryInputMapper <INode, string>("Description"); ioHandler.AddRegistryInputMapper <INode, string>("ToolTip"); ioHandler.AddRegistryInputMapper <INode, string>("Url"); ioHandler.AddInputMapper <IGraph, string>("GraphDescription", descriptionMapper); ioHandler.Read(graphControl.Graph, fileName); graphDescriptionTextBlock.Text = descriptionMapper[graphControl.Graph.GetFoldingView().Manager.MasterGraph] ?? string.Empty; graphControl.FitGraphBounds(new InsetsD(10)); }
/// <summary> /// Called when the application has been loaded /// </summary> private void OnLoad(object sender, EventArgs e) { // show a notification because the multi-page layout takes some time ShowLoadingIndicator(true); InitializeCoreLayouts(); InitializeInputMode(); // load the original graph modelGraph = new DefaultGraph(); GraphMLIOHandler ioHandler = new GraphMLIOHandler(); ioHandler.Read(modelGraph, "Resources/pop-artists-small.graphml"); // add the page bounds visual pageBoundsVisualCreator = new PageBoundsVisualCreator(); graphControl.BackgroundGroup.AddChild(pageBoundsVisualCreator); // calculate the multi-page layout RunMultipageLayout(); }
/// <summary> /// Populates the palette with the graphs stored in the resources folder. /// </summary> private void InitializePalette() { //Handle list item drawing paletteListBox.DrawItem += OnDrawItem; // register for the mouse down event to initiate the drag operation paletteListBox.MouseDown += OnMouseDown; // populate the palette var ioHandler = new GraphMLIOHandler(); foreach (var file in Directory.GetFiles("Resources").Where(f => f.EndsWith("graphml"))) { var graph = new DefaultGraph(); ioHandler.Read(graph, file); paletteListBox.Items.Add(graph); } }
/// <summary> /// Initializes the graph from the supplied GraphML file and creates the model from it. /// </summary> /// <remarks> /// While this reads the graph from a GraphML file and constructs the model from an already-finished graph, a /// real-world application would likely create the model from whichever data source is available and then create /// the graph from it. /// </remarks> private void InitGraphAndModel() { var graph = new DefaultGraph { NodeDefaults = { Style = new NodeControlNodeStyle("NodeStyle") { OutlineShape = new Ellipse() } }, EdgeDefaults = { Style = new EdgeSegmentControlEdgeStyle("EdgeStyle") } }; var ioh = new GraphMLIOHandler(); // Parse node kinds and other info IMapper <INode, NodeKind> nodeKinds = new DictionaryMapper <INode, NodeKind>(); IMapper <INode, NodeInfo> nodeInfos = new DictionaryMapper <INode, NodeInfo>(); ioh.AddInputMapper("NetworkMonitoring.NodeKind", nodeKinds); ioh.AddInputMapper("NetworkMonitoring.NodeInfo", nodeInfos); ioh.Read(graph, @"Resources\network.graphml"); foreach (var node in graph.Nodes) { // Create and attach the model node to the graph node. var modelNode = new ModelNode { Name = nodeInfos[node].Name, Ip = nodeInfos[node].Ip, Enabled = true, Kind = nodeKinds[node] }; node.Tag = modelNode; // Add the label var label = graph.AddLabel(node, "", FreeLabelModel.Instance.CreateDefaultParameter(), nodeLabelStyle, tag: modelNode); // Attach event handler for changing label visibility, so that the graph redraws accordingly. // Since visibility can change via clicking on the node *and* from within the label, we have to use an event // handler on the model node here. modelNode.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args) { if (args.PropertyName == "LabelVisible") { GraphControl.Invalidate(); } }; } foreach (var edge in graph.Edges) { // Create and attach the model edge to the graph edge var modelEdge = new ModelEdge { Source = (ModelNode)edge.GetSourceNode().Tag, Target = (ModelNode)edge.GetTargetNode().Tag }; edge.Tag = modelEdge; // Add the edge label var label = graph.AddLabel(edge, "", NinePositionsEdgeLabelModel.CenterCentered, edgeLabelStyle, tag: modelEdge); } // Create the mappings from model items to graph elements. modelNodeToINode = graph.Nodes.ToDictionary(node => (ModelNode)node.Tag); modelEdgeToIEdge = graph.Edges.ToDictionary(edge => (ModelEdge)edge.Tag); model = new NetworkModel(modelNodeToINode.Keys, modelEdgeToIEdge.Keys); GraphControl.Graph = graph; }