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

Directed Edges not working with CustomNode #270

Closed
AlexejPenner opened this issue Jul 23, 2021 · 2 comments
Closed

Directed Edges not working with CustomNode #270

AlexejPenner opened this issue Jul 23, 2021 · 2 comments

Comments

@AlexejPenner
Copy link

AlexejPenner commented Jul 23, 2021

Bug report

Extending the code for https://ipycytoscape.readthedocs.io/en/latest/examples/networkx.html#Custom-networkx-Node-Objects-that-inherit-from-ipycytoscape.Node by adding the directed=True flag does not add the arrow to the resulting visualized graph.

import ipycytoscape
import networkx as nx

class CustomNode(ipycytoscape.Node):
    def __init__(self, name, classes=''):
        super().__init__()
        self.data['id'] = name
        self.classes = classes

n1 = CustomNode("node 1", classes='class1')
n2 = CustomNode("node 2", classes='class2')
        
G = nx.MultiDiGraph()

G.add_node(n1)
G.add_node(n2)

G.add_edge(n1, n2)

custom_inherited = ipycytoscape.CytoscapeWidget()
custom_inherited.graph.add_graph_from_networkx(G, directed=True)
custom_inherited.set_style([
                        {
                            'selector': 'node.class1',
                            'css': {
                                'background-color': 'green'
                            }
                        },
                        {
                            'selector': 'node.class2',
                            'css': {
                                'background-color': 'red'
                            }
                        }])
custom_inherited

Actual outcome

image

Expected outcome

image

Version Info

  • ipycytoscape version : 1.2.2
  • Python version: 3.8
  • jupyter core version: 4.7.1
@marimeireles
Copy link
Collaborator

Hey @AlexejPenner thank you for opening this issue. I'll move the discussion to #56. I'm having a look on it, but not sure how much time I can spend on it.
Contributions are welcome and I'm around if you or anyone else have questions!
Thanks for opening the issue. I really dislike this bug and want to fix it =)

@AlexejPenner
Copy link
Author

AlexejPenner commented Jul 27, 2021

Thanks @marimeireles - in the meantime for anyone else running into this it seems pretty easy to get the arrow behavior by explicitly defining it like in #56

import ipycytoscape
import networkx as nx

class CustomNode(ipycytoscape.Node):
    def __init__(self, name, classes=''):
        super().__init__()
        self.data['id'] = name
        self.classes = classes

n1 = CustomNode("node 1", classes='class1')
n2 = CustomNode("node 2", classes='class2')
        
G = nx.MultiDiGraph()

G.add_node(n1)
G.add_node(n2)

G.add_edge(n1, n2)

custom_inherited = ipycytoscape.CytoscapeWidget()
custom_inherited.graph.add_graph_from_networkx(G, directed=True)
custom_inherited.set_style([
                        {
                            'selector': 'node.class1',
                            'css': {
                                'background-color': 'green'
                            }
                        },
                        {
                            'selector': 'node.class2',
                            'css': {
                                'background-color': 'red'
                            }
                        },{
                            "selector": "edge.directed",
                            "style": {
                                "curve-style": "bezier",
                                "target-arrow-shape": "triangle"
                            }
                        }])
custom_inherited

Screenshot from 2021-07-27 09-48-50

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