Skip to content

Commit

Permalink
fix download
Browse files Browse the repository at this point in the history
  • Loading branch information
yilinxia committed Feb 12, 2025
1 parent b00e3a2 commit f008b5b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 29 deletions.
12 changes: 7 additions & 5 deletions assets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@

.hover-button {
border: 4px solid transparent;
/* Ensures border width remains consistent */
/* Keeps border width consistent */
transition: border-color 0.2s ease-in-out, outline-width 0.2s ease-in-out;
box-sizing: border-box;
/* Ensures padding/border doesn't affect layout */
/* Prevents padding/border from shifting layout */
}

.hover-button:hover {
/* Applies when hovered or when the button is marked as selected */
.hover-button:hover,
.hover-button.selected {
border-color: black !important;
/* Keeps border width, only changes color */
/* Changes border color */
outline: 3px solid black;
/* Adds thickness without shifting layout */
/* Adds extra thickness */
}
34 changes: 32 additions & 2 deletions src/callbacks/explanation_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# callbacks/explanation_callbacks.py

from dash import html, callback, Input, Output, State
from dash import html, callback, Input, Output, State, callback_context, ALL
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
import json

# Import any necessary functions
from py_arg_visualisation.functions.import_functions.read_argumentation_framework_functions import (
Expand Down Expand Up @@ -63,7 +64,7 @@ def determine_hex_color(arg):
style={
"margin": "5px",
"backgroundColor": determine_hex_color(arg), # Set background color
"border": "1px solid gray", # Border matches color
# "border": "1px solid gray", # Border matches color
"color": "black", # Text color
},
)
Expand All @@ -80,3 +81,32 @@ def determine_hex_color(arg):
]
)
return arguments_div


@callback(
Output({"type": "argument-button-abstract", "index": ALL}, "className"),
Input({"type": "argument-button-abstract", "index": ALL}, "n_clicks"),
State({"type": "argument-button-abstract", "index": ALL}, "id"),
prevent_initial_call=True,
)
def update_selected_button(n_clicks_list, id_list):
ctx = callback_context
# If no button has been clicked yet, return the default class for all buttons.
if not ctx.triggered:
return ["hover-button" for _ in id_list]

# Identify the button that was clicked.
triggered_prop = ctx.triggered[0]["prop_id"]
# The triggered id comes in as a JSON string, so decode it.
triggered_id = json.loads(triggered_prop.split(".")[0])

# Build the new className list:
# The clicked button gets "hover-button selected"; all others remain "hover-button".
new_class_names = []
for btn_id in id_list:
if btn_id["index"] == triggered_id["index"]:
new_class_names.append("hover-button selected")
else:
new_class_names.append("hover-button")

return new_class_names
49 changes: 27 additions & 22 deletions src/callbacks/visualization_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Input("abstract-evaluation-accordion", "active_item"),
Input("layout-freeze-switch", "value"),
State("selected_arguments_changed", "data"),
State("explanation-graph", "dot_source"),
prevent_initial_call=True,
)
def create_visualization(
Expand All @@ -41,12 +42,11 @@ def create_visualization(
active_item,
layout_freeze,
selected_arguments_changed,
current_dot_source,
):
if not arguments or not attacks:
raise PreventUpdate

if selected_arguments == {}:
selected_arguments = None
if not isinstance(selected_arguments, dict):
selected_arguments = {}

Expand All @@ -57,9 +57,11 @@ def create_visualization(
arg_framework = read_argumentation_framework(arguments, attacks)
triggered_id = ctx.triggered_id

# Determine whether Tab "ArgumentationFramework" is active
if active_item == "ArgumentationFramework":
dot_source = generate_plain_dot_string(arg_framework, dot_layout)
selected_arguments_changed = False
# Determine whether Tab "Explanation" is active
elif active_item == "Explanation":
dot_source = generate_dot_string(
arg_framework,
Expand All @@ -70,9 +72,11 @@ def create_visualization(
special_handling,
layout_freeze,
)
# Determine whether Tab "Solution" is active
else:
if triggered_id == "abstract-evaluation-accordion":
dot_source = generate_plain_dot_string(arg_framework, dot_layout)

if (
triggered_id == "selected-argument-store-abstract"
and selected_arguments == {}
Expand Down Expand Up @@ -135,26 +139,27 @@ def create_visualization(
["dot", "-Tplain", "temp/layout.dot", "-o", "temp/layout.txt"],
check=True,
)
rank_dict = {
"NR": "Attacks",
"MR": "Unchallenged Arguments",
"AR": "Length of Arguments",
}
settings = f"""
// Input AF: {str(arg_framework)}
// Layer by: {rank_dict.get(dot_rank, "Unknown")}
// Use Blunders: {"Yes" if "BU" in special_handling else "No"}
// Use Re-Derivations: {"Yes" if "RD" in special_handling else "No"}
""".strip()

if triggered_id == "21-dot-download-button":
return (
dict(
content=settings + "\n" + dot_source,
filename="output.gv",
),
dot_source,
selected_arguments_changed,
)
# Determine whether Download button is pressed
if triggered_id == "21-dot-download-button":
rank_dict = {
"NR": "Attacks",
"MR": "Unchallenged Arguments",
"AR": "Length of Arguments",
}
settings = f"""
// Input AF: {str(arg_framework)}
// Layer by: {rank_dict.get(dot_rank, "Unknown")}
// Use Blunders: {"Yes" if "BU" in special_handling else "No"}
// Use Re-Derivations: {"Yes" if "RD" in special_handling else "No"}
""".strip()
return (
dict(
content=settings + "\n" + current_dot_source,
filename="output.gv",
),
dot_source,
selected_arguments_changed,
)

return None, dot_source, selected_arguments_changed

0 comments on commit f008b5b

Please sign in to comment.