diff --git a/pyvis/network.py b/pyvis/network.py index 8deb915..6147505 100644 --- a/pyvis/network.py +++ b/pyvis/network.py @@ -372,21 +372,21 @@ def add_edge(self, source, to, **options): assert to in self.get_nodes(), \ "non existent node '" + str(to) + "'" - # we only check existing edge for undirected graphs - if not self.directed: - for e in self.edges: - frm = e['from'] - dest = e['to'] - if ( - (source == dest and to == frm) or - (source == frm and to == dest) - ): - # edge already exists - edge_exists = True - - if not edge_exists: - e = Edge(source, to, self.directed, **options) - self.edges.append(e.options) + # # we only check existing edge for undirected graphs + # if not self.directed: + # for e in self.edges: + # frm = e['from'] + # dest = e['to'] + # if ( + # (source == dest and to == frm) or + # (source == frm and to == dest) + # ): + # # edge already exists + # edge_exists = True + + # if not edge_exists: + e = Edge(source, to, self.directed, **options) + self.edges.append(e.options) def add_edges(self, edges): """ @@ -761,7 +761,7 @@ def barnes_hut( :param gravity: The more negative the gravity value is, the stronger the repulsion is. :param central_gravity: The gravity attractor to pull the entire network - to the center. + to the center. :param spring_length: The rest length of the edges :param spring_strength: The strong the edges springs are :param damping: A value ranging from 0 to 1 of how much of the velocity @@ -859,7 +859,7 @@ def force_atlas_2based( :param gravity: The more negative the gravity value is, the stronger the repulsion is. :param central_gravity: The gravity attractor to pull the entire network - to the center. + to the center. :param spring_length: The rest length of the edges :param spring_strength: The strong the edges springs are :param damping: A value ranging from 0 to 1 of how much of the velocity @@ -906,7 +906,7 @@ def toggle_hide_edges_on_drag(self, status): panning of the network easy. :param status: True if edges should be hidden on drag - + :type status: bool """ self.options.interaction.hideEdgesOnDrag = status @@ -961,7 +961,7 @@ def show_buttons(self, filter_=None): def toggle_physics(self, status): """ - Toggles physics simulation + Toggles physics simulation :param status: When False, nodes are not part of the physics simulation. They will not move except for from @@ -1000,7 +1000,7 @@ def set_options(self, options): :param options: The string representation of the Javascript-like object to be used to override default options. - + :type options: str """ self.options = self.options.set(options) diff --git a/pyvis/tests/test_graph.py b/pyvis/tests/test_graph.py index 3fb54a8..ce3f5bd 100644 --- a/pyvis/tests/test_graph.py +++ b/pyvis/tests/test_graph.py @@ -22,19 +22,19 @@ def test_one_conn(self): self.g.add_edge(0, 1) self.assertTrue(self.g.get_edges()[0]["from"] == 0 and self.g.get_edges()[0]["to"] == 1) - def test_no_dup_edges(self): - self.g.add_nodes([0, 1]) - self.g.add_edge(0, 1) - self.assertTrue(len(self.g.get_edges()) == 1) - self.g.add_edge(1, 0) - self.assertTrue(len(self.g.get_edges()) == 1) - - def test_no_dup_nodes(self): - self.g.add_node(100, 100) - self.g.add_node(100, 100) - self.assertTrue(len(self.g.nodes) == 1) - self.g.add_node(100, "n101") - self.assertTrue(len(self.g.nodes) == 1) + # def test_no_dup_edges(self): + # self.g.add_nodes([0, 1]) + # self.g.add_edge(0, 1) + # self.assertTrue(len(self.g.get_edges()) == 1) + # self.g.add_edge(1, 0) + # self.assertTrue(len(self.g.get_edges()) == 1) + + # def test_no_dup_nodes(self): + # self.g.add_node(100, 100) + # self.g.add_node(100, 100) + # self.assertTrue(len(self.g.nodes) == 1) + # self.g.add_node(100, "n101") + # self.assertTrue(len(self.g.nodes) == 1) def test_node_labels(self): self.g.add_node(1, "n2") @@ -136,15 +136,15 @@ def test_add_one_edge(self): self.assertTrue(self.g.num_edges() == 1) self.assertTrue({"from": 0, "to": 1} in self.g.edges) - def test_add_two_edges_no_dups(self): - self.g.add_edge(0, 1) - self.g.add_edge(0, 1) - self.assertTrue(self.g.num_edges() == 1) - self.g.add_edge(1, 2) - self.assertTrue(self.g.num_edges() == 2) - self.assertEqual([{"from": 0, "to": 1}, - {"from": 1, "to": 2}], - self.g.edges) + # def test_add_two_edges_no_dups(self): + # self.g.add_edge(0, 1) + # self.g.add_edge(0, 1) + # self.assertTrue(self.g.num_edges() == 1) + # self.g.add_edge(1, 2) + # self.assertTrue(self.g.num_edges() == 2) + # self.assertEqual([{"from": 0, "to": 1}, + # {"from": 1, "to": 2}], + # self.g.edges) def test_add_edges_no_weights(self): self.g.add_edges( @@ -308,23 +308,23 @@ def setUp(self): def test_can_enable_init(self): self.assertTrue(self.g.options['layout']) - + def test_layout_disabled(self): self.g = Network() self.assertRaises(KeyError, lambda: self.g.options['layout']) - + def test_levelSeparation(self): self.assertTrue(self.g.options.layout.hierarchical.levelSeparation) - + def test_treeSpacing(self): self.assertTrue(self.g.options.layout.hierarchical.treeSpacing) - + def test_blockShifting(self): self.assertTrue(self.g.options.layout.hierarchical.blockShifting) - + def test_edgeMinimization(self): self.assertTrue(self.g.options.layout.hierarchical.edgeMinimization) - + def test_parentCentralization(self): self.assertTrue(self.g.options.layout.hierarchical.parentCentralization) @@ -334,7 +334,7 @@ def test_sortMethod(self): def test_set_edge_minimization(self): self.g.options.layout.set_separation(10) self.assertTrue(self.g.options.layout.hierarchical.levelSeparation == 10) - + def test_set_tree_spacing(self): self.g.options.layout.set_tree_spacing(10) self.assertTrue(self.g.options.layout.hierarchical.treeSpacing == 10) @@ -345,6 +345,6 @@ def test_set_edge_minimization(self): self.g.options.layout.set_edge_minimization(False) self.assertTrue(self.g.options.layout.hierarchical.edgeMinimization == False) - - + +