o
    Yh                     @  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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 erUd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)make_deprecated_name_warningshow_deprecation_warning)LayoutConfigWidthvalidate_width)StreamlitAPIException)GraphVizChart)gather_metrics)calc_md5N)DeltaGeneratorzgraphviz.Graphzgraphviz.Digraphzgraphviz.Sourcer   FigureOrDotc                   @  s6   e Zd Zed	ddddddZedddZdS )GraphvizMixingraphviz_chartNcontentwidthfigure_or_dotr   use_container_widthbool | Noner   r   returnr   c                C  s~   |durt tdddddddd |rd	nd
}| j }t| }t }t||| t|dd t	|d}| jj
d||dS )ay  Display a graph using the dagre-d3 library.

        .. Important::
            You must install ``graphviz>=0.19.0`` to use this command. You can
            install all charting dependencies (except Bokeh) as an extra with
            Streamlit:

            .. code-block:: shell

               pip install streamlit[charts]

        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.

        width : "content", "stretch", or int
            The width of the chart element. This can be one of the following:

            - ``"content"`` (default): The width of the element matches the
              width of its content, but doesn't exceed the width of the parent
              container.
            - ``"stretch"``: The width of the element matches the width of the
              parent container.
            - An integer specifying the width in pixels: The element has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the element matches the width
              of the parent container.

        .. deprecated::
            ``use_container_width`` is deprecated and will be removed in a
            future release. For ``use_container_width=True``, use
            ``width="stretch"``. For ``use_container_width=False``, use
            ``width="content"``.

        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

        Nr   r   z
2025-12-31znFor `use_container_width=True`, use `width='stretch'`. For `use_container_width=False`, use `width='content'`.F)include_st_prefix)show_in_browserstretchr   T)allow_contentr   r   )layout_config)r	   r   dg_get_delta_path_strr   encodeGraphVizChartProtomarshallr   r
   _enqueue)selfr   r   r   
delta_path
element_idgraphviz_chart_protor     r+   b/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/graphviz_chart.pyr   1   s*   d

zGraphvizMixin.graphviz_chartc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r'   r+   r+   r,   r!      s   
zGraphvizMixin.dg)N)r   r   r   r   r   r   r   r   )r   r   )__name__
__module____qualname__r   r   propertyr!   r+   r+   r+   r,   r   0   s     r   protor$   r   r)   strr   Nonec                 C  sT   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: N)
r   is_graphviz_chartsourceengine
isinstancer2   r   typespecr)   )r1   r   r)   r4   r7   r+   r+   r,   r%      s   



r%   )r1   r$   r   r   r)   r2   r   r3   )#__doc__
__future__r   typingr   r   r   typing_extensionsr   	streamlitr   streamlit.deprecation_utilr   r	   #streamlit.elements.lib.layout_utilsr
   r   r   streamlit.errorsr   !streamlit.proto.GraphVizChart_pb2r   r$   streamlit.runtime.metrics_utilr   streamlit.utilr   graphvizstreamlit.delta_generatorr   r2   r   __annotations__r   r%   r+   r+   r+   r,   <module>   s(   
 
