I am trying to convert the following example to be d3 v4 patible
I have been able to convert almost all of it, but I am having trouble with the following function:
this.el.transition().delay(100).duration(200).select('.needle').tween('reset-progress', function() {
return function(percentOfPercent) {
var progress = (1 - percentOfPercent) * oldValue;
repaintGauge(progress);
return d3.select(this).attr('d', recalcPointerPos.call(self, progress));
};
});
The error I'm getting is this.setAttribute is not a function
on the line with the return. I've verified that recalcPointerPos
is working correctly, so I think the issue is with the d3.select(this).attr syntax. Did something change for this type of selection between v3 and v4?
fiddle: /
I am trying to convert the following example to be d3 v4 patible http://bl.ocks/ameyms/9184728
I have been able to convert almost all of it, but I am having trouble with the following function:
this.el.transition().delay(100).duration(200).select('.needle').tween('reset-progress', function() {
return function(percentOfPercent) {
var progress = (1 - percentOfPercent) * oldValue;
repaintGauge(progress);
return d3.select(this).attr('d', recalcPointerPos.call(self, progress));
};
});
The error I'm getting is this.setAttribute is not a function
on the line with the return. I've verified that recalcPointerPos
is working correctly, so I think the issue is with the d3.select(this).attr syntax. Did something change for this type of selection between v3 and v4?
fiddle: https://jsfiddle/v1tok1k6/
Share Improve this question asked Feb 24, 2017 at 7:28 mattgabormattgabor 2,0846 gold badges26 silver badges38 bronze badges1 Answer
Reset to default 5The inner return select has the wrong this
scope for selecting the element. What you want is the outer functions this
, which represents the path
element. I'd do the select on the outer scope for caching.
this.el.transition().delay(300).duration(1500).select('.needle').tween('progress', function(d, i, e) {
var needle = d3.select(this);
return function(percentOfPercent) {
var progress = percentOfPercent * perc;
repaintGauge(progress);
return needle.attr('d', recalcPointerPos.call(self, progress));
};
});
updated fiddle
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744310670a4567930.html
评论列表(0条)