a
    Dfz(                     @   s   d dl Zd dlZddlmZmZmZmZmZm	Z	 ddl
mZ ddlmZmZmZ ddlmZ G dd	 d	eeZG d
d deeZG dd deeZG dd deeZG dd deZG dd deeZG dd deeZG dd deeZG dd deZdS )    N   )Dataset	Dimension	Element2D	NdOverlayOverlayutil)process_dimensions   )Points
RectanglesVectorField)Selection1DExprc                       st   e Zd ZdZejedgdddZejd ddZ	ejedgd	d
dZ
dZdZdZd fdd	Z fddZ  ZS )Charta  
    A Chart is an abstract baseclass for elements representing one or
    more independent and dependent variables defining a 1D coordinate
    system with associated values. The independent variables or key
    dimensions map onto the x-axis while the dependent variables are
    usually mapped to the location, height or spread along the
    y-axis. Any number of additional value dimensions may be
    associated with a Chart.

    If a chart's independent variable (or key dimension) is numeric
    the chart will represent a discretely sampled version of the
    underlying continuously sampled 1D space. Therefore indexing along
    this variable will automatically snap to the closest coordinate.

    Since a Chart is a subclass of a Dataset it supports the full set
    of data interfaces but usually each dimension of a chart represents
    a column stored in a dictionary, array or DataFrame.
    x)r
   r   zW
        The key dimension(s) of a Chart represent the independent
        variable(s).defaultboundsdocTr   constantyr
   Nzm
        The value dimensions of the Chart, usually corresponding to a
        number of dependent variables.r
   Nc                    sN   | t|| t|dg | jd kr6| jd t j|fi | d S )Nkdimsr
   z4Chart elements should only be supplied a single kdim)	updater	   lenget_max_kdim_countparamwarningsuper__init__)selfdatar   vdimsparams	__class__ d/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/element/chart.pyr!   2   s    zChart.__init__c                    s   t  |S )N)r    __getitem__)r"   indexr&   r(   r)   r*   8   s    zChart.__getitem__)NN)__name__
__module____qualname____doc__r   Listr   r   Stringgroupr$   _auto_indexable_1dr   Z_Chart__abstractr!   r*   __classcell__r(   r(   r&   r)   r      s   r   c                   @   s   e Zd ZdZejd ddZdS )Scattera  
    Scatter is a Chart element representing a set of points in a 1D
    coordinate system where the key dimension maps to the points
    location along the x-axis while the first value dimension
    represents the location of the point along the y-axis.
    Tr   Nr,   r-   r.   r/   r   r1   r2   r(   r(   r(   r)   r5   <   s   r5   c                   @   s   e Zd ZdZejd ddZdS )Curvez
    Curve is a Chart element representing a line in a 1D coordinate
    system where the key dimension maps on the line x-coordinate and
    the first value dimension represents the height of the line along
    the y-axis.
    Tr   Nr6   r(   r(   r(   r)   r7   G   s   r7   c                       s\   e Zd ZdZejd dddZejededgdddZ	ej
d	d
dZd fdd	Z  ZS )	ErrorBarsa  
    ErrorBars is a Chart element representing error bars in a 1D
    coordinate system where the key dimension corresponds to the
    location along the x-axis and the first value dimension
    corresponds to the location along the y-axis and one or two
    extra value dimensions corresponding to the symmetric or
    asymmetric errors either along x-axis or y-axis. If two value
    dimensions are given, then the last value dimension will be
    taken as symmetric errors. If three value dimensions are given
    then the last two value dimensions will be taken as negative and
    positive errors. By default the errors are defined along y-axis.
    A parameter `horizontal`, when set `True`, will define the errors
    along the x-axis.
    TzS
        A string describing the quantity measured by the ErrorBars
        object.)r   r   r   r   Zyerrorr   )r   r   r   FzB
        Whether the errors are along y-axis (vertical) or x-axis.)r   r   c                    s   | j r
dnd}| |}| |}||kr|rt| r| |}| d}t|  dkrf| d}n|}t|| }	t|| }
|s|	|
fS t	
|	|
|j|jS t ||S )a  Return the lower and upper bounds of values along dimension.

        Range of the y-dimension includes the symmetric or asymmetric
        error.

        Args:
            dimension: The dimension to compute the range on.
            data_range (bool): Compute range from data values
            dimension_range (bool): Include Dimension ranges
                Whether to include Dimension range and soft_range
                in range calculation

        Returns:
            Tuple containing the lower and upper bound
        r   r
   r      )
horizontalZget_dimension_indexZget_dimensionr   Zdimension_valuesZ
dimensionsnpZnanminZnanmaxr   dimension_rangerangeZ
soft_ranger    )r"   ZdimZ
data_ranger<   Zdim_with_errZdidxmeanZ	neg_errorZ	pos_errorlowerupperr&   r(   r)   r=   l   s    



zErrorBars.range)TT)r,   r-   r.   r/   r   r1   r2   r0   r   r$   Booleanr:   r=   r4   r(   r(   r&   r)   r8   R   s   r8   c                   @   s   e Zd ZdZejd ddZdS )Spreada0  
    Spread is a Chart element representing a spread of values or
    confidence band in a 1D coordinate system. The key dimension(s)
    corresponds to the location along the x-axis and the value
    dimensions define the location along the y-axis as well as the
    symmetric or asymmetric spread.
    Tr   Nr6   r(   r(   r(   r)   rB      s   rB   c                   @   s6   e Zd ZdZejd ddZejedgddZ	dZ
dS )	Barsa,  
    Bars is a Chart element representing categorical observations
    using the height of rectangular bars. The key dimensions represent
    the categorical groupings of the data, but may also be used to
    stack the bars, while the first value dimension represents the
    height of each bar.
    Tr   r   )r
   r9   r   r   r9   N)r,   r-   r.   r/   r   r1   r2   r0   r   r   r   r(   r(   r(   r)   rC      s   rC   c                       sv   e Zd ZdZejdgdZejd ddZeje	dgddd	Z
eje	d
gddZdZ fddZedd Z  ZS )	Histograma5  
    Histogram is a Chart element representing a number of bins in a 1D
    coordinate system. The key dimension represents the binned values,
    which may be declared as bin edges or bin centers, while the value
    dimensions usually defines a count, frequency or density associated
    with each bin.
    Zgrid)r   Tr   r   r
   r
   zW
        Dimensions on Element2Ds determine the number of indexable
        dimensions.r   Z	Frequencyr   rD   c                    sd   |d u rg }t |trLt|dkrLt|d d t|d krL|d d d }t j|fi | d S )Nr   r   r
   )
isinstancetupler   r    r!   )r"   r#   r%   r&   r(   r)   r!      s    zHistogram.__init__c                 C   s   | j j| | jd ddS )zJProperty to access the Histogram edges provided for backward compatibilityr   T)edges)Z	interfaceZcoordsr   )r"   r(   r(   r)   rJ      s    zHistogram.edges)r,   r-   r.   r/   r   r0   datatyper1   r2   r   r   r$   Z_binnedr!   propertyrJ   r4   r(   r(   r&   r)   rE      s   	rE   c                   @   sD   e Zd ZdZejd ddZejedgddZ	ejg ddZ
dZd	S )
Spikesa  
    Spikes is a Chart element which represents a number of discrete
    spikes, events or observations in a 1D coordinate system. The key
    dimension therefore represents the position of each spike along
    the x-axis while the first value dimension, if defined, controls
    the height along the y-axis. It may therefore be used to visualize
    the distribution of discrete events, representing a rug plot, or
    to draw the strength some signal.
    Tr   r   rF   rD   )r   NFN)r,   r-   r.   r/   r   r1   r2   r0   r   r   r$   r3   r(   r(   r(   r)   rM      s
   
rM   c                   @   s,   e Zd ZdZejd ddZedddZdS )	Areaa  
    Area is a Chart element representing the area under a curve or
    between two curves in a 1D coordinate system. The key dimension
    represents the location of each coordinate along the x-axis, while
    the value dimension(s) represent the height of the area or the
    lower and upper bounds of the area between curves.

    Multiple areas may be stacked by overlaying them an passing them
    to the stack method.
    Tr   Baselinec                    s*  t |s|S t|t}|r0tdd t|D }|jdd}tt|j} fdd|D }d}|j	dd	}t |d
kr|d }t
|j|dd|D ]~\\}	}
}|d }|
|j|jddd}
|du rd|
 < n|
|j | |
|j< ||
 < |
|j }||	 j	|
|d||	< q|r&t| S |S )z
        Stacks an (Nd)Overlay of Area or Curve Elements by offsetting
        their baselines. To stack a HoloMap or DynamicMap use the map
        method.
        c                 S   s   i | ]\}}||qS r(   r(   ).0ielr(   r(   r)   
<dictcomp>       zArea.stack.<locals>.<dictcomp>T)Zmulti_indexc                    s   g | ]}|j d   gqS )r   r$   )rP   rR   baseline_namer(   r)   
<listcomp>   rT   zArea.stack.<locals>.<listcomp>NF)Zshared_datar
   r   )levelsortrG   )r+   Z
fill_valuerU   )r   rH   r   r   	enumerateZdframelistr=   ZndimsclonezipgroupbyZ	droplevelZreindexr+   uniquenamevalues)clsZareasrW   Z
is_overlayZdflevelsr$   ZbaselineZstackedkeyZsdfZelement_vdimsZvdimr(   rV   r)   stack   s,    
 

z
Area.stackN)rO   )	r,   r-   r.   r/   r   r1   r2   classmethodrf   r(   r(   r(   r)   rN      s   rN   )numpyr;   r   corer   r   r   r   r   r   Zcore.dimensionr	   Zgeomr   r   r   Z	selectionr   r   r5   r7   r8   rB   rC   rE   rM   rN   r(   r(   r(   r)   <module>   s    .<$