d3 v4 api interpolate

方法说明
d3.interpolateinterpolate arbitrary values.
d3.interpolateArrayinterpolate arrays of arbitrary values.
d3.interpolateDateinterpolate dates.
d3.interpolateNumberinterpolate numbers.
d3.interpolateObjectinterpolate arbitrary objects.
d3.interpolateRoundinterpolate integers.
d3.interpolateStringinterpolate strings with embedded numbers.
d3.interpolateTransformCssinterpolate 2D CSS transforms.
d3.interpolateTransformSvginterpolate 2D SVG transforms.
d3.interpolateZoomzoom and pan between two views.
d3.interpolateRgbinterpolate RGB colors.
d3.interpolateRgbBasisgenerate a B spline through a set of colors.
d3.interpolateRgbBasisClosedgenerate a closed B spline through a set of colors.
d3.interpolateHslinterpolate HSL colors.
d3.interpolateHslLonginterpolate HSL colors, the long way.
d3.interpolateLabinterpolate Lab colors.
d3.interpolateHclinterpolate HCL colors.
d3.interpolateHclLonginterpolate HCL colors, the long way.
d3.interpolateCubehelixinterpolate Cubehelix colors.
d3.interpolateCubehelixLonginterpolate Cubehelix colors, the long way.
interpolate.gammaapply gamma correction during interpolation.
d3.interpolateBasisgenerate a B spline through a set of values.
d3.interpolateBasisClosedgenerate a closed B spline through a set of values.
d3.piecewisegenerate a piecewise linear interpolator from a set of values.
d3.quantizegenerate uniformly spaced samples from an interpolator.

var i = d3.interpolateRound(100, 200);
//插值可以理解为将(0,1)映射到(100,200)
i(0.1)
110
i(0.11)
111
i(0.111)
111

插值算法的一个bug

tween中的m输出都是2,所以不能在循环中使用

for (var m of [1,2]){
	 textRects = textRects.transition()
	         .attr('x', (d)=>padding.left + linear(d['values'][m]['GDP']))
	         .attr('y', (d)=>padding.top + (d['values'][m]['rank']-1)*rectHG+0.5*rectHeight)
	         .duration(duration)
	         .tween("text",function(d,tw){
	             console.log(m)
	                 var tw = d3.interpolateRound(d['values'][m-1]['GDP'],d['values'][m]['GDP'])
	                 return function(t){this.textContent = tw(t)}
	             })
}

循环异步
https://www.cnblogs.com/xiujun/p/10637037.html
https://observablehq.com/@d3/bar-chart-race

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值