ó
ÍÅ>Yc           @@  sY  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& d e' f d „  ƒ  YZ( e( ƒ  Z) d e f d „  ƒ  YZ* d S(   s   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).

i    (   t   absolute_import(   t   defaultdictN(   t   enumeration(   t   Autot   Eithert   Enumt   Stringt   value(   t   CategoricalAxist   DatetimeAxist   FactorRanget   glyphst   Gridt	   HoverToolt   Legendt
   LegendItemt
   LinearAxist   markerst   Plot(   t   DEFAULT_TOOLS(   t   _process_tools_argt   _glyph_functiont   _process_active_tools(   t   CategoricalScale(   t   _convert_responsivet   lineart   categoricalt   datetimet   ChartDefaultsc           B@  s   e  Z d  „  Z RS(   c         C@  só   t  | t ƒ s" t d | ƒ ‚ n  t | j d t ƒ ƒ } t | j d t ƒ ƒ } xš t | j | ƒ ƒ t | j	 ƒ D]v } | d k rÀ t
 |  | t ƒ } t
 | d d ƒ d k rë | | _ që qu t |  | ƒ ru t | | t
 |  | ƒ ƒ qu qu Wd S(   s   Apply this defaults to a chart.sV   ChartsDefaults should be only used on Chart objects but it's being used on %s instead.t   include_defaultst   toolst   _toolsN(   t
   isinstancet   Chartt
   ValueErrort   sett   properties_with_valuest   Truet   Falset   listt
   differencet   __deprecated_attributes__t   getattrt   NoneR   t   hasattrt   setattr(   t   selft   chartt	   all_propst   dirty_propst   kR   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   apply   s    (   t   __name__t
   __module__R3   (    (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyR      s   R!   c           B@  sk  e  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 e Z e Z e Z e j j d „  ƒ Z e j j d „  ƒ Z e j j d „  ƒ Z d „  Z d „  Z d  „  Z d! „  Z d" „  Z d# „  Z  d$ „  Z! d% „  Z" d& „  Z# e e d' „ Z$ d( „  Z% d) „  Z& d* „  Z' d+ „  Z( d, „  Z) e* e+ j, ƒ Z- e* e+ j. ƒ Z/ e* e+ j0 ƒ Z1 e* e2 j3 ƒ Z4 e* e+ j5 ƒ Z6 e* e2 j7 ƒ Z8 e* e2 j9 ƒ Z: e* e2 j; ƒ Z< e* e2 j= ƒ Z> e* e2 j? ƒ Z@ e* e2 jA ƒ ZB e* e+ jC ƒ ZD e* e+ jE ƒ ZF e* e+ jG ƒ ZH e* e+ jI ƒ ZJ e* e+ jK ƒ ZL e* e2 jM ƒ ZN e* e+ jO ƒ ZP e* e+ jQ ƒ ZR e* e+ jS ƒ ZT e* e+ jU ƒ ZV e* e+ jW ƒ ZX e* e+ jY ƒ ZZ e* e+ j[ ƒ Z\ e* e+ j] ƒ Z^ e* e+ j_ ƒ Z` e* e+ ja ƒ Zb e* e2 jc ƒ Zd e* e2 je ƒ Zf e* e2 jg ƒ Zh e* e+ ji ƒ Zj e* e2 jk ƒ Zl e* e+ jm ƒ Zn e* e+ jo ƒ Zp e* e2 jq ƒ Zr RS(/   sH    The main Chart class, the core of the ``Bokeh.charts`` interface.

    R   R!   t   helps1   
    A label for the x-axis. (default: None)
    s1   
    A label for the y-axis. (default: None)
    s3   
    What kind of scale to use for the x-axis.
    s3   
    What kind of scale to use for the y-axis.
    t   filenamet   servert   notebookt   widtht   heightt   xgridt   ygridt   legendbackground_fillt   border_fillt   logoR   t   title_text_baselinet   title_text_alignt   title_text_alphat   title_text_colort   title_text_font_stylet   title_text_font_sizet   title_text_fontt   title_standoffc         C@  s   t  j d ƒ d  S(   Ns]   Non-functional 'xgrid' setter has been removed; use 'xgrid' keyword argument to Chart instead(   t   warningst   warn(   R.   R   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyR<   W   s    c         C@  s   t  j d ƒ d  S(   Ns]   Non-functional 'ygrid' setter has been removed; use 'ygrid' keyword argument to Chart instead(   RI   RJ   (   R.   R   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyR=   [   s    c         C@  s   t  j d ƒ d  S(   Ns_   Non-functional 'legend' setter has been removed; use 'legend' keyword argument to Chart instead(   RI   RJ   (   R.   R   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   legend_   s    c         O@  s$  | j  d d  ƒ } x? d d d g D]. } | | k r" | | | d | <| | =q" q" Wd | k r{ d | k r{ t d ƒ ‚ n  d | k r¥ t | d ƒ | d <| d =n  | j  d	 d
 ƒ |  _ | j  d d
 ƒ |  _ | j  d d
 ƒ |  _ | j  d d
 ƒ |  _ | j  d d  ƒ } t t	 |  ƒ j
 | | Ž  | |  j _ t j |  ƒ | d  k	 rU| |  _ n  x4 |  j D]) } | | k r_t |  | | | ƒ q_q_Wg  |  _ t |  _ g  |  _ g  |  _ t t ƒ |  _ t t ƒ |  _ t t ƒ |  _ g  |  _ t |  d ƒ r |  j |  j |  j |  j |  j |  j ƒ n  d  S(   NR   R<   R=   RK   t   _t
   responsivet   sizing_modesT   Chart initialized with both 'responsive' and 'sizing_mode' supplied, supply only onet   active_dragt   autot   active_inspectt   active_scrollt
   active_tapt   titleR   (   t   popR+   R"   R   t   _active_dragt   _active_inspectt   _active_scrollt   _active_tapt   superR!   t   __init__RT   t   textt   defaultsR3   R   R)   R-   t   _glyphsR&   t   _builtt	   _builderst   _renderer_mapR   R'   t   _rangest   _labelst   _scalest	   _tooltipsR,   t   create_tools(   R.   t   argst   kwargsR   t   namet
   title_textR2   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyR[   c   sB    
					c         @  s3   |  j  | 7_  |  j j ‡  f d †  | Dƒ ƒ d  S(   Nc         @  s   i  |  ] } ˆ  | j  “ q S(    (   t   _id(   t   .0t   r(   t   builder(    s-   lib/python2.7/site-packages/bkcharts/chart.pys
   <dictcomp>—   s   	 (   t	   renderersRa   t   extend(   R.   Rn   Ro   (    (   Rn   s-   lib/python2.7/site-packages/bkcharts/chart.pyt   add_renderers•   s    c         C@  s!   |  j  j | ƒ | j |  ƒ d  S(   N(   R`   t   appendt   create(   R.   Rn   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   add_builder™   s    c         C@  s   |  j  | j | ƒ d  S(   N(   Rb   Rr   (   R.   t   dimt   range(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt
   add_ranges   s    c         C@  s   |  j  | j | ƒ d  S(   N(   Rc   Rr   (   R.   Ru   t   label(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt
   add_labels    s    c         C@  s   |  j  | j | ƒ d  S(   N(   Rd   Rr   (   R.   Ru   t   scale(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt
   add_scales£   s    c         C@  s   |  j  | 7_  d  S(   N(   Re   (   R.   t   tooltips(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   add_tooltips¦   s    c         C@  sQ   t  |  | d ƒ r< t |  j | ƒ d k r< |  j | d St  |  | d ƒ Sd  S(   NRx   i    (   R*   t   lenRc   (   R.   Ru   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   _get_labels©   s    -c         C@  sb   |  j  d d |  j d d |  j d ƒ ƒ |  _ |  j  d d |  j d d |  j d ƒ ƒ |  _ d  S(   Nt   xt   belowi    t   yt   left(   t	   make_axisRd   R   t   _xaxist   _yaxis(   R.   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   create_axes¯   s    /c         C@  sB   | r |  j  d |  j j ƒ n  | r> |  j  d |  j j ƒ n  d  S(   Ni    i   (   t	   make_gridR…   t   tickerR†   (   R.   R<   R=   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   create_grids³   s    c         C@  sŽ   t  | t ƒ r | r t } n t  | t ƒ r1 d St |  j j ƒ d k rŠ t |  | ƒ \ } } |  j | Œ  t |  j | | | | | ƒ n  d S(   s‘   Create tools if given tools=True input.

        Only adds tools if given boolean and does not already have
        tools added to self.
        Ni    (	   R    t   boolR   R~   t   toolbarR   R   t	   add_toolsR   (   R.   R   RO   RQ   RR   RS   t	   tool_objst   tool_map(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyRf   ¹   s    	c         C@  sÎ   |  j  ƒ  |  j |  j |  j ƒ |  j j rW |  j |  j |  j |  j	 |  j
 |  j ƒ n  t |  j ƒ d k rˆ |  j t d |  j ƒ ƒ n  t |  j t ƒ r© t ƒ  |  _ n  t |  j t ƒ rÊ t ƒ  |  _ n  d S(   s&   Add the axis, grids and tools
        i    R|   N(   R‡   RŠ   t   _xgridt   _ygridRŒ   R   Rf   R   RV   RW   RX   RY   R~   Re   R   R   R    t   x_rangeR
   R   t   x_scalet   y_ranget   y_scale(   R.   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt
   start_plotÌ   s    
+c         C@  s—   d } |  j t k r d } n	 |  j } g  } x8 | D]0 } | j t d t | d ƒ d | d ƒ ƒ q4 W| r“ t d | d | ƒ } |  j | ƒ n  d S(	   sœ  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.
        t   top_leftRx   i    Ro   i   t   locationt   itemsN(   R+   t   _legendR%   Rr   R   R   R   t
   add_layout(   R.   t   chart_legendsR˜   R™   RK   (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt
   add_legendÞ   s    		.c         C@  s  t  |  j | ƒ d k r( t d ƒ ‚ n  |  j | d } t |  | d | ƒ | d k rz t | t ƒ rq d } qz d } n  | d k r˜ t d | ƒ } nX | d	 k r¶ t d | ƒ } n: | d k rá t d
 t	 j
 d d | ƒ } n t d | ƒ } |  j | | ƒ | S(   sâ  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
        i    s)   Ranges must be added to derive axis type.iÿÿÿÿt   _rangeRP   R   R   t
   axis_labelR   t   major_label_orientationi   (   R~   Rb   R"   R-   R    R
   R   R	   R   t   npt   piR›   (   R.   Ru   R˜   Rz   Rx   t
   data_ranget   axis(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyR„   ö   s$    		c         C@  s&   t  d | d | ƒ } |  j | ƒ | S(   sý   Create 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
        t	   dimensionR‰   (   R   R›   (   R.   R¥   R‰   t   grid(    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyRˆ   !  s    N(   R7   R8   R9   R:   R;   R<   R=   R>   R?   R@   R   RA   RB   RC   RD   RE   RF   RG   RH   (s   R4   R5   t   __doc__t   __view_model__t   __subtype__R   R+   t   xlabelt   ylabelR   R   R   t   Scalet   xscalet   yscaleR]   t	   _defaultsR)   R%   R   R‘   Rš   R   R<   t   setterR=   RK   R[   Rq   Rt   Rw   Ry   R{   R}   R   R‡   RŠ   Rf   R–   R   R„   Rˆ   R   R   t   AnnularWedget   annular_wedget   Annulust   annulust   Arct   arcR   t   Asteriskt   asteriskt   Beziert   beziert   Circlet   circlet   CircleCrosst   circle_crosst   CircleXt   circle_xt   Crosst   crosst   Diamondt   diamondt   DiamondCrosst   diamond_crosst   Ellipset   ellipset   HBart   hbart   Imaget   imaget	   ImageRGBAt
   image_rgbat   ImageURLt	   image_urlt   InvertedTrianglet   inverted_trianglet   Linet   linet	   MultiLinet
   multi_linet   Ovalt   ovalt   Patcht   patcht   Patchest   patchest   Quadt   quadt	   Quadratict	   quadratict   Rayt   rayt   Rectt   rectt   Segmentt   segmentt   Squaret   squaret   SquareCrosst   square_crosst   SquareXt   square_xt   TextR\   t   Trianglet   trianglet   VBart   vbart   Wedget   wedget   XR€   (    (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyR!   2   s   						   	2												+	(+   R§   t
   __future__R    t   collectionsR   RI   t   numpyR¡   t   bokeh.core.enumsR   t   bokeh.core.propertiesR   R   R   R   R   t   bokeh.modelsR   R	   R
   R   R   R   R   R   R   R   R   t   bokeh.plottingR   t   bokeh.plotting.helpersR   R   R   t   bokeh.models.scalesR   t   bokeh.util._plot_arg_helpersR   R¬   t   objectR   R]   R!   (    (    (    s-   lib/python2.7/site-packages/bkcharts/chart.pyt   <module>	   s   (L	