Beispiel #1
0
 public SearchIndexerQuery(QueryGraph graph, EvalHandler handler)
     : base(graph, handler)
 {
 }
Beispiel #2
0
 public GraphViewerQueryHandler Create(QueryGraph graph, ICollection <QueryError> errors)
 {
     return(new GraphViewerQueryHandler());
 }
Beispiel #3
0
        private void LayoutGraphNodes(QueryGraph graph, Dictionary <IQueryNode, Node> queryNodesToViewNodes)
        {
            var levelIndexByNode = new Dictionary <IQueryNode, Tuple <int, int> >();
            var nodesByLevel     = new Dictionary <int, List <IQueryNode> >();
            var nodesToProcess   = new Queue <IQueryNode>();

            nodesToProcess.Enqueue(graph.root);

            while (nodesToProcess.Count > 0)
            {
                int currentLevel;
                int currentIndex;
                var currentNode = nodesToProcess.Dequeue();
                if (currentNode.parent == null)
                {
                    currentLevel = 0;
                    currentIndex = 0;
                }
                else
                {
                    var parentLevel = levelIndexByNode[currentNode.parent].Item1;
                    var parentIndex = levelIndexByNode[currentNode.parent].Item2;
                    currentLevel = parentLevel + 1;
                    currentIndex = parentIndex * 2 + (currentNode.parent.children[0] == currentNode ? 0 : 1);
                }
                levelIndexByNode.Add(currentNode, new Tuple <int, int>(currentLevel, currentIndex));

                if (!nodesByLevel.ContainsKey(currentLevel))
                {
                    nodesByLevel.Add(currentLevel, new List <IQueryNode>());
                }
                nodesByLevel[currentLevel].Add(currentNode);

                if (currentNode.leaf || currentNode.children == null)
                {
                    continue;
                }

                foreach (var child in currentNode.children)
                {
                    nodesToProcess.Enqueue(child);
                }
            }

            var maxLevel       = nodesByLevel.Keys.Max();
            var maxNumber      = 1 << maxLevel;
            var numberOfSpaces = maxNumber - 1;
            var nodeMaxWidth   = queryNodesToViewNodes.Values.Select(node => node.GetPosition().size.x).Max();
            var nodeMaxHeight  = queryNodesToViewNodes.Values.Select(node => node.GetPosition().size.y).Max();

            var totalLength    = maxNumber * nodeMaxWidth + numberOfSpaces * k_WidthBetweenNodes;
            var totalHeight    = (maxLevel + 1) * nodeMaxHeight + maxLevel * k_HeightBetweenNodes;
            var positionXStart = 0.0f - totalLength / 2.0f;
            var positionYStart = 0.0f + totalHeight / 2.0f;

            Vector2 GetNodePosition(int level, int index)
            {
                if (level == maxLevel)
                {
                    return(new Vector2(positionXStart + index * (nodeMaxWidth + k_WidthBetweenNodes), positionYStart));
                }

                var posChildLeft  = GetNodePosition(level + 1, index * 2);
                var posChildRight = GetNodePosition(level + 1, index * 2 + 1);

                return(new Vector2((posChildLeft.x + posChildRight.x) / 2.0f, posChildLeft.y - k_HeightBetweenNodes - nodeMaxHeight));
            }

            for (var level = maxLevel; level >= 0; --level)
            {
                foreach (var queryNode in nodesByLevel[level])
                {
                    var viewNode = queryNodesToViewNodes[queryNode];
                    var oldRect  = viewNode.GetPosition();
                    var newPos   = GetNodePosition(level, levelIndexByNode[queryNode].Item2);
                    var newRect  = new Rect(newPos, oldRect.size);
                    viewNode.SetPosition(newRect);
                }
            }
        }
Beispiel #4
0
 internal Query(QueryGraph graph, ICollection <QueryError> errors)
 {
     this.graph  = graph;
     this.errors = errors;
 }