Unable to select with D3.js in Ch

2019-01-15 20:50发布

Chrome doesn't select <linearGradient> with D3.js. In the following code all selections are empty.

var defs = d3.select("body").append("svg").append("defs");
defs.append("linearGradient");
defs.append("linearGradient");
console.log(defs.selectAll("linearGradient")); // empty
console.log(defs.selectAll("lineargradient")); // empty
console.log(d3.selectAll("linearGradient")); // empty

If you replace <linearGradient> with say <mask> it's all right.

var defs = d3.select("body").append("svg").append("defs");
defs.append("mask");
defs.append("mask");
console.log(defs.selectAll("mask")); // 2 elements selected

Firefox works fine for both. I'm using Chrome 28.0.1500.95. Please suggest a way to select the gradients.

1条回答
Deceive 欺骗
2楼-- · 2019-01-15 21:13

This is a bug in webkit -- see the bug report. The short answer is that for it's just broken. You may be able to work around this by keeping explicit references to the gradients you need to modify, e.g.

var grad1 = defs.append("linearGradient");
查看更多
登录 后发表回答