Skip to content

Commit b49861d

Browse files
committed
Add compatibility shim for setAttribute[NS] in IE9.
Similar to style.setProperty, IE9 does not always properly coerce attribute values to strings. This causes issues when attempting to set an instance of d3.rgb as an attribute value. Now that d3.interpolate can return d3.rgb instances, this situation can occur more frequently. This compatiblity shim overrides Element.prototype.setAttribute[NS] so that all attribute values are coerced to strings in IE9.
1 parent d3488d6 commit b49861d

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

d3.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ d3 = function() {
99
try {
1010
d3_document.createElement("div").style.setProperty("opacity", 0, "");
1111
} catch (error) {
12-
var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
12+
var d3_element_prototype = d3_window.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
13+
d3_element_prototype.setAttribute = function(name, value) {
14+
d3_element_setAttribute.call(this, name, value + "");
15+
};
16+
d3_element_prototype.setAttributeNS = function(space, local, value) {
17+
d3_element_setAttributeNS.call(this, space, local, value + "");
18+
};
1319
d3_style_prototype.setProperty = function(name, value, priority) {
1420
d3_style_setProperty.call(this, name, value + "", priority);
1521
};

0 commit comments

Comments
 (0)