コード例 #1
0
 /// <summary>
 ///     Creates a new visualisation with the given layout.
 /// </summary>
 /// <param name="layout">
 ///     A <see cref="T:Smog.GraphLayout"/> representing the layout
 ///     to use for the visualisation.
 /// </param>
 public Visualisation(IGraphLayout <TNode, TEdge> layout)
 {
     Layout   = layout;
     TimeStep = .5;
     Nodes    = new List <TNode>();
     Edges    = new List <TEdge>();
 }
コード例 #2
0
        public void Draw(IGraphLayout graphLayout, Rect totalDrawingArea, GraphSettings graphSettings)
        {
            var legendArea  = new Rect();
            var drawingArea = new Rect(totalDrawingArea);

            if (graphSettings.showLegend)
            {
                PrepareLegend(graphLayout.vertices);

                legendArea = new Rect(totalDrawingArea)
                {
                    width = EstimateLegendWidth() + s_BorderSize * 2
                };

                legendArea.x       = drawingArea.xMax - legendArea.width;
                drawingArea.width -= legendArea.width;// + s_BorderSize;

                DrawLegend(legendArea);
            }

            if (m_SelectedNode != null)
            {
                Event currentEvent = Event.current;
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    Vector2 mousePos = currentEvent.mousePosition;
                    if (drawingArea.Contains(mousePos))
                    {
                        m_SelectedNode = null;
                    }
                }
            }

            DrawGraph(graphLayout, drawingArea, graphSettings);
        }
コード例 #3
0
        public void Draw(IGraphLayout graphLayout, Rect drawingArea)
        {
            GraphSettings defaults;

            defaults.maximumNormalizedNodeSize = s_DefaultMaximumNormalizedNodeSize;
            defaults.maximumNodeSizeInPixels   = s_DefaultMaximumNodeSizeInPixels;
            defaults.aspectRatio = s_DefaultAspectRatio;
            defaults.showLegend  = true;
            Draw(graphLayout, drawingArea, defaults);
        }
コード例 #4
0
        void DrawGraph()
        {
            if (m_Visualizer == null)
            {
                return;
            }

            if (m_Layout == null)
            {
                m_Layout = new ReingoldTilford();
            }

            m_Visualizer.MaxDepth         = m_MaxDepth;
            m_Visualizer.MaxChildrenNodes = m_MaxChildrenNodes;
            m_Visualizer.RootNodeOverride = m_RootNodeOverride;
            m_Visualizer.Refresh();
            m_Layout.CalculateLayout((Graph)m_Visualizer);

            if (m_Renderer == null)
            {
                m_Renderer = new PlanGraphRenderer((renderer, vn) =>
                {
                    if (vn != null && vn.ExpansionNode)
                    {
                        if (vn.parent != null)
                        {
                            // We're looking to go into the children expansion of a node, so select the actual node;
                            // The one that was clicked on was placeholder for all of the children
                            m_RootNodeOverride = (IVisualizerNode)vn.parent;
                        }
                        else
                        {
                            // Navigate back up the hierarchy
                            m_RootNodeOverride = (IVisualizerNode)m_RootNodeOverride.parent;

                            // If there isn't another parent, then we're actually back at the root
                            if (m_RootNodeOverride != null && m_RootNodeOverride.parent == null)
                            {
                                m_RootNodeOverride = null;
                            }
                        }

                        renderer.ResetSelection();
                    }

                    m_GraphSettings.showInspector = vn != null;
                });
            }

            var toolbarHeight = EditorStyles.toolbar.fixedHeight;
            var graphRect     = new Rect(0, toolbarHeight, position.width, position.height - toolbarHeight);

            m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings, m_Visualizer);
        }
コード例 #5
0
        public void Draw(IGraphLayout _graphLayout, Rect _drawingArea)
        {
            GraphSettings defaults = new GraphSettings()
            {
                MaximumNormalizedNodeSize = DEFAULT_MAXIMUM_NORMALIZED_NODE_SIZE,
                MaximumNodeSizeInPixels   = DEFAULT_MAXIMUM_NODE_SIZE_IN_PIXELS,
                NodeAspectRatio           = DEFAULT_ASPECT_RATIO,
                ShowInspector             = true,
            };

            Draw(_graphLayout, _drawingArea, defaults);
        }
コード例 #6
0
        void OnGUI()
        {
            // Early out if there is no graphs.
            var selectedGraphs = GetGraphList();

            if (selectedGraphs.Count == 0)
            {
                ShowMessage("No PlayableGraph in the scene");
                return;
            }

            GUILayout.BeginVertical();
            m_CurrentGraph = GetSelectedGraphInToolBar(selectedGraphs, m_CurrentGraph);
            GUILayout.EndVertical();

            if (!m_CurrentGraph.IsValid())
            {
                ShowMessage("Selected PlayableGraph is invalid");
                return;
            }

            var graph = new PlayableGraphVisualizer(m_CurrentGraph);

            graph.Refresh();

            if (graph.IsEmpty())
            {
                ShowMessage("Selected PlayableGraph is empty");
                return;
            }

            if (m_Layout == null)
            {
                m_Layout = new ReingoldTilford();
            }

            m_Layout.CalculateLayout(graph);

            var graphRect = new Rect(0, s_ToolbarHeight, position.width, position.height - s_ToolbarHeight);

            if (m_Renderer == null)
            {
                m_Renderer = new DefaultGraphRenderer();
            }

            m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings);
        }
コード例 #7
0
        public LayoutEngine(NewItemsControl graphControl, IGraphLayout graphLayout)
        {
            if (graphControl == null)
            {
                throw new ArgumentNullException(nameof(graphControl));
            }

            GraphLayout = graphLayout;

            var count       = graphControl.Items.Count;
            var nodeBuilder = ImmutableArray.CreateBuilder <NodeDataBlock>(count);
            var edgeBuilder = ImmutableArray.CreateBuilder <EdgeDataBlock>(count);

            foreach (var item in graphControl.Items)
            {
                switch (item)
                {
                case Node node:
                    nodeBuilder.Add(CreateInstance <NodeDataBlock>(nodeBuilder.Count, node));
                    break;

                case Edge edge:
                    edgeBuilder.Add(CreateInstance <EdgeDataBlock>(edgeBuilder.Count, edge));
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }

            Nodes = nodeBuilder.Capacity == nodeBuilder.Count
                ? nodeBuilder.MoveToImmutable()
                : nodeBuilder.ToImmutable();
            Edges = edgeBuilder.Capacity == edgeBuilder.Count
                ? edgeBuilder.MoveToImmutable()
                : edgeBuilder.ToImmutable();

            foreach (var edge in Edges)
            {
                edge.Assign(this);
            }
            foreach (var node in Nodes)
            {
                node.Assign(this);
            }
        }
        public void Draw(IGraphLayout graphLayout, Rect totalDrawingArea, GraphSettings graphSettings)
        {
            if (m_LegendLabelStyle == null)
            {
                InitializeStyles();
            }

            var legendArea  = new Rect();
            var drawingArea = new Rect(totalDrawingArea);

            PrepareLegend(graphLayout.vertices);

            if (graphSettings.showInspector)
            {
                legendArea = new Rect(totalDrawingArea)
                {
                    width = Mathf.Max(EstimateLegendWidth(), drawingArea.width * 0.25f) + s_BorderSize * 2
                };

                legendArea.x       = drawingArea.xMax - legendArea.width;
                drawingArea.width -= legendArea.width; // + s_BorderSize;

                DrawLegend(graphSettings, legendArea);
            }

            if (m_SelectedNode != null)
            {
                Event currentEvent = Event.current;
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    Vector2 mousePos = currentEvent.mousePosition;
                    if (drawingArea.Contains(mousePos))
                    {
                        m_SelectedNode = null;

                        if (nodeClicked != null)
                        {
                            nodeClicked(m_SelectedNode);
                        }
                    }
                }
            }

            DrawGraph(graphLayout, drawingArea, graphSettings);
        }
コード例 #9
0
    private void DrawNodesUsingGraphAPI(Rect canvas)
    {
        if (selectedRecording != null && selectedRecording != lastDisplayedRecording)
        {
            MultiValueDictionary <BGoapNode, BGoapNode> childNodes = new MultiValueDictionary <BGoapNode, BGoapNode>();
            BGoapNode root = null;

            foreach (INode <BGoapState> inode in selectedRecording.search)
            {
                if (inode.GetParent() != null)
                {
                    childNodes.Add(inode.GetParent() as BGoapNode, inode as BGoapNode);
                }
                else
                {
                    root = inode as BGoapNode;
                }
            }

            graph = new AStarDebugGraph(childNodes, root, selectedRecording.goal);
            graph.Refresh();
            if (graph.IsEmpty())
            {
                ShowMessage("No graph data");
                return;
            }

            if (layout == null)
            {
                layout = new ReingoldTilford(false);
            }

            layout.CalculateLayout(graph);

            if (renderer == null)
            {
                renderer = new AStarDebugGraphRenderer();
            }

            renderer.Draw(layout, canvas, new GraphSettings()
            {
                maximumNodeSizeInPixels = 200, maximumNormalizedNodeSize = 1f, aspectRatio = 1.61f
            }, fontSize, offset);
        }
    }
 public void Draw(IGraphLayout graphLayout, Rect drawingArea, GraphSettings graphSettings)
 {
     this.graphLayout = graphLayout;
     if (this.graphLayout == null) return;
     
     foreach (var o in graphLayout.edges)
     {
         // find matching edge in dictionary so we can update the weights properly
         if (edgeToEdge.TryGetValue((o.destination.node.content, o.source.node.content), out var kvp))
         {
             foreach(var edge in kvp)
                 edge.style.opacity = o.source.node.weight * 0.8f + 0.2f;
         }
         // var graphEdge = edgeToEdge.FirstOrDefault(x => x.Key.destination.node == o.destination.node && x.Key.source.node == o.source.node).Value;
         // if(graphEdge != null)
         //     graphEdge.style.co
     }
 }
コード例 #11
0
        public void Draw(IGraphLayout _graphLayout, Rect _totalDrawingArea, GraphSettings _graphSettings)
        {
            if (m_SelectedNode != null)
            {
                Event currentEvent = Event.current;
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    Vector2 mousePos = currentEvent.mousePosition;
                    if (_totalDrawingArea.Contains(mousePos))
                    {
                        m_SelectedNode = null;

                        OnNodeClicked?.Invoke(m_SelectedNode);
                    }
                }
            }

            DrawGraph(_graphLayout, _totalDrawingArea, _graphSettings);
        }
コード例 #12
0
        public void Draw(IGraphLayout _graphLayout, Rect _totalDrawingArea, GraphSettings _graphSettings, PuppeteerPlanVisualiser _visualiser)
        {
            var drawingArea = new Rect(_totalDrawingArea);

            if (_graphSettings.ShowInspector)
            {
                var inspectorArea = new Rect(_totalDrawingArea)
                {
                    width = Mathf.Max(INSPECTOR_FIXED_WIDTH, drawingArea.width * 0.25f) + BORDER_SIZE * 2
                };

                inspectorArea.x    = drawingArea.xMax - inspectorArea.width;
                drawingArea.width -= inspectorArea.width;

                DrawInspector(inspectorArea, _visualiser);
            }

            Draw(_graphLayout, drawingArea, _graphSettings);
        }
コード例 #13
0
    public void Draw(IGraphLayout graphLayout, Rect totalDrawingArea, GraphSettings graphSettings, IPlanVisualizer visualizer)
    {
        var drawingArea = new Rect(totalDrawingArea);

        if (graphSettings.showInspector)
        {
            var inspectorArea = new Rect(totalDrawingArea)
            {
                width = Mathf.Max(s_InspectorFixedWidth, drawingArea.width * 0.25f) + s_BorderSize * 2
            };

            inspectorArea.x    = drawingArea.xMax - inspectorArea.width;
            drawingArea.width -= inspectorArea.width;

            DrawInspector(inspectorArea, visualizer);
        }

        m_GraphOnlySettings.maximumNormalizedNodeSize = graphSettings.maximumNormalizedNodeSize;
        m_GraphOnlySettings.maximumNodeSizeInPixels   = graphSettings.maximumNodeSizeInPixels;
        m_GraphOnlySettings.aspectRatio = graphSettings.aspectRatio;
        m_GraphOnlyRenderer.Draw(graphLayout, drawingArea, m_GraphOnlySettings);
    }
コード例 #14
0
    void OnGUI()
    {
        // Create a list of all the playable graphs extracted.
        IList <PlayableGraphInfo> graphInfos = new List <PlayableGraphInfo>();

        PlayableGraphInfo info;

        // If we requested, we extract automatically the PlayableGraphs from all the components
        // that are in the current scene.
        if (m_AutoScanScene)
        {
            // This code could be generalized, maybe if we added a IHasPlayableGraph Interface.
            IList <PlayableDirector> directors = FindObjectsOfType <PlayableDirector>();
            if (directors != null)
            {
                foreach (var director in directors)
                {
                    if (director.playableGraph.IsValid())
                    {
                        info.name  = director.name;
                        info.graph = director.playableGraph;
                        graphInfos.Add(info);
                    }
                }
            }

            IList <Animator> animators = FindObjectsOfType <Animator>();
            if (animators != null)
            {
                foreach (var animator in animators)
                {
                    if (animator.playableGraph.IsValid())
                    {
                        info.name  = animator.name;
                        info.graph = animator.playableGraph;
                        graphInfos.Add(info);
                    }
                }
            }
        }

        if (GraphVisualizerClient.GetGraphs() != null)
        {
            foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
            {
                if (clientGraph.Key.IsValid())
                {
                    info.name  = clientGraph.Value;
                    info.graph = clientGraph.Key;
                    graphInfos.Add(info);
                }
            }
        }

        // Early out if there is no graphs.
        if (graphInfos.Count == 0)
        {
            ShowMessage("No PlayableGraph in the scene");
            return;
        }

        GUILayout.BeginVertical();
        m_CurrentGraphInfo = GetSelectedGraphInToolBar(graphInfos, m_CurrentGraphInfo);
        GUILayout.EndVertical();

        if (!m_CurrentGraphInfo.graph.IsValid())
        {
            ShowMessage("Selected PlayableGraph is invalid");
            return;
        }

        var graph = new PlayableGraphVisualizer(m_CurrentGraphInfo.graph);

        graph.Refresh();

        if (graph.IsEmpty())
        {
            ShowMessage("Selected PlayableGraph is empty");
            return;
        }

        if (m_Layout == null)
        {
            m_Layout = new ReingoldTilford();
        }

        m_Layout.CalculateLayout(graph);

        var graphRect = new Rect(0, s_ToolbarHeight, position.width, position.height - s_ToolbarHeight);

        if (m_Renderer == null)
        {
            m_Renderer = new DefaultGraphRenderer();
        }

        m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings);
    }
コード例 #15
0
        // Draw the graph and returns the selected Node if there's any.
        private void DrawGraph(IGraphLayout graphLayout, Rect drawingArea, GraphSettings graphSettings)
        {
            // add border, except on right-hand side where the legend will provide necessary padding
            drawingArea = new Rect(drawingArea.x + s_BorderSize,
                                   drawingArea.y + s_BorderSize,
                                   drawingArea.width - s_BorderSize * 2,
                                   drawingArea.height - s_BorderSize * 2);

            var b = new Bounds(Vector3.zero, Vector3.zero);

            foreach (Vertex v in graphLayout.vertices)
            {
                b.Encapsulate(new Vector3(v.position.x, v.position.y, 0.0f));
            }

            // Increase b by maximum node size (since b is measured between node centers)
            b.Expand(new Vector3(graphSettings.maximumNormalizedNodeSize, graphSettings.maximumNormalizedNodeSize, 0));

            var scale  = new Vector2(drawingArea.width / b.size.x, drawingArea.height / b.size.y);
            var offset = new Vector2(-b.min.x, -b.min.y);

            Vector2 nodeSize = ComputeNodeSize(scale, graphSettings);

            GUI.BeginGroup(drawingArea);

            foreach (var e in graphLayout.edges)
            {
                Vector2 v0   = ScaleVertex(e.source.position, offset, scale);
                Vector2 v1   = ScaleVertex(e.destination.position, offset, scale);
                Node    node = e.source.node;

                if (graphLayout.leftToRight)
                {
                    DrawEdge(v1, v0, node.weight);
                }
                else
                {
                    DrawEdge(v0, v1, node.weight);
                }
            }

            Event currentEvent = Event.current;

            bool oldSelectionFound = false;
            Node newSelectedNode   = null;

            foreach (Vertex v in graphLayout.vertices)
            {
                Vector2 nodeCenter = ScaleVertex(v.position, offset, scale) - nodeSize / 2;
                var     nodeRect   = new Rect(nodeCenter.x, nodeCenter.y, nodeSize.x, nodeSize.y);

                bool clicked = false;
                if (currentEvent.type == EventType.MouseUp && currentEvent.button == 0)
                {
                    Vector2 mousePos = currentEvent.mousePosition;
                    if (nodeRect.Contains(mousePos))
                    {
                        clicked = true;
                        currentEvent.Use();
                    }
                }

                bool currentSelection = (m_SelectedNode != null) &&
                                        v.node.content.Equals(m_SelectedNode.content); // Make sure to use Equals() and not == to call any overriden comparison operator in the content type.

                DrawNode(nodeRect, v.node, currentSelection || clicked);

                if (currentSelection)
                {
                    // Previous selection still there.
                    oldSelectionFound = true;
                }
                else if (clicked)
                {
                    // Just Selected a new node.
                    newSelectedNode = v.node;
                }
            }

            if (newSelectedNode != null)
            {
                m_SelectedNode = newSelectedNode;

                if (nodeClicked != null)
                {
                    nodeClicked(m_SelectedNode);
                }
            }
            else if (!oldSelectionFound)
            {
                m_SelectedNode = null;
            }

            GUI.EndGroup();
        }
 public void Draw(IGraphLayout graphLayout, Rect drawingArea)
 {
     // doesn't seem to be used anywhere?
     throw new NotImplementedException();
 }
コード例 #17
0
 public void Draw(IGraphLayout graphLayout, Rect drawingArea, GraphSettings graphSettings)
 {
     Draw(graphLayout, drawingArea, graphSettings, 10, Vector2.zero);
 }