σ
ΞYc           @@  s  d  Z  d d l m Z d d l m Z d d l 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 m Z m Z d
 e f d     YZ d e f d     YZ d e
 f d     YZ d e
 f d     YZ d   Z d   Z d S(   s=   CollisionModifiers and DataOperators used to specify Chart manipulations.

The general approach for these operations is to use a class for modeling the
operation, which is lazy evaluated, and doesn't require the data on initialization.

An associated, user-facing function is provided for a more friendly interface.
i    (   t   absolute_import(   t   copy(   t   Instancet   Listt   Overridet   Stringi   (   t   DataOperator(   t   CollisionModifier(   t   ColumnLabel(   t   Countt   Statt   statst   Stackc           B@  s,   e  Z d  Z e d d  Z e d d  Z RS(   s[   Cumulates elements in the order of grouped values.

    Useful for area or bar glyphs.
    t   defaultt   stackt	   __stack__(   t   __name__t
   __module__t   __doc__R   t   namet   method_name(    (    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR      s   t   Dodgec           B@  s,   e  Z d  Z e d d  Z e d d  Z RS(   sh   Non-cumulative, moves glyphs around so they don't overlap.

    Useful for bar, box, or dot glyphs.
    R   t   dodget	   __dodge__(   R   R   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR      s   t   Blendc           B@  sJ   e  Z d  Z e d d d d  Z e d d d d  Z d   Z d   Z RS(	   s  Creates combined variables, increasing the number of distinct items.

    The primary action that blend is taking is combining and collapsing
    multiple columns together, using set algebra. You can think of this
    like taking two columns with similar or different data and stacking
    them on top of each other. The new categories are the union of the two sets. The
    operation is like an OR because a category in either variable is included
    in the blended variable

    .. note::
        The variables not being blended must be duplicated (consider a sample time).
        For example, two variables, 'sensor_a' and 'sensor_b' only contain two values,
        either 'on' or 'off', with one more column of 'datetime'. Blending 'sensor_a'
        and 'sensor_b' results in two columns, 'datetime' and 'sensors_state'.

    Example:

        - cat1 + cat2 = [cat1, cat2]
        - cat1 + num1 = [cat1, cat(num1)]
        - num1 + num2 = [num1, num2]

    Can be used to stack column oriented measures, so they can be colored. In
    this case, a new categorical column will be created that identifies each
    measure by name of the previous column.

    Can be used to combine categorical columns.

    ToDo: address booleans. Consider two columns, 'was_successful', 'was_effective'.
        It seems like blending of booleans would be performing an *or*.

    See Grammar of Graphics pgs. 67, 320
    R   t   valuet   helps^   The name of the column to
                          contain the values of the blended columns.t   variablesi   The name of the column
                            to contain the names of the columns that were blended.c         O@  s*   t  |  | d <t t |   j |   d  S(   Nt   columns(   t   listt   superR   t   __init__(   t   selft   colst
   properties(    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR   L   s    c         C@  s8   t  |  } | j d |  j d |  j d |  j  | j S(   Nt   measurest
   value_namet   var_name(   R   t   stack_measuresR   R   t   labels_namet   _data(   R    t   datat	   data_copy(    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyt   applyP   s    
(   R   R   R   R   R   R'   R   R+   (    (    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR   %   s    			t	   Aggregatec           B@  sD   e  Z e e  Z e e d  e   Z e	   Z
 d   Z d   Z RS(   R   c         K@  s   | j  d  } | d  k	 r> t | t  r> t |   | d <n  | j  d  } | d  k	 ri | g | d <n  t t |   j |   d  S(   Nt   statR   (   t   popt   Nonet
   isinstancet   strR   R   R,   R   (   R    R"   R-   t   col(    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR   ^   s    c         @  sζ   t  |  } |  j d  k r. t d   |  _ n  |  j  d   |  j d  k	 rd   |  j d d 7  n    |  j j j 7    |  _ |  j d  k r | j d  n |  j d      f d   } | j |  j	  } | j
 |  } | S(   Nt   countt    i    t   _c         @  s"    j  |     j |    <|  S(   N(   t   set_dataR   (   t   group(   t   agg_nameR2   R-   (    s2   lib/python2.7/site-packages/bkcharts/operations.pyt	   stat_funcz   s    (   R   R   R/   R   R-   t	   __class__R   t
   agg_columnt   groupbyt
   dimensionsR+   (   R    R)   R*   R9   t   gbt   agg(    (   R8   R2   R-   s2   lib/python2.7/site-packages/bkcharts/operations.pyR+   g   s     		(   R   R   R   R   R=   R   R
   R	   R-   R   R;   R   R+   (    (    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR,   X   s
   			c          O@  sg   | j  d  } |  d k	 r> t d t |    } | j   |  S| d k	 rW t d |  St d   d S(   s6  Stacks the :class:`CompositeGlyph`s.

    Stacks the glyphs which results in the glyphs having transformed data,
    which represents the stacked glyphs.

    Args:
        *comp_glyphs (:class:`CompositeGlyph`): a sequence of glyphs to stack

    Returns:
        comp_glyphs: a list of composite glyphs

    R   t   comp_glyphss&   You must stack on renderers or columnsN(   t   getR/   R   R   R+   t
   ValueError(   R@   t   kwargsR   t   stacker(    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyR      s    
c          O@  s   t  |  |   S(   s©  Provides a simple function for specifying a Blend data operation.

    Args:
        cols (str): each column to use for blending by name
        **kwargs: the keyword args supported by :class:`Blend`

            * name (str): name of the column to contain the blended values
            * labels_name (str): name of the column to contain the name of the columns
              used for blending


    See :class:`Blend`

    (   R   (   R!   RC   (    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyt   blend’   s    N(   R   t
   __future__R    R   t   bokeh.core.propertiesR   R   R   R   t   data_sourceR   t   modelsR   R"   R   R   R	   R
   R   R   R   R,   R   RE   (    (    (    s2   lib/python2.7/site-packages/bkcharts/operations.pyt   <module>   s   "		30	