Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network.set_options node color is broken. #289

Open
YouGuessedMyName opened this issue Jun 24, 2024 · 2 comments
Open

Network.set_options node color is broken. #289

YouGuessedMyName opened this issue Jun 24, 2024 · 2 comments

Comments

@YouGuessedMyName
Copy link

YouGuessedMyName commented Jun 24, 2024

To reproduce, run the following (not in a notebook):

from pyvis.network import Network
import networkx as nx

g = Network()

g.from_nx(nx.florentine_families_graph())
#g.show_buttons(filter_=['nodes'])
g.set_options("""
var options = {
    "nodes": {
        "color": {
            "background": "rgba(252,39,99,1)"
        }
    }
}""")

html = g.generate_html("example2.html")
with open("example2.html", mode='w', encoding='utf-8') as fp:
        fp.write(html)

Expected behavior: Florence family graph with purple background nodes.
Actual behavior: Florence family graph with default blue background nodes.

@linusheck
Copy link

I think the reason is that g.from_nx calls g.add_node with no argument for color, which leads to the nodes getting the default argument color="#97c2fc", which overrides anything you set in set_options. I think the library should not behave like this, the default argument for color being "#97c2fc" is dumb.

@YouGuessedMyName
Copy link
Author

Thank you Linus, if anyone else is also facing this issue, you can edit the node colors as expected if you generate a graph using g.add_node(1, color=None). The 'None' makes sure that the default color is not overwritten and VisJs actually applies the layout specified in set_options . The default value of the color argument of add_node should definitely be changed to 'None' in the source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants