Example #1
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;
        }
Example #2
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;
        }