Exemplo n.º 1
0
 public void Node_MouseMove(BaseNodePresenter node, int button)
 {
     if (NodeMouseMove != null)
     {
         NodeMouseMove(this, node, button);
     }
 }
Exemplo n.º 2
0
 private void Node_MouseUp(BaseNodePresenter node, int button)
 {
     if (NodeMouseUp != null)
     {
         NodeMouseUp(this, node, button);
     }
 }
Exemplo n.º 3
0
        private void Start()
        {
            _graphModel = _graphProvider.GetGraph();
            _chunks     = new GraphChunkContainer(_chunkDimensions, this);
            _chunks.CalcPositionRangeFromNodes(_graphModel.Nodes);

            var nps = new Dictionary <INode, BaseNodePresenter>();

            foreach (var node in _graphModel.Nodes)
            {
                var np = new BaseNodePresenter(node);
                np.Size *= _nodeTemplate.Scale;
                _nodePresenters.Add(np);
                nps.Add(node, np);
                _chunks.GetChunkFromPosition(np.Position).NodePresenters.Add(np);
            }
            foreach (var edge in _graphModel.Edges)
            {
                var source = nps[edge.Source];
                var target = nps[edge.Target];
                var ep     = new BaseEdgePresenter(edge, source, target);
                ep.Width *= _edgeTemplate.Scale;
                _edgePresenters.Add(ep);
                _chunks.GetChunkFromPosition(ep.Source.Position).EdgePresenters.Add(ep);
                source.targets.Add(ep);
                target.sources.Add(ep);
            }

            _chunks.InitGraphViews(_graphViewPrefab, transform, _nodeTemplate, _edgeTemplate);
        }
Exemplo n.º 4
0
        private void Start()
        {
            Debug.Log("Called Start");
            _graphModel = _graphProvider.GetGraph();
            var nps = new Dictionary <INode, BaseNodePresenter>();

            foreach (var node in _graphModel.Nodes)
            {
                var np = new BaseNodePresenter(node);
                np.Size *= _nodeTemplate.Scale;
                _nodePresenters.Add(np);
                nps.Add(node, np);
            }
            foreach (var edge in _graphModel.Edges)
            {
                var source = nps[edge.Source];
                var target = nps[edge.Target];
                var ep     = new BaseEdgePresenter(edge, source, target);
                ep.Width *= _edgeTemplate.Scale;
                _edgePresenters.Add(ep);
            }

            _graphView              = Instantiate(_graphViewPrefab, transform, false);
            _graphView.MouseDown   += GraphView_MouseDown;
            _graphView.MouseMove   += GraphView_MouseMove;
            _graphView.MouseUp     += GraphView_MouseUp;
            _graphView.NodeTemplate = _nodeTemplate;
            _graphView.SetGraph(NodePresenters, EdgePresenters);
        }
        private void Start()
        {
            //setup graph start
            _graphModel      = _graphProvider.GetGraph();
            _forceDirected2D = new ForceDirected2D(_graphModel, _stiffness, _repulsion, _damping);
            var nps = new Dictionary <INode, BaseNodePresenter>();

            foreach (var node in _graphModel.Nodes)
            {
                var np = new BaseNodePresenter(node);
                np.Size *= _nodeTemplate.Scale;
                _nodePresenters.Add(np);
                nps.Add(node, np);
            }
            foreach (var edge in _graphModel.Edges)
            {
                var source = nps[edge.Source];
                var target = nps[edge.Target];
                var ep     = new BaseEdgePresenter(edge, source, target);
                ep.Width *= _edgeTemplate.Scale;
                _edgePresenters.Add(ep);
            }
            _graphView              = Instantiate(_graphViewPrefab, transform, false);
            _graphView.MouseDown   += GraphView_MouseDown;
            _graphView.MouseMove   += GraphView_MouseMove;
            _graphView.MouseUp     += GraphView_MouseUp;
            _graphView.NodeTemplate = _nodeTemplate;
            _graphView.SetGraph(NodePresenters, EdgePresenters);
        }
Exemplo n.º 6
0
 public BaseEdgePresenter(IEdge <INode> edge, BaseNodePresenter source, BaseNodePresenter target)
 {
     _edgeModel = edge;
     Source     = source;
     Target     = target;
     Width      = 1;
     color      = new Color(0, 0, 1, 1);
     Attribute  = Random.Range(0.0f, 1.5f);
 }
Exemplo n.º 7
0
 private void GraphView_MouseUp(object sender, Vector3 position, int button)
 {
     if (_interactedNode == null)
     {
         return;
     }
     //  _interactedNode.Position = this.transform.InverseTransformPoint(position);
     _graphView.UpdateNodes(UpdateNodeInfo <BaseNodePresenter> .UpdateNodes(_interactedNode));
     Node_MouseUp(_interactedNode, button);
     _interactedNode = null;
 }
Exemplo n.º 8
0
            private void GraphView_MouseUp(object sender, Vector3 position, int button)
            {
                if (_interactedNode == null)
                {
                    return;
                }
                _interactedNode.Position = position;

                _interactedNode.FirstPosition = position;
                _interactedNode.selected      = false;
                GraphView.UpdateNodes(UpdateNodeInfo <BaseNodePresenter> .UpdateNodes(_interactedNode));
                parentChunkedGraphPresenter.Node_MouseUp(_interactedNode, button);
                _interactedNode = null;
            }
        //calls the force directed graph object, to calculate the movement, then applies it
        private void CalculateForceAndUpdate(float time)
        {
            _forceDirected2D.Calculate(time);
            //get new positions from model and apply to view
            Dictionary <int, Vector3> positionDict = _forceDirected2D.ApplyCalculation();

            foreach (var pos in positionDict)
            {
                BaseNodePresenter node = IDToNode(pos.Key);
                // if (!(node ==_interactedNode))
                node.Position = pos.Value * 0.01f;
            }
            _graphView.UpdateNodes(UpdateNodeInfo <BaseNodePresenter> .UpdateNodes(_nodePresenters.ToArray()));
        }
Exemplo n.º 10
0
 private void GraphView_MouseDown(object sender, Vector3 position, int button)
 {
     foreach (var node in NodePresenters)
     {
         var sqMag = (node.Position - position).sqrMagnitude;
         var sqRad = node.Size * node.Size;
         if (sqMag < sqRad)
         {
             Debug.Log("Node hit! " + node.Position);
             _interactedNode = node;
             parentChunkedGraphPresenter.Node_MouseDown(_interactedNode, button);
             break;
         }
     }
 }
Exemplo n.º 11
0
 private void GraphView_MouseDown(object sender, Vector3 position, int button)
 {
     //find which node is interacted with
     foreach (var node in _nodePresenters)
     {
         var sqMag = (this.transform.TransformPoint(node.Position) - position).sqrMagnitude;
         var sqRad = node.Size * node.Size;
         if (sqMag < sqRad)
         {
             Debug.Log("Node hit! " + this.transform.TransformPoint(node.Position) + " Button used: " + button);
             _interactedNode = node;
             Node_MouseDown(_interactedNode, button);
             break;
         }
     }
 }
        private void GraphView_MouseDown(object sender, Vector3 position, int button)
        {
            //find interacted node
            foreach (var node in _nodePresenters)
            {
                var sqMag = (this.transform.TransformPoint(node.Position) - position).sqrMagnitude;
                var sqRad = node.Size * node.Size;
                if (sqMag < sqRad)
                {
                    Debug.Log("Node hit! " + this.transform.TransformPoint(node.Position) + " Button used: " + button);
                    _interactedNode = node;
                    Node_MouseDown(_interactedNode, button);
                    //Pin interacted node, so it gets no force calculations
                    _forceDirected2D.PinNode(_interactedNode._nodeModel, true);

                    break;
                }
            }
        }