-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(network) selected image: setting image doesn't affect current image #2894
Conversation
Hi there, For my understanding: Is this a fix for something that happens during the resetting of the options? |
Hi there, |
The issue I have with the changes is that they assume that options can be reset. Which is fine, but they don't take into account that the images themselves can be reset. To be honest, most of the code does not take the resetting of the options into account. So, the underlying question for me becomes, should we support it? My opinion is that is should be possible, and I'm willing to restrict the implementation to the images. I have to think about how to handle this myself. Will get back on this. |
OK, I think I'm overextending my thoughts here. This PR is obviously an itch you're scratching. I'll pick up the gist of the previous comment in a separate issue/PR. |
I'm doing my best to find a test case for this fix, without success. Can you perhaps provide a test example where the selection disappears after calling
I found exactly one case in which the node is remade from scratch: when option I'm currently at a loss here; I don't see the fix as-is solving anything. Perhaps we're using different Update: using latest stable doesn't make a difference. Select is still working properly. |
This issue is happening on our customised private version of Vis. Maybe my use case is not even possible with the normal version? I'll try to put together an example that reproduces this issue. Until then stay put :) |
I managed to set up an example that reproduces this issue: Steps to reproduce:
I tried the exact same example on my machine with the fix applied and the bug was not there. |
👍 Thanks for taking the trouble to make a demo! Much appreciated. I can see now how your changes address an issue. However, I with my pedantic frame of mind, see a whole more bunch of related problems here. For example, it's now possible to initialize an image node without any images, which leads to errors on drawing. Methinks it's ripe for further improvement. But that's not the topic of this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your issue has uncovered many things wrong with the setting of the node images. Rather than having you take the full brunt fixing this, I'll make a separate PR for all stuff outside your code changes. I'll still review the code you submitted.
Ok then I leave it to you. |
|
||
if (imageObjAlt) { | ||
this.imageObjAlt = imageObjAlt; | ||
if (imageObjAlt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imageObjAlt
needs to be set always, not just if it is defined. It should be possible to remove the alt image in an update.
This also applies to the uses of imageObjAlt
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove those checks and create an image node only containing an unselected
image or even no image (which is stupid but possible to do) then we get a JS error.
You may want to update the code yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yes, the code needs to be rearranged somewhat.
You may want to update the code yourself.
If you mean that I create another PR to fix this, that's perfectly fine with me.
Shall I close this PR and create a new one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please. I don't feel like refactoring the codebase myself. I'm too used to TypeScript now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK fine.
I'm too used to TypeScript now :)
Oh, you lucky bastard. I'm itching to go there. There is no hope for TypeScript in vis.js
, but I've been rabidly refactoring my own current project to make it possible.
Thank you sincerely for your effort here. The bug is genuine and it needs to be tackled. All the best!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no hope for TypeScript in vis.js
I understand that it would be an important update but maybe would it bring vis.js
(or .ts
??) to the next step! An intermediary step could be to switch to strict ES6 using eslint (with no var
s etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An intermediary step could be to switch to strict ES6 using eslint
Oh yes, definitely. That is actually an active discussion between the admins here 😄. Let's hope something good will come out of that!
if (imageObj) { | ||
this.imageObj = imageObj; | ||
if (!this.selected) { | ||
if (imageObj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: imageObj must always be defined on the call of this method. For the intent of your code changes, you can assume this is so.
I wasn't implying in the review that I would do all the work. After extensive testing, I did find one issue, see the review notes. I would appreciate it if you can make this fix; however, if you prefer that I do it, that's actually OK with me. Shall I take it on me? |
I just read your message. I will have a look at it soon. |
Closed because superseded by #3053. |
In our private project, I encountered the case where a selected image was redrawn. In that case, the node switched back to the unselected image. This PR fixes this.