简体   繁体   English

d3退出过渡:如何展平路径然后删除

[英]d3 exit transition: how to flatten path and then remove

Description : I have a multiple line chart with controls to filter which lines show, so lines are entering and exiting. 描述 :我有一个带有控制权的多折线图,用于过滤显示哪些线,因此线进入和退出。

Desired effect : I want to transition the line to be exactly where the x-axis is (flattening it to a horizontal line the width of the x axis) before it disappears. 所需效果 :我想在线条消失之前将其转变为准确的x轴位置(将其展平为x轴宽度的水平线)。

What I'm trying : 我正在尝试

var moveBottomLeft = `M0,${this.height - margin.bottom}`;
var lineBottomRight = `L${this.width - margin.right},${this.height-margin.bottom}`;

path.exit().transition().duration(DURATION).attr('d', moveBottomLeft+lineBottomRight).remove();

What happens : 会发生什么

  1. All of the line disappears besides the first section. 除第一部分外,所有行均消失。

  2. That small section of line expands to the width of the x axis, and translates down to where it is. 线的那小部分扩展到x轴的宽度,并向下平移到它的位置。

Instead, I would like the whole line to transform (not just that first section). 相反,我希望整行都进行转换(而不仅仅是第一部分)。 How can I achieve this? 我该如何实现?

Figured it out: use d3.svg.line() , but set y to just return the height of the chart. 弄清楚了:使用d3.svg.line() ,但是将y设置为仅返回图表的高度。 (my code looks different, but I think this would be close) (我的代码看起来不同,但是我认为这会很接近)

path.exit().transition().attr('d', function() {
    return d3.svg.line()
        .x(function(d){return d})
        .y(function(d){return chartHeight})(lineData)
})
.remove()

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

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