예제 #1
0
        private static GraphMapData GetClusteredGraph(GraphMapData graphMapData, GraphComponents graphComponents)
        {
            GraphMapData graphComponentsMapData = new GraphMapData();

            IEnumerable <INodeShape> clusteredComponents = graphComponents.GetNodeViewModels();

            foreach (PartitionNode clusteredComponent in clusteredComponents)
            {
                NodeMapData nodeMapData = new TextNodeMapData(clusteredComponent.ID);
                graphComponentsMapData.Add(nodeMapData);

                // Properties
                object[] dimensionAndPosition = GetPartitionNodeDimensionAndPosition(graphMapData, clusteredComponent);
                nodeMapData.Dimension = (Size)dimensionAndPosition[0];
                nodeMapData.Position  = (Point)dimensionAndPosition[1];

                nodeMapData.IsHidden = clusteredComponent.IsHidden;

                IEnumerable <IEdge> clusteredComponentEdges = graphComponents.GetEdges(clusteredComponent);
                foreach (IEdge clusteredComponentEdge in clusteredComponentEdges)
                {
                    EdgeMapData edgeMapData = new EdgeMapData(clusteredComponentEdge.Source.ID, clusteredComponentEdge.Target.ID);
                    graphComponentsMapData.Add(edgeMapData);
                }
            }

            return(graphComponentsMapData);
        }
예제 #2
0
        public static GraphMapData JsonToGraph(TracWrapper tracWrapper)
        {
            if (tracWrapper == null)
            {
                throw new ArgumentNullException();
            }

            GraphMapData graph = new GraphMapData();

            IconNodeMapData seedNode = SeedToNode(tracWrapper.trac.result.seed);

            graph.Add(seedNode);

            // by definition Data are guaranteed to not have been seen yet
            foreach (Data data in tracWrapper.trac.result.datas)
            {
                IconNodeMapData dataNode = DataToNode(data);
                graph.Add(dataNode);

                EdgeMapData edgeToSeed = new EdgeMapData(seedNode.Id, dataNode.Id);
                graph.Add(edgeToSeed);

                // by definition Contact may have already been seen
                if (data.contacts != null)
                {
                    foreach (Data contact in data.contacts)
                    {
                        if (!contact.address.Equals(seedNode.Id))
                        {
                            NodeMapData contactNode;
                            bool        nodeAlreadyExists = graph.TryGetNode(contact.address, out contactNode);
                            if (!nodeAlreadyExists)
                            {
                                contactNode = DataToNode(contact);
                                graph.Add(contactNode);
                            }

                            EdgeMapData edgeToData = new EdgeMapData(dataNode.Id, contactNode.Id);
                            graph.Add(edgeToData);
                        }
                    }
                }
            }

            return(graph);
        }
예제 #3
0
        public static GraphMapData AnbToGraph(Chart chart)
        {
            if (chart == null)
            {
                throw new ArgumentNullException();
            }

            GraphMapData graph = new GraphMapData();

            foreach (ChartItem chartItem in chart.chartItemCollection.chartItems)
            {
                if (chartItem.end != null)
                {
                    IconNodeMapData node = new IconNodeMapData(chartItem.end.entity.attrEntityId);
                    graph.Add(node);

                    node.Label = chartItem.attrLabel;

                    SolidColorBrush backgroundColor = Conversion.HexColorToBrush(chartItem.ciStyle.font.attrBackColour);
                    node.BackgroundColor = backgroundColor.Color;

                    foreach (Anb.Attribute attribute in chartItem.attributeCollection.attributes)
                    {
                        AttributeMapData objAttribute = new AttributeMapData(attribute.attrAttributeClass, attribute.attrValue);
                        node.Attributes.Add(objAttribute.Name, objAttribute);
                    }
                }
                else
                {
                    EdgeMapData edge = new EdgeMapData(chartItem.link.attrEnd1Id, chartItem.link.attrEnd2Id);
                    graph.Add(edge);

                    edge.Label = chartItem.link.linkStyle.attrType;
                }
            }

            return(graph);
        }
예제 #4
0
        /// <summary>
        /// Returns bare-bone graph needed for layouts
        /// </summary>
        /// <param name="graphComponents">GraphComponents</param>
        /// <returns>GraphMapData</returns>
        public static GraphMapData GetGraph(GraphComponents graphComponents)
        {
            GraphMapData graph = new GraphMapData();

            // Nodes
            IEnumerable <INodeShape> uiNodeViewModels = graphComponents.GetNodeViewModels();

            foreach (NodeViewModelBase uiNodeVM in uiNodeViewModels)
            {
                NodeMapData objNode = new TextNodeMapData(uiNodeVM.ParentNode.ID);
                graph.Add(objNode);

                // Properties
                Size dimension = new Size(uiNodeVM.Width, uiNodeVM.Height);
                objNode.Dimension = dimension;
                objNode.Position  = uiNodeVM.Position;
                objNode.IsHidden  = uiNodeVM.IsHidden;
            }

            // Edges
            IEnumerable <IEdgeViewModel> uiEdgeViewModels = graphComponents.GetEdgeViewModels();

            foreach (EdgeViewModelBase uiEdgeVM in uiEdgeViewModels)
            {
                EdgeMapData objEdge = new EdgeMapData(uiEdgeVM.ParentEdge.Source.ID, uiEdgeVM.ParentEdge.Target.ID);
                graph.Add(objEdge);

                // Properties
                objEdge.Type = uiEdgeVM.ParentEdge.Type;
                SimilarityDataEdge uiSDE = uiEdgeVM.ParentEdge as SimilarityDataEdge;
                if (uiSDE != null)
                {
                    objEdge.Weight = uiSDE.Weight;
                }
            }

            return(graph);
        }
예제 #5
0
        private static GraphMapData GetGraph(GraphMapData graphMapData, GraphComponents clusteredGraph)
        {
            GraphMapData clusteredGraphMapData = new GraphMapData();

            // Nodes
            IEnumerable <INodeShape> uiNodeViewModels = clusteredGraph.GetNodeViewModels();

            foreach (NodeViewModelBase uiNodeVM in uiNodeViewModels)
            {
                NodeMapData nodeMapData = graphMapData.Nodes[uiNodeVM.ParentNode.ID];
                clusteredGraphMapData.Add(nodeMapData);

                // Edges
                IEnumerable <IEdge> uiEdgeViewModels = clusteredGraph.GetEdges(uiNodeVM.ParentNode);
                foreach (IEdge uiEdgeVM in uiEdgeViewModels)
                {
                    string      edgeKey     = uiEdgeVM.Source.ID + uiEdgeVM.Target.ID;
                    EdgeMapData edgeMapData = graphMapData.Edges[edgeKey];
                    clusteredGraphMapData.Add(edgeMapData);
                }
            }

            return(clusteredGraphMapData);
        }
예제 #6
0
        /// <summary>
        /// Converts the provided GraphComponents instance to a GraphMapData
        /// instance that can be exported to a target file format
        /// </summary>
        /// <param name="graphComponents">The graph to be exported</param>
        /// <returns>A GraphMapData instance ready to be exported to the target format</returns>
        public static GraphMapData ExportGraph(this GraphComponents graphComponents)
        {
            GraphMapData graph = new GraphMapData();

            // Nodes
            IEnumerable <INodeShape> uiNodeViewModels = graphComponents.GetNodeViewModels();

            foreach (NodeViewModelBase uiNodeVM in uiNodeViewModels)
            {
                NodeMapData objNode = GetNode(uiNodeVM);
                graph.Add(objNode);
            }

            // Edges
            IEnumerable <IEdgeViewModel> edgeViewModels = graphComponents.GetEdgeViewModels();

            foreach (EdgeViewModelBase uiEdge in edgeViewModels)
            {
                EdgeMapData objEdge = GetEdge(uiEdge);
                graph.Add(objEdge);
            }

            return(graph);
        }
예제 #7
0
        /// <summary>
        /// Performs the actual import for the given GraphML or SnaglML data.
        /// The Import method should be called rather than calling
        /// this method directly.
        /// </summary>
        /// <param name="data">GraphML or SnaglML</param>
        /// <returns>The graph data mapped as a <see cref="GraphMapData"/> object</returns>
        internal override GraphMapData ImportData(string data)
        {
            // TODO Should validate against XSD
            // TODO Processing should conform to GraphML defined processing rules

            GraphMapData graph = new GraphMapData();

            bool haveEncounteredGraph = false;

            using (TextReader stringReader = new StringReader(data))
            {
                XmlReaderSettings settings = new XmlReaderSettings
                {
                    CloseInput       = true,
                    ConformanceLevel = ConformanceLevel.Document,
                    DtdProcessing    = DtdProcessing.Parse,
                    IgnoreWhitespace = true
                };
                using (XmlReader reader = XmlReader.Create(stringReader, settings))
                {
                    // while we know the graph element must be first as per the schema the compiler does not, so these is assigned a value here
                    NodeTypes defaultNodeType = NodeTypes.Text;
                    //GraphType defaultGraphType = GraphType.Undirected;

                    while (reader.Read())
                    {
                        if (reader.IsStartElement())
                        {
                            switch (reader.LocalName)
                            {
                            case "graph":
                                if (!haveEncounteredGraph)
                                {
                                    haveEncounteredGraph = true;

                                    string nodeType = reader.GetAttribute("nodeType", BERICO_NAMESPACE_URI);
                                    defaultNodeType = GetDefaultNodeType(nodeType);

                                    //string edgeDefault = reader.GetAttribute("edgedefault");
                                    //defaultGraphType = GetDefaultEdgeType(edgeDefault);
                                }
                                else
                                {
                                    throw new Exception("Both multiple graphs per file and nested graphs are unsupported.");
                                }
                                break;

                            case "node":
                                NodeMapData node = ReadNode(reader, defaultNodeType);
                                graph.Add(node);
                                break;

                            case "edge":
                                EdgeMapData edge = ReadEdge(reader);
                                graph.Add(edge);
                                break;
                            }
                        }
                    }
                }
            }

            return(graph);
        }