Skip to content

Commit

Permalink
add reverse selection button
Browse files Browse the repository at this point in the history
  • Loading branch information
engu-m committed Mar 5, 2024
1 parent 7e42757 commit 6a4474a
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@
[
dbc.ButtonGroup(
[
dbc.Button(
children=html.I(
className="fa-solid fa-yin-yang px-1", style={"color": "black"}
),
id="btn-reverse-selection",
outline=True,
),
dbc.Popover(
"Reverse node selection",
target="btn-reverse-selection",
body=True,
trigger="hover",
placement="top",
),
dbc.Button(
children=html.I(className="fa-solid fa-broom px-1", style={"color": "white"}),
id="btn-rm-lonely-nodes",
Expand Down Expand Up @@ -193,7 +207,7 @@
"fcose",
"cola",
"euler",
"spread",
# "spread",
]
),
clearable=False,
Expand Down Expand Up @@ -250,7 +264,8 @@
Input("actor_add", "n_submit"),
State("actor_add", "value"),
State(cyto_graph, "elements"),
prevent_initial_call="initial_duplicate",
# prevent_initial_call="initial_duplicate",
prevent_initial_call=True,
)
def add_actor(nclicks, nsubmit, actor, elements):
query_result = get_actor_relations(actor, database)
Expand Down Expand Up @@ -334,6 +349,8 @@ def rm_actor(nclicks, nsubmit, actor, elements):
prevent_initial_call=True,
)
def rm_selected_nodes(_, selected_nodes, elements):
if not selected_nodes:
return elements
ids_to_remove = {node["id"] for node in selected_nodes}
return rm_node_ids(ids_to_remove, elements)

Expand Down Expand Up @@ -424,6 +441,20 @@ def remove_lonely_actors(_, elements):
return rm_node_ids(lonely_nodes_ids, elements)


@app.callback(
Output(cyto_graph, "selectedNodeData"),
Input("btn-reverse-selection", "n_clicks"),
State(cyto_graph, "selectedNodeData"),
State(cyto_graph, "elements"),
prevent_initial_call=True,
)
def reverse_selection(_, selectedNodeData, elements):
nodeData = [node["data"] for node in get_nodes(elements)]
selectedData = selectedNodeData
not_selectedData = list(filter(lambda x: x not in selectedData, nodeData))
return not_selectedData


def get_single_node_info(data_node, elements):
nodes = get_nodes(elements)
degrees = get_degrees(elements)
Expand Down

0 comments on commit 6a4474a

Please sign in to comment.