Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void AddEdge(ScriptableEdgeMapData scriptableEdge)
        {
            EdgeMapData objEdge = ScriptableMapper.GetEdge(scriptableEdge);

            GraphComponents graphComponents = GraphManager.Instance.DefaultGraphComponentsInstance;

            MappingExtensions.AddEdge(graphComponents, CreationType.Live, objEdge);
        }
Ejemplo n.º 3
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]);
     }
 }
Ejemplo n.º 4
0
 public Edges(int index, Centers leftCenter, Centers rightCenter, Corners startCorner, Corners endCorner, VoronoiPoint mdpt)
 {
     Index           = index;
     delaunayCenter1 = leftCenter;
     delaunayCenter2 = rightCenter;
     voronoiCorner1  = startCorner;
     voronoiCorner2  = endCorner;
     midpoint        = mdpt;
     BordersAndProtrudes();
     mapdata = new EdgeMapData();
 }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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;
                }
            }
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }