a
    ~bC$                  
   @   s
  d dl mZmZmZ d dlZd dlZd dlZzd dlm	Z	 W n   dZ	Y n0 ddl
mZmZ ddlmZ ddlmZmZm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 G dd deZededdedddgdZ e!e  G dd deZ"dS )    )absolute_importdivisionunicode_literalsN)cartesian_to_axial   )	Dimension	Operation)
Compositor)
basestringisfinite	max_range)HexTiles)dim   )ColorbarPlot)BokehOverlaySelectionDisplay)base_propertiesline_propertiesfill_propertiesc                   @   sn   e Zd ZdZejejej	e
fddZejdee
fdZejddZejddZejd	d
d	gdZdddZdS )hex_binningz
    Applies hex binning by computing aggregates on a hexagonal grid.

    Should not be user facing as the returned element is not directly
    useable.
    z
      Aggregation function or dimension transform used to compute bin
      values. Defaults to np.size to count the number of values
      in each bin.defaultclass_doc2   )r   r   F)r   Npointyflat)r   objectsc                     sJ  | j j| j j| j j  }}}| j jr,ddgnddg} fdd|D \\}}\}	}
t|trf|\}}n
|| }}|| | d }|
|	 | d }| jdkr|n|}t|rt|r|dks|| }nd} fdd|D \}}t|s 	g S t|t|@ }|| ||  }}t
||||d |\}}||f}|tju rZtj}t|df}d	g}n. jsltd
n j}t fdd|D }|| } fdd|D \}}|j	||fd|j	|	|
fd }}| j jr||gn||g} j	|||dj|d}| j jd ur4| j jdkr4|d d d d | j jd f }|j||j|i|_|S )Nr   r   c                 3   s   | ]}  |V  qd S Nrange.0ielement Alib/python3.9/site-packages/holoviews/plotting/bokeh/hex_tiles.py	<genexpr>1       z'hex_binning._process.<locals>.<genexpr>UUUUUU?r   c                 3   s   | ]}  |V  qd S r   dimension_valuesr!   r$   r&   r'   r(   ?   r)   topCountz<HexTiles aggregated by value must define a value dimensions.c                 3   s   | ]}  |V  qd S r   r+   )r"   Zvdimr$   r&   r'   r(   Q   r)   c                 3   s   | ]}  |V  qd S r   )get_dimensionr!   r$   r&   r'   r(   U   r)   r   )kdimsvdims)function)pgridsize
aggregatororientationinvert_axes
isinstancetupler   lenZcloner   npsizesumZ	full_liker1   
ValueErrorZ	aggregate	min_countnamecdims) selfr%   keyr4   r5   r6   Zindexesx0x1y0y1sxsyxsizeysizer<   scalexyZfiniteqrZcoordsvaluesr1   dataxdydZxdnZydnr0   Zaggr&   r$   r'   _process,   sN    





"zhex_binning._process)N)__name__
__module____qualname____doc__paramClassSelectorr;   r<   typesFunctionTyper9   r5   intr4   ZBooleanr7   Numberr?   ObjectSelectorr6   rU   r&   r&   r&   r'   r      s   r   r   rR   TZbokeh)Zoutput_typeZtransfer_optionsZtransfer_parametersZbackendsc                       s   e Zd Zejejeje	fddZ
ejdee	fddZejdddZejdd	dgd
dZejdeefdddZejddddZejddddZejdeefdddZe Zee e ddg Zeddg ZeddZd# fdd	Zdd  Z d!d" Z!  Z"S )$HexTilesPlotz
      Aggregation function or dimension transform used to compute
      bin values.  Defaults to np.size to count the number of values
      in each bin.r   r   a  
      Number of hexagonal bins along x- and y-axes. Defaults to uniform
      sampling along both axes when setting and integer but independent
      bin sampling can be specified a tuple of integers corresponding to
      the number of bins along each axis.Nzq
      The display threshold before a bin is shown, by default bins with
      a count of less than 1 are hidden.)r   r   r   r   zM
      The orientation of hexagon bins. By default the pointy side is on top.)r   r   r      TzN
        Deprecated in favor of color style mapping, e.g. `color=dim('color')`)r   r   Z
allow_Noner   g?)r   Na  
      When size_index is enabled this defines the maximum size of each
      bin relative to uniform tile size, i.e. for a value of 1, the
      largest bin will match the size of bins when scaling is disabled.
      Setting value larger than 1 will result in overlapping bins.)r   Zboundsr   r   a  
      When size_index is enabled this defines the minimum size of each
      bin relative to uniform tile size, i.e. for a value of 1, the
      smallest bin will match the size of bins when scaling is disabled.
      Setting value larger than 1 will result in overlapping bins.zB
      Index of the dimension from which the sizes will the drawn.ZcmaprL   Z	line_dashZhex_tile)Zsinglecombinedc                    s   |j d d \}}|j||j d< |j||j d< |j|j}|r|j|v r|j||j d< t|j||j d g||j d< |j|j}|r|j|v r|j||j d< t|j||j d g||j d< tt| 	|||S )Nrb   rR   ZhardZsoft)
r0   r    r@   rA   getr   Z
soft_rangesuperra   get_extents)rB   r%   rangesZ
range_typeZxdimZydimrS   rT   	__class__r&   r'   rf      s    ""zHexTilesPlot.get_extentsc                 C   s&   | j tju rtdg}n|j}|i fS )Nr.   )r5   r;   r<   r   r1   )rB   r%   Zdimsr&   r&   r'   _hover_opts   s    zHexTilesPlot._hover_optsc                    sJ  ddd}t  s&g g d}|||fS  fddtdD \}}| jrV jd d d n j\}}	|j|	j \}
}\}}t| jtr| j\}}n| j| j }}||
 | d }|| | d }| jd	kr|n|}|| }||d}|  ||\}}|	| |	| | j
d ur@| j
d
kr@|d d }| j
|_|jd
 | j_| |  j | jd |d< ||d< ||d<  | j}|d}|rt|tr| v st|tr| jd d }|d ur@ |}| jtju r| }d
}n| }| }| j| j krt!d| j | j }d|d< || | | | j |d< |||fS )NrO   rP   )rO   rP   c                 3   s   | ]}  |V  qd S r   r+   r!   r$   r&   r'   r(      r)   z(HexTilesPlot.get_data.<locals>.<genexpr>rb   r*   r   r   ZcolorZ	transformr-   r6   r<   Zaspect_scalerL   zbCannot declare style mapping for 'scale' option and declare a size_index; ignoring the size_index.z=min_scale parameter must be smaller than max_scale parameter.)"r:   r    r7   r0   r8   r4   r9   r6   Z_get_color_dataupdater?   ZlowZpalettestateZbackground_fill_colorZ_get_hover_datar1   r/   
size_indexrd   r
   dim_transformrZ   Zwarningr,   r5   r;   r<   maxptpmin	min_scale	max_scaler>   )rB   r%   rg   ZstylemappingrR   rO   rP   rM   rN   rD   rE   rF   rG   rH   rI   rJ   rK   r<   rL   ZcdataZcmappingZcmapperZ	scale_dimZsizesrq   Zbaseliner&   r$   r'   get_data   s\    


 





zHexTilesPlot.get_data)rc   )#rV   rW   rX   rZ   r[   r;   r<   r\   r]   r9   r5   r^   r4   r_   r?   r`   r6   r
   Zcolor_indexrt   rs   rn   r   Zselection_displayr   r   r   Z
style_optsZ_nonvectorized_stylesdictZ_plot_methodsrf   rj   rv   __classcell__r&   r&   rh   r'   ra   i   s.   
ra   )#Z
__future__r   r   r   r\   rZ   Znumpyr;   Zbokeh.util.hexr   corer   r   Zcore.optionsr	   Z	core.utilr
   r   r   r%   r   Zutil.transformr   ro   r   Z	selectionr   Zstylesr   r   r   r   Z
compositorregisterra   r&   r&   r&   r'   <module>   s,   
L

