Skip to content

Commit

Permalink
Merge pull request #2 from WestHealth/feature/add-node-font-color
Browse files Browse the repository at this point in the history
Feature/add node font color
  • Loading branch information
boludo00 committed May 14, 2018
2 parents 06950ad + bb09e48 commit a81ca8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
14 changes: 11 additions & 3 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ class Network(object):
:type directed: bool
"""

def __init__(self, height="500px", width="500px", directed=False, notebook=False, bgcolor="#ffffff"):
def __init__(self,
height="500px",
width="500px",
directed=False,
notebook=False,
bgcolor="#ffffff",
font_color=False):
self.nodes = []
self.edges = []
self.height = height
self.width = width
self.html = ""
self.shape = "dot"
self.shape = "dot"
self.font_color = font_color
self.directed = directed
self.bgcolor = bgcolor
self.use_DOT = False
Expand All @@ -49,6 +56,7 @@ def __init__(self, height="500px", width="500px", directed=False, notebook=False

if notebook:
self.prep_notebook()


def __str__(self):
"""
Expand Down Expand Up @@ -185,7 +193,7 @@ def add_node(self, n_id, label=None, shape="dot", **options):
else:
node_label = n_id
if n_id not in self.node_ids:
n = Node(n_id, shape, label=node_label, **options)
n = Node(n_id, shape, label=node_label, font_color=self.font_color, **options)
self.nodes.append(n.options)
self.node_ids.append(n_id)

Expand Down
4 changes: 3 additions & 1 deletion pyvis/node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Node(object):

def __init__(self, n_id, shape, label, **opts):
def __init__(self, n_id, shape, label, font_color=False, **opts):
self.options = opts
self.options["id"] = n_id
self.options["label"] = label
self.options["shape"] = shape
if font_color:
self.options["font"] = dict(color=font_color)
12 changes: 6 additions & 6 deletions pyvis/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,19 @@ def setUp(self):
self.g.add_nodes([0, 1, 2, 3])

def test_toggle_drag_nodes(self):
self.assertTrue(self.g.options.interaction['drag_nodes'])
self.assertTrue(self.g.options.interaction['dragNodes'])
self.g.toggle_drag_nodes(False)
self.assertFalse(self.g.options.interaction['drag_nodes'])
self.assertFalse(self.g.options.interaction['dragNodes'])

def test_toggle_hide_edges_on_drag(self):
self.assertFalse(self.g.options.interaction['hide_edges_on_drag'])
self.assertFalse(self.g.options.interaction['hideEdgesOnDrag'])
self.g.toggle_hide_edges_on_drag(True)
self.assertTrue(self.g.options.interaction['hide_edges_on_drag'])
self.assertTrue(self.g.options.interaction['hideEdgesOnDrag'])

def test_toggle_hide_nodes_on_drag(self):
self.assertFalse(self.g.options.interaction['hide_nodes_on_drag'])
self.assertFalse(self.g.options.interaction['hideNodesOnDrag'])
self.g.toggle_hide_nodes_on_drag(True)
self.assertTrue(self.g.options.interaction['hide_nodes_on_drag'])
self.assertTrue(self.g.options.interaction['hideNodesOnDrag'])


class ConfigureTestCase(unittest.TestCase):
Expand Down

0 comments on commit a81ca8e

Please sign in to comment.