ó
±éRc           @  s  d  Z  d d l m Z m Z d d l Z d d l 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 d d	 l m Z d
 e	 f d „  ƒ  YZ d e f d „  ƒ  YZ e e d e e e d e e d d e d „ Z e j j d e j e ƒ ƒ d S(   sG  
Place a table below the x-axis at location loc.

The table consists of a grid of cells.

The grid need not be rectangular and can have holes.

Cells are added by specifying their row and column.

For the purposes of positioning the cell at (0, 0) is
assumed to be at the top left and the cell at (max_row, max_col)
is assumed to be at bottom right.

You can add additional cells outside this range to have convenient
ways of positioning more interesting grids.

Author    : John Gill <jng@europe.renre.com>
Copyright : 2004 John Gill and John Hunter
License   : matplotlib license

iÿÿÿÿ(   t   divisiont   print_functionN(   t   Artistt   allow_rasterization(   t	   Rectangle(   t   is_string_like(   t	   docstring(   t   Text(   t   Bboxt   Cellc           B  s˜   e  Z d  Z d Z d d e d d d d „ Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   s;   
    A cell is a Rectangle with some associated text.

    gš™™™™™¹?t   kt   wt    c
   
      C  s“   t  j |  | d | d | d | d | ƒ|  j t ƒ | d  k rJ d } n  | |  _ t d | d d | d	 d
 | d |	 ƒ |  _ |  j j t ƒ d  S(   Nt   widtht   heightt	   edgecolort	   facecolort   rightt   xi    t   yi   t   textt   fontproperties(   R   t   __init__t   set_clip_ont   Falset   Nonet   _locR   t   _text(
   t   selft   xyR   R   R   R   t   fillR   t   locR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR   )   s    			 c         C  s   t  j |  | ƒ d  S(   N(   R   t   set_transform(   R   t   trans(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR    >   s    c         C  s$   t  j |  | ƒ |  j j | ƒ d  S(   N(   R   t
   set_figureR   (   R   t   fig(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR"   B   s    c         C  s   |  j  S(   s   Return the cell Text intance(   R   (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   get_textF   s    c         C  s   |  j  j | ƒ d  S(   N(   R   t   set_fontsize(   R   t   size(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR%   J   s    c         C  s   |  j  j ƒ  S(   s   Return the cell fontsize(   R   t   get_fontsize(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR'   M   s    c         C  sj   |  j  ƒ  } |  j | ƒ } xH | d k re | |  j ƒ  k re | d 8} |  j | ƒ |  j | ƒ } q W| S(   s#    Shrink font size until text fits. i   (   R'   t   get_required_widtht	   get_widthR%   (   R   t   renderert   fontsizet   required(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   auto_set_font_sizeQ   s    !
c         C  sA   |  j  ƒ  s d  St j |  | ƒ |  j | ƒ |  j j | ƒ d  S(   N(   t   get_visibleR   t   drawt   _set_text_positionR   (   R   R*   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR/   \   s
    c   	      C  sä   |  j  | ƒ } | j \ } } } } |  j j d ƒ | | d } |  j d k rr |  j j d ƒ | | d } nX |  j d k r¥ |  j j d ƒ | | |  j } n% |  j j d ƒ | | d |  j } |  j j | | f ƒ d S(   sm    Set text up so it draws in the right place.

        Currently support 'left', 'center' and 'right'
        t   centerg       @t   leftR   g      ð?N(   t   get_window_extentt   boundsR   t   set_verticalalignmentR   t   set_horizontalalignmentt   PADt   set_position(	   R   R*   t   bboxt   lt   bR   t   hR   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR0   g   s    c         C  s.   |  j  j | ƒ } | j |  j ƒ  ƒ } | j S(   s'    Get text bounds in axes co-ordinates. (   R   R3   t   inverse_transformedt   get_data_transformR4   (   R   R*   R9   t   bboxa(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   get_text_bounds€   s    c         C  s.   |  j  | ƒ \ } } } } | d d |  j S(   s#    Get width required for this cell. g      ð?g       @(   R@   R7   (   R   R*   R:   R;   R   R<   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR(   †   s    c         K  s   |  j  j | ƒ d S(   s&   update the text properties with kwargsN(   R   t   update(   R   t   kwargs(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   set_text_props‹   s    N(   t   __name__t
   __module__t   __doc__R7   t   TrueR   R   R    R"   R$   R%   R'   R-   R   R/   R0   R@   R(   RC   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR	   "   s$   									t   Tablec           B  sU  e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6Z d Z d% Z d8 d8 d& „ Z d' „  Z d( „  Z	 e
 d) „  ƒ Z d* „  Z d+ „  Z d, „  Z e Z d- „  Z d. „  Z d/ „  Z d0 „  Z e d1 „ Z d2 „  Z d3 „  Z d4 „  Z d5 „  Z d6 „  Z d7 „  Z RS(9   s7  
    Create a table of cells.

    Table can have (optional) row and column headers.

    Each entry in the table can be either text or patches.

    Column widths and row heights for the table can be specifified.

    Return value is a sequence of text, line and patch instances that make
    up the table
    i    t   besti   s   upper righti   s
   upper lefti   s
   lower lefti   s   lower righti   s   center lefti   s   center righti   s   lower centeri   s   upper centeri	   R1   i
   s	   top righti   s   top lefti   s   bottom lefti   s   bottom righti   R   i   R2   i   t   topi   t   bottomg{®Gáz”?c         K  s  t  j |  ƒ t | ƒ rZ | |  j k rZ t j d | d j |  j j ƒ  ƒ f ƒ d } n  t | ƒ r~ |  j j | d ƒ } n  |  j	 | j
 ƒ | |  _ | |  _ | |  _ |  j | j ƒ g  |  _ i  |  _ g  |  _ g  |  _ t |  _ |  j | ƒ |  j t ƒ d  |  _ d  S(   NsI   Unrecognized location %s. Falling back on bottom; valid locations are
%s	s   
	RK   i   (   R   R   R   t   codest   warningst   warnt   joint   iterkeyst   getR"   t   figuret   _axesR   t   _bboxR    t	   transAxest   _textst   _cellst	   _autoRowst   _autoColumnsRG   t   _autoFontsizeRA   R   R   R   t   _cachedRenderer(   R   t   axR   R9   RB   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR   ´   s(    	 									c         O  s_   d } t  | | | Ž } | j |  j ƒ | j |  j ƒ  ƒ | j t ƒ | |  j | | f <d S(   s    Add a cell to the table. i    N(   i    i    (   R	   R"   RR   R    t   get_transformR   R   RW   (   R   t   rowt   colt   argsRB   R   t   cell(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   add_cellÒ   s    c         C  s&   |  j  d |  j j |  j j j d S(   Ng      R@g333333ó?(   t   FONTSIZERR   t   dpiRS   R9   R   (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   _approx_text_heightÝ   s    c         C  sµ   | d  k r |  j } n  | d  k r3 t d ƒ ‚ n  | |  _ |  j ƒ  sL d  S| j d ƒ |  j | ƒ |  j j ƒ  } | j ƒ  x" | D] } |  j | j	 | ƒ q† W| j
 d ƒ d  S(   Ns   No renderer definedt   table(   R   R[   t   RuntimeErrorR.   t
   open_groupt   _update_positionsRW   t   keyst   sortR/   t   close_group(   R   R*   Rj   t   key(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR/   á   s    	
c         C  st   g  |  j  j ƒ  D]< } | d d k r | d d k r |  j  | j | ƒ ^ q } t j | ƒ } | j |  j ƒ  ƒ S(   sr   Get a bbox, in axes co-ordinates for the cells.

        Only include those in the range (0,0) to (maxRow, maxCol)i    i   (   RW   RP   R3   R   t   unionR=   R]   (   R   R*   t   post   boxesR9   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   _get_grid_bboxø   s
    <c         C  s¼   t  |  j ƒ r |  j |  | ƒ S|  j d k	 r® g  |  j j ƒ  D]? } | d d k r> | d d k r> |  j | j |  j ƒ ^ q> } t j | ƒ } | j	 | j
 | j ƒ i  f St i  f Sd S(   sU   Test whether the mouse event occurred in the table.

        Returns T/F, {}
        i    i   N(   t   callablet	   _containsR[   R   RW   RP   R3   R   Rn   t   containsR   R   R   (   R   t
   mouseeventRo   Rp   R9   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyRt     s    ?c         C  s   |  j  j ƒ  S(   s)   Return the Artists contained by the table(   RW   t   values(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   get_children  s    c         C  s8   g  |  j  j ƒ  D] } | j | ƒ ^ q } t j | ƒ S(   s5   Return the bounding box of the table in window coords(   RW   Rv   R3   R   Rn   (   R   R*   Ra   Rp   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR3     s    (c         C  st  i  } i  } xy |  j  j ƒ  D]h \ \ } } } | j | d ƒ } t | | j ƒ  ƒ | | <| j | d ƒ } t | | j ƒ  ƒ | | <q Wd } i  }	 | j ƒ  }
 |
 j ƒ  x& |
 D] } | |	 | <| | | 7} q± Wd } i  } | j ƒ  } | j ƒ  | j ƒ  x& | D] } | | | <| | | 7} qWxE |  j  j ƒ  D]4 \ \ } } } | j	 |	 | ƒ | j
 | | ƒ q8Wd S(   sW    Calculate row heights and column widths.

        Position cells accordingly.
        g        i    N(   RW   t	   iteritemst
   setdefaultt   maxt
   get_heightR)   Rj   Rk   t   reverset   set_xt   set_y(   R   t   widthst   heightsR^   R_   Ra   R   R   t   xpost   leftst   colst   ypost   bottomst   rows(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   _do_cell_alignment"  s2    "




"c         C  s   |  j  j | ƒ d  S(   N(   RY   t   append(   R   R_   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   auto_set_column_widthG  s    c         C  s‘   g  |  j  D] } | d | k r
 | ^ q
 } d } x3 | D]+ } |  j  | } t | j | ƒ | ƒ } q9 Wx" | D] } |  j  | j | ƒ qo Wd S(   s-    Automagically set width for column.
        i   i    N(   RW   Rz   R(   t	   set_width(   R   R_   R*   Rm   t   cellsR   Ra   t   c(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   _auto_set_column_widthK  s    ,c         C  s   | |  _  d S(   s    Automatically set font size. N(   RZ   (   R   t   value(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR-   Z  s    c         C  sÇ   t  |  j ƒ d k r d  S|  j j ƒ  d j ƒ  } g  } xa |  j j ƒ  D]P \ } } | d |  j k rm qH n  | j | ƒ } t | | ƒ } | j | ƒ qH Wx$ |  j j	 ƒ  D] } | j
 | ƒ q¬ Wd  S(   Ni    i   (   t   lenRW   Rv   R'   Rx   RY   R-   t   minRˆ   t
   itervaluesR%   (   R   R*   R+   R‹   Rm   Ra   R&   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   _auto_set_font_size^  s    c         C  sL   xE |  j  j ƒ  D]4 } | j | j ƒ  | ƒ | j | j ƒ  | ƒ q Wd S(   s:    Scale column widths by xscale and row heights by yscale. N(   RW   R‘   RŠ   R)   t
   set_heightR{   (   R   t   xscalet   yscaleRŒ   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   scalep  s    c         C  s+   x$ |  j  j ƒ  D] } | j | ƒ q Wd S(   sW   
        Set the fontsize of the cell text

        ACCEPTS: a float in points
        N(   RW   R‘   R%   (   R   R&   Ra   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyR%   v  s    c         C  sY   xR |  j  j ƒ  D]A } | j ƒ  | j ƒ  } } | j | | ƒ | j | | ƒ q Wd S(   s+   Move all the artists by ox,oy (axes coords)N(   RW   R‘   t   get_xt   get_yR}   R~   (   R   t   oxt   oyRŒ   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   _offset€  s    c          C  sô  x! |  j  D] } |  j | | ƒ q
 W|  j r= |  j | ƒ n  |  j ƒ  |  j | ƒ } | j \ } } } } |  j d  k	 rÈ |  j \ } }	 }
 } |  j	 |
 | | | ƒ | | } |	 | } |  j ƒ  nt
 t |  j ƒ ƒ \ } } } } } } } } } } } } } } } } } } d | d | } d | d | } |  j | | | f k r_|  j | } n  |  j | | | | | f k r•d | | |  j } n  |  j | | | | f k rÈd | | |  j } n  |  j | | | f k rð|  j | } n  |  j | | | f k rd | d | } n  |  j | | | f k rJd | d | } n  |  j | | | f k rp| | } n  |  j | | | f k r•d | } n  |  j | | | f k rºd | } n  |  j | | | f k rà| | } n  |  j | | ƒ d  S(   Ng      à?i   i   g      ð?(   RY   R�   RZ   R’   R‡   Rq   R4   RT   R   R–   t   rangeR�   RL   R   t   AXESPADR›   (    R   R*   R_   R9   R:   R;   R   R<   t   rlt   rbt   rwt   rhR™   Rš   t   BESTt   URt   ULt   LLt   LRt   CLt   CRt   LCt   UCt   Ct   TRt   TLt   BLt   BRt   Rt   Lt   Tt   B(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyRi   ˆ  sJ    	


Kc         C  s   |  j  S(   s#   return a dict of cells in the table(   RW   (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt	   get_celld¿  s    N(   RD   RE   RF   RL   Rc   R�   R   R   Rb   Re   R   R/   Rq   Rt   Rw   t   get_child_artistsR3   R‡   R‰   R�   RG   R-   R’   R–   R%   R›   Ri   R´   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyRH   �   sP   

							%					
		7R   R2   R1   RK   c         K  s¥  | d k r? t | ƒ } t | d ƒ } d g | g | } n  t | ƒ } t | d ƒ } x& | D] } t | ƒ | k sb t ‚ qb W| d k	 rÔ t | ƒ | k s¨ t ‚ x: | D] } t | ƒ | k s¯ t ‚ q¯ Wn d | g | } | d k rd | g | } n  d } | d k r@| d k	 rYd g | } | d } qYn | d k rYd | } n  | d k	 r€t | ƒ | k s€t ‚ n  d } | d k r·|	 d k	 rÖd g | } d } qÖn |	 d k rÖd | }	 d } n  | d k	 rýt | ƒ | k sýt ‚ n  | d k rd | g | } n  t |  | | | � } | j ƒ  } xq t | ƒ D]c } xZ t | ƒ D]L } | j | | | d | | d | d | | | d	 | | | d
 | ƒq^WqKW| d k	 rxQ t | ƒ D]@ } | j d | d | | d | d | | d	 |	 | d
 |
 ƒqËWn  | d k	 r”xT t | ƒ D]F } | j | | d d | pMd d | d | | d	 | | d
 | ƒq+W| d k r”| j d ƒ q”n  |  j | ƒ | S(   sd  
    TABLE(cellText=None, cellColours=None,
          cellLoc='right', colWidths=None,
          rowLabels=None, rowColours=None, rowLoc='left',
          colLabels=None, colColours=None, colLoc='center',
          loc='bottom', bbox=None)

    Factory function to generate a Table instance.

    Thanks to John Gill for providing the class and table.
    i    R   R   g      ð?i   R   R   R   R   R   iÿÿÿÿgVçž¯Ò<N(	   R   R�   t   AssertionErrorRH   Re   t   xrangeRb   R‰   t	   add_table(   R\   t   cellTextt   cellColourst   cellLoct	   colWidthst	   rowLabelst
   rowColourst   rowLoct	   colLabelst
   colColourst   colLocR   R9   RB   R†   Rƒ   R^   t   rowLabelWidtht   offsetRf   R   R_   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyRf   Ä  sz    
	(   RF   t
   __future__R    R   RM   t   artistR   R   t   patchesR   t   cbookR   t
   matplotlibR   R   R   t
   transformsR   R	   RH   R   Rf   t   interpdRA   t   kwdoc(    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/table.pyt   <module>   s$   nÿ 6		b