new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

D3 · all subjects

d3-selection/namespaces

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

d3.namespace function

d3.namespace qualifies a prefixed XML name, such as 'xlink:href'.

d3.namespaces function

d3.namespaces provides the built-in XML namespaces.

namespace() function signature

The namespace(name) function qualifies a specified name which may or may not have a namespace prefix. If the name contains a colon, the substring before the colon is interpreted as the namespace prefix and must be registered in d3.namespaces. The function returns an object with space and local attributes describing the full namespace URL and the local name. If the name does not contain a colon, the function merely returns the input name.

namespace() example with svg:text

d3.namespace("svg:text") returns {space: "http://www.w3.org/2000/svg", local: "text"}

namespaces map initial value

The d3.namespaces object is a map of registered namespace prefixes with the initial value: {svg: "http://www.w3.org/2000/svg", xhtml: "http://www.w3.org/1999/xhtml", xlink: "http://www.w3.org/1999/xlink", xml: "http://www.w3.org/XML/1998/namespace", xmlns: "http://www.w3.org/2000/xmlns/"}

namespaces map is extensible

Additional prefixes may be assigned to the d3.namespaces map as needed to create elements or attributes in other namespaces.

Creating HTML inside SVG with foreignObject

To append an HTML element to a parent in a different namespace, such as creating a div inside an SVG foreignObject element, you must specify the namespace prefix. Example: d3.create("svg").append("foreignObject").attr("width", 300).attr("height", 100).append("xhtml:div").text("Hello, HTML!")

Give your agent this brain