New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added plug-in for custom node shapes and images #106
Conversation
drawNodeShape (used by drawNode) drawHoverNodeBorder/Shape (used by drawHoverNode) drawActiveNodeBorder/Shape (use by drawActiveNode) The drawing functions gets color, x, y and size as parameters, and draw to a ctx parameter. Optionally the drawing functions can use the node.attr data to do additional stuff (may be used by plug-ins later on). The drawing functions adhere to keeping the drawn shape in the radius of 'size' - so that other graph calculations work well. In the default case - all functions draw a filled circle according to the passed parameters. This is identical to the current behavior.
- skeleton - on init store original plotter methods and replace with plug-in drawShapedNode function - on finalize restore original plotter functions - currently drawShapedNode focuses on adding images on top of the regular circle shapes. Image attributes taken from node.attr.image. Function not yet complete
… (instance override instead of class override) - image on nodes work well in nodeShapes plugin
currently the circle drawing from the original Plotter class are plugged as shape 'circle'
- extending sigma.tools with shape drawing functions - 'shape' attribute is now a hash, with shape name in 'name' inside it. Allows adding more options - see impl. of star allows configuring number of points and inner radius
… reached also addede custom node shape to public API
@@ -215,10 +215,10 @@ function Plotter(nodesCtx, edgesCtx, labelsCtx, hoverCtx, graph, w, h) { | |||
s['hidden'] || |
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.
Looks like the diff reflects a lot of indentation corrections, likely caused by my vim's auto-indent
I added a comment below ONLY FOR real (non-indent) code changes to make the review easier
That's really awesome. I can definitely use that. Thanks! |
Thanks! I'll start writing the classic-video-games-node-shape-expansion pack ;) |
oops.. closed by mistake, reopened. |
- set number of pointes - set rotation (degrees) clockwise - 'iso-poly' with numPoint=3 equals 'triangle'. add 'rotate': 60 to turn it on its head - 'iso-poly' with numPoint=4 equals 'diamond'. add 'rotate': 45 to make it a 'square'
also updated online sample on https://dl.dropboxusercontent.com/u/45136256/sigma.js/nodeshapes.html
awesome work! |
awesome work!! 👍 I put node-shape like this [viz:node-shape value="image" uri="/img/switch.png" /] = ( ] to > ) |
Thanks. Currently it does not work with parseGexf - the problem is that since the node shapes/images are plug-in functionality, it would not be the best behavior to put dependent code in another plug-in. However, this would be easy to add to a custom version of the GEXF plug-in:
Let me know if you need help with this |
nice~ I make very very rough code . anyway it seems work.
don't blame me :) |
Thanks :) I love it!! |
Great plug-in there ! 👍 @Bhb2011 @rpeleg1970 In graph loading script : sigInst.parseGexf('{{ asset("assets/json/linternaute.gexf")}}');
sigInst.startNodeShapes(); In parseGexf.js : //add node shape
var shapeNodes = nodeNode.getElementsByTagName('nodeshape');
shapeNodes = shapeNodes.length ?
shapeNodes :
nodeNode.getElementsByTagName('viz:nodeshape');
if(shapeNodes.length>0){
shapeNode = shapeNodes[0];
nodeShape = shapeNode.getAttribute('value');
imgUri = shapeNode.getAttribute('uri');
}
// Create Node
var node = {label:label, size:size, x:x, y:y, attributes:[], color:color, shape:{name: nodeShape}, image:{url:imgUri, scale:1}}; // The graph node In my gexf file : <viz:nodeshape value="square" uri="/assets/img_wd/Post.png"></viz:nodeshape> Thanx for your advice |
Hello @blt909 I understand you took the code that worked for @Bhb2011 . One thing that comes to mind - I see you call sigInst.startNodeShapes() AFTER you call sigInst.parseGexf('...'). This means that when you run the parse- the node-shape plug-in is not yet initialized. Can you try reverse the order and try again? Thanks |
Hello @rpeleg1970 I reversed the instructions sequence and tried again with no improval .
Thanks |
Hmm... Is the asset URI correct? I see when you load the GEXF file you load it from 'assets/...' (relative path) while for the image you use an absolute path ('/assets/...') Also - before you try the GEXF - can try to use an example similar to https://dl.dropboxusercontent.com/u/45136256/sigma.js/nodeshapes.html - just to see the plug-in is working well as is? |
I verified my assets URIs, they are both ok (relative one comes from a templating engine, absolute one is a copy/paste from the output of the templating engine for testing the plugin). Here's the simpliest example possible for a gexf file (2 nodes , 1 edge) : <?xml version='1.0' encoding='UTF-8'?>
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2" xmlns:viz="http://www.gexf.net/1.2draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd">
<meta lastmodifieddate="2013-12-11">
<creator>Gephi 0.8.1</creator>
<description></description>
</meta>
<graph defaultedgetype="undirected" mode="static">
<attributes class="node" mode="static">
<attribute id="onto_class" title="onto_class" type="string"/>
<attribute id="note" title="note" type="integer"/>
</attributes>
<nodes>
<node id="Agent35" label="Agent35">
<attvalues>
<attvalue for="onto_class" value="Agent"/>
<attvalue for="note" value="0"/>
</attvalues>
<viz:size value="1.0"/>
<viz:nodeshape value="square" uri="/assets/img_wd/Agent.png"></viz:nodeshape>
<viz:position x="40.94513" y="-36.955757" z="0.0"/>
<viz:color r="153" g="153" b="153"/>
</node>
<node id="Post36" label="Post36">
<attvalues>
<attvalue for="onto_class" value="Post"/>
<attvalue for="note" value="0"/>
</attvalues>
<viz:size value="1.0"/>
<viz:nodeshape value="diamond" uri="/assets/img_wd/Post.png"></viz:nodeshape>
<viz:position x="-40.94513" y="36.955757" z="0.0"/>
<viz:color r="153" g="153" b="153"/>
</node>
</nodes>
<edges>
<edge source="Agent35" target="Post36" label="webdrone:postedBy">
<attvalues/>
</edge>
</edges>
</graph>
</gexf> I'm looking forward to test that the plugin is working well without the GEXF loader Thanks |
Hi I used your exact code with the obvious modification of images and locations, to fit my setup. It worked well, sorry..
Hope any of this helps |
Hi I checked the few points :
So I think there's something disturbing the access to the methods.
|
Hmmm... kind of ran out of ideas, wish I could recreate it here. I would try to break inside the draw.*NodeShape, in the sigma.nodeShapes.js, and see where its going, and where it's blocked. one last idea as I write: Cheers |
Hi, that awkward you realize it was so simple after all ^^. Sorry for the waste of your time Ron and thanks for your attention. |
Great, glad I helped |
Here is how custom node renderers work in the new version of sigma: Everyone wants different ways to render nodes, but I cannot merge everything in the core. So, from now, it is easy for you to develop custom node renderers on the fly or as plugins for your specific needs. I just added an example with a renderer that draws images instead of discs, to show how it works. Anyway, the plugin still sounds relevant, to make it easier to display nodes as images + shapes. It might be interested to port it to the new sigma. |
Hi Alexis, I will take the porting on me, thanks for the feedback ! Cheers ב-12 בינו 2014, בשעה 18:13, "Alexis Jacomy" notifications@github.com כתב/ה:
|
That's good news, thanks for this :) |
Dragging an unselected node while another node is selected drags both
Hi,
I added a plug-in called sigma.nodeShapes - demo / intro code sample here: https://dl.dropboxusercontent.com/u/45136256/sigma.js/nodeshapes.html
the plug-in itself adds more node drawing functions for:
In addition, the plug-in exposes an API to add additional custom shapes - also shown in demo with a 'Pacman' node.
All node drawing functions keep the shape bounded in the node size radius. This is important for keeping the rest working - mouse click and hover, force atlas, arrow edges, etc.
Last - the plug-in adds the ability to draw images on nodes, demonstrated as well. This addresses issue #83
This plugin is based on minimal changes to plotter - needed to expose the functionality that currently draws circle for regular, active, and hover nodes (as well as borders). no changes to node attribute were made - the attributes for shape and image drawing are piggybacked on the node.attr bag.
_NOTE_: post-mortem I noticed the file changes for plotter.js shows a lot of false diffs, due to auto-indent in my vi editor. I believe these are good indentations but can provide a non-indented version if you prefer. To help you review the code - I added a note next to each REAL code change (see under Files Changed tab)