Hi,
I am trying to implement a simple labeled edge renderer for the
springgraph component. The code is very simple, just trying to add a
label in between the source node and destination node, also update the
label's position everytime the nodes are moved. i manage to get the
label to show on screen but i can't get it to move with the end nodes.
I have attached my code below, can anyone help?
(I tried posting through nabble but the messages didnt seem to be
getting to the list, so I am reposting in yahoo, apology for any
duplicate messages)
public class LabelEdgeRenderer implements IEdgeRenderer
{
private var labels:Array = new Array();
public function draw(g:Graphics, f:UIComponent,
t:UIComponent, fromX:int, fromY:int, toX:int, toY:int,
graph:Graph):Boolean
{
var fromItem: Item = (f as IDataRenderer).data
as Item;
var toItem: Item = (t as IDataRenderer).data
as Item;
var linkData: Object =
graph.getLinkData(fromItem, toItem);
var alpha: Number = 1.0;
var thickness: int = 1;
var color;
if((linkData != null) &&
(linkData.hasOwnProperty("settings"))) {
var settings: Object = linkData.settings;
alpha = settings.alpha;
thickness = settings.thickness;
color = settings.color;
}
g.lineStyle(thickness,color,alpha);
g.beginFill(0);
g.moveTo(fromX, fromY);
g.lineTo(toX, toY);
g.endFill();
var label:Label = new Label();
label.text = "an edge label";
//codes for checking duplicate labels is
omitted for brevity
if(!labelExists(label)) {
f.parent.addChild(label);
}
var p:Point = new Point(f.x, f.y);
p = f.parent.globalToLocal(p);
label.label.x = p.x;
label.label.y = p.y;
return true;
}
}