
    -Ph;                         d dl Z d dlZd dlZd dlZd dlZd dlmZ 	 d dlmZ n# e	$ r	 d dl
mZ Y nw xY w e            Z G d de          Z e            Z[d Zd	dZdS )
    N)reduce)gcdc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zi fdZed             Zej        d             Zd Zd Zd Zd ZdS )TemplatesConfigzO
    Singleton object containing the current figure templates (aka themes)
    c                 `    i | _         g d}|D ]}t          | j         |<   d | _        d | _        d S )N)ggplot2seabornsimple_whiteplotlyplotly_whiteplotly_darkpresentationxgridoffygridoffgridonnone)
_templatesLazy
_validator_default)selfdefault_templatestemplate_names      T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/io/_templates.py__init__zTemplatesConfig.__init__   sO     
 
 
 / 	2 	2M-1DOM**    c                 *    t          | j                  S N)lenr   r   s    r   __len__zTemplatesConfig.__len__7   s    4?###r   c                     || j         v S r   )r   )r   items     r   __contains__zTemplatesConfig.__contains__:   s    t&&r   c                 *    t          | j                  S r   )iterr   r    s    r   __iter__zTemplatesConfig.__iter__=   s    DO$$$r   c                 "   t          |t                    r|                    d          }n|g}g }|D ]}| j        |         }|t          u rddlm} |dk    r |i g          }|| j        |<   nwt          j        	                    dd|dz             }t          j        d	|                              d
          }t          j        |          }	 ||	d          }|| j        |<   |                    | j        |                     | j        | S )N+r   Templater   )data_scatterpackage_data	templatesz.jsonr   zutf-8F)	_validate)
isinstancestrsplitr   r   plotly.graph_objs.layoutr+   ospathjoinpkgutilget_datadecodejsonloadsappendmerge_templates)
r   r#   template_namesr.   r   templater+   r5   template_strtemplate_dicts
             r   __getitem__zTemplatesConfig.__getitem__@   s9   dC   	$!ZZ__NN"VN	+ 	= 	=M}5H4====== F**'xbT:::H5=DOM22 7<<&]W5L D $+#3Hd#C#C#J#J7#S#SL$(J|$<$<M'xGGGH5=DOM2T_];<<<<#t#Y//r   c                 @    |                      |          | j        |<   d S r   )r/   r   )r   keyvalues      r   __setitem__zTemplatesConfig.__setitem__^   s     #~~e44r   c                 >    | j         |= | j        |k    r	d | _        d S d S r   )r   r   )r   rD   s     r   __delitem__zTemplatesConfig.__delitem__a   s.    OC  =C DMMM  r   c                 n    | j         sddlm}  |            | _         | j                             |          S )Nr   )TemplateValidator)r   plotly.validators.layoutrJ   validate_coerce)r   rE   rJ   s      r   r/   zTemplatesConfig._validatei   sD     	2BBBBBB//11DO..u555r   c                 4    | j                                         S r   )r   keysr    s    r   rN   zTemplatesConfig.keysq   s    ##%%%r   c                 4    | j                                         S r   )r   itemsr    s    r   rP   zTemplatesConfig.itemst   s    $$&&&r   c                 Z    t          |fi |                                D ]
\  }}|| |<   dS )ai  
        Update one or more templates from a dict or from input keyword
        arguments.

        Parameters
        ----------
        d: dict
            Dictionary from template names to new template values.

        kwargs
            Named argument value pairs where the name is a template name
            and the value is a new template value.
        N)dictrP   )r   dkwargskvs        r   updatezTemplatesConfig.updatew   sH     %%f%%++-- 	 	DAqDGG	 	r   c                     | j         S )a  
        The name of the default template, or None if no there is no default

        If not None, the default template is automatically applied to all
        figures during figure construction if no explicit template is
        specified.

        The names of available templates may be retrieved with:

        >>> import plotly.io as pio
        >>> list(pio.templates)

        Returns
        -------
        str
        )r   r    s    r   defaultzTemplatesConfig.default   s    $ }r   c                 >    |                      |           || _        d S r   )r/   r   )r   rE   s     r   rY   zTemplatesConfig.default   s!     	ur   c                 x    d                     t          | j                  |                                           S )NzuTemplates configuration
-----------------------
    Default template: {default}
    Available templates:
{available}
)rY   	available)formatreprrY   _available_templates_strr    s    r   __repr__zTemplatesConfig.__repr__   s=     F&&$2O2O2Q2Q  
 
	
r   c           	          d                     t          j        t          t	          |                     ddd                    }|S )ze
        Return nicely wrapped string representation of all
        available template names
        
G   z        z	         )widthinitial_indentsubsequent_indent)r6   textwrapwrapr^   list)r   r\   s     r   r_   z(TemplatesConfig._available_templates_str   sM    
 IIMT$ZZ  &")	  
 
	 r   c                 P    |rt          | j        |          S ddlm}  |            S )a  
        Merge a collection of templates into a single combined template.
        Templates are process from left to right so if multiple templates
        specify the same propery, the right-most template will take
        precedence.

        Parameters
        ----------
        args: list of Template
            Zero or more template objects (or dicts with compatible properties)

        Returns
        -------
        template:
            A combined template object

        Examples
        --------

        >>> pio.templates.merge_templates(
        ...     go.layout.Template(layout={'font': {'size': 20}}),
        ...     go.layout.Template(data={'scatter': [{'mode': 'markers'}]}),
        ...     go.layout.Template(layout={'font': {'family': 'Courier'}}))
        layout.Template({
            'data': {'scatter': [{'mode': 'markers', 'type': 'scatter'}]},
            'layout': {'font': {'family': 'Courier', 'size': 20}}
        })
        r   r*   )r   _merge_2_templatesr3   r+   )r   argsr+   s      r   r=   zTemplatesConfig.merge_templates   s=    :  	$148889999998::r   c                    |                      |          }|                      |          }|j        D ]}|j        |         }|j        |         }|r|rt          |          t          |          z  t          t          |          t          |                    z  }||t          |          z  z  |j        |<   ||t          |          z  z  |j        |<   |                    |           |S )a  
        Helper function for merge_templates that merges exactly two templates

        Parameters
        ----------
        template1: Template
        template2: Template

        Returns
        -------
        Template:
            merged template
        )r/   datar   r   rW   )	r   	template1	template2resultother
trace_typeresult_tracesother_traceslcms	            r   rk   z"TemplatesConfig._merge_2_templates   s    	**y)) !+ 	S 	SJ"K
3M :j1L S S&&,''(3}--s</@/@AAB  +83#mBTBT;T*UJ' *6L@Q@Q9Q)R
:& 	er   N)__name__
__module____qualname____doc__r   r!   r$   r'   rB   rF   rH   r/   rN   rP   rW   propertyrY   setterr`   r_   r=   rk    r   r   r   r      sB          8$ $ $' ' '% % %0 0 0<5 5 5! ! !6 6 6& & &' ' '     $   X& ^  ^	
 	
 	
  " " "H' ' ' ' 'r   r   c                    ddl m}m}m} t	          | j                  D ]}|dk    s||v r| |         }||         }|                     |          }	t          |	|          rt          |||           |j        sd| |<   at          |	|          r|rt	          |          }
d |
D             }||dd         dz            }|D ]}|j	        }|rt                      }|j	        |v r4|                    |j	                  }|
|         }t          |||           nT|                                }t          |||           |
                    |           |                    |j	                   ||_	        t          |||           |
||<   n|	j        r ||          s|||<   	 d| |<   # t          $ r Y w xY wdS )a  
    Move style properties from fig_obj to template_obj.

    Parameters
    ----------
    fig_obj: plotly.basedatatypes.BasePlotlyType
    template_obj: plotly.basedatatypes.BasePlotlyType
    skip: set of str
        Set of names of properties to skip
    r   )CompoundValidatorCompoundArrayValidatoris_arrayr?   Nc                     g | ]	}|j         
S r}   )name).0els     r   
<listcomp>z)walk_push_to_template.<locals>.<listcomp>9  s    %J%J%J"bg%J%J%Jr   defaults)_plotly_utils.basevalidatorsr   r   r   ri   _props_get_validatorr0   walk_push_to_templater   setindex	__class__r<   array_ok
ValueError)fig_objtemplate_objskipr   r   r   propfig_valtemplate_val	validatortemplate_elementstemplate_element_namestemplate_propdefaultsfig_elelement_name
item_indextemplate_els                    r   r   r     sf             W^$$ 2 2:$-#D)**400	i!233 (	!'<>>>> % $	#9:: #	w #	 $\ 2 2%J%J8I%J%J%J"$0crcZ1G$H!! O O%{ O55D{&<<<%;%A%A&+%N%N
&7
&C-fk4HHHH&,&6&6&8&8-fk4HHH)00===.55fkBBB #/FKK)&2GNNNN!2L# 	88G+<+< 	!(L $   	W2 2s   %F,,
F:9F:titletextc                    ddl m} ddlm} t	          | |          s ||           } |st                      }nt          |          }|                    d           t          j        |           }t          |j
        |j
        j        j
        |           i }t          |j                  D ]}|                    |j        d          }t          |j
        j        j        |j                           }t!          |          |k    r:|                    |                                           t!          |          |k    :||         }	t          ||	|           ||j
        j        j        |j        <   |dz   ||j        <   d}
|j
        j        j        D ]M|j
        j        j                 }fd|D             }t'          |          rd	|j
        j        j        <   Kd
}
N|
sd	|j
        j        _        |S )a"
  
    Return a copy of a figure where all styling properties have been moved
    into the figure's template.  The template property of the resulting figure
    may then be used to set the default styling of other figures.

    Parameters
    ----------
    fig
        Figure object or dict representing a figure
    skip
        A collection of names of properties to skip when moving properties to
        the template. Defaults to ('title', 'text') so that the text
        of figure titles, axis titles, and annotations does not become part of
        the template

    Examples
    --------
    Imports

    >>> import plotly.graph_objs as go
    >>> import plotly.io as pio

    Construct a figure with large courier text

    >>> fig = go.Figure(layout={'title': 'Figure Title',
    ...                         'font': {'size': 20, 'family': 'Courier'},
    ...                         'template':"none"})
    >>> fig # doctest: +NORMALIZE_WHITESPACE
    Figure({
        'data': [],
        'layout': {'font': {'family': 'Courier', 'size': 20},
                   'template': '...', 'title': {'text': 'Figure Title'}}
    })

    Convert to a figure with a template. Note how the 'font' properties have
    been moved into the template property.

    >>> templated_fig = pio.to_templated(fig)
    >>> templated_fig.layout.template
    layout.Template({
        'layout': {'font': {'family': 'Courier', 'size': 20}}
    })
    >>> templated_fig
    Figure({
        'data': [], 'layout': {'template': '...', 'title': {'text': 'Figure Title'}}
    })


    Next create a new figure with this template

    >>> fig2 = go.Figure(layout={
    ...     'title': 'Figure 2 Title',
    ...     'template': templated_fig.layout.template})
    >>> fig2.layout.template
    layout.Template({
        'layout': {'font': {'family': 'Courier', 'size': 20}}
    })

    The default font in fig2 will now be size 20 Courier.

    Next, register as a named template...

    >>> pio.templates['large_courier'] = templated_fig.layout.template

    and specify this template by name when constructing a figure.

    >>> go.Figure(layout={
    ...     'title': 'Figure 3 Title',
    ...     'template': 'large_courier'}) # doctest: +ELLIPSIS
    Figure(...)

    Finally, set this as the default template to be applied to all new figures

    >>> pio.templates.default = 'large_courier'
    >>> fig = go.Figure(layout={'title': 'Figure 4 Title'})
    >>> fig.layout.template
    layout.Template({
        'layout': {'font': {'family': 'Courier', 'size': 20}}
    })

    Returns
    -------
    go.Figure
    r   )
BaseFigure)Figureuid)r      Fc                 D    g | ]}|                                 d ik    S )type)to_plotly_json)r   tracers   s     r   r   z to_templated.<locals>.<listcomp>  s/    WWWuE((**vz.BBWWWr   NT)plotly.basedatatypesr   plotly.graph_objsr   r0   r   addcopydeepcopyr   layoutr?   ri   rn   getr   r   r<   r   all)figr   r   r   templated_figtrace_type_indexesr   template_indextemplate_tracestemplate_traceany_non_emptytracesis_emptyrs   s                @r   to_templatedr   ]  s<   n 0/////((((((c:&& fSkk  uu4yy 	HHUOOO M#&&M m2;B   
 m()) < <+//
A>> }3<A%*MNN/""n44""5??#4#4555 /""n44
 )8 	e^$???? :I%*5:6 *8!);5:&& M#*38 ! !
%.3J?WWWWPVWWWx== 	!=AM ).z:: MM  2-1%*r   )r   )rg   r7   r   r4   r:   	functoolsr   mathr   ImportError	fractionsobjectr   r   r.   r   r   r}   r   r   <module>r      s      				           vxx
v v v v vf v v vv O	
C C CLS S S S S Ss   # 11