U
    cY&                     @   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   :/tmp/pip-unpacked-wheel-fki0jwev/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rt|	|
|| |S |tddgkrt||
|| |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rt|	|||S |tdgkrt||||S n| dkr|tddgkrt||||| 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rt||
||S |tdgkrt|	|||| S |tdgkrt||||| 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rtd
dt||gt||gS |tddgkrtddt||gt||gS |tddd	gkrt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rtd	dt||gt||gS |tdd
gkrtd
dt||gt||gS |tdgkrt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rtddt||gt||gS |tddd	gkrt| dkrd
nd	| dkrd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rtd
dt||gt||gS |tdd
gkrt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rt|||}	n|drt|||}	|	 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lineZ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>    
  
  rM   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   rI   rA   )drD   Z	no_prefixZwith_prefixrB   r   r   r	   split_dict_by_key_prefix   s    
rO   N)F)
r
   r   r   r   r!   r(   r?   r@   rM   rO   r   r   r   r	   <module>   s   

AA@