o
    h                     @  s   U d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ erCdd
lZddlmZ edddef Zded< G dd dZdddZd
S )z&Streamlit support for GraphViz charts.    )annotations)TYPE_CHECKINGUnioncast)	TypeAlias)	type_util)StreamlitAPIException)GraphVizChart)gather_metrics)calc_md5N)DeltaGeneratorzgraphviz.Graphzgraphviz.Digraphzgraphviz.Sourcer   FigureOrDotc                   @  s0   e Zd Zed	ddd	d
ZedddZdS )GraphvizMixingraphviz_chartFfigure_or_dotr   use_container_widthboolreturnr   c                 C  s8   | j  }t| }t }t|||| | j d|S )a  Display a graph using the dagre-d3 library.

        Parameters
        ----------
        figure_or_dot : graphviz.dot.Graph, graphviz.dot.Digraph, graphviz.sources.Source, str
            The Graphlib graph object or dot string to display

        use_container_width : bool
            Whether to override the figure's native width with the width of
            the parent container. If ``use_container_width`` is ``False``
            (default), Streamlit sets the width of the chart to fit its contents
            according to the plotting library, up to the width of the parent
            container. If ``use_container_width`` is ``True``, Streamlit sets
            the width of the figure to match the width of the parent container.

        Example
        -------
        >>> import streamlit as st
        >>> import graphviz
        >>>
        >>> # Create a graphlib graph object
        >>> graph = graphviz.Digraph()
        >>> graph.edge("run", "intr")
        >>> graph.edge("intr", "runbl")
        >>> graph.edge("runbl", "run")
        >>> graph.edge("run", "kernel")
        >>> graph.edge("kernel", "zombie")
        >>> graph.edge("kernel", "sleep")
        >>> graph.edge("kernel", "runmem")
        >>> graph.edge("sleep", "swap")
        >>> graph.edge("swap", "runswap")
        >>> graph.edge("runswap", "new")
        >>> graph.edge("runswap", "runmem")
        >>> graph.edge("new", "runmem")
        >>> graph.edge("sleep", "runmem")
        >>>
        >>> st.graphviz_chart(graph)

        Or you can render the chart from the graph using GraphViz's Dot
        language:

        >>> st.graphviz_chart('''
            digraph {
                run -> intr
                intr -> runbl
                runbl -> run
                run -> kernel
                kernel -> zombie
                kernel -> sleep
                kernel -> runmem
                sleep -> swap
                swap -> runswap
                runswap -> new
                runswap -> runmem
                new -> runmem
                sleep -> runmem
            }
        ''')

        .. output::
           https://doc-graphviz-chart.streamlit.app/
           height: 600px

        r   )dg_get_delta_path_strr   encodeGraphVizChartProtomarshall_enqueue)selfr   r   
delta_path
element_idgraphviz_chart_proto r   U/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/graphviz_chart.pyr   (   s
   
GzGraphvizMixin.graphviz_chartc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r   r   r   r   w   s   
zGraphvizMixin.dgN)F)r   r   r   r   r   r   )r   r   )__name__
__module____qualname__r
   r   propertyr   r   r   r   r   r   '   s    Nr   protor   r   r   r   r   strr   Nonec                 C  sX   t |r|j}|j}nt|tr|}d}ntdt| || _|| _|| _	|| _
dS )zXConstruct a GraphViz chart object.

    See DeltaGenerator.graphviz_chart for docs.
    dotz%Unhandled type for graphviz chart: %sN)r   is_graphviz_chartsourceengine
isinstancer%   r   typespecr   r   )r$   r   r   r   r'   r*   r   r   r   r   }   s   



r   )
r$   r   r   r   r   r   r   r%   r   r&   )__doc__
__future__r   typingr   r   r   typing_extensionsr   	streamlitr   streamlit.errorsr   !streamlit.proto.GraphVizChart_pb2r	   r   streamlit.runtime.metrics_utilr
   streamlit.utilr   graphvizstreamlit.delta_generatorr   r%   r   __annotations__r   r   r   r   r   r   <module>   s"   
V