Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3 doesn't append namespace attributes to svg element

I wonder why D3.js doesn't add the namespace attributes to the SVG element.

d3.ns.prefix.ex = 'http://example.com/';
var chart = d3.select('#chart').append('svg:svg');

I think the output should something like:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:ex="http://example.com/">

Actually its just

<svg>

See this fiddle for a complete example: http://jsfiddle.net/7kWDK/

like image 285
Slevin Avatar asked Nov 11 '22 05:11

Slevin


1 Answers

namespace attributes are only relevant when documents are served as some XML mime type e.g. image/svg+xml.

namespaces don't do anything in html markup such as jsfiddle so d3 doesn't need to create them.

If you want namespaces then you could add the attributes manually in html or alternatively switch to xhtml where the attributes will be automatically created.

like image 172
Robert Longson Avatar answered Nov 15 '22 07:11

Robert Longson