σ
ΞYc           @@  sβ   d  Z  d d l m Z d d l Z d d l 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 m Z m Z m Z m Z m Z d	 d
 l m Z m Z d e f d     YZ d e f d     YZ d S(   s   

i    (   t   absolute_importN(   t	   iteritems(   t   HasProps(   t   GlyphRenderer(   t   ColumnDataSource(   t   Anyt   Colort   Dictt   Eithert   Floatt   Instancet   Listt   Stringi   (   t   Columnt   ColumnLabelt   CompositeGlyphc           B@  sΔ  e  Z d  Z e e e e e  d d d d Z e e e	  e e  d d Z
 e e d d Z e e e   Z e e e  Z e e d d Z e d d d d	  Z e d d  Z e d d
 d d  Z e	 d d  Z e	 d d  Z e	 d d  Z e	 d d  Z e	 d d  Z e	 d d  Z d   Z d   Z d   Z e  d    Z! e  d    Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ e, d    Z- RS(   sY  Represents a subset of data.

    A collection of hetero or homogeneous glyph
    renderers which represent a subset of data. The
    purpose of the composite glyph is to abstract
    away the details of constructing glyphs, based on
    the details of a subset of data, from the grouping
    operations that a generalized builders must implement.

    In general, the Builder operates at the full column
    oriented data source level, segmenting and assigning
    attributes from a large selection, while the composite glyphs
    will typically be passed an array-like structures with
    one or more singular attributes to apply.

    Another way to explain the concept is that the Builder
    operates as the groupby, as in pandas, while the
    CompositeGlyph operates as the function used in the apply.

    What is the responsibility of the Composite Glyph?
        - Produce GlyphRenderers
        - Apply any aggregations
        - Tag the GlyphRenderers with the group label
        - Apply transforms due to chart operations
            - Note: Operations require implementation of special methods
    t   defaultt   Nonet   helps   Identifies the subset of data.sU  
        Array-like values, which are used as the input to the composite glyph.

        Most composite glyphs add their own representation of one or more values-like
        columns/arrays that they receive as inputs. These are compiled together for
        generating `source`, `data`, and `df` by the individual composite glyphs.
        s   The data source used for the contained
        glyph renderers. Simple glyphs part of the composite glyph might not use the
        column data source.s\   A list of chart operations that can be applied to
        manipulate their visual depiction.t   grayss   A high level color. Some glyphs will
        implement more specific color attributes for parts or specific glyphs.t   blacks5   A default outline color for contained
        glyphs.gι?g      π?g        c         K@  sg   | j  d  } t   j |  s3 t   j |  rC | g | d <n  t t |   j |   |  j   d  S(   Nt   values(   t   getR   t   is_validR	   t   superR   t   __init__t   setup(   t   selft
   propertiest   vals(    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR   O   s
    $c         C@  sB   g  |  j    D] } | ^ q |  _ |  j d k	 r> |  j   n  d S(   s=   Build renderers and data source and set sources on renderers.N(   t   build_rendererst	   renderersR   t   refresh(   R   t   renderer(    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR   V   s    "c         C@  s   |  j  d k	 r |  j   } | d k	 r t | t  rE t |  } n  t | t  rp | d k	 rp t d   n |  j |  |  _ |  j	   q n  d S(   sr   Update the GlyphRenderers.

        .. note:
            this method would be called after data is added.
        s2   build_source must return dict or ColumnDataSource.N(
   R   R   t   build_sourcet
   isinstancet   dictR   t	   TypeErrort   add_chart_indext   sourcet   _set_sources(   R   t   dataR'   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR    \   s    c         C@  s!   |  j  d  k	 r |  j  j Si  Sd  S(   N(   R'   R   R)   (   R   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR)   q   s    
c         C@  s'   |  j  r t j |  j   St j   Sd  S(   N(   R)   t   pdt	   DataFrame(   R   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt   dfx   s    	c         C@  sλ   t  | t  r! | } | j } n d } d | k rΚ t t | j     d k rΚ t t | j    d  } |  j g | | d <t  |  j t	  rΚ x1 t
 |  j  D] \ } } | g | | | <q£ WqΚ n  | d k	 rγ | | _ | S| Sd S(   sF  Add identifier of the data group as a column for each row.

        Args:
            data (dict or `ColumnDataSource`): can be the type of data used internally
                to ColumnDataSource, or a ColumnDataSource.

        Returns:
            dict or `ColumnDataSource`: returns the same type of data provided
        t   chart_indexi    N(   R#   R   R)   R   t   lent   listt   keysR   t   labelR$   R   (   R   R)   R'   t   n_rowst   colt   val(    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR&      s    *	c         c@  s   t    Vd  S(   N(   R   (   R   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR   ’   s    c         C@  s,   i  } |  j  d  k	 r( i |  j  d 6} n  | S(   NR   (   R   R   (   R   R)   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR"   ₯   s    c         C@  s$   x |  j  D] } |  j | _ q
 Wd S(   sε   Store reference to source in each GlyphRenderer.

        .. note::
            if the glyphs that are part of the composite glyph differ, you may have to
            override this method and handle the sources manually.
        N(   R   R'   t   data_source(   R   R!   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR(   ­   s    c         C@  s   d S(   sB   A special method the `stack` function applies to composite glyphs.N(    (   R   t   glyphs(    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt	   __stack__·   s    c         C@  s   d S(   sC   A special method the `jitter` function applies to composite glyphs.N(    (   R   R6   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt
   __jitter__»   s    c         C@  s   d S(   sB   A special method the `dodge` function applies to composite glyphs.N(    (   R   R6   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt	   __dodge__Ώ   s    c         C@  s   d S(   sD   A special method the `overlay` function applies to composite glyphs.N(    (   R   R6   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt   __overlay__Γ   s    c         C@  s   d  S(   N(    (   R   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt   apply_operationsΗ   s    c         C@  s@   i  } x3 t  |  j  D]" \ } } | j d t  | | <q W| S(   Nt	   withbases(   R   R6   t   class_propertiest   True(   t   clst   propst   namet   glyph(    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt   glyph_propertiesΚ   s    (.   t   __name__t
   __module__t   __doc__R   R   R   R   R1   R   R	   R   R
   R   R'   R   R   R   R6   t
   operationsR   t   colort
   fill_colort
   line_colort
   fill_alphat
   line_alphat   left_buffert   right_buffert
   top_buffert   bottom_bufferR   R   R    t   propertyR)   R,   R&   R   R"   R(   R7   R8   R9   R:   R;   t   classmethodRC   (    (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyR      sJ   												#			
					t   CollisionModifierc           B@  st   e  Z d  Z e e e  d d Z e d d  Z e d d  Z	 e
 e e e  d d Z d   Z d d  Z RS(	   s5  Models an special type of operation that alters how glyphs interact.

    Used to handle the manipulation of glyphs for operations, such as stacking. The
    list of `CompositeGlyph`s can either be input into the `CollisionModifier` as
    keyword args, or added individually with the `add_glyph` method.
    R   sA   A list of composite glyphs,
        to apply the modification to.s#   The name of the collision modifier.sz   The name of the method that will be utilized on
        the composite glyphs. This method must exist on all `comp_glyphs`.sc   Some collision modifiers
        might require column labels to apply the operation in relation to.c         C@  s   |  j  j |  d  S(   N(   t   comp_glyphst   append(   R   t
   comp_glyph(    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt	   add_glyphβ   s    c         C@  ss   t  |  j  d k r! | |  _ n  t  |  j  d k rY t |  j d |  j  |  j  n t d |  j j   d  S(   Ni    s6   %s must be applied to available renderers, none found.(   R.   RT   t   getattrt   method_namet   AttributeErrort	   __class__RD   (   R   R   (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt   applyε   s    #N(   RD   RE   RF   R   R
   R   RT   R   RA   RY   R   R   t   columnsRW   R   R\   (    (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyRS   Σ   s   				(   RF   t
   __future__R    t   pandasR*   t   sixR   t   bokeh.core.has_propsR   t   bokeh.models.renderersR   t   bokeh.models.sourcesR   t   bokeh.core.propertiesR   R   R   R   R	   R
   R   R   R   R   R   R   RS   (    (    (    s.   lib/python2.7/site-packages/bkcharts/models.pyt   <module>   s   :Γ