U
    Y»{jY&  ã                   @   sV   d d„ Z dd„ Zdd„ Zdd„ Zdd	„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Z	dS )c                 C   s(   t | ƒdkrtdƒ‚tt| ƒƒt | ƒ S )Né    zx must have positive length)ÚlenÚ
ValueErrorÚfloatÚsum©Úx© r   úU/var/www/html/bwave/python/venv/lib/python3.8/site-packages/plotly/shapeannotation.pyÚ_mean   s    r
   c                 C   s   t t| ƒdd„ d�d d S )Nc                 S   s   | d S ©Né   r   ©Útr   r   r	   Ú<lambda>   ó    z_argmin.<locals>.<lambda>)Úkeyr   ©ÚsortedÚ	enumerater   r   r   r	   Ú_argmin
   s    r   c                 C   s   t t| ƒdd„ dd�d d S )Nc                 S   s   | d S r   r   r   r   r   r	   r      r   z_argmax.<locals>.<lambda>T)r   Úreverser   r   r   r   r   r	   Ú_argmax   s    r   c                 C   s   t | |||dd�S )zDefault annotation parametersF)ÚxanchorÚyanchorr   ÚyZ	showarrow)Údict)r   r   r   r   r   r   r	   Ú_df_anno   s    r   c                 C   s   d| ksd| ks|   d¡ | S )NÚinsideÚoutside)Úadd)Úposr   r   r	   Ú_add_inside_to_position   s    
r!   Fc                 C   s2   | d krd} | }t |  d¡ƒ} |r*t| ƒ} | |fS )Nz	top rightú )ÚsetÚsplitr!   )ÚpositionÚprepend_insideÚpos_strr   r   r	   Ú_prepare_position   s    r(   c                 C   sê  |d }|d }|d }|d }||g}||g}d}	d}
d}d}d	}d
}t |ƒ}t|ƒ}t|ƒ}t|ƒ}t|ƒ}t |ƒ}t|ƒ}t|ƒ}t|ƒ}t|ƒ}t|ƒ\}}| dk�r¾|tddgƒkrÐt|	|
|| |ƒS |tddgƒkròt||
|| |ƒS |tdgƒk�rt|||| |ƒS |td	dgƒk�r8t|	||| |ƒS |td	dgƒk�r\t|||| |ƒS |td	gƒk�r~t||
|| |ƒS |tdgƒk�rœt|	|||ƒS |tdgƒk�rØt||||ƒS �n| dk�rØ|tddgƒk�rìt||||| ƒS |tddgƒk�rt|	|||| ƒS |tdgƒk�r.t||||ƒS |td	dgƒk�rRt||
||| ƒS |td	dgƒk�rvt|	|
||| ƒS |td	gƒk�r”t||
||ƒS |tdgƒk�r¶t|	|||| ƒS |tdgƒk�rØt||||| ƒS td|f ƒ‚d S )NÚx0Úx1Úy0Úy1ÚrightÚtopÚleftÚcenterÚbottomÚmiddleZvlineZhlinez Invalid annotation position "%s")	ÚmaxÚminr
   r   r   r(   r#   r   r   )Ú
shape_typeÚ
shape_argsr%   r)   r*   r+   r,   ÚXÚYÚRÚTÚLÚCÚBÚMZaYZiYZeYZaaYZaiYZaXZiXZeXZaaXZaiXr'   r   r   r	   Úannotation_params_for_line'   st    

r?   c                 C   sè  |d }|d }|d }|d }t |dd�\}}|tddd	gƒkr`td	dt||gƒt||gƒƒS |tddd
gƒkr�td
dt||gƒt||gƒƒS |tddgƒkr¾tddt||gƒt||gƒƒS |tddd	gƒkrîtd	dt||gƒt||gƒƒS |tddd
gƒk�r td
dt||gƒt||gƒƒS |tddgƒk�rPtddt||gƒt||gƒƒS |tdd	gƒk�r€td	dt||gƒt||gƒƒS |tdd
gƒk�r°td
dt||gƒt||gƒƒS |tdgƒk�rÞtddt||gƒt||gƒƒS |tddd	gƒk�r,t| dk�rd
nd	| dk�rdndt||gƒt||gƒƒS |tddd
gƒk�rzt| dk�rPd	nd
| dk�r`dndt||gƒt||gƒƒS |tddgƒk�rªtddt||gƒt||gƒƒS |tddd	gƒk�røt| dk�rÎd
nd	| dk�rÞdndt||gƒt||gƒƒS |tddd
gƒk�rFt| dk�rd	nd
| dk�r,dndt||gƒt||gƒƒS |tddgƒk�rvtddt||gƒt||gƒƒS |tdd	gƒk�r¦td
dt||gƒt||gƒƒS |tdd
gƒk�rÖtd	dt||gƒt||gƒƒS td|f ƒ‚d S )Nr)   r*   r+   r,   T)r&   r   r.   r/   r-   r0   r1   r2   r   ZvrectZhrectzInvalid annotation position %s)r(   r#   r   r4   r3   r
   r   )r5   r6   r%   r)   r*   r+   r,   r'   r   r   r	   Úannotation_params_for_recth   sx    

ü

ü

ü

ür@   c           
         sð   d‰ t ˆ ƒ}tt‡ fdd„| ¡ ƒƒ}| dkr>t |ƒdkr>dS | dkrLtƒ } |D ]&}|dkr^qP||d… }|| | |< qPd}d| ¡ kr�|d }| d¡r¨t|||ƒ}	n| d¡r¾t|||ƒ}	|	 ¡ D ]$}|| ksÞ| | dkrÆ|	| | |< qÆ| S )	a8  
    annotation: a go.layout.Annotation object, a dict describing an annotation, or None
    shape_type: one of 'vline', 'hline', 'vrect', 'hrect' and determines how the
                x, y, xanchor, and yanchor values are set.
    shape_args: the parameters used to draw the shape, which are used to place the annotation
    kwargs:     a dictionary that was the kwargs of a
                _process_multiple_axis_spanning_shapes spanning shapes call. Items in this
                dict whose keys start with 'annotation_' will be extracted and the keys with
                the 'annotation_' part stripped off will be used to assign properties of the
                new annotation.

    Property precedence:
    The annotation's x, y, xanchor, and yanchor properties are set based on the
    shape_type argument. Each property already specified in the annotation or
    through kwargs will be left as is (not replaced by the value computed using
    shape_type). Note that the xref and yref properties will in general get
    overwritten if the result of this function is passed to an add_annotation
    called with the row and col parameters specified.

    Returns an annotation populated with fields based on the
    annotation_position, annotation_ prefixed kwargs or the original annotation
    passed in to this function.
    Zannotation_c                    s
   |   ˆ ¡S )N)Ú
startswith)Úk©Úprefixr   r	   r   Ä   r   z0axis_spanning_shape_annotation.<locals>.<lambda>Nr   Úannotation_positionÚlineÚrect)r   ÚlistÚfilterÚkeysr   Úendswithr?   r@   )
Ú
annotationr5   r6   ÚkwargsZ
len_prefixZannotation_keysrB   ZsubkrE   Z
shape_dictr   rC   r	   Úaxis_spanning_shape_annotation©   s>    
  ÿ
  ÿrN   c                 C   sF   t ƒ }t ƒ }|  ¡ D ](}| |¡r0| | ||< q| | ||< q||fS )zë
    Returns two dictionaries, one containing all the items whose keys do not
    start with a prefix and another containing all the items whose keys do start
    with the prefix. Note that the prefix is not removed from the keys.
    )r   rJ   rA   )ÚdrD   Z	no_prefixZwith_prefixrB   r   r   r	   Úsplit_dict_by_key_prefixé   s    
rP   N)F)
r
   r   r   r   r!   r(   r?   r@   rN   rP   r   r   r   r	   Ú<module>   s   

AA@