Published
Edited
Aug 14, 2022
Insert cell
Insert cell
Insert cell
wrapper = d3.select("h1").attr("width", 200)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
typeof wrapper
Insert cell
wrapper instanceof d3.selection
Insert cell
(d3.selection.prototype.dattr = dattr)
Insert cell
Insert cell
Insert cell
{
// debugger;
wrapper.dattr("height", 500);
}
Insert cell
Insert cell
function dattr(name, value) {
var fullname = d3.namespace(name);

if (arguments.length < 2) {
var node = this.node();
return fullname.local
? node.getAttributeNS(fullname.space, fullname.local)
: node.getAttribute(fullname);
}

return this.each(
(value == null
? fullname.local
? attrRemoveNS
: attrRemove
: typeof value === "function"
? fullname.local
? attrFunctionNS
: attrFunction
: fullname.local
? attrConstantNS
: attrConstant)(fullname, value)
);
}
Insert cell
function attrRemove(name) {
return function () {
this.removeAttribute(name);
};
}
Insert cell
function attrRemoveNS(fullname) {
return function () {
this.removeAttributeNS(fullname.space, fullname.local);
};
}
Insert cell
function attrConstant(name, value) {
return function () {
this.setAttribute(name, value);
};
}
Insert cell
function attrConstantNS(fullname, value) {
return function () {
this.setAttributeNS(fullname.space, fullname.local, value);
};
}
Insert cell
function attrFunction(name, value) {
return function () {
var v = value.apply(this, arguments);
if (v == null) this.removeAttribute(name);
else this.setAttribute(name, v);
};
}
Insert cell
function attrFunctionNS(fullname, value) {
return function () {
var v = value.apply(this, arguments);
if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
else this.setAttributeNS(fullname.space, fullname.local, v);
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more