Beispiel #1
0
 public void Add(EdgeMapData edge)
 {
     string edgeKey = GetKey(edge);
     if (!edges.ContainsKey(edgeKey))
     {
         edges.Add(edgeKey, edge);
     }
 }
Beispiel #2
0
        public void Add(EdgeMapData edge)
        {
            string edgeKey = GetKey(edge);

            if (!edges.ContainsKey(edgeKey))
            {
                edges.Add(edgeKey, edge);
            }
        }
Beispiel #3
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;
        }
Beispiel #4
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;
        }
Beispiel #5
0
        public static EdgeMapData GetEdge(ScriptableEdgeMapData scriptableEdge)
        {
            EdgeMapData edge = new EdgeMapData(scriptableEdge.Source, scriptableEdge.Target);

            // Properties
            edge.Type = (EdgeType)Enum.Parse(typeof(EdgeType), scriptableEdge.Type, false);
            edge.Thickness = scriptableEdge.Thickness;
            edge.Color = GetColor(scriptableEdge.Color);
            edge.Label = scriptableEdge.Label;
            edge.IsLabelTextUnderlined = scriptableEdge.IsLabelTextUnderlined;
            edge.LabelBackgroundColor = GetColor(scriptableEdge.LabelBackgroundColor);
            edge.LabelForegroundColor = GetColor(scriptableEdge.LabelForegroundColor);
            edge.LabelFontStyle = GetFontStyle(scriptableEdge.LabelFontStyle);
            edge.LabelFontWeight = GetFontWeight(scriptableEdge.LabelFontWeight);
            if (!String.IsNullOrEmpty(scriptableEdge.LabelFont))
            {
                FontFamily fontFamily = new FontFamily(scriptableEdge.LabelFont);
                edge.LabelFont = fontFamily;
            }
            edge.Weight = scriptableEdge.Weight;

            // Attributes
            foreach (KeyValuePair<string, ScriptableAttributeMapData> kvp in scriptableEdge.Attributes)
            {
                ScriptableAttributeMapData scriptableAttribute = kvp.Value;

                AttributeMapData attribute = new AttributeMapData(scriptableAttribute.Name, scriptableAttribute.Value);
                attribute.SemanticType = (SemanticType)scriptableAttribute.SemanticType;
                attribute.SimilarityMeasure = scriptableAttribute.SimilarityMeasure;
                attribute.IsHidden = scriptableAttribute.IsHidden;

                edge.Attributes.Add(kvp.Key, attribute);
            }

            return edge;
        }
        /// <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;
        }
Beispiel #7
0
        public static EdgeMapData GetEdge(ScriptableEdgeMapData scriptableEdge)
        {
            EdgeMapData edge = new EdgeMapData(scriptableEdge.Source, scriptableEdge.Target);

            // Properties
            edge.Type                  = (EdgeType)Enum.Parse(typeof(EdgeType), scriptableEdge.Type, false);
            edge.Thickness             = scriptableEdge.Thickness;
            edge.Color                 = GetColor(scriptableEdge.Color);
            edge.Label                 = scriptableEdge.Label;
            edge.IsLabelTextUnderlined = scriptableEdge.IsLabelTextUnderlined;
            edge.LabelBackgroundColor  = GetColor(scriptableEdge.LabelBackgroundColor);
            edge.LabelForegroundColor  = GetColor(scriptableEdge.LabelForegroundColor);
            edge.LabelFontStyle        = GetFontStyle(scriptableEdge.LabelFontStyle);
            edge.LabelFontWeight       = GetFontWeight(scriptableEdge.LabelFontWeight);
            if (!String.IsNullOrEmpty(scriptableEdge.LabelFont))
            {
                FontFamily fontFamily = new FontFamily(scriptableEdge.LabelFont);
                edge.LabelFont = fontFamily;
            }
            edge.Weight = scriptableEdge.Weight;

            // Attributes
            foreach (KeyValuePair <string, ScriptableAttributeMapData> kvp in scriptableEdge.Attributes)
            {
                ScriptableAttributeMapData scriptableAttribute = kvp.Value;

                AttributeMapData attribute = new AttributeMapData(scriptableAttribute.Name, scriptableAttribute.Value);
                attribute.SemanticType      = (SemanticType)scriptableAttribute.SemanticType;
                attribute.SimilarityMeasure = scriptableAttribute.SimilarityMeasure;
                attribute.IsHidden          = scriptableAttribute.IsHidden;

                edge.Attributes.Add(kvp.Key, attribute);
            }

            return(edge);
        }
Beispiel #8
0
 private NodeMapData GetOppositeNode(GraphMapData graph, EdgeMapData edge, NodeMapData node)
 {
     if (edge.Source.Equals(node.Id))
     {
         return graph.Nodes[edge.Target];
     }
     else
     {
         return graph.Nodes[edge.Source];
     }
 }
Beispiel #9
0
 private static string GetKey(EdgeMapData edge)
 {
     string edgeKey = edge.Source + edge.Target;
     return edgeKey;
 }
Beispiel #10
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;
        }
Beispiel #11
0
        private static void WriteEdge(XmlWriter writer, EdgeMapData objEdge)
        {
            writer.WriteStartElement("edge");
            writer.WriteAttributeString("source", objEdge.Source);
            writer.WriteAttributeString("target", objEdge.Target);

            bool isDirected = false;
            if (objEdge.Type == EdgeType.Directed)
            {
                isDirected = true;
            }
            writer.WriteAttributeString("directed", isDirected.ToString());

            writer.WriteAttributeString("berico", "type", BERICO_NAMESPACE_URI, "Berico.SnagL.Model.Edge");

            WritePropData(writer, EDGE_PROPERTY_PREFIX, "DisplayValue", objEdge.Label);
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "LabelTextUnderline", objEdge.IsLabelTextUnderlined.ToString());
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "Thickness", objEdge.Thickness.ToString());
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "LabelFontStyle", objEdge.LabelFontStyle.ToString());
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "LabelFontWeight", objEdge.LabelFontWeight.ToString());

            if (objEdge.LabelFont != null)
            {
                WritePropData(writer, EDGE_PROPERTY_PREFIX, "LabelFont", objEdge.LabelFont.Source);
            }

            string color = GetSnaglStrColor(objEdge.Color);
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "Color", color);

            string labelBackgroundColor = GetSnaglStrColor(objEdge.LabelBackgroundColor);
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "LabelBackgroundColor", labelBackgroundColor);

            string labelForegroundColor = GetSnaglStrColor(objEdge.LabelForegroundColor);
            WritePropData(writer, EDGE_PROPERTY_PREFIX, "LabelForegroundColor", labelForegroundColor);

            foreach (KeyValuePair<string, AttributeMapData> kvp in objEdge.Attributes)
            {
                string description = "{\"Name\":\"" + kvp.Value.Name + "\",\"PreferredSimilarityMeasure\":\"" + kvp.Value.SimilarityMeasure + "\",\"SemanticType\":" + (int)kvp.Value.SemanticType + ",\"Visible\":" + (!kvp.Value.IsHidden).ToString().ToLower() + "}";
                WriteAttrData(writer, EDGE_ATTRIBUTE_PREFIX, kvp.Value.Name, description, kvp.Value.Value);
            }

            writer.WriteEndElement();
        }
Beispiel #12
0
        /// <summary>
        /// Reads the edge data from the specified XmlReader
        /// </summary>
        /// <param name="reader">Reader from which to read edge data from</param>
        private static EdgeMapData ReadEdge(XmlReader reader)
        {
            string sourceId = reader.GetAttribute("source");
            string targetId = reader.GetAttribute("target");

            EdgeMapData objEdge = new EdgeMapData(sourceId, targetId);

            string directed = reader.GetAttribute("directed");
            if (directed != null)
            {
                bool isDirected = bool.Parse(directed);
                if (isDirected)
                {
                    objEdge.Type = EdgeType.Directed;
                }
            }

            // this is not used for anything
            //string edgeTypeName = reader.GetAttribute("type", BERICO_NAMESPACE_URI);

            if (reader.ReadToDescendant("data"))
            {
                do
                {
                    string dataKey = reader.GetAttribute("key");
                    string dataValue = reader.ReadElementContentAsString();

                    if (dataKey.StartsWith(EDGE_PROPERTY_PREFIX))
                    {
                        string propertyName = dataKey.Substring(EDGE_PROPERTY_PREFIX.Length);
                        switch (propertyName)
                        {
                            case "DisplayValue":
                                objEdge.Label = dataValue;
                                break;

                            case "Thickness":
                                objEdge.Thickness = double.Parse(dataValue);
                                break;

                            case "Color":
                                Color color = Conversion.HexColorToBrush(dataValue).Color;
                                objEdge.Color = color;
                                break;

                            case "LabelBackgroundColor":
                                Color labelBackgroundColor = Conversion.HexColorToBrush(dataValue).Color;
                                objEdge.LabelBackgroundColor = labelBackgroundColor;
                                break;

                            case "LabelForegroundColor":
                                Color labelForegroundColor = Conversion.HexColorToBrush(dataValue).Color;
                                objEdge.LabelForegroundColor = labelForegroundColor;
                                break;

                            case "LabelFontStyle":
                                objEdge.LabelFontStyle = (FontStyle)typeof(FontStyles).GetProperty(dataValue).GetValue(null, null);
                                break;

                            case "LabelFontWeight":
                                objEdge.LabelFontWeight = (FontWeight)typeof(FontWeights).GetProperty(dataValue).GetValue(null, null);
                                break;

                            case "LabelTextUnderline":
                                objEdge.IsLabelTextUnderlined = bool.Parse(dataValue);
                                break;
                        }
                    }
                    else if (!dataKey.EndsWith(ATTRIBUTE_DESCRIPTOR_SUFFIX))
                    {
                        string attributeName = dataKey.Substring(EDGE_ATTRIBUTE_PREFIX.Length, dataKey.Length - (EDGE_ATTRIBUTE_PREFIX.Length + ATTRIBUTE_VALUE_SUFFIX.Length));
                        AttributeMapData objAttribute = new AttributeMapData(attributeName, dataValue);
                        objEdge.Attributes.Add(objAttribute.Name, objAttribute);
                    }
                } while (reader.LocalName == "data" || (string.IsNullOrEmpty(reader.LocalName) && reader.ReadToNextSibling("data")));
            }

            return objEdge;
        }
Beispiel #13
0
        /// <summary>
        /// Adds the specificed edge
        /// </summary>
        /// <param name="graphComponents">The Graph that data is being imported into</param>
        /// <param name="creationType">The specified CreationType</param>
        /// <param name="objEdge">Edge to be added</param>
        public static void AddEdge(GraphComponents graphComponents, CreationType creationType, EdgeMapData objEdge)
        {
            INode uiSourceNode = graphComponents.Data.GetNode(objEdge.Source);
            if (uiSourceNode == null && creationType == CreationType.Imported)
            {
                throw new Exception("Missing Source Node");
            }
            else if (uiSourceNode == null)// && creationType == CreationType.Live
            {
                uiSourceNode = new GhostNode(objEdge.Source);
            }

            INode uiTargetNode = graphComponents.Data.GetNode(objEdge.Target);
            if (uiTargetNode == null && creationType == CreationType.Imported)
            {
                throw new Exception("Missing Target Node");
            }
            else if (uiTargetNode == null)// && creationType == CreationType.Live
            {
                uiTargetNode = new GhostNode(objEdge.Target);
            }

            if (string.IsNullOrEmpty(objEdge.Label) && objEdge.Attributes.Count == 0)
            {
                Berico.SnagL.Model.Edge uiEdge = new Berico.SnagL.Model.Edge(uiSourceNode, uiTargetNode);
                uiEdge.SourceMechanism = creationType;

                // Properties
                uiEdge.Type = objEdge.Type;

                // the EdgeViewModel must be created after uiEdge has had a Type specified
                IEdgeViewModel uiEdgeVM = EdgeViewModelBase.GetEdgeViewModel(uiEdge, graphComponents.Scope);
                graphComponents.AddEdgeViewModel(uiEdgeVM);
            }
            else
            {
                DataEdge uiEdge = new DataEdge(uiSourceNode, uiTargetNode);
                uiEdge.SourceMechanism = creationType;

                // Properties
                uiEdge.Type = objEdge.Type;
                uiEdge.DisplayValue = objEdge.Label;

                // the EdgeViewModel must be created after uiEdge has had a Type specified
                IEdgeViewModel uiEdgeVM = EdgeViewModelBase.GetEdgeViewModel(uiEdge, graphComponents.Scope);
                graphComponents.AddEdgeViewModel(uiEdgeVM);

                uiEdgeVM.Thickness = objEdge.Thickness;
                uiEdgeVM.Color = new SolidColorBrush(objEdge.Color);
                uiEdgeVM.EdgeLine.Text = objEdge.Label;
                uiEdgeVM.EdgeLine.LabelTextUnderline = objEdge.IsLabelTextUnderlined;
                uiEdgeVM.EdgeLine.LabelBackgroundColor = new SolidColorBrush(objEdge.LabelBackgroundColor);
                uiEdgeVM.EdgeLine.LabelForegroundColor = new SolidColorBrush(objEdge.LabelForegroundColor);
                uiEdgeVM.EdgeLine.LabelFontStyle = objEdge.LabelFontStyle;
                uiEdgeVM.EdgeLine.LabelFontWeight = objEdge.LabelFontWeight;
                if (objEdge.LabelFont != null)
                {
                    uiEdgeVM.EdgeLine.LabelFont = objEdge.LabelFont;
                }

                // Attributes
                foreach (KeyValuePair<string, AttributeMapData> objEdgeAttrKVP in objEdge.Attributes)
                {
                    Attributes.Attribute uiEdgeAttribute = new Attributes.Attribute(objEdgeAttrKVP.Value.Name);
                    AttributeValue uiEdgeAttributeValue = new AttributeValue(objEdgeAttrKVP.Value.Value);

                    uiEdge.Attributes.Add(uiEdgeAttribute.Name, uiEdgeAttributeValue);
                    //GlobalAttributeCollection.GetInstance(graphComponents.Scope).Add(uiEdgeAttribute, uiEdgeAttributeValue);

                    uiEdgeAttribute.SemanticType = objEdgeAttrKVP.Value.SemanticType;
                    uiEdgeAttribute.PreferredSimilarityMeasure = objEdgeAttrKVP.Value.SimilarityMeasure;
                    uiEdgeAttribute.Visible = !objEdgeAttrKVP.Value.IsHidden;
                }
            }
        }
Beispiel #14
0
        private static EdgeMapData GetEdge(EdgeViewModelBase uiEdge)
        {
            EdgeMapData objEdge = new EdgeMapData(uiEdge.ParentEdge.Source.ID, uiEdge.ParentEdge.Target.ID);

            // Properties
            objEdge.Type = uiEdge.ParentEdge.Type;
            objEdge.IsLabelTextUnderlined = uiEdge.EdgeLine.LabelTextUnderline;
            objEdge.Thickness = uiEdge.Thickness;
            objEdge.Color = ((SolidColorBrush)uiEdge.Color).Color;
            objEdge.LabelBackgroundColor = ((SolidColorBrush)uiEdge.LabelBackgroundColor).Color;
            objEdge.LabelForegroundColor = ((SolidColorBrush)uiEdge.LabelForegroundColor).Color;
            objEdge.LabelFontStyle = uiEdge.LabelFontStyle;
            objEdge.LabelFontWeight = uiEdge.LabelFontWeight;
            objEdge.LabelFont = uiEdge.LabelFont;

            if (uiEdge.ParentEdge.GetType().Equals(typeof(DataEdge)))
            {
                DataEdge dataEdge = (DataEdge)uiEdge.ParentEdge;
                objEdge.Label = dataEdge.DisplayValue;

                // Attributes
                foreach (KeyValuePair<string, AttributeValue> uiDataEdgeAttrKVP in dataEdge.Attributes)
                {
                    //Attributes.Attribute uiEdgeAttribute = GlobalAttributeCollection.GetInstance(scope).GetAttribute(uiDataEdgeAttrKVP.Key);

                    AttributeMapData objEdgeAttribute = new AttributeMapData(uiDataEdgeAttrKVP.Key, uiDataEdgeAttrKVP.Value.Value);
                    objEdge.Attributes.Add(objEdgeAttribute.Name, objEdgeAttribute);

                    //objEdgeAttribute.SemanticType = uiEdgeAttribute.SemanticType;
                    //objEdgeAttribute.SimilarityMeasure = uiEdgeAttribute.PreferredSimilarityMeasure;
                    //objEdgeAttribute.IsHidden = !uiEdgeAttribute.Visible;
                }
            }

            return objEdge;
        }
Beispiel #15
0
        private static string GetKey(EdgeMapData edge)
        {
            string edgeKey = edge.Source + edge.Target;

            return(edgeKey);
        }