Skip to content

Commit

Permalink
add node labels to tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
pwrose authored and marimeireles committed Apr 21, 2021
1 parent 77999eb commit 4914f7f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions ipycytoscape/cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,17 @@ def get_node_labels_by_priority(g):
return sorted(counts, key=counts.get)

@staticmethod
def create_tooltip(node_attributes):
def create_tooltip(node_attributes, node_labels):
"""
Returns a string of all node attributes that can be used as a tooltip.
Returns a string of node labels and node attributes to be used as a tooltip.
Parameters
----------
node_attributes : dictionary of node attributes
"""
return "\n".join(k + ":" + str(v) for k, v in node_attributes.items())
labels = ",".join(str(label) in node_labels)
attributes "\n".join(k + ":" + str(v) for k, v in node_attributes.items())
return labels + "\n" + attributes

def add_graph_from_neo4j(self, g):
"""
Expand Down Expand Up @@ -679,7 +681,8 @@ def add_graph_from_neo4j(self, g):

# create tooltip text string
if not "tooltip" in node_attributes:
tooltip_text = self.create_tooltip(node_attributes)
tooltip_text = self.create_tooltip(node_attributes, node.labels)
node_attributes["tooltip"] = tooltip_text

# assign unique id to node
node_attributes["id"] = node.identity
Expand All @@ -692,8 +695,8 @@ def add_graph_from_neo4j(self, g):
node_attributes["label"] = priority_labels[index]

# add tooltip text as an attibute
if not "tooltip" in node_attributes:
node_attributes["tooltip"] = tooltip_text
#if not "tooltip" in node_attributes:
# node_attributes["tooltip"] = tooltip_text

# create node
node_instance = Node()
Expand Down

0 comments on commit 4914f7f

Please sign in to comment.