【发布时间】:2019-09-11 11:40:07
【问题描述】:
我是 D3 和 ReactJS 的新手,我试图用直线剪圆,但不知道它是如何工作的。我有这个 HTML 代码来绘制图像;
<div >
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" className="clip-path" ref={this.attachCircle.bind(this)}>
</svg>
</div>
这是我绘制图像的函数;
attachCircle = (svgRef:SVGElement) => {
const svg = d3.select(svgRef);
// draw a circle
svg.append("circle") // shape it as an ellipse
.attr("cx", 100) // position the x-centre
.attr("cy", 80) // position the y-centre
.attr("r", 80) // set the x radius
.attr("fill", "SteelBlue")
}
结果是这样的;
但只要我将clipPath 添加到圈子;
svg.append("clipPath") // define a clip path
.attr("id", "clip") // give the clipPath an ID
.append("circle") // shape it as an ellipse
.attr("cx", 100) // position the x-centre
.attr("cy", 80) // position the y-centre
.attr("r", 80) // set the x radius
.attr("fill", "SteelBlue")
它在屏幕上什么也不显示。它没有画任何圆圈或任何东西。
谁能解释为什么会这样?或者我错过了什么?
【问题讨论】:
标签: javascript reactjs d3.js