Inheritance d3元素对父节点数据的引用数据

Inheritance d3元素对父节点数据的引用数据,inheritance,d3.js,data-binding,Inheritance,D3.js,Data Binding,我正在用d3做一个饼图。图的每一部分都有一条内部路径和一条外部路径。这样,当两组路径都需要转换时,它们基于相同的数据集 因此,我的想法是将数据绑定到一组“g”(带有类“.piece”),然后让路径集(“.innerpath”和“.outerpath”)都有指向其父数据集的数据点 我该怎么做 pieces = container.selectAll('.piece') .data(pie(data)) .enter().append('g') .each(function(

我正在用d3做一个饼图。图的每一部分都有一条内部路径和一条外部路径。这样,当两组路径都需要转换时,它们基于相同的数据集

因此,我的想法是将数据绑定到一组“g”(带有类“.piece”),然后让路径集(“.innerpath”和“.outerpath”)都有指向其父数据集的数据点

我该怎么做

pieces = container.selectAll('.piece')
    .data(pie(data))
    .enter().append('g')
    .each(function(d) { this._current = d; }); // store the initial angles

outerPaths = pieces.append('path')
    .data(function(){
    // ??
    }).attr('d', outerArc)
    .attr('class', 'outerpath');
向路径添加组

  var path = svg.datum(data).selectAll("path")
      .data(pie)
    .enter().append("g");
向组中添加带外弧的路径

path.append("path")
  .attr("fill", function(d, i) { return color(i); })
  .classed("outer", true)//add class outer
  .attr("d", arco)
  .each(function(d) { this._current = d; })
向组中添加带内弧的路径

path.append("path")
  .attr("fill", function(d, i) { return color(i + 1); })
  .classed("inner", true)//add class inner
  .attr("d", arci)
  .each(function(d) { this._current = d; })
在两条道路之间切换

function change() {
    var value = this.value;
    clearTimeout(timeout);
    pie.value(function(d) { return d[value]; }); // change the value function
    path = path.data(pie); // compute the new angles
    path.select(".outer").transition().duration(750).attrTween("d", arcTweeno); // redraw the arcs
    path.select(".inner").transition().duration(750).attrTween("d", arcTweeni); // redraw the arcs
  }

工作代码

在这种情况下,不需要数据块来追加路径。这应该可以工作
outerPaths=pieces.append('path').attr('d',outerArc.attr('class','outerpath')我认为问题在于,在路径的弧段上,我使用的是这个。_current(请参阅),它不在路径中。是的,我猜想您可能错过了这一行
。每个(函数(d){this._current=d;});//将初始角度存储在起始角度附加到路径的位置(在您的情况下,它应该是组)。我的.pieces上有这一行。你是说我也应该把它放在我的道路上?我可以把这个价值指向碎片吗。类似于
.each(函数(d){this.\u current=this.parentNode.\u current;})(这会产生一些意想不到的结果)我把它放在一个plunk上,它在一个组中有两条路径。请看一看。希望这就是你想要的。