import graphviz
import subprocess
from IPython.display import display, IFrame
# The DOT code as a string (exactly as you provided)
font="Arial"
dot_code = """digraph {
fontname="arial"
user [label="user \n id: user", shape=ellipse, style=filled, fillcolor=yellow, fontname="Arial", URL="https://www.bio-century.net/"];
graph [ dpi = 1200 ];
user -> landing_page -> projects -> analysis_of_bioimages [style=invis];
subgraph cluster {
fontname="arial";
label="bio-century.net";
labeljust=l;
landing_page [label="landing page \n id: landing_page", shape=box, style=filled, fillcolor=lightblue, fontname="Arial"];
intro [label="intro \n id: landing_page", shape=box, style=filled, fillcolor=lightblue, fontname="Arial"];
user -> landing_page [constraint=false; style=filled; fontcolor=green];
landing_page -> intro [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
landing_page -> projects [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
landing_page -> shorts_tools [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
landing_page -> links [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
projects [label="projects \n id: projects", shape=box, style=filled, fillcolor=lightblue, fontname="Arial", URL="https://www.nationalgallery.org.uk/paintings/vincent-van-gogh-sunflowers"];
subgraph projectssec {
fontname="arial";
label="test";
labeljust=l;
geoanalytics [label="Geoanalytics \n id: geoanalytics", shape=box, style=filled, fillcolor=lightblue, fontname="Arial"];
sequence_analysis [label="Sequence Analysis \n id: sequence_analysis", shape=box, style=filled, fillcolor=lightblue, fontname="Arial", URL="https://github.com/bio-century/Sequence_Analysis"];
analysis_of_bioimages [label="Analysis of Bioimages \n id: analysis_of_bioimages", shape=box, style=filled, fillcolor=lightblue, fontname="Arial", URL="https://github.com/bio-century/Analysis_Of_BioImages"];
actionbutton_dashboard [label="Actionbutton-Dashboard \n id: actionbutton_dashboard", shape=box, style=filled, fillcolor=lightblue, fontname="Arial", URL="https://github.com/bio-century/Actionbutton-Dashboard"];
poi_roi_map [label="POI-ROI-map \n id: poi_roi_map", shape=box, style=filled, fillcolor=lightblue, fontname="Arial", URL="https://github.com/bio-century/POI-ROI-map"];
projects -> geoanalytics [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
projects -> sequence_analysis [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
projects -> analysis_of_bioimages [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
projects -> actionbutton_dashboard [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
projects -> poi_roi_map [constraint=false; style=filled; fontcolor=green, fontname="Arial"];
projects -> geoanalytics -> sequence_analysis -> analysis_of_bioimages -> actionbutton_dashboard -> poi_roi_map [style=invis];
}
shorts_tools [label="shorts_tools \n id: shorts_tools", shape=box, style=filled, fillcolor=lightblue, fontname="Arial"];
links [label="links \n id: links", shape=box, style=filled, fillcolor=lightblue, fontname="Arial", URL="https://djangosbadmin.bio-century.net/"];
{rank = same; intro; projects; shorts_tools; links;}
}
}
"""
# {rank = same; geoanalytics; sequence_analysis; analysis_of_bioimages; actionbutton_dashboard; poi_roi_map;}
# Create a Digraph object using the DOT code directly
dot = graphviz.Source(dot_code)
# Render the graph to a PNG file and view it
# dot.render('graphviz', format='png', view=False, dpi=300)
# Render the graph to a temporary file first (SVG)
temp_path = dot.render('graphviz', format='pdf')
print(temp_path)