选择弧/元素 [英] Selecting arc/element

查看:99
本文介绍了选择弧/元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sunburst 中,如何使代码选择根弧,刚产生所有弧之后?

In the sunburst, how can I make code select a root arc, just after all arcs was generated?

例如,在代码中:

var first_arc = ""
.json("../data/flare.json", function(json) {
   var path = vis.data([json]).selectAll("path")
       .data(partition.nodes)
     .enter().append("path")
       .attr("display", function(d) { return d.depth ? null : "none"; })
       .attr("d", arc)
       .attr("t_name", function(d) {return d.name})
       .style("fill-rule", "evenodd")
       .on("click", function(d)...

在单击中间弧时将其作为"d"传递给函数".

it would be passed as "d" to the "function" on click on the middle arc.

(其数据首先在json文件中显示)

(its data goes first in the json file)

更新1 :像这样更改代码…

.style("fill-rule", function(d) {
   if (first_arc == "") first_arc = d; return "evenodd"})

…解决了问题,它返回object:

…solved the problem, it returns object:

name: "flare"
children: Array[10]
...

但是这种解决方案看起来不正确,也不通用.

but this solution doesn't look right and isn't general.

更新2 :我尝试了几种选择,例如:

Update 2: I tried several selects, for example:

first_arc = d3.select("[name='flare']")

通常返回array:

0: null
length: 1
parentNode: HTMLHtmlElement
__proto__: Array[0]

或未定义"

更新3 :

first_arc = d3.select("[t_name='flare']")

返回带有孩子的大小为1的array:

returns array of size 1 with children:

0: SVGPathElement
   __data__: Object

,其中__data__是我要寻找的对象,但我无法选择它.

, where __data__ is the object I'm after, but I can't manage to select it.

推荐答案

根节点是将深度"属性设置为0的根节点.因此,您可以说:

The root node is the one with a "depth" attribute set to 0. So you can say:

d3.selectAll("path").filter(function(d) { return d.depth === 0; })

您的上述尝试无效,因为 D3使用CSS3选择元素.因此,您只能将d3.select和d3.selectAll与 CSS3 选择器一起使用,即可以不能以这种方式访问​​绑定到每个元素的数据.筛选绑定数据的方法是使用 selection.filter .

Your attempts above weren't working because D3 uses CSS3 to select elements. So you can only use d3.select and d3.selectAll with CSS3 selectors i.e. you can't access the data bound to each element this way. The way to filter on the bound data is to use selection.filter.

D3选择实际上是一个元素数组,请参见对选择进行操作"部分.

D3 selections are literally an array of elements, see the "Operating on Selections" section.

最后,您可以使用选择来获取元素的绑定__data__属性.datum().

Lastly, you can get the bound __data__ property for an element using selection.datum().

这篇关于选择弧/元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆