G = nx.DiGraph()
G.add_weighted_edges_from(df_weighted_edges_tutar)
for node_id in G.nodes:
node = G.nodes[node_id]
gelen_eft_adedi = total_gelen_eft_adet[total_gelen_eft_adet.index ==
node_id]["gelen_eft_adet"].values[0]
gelen_eft_adedi_karsi_taraf = total_gelen_eft_adet[
total_gelen_eft_adet.index == node_id]["giden_eft_adet"].values[0]
node[
'hover'] = f"{node_id}\nGelen EFT Adedi: {gelen_eft_adedi}\nGelen EFT Tutarı: {total_source_node_size_dict[node_id]:,} TL\nGelen EFT Adedi (Karşı Taraf): {gelen_eft_adedi_karsi_taraf}"
node["size"] = total_source_node_size_dict[node_id]
# Node properties: Size by transfer amount, shape by size, color by community
colors = [
'blue', 'green', 'red', 'orange', "gold", "olive", "purple", "darkred",
"darkblue", "darkgrey", "violet"
]
for node_id in G.nodes:
node = G.nodes[node_id]
for community_counter, community_members in enumerate(communities):
if node_id in community_members:
break
node['color'] = colors[community_counter % len(colors)]
# Edge properties: Size by total incoming transfer amount, color by community (within=community color, between=black)
for edge_id in G.edges:
edge = G.edges[edge_id]
source_node = G.nodes[edge_id[0]]
target_node = G.nodes[edge_id[1]]
is_customer = df_sums[(df_sums.target == edge_id[1]) & (
df_sums.source == edge_id[0])]["is_customer"].values[0]
customer_map = {1: "Yes", 0: "No"}
edge['color'] = source_node['color'] if source_node[
'color'] == target_node['color'] else 'b-'
edge[
"hover"] = f"{edge_id[0]} --> {edge_id[1]}\nEFT Amount: {edge['weight']:,} TL\nIs Customer?: {customer_map[is_customer]}"
gv.d3(G,
use_node_size_normalization=True,
node_size_normalization_max=100,
details_height=250,
graph_height=650,
node_size_data_source='size',
use_edge_size_normalization=True,
edge_size_data_source='weight',
edge_curvature=-0.3,
edge_size_factor=1.1,
node_hover_neighborhood=True,
node_label_data_source='label',
many_body_force_max_distance=-500,
use_many_body_force_max_distance=True,
show_details=True,
layout_algorithm_active=True,
edge_hover_tooltip=True)
I would like to change the edge style to dashed line if the source node is not a customer. it is determined in the is is_customer parameter and already tried to put in edge properties as edge["style"] but did not work. I also tried to state the edge styles in networkx's draw_networkx_edges module but could not integrate it with gravis graph.
Another question is, is there any feature on gravis for selecting and filtering nodes/edges with a search bar like pyvis. I cannot use pyvis on my work computer. it does not let the rendering. So if there is a similar feature in gravis it would be great for me to learn.
One last question, what is the best way of displaying the community colors as a legend at an appropriate place at the network.
As the author of the Gravis i hope @robert-haas would see this post as well :)