Esempio n. 1
0
        /// <summary>
        /// Maps a <see cref="ScriptableNodeMapData"/> object from a <see cref="NodeMapData"/> object
        /// </summary>
        /// <param name="node">The <see cref="NodeMapData"/> object to map from</param>
        /// <returns>A <see cref="ScriptableNodeMapData"/> object mapped from from a <see cref="NodeMapData"/> object</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="node"/> is null</exception>
        public static ScriptableNodeMapData GetNode(NodeMapData node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ScriptableNodeMapData scriptableNode = new ScriptableNodeMapData
            {
                BackgroundColor = node.BackgroundColor.ToString(),
                Description     = node.Description,
                Dimension       = new ScriptableSize(node.Dimension.Height, node.Dimension.Width),
                Id             = node.Id,
                IsHidden       = node.IsHidden,
                Label          = node.Label,
                Position       = new ScriptablePoint(node.Position.X, node.Position.Y),
                SelectionColor = node.SelectionColor.ToString()
            };

            foreach (KeyValuePair <string, AttributeMapData> kvp in node.Attributes)
            {
                AttributeMapData           attributeMapData        = kvp.Value;
                ScriptableAttributeMapData scriptableAttributeData = new ScriptableAttributeMapData
                {
                    IsHidden          = attributeMapData.IsHidden,
                    Name              = attributeMapData.Name,
                    SemanticType      = (int)attributeMapData.SemanticType,
                    SimilarityMeasure = attributeMapData.SimilarityMeasure,
                    Value             = attributeMapData.Value
                };

                scriptableNode.Attributes.Add(kvp.Key, scriptableAttributeData);
            }

            return(scriptableNode);
        }
Esempio n. 2
0
        /// <summary>
        /// Calulates the subtrees overall position
        /// </summary>
        /// <param name="graph">The object containing the graph data</param>
        /// <param name="node">The root node view model for this tree</param>
        /// <param name="layer">The layer (or row in the tree) being analyzed</param>
        private void CalulateSubtreePosition(GraphMapData graph, NodeMapData node, int layer)
        {
            IList<NodeMapData> children = new List<NodeMapData>();
            double totalWidth = 0D;

            //TODO:  MAYBE REVISE TO USE GET NEIGHBORS

            // Loop over the provided nodes edges in order to get its children
            foreach (EdgeMapData edge in GetNodesEdges(graph, node))
            {
                // TODO:  HANDLE EDGE VISIBILITY

                // Get the node at the opposite end of this edge
                NodeMapData childNode = GetOppositeNode(graph, edge, node);

                // Ensure that the node has not already been positioned
                if (childNode != null && !childNode.IsHidden && !processedNodes.Contains(childNode.Id))
                {
                    // Position the node
                    children.Add(childNode);
                    totalWidth += childNode.Dimension.Width;
                    processedNodes.Add(childNode.Id);
                }
            }

            // If there are no children, then we are done
            if (children.Count == 0)
            {
                return;
            }

            // Now we need to analyze and lay out all the children as a unit
            totalWidth += (children.Count - 1D) * NODE_SPACING;

            double currentX = node.Position.X - ((totalWidth - children[0].Dimension.Width) / 2D);
            double currentY = node.Position.Y + node.Dimension.Height + LAYER_SPACING;

            // Determine if the layers overlap
            double intersectAmount = IntersectsOnLayer(layer, currentX, currentX + totalWidth);

            // Check if we had an intersection
            if (intersectAmount != 0)
            {
                double pushAmount = intersectAmount / 2D;
                currentX -= pushAmount;

                // Give the nodes a little shove so they no longer
                // intersect with another subtree
                PushNodesOver(layer, node, pushAmount);

                // Make sure to push over the nodes in the root layer as well
            }

            AddSpanToLayer(layer, currentX, currentX + totalWidth);

            // Once we get here we have a good position, so we need to set it
            foreach (NodeMapData currentChildNode in children)
            {
                SaveNodePosition(currentChildNode, currentX, currentY);
                AddToLayer(currentChildNode, layer);

                currentX += currentChildNode.Dimension.Width + NODE_SPACING;
            }

            // Now we need to do the same thing for each
            // of the children node, recursively
            foreach (NodeMapData currentChildNode in children)
            {
                CalulateSubtreePosition(graph, currentChildNode, layer + 1);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the provided node view model to the specified layer
        /// </summary>
        /// <param name="node">The node view model to be added</param>
        /// <param name="currentLayer">The layer to add the view model too</param>
        private void AddToLayer(NodeMapData node, int currentLayer)
        {
            // Loop over all the layers up to the specified layer
            while (layers.Count <= currentLayer)
            {
                layers.Add(new List<NodeMapData>());
            }

            // Add the provided node view model to the layer
            layers[currentLayer].Add(node);
        }
Esempio n. 4
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;
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
 public bool TryGetNode(string id, out NodeMapData node)
 {
     bool result = nodes.TryGetValue(id, out node);
     return result;
 }
Esempio n. 7
0
        public bool TryGetNode(string id, out NodeMapData node)
        {
            bool result = nodes.TryGetValue(id, out node);

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Pushes over all nodes in the specified layer by the specified amount
        /// </summary>
        /// <param name="layer">The current layer being analyzed</param>
        /// <param name="endNode">The last node view model to be processed</param>
        /// <param name="amount">The amount to shove the nodes over</param>
        private void PushNodesOver(int layer, NodeMapData endNode, double amount)
        {
            // Ensure that we have any layers
            if (layers.Count > layer)
            {
                // push the nodes over
                foreach (NodeMapData currentNode in layers[layer])
                {
                    if (currentNode.Id.Equals(endNode.Id))
                    {
                        break;
                    }

                    currentNode.Position = new Point(currentNode.Position.X + amount, currentNode.Position.Y);
                }

                // Continue pushing nodes over for each layer (recursively)
                PushNodesOver(layer + 1, endNode, amount);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Maps a <see cref="ScriptableNodeMapData"/> object from a <see cref="NodeMapData"/> object
        /// </summary>
        /// <param name="node">The <see cref="NodeMapData"/> object to map from</param>
        /// <returns>A <see cref="ScriptableNodeMapData"/> object mapped from from a <see cref="NodeMapData"/> object</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="node"/> is null</exception>
        public static ScriptableNodeMapData GetNode(NodeMapData node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            ScriptableNodeMapData scriptableNode = new ScriptableNodeMapData
            {
                BackgroundColor = node.BackgroundColor.ToString(),
                Description = node.Description,
                Dimension = new ScriptableSize(node.Dimension.Height, node.Dimension.Width),
                Id = node.Id,
                IsHidden = node.IsHidden,
                Label = node.Label,
                Position = new ScriptablePoint(node.Position.X, node.Position.Y),
                SelectionColor = node.SelectionColor.ToString()
            };

            foreach (KeyValuePair<string, AttributeMapData> kvp in node.Attributes)
            {
                AttributeMapData attributeMapData = kvp.Value;
                ScriptableAttributeMapData scriptableAttributeData = new ScriptableAttributeMapData
                {
                    IsHidden = attributeMapData.IsHidden,
                    Name = attributeMapData.Name,
                    SemanticType = (int)attributeMapData.SemanticType,
                    SimilarityMeasure = attributeMapData.SimilarityMeasure,
                    Value = attributeMapData.Value
                };

                scriptableNode.Attributes.Add(kvp.Key, scriptableAttributeData);
            }

            return scriptableNode;
        }
Esempio n. 10
0
        /// <summary>
        /// Adds the specificed node
        /// </summary>
        /// <param name="graphComponents">The Graph that data is being imported into</param>
        /// <param name="creationType">The specified CreationType</param>
        /// <param name="objNode">Node to be added</param>
        public static void AddNode(GraphComponents graphComponents, CreationType creationType, NodeMapData objNode)
        {
            // Create new node
            Node uiNode = new Node(objNode.Id);
            uiNode.SourceMechanism = creationType;

            // TODO as NodeMapData types expands, this needs to be adjusted
            NodeTypes uiNodeType = NodeTypes.Simple;
            if (objNode is IconNodeMapData)
            {
                uiNodeType = NodeTypes.Icon;
            }
            else if (objNode is TextNodeMapData)
            {
                uiNodeType = NodeTypes.Text;
            }

            NodeViewModelBase uiNodeVM = NodeViewModelBase.GetNodeViewModel(uiNodeType, uiNode, graphComponents.Scope);

            // Properties
            if (uiNodeType == NodeTypes.Icon)
            {
                IconNodeMapData objIconNode = (IconNodeMapData)objNode;
                if (objIconNode.ImageSource != null)
                {
                    ((IconNodeViewModel)uiNodeVM).ImageSource = objIconNode.ImageSource.ToString();
                }
            }

            uiNodeVM.Description = objNode.Description;
            uiNodeVM.DisplayValue = objNode.Label;
            uiNodeVM.Width = objNode.Dimension.Width;
            uiNodeVM.Height = objNode.Dimension.Height;
            uiNodeVM.Position = objNode.Position;
            uiNodeVM.IsHidden = objNode.IsHidden;

            SolidColorBrush uiBackgroundColorBrush = new SolidColorBrush(objNode.BackgroundColor);
            uiNodeVM.BackgroundColor = uiBackgroundColorBrush;

            SolidColorBrush uiSelectionColorBrush = new SolidColorBrush(objNode.SelectionColor);
            uiNodeVM.SelectionColor = uiSelectionColorBrush;

            if (uiNodeVM.Height == 0)
            {
                uiNodeVM.Height = 45;
            }

            if (uiNodeVM.Width == 0)
            {
                uiNodeVM.Width = 45;
            }

            // Add the node to the graph
            graphComponents.AddNodeViewModel(uiNodeVM);

            // Attributes
            foreach (KeyValuePair<string, AttributeMapData> objNodeAttrKVP in objNode.Attributes)
            {
                Attributes.Attribute uiNodeAttribute = new Attributes.Attribute(objNodeAttrKVP.Value.Name);
                AttributeValue uiNodeAttributeValue = new AttributeValue(objNodeAttrKVP.Value.Value);

                uiNode.Attributes.Add(uiNodeAttribute.Name, uiNodeAttributeValue);
                GlobalAttributeCollection.GetInstance(graphComponents.Scope).Add(uiNodeAttribute, uiNodeAttributeValue);

                uiNodeAttribute.SemanticType = objNodeAttrKVP.Value.SemanticType;
                uiNodeAttribute.PreferredSimilarityMeasure = objNodeAttrKVP.Value.SimilarityMeasure;
                uiNodeAttribute.Visible = !objNodeAttrKVP.Value.IsHidden;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastNode"></param>
        /// <param name="thisNode"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        private static double GetAngle(NodeMapData thisNode, double radius)
        {
            // Is this the first node?
            //if (lastNode == null) return 0;

            // Lay out node after the
            double circumference = 2 * Math.PI * radius;

            double chordLength = CalculateChordLength(thisNode);

            // Percent of the total circumference we need to move
            double percent = (MIN_NODE_ARC_SPACING + chordLength) / circumference;
            return 360.0 * percent;
        }
Esempio n. 12
0
 /// <summary>
 /// Calulcates the length of the chord for the provided NodeViewModelBase
 /// object.  A 'chord' is a line segment that connects two points on a 
 /// curve.
 /// </summary>
 /// <param name="node">Node for which to calculate the chord length for</param>
 /// <returns>The chord length for the givenn node</returns>
 private static double CalculateChordLength(NodeMapData node)
 {
     // Use the Pythagorean theorem to calculate the length of the chord
     // segment between each node based on the height and width of the
     // provided node.
     return Math.Sqrt(node.Width * node.Width + node.Height * node.Height + 1);
 }
Esempio n. 13
0
        private static int NodeSizeComparer(NodeMapData first, NodeMapData second)
        {
            double areaFirst = first.Dimension.Width * first.Dimension.Height;
            double areaSecond = second.Dimension.Width * second.Dimension.Height;

            return -areaFirst.CompareTo(areaSecond);
        }
Esempio n. 14
0
 /// <summary>
 /// Determines the ranking of the provided node
 /// </summary>
 /// <param name="graph">The object containing the graph data</param>
 /// <param name="node">The node to get the rank for</param>
 /// <returns>the rank for this node</returns>
 private double GetNodeRanking(GraphMapData graph, NodeMapData node)
 {
     // Check if we have a custom ranker to use.  A custom ranker
     // is a custom delegate that is used to determine the nodes
     // rank.
     if (CustomRootRanker != null)
     {
         return CustomRootRanker(node);
     }
     else
     {
         // As a fallback, determine the nodes rank base on the
         // number of edges that it has
         return GetNumberOfEdges(graph, node);
     }
 }
Esempio n. 15
0
        private static void WriteNode(XmlWriter writer, NodeMapData objNode)
        {
            writer.WriteStartElement("node");
            writer.WriteAttributeString("id", objNode.Id);

            if (objNode.GetType().Equals(typeof(IconNodeMapData)))
            {
                WritePropData(writer, NODE_PROPERTY_PREFIX, "ImageSource", ((IconNodeMapData)objNode).ImageSource.ToString());
            }

            WritePropData(writer, NODE_PROPERTY_PREFIX, "Description", objNode.Description);
            WritePropData(writer, NODE_PROPERTY_PREFIX, "DisplayValue", objNode.Label);
            WritePropData(writer, NODE_PROPERTY_PREFIX, "Height", objNode.Dimension.Height.ToString());
            WritePropData(writer, NODE_PROPERTY_PREFIX, "Width", objNode.Dimension.Width.ToString());
            WritePropData(writer, NODE_PROPERTY_PREFIX, "Position", objNode.Position.ToString());
            WritePropData(writer, NODE_PROPERTY_PREFIX, "IsHidden", objNode.IsHidden.ToString());

            string backgroundColor = GetSnaglStrColor(objNode.BackgroundColor);
            WritePropData(writer, NODE_PROPERTY_PREFIX, "BackgroundColor", backgroundColor);

            string selectionColor = GetSnaglStrColor(objNode.SelectionColor);
            WritePropData(writer, NODE_PROPERTY_PREFIX, "SelectionColor", selectionColor);

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

            writer.WriteEndElement();
        }
Esempio n. 16
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];
     }
 }
Esempio n. 17
0
 public void Add(NodeMapData node)
 {
     nodes.Add(node.Id, node);
 }
Esempio n. 18
0
 private void SaveNodePosition(NodeMapData node, double x, double y)
 {
     node.Position = new Point(x, y);
     maxXPosition = Math.Max(x + node.Dimension.Width, maxXPosition);
 }
Esempio n. 19
0
 public void Add(NodeMapData node)
 {
     nodes.Add(node.Id, node);
 }