def render_single_step_html(step, idx):
arr = step["array"]
compare = step["compare"]
swapped = step["swapped"]
swapped_indices = step.get("swapped_indices")
# Container wrapper (centering)
html = f"""
Step {idx}
"""
# Height multiplier = taller bars
HEIGHT_MULT = 8 # increase to make bars even taller
for i, val in enumerate(arr):
# DEFAULT GRAY
color = "#777"
# SWAP takes priority (GREEN)
if swapped and swapped_indices and (i in swapped_indices):
color = "#4caf50"
# COMPARISON (ORANGE)
elif compare and (i == compare[0] or i == compare[1]):
color = "#ffa500"
bar_height = 20 + val * HEIGHT_MULT
html += f"""
{val}
"""
# close bar container
html += "
"
# Explanation text under the graph
if swapped and swapped_indices:
html += "
Swap happened
"
elif compare:
html += f"
Comparing {compare[0]} and {compare[1]}
"
else:
html += "
Snapshot
"
html += "
" # close outer container
return html