-
Notifications
You must be signed in to change notification settings - Fork 1.5k
can we add hexagon as shape for node in network #3418
Comments
The right way to do this, would be to add the hexagon as a drawable shape to An alternative would be to draw the shape yourself in the SVG is supported, but drawing SVG's on a canvas element has severe limitations. See example HTML in Nodes. |
I have added following in code snippet in the lib/network/shapes.js /**
* Draw a Hexagon shape with 6 sides
* @param {Number} x horizontal center
* @param {Number} y vertical center
* @param {Number} r radius
*/
CanvasRenderingContext2D.prototype.hexagon = function (x, y, r) {
// http://www.html5canvastutorials.com/labs/html5-canvas-star-spinner/
this.beginPath();
var a = (Math.PI*2)/6;
this.translate(x,y);
this.moveTo(radius,0);
for (var i = 1; i < sides; i++) {
this.lineTo(radius*Math.cos(a*i),radius*Math.sin(a*i));
}
this.closePath();
}; should I need to also update the vis.js file |
Hugely appreciated that you took it upon yourself to pick this up. However, there's just a bit more work to do. The next step is to add a class in I'll get back to you on the first available opportunity. |
I added the class Hexagon in lib/network/module/components/nodes/shapes |
You are fast, my friend. Two more steps to go with the source code, if you're up to it:
After that, the code is done. To build:
And now is a good moment to test if it still works and your new shape works:
{id: 1, label: 'Node 1', shape:'hexagon'}, ...and refresh. If it all works, congrats, you are an open source developer! Edit: And also, the documentation will need updating. I know, a lot of work in total. And this is a simple change. |
I did all the changes, but it's not working still shows an ellipse shape |
OK, great that you went so far. I'll need a bit more than that to go on. What errors are you getting? Do you have the code changes available, so I can look into it? It would be ideal if you had a fork on |
Sorry for the delay, here is my code https://github.com/rg2609/vis |
OK. It looks like you made your changes in the I sincerely hope you continue on this path! |
gulp lint throws an error |
OK. Yes, that would be missing in the |
I moved to the develop branch and also run npm install, but still, its giving an error |
OK, following you here. Did the following:
I see the following
Is this the same that you get? This means that you'll need to add some commenting to your added classes and methods. It's not a code error. You can skip this for now. Now, try compiling a
On my machine, it builds perfectly. If that's the same for you, try out the examples as I described above:
...and refresh. |
This is turning out to be a development tutorial for |
I have a problem in |
I can only do |
can I create pull request to merge in your develop branch? |
Not necessary, I've cloned your repo. Just update there and tell me when you're done. Edit: Maybe I misunderstood. If you're done, of course you can create a pull request on main repo. |
done with the logic of drawing hexagon, you can now do the |
Almost there! ...
this.lineTo(x + r*Math.cos(a*i), y + r*Math.sin(a*i)); // note x,y
... |
oops sorry, thank you for your review, updated that one |
Thank you, will I create PR to marge in the |
👍 Merge to |
No, don't close it now. It will be closed when the PR is added to the Release build. |
👍 okay..... |
Fixed awaiting release of #3420 |
I am using the Network layout and I wanted to show node in hexagon shape, how can I do this, can we use SVG script in vis js
The text was updated successfully, but these errors were encountered: