Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions d3graph/d3graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)}

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions d3graph/d3js/d3graphscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down