
    ը	fwe                        d Z ddlZddlmZ ddlmZ ddlZddlZddl	m
Z
 	 ddlZ ej                  d       ddlmZ ddlm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#m$Z$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z, dZ-g dZ.d Z/ G d dej`                        Z1 G d d      Z2d Z3 G d de4      Z5ddZ6e7dk(  r e6        yy# e$ r"Z e ed
      j7                  e            dZ[ww xY w)aT  
@package frame

@brief Timeline Tool

Classes:
 - frame::DataCursor
 - frame::TimelineFrame
 - frame::LookUp

(C) 2012-2020 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Anna Kratochvilova <kratochanna gmail.com>
    N)ceil)cycle)reduceWXAgg)gridspec)Figure)FigureCanvasWxAggNavigationToolbar2WxAggzThe Timeline Tool needs the "matplotlib" (python-matplotlib and on some systems also python-matplotlib-wx) package(s) to be installed. {})GError
GException
RunCommand)gselect)Button
StaticText)	globalvar   )bgrcmykc                      g }t         j                  j                  d      D ]  }	 t        |      }|j	                  |       ! |t        |       k  ryy# t
        $ r |j	                  d       Y Nw xY w)z-Checks if given version or newer is installed.r   FT)
matplotlib__version__splitintappend
ValueErrorlist)versionversionInstalledivs       //usr/lib/grass83/gui/wxpython/timeline/frame.pycheck_versionr(   =   sw    ##))#. '	'AA##A&' $w-'  	'##A&	's   AA10A1c                   p    e Zd ZdZ ed      fdZd Zd Zd Zd Z	d Z
d	 Zdd
Zd Zd Zd Zd Zd Zy)TimelineFramez!The main frame of the applicationzTimeline Toolc                    t         j                  j                  | |t         j                  |       t	        j
                  d       g | _        i | _        | j                          d | _	        d | _
        t	        j                         | _        | j                  j                          | j                  t         j                  | j                          y )N)idtitleT)wxFrame__init__ID_ANYtgisinitdatasetstimeData_layouttemporalTypeunitSQLDatabaseInterfaceConnectiondbifconnectBind	EVT_CLOSEOnClose)selfparentr-   s      r'   r0   zTimelineFrame.__init__O   s    
$299EB		$ 	779					",,-    c                     | j                   j                  du r| j                   j                          t        j                          | j                          y)zbClose the database interface and stop the messenger and C-interface
        subprocesses.
        TN)r:   	connectedcloser2   stop_subprocessesDestroyr?   events     r'   r>   zTimelineFrame.OnClose]   s9     99$&IIOO rA   c           	      	   t        j                  |       | _        t        dd      | _        t        | j                  t         j                  | j                        | _        d| _        d| _	        t        | j                        | _        t        j                  t         j                        | _        | j                  j                  | j                  dt         j                   t         j"                  z  t         j$                  z         | j                  j                  | j                  dt         j$                         | j                  j'                  d       t        j(                  dd	      }t+        j,                  | j                  t         j                  t.        j0                  d
d      | _        t5        | j                  t         j                  t7        d            | _        | j8                  j;                  t         j<                  | j>                         t5        | j                  t         j                  t7        d            | _         | j@                  j;                  t         j<                  | jB                         t        jD                  | j                  t         j                  t7        d            | _#        | jF                  j;                  t         jH                  | j>                         tK        ddd      s>| jF                  jM                  t7        d             | jF                  jO                          |j                  tQ        | j                  t         j                  t7        d            dt         j$                  t         jR                  z         |j                  | j2                  dt         j$                         |j                  | j8                  dt         j$                         |j                  | j@                  dt         j$                         |j                  | jF                  dt         j$                  t         jR                  z         | j                  j                  |dt         j$                  t         jT                  z  d       | j                  jW                  | j                         | j                  jY                  |        y)zCreates the main panel with all the controls on it:
        * mpl canvas
        * mpl navigation toolbar
        * Control panel for interaction
        )g      @g      @r   r   r   )	facecolorNr   r   
      )hgapvgapstdsT)r@   r,   sizetypemultipleDraw)r,   labelHelpz"3D plot of spatio-temporal extentsz83D plot of spatio-temporal extents (matplotlib >= 1.0.0)zSelect space time dataset(s):r   r   )posflag)r   r   )r   r   )r      )rZ   r   )
proportionrY   border)-r.   Panelpanelr   fig	FigCanvasr1   canvasaxes2daxes3dNavigationToolbartoolbarBoxSizerVERTICALvboxAddLEFTTOPEXPAND	AddSpacerGridBagSizerr   Selectr   DIALOG_GSELECT_SIZEdatasetSelectr   _
drawButtonr<   
EVT_BUTTONOnRedraw
helpButtonOnHelpCheckBoxview3dCheckEVT_CHECKBOXr(   SetLabelDisabler   ALIGN_CENTER_VERTICALALLSetSizerFit)r?   	gridSizers     r'   r6   zTimelineFrame._layoutf   s    XXd^
 *	:

BIItxx@ )5 KK,			dkk1bgg&6&BC		dllAryy1		BOO3	$^^::yy..
 !		6KR]]DMM: 		6KR]]DKK8;;JJ299A.R,S
 	boot}}=Q1%%%OP $$&

ryy2Q0R R555 	 	
 	d((f299Edoo6		Bdoo6		B&ryy2;S;S/S 	 	
 			iABII4FrR

DII&		drA   c           	         i | _         d}d}|D ]  }|d   dz   |d   z   }|d   }t        j                  ||      }|j                  | j                        st        | t        d      |z          y|j                  | j                         i | j                   |<   |d   | j                   |   d	<   |j                         | j                   |   d
<   || j                   |   d
   }n-| j                   |   d
   |k7  rt        | t        d              y|j                  | j                        }|j                  || j                        | j                   |   d<   |j                         | j                   |   d<   d| j                   |   d<   | j                   |   d
   dk(  re|j                         \  }	}
| j                   |   d<   || j                   |   d   }n,| j                   |   d   |k7  rt        | t        d              yg | j                   |   d<   g | j                   |   d<   g | j                   |   d<   g | j                   |   d<   g | j                   |   d<   g | j                   |   d<   g | j                   |   d<   dj                  g d      }|j                  |dd| j                        }|s4t        | t        d      j                  |d   dz   |d   z                 y|D ]  }|\  }}	}
}}}}| j                   |   d   j!                  |	       | j                   |   d   j!                  |
       | j                   |   d   j!                  |       | j                   |   d   j!                  |       | j                   |   d   j!                  |       | j                   |   d   j!                  |       | j                   |   d   j!                  |         || _        || _        y) zLoad data and read propertiesNr   @r   rZ   )r:   z+Dataset <%s> not found in temporal database)messageelementTyper7   zRDatasets have different temporal type (absolute x relative), which is not allowed.)r@   r   )mapsr:   validTopologytemporalMapTyper8   relativez7Datasets have different time unit which is not allowed.start_datetimeend_datetimenamesnorthsouthwesteast,)name
start_timeend_timer   r   r   r   r   )columnswhereorderr:   zDataset <{name}> is empty)r   )r5   r2   dataset_factoryis_in_dbr:   r   rr   selectget_temporal_typeget_registered_maps_as_objectscheck_temporal_topologyget_map_timeget_relative_timejoinget_registered_mapsformatr    r7   r8   )r?   
timeseriesmoder8   seriesr   etypespr   startendr   rowsrowmapNamer   r   r   r   s                      r'   _getDatazTimelineFrame._getData   s     Q	9F!9s?VAY.D1IE%%eT2B;;DII;.KLPTU II499I%"$DMM$17DMM$.242F2F2HDMM$/|}}T*>:t$^4<G  44$))4DD353M3M		 4N 4DMM$0 68__5FDMM$ 12*.DMM$'}}T">2j@:<:N:N:P7sDMM$/7<==.v6D]]4(0D8ST 46DMM$ 0124DMM$/+-DMM$(+-DMM$(+-DMM$(*,DMM$'*,DMM$'hhTG ))t<dii * D 9:AA#AY_vay8 B   9@C=UE4d#$45<<UCd#N3::3?d#G,33G<d#G,33E:d#G,33E:d#F+2248d#F+22489SQ	9f !	rA   c                    | j                   j                          | j                   j                  d       | j                  dk(  rt        j
                  }nd }t        t              }g }| j                  D ]   }|d   dz   |d   z   } || j                  |   d         }| j                  |   d   }|d	k(  r || j                  |   d
         |z
  }ndgt        |      z  }| j                  |   d   }| j                  |   d   t        j                  |      z
  }	| j                  |   d   }
| j                  |   d   t        j                  |
      z
  }t        |      }|j                  | j                   j                  ||
||	|||t                      # t#        j$                  dd      }t#        j&                  |      }d|v rU| j                   j)                  t+        d      |d   z         | j                   j-                  t+        d      |d   z         nH| j                   j)                  t+        d             | j                   j-                  t+        d             | j                  dk(  r't/        ddd      r| j                   j1                          | j                   j3                  t+        d             | j                   j5                          | j6                  j9                          y)zDraws 3d view (spatio-temporal extents).


        Only for matplotlib versions >= 1.0.0.
        Earlier versions cannot draw time ticks and alpha
        and it has a slightly different API.
        Fabsolutec                     | S N xs    r'   <lambda>z-TimelineFrame._draw3dFigure.<locals>.<lambda>       rA   r   r   r   r   r   intervalr   r   r   r   r   )coloralphazg.projr   )flagsr8   zX [%s]zY [%s]XYTimeN)rc   cleargridr7   mdatesdate2numr   COLORSr4   r5   lennparraynextr    bar3dALPHAgrassread_commandparse_key_val
set_xlabelrr   
set_ylabelr(   
zaxis_date
set_zlabel
mouse_initra   draw)r?   convertcolorsplotsr   startZmapTypedZstartXdXstartYdYr   paramss                 r'   _draw3dFigurezTimelineFrame._draw3dFigure  sx    	
*ooG!GvMM 	D7S=47*DT]]401ABCFmmD)*;<G*$T]]40@AFJ S3v;&]]4(0Ft$V,rxx/??B]]4(1Ft$W-0@@BLELL!!FFBBe5 " !	, ##HC8$$V,VKK""1X;#?@KK""1X;#?@KK""1S6*KK""1S6*
*Q1%&&(qy) rA   c                 B   | j                   j                          | j                   j                  d       | j                  dk(  rt        j
                  }nd }t        t              }g }g }g }t        | j                        }t        | j                        D ]  \  }}|j                  |d          |d   dz   |d   z   }|j                  |       g }	g }
| j                  |   d   } || j                  |   d         }|d	k(  rx || j                  |   d
         }t        t        ||            }|t        j                   |      z
  }t        t        ||            }	|j#                  d|dz
  |dz   f||       n|}
|j#                  d||
|       t%        |      }|d	k(  r;|j                  | j                   j'                  |	|dz
  df|dt(        d             G|j                  | j                   j+                  |
|gt-        |
      z  dd|d      d           | j                  dk(  r5| j                   j/                          | j0                  j3                          n1| j                   j5                  t7        d      | j8                  z         | j                   j;                  |       | j                   j=                  |       | j                   j?                  tA        |      dz
  tC        |      dz          | j                   jE                         }tG        |d   |d   z
  dz        }| j                   jI                  |d   |z
  |d   |z          | j                   jK                  d       | jL                  jO                          tQ        ||tR               y)z Draws 2D plot (temporal extents)Tr   c                     | S r   r   r   s    r'   r   z-TimelineFrame._draw2dFigure.<locals>.<lambda>J  r   rA   r   r   r   r   r   r   r   barg?)type_yrangexrangesdatasetNamepointg?black)r   r   
facecolors	edgecolorr   pickeroNone)marker	linestyler   r   z	Time [%s]g      4@N)*rb   r   r   r7   r   r   r   r   LookUpr5   	enumerater4   r    r"   zipr   r   
AddDatasetr   broken_barhr   plotr   
xaxis_dater_   autofmt_xdater   rr   r8   
set_yticksset_yticklabelsset_ylimminmaxget_xlimr   set_xlimset_axisbelowra   r   
DataCursor
InfoFormat)r?   r   r   yticksNames	yticksPosr   lookUpr%   r   barData	pointDatar   r   r   
lookUpDatadurationr   xlimpaddings                      r'   _draw2dFigurezTimelineFrame._draw2dFigureC  sN   
*ooG!Gv	& / 3	GAttAw'7S=47*DQGImmD)*;<GDMM$/0@ABE*$dmmD1.AB!#eS/2
%0s5(34!!GQW-& $	 "  "	!!!!YD "  LE*$KK++ ' !C~#(")## , 	 KK$$!c)n,""(## %  	U3	j 
*KK""$HH""$ KK""1[>DII#=>y)##K0S^a/Y!1CD {{##%Q$q')T12T!Ww.Q'0AB!!$'5&*-rA   c                 0   | j                   j                         j                         }|sy|j                  d      }	 | j	                  |      }|sy	 || _        | j                          y# t
        $ r!}t        | t        |      d       Y d}~yd}~ww xY w)zRequired redrawing.Nr   Fr@   r   showTraceback)
rq   GetValuestripr   _checkDatasetsr   r   strr4   _redraw)r?   rH   r4   errors       r'   ru   zTimelineFrame.OnRedraw  s    %%..0668>>#&	**84H  !  	$E
%H	s   A+ +	B4BBc           
      2   t        ddd      s| j                  j                  |||       yt        | j                  j
                        D ]J  \  }}|j                  t        j                  t        j                  ||| j                        |             L y)zChange figure geometry

        https://github.com/kecnry/autofig/commit/93e6debb953f5b2afe05f463064d60b9566afa59

        :param int rows: number of rows
        :param int cols: number of cols
        :param int num: subplot order
              r   figureN)
r(   rb   change_geometryr   r_   axesset_subplotspecr   SubplotSpecGridSpec)r?   nrowsncolsnumr%   axs         r'   _change_figure_geometryz%TimelineFrame._change_figure_geometry  s     Q1%KK''uc:"488==1 
2""(( ))!!#'88
 	
rA   c                    | j                  | j                         | j                  s"| j                  j	                  ddd      | _        | j                          t        ddd      r| j                  j                         rv| j                  ddd       | j                  s*ddlm} | j                  j	                  dddd      | _
        | j                  j                  d       | j                          y	| j                  rL| j                  j                  | j                         d	| _
        | j                          | j                          | j                   j#                          y	y	)
zXReadraw data.

        Decides if to draw also 3D and adjusts layout if needed.
        r   r   rZ   )r  r  r  )Axes3D3d)
projectionTN)r   r4   rb   r_   add_subplotr	  r(   ry   	IsCheckedr!  rc   mpl_toolkits.mplot3dr#  set_visibler   delaxesra   r   )r?   r#  s     r'   r  zTimelineFrame._redraw  s   
 	dmm$ {{((..q!Q7DKAq!))+,,1A1,E{{ <"&(("6"6q!Q4"6"PDK''-""$;;HH$$T[[1"&DK002&&(  "% "rA   c                 ^   g }t        j                  dd| j                        }t        j                  |      D cg c]@  \  }}t        j                  |      D cg c]  \  }}|D cg c]  }|||f	 c} c}}}B }	}}}}}|	rWt        d t        d |	            }	t        j                         j                         t        |	fd      D 
cg c]  }
|
 }	}
|D ]  }t        d      |z  }|j                  d	      d
k\  rE|j                  d	d      \  }}t        |	      D cg c]  \  }\  }}}||k(  r||k(  r| }}}}}n*t        |	      D cg c]  \  }\  }}}||k(  r| }}}}}t        |      d
k(  rt        |      t        |      dk\  rt        j                   | t        d|z        t        d      |D 
cg c]  }
d|	|
   d
   |	|
   d   |	|
   d   dz   c}
t        j"                  t        j$                  z        }|j'                         t        j(                  k(  r)|j+                         }|j-                  |	||             {}|j-                  |	|d
              |S c c}w c c}}}w c c}}}}}w c c}
w c c}}}}w c c}}}}w c c}
w )zChecks and validates datasets.

        Reports also type of dataset (e.g. 'strds').

        :return: (mapName, mapset, type)
        rP   T)
group_typer:   c                     | |z   S r   r   r   r   s     r'   r   z.TimelineFrame._checkDatasets.<locals>.<lambda>  s
    QU rA   c                     | |z   S r   r   r.  s     r'   r   z.TimelineFrame._checkDatasets.<locals>.<lambda>  s
    A rA   c                 ,    j                  | d         S )Nr   )index)lmapsetss    r'   r   z.TimelineFrame._checkDatasets.<locals>.<lambda>  s    W]]1Q4=P rA   )keyz"Space time dataset <%s> not found.r   r   r   rZ   z+Please specify the space time dataset <%s>.zAmbiguous dataset namez%(map)s@%(mapset)s: %(etype)s)mapmapsetr   )r   captionchoicesstyle)r2   tlist_groupedr:   six	iteritemsr   get_tgis_c_library_interfaceavailable_mapsetssortedrr   findr   r   r   r   r.   SingleChoiceDialogCHOICEDLG_STYLEOK	ShowModalID_OKGetSelectionr    )r?   r4   	validatedtDictr6  
etypesDictr   r   r5  allDatasetsr%   dataseterrorMsg	nameShortnr   
mapsetNameindicesdlgr1  r3  s                       @r'   r  zTimelineFrame._checkDatasets  s    	""6dK '*mmE&:
 

 #
 $'==#< E4 266##vu%6
 
  "F+={$KK 779KKMG!+3PQK    *	:G=>HH||C A%$+MM#q$9!	6 <E[;Q 77GZ G+
f0D   8A7M 33GVU')   7|q  **W"++KgUV67 ")
  <'21~a'8*5a.*;)4Q):
 ,,ruu4" ==?bhh.,,.E$$[%@A  WQZ!89U*	:X w 7

sB   !J"J.J :J?J	J2J"J""J* JJc                      t        ddd       y )Nzg.manualTzg.gui.timeline)quietentry)r   rG   s     r'   rw   zTimelineFrame.OnHelp,  s    :T1ABrA   c                 (   |sy	 | j                  |      }|sy	 || _        | j
                  j                  dj                  t        d |                   | j                          y# t        $ r!}t        | t        |      d       Y d}~yd}~ww xY w)zSet dataNFr  r   c                     | d   dz   | d   z   S )Nr   r   r   r   r   s    r'   r   z+TimelineFrame.SetDatasets.<locals>.<lambda>>  s    1Q4#:!#4 rA   )
r  r   r   r  r4   rq   SetValuer   r5  r  )r?   r4   r  s      r'   SetDatasetszTimelineFrame.SetDatasets1  s    	**84H 
 !##HHS4h?@	
 	  	$E
%H	s   A' '	B0BBc                 V    t        ddd      r| j                  j                  |       yy)zShow also 3D if possibler   r   N)r(   ry   rW  )r?   shows     r'   Show3DzTimelineFrame.Show3DB  s'    Aq!%%d+ "rA   NrJ   )__name__
__module____qualname____doc__rr   r0   r>   r6   r   r   r	  ru   r!  r  r  rw   rX  r[  r   rA   r'   r*   r*   L   sX    +%&%7 .GRZx6pV.p"0#>GRC
",rA   r*   c                   "    e Zd ZdZd Zd Zd Zy)r   z.Helper class for searching info by coordinatesc                      i | _         || _        y r   )datar5   )r?   r5   s     r'   r0   zLookUp.__init__K  s    	 rA   c                 
   |dk(  r<d|i| j                   |<   t        |      D ]  \  }\  }}|| j                   |   ||f<    y |dk(  r=d|i| j                   ||f<   t        |      D ]  \  }}|| j                   ||f   ||f<    y y )Nr   r   r   )rb  r   )r?   r   r   r   r   r%   r   r   s           r'   r   zLookUp.AddDatasetO  s    E>!' 5DIIf#,W#5 4<E323		&!5#,/4g+1;*?DIIvv&'%g. @5>?		66*+UEN;@ rA   c                 x   d }| j                   j                         D ]]  }|d   |cxk  r	|d   k  sn | j                   |   j                         D ]"  }|dk7  s	|d   |cxk  r	|d   k  sn ||f} n |s] n |sy | j                   |d      d   }| j                   |d      |d      }| j                  ||fS )Nr   r   r   )rb  keysr5   )r?   r   r   re  keyYkeyXr   mapIndexs           r'   GetInformationzLookUp.GetInformationY  s    IINN$ 	DAw!&tAw& IIdO002 Dv~$q'Q*A$q'*A#Tz 	 iiQ(099T!W%d1g.}}k833rA   N)r\  r]  r^  r_  r0   r   ri  r   rA   r'   r   r   H  s    8!@4rA   r   c                    g }| |   d   }|j                  d      \  }}|dk(  r|j                  t        d      |z         nE|dk(  r|j                  t        d      |z         n"|dk(  r|j                  t        d      |z         |j                  t        d	      |z         |j                  t        d
      | |   d   |   z         |j                  t        d      | |   d   |   z         |j                  t        d      | |   d   |   z         | |   d   s|j                  t        d             |j                  t        d             dj                  |      S )z!Formats information about datasetr   r   strdszSpace time raster dataset: %sstvdszSpace time vector dataset: %sstr3dsz Space time 3D raster dataset: %sz
Mapset: %szMap name: %sr   zStart time: %sr   zEnd time: %sr   r   zWARNING: invalid topologyz
Press Del to dismiss.
)r   r    rr   r   )r5   r   rh  textr   r   r6  s          r'   r   r   k  sL   D[!-0E$$S)LD&A56=>	'	A56=>	(	A89D@AKK,&()KK.!H[$9'$B8$LLMKK"#h{&;<L&Mh&WWXKK.!H[$9.$I($SSTK 1A123KK+,-99T?rA   c                   0    e Zd ZdZ	 	 	 ddZd Zd Zd Zy)r   zA simple data cursor widget that displays the x,y location of a
    matplotlib artist when it is selected.


    Source: http://stackoverflow.com/questions/4652439/
            is-there-a-matplotlib-equivalent-of-matlabs-datacursormode/4674445
    c                 x   || _         || _        || _        || _        t	        j
                  |      s|g}|| _        t        t        d | j                  D                    | _	        t        t        d | j                  D                    | _
        i | _        | j                  D ]   }| j                  |      | j                  |<   " | j                  D ]  }|j                  |        | j                  D ]D  }	|	j                  j                  d|        |	j                  j                  d| j                          F y)aO  Create the data cursor and connect it to the relevant figure.
        "artists" is the matplotlib artist or sequence of artists that will be
            selected.
        "tolerance" is the radius (in points) that the mouse click must be
            within to select the artist.
        "offsets" is a tuple of (x,y) offsets in points from the selected
            point to the displayed annotation box
        "display_all" controls whether more than one annotation box will
            be shown if there are multiple axes.  Only one will be shown
            per-axis, regardless.
        c              3   4   K   | ]  }|j                     y wr   )r  ).0arts     r'   	<genexpr>z&DataCursor.__init__.<locals>.<genexpr>  s     ?3chh?   c              3   4   K   | ]  }|j                     y wr   r  )rs  r   s     r'   ru  z&DataCursor.__init__.<locals>.<genexpr>  s      ?r ?rv  
pick_eventkey_press_eventN)r  formatFunctionoffsetsdisplay_allr   iterableartiststuplesetr  figuresannotationsannotateset_pickradiusra   mpl_connect
keyPressed)
r?   r~  r  rz  	tolerancer{  r|  r   artistr_   s
             r'   r0   zDataCursor.__init__  s	   ( ,&{{7#iG#?$,,??@	S ?TYY ??@)) 	5B#'==#4DR 	5ll 	-F!!),	-<< 	GCJJ""<6JJ""#4dooF	GrA   c                     |j                   dk7  ry| j                  D ]:  }| j                  |   j                  d       |j                  j                          < y)z3Key pressed - hide annotation if Delete was presseddeleteNF)r4  r  r  r)  ra   r   )r?   rH   r   s      r'   r  zDataCursor.keyPressed  sM    99 )) 	 BR ,,U3LL	 rA   c                     |j                  | j                  dd| j                  ddt        ddd      t        d	d
      dd
      }|j	                  d       |S )z;Draws and hides the annotation box for the given axis "ax".rW   centerzoffset pointsbottomzround,pad=0.5yellowgffffff?)boxstylefcr   z->z
arc3,rad=0)
arrowstyleconnectionstyleFleft)	xyhaxytext
textcoordsvabbox
arrowpropsannotation_clipmultialignment)r  rz  r{  dictr)  )r?   r   
annotations      r'   r  zDataCursor.annotate  sc    [[<<&83Gt\J!! ! 

 	u%rA   c                    |j                   j                  |j                   j                  }}| j                  |j                  j
                     }|+| j                  s0| j                  j                         D ]  }|j                  d        ||f|_	        dt        t        |j                              v r[|j                  j                         d   }|j                  j                         }|t        j                  t!        ||z
                 }| j"                  j%                  ||      }|sy | j&                  | }|j)                  |       |j                  d       |j*                  j-                          yy)z,Intended to be called through "mpl_connect".NFLine2Dr   T)
mouseeventxdataydatar  r  r  r|  valuesr)  r  r  rR   	get_ydata	get_xdatar   argminabsr  ri  rz  set_textra   r   )	r?   rH   r   r   r  annxDatainforo  s	            r'   __call__zDataCursor.__call__  s=    %%u'7'7'='=1%%ell&7&78
=##++224 +COOE*+ qDJM3tELL122LL**,Q/..0"))C	N34;;--a3D&4&&-D%""4(LL' rA   N)rM   )i   F)r\  r]  r^  r_  r0   r  r  r  r   rA   r'   r   r     s(     &GP $ rA   r   c                 `    t        |       }|r|j                  |       |j                          y r   )r*   rX  Show)r@   r4   frames      r'   runr    s&    &!E(#	JJLrA   __main__)NN)8r_  r;  mathr   	itertoolsr   numpyr   r.   	functoolsr   r   user   matplotlib.figurer   !matplotlib.backends.backend_wxaggr	   r`   r
   rd   matplotlib.datesdatesr   ImportErrorerr   r   grass.scriptscriptr   grass.temporaltemporalr2   	core.gcmdr   r   r   gui_corer   gui_core.wrapr   r   corer   r   r   r(   r/   r*   r   r   objectr   r  r\  r   rA   r'   <module>r     s   $     	  JNN7#( &   4 4  , 		,y,BHH y,x 4  4F2d  d N zE U  
	-	
 &) s   0C C+	C&&C+