【发布时间】:2017-01-25 15:03:20
【问题描述】:
我正在尝试创建一个函数,该函数将作为重复绘制线条并将它们淡出的基础。我大致受到彼得库克的风图的启发,他在这里讨论:http://prcweb.co.uk/making-the-uk-wind-chart/。我正在尝试重新创建他的测试线。
我可以让测试线工作——但前提是它们向左绘制或摆动,即当原始 x2 大于它们过渡到的新 x2 时。下面的代码按我预期的方式工作。但是,如果我将它正在绘制的 x2 更改为(标有注释“ISSUE IS HERE”)大于 500,它将不会绘制。我很困惑。为什么它会在意它画的方向?
<!DOCTYPE html>
<html>
<head>
<title>TITLE GOES HERE</title>
</head>
<body>
<svg></svg>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
function lineAnimate(selection) {
selection
.attr('x1', 500)
.attr('x2', 500)
.attr("stroke-width", 2)
.attr("stroke", "black")
.attr('y1', function(d) {return d;})
.attr('y2', function(d) {return d;})
.style('opacity', 0.5)
.transition()
.ease('linear')
.duration(1000)
// .delay(function(d) {return d*10;})
.attr('x2', 200) // ISSUE IS HERE
.transition()
.delay(1000)
.duration(1000)
.style('opacity', 0)
.each('end', function() {d3.select(this).call(lineAnimate)})
console.log("done");
}
var svg = d3.select('svg')
.selectAll('line')
.data([5, 10, 15, 20, 25])
.enter()
.append('line')
.call(lineAnimate);
console.log(svg.size());
</script>
</body>
</html>
【问题讨论】:
标签: javascript d3.js transition