def test_draw_single_node(self): g = networkx.DiGraph() g.add_node('a') container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) self.assertPathsAreCreated(container)
def setUp(self): g = networkx.DiGraph() self.container = GraphContainer(graph=g) self.tool = GraphNodeSelectionTool(component=self.container) self.container.tools.append(self.tool) node = GraphNodeComponent(position=[0, 0]) self.container.components.append(node)
def setUp(self): g = networkx.DiGraph() self.container = GraphContainer(graph=g) self.tool = GraphNodeHoverTool(component=self.container, callback=mock.Mock()) self.container.tools.append(self.tool) self.container.components.append( GraphNodeComponent(position=[0, 0], value='test'))
def test_traited_node(self): event = BasicEvent(x=0, y=0, handled=False) self.container.components.pop(0) node = GraphNodeComponent( value=TraitedNodeValue(label='traited_node'), position=[0, 0]) self.container.components.append(node) self.tool.normal_left_dclick(event) node.value.edit_traits.assert_called_once_with()
def test_draw_not_directed(self): d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': []} g = graph_from_dict(d) g = g.to_undirected() container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) self.assertPathsAreCreated(container)
def create_graph_container(self): """ Utility method to generate a GraphContainer with a simple graph for re-use in several tests herein. """ d = {'a': ['b'], 'b': ['c', 'd'], 'c': [], 'd': []} g = graph_from_dict(d) container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) return container
def test_on_hover_no_callback(self): g = networkx.DiGraph() container = GraphContainer(graph=g) tool = GraphNodeHoverTool(component=container, callback=None) container.tools.append(tool) container.components.append( GraphNodeComponent(position=[0, 0], value='test')) # test in tool._last_xy = (0, 0) tool.on_hover()
def test_weighted(self): g = networkx.Graph() g.add_edge('a', 'b', weight=0.6) g.add_edge('a', 'c', weight=0.2) g.add_edge('c', 'd', weight=0.1) g.add_edge('c', 'e', weight=0.7) g.add_edge('c', 'f', weight=0.9) g.add_edge('a', 'd', weight=0.3) container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) self.assertPathsAreCreated(container)
def _graph_changed(self, new): """ handler for changes to graph attribute """ for component in self._canvas.components: component.container = None self._canvas._components = [] for node in new.nodes(): # creating a component will automatically add it to the canvas GraphNodeComponent(container=self._canvas, value=node) self._canvas.graph = new self._canvas._graph_layout_needed = True self._canvas.request_redraw()
def test_do_layout(self): container = self.create_graph_container() # test spring layout container.style = 'spring' self.assertTrue(container._graph_layout_needed) container.do_layout() self.assert_in_bounds(container) self.assertFalse(container._graph_layout_needed) # test tree layout container = self.create_graph_container() container.style = 'tree' self.assertTrue(container._graph_layout_needed) container.do_layout() self.assert_in_bounds(container) self.assertFalse(container._graph_layout_needed) # test shell layout container = self.create_graph_container() container.style = 'shell' self.assertTrue(container._graph_layout_needed) container.do_layout() self.assert_in_bounds(container) self.assertFalse(container._graph_layout_needed) # test spectral layout container = self.create_graph_container() container.style = 'spectral' self.assertTrue(container._graph_layout_needed) container.do_layout() self.assert_in_bounds(container) self.assertFalse(container._graph_layout_needed) # test circular layout g = networkx.balanced_tree(3, 5) container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) container.style = 'circular' self.assertTrue(container._graph_layout_needed) container.do_layout() self.assert_in_bounds(container) self.assertFalse(container._graph_layout_needed)
def test_draw_directed_arrow_direction(self): d = {'a': ['b'], 'b': []} g = graph_from_dict(d) container = GraphContainer(graph=g) for node in g.nodes(): GraphNodeComponent(container=container, value=node) # Node a is to the left of node b container._layout_needed = False container.components[0].x = 0.0 container.components[1].x = 100.0 container.components[0].y = 0.0 container.components[1].y = 0.0 self.assertPathsAreCreated(container) # Node a is to the right of node b container._layout_needed = False container.components[0].x = 100.0 container.components[1].x = 0.0 container.components[0].y = 0.0 container.components[1].y = 0.0 self.assertPathsAreCreated(container) # Node a is above of node b container._layout_needed = False container.components[0].x = 0.0 container.components[1].x = 0.0 container.components[0].y = 0.0 container.components[1].y = 100.0 self.assertPathsAreCreated(container) # Node a is below of node b container._layout_needed = False container.components[0].x = 0.0 container.components[1].x = 0.0 container.components[0].y = 100.0 container.components[1].y = 0.0 self.assertPathsAreCreated(container)
def setUp(self): self.node = GraphNodeComponent()