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 doesn't work when loading the graph from a DOT file. #129

Closed
tuschla opened this issue Jan 7, 2022 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@tuschla
Copy link

tuschla commented Jan 7, 2022

I tried using the set_options method as boludo00 demonstrated. This works fine.

However when I read the edges and nodes from a DOT file the options I set afterwards with set_options have no effect.

What you can do to replicate this:

import pyvis
graph = pyvis.network.Network()
graph.from_DOT("./example_dotfile.dot")
graph.set_options("""
var options = {
    "physics": {
        "enabled": false,
        "stabilization": 10,
        "barnesHut": {
            "springLength": 200
        }
    }
}
""")
graph.show("test.html")

Here is an example DOT file for testing:

digraph {
    a [label=12];
    b [label=7];
    c [label=3];
    a -> b[label="solid edge"];                     
    a -> b [label="dashed edge"]; 
    a -> c [label="dashed edge"]; 
    a -> c [label="dotted edge"];      
}

Adding the following to the generated js will work though.

options.physics = {
    enabled: false,
    stabilization: 10,
    barnesHut: {
        springLength: 200
    }
}
@Darkproduct
Copy link
Contributor

Here is the fix:

var options = parsedData.options;
options.nodes = {
shape: "dot"
}

Change those lines to:

var options = parsedData.options;
options = Object.assign(options, {
    nodes: {
        shape: "dot"
    },
});
{% if options %}
options = Object.assign(options, {{options|safe}})
{% endif %}

@tuschla
Copy link
Author

tuschla commented Jan 7, 2022

I can confirm this works! :)

@jhunpingco
Copy link
Contributor

@Darkproduct Can you write a pull request for this change?

@jhunpingco jhunpingco added the enhancement New feature or request label Feb 9, 2022
@Darkproduct
Copy link
Contributor

Yea, I can do that. Should this also include the fix for #128? I mean the version of vis-network this project currently uses is 5? years old.

@jhunpingco
Copy link
Contributor

Please. That makes sense.

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

No branches or pull requests

3 participants