Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge tooltip property #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions d3graph/d3graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
from packaging import version
import datazets as dz

logger = logging.getLogger('')
logger = logging.getLogger(__name__)
for handler in logger.handlers[:]:
logger.removeHandler(handler)
console = logging.StreamHandler()
formatter = logging.Formatter('[d3graph] %(levelname)s> %(message)s')
console.setFormatter(formatter)
logger.addHandler(console)
logger = logging.getLogger(__name__)


# %%
Expand Down Expand Up @@ -894,6 +893,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 @@ -1000,6 +1000,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 @@ -1054,6 +1055,7 @@ def adjmat2dict(adjmat: pd.DataFrame,
df['label_color']=label_color
df['label_fontsize']=label_fontsize
df['edge_style']=edge_style
df['tooltip'] = df['weight'].astype(str)

# Creation dictionary
source_target = list(zip(df['source'], df['target']))
Expand All @@ -1070,6 +1072,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 @@ -1145,6 +1148,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 @@ -75,6 +75,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
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
colourmap
ismember
jinja2
markupsafe==2.0.1
networkx>2
numpy
packaging
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
'ismember',
'jinja2',
'packaging',
'markupsafe==2.0.1',
'python-louvain',
'datazets'],
python_requires='>=3',
Expand Down