ó
ÎYc           @@  ső   d  Z  d d l m Z d d l m Z m Z m Z m Z m Z m	 Z	 m
 Z
 d d l 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 m Z d d d d d  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 Horizon class which lets you build your Horizon charts
just passing the arguments to the Chart class and calling the proper
functions.
i    (   t   absolute_import(   t   Floatt   Intt   Listt   string_typest   Stringt   Colort   Bool(   t   CategoricalAxis(   t   ColumnDataSource(   t   FactorRanget   DataRange1d(   t   create_and_build(   t   HorizonGlyphi   (   t   LineBuilderi   (   t	   ColorAttrt   IdAttrc         K@  s  | | d <| | d <| | d <| j  d t  } | t k rE d } nZ t | t  r | j d d  } | j d d  } | j d	 d  } | j d
 d  } n  | | d <t t |  |  } t | j d _	 i t
 d | j d j  d 6| _ | j t d d  d  | S(   s   Create a horizon chart using :class:`HorizonBuilder
    <bkcharts.builders.scatter_builder.HorizonBuilder>`
    to render the geometry from values.

    Args:
        data (:ref:`userguide_charts_data_types`): table-like data
        x (str or list(str), optional): the column label to use for the x dimension
        y (str or list(str), optional): the column label to use for the y dimension

    In addition to the parameters specific to this chart,
    :ref:`userguide_charts_defaults` are also accepted as keyword parameters.

    Returns:
        :class:`Chart`: includes glyph renderers that generate the scatter points

    Examples:

    .. bokeh-plot::
        :source-position: above

        import pandas as pd
        from bkcharts import Horizon, output_file, show

        # read in some stock data from the Yahoo Finance API
        AAPL = pd.read_csv(
            "http://ichart.yahoo.com/table.csv?s=AAPL&a=0&b=1&c=2000&d=0&e=1&f=2010",
            parse_dates=['Date'])

        MSFT = pd.read_csv(
            "http://ichart.yahoo.com/table.csv?s=MSFT&a=0&b=1&c=2000&d=0&e=1&f=2010",
            parse_dates=['Date'])

        IBM = pd.read_csv(
            "http://ichart.yahoo.com/table.csv?s=IBM&a=0&b=1&c=2000&d=0&e=1&f=2010",
            parse_dates=['Date'])

        data = dict([
            ('AAPL', AAPL['Adj Close']),
            ('Date', AAPL['Date']),
            ('MSFT', MSFT['Adj Close']),
            ('IBM', IBM['Adj Close'])]
        )

        hp = Horizon(data, x='Date', plot_width=800, plot_height=300,
                     title="horizon plot using stock inputs")

        output_file("horizon.html")

        show(hp)

    t   xt   yt   seriest   toolss
   save,resett   pant    t
   wheel_zoomt   box_zooms   ,,t   ,i    t   factorst   y_range_namet   left(   t   gett   Truet
   isinstanceR   t   replaceR   t   HorizonBuildert   FalseR   t   visibleR
   t	   _builderst   series_namest   extra_y_rangest
   add_layoutR   (   t   dataR   R   R   t   kwsR   t   chart(    (    s@   lib/python2.7/site-packages/bkcharts/builders/horizon_builder.pyt   Horizon%   s"    4


	
#R!   c           B@  sß   e  Z d  Z e Z i e d e  d 6e d e  d 6Z e	 d d d Z
 e	 d d d Z e d	 d d
 Z e d e d d  Z e d d  Z e e d d Z e d d  Z e d d  Z d   Z d   Z d   Z RS(   sř   Produces glyph renderers representing a horizon chart from many input types.

    The builder handles ingesting the data, deriving settings when not provided,
    building the renderers, then setting ranges, and modifying the chart as needed.

    t   sortt   colorR   s   #006400t   helps?   
    The color of the positive folds. (default: "#006400")
    s   #6495eds?   
    The color of the negative folds. (default: "#6495ed")
    i   sH   
    The number of folds stacked on top of each other. (default: 3)
    t   defaults#  When True, the negative values will be
    plotted as their absolute value, then their individual axes is flipped. If False,
    then the negative values will still be taken as their absolute value, but the base
    of their shape will start from the same origin as the positive values.
    s!   Count of the unique series names.sf   The binedges calculated from the number of folds,
    and the maximum value of the entire source data.s*   The column that contains the series names.s   The size of the bin.c         C@  s   t  t |   j   |  j d j d  k rC |  j d j d |  _ n |  j d j d |  _ t |  j  d k r |  j	 |  j  n  t |  j  |  _
 d  S(   NR   R-   i    (   t   superR!   t   setupt
   attributest   columnst   Nonet   series_columnt   lenR%   t
   set_seriest   series_count(   t   self(    (    s@   lib/python2.7/site-packages/bkcharts/builders/horizon_builder.pyR1      s    c         C@  sÄ   t  t |   j   t |  j j t |  j j   |  j |  _ g  t	 |  j d  D] } | |  j ^ qR |  _
 t |  j j  } |  j d j d | d |  j  |  j d j d | d |  j  d  S(   Ni   R   R(   R3   R-   (   R0   R!   t   process_datat   maxR   t   abst   mint	   num_foldst   fold_heightt   ranget   binsR	   t   _datat   dfR2   R1   R5   t	   pos_color(   R9   t   bin_idt   ds(    (    s@   lib/python2.7/site-packages/bkcharts/builders/horizon_builder.pyR:   §   s    +0 c         C@  sG   t  t |   j   t d d  |  _ d |  j _ |  j j |  j _	 d  S(   Nt   range_paddingi    (
   R0   R!   t
   set_rangesR   t   x_ranget   y_ranget   startR   R;   t   end(   R9   (    (    s@   lib/python2.7/site-packages/bkcharts/builders/horizon_builder.pyRH   ł   s    (   t   __name__t
   __module__t   __doc__R   t   glyphR   R"   R   t   default_attributesR   RD   t	   neg_colorR   R>   R   R   t   flip_negR8   R   R   RA   R   R5   R?   R1   R:   RH   (    (    (    s@   lib/python2.7/site-packages/bkcharts/builders/horizon_builder.pyR!   r   s(   											N(   RO   t
   __future__R    t   bokeh.core.propertiesR   R   R   R   R   R   R   t   bokeh.models.axesR   t   bokeh.models.sourcesR	   t   bokeh.models.rangesR
   R   t   bkcharts.builderR   t   bkcharts.glyphsR   t   line_builderR   R2   R   R   R4   R+   R!   (    (    (    s@   lib/python2.7/site-packages/bkcharts/builders/horizon_builder.pyt   <module>   s   4M