Endpoint label

329 views
Skip to first unread message

Mac

unread,
Mar 1, 2012, 10:12:07 AM3/1/12
to jsPlumb
Hi!

How I could get the label of an endpoint? I'm trying to bind the
endpointClick event like this:

jsPlumb.bind("endpointClick", function(endpoint, originalEvent) {

var label = endpoint.getOverlay("Label");
alert(label);

});


jsPlumb.bind("endpointClick", function(endpoint, originalEvent) {

var label = endpoint.getLabel();
alert(label);

});

but neither of them are working.. could you give me some help?

thanks in advance!

Simon Porritt

unread,
Mar 1, 2012, 3:00:06 PM3/1/12
to jsp...@googlegroups.com
getOverlay takes an overlay id as argument, so you have to have
configured the endpoint with an id, something like:

var ep = jsPlumb.addEndpoint("el", {
overlays:[ ["Label", {label:"FOO", id:"labelId" } ]]
});

then you can retrieve it with

var overlay = ep.getOverlay("labelId");

Remember that getOverlay returns the Overlay object and not the text
of the label; you would need to do this to get the text:

overlay.getLabel();

The getLabel method works only if you used the "label" parameter on
the Endpoint:

var ep = jsPlumb.addEndpoint("el", {
label:"FOO"
});

console.log(ep.getLabel()); // prints "FOO"

This mechanism is just a shortcut mechanism because label overlays are
quite common. Behind the scenes it's treated the same way as any
other overlay - jsPlumb uses this id:

var _internalLabelOverlayId = "__label";

...meaning you can of course retrieve a label set with the "label"
parameter like this:

endpoint.getOverlay("__label");

if you really wanted to. for some reason.

Mac

unread,
Mar 2, 2012, 4:43:29 AM3/2/12
to jsPlumb
Thank you so much Simon! it works perfectly :)

Mac

unread,
Mar 2, 2012, 5:35:47 AM3/2/12
to jsPlumb
Hi!

I have another question about this... sorry but I couldn't find it in
the documentation.. :(

I also want to get the label of the endpoint but when the connection
is clicked..

I'm doing this:

jsPlumb.bind("dblclick", function(connection, originalEvent) {

var label = connection.sourceEndpoint.getOverlay("label");
alert(label.getLabel());

});


jsPlumb.bind("dblclick", function(connection, originalEvent) {

var label = connection.source.getOverlay("label");
alert(label.getLabel());

});

but neither of them are working.. where is the mistake?

thank you so much for your help..

Simon Porritt

unread,
Mar 2, 2012, 7:16:02 PM3/2/12
to jsp...@googlegroups.com

Connection has an 'endpoints' array.

connection.endpoints[0] - source
connection.endpoints[1] - target

I really should document this. I will do that for the 1.3.7 release.

Mac

unread,
Mar 5, 2012, 3:14:10 AM3/5/12
to jsPlumb
Thank you so much Simon!

On Mar 3, 1:16 am, Simon Porritt <simon.porr...@gmail.com> wrote:
> Connection has an 'endpoints' array.
>
> connection.endpoints[0] - source
> connection.endpoints[1] - target
>
> I really should document this. I will do that for the 1.3.7 release.
>
Reply all
Reply to author
Forward
0 new messages