B
    &[_[&                 @   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-install-l29rncou/plotly/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	enumerate)r   r   r   r   _argmin
   s    r   c             C   s   t t| dd ddd d S )Nc             S   s   | d S )Nr
   r   )r   r   r   r   r      r   z_argmax.<locals>.<lambda>T)r   reverser   )r   r   )r   r   r   r   _argmax   s    r   c             C   s   t | |||ddS )z Default annotation parameters F)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)   r,   r-   r.   r   ZvrectZhrectzInvalid annotation position %s)r$   r   r   r0   r/   r	   r   )r1   r2   r!   r%   r&   r'   r(   r#   r   r   r   annotation_params_for_recth   sp    



r<   c       
         s   d t  }tt fdd| }| dkr>t |dkr>dS | dkrLt } x.|D ]&}|dkr`qR||d }|| | |< qRW d}d| kr|d }|drt|||}	n|drt|||}	x0|	 D ]$}|| ks| | dkr|	| | |< qW | 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<   )

annotationr1   r2   kwargsZ
len_prefixZannotation_keysr>   Zsubkr@   Z
shape_dictr   )r?   r   axis_spanning_shape_annotation   s2    



rH   c             C   sJ   t  }t  }x4|  D ](}||r2| | ||< q| | ||< qW ||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   rD   r=   )dr?   Z	no_prefixZwith_prefixr>   r   r   r   split_dict_by_key_prefix   s    
rJ   N)F)
r	   r   r   r   r   r$   r;   r<   rH   rJ   r   r   r   r   <module>   s   

AA@