Change all nodes to an image when displayed

99 views
Skip to first unread message

Eoin Irwin

unread,
Jan 27, 2017, 2:15:21 PM1/27/17
to JavaScript InfoVis Toolkit
The above image shows the circle nodes, however, I'm looking to get a custom image to display instead. Similar to the switch attached.



Anyone aware how to achieve this? 

Thanks,
Eoin
current.PNG
switch.PNG

Hamann

unread,
Jan 28, 2017, 3:00:09 PM1/28/17
to JavaScript InfoVis Toolkit
if u want 2 load a img as Node Type , u could do this

First make your own custom node type:

$jit.RGraph.Plot.NodeTypes
.implement(
{
'exampleIMG' : {
'img' : "default.png",
'render' : function(node, canvas) {
var ctx = (typeof canvas.getCtx == "function" ? canvas
.getCtx()
: canvas.getContext("2d"));
var img = new Image();
img.src = "htttp://www.example.com/png/example.png";
var pos = node.pos.getc(true);
ctx.drawImage(img, pos.x - (img.width / 2),
pos.y - (img.height / 2));
},
'contains' : function(node, pos) {
return false;
}
}
});

just defined node as "exampleIMG" in your JSON data structure
or test direct in your debug console (chrome)

$jit.Graph.Util.eachNode(rgraph.graph, function(test) { 
 test.data.$type = "exampleIMG"; 
 }); 
 rgraph.refresh();

Good luck :P



Op vrijdag 27 januari 2017 20:15:21 UTC+1 schreef Eoin Irwin:

Eoin Irwin

unread,
Jan 29, 2017, 9:23:22 AM1/29/17
to JavaScript InfoVis Toolkit
It's working! Thanks very much Hamann! 

Appreciated :) 

Hamann

unread,
Jan 30, 2017, 7:50:54 AM1/30/17
to JavaScript InfoVis Toolkit
Ow i forget this

If you want transparency
Add this 2 your code

ctx.globalAlpha =0.5

also you could do something with when image onload like this

img.onload = function() {
ctx.drawImage(img, pos.x - (img.width / 2),
pos.y - (img.height / 2));
}

Good Luck :P

Op zondag 29 januari 2017 15:23:22 UTC+1 schreef Eoin Irwin:
Reply all
Reply to author
Forward
0 new messages