B
    >Y20                 @   s   d Z ddlmZ 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mZmZmZ ddlmZmZmZmZmZ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# ddl$m%Z% e	dddZ&G dd de'Z(e( Z)G dd deZ*dS )a   This is the Bokeh charts interface. It gives you a high level API to build
complex plot is a simple way.

This is the main Chart class which is able to build several plots using the low
level Bokeh API. It setups all the plot characteristics and lets you plot
different chart types, taking OrderedDict as the main input. It also supports
the generation of several outputs (file, server, notebook).

    )absolute_import)defaultdictN)enumeration)AutoEitherEnumStringvalue)CategoricalAxisDatetimeAxisFactorRangeglyphsGrid	HoverToolLegend
LegendItem
LinearAxismarkersPlot)DEFAULT_TOOLS)_process_tools_arg_glyph_function_process_active_tools)CategoricalScale)_convert_responsivelinearcategoricaldatetimec               @   s   e Zd Zdd ZdS )ChartDefaultsc             C   s   t |tstd| t|jdd}t|jdd}xht||t|j D ]L}|dkrt| |d}t|dddkr||_	qPt
| |rPt||t| | qPW dS )zApply this defaults to a chart.zVChartsDefaults should be only used on Chart objects but it's being used on %s instead.T)Zinclude_defaultsFtools_toolsN)
isinstanceChart
ValueErrorsetZproperties_with_valueslist
difference__deprecated_attributes__getattrr    hasattrsetattr)selfZchartZ	all_propsZdirty_propskr	    r-   -lib/python3.7/site-packages/bkcharts/chart.pyapply   s    


zChartDefaults.applyN)__name__
__module____qualname__r/   r-   r-   r-   r.   r      s   r   c                   sx  e Zd ZdZdZd ZedddZedddZe	e
eeddZe	e
eeddZeZd	Zd
Zd
Zd
Zejjdd Zejjdd Zejjdd Z fddZdd Zdd Zdd Z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-d. Z(e)e*j+Z,e)e*j-Z.e)e*j/Z0e)e1j2Z3e)e*j4Z5e)e1j6Z7e)e1j8Z9e)e1j:Z;e)e1j<Z=e)e1j>Z?e)e1j@ZAe)e*jBZCe)e*jDZEe)e*jFZGe)e*jHZIe)e*jJZKe)e1jLZMe)e*jNZOe)e*jPZQe)e*jRZSe)e*jTZUe)e*jVZWe)e*jXZYe)e*jZZ[e)e*j\Z]e)e*j^Z_e)e*j`Zae)e1jbZce)e1jdZee)e1jfZge)e*jhZie)e1jjZke)e*jlZme)e*jnZoe)e1jpZq  ZrS )0r"   zH The main Chart class, the core of the ``Bokeh.charts`` interface.

    r   Nz1
    A label for the x-axis. (default: None)
    )helpz1
    A label for the y-axis. (default: None)
    z3
    What kind of scale to use for the x-axis.
    z3
    What kind of scale to use for the y-axis.
    )filenameZserverZnotebookwidthZheightxgridygridZlegendbackground_fillZborder_fillZlogor   Ztitle_text_baselineZtitle_text_alignZtitle_text_alphaZtitle_text_colorZtitle_text_font_styleZtitle_text_font_sizeZtitle_text_fontZtitle_standoffTc             C   s   t d d S )Nz]Non-functional 'xgrid' setter has been removed; use 'xgrid' keyword argument to Chart instead)warningswarn)r+   r	   r-   r-   r.   r6   W   s    zChart.xgridc             C   s   t d d S )Nz]Non-functional 'ygrid' setter has been removed; use 'ygrid' keyword argument to Chart instead)r8   r9   )r+   r	   r-   r-   r.   r7   [   s    zChart.ygridc             C   s   t d d S )Nz_Non-functional 'legend' setter has been removed; use 'legend' keyword argument to Chart instead)r8   r9   )r+   r	   r-   r-   r.   legend_   s    zChart.legendc                st  | dd }x*dD ]"}||kr|| |d| < ||= qW d|krPd|krPtdd|krnt|d |d< |d= | dd| _| d	d| _| d
d| _| dd| _| dd }tt| j	|| || j
_t|  |d k	r|| _x&| jD ]}||krt| |||  qW g | _d| _g | _g | _tt| _tt| _tt| _g | _t| drp| | j| j| j| j| j d S )Nr   )r6   r7   r:   _Z
responsiveZsizing_modezTChart initialized with both 'responsive' and 'sizing_mode' supplied, supply only oneactive_dragautoactive_inspectactive_scroll
active_taptitleFr    )popr#   r   _active_drag_active_inspect_active_scroll_active_tapsuperr"   __init__rA   textdefaultsr/   r    r'   r*   Z_glyphsZ_built	_builders_renderer_mapr   r%   _ranges_labels_scales	_tooltipsr)   create_tools)r+   argskwargsr   nameZ
title_textr,   )	__class__r-   r.   rH   c   sB    





zChart.__init__c                s,   |  j |7  _ | j fdd|D  d S )Nc                s   i | ]} |j qS r-   )Z_id).0r)builderr-   r.   
<dictcomp>   s    z'Chart.add_renderers.<locals>.<dictcomp>)	renderersrL   extend)r+   rX   rZ   r-   )rX   r.   add_renderers   s    zChart.add_renderersc             C   s   | j | ||  d S )N)rK   appendZcreate)r+   rX   r-   r-   r.   add_builder   s    zChart.add_builderc             C   s   | j | | d S )N)rM   r]   )r+   dimranger-   r-   r.   
add_ranges   s    zChart.add_rangesc             C   s   | j | | d S )N)rN   r]   )r+   r_   labelr-   r-   r.   
add_labels   s    zChart.add_labelsc             C   s   | j | | d S )N)rO   r]   )r+   r_   scaler-   r-   r.   
add_scales   s    zChart.add_scalesc             C   s   |  j |7  _ d S )N)rP   )r+   tooltipsr-   r-   r.   add_tooltips   s    zChart.add_tooltipsc             C   s@   t | |d s.t| j| dkr.| j| d S t | |d S d S )Nrb   r   )r(   lenrN   )r+   r_   r-   r-   r.   _get_labels   s     zChart._get_labelsc             C   sH   |  dd| jd d | d| _|  dd| jd d | d| _d S )NxZbelowr   yleft)	make_axisrO   ri   _xaxis_yaxis)r+   r-   r-   r.   create_axes   s    "zChart.create_axesc             C   s,   |r|  d| jj |r(|  d| jj d S )Nr      )	make_gridrn   tickerro   )r+   r6   r7   r-   r-   r.   create_grids   s    zChart.create_gridsc             C   sb   t |tr|rt}nt |tr"dS t| jjdkr^t| |\}}| j|  t| j||||| dS )zCreate tools if given tools=True input.

        Only adds tools if given boolean and does not already have
        tools added to self.
        Nr   )	r!   boolr   rh   toolbarr   r   	add_toolsr   )r+   r   r<   r>   r?   r@   Z	tool_objsZtool_mapr-   r-   r.   rQ      s    

zChart.create_toolsc             C   s   |    | | j| j | jjr<| | j| j| j	| j
| j t| jdkr\| t| jd t| jtrpt | _t| jtrt | _dS )z&Add the axis, grids and tools
        r   )rf   N)rp   rt   _xgrid_ygridrv   r   rQ   r    rC   rD   rE   rF   rh   rP   rw   r   r!   Zx_ranger   r   Zx_scaleZy_rangeZy_scale)r+   r-   r-   r.   
start_plot   s    zChart.start_plotc             C   sh   d}| j dkrd}n| j }g }x*|D ]"}|tt|d |d d q$W |rdt||d}| | dS )a  Add the legend to your plot, and the plot to a new Document.

        It also add the Document to a new Session in the case of server output.

        Args:
            legends(List(Tuple(String, List(GlyphRenderer)): A list of
                tuples that maps text labels to the legend to corresponding
                renderers that should draw sample representations for those
                labels.
        NTZtop_leftr   rq   )rb   rZ   )locationitems)_legendr]   r   r	   r   
add_layout)r+   Zchart_legendsr{   r|   r:   r-   r-   r.   
add_legend   s    

"zChart.add_legendc             C   s   t | j| dkrtd| j| d }t| |d | |dkrTt|trPd}nd}|dkrht|d}n:|d	kr|t|d}n&|dkrtt	j
d
 |d}n
t|d}| || |S )a  Create linear, date or categorical axis depending on the location,
        scale and with the proper labels.

        Args:
            location(str): the space localization of the axis. It can be
                ``left``, ``right``, ``above`` or ``below``.
            scale (str): the scale on the axis. It can be ``linear``, ``datetime``
                or ``categorical``.
            label (str): the label on the axis.

        Return:
            Axis: Axis instance
        r   z)Ranges must be added to derive axis type.Z_ranger=   r   r   )
axis_labelr      )Zmajor_label_orientationr   )rh   rM   r#   r*   r!   r   r   r   r
   npZpir~   )r+   r_   r{   rd   rb   Z
data_rangeZaxisr-   r-   r.   rm      s$    

zChart.make_axisc             C   s   t ||d}| | |S )zCreate the grid just passing the axis and dimension.

        Args:
            dimension(int): the dimension of the axis, ie. xaxis=0, yaxis=1.
            ticker (obj): the axis.ticker object

        Return:
            Grid: A Grid instance
        )	dimensionrs   )r   r~   )r+   r   rs   Zgridr-   r-   r.   rr   !  s    
zChart.make_grid)TT)sr0   r1   r2   __doc__Z__view_model__Z__subtype__r   ZxlabelZylabelr   r   r   ScaleZxscaleZyscalerJ   Z	_defaultsr'   rx   ry   r}   r   r6   setterr7   r:   rH   r\   r^   ra   rc   re   rg   ri   rp   rt   rQ   rz   r   rm   rr   r   r   ZAnnularWedgeZannular_wedgeZAnnulusZannulusZArcZarcr   ZAsteriskZasteriskZBezierZbezierZCircleZcircleZCircleCrossZcircle_crossZCircleXZcircle_xZCrossZcrossZDiamondZdiamondZDiamondCrossZdiamond_crossZEllipseZellipseZHBarZhbarZImageZimageZ	ImageRGBAZ
image_rgbaZImageURLZ	image_urlZInvertedTriangleZinverted_triangleZLinelineZ	MultiLineZ
multi_lineZOvalZovalZPatchZpatchZPatchesZpatchesZQuadZquadZ	QuadraticZ	quadraticZRayZrayZRectZrectZSegmentZsegmentZSquareZsquareZSquareCrossZsquare_crossZSquareXZsquare_xZTextrI   ZTriangleZtriangleZVBarZvbarZWedgeZwedgeXrj   __classcell__r-   r-   )rU   r.   r"   2   s   

2
+

































r"   )+r   Z
__future__r   collectionsr   r8   Znumpyr   Zbokeh.core.enumsr   Zbokeh.core.propertiesr   r   r   r   r	   Zbokeh.modelsr
   r   r   r   r   r   r   r   r   r   r   Zbokeh.plottingr   Zbokeh.plotting.helpersr   r   r   Zbokeh.models.scalesr   Zbokeh.util._plot_arg_helpersr   r   objectr   rJ   r"   r-   r-   r-   r.   <module>	   s   4