@@ -301,7 +301,7 @@ def int_or_zero(value: str) -> int:
301
301
return 0
302
302
303
303
304
- def assign_colors (db : DatabaseHandler , graph : nx .Graph , color_by : str , boolean : bool = False ) -> None :
304
+ def assign_colors (db : DatabaseHandler , graph : nx .Graph , color_by : str , bool : bool = False ) -> None :
305
305
"""Assign a 'color' attribute to each node in the graph.
306
306
307
307
Each color will be in '#FFFFFF' format.
@@ -311,7 +311,7 @@ def assign_colors(db: DatabaseHandler, graph: nx.Graph, color_by: str, boolean:
311
311
log .warning (f'assign colors by { color_by } ' )
312
312
for n in graph .nodes :
313
313
value = str (graph .nodes [n ].get (color_by , 'null' ))
314
- if boolean :
314
+ if bool :
315
315
graph .nodes [n ]['color' ] = 'b4771f' if int_or_zero (value ) > 0 else 'dddddd'
316
316
else :
317
317
graph .nodes [n ]['color' ] = get_consistent_color (db , color_by , value )
@@ -597,7 +597,7 @@ def get_giant_component(graph: nx.Graph) -> nx.Graph:
597
597
return graph .subgraph (components [- 1 ]) if len (components ) > 0 else graph
598
598
599
599
600
- def generate_graph (db : DatabaseHandler , timespans_id : int ) -> nx .Graph :
600
+ def generate_graph (db : DatabaseHandler , timespans_id : int , remove_platforms : bool = True ) -> nx .Graph :
601
601
"""Generate a graph of the network of media for the given timespan, but do not layout."""
602
602
media = get_media_network (db = db , timespans_id = timespans_id )
603
603
graph = get_media_graph (media = media )
@@ -608,9 +608,10 @@ def generate_graph(db: DatabaseHandler, timespans_id: int) -> nx.Graph:
608
608
609
609
log .info (f"graph after giant component: { len (graph .nodes ())} nodes" )
610
610
611
- graph = remove_platforms_from_graph (graph = graph )
611
+ if remove_platforms :
612
+ graph = remove_platforms_from_graph (graph = graph )
612
613
613
- log .info (f"graph after platform removal: { len (graph .nodes ())} nodes" )
614
+ log .info (f"graph after platform removal: { len (graph .nodes ())} nodes" )
614
615
615
616
return graph
616
617
@@ -644,12 +645,13 @@ def get_default_size_attribute(db: DatabaseHandler, timespans_id: int) -> str:
644
645
def generate_and_layout_graph (db : DatabaseHandler ,
645
646
timespans_id : int ,
646
647
memory_limit_mb : int ,
648
+ remove_platforms : bool = True ,
647
649
color_by : str = 'community' ) -> nx .Graph :
648
650
"""Generate and layout a graph of the network of media for the given timespan.
649
651
650
652
The layout algorithm is force atlas 2, and the resulting is 'position' attribute added to each node.
651
653
"""
652
- graph = generate_graph (db = db , timespans_id = timespans_id )
654
+ graph = generate_graph (db = db , timespans_id = timespans_id , remove_platforms = remove_platforms )
653
655
# run layout with all nodes in giant component, before reducing to smaler number to display
654
656
run_fa2_layout (graph = graph , memory_limit_mb = memory_limit_mb )
655
657
0 commit comments