o
    Uh'                     @  s@  d dl mZ d dlmZmZmZ d dlZd dlmZm	Z	m
Z
 d dlmZ d dlZd dlZd dl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mZmZmZmZ d dlm Z  G dd dZ!e
e"e!f Z#e
e$e!f Z%e
e&e!f Z'e
e$e(e!f Z)e
e$eee!f Z*eG dd dZ+d#ddZ,		d$d%dd Z-d!d" Z.dS )&    )annotations)	dataclassfieldsfieldN)AnyCallableUnion)	Generator)ndarray)	DataFrame)Artist)Scale)
PROPERTIESProperty	RGBATupleDashPatternDashPatternWithOffset)PlotSpecErrorc                   @  sT   e Zd Z					ddddZdd ZedddZedddZedddZdS )MappableNFTvalr   depend
str | Nonercautoboolgroupingc                 C  sL   |dur
|t v s
J |dur|tjv sJ || _|| _|| _|| _|| _dS )a  
        Property that can be mapped from data or set directly, with flexible defaults.

        Parameters
        ----------
        val : Any
            Use this value as the default.
        depend : str
            Use the value of this feature as the default.
        rc : str
            Use the value of this rcParam as the default.
        auto : bool
            The default value will depend on other parameters at compile time.
        grouping : bool
            If True, use the mapped variable to define groups.

        N)r   mplrcParams_val_rc_depend_auto	_grouping)selfr   r   r   r   r    r$   G/var/www/vscode/kcb/lib/python3.10/site-packages/seaborn/_marks/base.py__init__   s   
zMappable.__init__c                 C  sn   | j durdt| j  d}|S | jdurd| j d}|S | jdur,d| j d}|S | jr3d}|S d}|S )z?Nice formatting for when object appears in Mark init signature.N<>z<depend:z<rc:z<auto>z<undefined>)r   reprr    r   r!   )r#   sr$   r$   r%   __repr__?   s   
	

zMappable.__repr__returnc                 C     | j S )z>Return the name of the feature to source a default value from.)r    r#   r$   r$   r%   r   M   s   zMappable.dependc                 C  r-   N)r"   r.   r$   r$   r%   r   R   s   zMappable.groupingc                 C  s,   | j dur| j S | jdurtj| jS dS )zGGet the default value for this feature, or access the relevant rcParam.N)r   r   r   r   getr.   r$   r$   r%   defaultV   s
   

zMappable.default)NNNFT)
r   r   r   r   r   r   r   r   r   r   )r,   r   )r,   r   )	__name__
__module____qualname__r&   r+   propertyr   r   r1   r$   r$   r$   r%   r      s    $r   c                   @  sh   e Zd ZU dZeedZded< edd Z	edd Z
		d#d$ddZd%ddZd&ddZd'd!d"Zd	S )(Markz4Base class for objects that visually represent data.)default_factorydict
artist_kwsc                   s    fddt  D S )Nc                   s(   i | ]}t |jtr|jt |jqS r$   )
isinstancer1   r   namegetattr.0fr.   r$   r%   
<dictcomp>p   s    
z(Mark._mappable_props.<locals>.<dictcomp>r   r.   r$   r.   r%   _mappable_propsn   s   
zMark._mappable_propsc                 C  s   dd t | D S )Nc                 S  s&   g | ]}t |jtr|jjr|jqS r$   )r:   r1   r   r   r;   r=   r$   r$   r%   
<listcomp>y   s    
z(Mark._grouping_props.<locals>.<listcomp>rA   r.   r$   r$   r%   _grouping_propsu   s   zMark._grouping_propsNdataDataFrame | dict[str, Any]r;   strscalesdict[str, Scale] | Noner,   r   c              
   C  sJ  | j | }t|t|}t|t }t|tj}|o |d }|dkr+|o*||v}|rD|	|}|r;|gt
| }|rBt|}|S ||v r|du sP||vrU|| }n"|| }	|| }
z|	|
}W n tyv } ztd||d}~ww |r~t|}|S |jdur| ||j|S |	|j}|r|gt
| }|rt|}|S )a  Obtain default, specified, or mapped value for a named feature.

        Parameters
        ----------
        data : DataFrame or dict with scalar values
            Container with data values for features that will be semantically mapped.
        name : string
            Identity of the feature / semantic.
        scales: dict
            Mapping from variable to corresponding scale object.

        Returns
        -------
        value or array of values
            Outer return type depends on whether `data` is a dict (implying that
            we want a single value) or DataFrame (implying that we want an array
            of values with matching length).

        stylewidthNzScaling operation)rB   r   r0   r   r:   r   pdr   endswithstandardizelennparray	Exceptionr   _duringasarrayr   _resolver1   )r#   rE   r;   rH   featurepropdirectly_specifiedreturn_multiplereturn_arrayscalevalueerrr1   r$   r$   r%   rU      sH   






zMark._resolvec                 C  s<   d|vrdn|d j }d|vrdn|d j }||krdS dS )Nxr   y)	_priority)r#   rH   r^   r_   r$   r$   r%   _infer_orient   s
   zMark._infer_orientsplit_generatorCallable[[], Generator]dict[str, Scale]orientNonec                 C  s   t  )z#Main interface for creating a plot.)NotImplementedError)r#   rb   rH   re   r$   r$   r%   _plot   s   z
Mark._plot	variables	list[str]r\   Artist | Nonec                 C  s   d S r/   r$   )r#   ri   r\   rH   r$   r$   r%   _legend_artist   s   zMark._legend_artistr/   )rE   rF   r;   rG   rH   rI   r,   r   )rH   r8   r,   rG   )rb   rc   rH   rd   re   rG   r,   rf   )ri   rj   r\   r   rH   rd   r,   rk   )r2   r3   r4   __doc__r   r8   r9   __annotations__r5   rB   rD   rU   ra   rh   rl   r$   r$   r$   r%   r6   h   s   
 


I
	r6   markrE   r   rH   rd   r,   dict[str, Any]c                   s    fddj D }|S )Nc                   s   i | ]
}|  |qS r$   )rU   )r>   r;   rE   ro   rH   r$   r%   r@      s    z&resolve_properties.<locals>.<dictcomp>)rB   )ro   rE   rH   propsr$   rq   r%   resolve_properties   s   rs    DataFrame | dictprefixrG   rI   RGBATuple | ndarrayc                 C  s   |  || d|}| d| jv r|  || d|}n|  |d|}ddd}t|dk rUtdd |D rUt|d	krEtj|S ||rK|ntj	}tj||S t|dkri|j
d
 d	kritj|S t||d
d|tj	}tj||S )a  
    Obtain a default, specified, or mapped value for a color feature.

    This method exists separately to support the relationship between a
    color and its corresponding alpha. We want to respect alpha values that
    are passed in specified (or mapped) color values but also make use of a
    separate `alpha` variable, which can be mapped. This approach may also
    be extended to support mapping of specific color channels (i.e.
    luminance, chroma) in the future.

    Parameters
    ----------
    mark :
        Mark with the color property.
    data :
        Container with data values for features that will be semantically mapped.
    prefix :
        Support "color", "fillcolor", etc.

    coloralphaNc                 S  s"   t | jjdkpt | |S )z5Detect "invisible" colors to set alpha appropriately.r?   )rP   rQ   dtypekindisfiniteall)r^   axisr$   r$   r%   visible  s   "zresolve_color.<locals>.visible   c                 s  s    | ]}t |tV  qd S r/   )r:   float)r>   r^   r$   r$   r%   	<genexpr>  s    z resolve_color.<locals>.<genexpr>      )r~   r/   )rU   rB   rP   ndimr}   rO   r   colorsto_rgbananshapeto_rgba_arraywhere)ro   rE   rv   rH   rx   ry   r   r$   r$   r%   resolve_color   s   
 r   c                 C  sv   dd t | D }ddtjddd |D dddd	g}| jd
}d
g |d d ||dd  }|| _| S )Nc                 S  s   g | ]}t |jtr|jqS r$   )r:   r1   r   r;   r=   r$   r$   r%   rC   ,  s    z'document_properties.<locals>.<listcomp>rt   z/    This mark defines the following properties:z, c                 S  s   g | ]}d | d qS )|r$   )r>   pr$   r$   r%   rC   1  s    N   z        )rK   initial_indentsubsequent_indent
r   )r   textwrapfilljoinrm   split)ro   
propertiestextdocstring_linesnew_docstringr$   r$   r%   document_properties*  s$   	

r   )ro   r6   rE   r   rH   rd   r,   rp   )rt   N)
ro   r6   rE   ru   rv   rG   rH   rI   r,   rw   )/
__future__r   dataclassesr   r   r   r   typingr   r   r   collections.abcr	   numpyrP   pandasrL   
matplotlibr   r
   r   matplotlib.artistr   seaborn._core.scalesr   seaborn._core.propertiesr   r   r   r   r   seaborn._core.exceptionsr   r   r   MappableBoolrG   MappableStringr   MappableFloattupleMappableColorMappableStyler6   rs   r   r   r$   r$   r$   r%   <module>   s6    G
8