예제 #1
0
        /// <summary>
        /// Get adjacency graph from input graph
        /// </summary>
        /// <param name="graph">GraphMapData</param>
        /// <returns>AdjacencyGraph</returns>
        public static AdjacencyGraph<string, Edge<string>> GetAdjacencyGraph(GraphMapData graph)
        {
            ICollection<NodeMapData> nodes = graph.GetNodes();
            AdjacencyGraph<string, Edge<string>> adjacencyGraph = new AdjacencyGraph<string, Edge<string>>(true, nodes.Count);

            foreach (NodeMapData node in nodes)
            {
                adjacencyGraph.AddVertex(node.Id);
            }

            foreach (EdgeMapData edge in graph.GetEdges())
            {
                Edge<string> quickGraphEdge = new Edge<string>(edge.Source, edge.Target);
                adjacencyGraph.AddEdge(quickGraphEdge);
            }

            return adjacencyGraph;
        }
예제 #2
0
파일: TreeLayout.cs 프로젝트: senfo/snaglV2
        private static double GetNumberOfEdges(GraphMapData graph, NodeMapData node)
        {
            double numEdges = 0D;

            foreach (EdgeMapData edge in graph.GetEdges())
            {
                if (edge.Source.Equals(node.Id) || edge.Target.Equals(node.Id))
                {
                    numEdges++;
                }
            }

            return numEdges;
        }
예제 #3
0
파일: TreeLayout.cs 프로젝트: senfo/snaglV2
        private static ICollection<EdgeMapData> GetNodesEdges(GraphMapData graph, NodeMapData node)
        {
            ICollection<EdgeMapData> edges = new List<EdgeMapData>();

            foreach (EdgeMapData edge in graph.GetEdges())
            {
                if (edge.Source.Equals(node.Id) || edge.Target.Equals(node.Id))
                {
                    edges.Add(edge);
                }
            }

            return edges;
        }
예제 #4
0
        public static Chart GraphToAnb(GraphMapData graph)
        {
            Chart chart = new Chart();
            chart.chartItemCollection = new ChartItemCollection();
            chart.chartItemCollection.chartItems = new Collection<ChartItem>();

            foreach (IconNodeMapData node in graph.GetNodes())
            {
                ChartItem chartItem = new ChartItem();
                chart.chartItemCollection.chartItems.Add(chartItem);

                chartItem.attrLabel = node.Label;

                string hexBackgroundColor = String.Format("#{0:x2}{1:x2}{2:x2}{3:x2}", node.BackgroundColor.A, node.BackgroundColor.R, node.BackgroundColor.G, node.BackgroundColor.B);
                chartItem.ciStyle = new CIStyle();
                chartItem.ciStyle.font = new Font();
                chartItem.ciStyle.font.attrBackColour = hexBackgroundColor;

                chartItem.end = new End();
                chartItem.end.entity = new Entity();
                chartItem.end.entity.icon = new Icon();
                chartItem.end.entity.icon.iconStyle = new IconStyle();

                chartItem.attributeCollection = new AttributeCollection();
                chartItem.attributeCollection.attributes = new Collection<Anb.Attribute>();
                foreach (KeyValuePair<string, AttributeMapData> kvp in node.Attributes)
                {
                    Anb.Attribute attribute = new Anb.Attribute();
                    chartItem.attributeCollection.attributes.Add(attribute);

                    attribute.attrAttributeClass = kvp.Key;
                    attribute.attrValue = kvp.Value.Value;
                }
            }

            foreach (EdgeMapData edge in graph.GetEdges())
            {
                ChartItem chartItem = new ChartItem();
                chart.chartItemCollection.chartItems.Add(chartItem);

                chartItem.link = new Link();
                chartItem.link.attrEnd1Id = edge.Source;
                chartItem.link.attrEnd2Id = edge.Target;

                chartItem.link.linkStyle = new LinkStyle();
                chartItem.link.linkStyle.attrType = edge.Label;
            }

            return chart;
        }
예제 #5
0
        private static void WriteHeader(XmlWriter writer, GraphMapData graph)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("graphml", "http://graphml.graphdrawing.org/xmlns");
            writer.WriteAttributeString("xmlns", "berico", string.Empty, BERICO_NAMESPACE_URI);
            writer.WriteAttributeString("xmlns", "xsi", string.Empty, "http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("xsi", "schemaLocation", string.Empty, "http://graphml.graphdrawing.org.xmlns/1.0/graphml.xsd");

            if (graph.GetNodes().Count > 0)
            {
                bool graphHasIconNode = false;
                foreach (NodeMapData objNode in graph.GetNodes())
                {
                    if (objNode is IconNodeMapData)
                    {
                        graphHasIconNode = true;
                        break;
                    }
                }
                if (graphHasIconNode)
                {
                    WritePropKey(writer, NODE_PROPERTY_PREFIX, "ImageSource", "node");
                }

                WritePropKey(writer, NODE_PROPERTY_PREFIX, "Description", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "DisplayValue", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "Width", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "Height", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "Position", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "IsHidden", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "BackgroundColor", "node");
                WritePropKey(writer, NODE_PROPERTY_PREFIX, "SelectionColor", "node");
            }

            if (graph.GetEdges().Count > 0)
            {
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "DisplayValue", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "LabelTextUnderline", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "Thickness", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "Color", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "LabelBackgroundColor", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "LabelForegroundColor", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "LabelFontStyle", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "LabelFontWeight", "edge");
                WritePropKey(writer, EDGE_PROPERTY_PREFIX, "LabelFont", "edge");
            }

            ISet<string> seenAttributes = new HashSet<string>();
            foreach (NodeMapData objNode in graph.GetNodes())
            {
                foreach (KeyValuePair<string, AttributeMapData> kvp in objNode.Attributes)
                {
                    if (seenAttributes.Add(kvp.Key))
                    {
                        WriteAttrKey(writer, NODE_ATTRIBUTE_PREFIX, kvp.Value.Name, "node");
                    }
                }
            }

            seenAttributes.Clear();
            foreach (EdgeMapData objEdge in graph.GetEdges())
            {
                foreach (KeyValuePair<string, AttributeMapData> kvp in objEdge.Attributes)
                {
                    if (seenAttributes.Add(kvp.Key))
                    {
                        WriteAttrKey(writer, EDGE_ATTRIBUTE_PREFIX, kvp.Value.Name, "edge");
                    }
                }
            }
        }
예제 #6
0
        private static void WriteGraphContent(XmlWriter writer, GraphMapData graph)
        {
            writer.WriteStartElement("graph");
            writer.WriteAttributeString("id", "snagl_export_graph");

            GraphType edgedefault = GraphType.Undirected;
            foreach (EdgeMapData objEdge in graph.GetEdges())
            {
                if (objEdge.Type == EdgeType.Directed)
                {
                    edgedefault = GraphType.Directed;
                    break;
                }
            }
            writer.WriteAttributeString("edgedefault", edgedefault.ToString());

            NodeTypes defaultNodeType = NodeTypes.Text;
            foreach (NodeMapData objNode in graph.GetNodes())
            {
                if (objNode is IconNodeMapData)
                {
                    defaultNodeType = NodeTypes.Icon;
                    break;
                }
            }
            writer.WriteAttributeString("berico", "nodeType", BERICO_NAMESPACE_URI, defaultNodeType.ToString());

            foreach (NodeMapData objNode in graph.GetNodes())
            {
                WriteNode(writer, objNode);
            }

            foreach (EdgeMapData objEdge in graph.GetEdges())
            {
                WriteEdge(writer, objEdge);
            }

            writer.WriteEndElement();
        }
예제 #7
0
        /// <summary>
        /// Get bidirectional graph from input graph
        /// </summary>
        /// <param name="graph">GraphMapData</param>
        /// <returns>BidirectionalGraph</returns>
        public static BidirectionalGraph<string, WeightedEdge<string>> GetBidirectionalGraph(GraphMapData graph)
        {
            ICollection<NodeMapData> nodes = graph.GetNodes();
            BidirectionalGraph<string, WeightedEdge<string>> bidirectionalGraph = new BidirectionalGraph<string, WeightedEdge<string>>(true, nodes.Count);

            foreach (NodeMapData node in nodes)
            {
                bidirectionalGraph.AddVertex(node.Id);
            }

            foreach (EdgeMapData edge in graph.GetEdges())
            {
                WeightedEdge<string> weightedEdge = new WeightedEdge<string>(edge.Source, edge.Target, edge.Weight);
                bidirectionalGraph.AddEdge(weightedEdge);
            }

            return bidirectionalGraph;
        }