Edge label doesn't disappear after disappearance of edges.

206 views
Skip to first unread message

Socratees Samipillai

unread,
Dec 20, 2010, 5:17:12 PM12/20/10
to javascript-information...@googlegroups.com
I've got a quick question.

I successfully customized edges in a Space Tree by implementing my own EdgeType, and then created a label which had an image on it, then positioned the label in such  a way that it is located exactly on top of the node. At this point, I'm running in to couple of issues.
  1. The position of the edge label remains static so it does not move around along with the edge when the user does so. How do I dynamically update the position of the edge label when the tree is dragged?
  2. When the node and the edge that is associated with the label disappears, the associated edge label does not disappear. How can i remove the label?
Thanks everybody.
Socratees.
original position.png
position after user drag.png
unattached labels 1.png

Federico Giacanelli

unread,
Apr 22, 2011, 5:02:54 AM4/22/11
to javascript-information...@googlegroups.com
I need to create edges with labels... please can you post your code?

Thanks,
Fed


On Mon, Dec 20, 2010 at 11:17 PM, Socratees Samipillai <ss6...@gmail.com> wrote:
I've got a quick question.

I successfully customized edges in a Space Tree by implementing my own EdgeType, and then created a label which had an image on it, then positioned the label in such  a way that it is located exactly on top of the node. At this point, I'm running in to couple of issues.

Socratees

unread,
Apr 22, 2011, 2:28:33 PM4/22/11
to javascript-information...@googlegroups.com
I did that a while back and haven't worked on it long since. Anyways, here's the code.

	$jit.ST.Plot.EdgeTypes.implement({  
		'mySpecialType': {  
			'render': function(adj, canvas) {				
				
				var data = adj.data;
				
				/*
				if(data.labelid) {
					var label = document.getElementById(data.labelid);
					var labelcontainer = this.labels.getLabelContainer();
					if(label && labelcontainer) {
						alert(label.parentNode.id);
						labelcontainer.removeChild(label);
					}
				}
				*/
				
				if(data.labelid) {
				
					var domlabel = document.getElementById(data.labelid);
					
					if(!domlabel) {
						domlabel= document.createElement('span');							
						domlabel.id = data.labelid;
						domlabel.innerHTML = "<img src='http://dl.dropbox.com/u/358218/static/spacetree/icons/favourite.gif'/>";					
						var style = domlabel.style;
						style.position = 'absolute';
						style.display = 'block';
					}
					
					var pos = adj.nodeFrom.pos.getc(true);
					var posChild = adj.nodeTo.pos.getc(true);
					var radius = this.viz.canvas.getSize();
					
					domlabel.style.left = parseInt((pos.x + posChild.x + radius.width - domlabel.offsetWidth) /2) + 'px';
					domlabel.style.top = parseInt((pos.y + posChild.y + radius.height) /2) + 'px';
					domlabel.style.display = 'block';
					
					this.labels.getLabelContainer().appendChild(domlabel);
				}
				this.edgeTypes.bezier.render.call(this, adj, canvas);
			},
			'contains': function(adj, pos) {
				return false;
			}
		}
	});
Thanks,
Socratees.

Rampy

unread,
May 25, 2012, 8:30:51 AM5/25/12
to javascript-information...@googlegroups.com
Hi

I am using SpaceTree and i want to write some percentages on edges but I did not manage to do it.
I tried your code, but nothing appears on edges.

I do not have the variable data.labelid, it is always undefined. Where i have to define this variable?

Can you help me ?

jjon

unread,
May 27, 2012, 12:55:07 PM5/27/12
to JavaScript InfoVis Toolkit
Rampy,

If I understand Socratees' code correctly, the data.labelid value is
coming from his json input. If your data has something like this
shape:

{
  "id": "300014898",
  "name": "string serving as label for node",
  "data": {
    "labelid": "eggs",
    "some_data": "ham",
    "more_data": "spam",
  },
  "children": []
}

then in your init() function you can access anything defined in the
"data" property like this: data.labelid, or data.some_data

On May 25, 5:30 am, Rampy <julien.rampelb...@gmail.com> wrote:
> Hi
>
> I am using SpaceTree and i want to write some percentages on edges but
> I did not manage to do it.
> I tried your code, but nothing appears on edges.
>
> I do not have the variable data.labelid, it is always undefined. Where i
> have to define this variable?
>
> Can you help me ?

Reply all
Reply to author
Forward
Message has been deleted
0 new messages