σ
ΞYc        
   @@  sΌ   d  Z  d d l m Z d d l 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 d d	 l m Z d d d d
 d d e e 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 Histogram class which lets you build your histograms just passing
the arguments to the Chart class and calling the proper functions.
i    (   t   absolute_import(   t   Boolt   Intt   Eithert   Floatt   List(   t   Range1di   (   t   create_and_buildi   (   t
   BarBuilder(   t   HistogramGlypht   countt   linearc
         K@  s   |	 r% t  |	 t  r% t d   n  |	 } | |
 d <| |
 d <| |
 d <| |
 d <| |
 d <| |
 d <| |
 d <| |
 d	 <| |
 d
 <t t |  |
  S(   s%	   Create a histogram chart with one or more histograms.

    Create a histogram chart using :class:`HistogramBuilder
    <bkcharts.builders.histogram_builder.HistogramBuilder>` to
    render the glyphs from input data and specification. This primary
    use case for the histogram is to depict the distribution of a
    variable by binning and aggregating the values in each bin.

    This chart implements functionality to provide convenience in optimal
    selection of bin count, but also for segmenting and comparing segments of
    the variable by a categorical variable.

    Args:
      data (:ref:`userguide_charts_data_types`): the data source for the chart.
        Must consist of at least 2 values. If all values are equal, the result
        is a single bin with arbitrary width.
      values (str, optional): the values to use for producing the histogram using
        table-like input data
      label (str or list(str), optional): the categorical variable to use for creating
        separate histograms
      color (str or list(str) or `~bkcharts._attributes.ColorAttr`, optional): the
        categorical variable or color attribute specification to use for coloring the
        histogram, or explicit color as a string.
      agg (str, optional): how to aggregate the bins. Defaults to "count".
      bins (int or list(float), optional): the number of bins to use, or an explicit
        list of bin edges. Defaults to None to auto select.
      density (bool, optional): whether to normalize the histogram. Defaults to False.

      **kw:

    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 histograms

    Examples:

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

        from bkcharts import Histogram, output_file, show
        from bokeh.layouts import row
        from bokeh.sampledata.autompg import autompg as df

        hist = Histogram(df, values='mpg', title="Auto MPG Histogram", plot_width=400)
        hist2 = Histogram(df, values='mpg', label='cyl', color='cyl', legend='top_right',
                          title="MPG Histogram by Cylinder Count", plot_width=400)

        output_file('hist.html')
        show(row(hist, hist2))
    sC   continuous_range must be an instance of bokeh.models.ranges.Range1dt   labelt   valuest   colort   aggt   yscalet   xgridt   ygridt   y_ranget   bins(   t
   isinstanceR   t
   ValueErrorR   t   HistogramBuilder(   t   dataR   R   R   R   R   R   R   R   t   continuous_ranget   kwR   (    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyt	   Histogram#   s    7








R   c           B@  sk   e  Z d  Z e e e  e d d	 d d Z e	 e
 d d Z e Z d   Z d   Z d   Z d   Z RS(
   s»   Generates one to many histograms with unique attributes.

    The HistogramBuilder is responsible for producing a chart
    containing one to many histograms from table-like inputs.

    t   defaultt   helps  
    If bins is an int, it defines the number of equal-width bins in the
    given range. If bins is a sequence, it defines the
    bin edges, including the rightmost edge, allowing for non-uniform
    bin widths.

    (default: None, use Freedman-Diaconis rule)
    sv  
    Whether to normalize the histogram.

    If True, the result is the value of the probability *density* function
    at the bin, normalized such that the *integral* over the range is 1. If
    False, the result will contain the number of samples in each bin.

    For more info check :class:`~bkcharts.glyphs.HistogramGlyph`
    documentation.

    (default: False)
    c         C@  s9   t  t |   j   |  j d j d  k	 r5 d |  _ n  d  S(   NR   g333333γ?(   t   superR   t   setupt
   attributest   columnst   Nonet
   fill_alpha(   t   self(    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyR      s    c         C@  s   t  d |  j d |  j  S(   s6   Build kwargs that are unique to the histogram builder.R   t   density(   t   dictR   R%   (   R$   (    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyt   get_extra_args   s    c         C@  s   d  S(   N(    (   R$   (    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyt   _apply_inferred_index   s    c         C@  sζ   t  g  |  j D] } | j ^ q  } t g  |  j D] } | j ^ q2  } t  g  |  j D] } | j ^ qW  } t g  |  j D] } | j ^ q|  } | | d d } t d | | d | |  |  _ t d | d | d  |  _	 d S(   s]   Push the Bar data into the ColumnDataSource and calculate
        the proper ranges.
        g       @g©?t   startt   endgρ?N(
   t   maxt   comp_glyphst   x_maxt   mint   x_mint   y_maxt   y_minR   t   x_rangeR   (   R$   t
   comp_glyphR-   R/   R0   R1   t   x_buffer(    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyt
   set_ranges   s    %%%% N(   t   __name__t
   __module__t   __doc__R   R   R   R   R"   R   R   t   FalseR%   R	   t   glyphR   R'   R(   R5   (    (    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyR   n   s   						N(   R8   t
   __future__R    t   bokeh.core.propertiesR   R   R   R   R   t   bokeh.modelsR   t   builderR   t   bar_builderR   t   glyphsR	   R"   R9   t   TrueR   R   (    (    (    sB   lib/python2.7/site-packages/bkcharts/builders/histogram_builder.pyt   <module>   s   (I