
    e#              
          d dl mZ d dlZd dlZd dlmZ ddlmZm	Z	 ddl
mZ ddl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e	          Z ededdedddg          Z ej        e            G d de          ZdS )    )CallableN)cartesian_to_axial   )	Dimension	Operation)
Compositor)isfinite	max_range)HexTiles)dim   )ColorbarPlot)BokehOverlaySelectionDisplay)base_propertiesfill_propertiesline_propertiesc                       e Zd ZdZ ej        ej        ee	fd          Z
 ej        dee	f          Z ej        d          Z ej        d          Z ej        d	d
d	g          Z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
    usable.
    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                    | j         j        | j         j        | j         j        }}}| j         j        rddgnddg}fd|D             \  \  }}\  }	}
t          |t                    r|\  }}n||}}||z
  |z  dz  }|
|	z
  |z  dz  }| j        dk    r|n|}t          |          rt          |          r|dk    s||z  }nd}fd|D             \  }}t          |          s	                    g           S t          |          t          |          z  }||         ||         }}t          ||||dz   |          \  }}||f}|t          j        u r&t          j        }t          j        |d          f}dg}n8j        st!          d	          j        }t          fd
|D                       }||z   }fd|D             \  }}|	                    ||f          |	                    |	|
f          }}| j         j        r||gn||g}	                    |||                              |          }| j         j        +| j         j        dk    r|d d d d | j         j        d f         }|j        ||j        |i|_        |S )Nr   r   c              3   B   K   | ]}                     |          V  d S Nrange.0ielements     Blib/python3.11/site-packages/holoviews/plotting/bokeh/hex_tiles.py	<genexpr>z'hex_binning._process.<locals>.<genexpr>,   s/      @@1gmmA..@@@@@@    UUUUUU?r   c              3   B   K   | ]}                     |          V  d S r   dimension_valuesr"   s     r&   r'   z'hex_binning._process.<locals>.<genexpr>:   s1      ==((++======r(   topCountz<HexTiles aggregated by value must define a value dimensions.c              3   B   K   | ]}                     |          V  d S r   r+   )r#   vdimr%   s     r&   r'   z'hex_binning._process.<locals>.<genexpr>L   s1      LLd733D99LLLLLLr(   c              3   B   K   | ]}                     |          V  d S r   )get_dimensionr"   s     r&   r'   z'hex_binning._process.<locals>.<genexpr>P   s1      <<q'''**<<<<<<r(   r    )kdimsvdims)function)pgridsize
aggregatororientationinvert_axes
isinstancetupler	   lencloner   npsizesum	full_liker4   
ValueError	aggregate	min_countnamecdims) selfr%   keyr7   r8   r9   indexesx0x1y0y1sxsyxsizeysizer@   scalexyfiniteqrcoordsvaluesr4   dataxdydxdnydnr3   aggs     `                              r&   _processzhex_binning._process'   s   ,0FOTV=NPTPVPbk* !F.:1a&&QF@@@@@@@R(2rh&& 	(FBxBR%g&R%g&(F22uuE?? 	x 	uzz%KEEE >===W===11vv 	%==$$$!x{{*y!F)1!!Qk%.?GG1A   Jl1a((*FIEE 	M : ; ; ; MELLLLeLLLLLF <<<<G<<<B882r(8++RXXRHX-E-ES"f0@c

sCjMM$e5M99Y
Y++ 	 6'DF,<q,@,@aaaDF,---.CWc27C0	
r(   r   )__name__
__module____qualname____doc__paramClassSelectorr?   r@   r   r<   r8   intr7   Booleanr:   NumberrE   ObjectSelectorr9   ra    r(   r&   r   r      s          %$5 1 8  J #u"2sElCCCH%-...KT***I&%&x&(ASTTTK3 3 3 3 3 3r(   r   r   r[   Tbokeh)output_typetransfer_optionstransfer_parametersbackendsc                       e Zd Z ej        ej        eefd          Z	 ej        de
efd          Z ej        dd          Z ej        dd	dgd
          Z ej        dee
fdd          Z ej        ddd          Z ej        ddd          Z ej        dee
fdd          Z e            Zeez   ez   ddgz   Zeddgz   Z ed          Zd  fd	Zd Zd Z  x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   
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   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.cmaprS   	line_dashhex_tile)singlecombinedc                    |j         d d         \  }}|j        ||j                 d<   |j        ||j                 d<   |j                            |j                  }|rS|j        |v rJ|j        ||j                 d<   t          |j        ||j                 d         g          ||j                 d<   |j                            |j                  }|rS|j        |v rJ|j        ||j                 d<   t          |j        ||j                 d         g          ||j                 d<   t                                          |||          S )Nrt   r[   hardsoft)	r3   r!   rF   rG   getr
   
soft_rangesuperget_extents)
rH   r%   ranges
range_typekwargsxdimydimr\   r]   	__class__s
            r&   r   zHexTilesPlot.get_extents   s1   ]2A2&
d$(Jty&!$(Jty&!]ty)) 	^$)v%%(*F49f%(12=&BSTZB[2\(](]F49f%]ty)) 	^$)v%%(*F49f%(12=&BSTZB[2\(](]F49f%ww""7FJ???r(   c                 `    | j         t          j        u rt          d          g}n|j        }|i fS )Nr.   )r8   r?   r@   r   r4   )rH   r%   dimss      r&   _hover_optszHexTilesPlot._hover_opts   s3    ?bg%%g&&'DD=DRxr(   c                    ddd}t                    s
g g d}|||fS fdt          d          D             \  }}| j        rj        d d d         nj        \  }}	|j        |	j        c\  }
}\  }}t	          | j        t                    r| j        \  }}n| j        | j        }}||
z
  |z  dz  }||z
  |z  dz  }| j        dk    r|n|}||z  }||d}|                     ||          \  }}|	                    |           |	                    |           | j
        <| j
        d	k    r1|d
         d         }| j
        |_        |j        d	         | j        _        |                     |j                   | j        dz   |d<   ||d<   ||d<                       | j                  }|                    d          }|rJt	          |t(                    r|v st	          |t*                    r| j                            d           d }|                    |          }| j        t4          j        u r|                                }d	}n(|                                }|                                }| j        | j         k    rtC          d          | j         | j        z
  }d|d<   ||z
  |z  |z  | j        z   |d<   |||fS )NrW   rX   )rW   rX   c              3   B   K   | ]}                     |          V  d S r   r+   r"   s     r&   r'   z(HexTilesPlot.get_data.<locals>.<genexpr>   s1      >>((++>>>>>>r(   rt   r)   r   r   color	transformr-   r9   r@   aspect_scalerS   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!   r:   r3   r;   r7   r<   r9   _get_color_dataupdaterE   lowpalettestatebackground_fill_color_get_hover_datar4   r2   
size_indexr   strdim_transformrf   warningr,   r8   r?   r@   maxptpmin	min_scale	max_scalerC   )rH   r%   r   stylemappingr[   rW   rX   rT   rU   rK   rL   rM   rN   rO   rP   rQ   rR   r@   rS   cdatacmappingcmapper	scale_dimsizesr   baselines    `                         r&   get_datazHexTilesPlot.get_data   s   #&&7|| 	("%%D%''>>>>U1XX>>>1&*&6Iw}TTrT""GM1WagR(2rdmU++ 	2]FB]DMBR%g&R%g&(F22uueQ..wFFxEx   >%$.A*=*=w'4G.GK/6q/ADJ,T7GM:::#/5mf %n))$/::			'"" 	Juc22 	u7G7G%e];; 8HJ  T U U UI ,,Y77E"'))iikkiikk 99;;~..  "= > > >NT^3E&GG$x/36%?4>QDMWe##r(   )r{   )"rb   rc   rd   rf   rg   r?   r@   r   r<   r8   rh   r7   rj   rE   rk   r9   r   color_indexr   r   r   r   selection_displayr   r   r   
style_opts_nonvectorized_stylesdict_plot_methodsr   r   r   __classcell__)r   s   @r&   rs   rs   d   s       $$5 1 8  J #u"2sEl I- . . .H T 0, - - -I '%&x&(AS,PQ Q QK &%%ac
15 <QR R RK S AF G G GI Qy ?F G G GI %$T3*04 ;EF F FJ 5466 ?2_DPWGXXJ+v{.CCD
+++M@ @ @ @ @ @  5$ 5$ 5$ 5$ 5$ 5$ 5$r(   rs   )collections.abcr   numpyr?   rf   bokeh.util.hexr   corer   r   core.optionsr   	core.utilr	   r
   r%   r   util.transformr   r   r   	selectionr   stylesr   r   r   r   
compositorregisterrs   rl   r(   r&   <module>r      s   $ $ $ $ $ $      - - - - - - ( ( ( ( ( ( ( ( & & & & & & , , , , , , , ,       2 2 2 2 2 2 ! ! ! ! ! ! 3 3 3 3 3 3 E E E E E E E E E EI I I I I) I I IX ZT6xtwi  
 
 J   }$ }$ }$ }$ }$< }$ }$ }$ }$ }$r(   