Пример #1
0
        /// <summary>
        /// Converts a GraphMapData instance, with data from an import operation,
        /// to a Graph (GraphComponents)
        /// </summary>
        /// <param name="graph">The mapping data to be imported into the Graph</param>
        /// <param name="graphComponents">The Graph that data is being imported into</param>
        /// <param name="creationType">The specified CreationType</param>
        public static void ImportGraph(this GraphMapData graph, GraphComponents graphComponents, CreationType creationType)
        {
            // Ensure that valid mapping data was provided
            if (graph == null)
            {
                throw new ArgumentNullException("graph", "No mapping data was provided");
            }

            graphComponents.NodeType = NodeTypes.Text;
            foreach (NodeMapData objNode in graph.GetNodes())
            {
                if (objNode is IconNodeMapData)
                {
                    graphComponents.NodeType = NodeTypes.Icon;
                    break;
                }
            }

            // TODO edgedefault?

            // Loop over the node mapping objects
            foreach (NodeMapData objNode in graph.GetNodes())
            {
                AddNode(graphComponents, creationType, objNode);
            }

            // Edges
            foreach (EdgeMapData objEdge in graph.GetEdges())
            {
                AddEdge(graphComponents, creationType, objEdge);
            }
        }
Пример #2
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();
        }
Пример #3
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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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");
                    }
                }
            }
        }