简体   繁体   English

d3-画笔范围所需的帮助()

[英]d3 - required help in brush extent()

Here's the fiddle . 这是小提琴

When I use the brush, the colored areas start off beyond the x axis defined. 当我使用画笔时,彩色区域开始于定义的x轴之外。

For the line in the graph, I got a suggestion in this SO to add clip-path: url(#clip) to the line css. 对于图中的线,我在此SO中提出了一条建议clip-path: url(#clip)到css线中。 It works. 有用。 After applying that, the line starts exactly from the 0 of x when using the brush. 应用后,使用画笔时该行从x的0开始精确地开始。

But when I apply the same logic to the css of the .area.above and .area.below , it doesn't work. 但是,当我对.area.above.area.below的CSS应用相同的逻辑时,它不起作用。

The areas are clipped correctly but only one is actually displayed...from inspecting the elements in the browser developer tools, one of the areas is apparently overlaying the other. 正确裁剪了这些区域,但是实际上只显示了一个区域...通过检查浏览器开发人员工具中的元素,一个区域显然覆盖了另一个区域。

Some one help me where I'm making the mistake? 有人帮我弄错了吗?

Thanks in advance. 提前致谢。

Here's a fiddle which I think does what you want: http://jsfiddle.net/henbox/jzPaq/ 这是我认为可以满足您需要的小提琴: http : //jsfiddle.net/henbox/jzPaq/

The problem was that you can only have one clip-path defined for an element. 问题是您只能为一个元素定义一个clip-path So adding the rectangular clipPath: 因此,添加矩形clipPath:

...append("clipPath")
    .attr("id", "clip")
    .append("rect")
        .attr("width", width)
        .attr("height", height);

was over-writing the clip-below and clip-above ones (in <path class="area below"...> and <path class="area above"...> respectively. 正在覆盖clip-below clip-aboveclip-above (分别位于<path class="area below"...><path class="area above"...>

The solution I used was based on this info: http://apike.ca/prog_svg_clip.html 我使用的解决方案基于以下信息: http : //apike.ca/prog_svg_clip.html

For the 'below' I used the intersection of the rectangular (#clip) and 'below' clip paths, like this: 对于“下方”,我使用了矩形(#clip)和“下方”剪辑路径的交集,如下所示:

Give the path element an id (clipbelowshape): 给path元素指定一个id (clipbelowshape):

focus.append("clipPath")
    .attr("id", "clip-below")
    .append("path")
        .attr("id", "clipbelowshape")
        .attr("d", area.y0(height));

Create the intersect of clip clipPath with clipbelowshape : 使用clipbelowshape 创建 clip clipPath 的相交

var clipbelowintersect = focus.append("clipPath")
    .attr("id", "clipbelowintersect")
    .attr("clip-path", "url(#clip)");

clipbelowintersect.append("use")
    .attr("xlink:href", "#clipbelowshape");

Use the new intersect clip path 使用新的相交剪辑路径

focus.append("path")
    .attr("class", "area below")
    .attr("clip-path", "url(#clipbelowintersect)")
    .attr("d", area);

Do the same thing with the above path 用上面的路径做同样的事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM