diff --git a/d3graph/d3graph.py b/d3graph/d3graph.py index f01e810..61453af 100644 --- a/d3graph/d3graph.py +++ b/d3graph/d3graph.py @@ -823,10 +823,10 @@ def set_path(self, filepath=None) -> str: dirname = os.path.join(gettempdir(), 'd3graph') else: dirname, filename = os.path.split(filepath) - + if filename in (None, ''): filename = 'd3graph.html' - + if dirname in (None, ''): dirname = os.path.join(gettempdir(), 'd3graph') @@ -1009,6 +1009,7 @@ def json_create(G: nx.Graph) -> str: links[i]['label'] = links[i]['label'] links[i]['label_color'] = links[i]['label_color'] links[i]['label_fontsize'] = links[i]['label_fontsize'] + links[i]['tooltip'] = links[i]['tooltip'] links_new.append(links[i]) # Set node properties @@ -1125,6 +1126,7 @@ def adjmat2dict(adjmat: pd.DataFrame, 'label': Text label for the edge. 'label_color': color of the label. 'label_fontsize': fontsize of the label. + 'tooltip': Text that is shown when hovering over the edge. """ # Convert adjacency matrix into vector @@ -1192,15 +1194,8 @@ def adjmat2dict(adjmat: pd.DataFrame, df['label_fontsize']=label_fontsize df['edge_style']=edge_style df['edge_opacity'] = edge_opacity + df['tooltip'] = df['weight'].astype(str) - # Handle node_source edge color - if edge_color == 'node_source' and node_color_map is not None: - df['edge_color'] = df['source'].map(node_color_map) - elif edge_color == 'node_target' and node_color_map is not None: - df['edge_color'] = df['target'].map(node_color_map) - else: - df['edge_color'] = edge_color - # Creation dictionary source_target = list(zip(df['source'], df['target'])) if len(source_target)==0: @@ -1218,6 +1213,7 @@ def adjmat2dict(adjmat: pd.DataFrame, 'label': df['label'].iloc[i], 'label_color': df['label_color'].iloc[i], 'label_fontsize': df['label_fontsize'].iloc[i], + 'tooltip': df['tooltip'].iloc[i] } for i, edge in enumerate(source_target)} @@ -1294,6 +1290,7 @@ def edges2G(edge_properties: dict, G: nx.Graph = None) -> nx.Graph: label=edge_properties[edge]['label'], label_color=edge_properties[edge]['label_color'], label_fontsize=edge_properties[edge]['label_fontsize'], + tooltip=edge_properties[edge]['tooltip'] ) return G diff --git a/d3graph/d3js/d3graphscript.js b/d3graph/d3js/d3graphscript.js index 3cfdbaa..d118039 100644 --- a/d3graph/d3js/d3graphscript.js +++ b/d3graph/d3js/d3graphscript.js @@ -82,6 +82,8 @@ function d3graphscript(config = { // .style("stroke-width", 1); // WIDTH OF THE LINKS ; + link.append("title").text(function(d) { return d.tooltip; }); + // ADD TEXT ON THE EDGES (PART 1/2) var linkText = svg.selectAll(".link-text") .data(graph.links)