命名空间
🌐 Namespaces
XML 命名空间很有趣!对吧?🤪 幸好你大多数情况下可以忽略它们。
🌐 XML namespaces are fun! Right? 🤪 Fortunately you can mostly ignore them.
你需要指定它们的一种情况是,当将一个元素附加到属于不同命名空间的父元素时;通常是在 SVG foreignObject 元素内创建一个 div:
🌐 A case where you need to specify them is when appending an element to a parent that belongs to a different namespace; typically, to create a div inside a SVG foreignObject element:
d3.create("svg")
.append("foreignObject")
.attr("width", 300)
.attr("height", 100)
.append("xhtml:div")
.text("Hello, HTML!");命名空间(name)
🌐 namespace(name)
来源 · 限定指定的名称,该名称可能有也可能没有命名空间前缀。
d3.namespace("svg:text") // {space: "http://www.w3.org/2000/svg", local: "text"}如果名称包含冒号(:),冒号前的子字符串将被解释为命名空间前缀,该前缀必须已在 d3.namespaces 中注册。返回一个对象,其中 space 和 local 属性描述完整的命名空间 URL 和局部名称。如果名称不包含冒号,此函数仅返回输入名称。
🌐 If the name contains a colon (:), the substring before the colon is interpreted as the namespace prefix, which must be registered in d3.namespaces. Returns an object space and local attributes describing the full namespace URL and the local name. If the name does not contain a colon, this function merely returns the input name.
namespaces
来源 · 已注册命名空间前缀的地图。初始值为:
{
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/"
}可以根据需要分配其他前缀,以便在其他命名空间中创建元素或属性。
🌐 Additional prefixes may be assigned as needed to create elements or attributes in other namespaces.