Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可否用d3中的.html()去直接写一个defs之类的 #84

Open
ckinmind opened this issue May 28, 2018 · 0 comments
Open

可否用d3中的.html()去直接写一个defs之类的 #84

ckinmind opened this issue May 28, 2018 · 0 comments
Labels

Comments

@ckinmind
Copy link
Owner

ckinmind commented May 28, 2018

经过测试可以

const defs = svgElems.append("defs")
const filter = defs.append("filter")
      .attr("id", "drop-shadow")
      .attr("height", "130%")



    filter.append("feGaussianBlur")
      .attr("in", "SourceAlpha")
      .attr("stdDeviation", 4)
      .attr("result", "blur")
    filter.append("feOffset")
      .attr("in", "blur")
      .attr("dx", 2)
      .attr("dy", 2)
      .attr("result", "offsetBlur")
    filter.append("feFlood")
      .attr("in", "offsetBlur")
      .attr("flood-color", "#3d3d3d")
      .attr("flood-opacity", "0.5")
      .attr("result", "offsetColor")
    filter.append("feComposite")
      .attr("in", "offsetColor")
      .attr("in2", "offsetBlur")
      .attr("operator", "in")
      .attr("result", "offsetBlur")

    const feMerge = filter.append("feMerge")

    feMerge.append("feMergeNode")
      .attr("in", "offsetBlur")
    feMerge.append("feMergeNode")
      .attr("in", "SourceGraphic")

/******   以上这段代码可以写成   ****** /

svgElems.append('defs')
      .html(`<filter id="drop-shadow">
<feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"></feGaussianBlur>
<feOffset in="blur" dx="2" dy="2" result="offsetBlur"></feOffset><feFlood in="offsetBlur" flood-color="#3d3d3d" flood-opacity="0.5" result="offsetColor"></feFlood>
<feComposite in="offsetColor" in2="offsetBlur" operator="in" result="offsetBlur"></feComposite><feMerge><feMergeNode in="offsetBlur"></feMergeNode><feMergeNode in="SourceGraphic"></feMergeNode></feMerge></filter>`)

经过测试这两种方式等价,但是明显下面这种方式看起来方便很多

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant