anvaka / VivaGraphJS

Graph drawing library for JavaScript
Other
3.76k stars 425 forks source link

Cannot set attribute xlink:href #66

Closed atima closed 10 years ago

atima commented 10 years ago

I try to add text to path with textPath, which requires xlink:href attribute. However, the code seem to be corrupted. This happens whenever I set xlink:href.

For example, svgText = Viva.Graph.svg('text').attr('y', '-4px').attr('xlink:href', 'www.google.com').text(node.id),

will render nothing.

Any Idea?

anvaka commented 10 years ago

Do you have a jsfiddle/plunkr demo to see the whole thing?

atima commented 10 years ago

http://jsfiddle.net/atima/yc3tB/1/

line 42-46. After I added xlink:href (line 44), the links are gone.

anvaka commented 10 years ago

Oh, I see. There is an exception on that page. If you want to use xlink namespaces do

label.setAttributeNS("http://www.w3.org/1999/xlink", "href", '#' + link.data.id);

More details about this are described here: http://www.w3.org/Graphics/SVG/WG/wiki/Href . This example does not fail, however, if you are trying to make text follow a path, you'll need to declare those paths in the defs section (per SVG spec).

Alternatively you can try to use text transforms and update them in each placeLink() call.

PS: Working with plain SVG is painful sometimes. You might want to find a library which provides higher level abstractions on top of it. VivaGraph does not care what creates SVGElement, as long as you return it from svggraphic's node() method.

atima commented 10 years ago

Thanks for your help. I use text transforms as the suggestion.

Here is the example code for someone who may interest in link label creation: http://jsfiddle.net/atima/yc3tB/7/

karthim commented 9 years ago

Hi,

Thanks for example code showing how to add edge label. When you remove the link using graph.removeLink method, the label is not getting removed. It stays in the graph. Do you have any suggestion on how to link the label with the edge so that when we remove the edge the label also gets removed.

Regards, Karthic

VladBrok commented 1 year ago

Thanks for your help. I use text transforms as the suggestion.

Here is the example code for someone who may interest in link label creation: http://jsfiddle.net/atima/yc3tB/7/

@atima thank you