Skip to content

Commit

Permalink
Merge pull request #4 from idaks/layered_vis
Browse files Browse the repository at this point in the history
New Features for Layered vis
  • Loading branch information
DaphneOdekerken authored Aug 23, 2024
2 parents f7c3ea6 + 08e4fb4 commit 9ab5553
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pathlib

from collections import defaultdict
import clingo

from py_arg_visualisation.functions.graph_data_functions.get_color import \
Expand All @@ -26,7 +26,12 @@ def generate_plain_dot_string(argumentation_framework, layout=any):


def generate_dot_string(
argumentation_framework, selected_arguments, color_blind_mode=False, layout=any):
argumentation_framework, selected_arguments,
color_blind_mode=False,
layout=any,
rank=any,
dot_con=any,
dot_rm_edge=any):
gr_status_by_arg, number_by_argument = get_numbered_grounded_extension(
argumentation_framework)
dot_string = "digraph {\n"
Expand All @@ -35,7 +40,7 @@ def generate_dot_string(
# Adding node information
is_extension_representation = False
argument_extension_state = {}
undefined_arguments = []
# undefined_arguments = []
unselected_arguments = \
{arg.name for arg in argumentation_framework.arguments}
for color, arguments in selected_arguments.items():
Expand All @@ -47,8 +52,8 @@ def generate_dot_string(
status = 'defeated'
elif color == 'yellow':
status = 'undefined'
if len(arguments)!=0:
undefined_arguments=arguments
# if len(arguments)!=0:
# undefined_arguments=arguments
else:
status = 'other'
for argument_name in arguments:
Expand Down Expand Up @@ -89,74 +94,139 @@ def generate_dot_string(
attack.to_argument.name]
from_argument_number = \
number_by_argument[attack.from_argument.name]
to_argument_number = \
number_by_argument[attack.to_argument.name]

# cal the against wind
against_wind = False
from_num = float('inf') if from_argument_number == "∞" else int(from_argument_number)
to_num = float('inf') if to_argument_number == "∞" else int(to_argument_number)
against_wind = from_num == float('inf') and to_num != float('inf')
against_wind = against_wind or (from_num > to_num)

if from_num == float('inf'):
label = '∞'
else:
label = str( from_num + 1)

constraint = False

# set initial style
style = 'solid'
try:
num = int(from_argument_number)
label = str( num + 1)
except ValueError:
label = from_argument_number
arrow_style = 'vee'
constraint_value = ''
# handle grounded extensions
# Accepted -> Defeated
if from_argument_grounded_state == 'accepted' and \
to_argument_grounded_state == 'defeated':
full_color = get_color('green', color_blind_mode)
# Defeated -> Accepted
elif from_argument_grounded_state == 'defeated' and \
to_argument_grounded_state == 'accepted':
full_color = get_color('red', color_blind_mode)
elif from_argument_grounded_state != 'accepted' and \
to_argument_grounded_state == 'defeated':
constraint = True
full_color = get_color('gray', color_blind_mode)
style = 'dotted'
label = ''
else:

# grounded_edge_color = get_color('yellow', color_blind_mode)
#handle the stable extensions
# Stable Accepted -> Defeated (Grounded Undefined)
if from_argument_extension_state == 'accepted' and \
to_argument_extension_state == 'defeated':
extension_edge_color = get_color('green', color_blind_mode)
full_color = \
f'{extension_edge_color}'
label = ''
# Stable Defeated -> Accepted(Grounded Undefined)
elif from_argument_extension_state == 'defeated' and \
to_argument_extension_state == 'accepted':
extension_edge_color = get_color('red', color_blind_mode)
full_color = \
f'{extension_edge_color}'
label = ''
# Undefined -> Undefined
elif from_argument_extension_state == 'undefined' and \
to_argument_extension_state == 'undefined':
full_color = get_color('dark-yellow', color_blind_mode)
else:
constraint = True
extension_edge_color = get_color('gray', color_blind_mode)
full_color = \
f'{extension_edge_color}'
style = set_style("UU", style, dot_rm_edge)
constraint_value = set_con("UU", dot_con)
# Undefined -> Defeated
elif from_argument_extension_state == 'undefined' and \
to_argument_extension_state == 'defeated':
full_color = get_color('gray', color_blind_mode)
style = 'dotted'
style = set_style("UD", style, dot_rm_edge)
arrow_style = 'onormal'
constraint_value= set_con("UD", dot_con)
label = ''
# Defeated -> Undefined
elif from_argument_extension_state == 'defeated' and \
to_argument_extension_state == 'undefined':
full_color = get_color('gray', color_blind_mode)
style = 'dotted'
style = set_style("DU", style, dot_rm_edge)
arrow_style = 'onormal'
constraint_value = set_con("DU", dot_con)
label = ''
# Defeated -> Defeated
elif from_argument_extension_state == 'defeated' and \
from_argument_extension_state == 'defeated':
full_color = get_color('gray', color_blind_mode)
style = 'dotted'
style = set_style("DD", style, dot_rm_edge)
arrow_style = 'onormal'
constraint_value = set_con("DD", dot_con)
label = ''

if constraint:
constraint_str = "constraint=true"
if against_wind:
if style == 'dotted':
pass
elif style == "invis":
pass
else:
style = 'dashed'
style = set_style("AW", style, dot_rm_edge)
edge = f'"{attack.to_argument.name}" -> ' \
f'"{attack.from_argument.name}" ' \
f'[dir=back ' \
f'color="{full_color}" ' \
f'style= "{style}"' \
f'{constraint_value}' \
f'fontcolor="{full_color}"' \
f'arrowtail="{arrow_style}"' \
f'arrowhead="{arrow_style}"' \
f'headlabel="{label}"]\n'
else:
constraint_str = ''

edge = f'"{attack.from_argument.name}" -> ' \
f'"{attack.to_argument.name}" ' \
f'[color="{full_color}" ' \
f'style="{style}" ' \
f'taillabel="{label}" {constraint_str}]\n'
edge = f'"{attack.from_argument.name}" -> ' \
f'"{attack.to_argument.name}" ' \
f'[color="{full_color}" ' \
f'style="{style}"' \
f'{constraint_value}' \
f'fontcolor="{full_color}"' \
f'arrowtail="{arrow_style}"' \
f'arrowhead="{arrow_style}"' \
f'taillabel="{label}"]\n'
else:
edge = f'"{attack.from_argument.name}" -> ' \
f'"{attack.to_argument.name}"\n'
dot_string += " "+edge


# Enable Ranks
number_by_argument = {k: v for k, v in number_by_argument.items() if v != '∞'}
min_state_nodes = [node for node, value in number_by_argument.items() if value == min(number_by_argument.values())]
max_state_nodes = [node for node, value in number_by_argument.items() if value == max(number_by_argument.values())]

min_rank_string = f"{{rank = min {' '.join(min_state_nodes)}}}"
max_rank_string = f"{{rank = max {' '.join(max_state_nodes+undefined_arguments)}}}"
dot_string += f" {min_rank_string}\n {max_rank_string}\n"
if rank=="NR":
pass
elif rank=="AR":
max_value = max(number_by_argument.values())
# Create a new dictionary excluding nodes with the maximum value
filtered_arguments = {k: v for k, v in number_by_argument.items() if v != max_value}
nodes_by_value = defaultdict(list)
for node, value in filtered_arguments.items():
nodes_by_value[value].append(node)
for value, nodes in nodes_by_value.items():
same_rank_string = f"{{rank = same {' '.join(nodes)}}}"
dot_string += f" {same_rank_string}\n"
elif rank=="MR":
min_state_nodes = [node for node, value in number_by_argument.items() if value == min(number_by_argument.values())]
min_rank_string = f"{{rank = min {' '.join(min_state_nodes)}}}"
dot_string += f" {min_rank_string}\n"

dot_string += "}"
# print(dot_string)
return dot_string


Expand Down Expand Up @@ -194,3 +264,16 @@ def get_numbered_grounded_extension(argumentation_framework):
number_by_argument[argument_name] = str(atom.arguments[2])
status_by_argument[argument_name] = atom.arguments[0].name
return status_by_argument, number_by_argument


def set_style(keyword, style, rm_edge):
if rm_edge!= None and keyword in rm_edge:
return "invis"
else:
return style

def set_con(keyword, rm_edge):
if rm_edge!= None and keyword in rm_edge:
return 'constraint="false"'
else:
return ''
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def get_color(required_color: str, color_blind_mode: bool) -> str:
if color_blind_mode:
if required_color == 'gray':
return '#dddddd'
return '#919191'
if required_color == 'blue':
return '#6D90E3'
if required_color == 'dark-blue':
Expand Down
Loading

0 comments on commit 9ab5553

Please sign in to comment.