Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

When in addEdgeMode() the click network.on('click', ... does not fire. #3131

Closed
jmvenancio opened this issue Jun 4, 2017 · 21 comments
Closed

Comments

@jmvenancio
Copy link

jmvenancio commented Jun 4, 2017

I activate the addEdgeMode() and then when I click in the canvas nothing ``happens.

network.on('click', function (properties) {
        var point = properties.pointer.DOM;
        var selNodes = properties.nodes;
        //console.log(point);
        var selecNode = nodes.get([selNodes])[0];
        console.log(selecNode.id);
        console.log(node_sel);`

Although this works when the addEdgeMode is not active.

Thank you in advance :)

@wimrijnders
Copy link
Contributor

wimrijnders commented Jun 5, 2017

Here is a jsbin with addEdgeMode() called, derived from example network/events/interactionEvents. It works just fine.

When I add your example code, it doesn't work. I have added it in the jsbin, commented out. Could you please adjust the jsbin example so that it does work?

@jmvenancio
Copy link
Author

Thank you for your answer.

I just noticed it has the same problem! When you click and drag to draw the edge the click event is not fired... I need to know the starting node of the edge that I am drawing...

@jmvenancio
Copy link
Author

I edited the jsbin and if you notice if you start drawing an edge no event is fired. Even if you change to dragStart

@wimrijnders
Copy link
Contributor

Aha, so the issue is not with the click event. There is a dragStart, but it's meant to be used with dragging nodes. I'll see how this translates to dragging new edges.

@jmvenancio
Copy link
Author

Thank you! I am really struggling here to get the starting node! In fact I think that an edgeStart and an edgeEnd events would be really apperciated.

@wimrijnders
Copy link
Contributor

wimrijnders commented Jun 5, 2017

There's no way I can offer you a workaround for this. The code needs to be changed in ManipulationSystem.

There are two points in there in which dragStart is used, they would both need to have an emit event added. It shouldn't be hard.

Are you using the github repo BTW? Or just a ready-made vis.js?

@jmvenancio
Copy link
Author

I am using an ready-made vis.js... I can try to look at the code of manipulation system and try to implement this feature. But I can't promise anything

@wimrijnders
Copy link
Contributor

No, you don't have to. It's just that it would make it easier to give you a quick solution. Otherwise you would have to wait for the next release.

I know what to do here; I'll think of how I can get you something that works, quickly.

@jmvenancio
Copy link
Author

Ok! I am not in a rush! When will it be the next release? I can actually use the github repo but in the final version of my project I would need the ready-made

Thanks a lot for your work!

@wimrijnders
Copy link
Contributor

Next release is not planned yet; that decision is made when there is enough new stuff to put into it.
I'm thinking that I could make you an interim build, until the changes you need are released. We'll figure it out.

Thanks a lot for your work!

My pleasure! Gratitude is good currency for open-source work.

@jmvenancio
Copy link
Author

Thank you! Tell me something when you have any news!

@wimrijnders
Copy link
Contributor

wimrijnders commented Jun 6, 2017

Generating a dragStart event for adding an edge is easy. The following changes are required:

In ManipulationSystem.js:

  addEdgeMode() {
...
    this._temporaryBindUI('onDragStart',this._dragStartEdge.bind(this));
...
  }
...
  _dragStartEdge(event) {
    let pointer = this.lastTouch;
    this.selectionHandler._generateClickEvent('dragStart', event, pointer, undefined, true);
  }

There is no need to add a specific dragEnd for ManipulationSystem, the regular event fires already.

Now, there is a slight problem with the definition of the events. From the documentation, the event that is passed in:

{
  nodes: [Array of selected nodeIds],
  edges: [Array of selected edgeIds],
  event: [Object] original click event,
  pointer: {
    DOM: {x:pointer_x, y:pointer_y},
    canvas: {x:canvas_x, y:canvas_y}
  }
}

The problem is that, when adding a new edge, there are no selected nodes and edges. Well, technically there are, but in the strict sense these are the nodes and edges selected already in the network. This has nothing to do with the node being dragged from. Also, note that the edge that is being added does not even exist in the network at the time of dragging.

In order to avoid confusion with the matter, I prefer to just not pass the selected nodes and edges through (last parameter in _getClickEvent() call).


There is another action available in ManipulationSystem that warrants dragStart and dragEnd events, namely the editing of a current edge. The problem here is that extra control nodes are added to the view to manipulate the edit. In dragStart, when trying to determine the starting node, what you get is the control node, and not the original node.

I can't solve this, so I'm just going to ignore editing edges for this issue.

@wimrijnders
Copy link
Contributor

I have adjusted the jsbin for these changes, see if this is to your liking.

In the drag events, the id of current node is determined with method getNodeAt(). I believe this is sufficient for your purposes.

@jmvenancio
Copy link
Author

I can not test the version in jsbin. There is something wrong with the vis imported.

@wimrijnders
Copy link
Contributor

I see what you mean. The external resources take an eternity to download.
I tried the vis on github and a copy on my personal server. Both are easily available but jsbin doesn't load them.

I'm quite positive that the vis is in order; I think this is a glitch on jsbin itself. I'd wait a bit and try again.

@jmvenancio
Copy link
Author

I manage to solve the problem in jsbin and now I am using your vis.js version in my project! It solves my problem :) can I still use this version until the next release?

@jmvenancio
Copy link
Author

jmvenancio commented Jun 6, 2017

If you put the script like this <script type="text/javascript" src="https://rawgit.com/wimrijnders/github_bugs/master/vis/issue3131/vis.min.js"></script> int the html it works fine in jsbin! Thank you again !!

I changed from raw.githubusercontent.com to rawgit.com

@wimrijnders
Copy link
Contributor

wimrijnders commented Jun 6, 2017

TIL github url's but still not working for me. I think the internet has the hiccups.
Edit: Live preview works, though.

It solves my problem ;)

OK, great. Yeah, you could use that version. I'd prefer it if you download it to your machine and use it locally.

@jmvenancio
Copy link
Author

Ok I will do that! I would apreciate if you let me know when the next release is out!

Many thanks again!

@wimrijnders
Copy link
Contributor

wimrijnders commented Jun 7, 2017

let me know when the next release is out!

I could promise I will do that, but I know myself and I will likely forget. Rather than depending entirely on me, please check periodically yourself.

Update: Sorry to say the fix didn't make it into latest release 4.20.1. I hope we're not testing your patience too much....

@gs-pkumari
Copy link

How we can show details on clicking any node.?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants