例如,如果我想转换yAxis域,我可以这样做
this.yAxis
.transition()
.call(this.createYAxis)
.attr('transform', `translate( ${this.Axes.Y.offset}, 0 )`);
Run Code Online (Sandbox Code Playgroud)
我还想在相同的选择中设置文本大小,但我不想为文本大小设置动画.这可能在同一个链中吗?例如,
this.yAxis
.transition()
.call(this.createYAxis)
.attr('transform', `translate( ${this.Axes.Y.offset}, 0 )`)
//I don't want anything past this point to be a part of the transition
.selectAll('text')
.style('font-size', '15px');
Run Code Online (Sandbox Code Playgroud)
现在我只是使用两个单独的调用
this.yAxis
.transition()
.call(this.createYAxis)
.attr('transform', `translate( ${this.Axes.Y.offset}, 0 )`);
this.yAxis.selectAll( 'text')
.style( 'font-size', '15px' )
Run Code Online (Sandbox Code Playgroud)
作为D3的V4有一个方法transition.selection(),其
返回与此转换对应的选择.
通过这种方法,您可以摆脱之前开始的过渡selection.transition().这使得连续方法链可以作用于选择而不是转换.
var svg = d3.select("svg");
var scale = d3.scalePoint()
.domain(["foo", "bar", "baz"])
.range([30, 270]);
var axis = d3.axisBottom(scale);
var gX = svg.append("g")
.transition()
.duration(1000)
.call(axis)
.attr("transform", "translate(0,50)")
.selection() // <-- get the selection corresponding to the transition
.style("font-size", "26px");Run Code Online (Sandbox Code Playgroud)
<script src="https://d3js.org/d3.v4.js"></script>
<svg></svg>Run Code Online (Sandbox Code Playgroud)