简体   繁体   中英

node attributes in D3

https://github.com/mbostock/d3/wiki/Force-Layout#wiki-nodes

That mentions the following attributes for nodes: index, x, y, px, py, fixed and weight

http://bl.ocks.org/mbostock/4062045

That example uses two node attributes that the above URL doesn't mention: name and group.

Is this an error in the part of the documentation (ie. link 1) or the example (ie. link 2) doing something extra to make those work that I'm just not understanding?

Thanks!

The attributes the first link mentions are the ones that the force layout uses to run the simulation. In addition to those, you can use any other attributes to store additional information -- such as in the second link. The difference is that the ones that the documentation mentions have meaning for the force layout in general, whereas the ones that the second one is adding are specific to this one.

In any visualisation, you'll have additional attributes that contain information like node labels, colors etc. You are free to use whatever (unused) names you like for those.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM