σ
ΞYc           @@  s
  d  Z  d d l m Z d d l Z d d l 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 d d l 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 e f d     YZ d S(   s    Properties for modeling Chart inputs, constraints, and dependencies.

selection spec:
    [['x'], ['x', 'y']]
    [{'x': categorical, 'y': numerical}]

i    (   t   absolute_importN(   t   HasProps(   t   PrimitiveProperty(   t   Arrayt   bokeh_integer_typest   Boolt   Eithert   Intt   Listt   Stringi   (   t   special_columnst   title_from_columnst   Columnc           B@  s)   e  Z d  Z d   Z d   Z d   Z RS(   sλ   Represents column-oriented data.

    This property is used to provide a consistent interface for column-like data. The
    property both validates the data types set, and transforms all column-like data into
    `pd.Series` data.
    c         C@  sO   t  t |   j |  } t | t j  pN t | t j  pN t | t  pN | S(   N(   t   superR   t   _is_seqt
   isinstancet   pdt   Seriest   Indext   list(   t   selft   valuet   is_array(    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR      s    $c         C@  s   t  j |  S(   N(   R   R   (   R   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   _new_instance   s    c         C@  s   | d  k r d  St | t j  r. | j } n t j |  j } t t |   j |  } y t j |  SWn! t k
 r t d |   n Xd  S(   Ns   Could not transform %r(	   t   NoneR   R   R   t   valuesR   R   t	   transformt
   ValueError(   R   R   t   arrt   trans_array(    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR   "   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR      s   		t   Logicalc           B@  s   e  Z d  Z d   Z RS(   sc   A boolean like data type.

    This property is valid for both python and numpy boolean types.
    c         C@  s   y t  t |   j |  Wn| t k
 r t | t  rK t j |  } n  t | t j  r t j	 |  } t
 |  d k r d  St d |   q n Xd  S(   Ni   s5   expected a Bool or array with 2 unique values, got %s(   R   R!   t   validateR   R   R   t   npt   arrayt   ndarrayt   uniquet   len(   R   R   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR"   8   s    (   R   R   R    R"   (    (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR!   3   s   t   ColumnLabelc           B@  s2   e  Z d  Z d d d d  Z d   Z d   Z RS(   s"   Specify a column by name or index.c         C@  s;   t  t f } | |  _ t t |   j d | d | |  d  S(   Nt   defaultt   help(   R	   R   t   columnsR   R(   t   __init__(   R   R+   R)   R*   t   types(    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR,   K   s    	c         C@  s   t  t |   j |  |  j r t |  t k rY t |  j  | k rJ d St d   q | |  j k r | t k r t d |  j   q n  d S(   sK   If we are given a column list, make sure that the column provided is valid.Ns   Not a valid column selection.s7   Column provided is not in the list of valid columns: %s(	   R   R(   R"   R+   t   typeR   R'   R   R
   (   R   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR"   Q   s    	c         C@  s   d S(   Ns   Column Name or Column String(    (   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   __str___   s    N(   R   R   R    R   R,   R"   R/   (    (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR(   H   s   	t	   Dimensionc           B@  s  e  Z d  Z e   Z e e e e  d d Z e e	 e e	  d d Z
 e e e e  d d Z e e e e  d d Z e e	 e e	  d d Z d   Z d   Z e d    Z d   Z d   Z e d    Z e d    Z e d	    Z e d
    Z e d    Z RS(   sΚ  Configures valid Chart column selections.

    A dimension is Chart property that is assigned one or more columns names or indices.
    Each column can match one or more column types, which are important to charts,
    because the type of column selection can greatly affect the behavior of generalized
    Charts.

    The Dimension also provides convenient utilities for accessing information
    about the current provided configuration at the global, non-grouped level.

    The dimension configuration does not require the data, but when the data is
    added using the `set_data` method, then validation can occur of the settings
    by using the `valid` and `invalid` types identified by the selection.
    R)   c         K@  s<   | | d <t  t |   j |   t j   |  _ d  |  _ d  S(   Nt   name(   R   R0   R,   R   t	   DataFramet   _dataR   t   _chart_source(   R   R1   t
   properties(    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR,   |   s    
c         C@  se   t  |  j  } g  } xI | D]A } |   } y | j |  | j |  Wq t k
 r\ q Xq W| S(   s,   Returns all property types that are matched.(   R   t   validR"   t   appendR   (   R   t   col_datat   valid_typest   matchest
   valid_typet   prop(    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   get_valid_types   s    	c         C@  si   |  j  j s |  j d k r( t j d  S|  j t t j    k rW t |  j |  j   S|  j  |  j Sd S(   sm   The data selected for the Dimension.

        Returns pd.Series(1) if data is empty or no selection.
        i   N(	   R3   t   emptyt	   selectionR   R   R   R   R
   t   keys(   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   data   s
    c         C@  s   t  |  j j  S(   N(   R'   RA   t   index(   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   __len__£   s    c         C@  sA   | |  j  |  _ | |  _ | j |  _ t |  j j j  |  _ d S(   s°   Set data property so that builders has access to configuration metadata.

        Args:
            data (`ChartDataSource`): the data source associated with the chart
        N(   R1   R?   R4   t   dfR3   R   R+   R   (   R   RA   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   set_data¦   s    	c         C@  s?   t  |  j t j  r" |  j j   S|  j j d d  j   Sd S(   s-   The minimum of one to many column selections.t   axisi   N(   R   RA   R   R   t   min(   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyRG   ±   s    c         C@  s?   t  |  j t j  r" |  j j   S|  j j d d  j   Sd S(   s-   The maximum of one to many column selections.RF   i   N(   R   RA   R   R   t   max(   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyRH   Ή   s    c         C@  s8   t  |  j t j  r* |  j j |  j d S|  j j Sd  S(   Ni    (   R   RA   R   R2   t   dtypesR?   t   dtype(   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyRJ   Α   s    c         C@  s*   |  j  d k r t S|  j  j |  j  Sd S(   sH   Check the `ChartDataSource` to see if the selection is a derived column.N(   R4   R   t   Falset   is_computedR?   (   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   computedΘ   s    c         C@  s   t  |  j  S(   s5   A title formatted representation of selected columns.(   R   R?   (   R   (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   selected_titleΠ   s    N(   R   R   R    R	   R1   R   R   R   t	   alt_namesR(   R+   R   R6   t   invalidR?   R,   R=   t   propertyRA   RC   RE   RG   RH   RJ   RM   RN   (    (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR0   c   s"   					t   EitherColumnc           B@  s   e  Z d  Z d   Z RS(   s'   Allow providing option of column types.c         C@  sZ   t  t |   j | |  } t | t  r. | St | t j  rJ | j   St d   d  S(   Ns   Failed when comparing Columns(	   R   RR   R:   R   t   boolR   R   t   allR   (   R   t   newt   oldt
   comparison(    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyR:   Ϊ   s    
(   R   R   R    R:   (    (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyRR   Φ   s   (   R    t
   __future__R    t   numpyR#   t   pandasR   t   bokeh.core.has_propsR   t   bokeh.core.property.basesR   t   bokeh.core.propertiesR   R   R   R   R   R   R	   t   utilsR
   R   R   R!   R(   R0   RR   (    (    (    s2   lib/python2.7/site-packages/bkcharts/properties.pyt   <module>   s   4 s