Zsailer / nx_altair

Draw interactive NetworkX graphs with Altair
MIT License
223 stars 26 forks source link

Setting node size #12

Closed GiulioRossetti closed 4 years ago

GiulioRossetti commented 5 years ago

Hi, I'm trying, without success, to assign a specific size to each node.

If I get it right this should be possible by linking the node_size property to a node attribute. Unfortunately, the result is a graph with all nodes represented as dots (size=1 i guess).

What am I doing wrong?

Here's my code:

for n in g.nodes():
    g.nodes[n]['name'] = n
    w = randint(300, 1000)
    g.nodes[n]['size'] = w
    print(w)

pos = nx.spring_layout(g)

viz = nxa.draw_networkx(
    g, 
    pos=pos,
    node_color='#ff0000',
    width='weight',
    edge_color='black',
    node_label='name',
    node_size='size'
)

viz.interactive()
Zsailer commented 5 years ago

@GiulioRossetti, you're right! This should work. I'll let you know when I have this fixed.

Zsailer commented 5 years ago

@GiulioRossetti I'm still investigating this issue.

Here's what I've come up with so far... It looks like the problem might be upstream (in Altair or Vega). Trying to style the nodes and edges leads to this issue. If you plot the individual layers of the Altair chart, the styling is correct. I've investigated the Vega spec as well, and everything looks fine, but the rendering is incorrect. I'll dive into Altair+Vega further and see what I can find. I'll update you once I find the problem.

GiulioRossetti commented 5 years ago

@Zsailer thanks again for your work! I'll wait for updates then.

Zsailer commented 4 years ago

Sorry for not returning to this issue sooner, @GiulioRossetti. This seems to be working for me. If you're still having issues, feel free to reopen this issue. Thanks!