Reputation: 4189
I need to convert the following svg
filter (since I cannot rely on pure css
filter)
<filter id="brightness">
<feComponentTransfer>
<feFuncR type="linear" slope="2"/>
<feFuncG type="linear" slope="2"/>
<feFuncB type="linear" slope="2"/>
</feComponentTransfer>
</filter>
in D3
code. But the code below (JSFiddle here) does not work:
const svg = d3.select("svg")
var filter = svg.append("defs")
.attr("id", "brightness")
.append("feComponentTransfer")
filter.append("feFuncR").attr("type","linear").attr("slope","2");
filter.append("feFuncG").attr("type","linear").attr("slope","2");
filter.append("feFuncB").attr("type","linear").attr("slope","2");
var circle=svg.append("circle")
.attr("cx",100)
.attr("cy",100)
.attr("r",100)
.attr("fill","red")
.style("fill", "url(#brightness)");
Maybe the two last lines conflict. How can I correct?
Upvotes: 0
Views: 676
Reputation: 123985
Once you've fixed all that you'd get this...
const svg = d3.select("svg")
var filter = svg.append("defs")
.append("filter")
.attr("id", "brightness")
.append("feComponentTransfer")
filter.append("feFuncR").attr("type","linear").attr("slope","2");
filter.append("feFuncG").attr("type","linear").attr("slope","2");
filter.append("feFuncB").attr("type","linear").attr("slope","2");
var circle=svg.append("circle")
.attr("cx",100)
.attr("cy",100)
.attr("r",100)
.attr("fill", "red")
.attr("filter", "url(#brightness)");
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<svg></svg>
Upvotes: 4