Public Member Functions | |
| def | __init__ |
| Default constructor. | |
| def | getZoomFactor |
| Returns the zoom factor, computed by looking at the current Y Axis. | |
| def | getLonLatFromMouseXY |
| Convert the mouse XY coordinates (from MouseEvent) into map longitude/latitude coordinates. | |
| def | getAxesXYFromMouseXY |
| Convert the mouse X/Y coordinates (from MouseEvent) to Figure axes X/Y values coordinates. | |
| def | setCurrentXYLim |
| Sets the new zoom values expressed in terms of new Figure Axes values. | |
| def | setFullXYLim |
| sets the minimum zoom values. | |
| def | computeFullXYLim |
| Returns the minimum zoom value. | |
| def | getCurrentXYLim |
| Returns the current X, Y Axes values. | |
| def | adjustAxisToCanavas |
| adjusts the X and Y axes to match the same aspect ratio as a whatever the Canavas just changed to. | |
| def | freeZoom |
| Zoom (i.e change the X/Y Axes values) using the results of a from/to rectangle. | |
| def | freeZoomChangeAspect |
| Zoom (i.e change the X/Y Axes) using the results of a from/to rectangle. | |
| def | zoomIn |
| Zoom in using some fixed amount. | |
| def | zoomOut |
| Zoom out using some fixed amount. | |
| def | resetZoom |
| Initialize Zoom values (during map initialization). | |
| def | resetCurrentZoom |
| Reset the Zoom values (Part of the map's redraw cycle). | |
| def | pan |
| Pan to a new location screen location. | |
Public Attributes | |
| axes | |
| currentXAxis | |
| currentYAxis | |
| fullXAxis | |
| fullYAxis | |
Any conversion (screen to map and vice versa), scaling, zooming and panning methods will be found here.
For additional information, please refer to the MatplotLib documentation
Definition at line 24 of file figureAxesWrapper.py.
| def objects.gui.figureAxesWrapper.figureAxesWrapper.__init__ | ( | self, | ||
| ax | ||||
| ) |
Default constructor.
| ax | This is the Axes object returned from the Figure.add_axes(...) method |
Definition at line 28 of file figureAxesWrapper.py.
00028 : 00029 self.axes = ax 00030 00031 # current zoom setting 00032 self.currentXAxis = None 00033 self.currentYAxis = None 00034 00035 # full zoom settings 00036 self.fullXAxis = None 00037 self.fullYAxis = None 00038 00039 00040 ## Returns the zoom factor, computed by looking at the current Y Axis.
| def objects.gui.figureAxesWrapper.figureAxesWrapper.adjustAxisToCanavas | ( | self, | ||
| newCanavasSize | ||||
| ) |
adjusts the X and Y axes to match the same aspect ratio as a whatever the Canavas just changed to.
This is usually in response to the user resizing the screen, and therefore changing the shape of the screen rectangle.
| newCanavasSize | New Canavas Size. |
Definition at line 113 of file figureAxesWrapper.py.
00113 : 00114 00115 x1, y1 = self.axes.transData.xy_tup( (self.currentXAxis[0], self.currentYAxis[0]) ) 00116 x2, y2 = self.axes.transData.xy_tup( (self.currentXAxis[1], self.currentYAxis[1]) ) 00117 #MH#x1, y1 = self.axes.transData.transform( (self.currentXAxis[0], self.currentYAxis[0]) ) 00118 #MH#x2, y2 = self.axes.transData.transform( (self.currentXAxis[1], self.currentYAxis[1]) ) 00119 00120 frm = wx.Point() 00121 to = wx.Point() 00122 00123 frm.x=x1;frm.y=y1;to.x=x2;to.y=y2 00124 00125 # since the from/to did not change, this will essentially just change the aspect 00126 self.freeZoomChangeAspect(frm, to, newCanavasSize, False) 00127 00128 00129 ## Zoom (i.e change the X/Y Axes values) using the results of a from/to rectangle.
| def objects.gui.figureAxesWrapper.figureAxesWrapper.computeFullXYLim | ( | self | ) |
Returns the minimum zoom value.
I.e the "Zoomed all the way out" value. Typically this is only called once (when the map is created).
Definition at line 99 of file figureAxesWrapper.py.
00099 : 00100 self.fullXAxis = self.axes.get_xlim() 00101 self.fullYAxis = self.axes.get_ylim() 00102 ## Returns the current X, Y Axes values
| def objects.gui.figureAxesWrapper.figureAxesWrapper.freeZoom | ( | self, | ||
| frm, | ||||
| to | ||||
| ) |
Zoom (i.e change the X/Y Axes values) using the results of a from/to rectangle.
Note the this will not sync with the main window's aspect ratio.
| frm | wx.Point | |
| to | wx.Point |
Definition at line 134 of file figureAxesWrapper.py.
00134 : 00135 # normalize values 00136 if (frm.x > to.x): 00137 normStartX, normEndX = to.x, frm.x 00138 else: 00139 normStartX, normEndX = frm.x, to.x 00140 00141 if (frm.y > to.y): 00142 normStartY, normEndY = to.y, frm.y 00143 else: 00144 normStartY, normEndY = frm.y, to.y 00145 00146 startX, startY = self.axes.transData.inverse_xy_tup( (normStartX, normStartY) ) 00147 endX, endY = self.axes.transData.inverse_xy_tup( (normEndX, normEndY) ) 00148 #MH##startX, startY = self.axes.transData.inverted().transform( (normStartX, normStartY) ) 00149 #MH##endX, endY = self.axes.transData.inverted().transform( (normEndX, normEndY) ) 00150 00151 self.setCurrentXYLim((startX, endX),(startY, endY)) 00152 00153 00154 ## Zoom (i.e change the X/Y Axes) using the results of a from/to rectangle.
| def objects.gui.figureAxesWrapper.figureAxesWrapper.freeZoomChangeAspect | ( | self, | ||
| frm, | ||||
| to, | ||||
| canavas, | ||||
validateSelectionSize = True | ||||
| ) |
Zoom (i.e change the X/Y Axes) using the results of a from/to rectangle.
Note the this will sync with the main window's aspect ratio, so actual zoom amount will be approximated to some degree.
| frm | wx.Point | |
| to | wx.Point | |
| canavas | The canvas, whose aspect ratio must be matched. | |
| validateSelectionSize | If True, it will not allow the user to zoom if the from to rectangle is too small. This is done to prevent the user from accidentally dragging the mouse (and then zooming in way too far) when in Zoom mode. |
Definition at line 162 of file figureAxesWrapper.py.
00162 : 00163 00164 #1) normalize values 00165 if (frm.x > to.x): 00166 normStartX, normEndX = to.x, frm.x 00167 else: 00168 normStartX, normEndX = frm.x, to.x 00169 00170 if (frm.y > to.y): 00171 normStartY, normEndY = to.y, frm.y 00172 else: 00173 normStartY, normEndY = frm.y, to.y 00174 00175 00176 #2) figure out aspect ratios 00177 propX, propY = canavas 00178 00179 # validate 00180 if propY == 0: return 00181 if normEndY - normStartY == 0: return 00182 00183 canavasAspectRatio = float(propX)/float(propY) 00184 marquisAspectRatio = float(abs(normEndX - normStartX)) / float(abs(normEndY - normStartY)) 00185 00186 # this value could vary, but a 5-1 or 1-5 ratio for a marquis selection is probably 00187 # the result of the user making an error 00188 # 00189 if validateSelectionSize == True: 00190 if marquisAspectRatio > 5 or marquisAspectRatio < 0.2: 00191 return 00192 00193 if canavasAspectRatio == 0: return 00194 00195 # need to strech the X axis 00196 if (canavasAspectRatio > 1): 00197 newWidth = abs(normEndY - normStartY) * canavasAspectRatio 00198 00199 # this is the amount we need to stretch the x axis by 00200 deltaWidth = (newWidth / 2) - (abs(normEndX - normStartX) / 2) 00201 00202 # now just adjust the X axis 00203 normStartX = normStartX - deltaWidth 00204 normEndX = normEndX + deltaWidth 00205 00206 else: #strech the Y axis only 00207 newHeight = abs(normEndX - normStartX) / canavasAspectRatio 00208 00209 # this is the amount we need to stretch the Y axis by 00210 deltaHeight = (newHeight / 2) - (abs(normEndY - normStartY) / 2) 00211 00212 # now just adjust the Y axis 00213 normStartY = normStartY - deltaHeight 00214 normEndY = normEndY + deltaHeight 00215 00216 00217 tStartX, tStartY = self.axes.transData.inverse_xy_tup( (normStartX, normStartY) ) 00218 tEndX, tEndY = self.axes.transData.inverse_xy_tup( (normEndX, normEndY) ) 00219 #MH##tStartX, tStartY = self.axes.transData.inverted().transform( (normStartX, normStartY) ) 00220 #MH##tEndX, tEndY = self.axes.transData.inverted().transform( (normEndX, normEndY) ) 00221 00222 00223 # make sure we do not exceed our mins and maxes 00224 if tStartX < self.fullXAxis[0]:startX = self.fullXAxis[0] 00225 else:startX = tStartX 00226 00227 if tEndX > self.fullXAxis[1]:endX = self.fullXAxis[1] 00228 else:endX = tEndX 00229 00230 if tStartY < self.fullYAxis[0]:startY = self.fullYAxis[0] 00231 else:startY = tStartY 00232 00233 if tEndY > self.fullYAxis[1]:endY = self.fullYAxis[1] 00234 else:endY = tEndY 00235 00236 # reset the limits 00237 self.setCurrentXYLim((startX, endX),(startY, endY)) 00238
| def objects.gui.figureAxesWrapper.figureAxesWrapper.getAxesXYFromMouseXY | ( | self, | ||
| mouseX, | ||||
| mouseY | ||||
| ) |
Convert the mouse X/Y coordinates (from MouseEvent) to Figure axes X/Y values coordinates.
| mouseX | Screen X position as determined by a mouse event | |
| mouseY | Screen Y position as determined by a mouse event |
Definition at line 73 of file figureAxesWrapper.py.
00073 : 00074 axesX, axesY = self.axes.transData.inverse_xy_tup( (mouseX,mouseY) ) 00075 #MH##axesX, axesY = self.axes.transData.inverted().transform( (mouseX,mouseY) ) 00076 00077 return axesX, axesY 00078 ## Sets the new zoom values expressed in terms of new Figure Axes values
| def objects.gui.figureAxesWrapper.figureAxesWrapper.getCurrentXYLim | ( | self | ) |
Returns the current X, Y Axes values.
Definition at line 105 of file figureAxesWrapper.py.
00105 : 00106 return self.currentXAxis, self.currentYAxis 00107 00108 ## adjusts the X and Y axes to match the same aspect ratio as a
| def objects.gui.figureAxesWrapper.figureAxesWrapper.getLonLatFromMouseXY | ( | self, | ||
| mouseX, | ||||
| mouseY, | ||||
| main_map | ||||
| ) |
Convert the mouse XY coordinates (from MouseEvent) into map longitude/latitude coordinates.
| mouseX | Screen X position as determined by a mouse event | |
| mouseY | Screen Y position as determined by a mouse event | |
| main_map | BaseMap object |
Definition at line 57 of file figureAxesWrapper.py.
00057 : 00058 mouseMapX, mouseMapY = self.axes.transData.inverse_xy_tup( (mouseX,mouseY) ) 00059 mouseMapX, mouseMapY = self.axes.transData.inverse_xy_tup( (mouseX,mouseY) ) 00060 00061 #MH##mouseMapX, mouseMapY = self.axes.transData.inverted().transform( (mouseX,mouseY) ) 00062 #MH##mouseMapX, mouseMapY = self.axes.transData.inverted().transform( (mouseX,mouseY) ) 00063 00064 lon, lat = main_map(mouseMapX, mouseMapY, True) 00065 00066 return lon, lat 00067 ## Convert the mouse X/Y coordinates (from MouseEvent) to Figure axes X/Y values
| def objects.gui.figureAxesWrapper.figureAxesWrapper.getZoomFactor | ( | self | ) |
Returns the zoom factor, computed by looking at the current Y Axis.
Zooming and panning in MatplotLib can be achieved setting the current axes to some fraction of the figure Axes.S For example, if the X axes range is (0, 100), then setting a new range of (25, 75) will be the equivalent of a 200% zoom. Similarly, by changing these numbers one can also achieve a panning effect.
Definition at line 47 of file figureAxesWrapper.py.
00047 : 00048 return abs(self.currentYAxis[1] - self.currentYAxis[0]) 00049 00050 ## Convert the mouse XY coordinates (from MouseEvent) into map longitude/latitude
| def objects.gui.figureAxesWrapper.figureAxesWrapper.pan | ( | self, | ||
| frm, | ||||
| to | ||||
| ) |
Pan to a new location screen location.
| frm | From location. Used to calculate the Pan Amount | |
| to | To location. Used to calculate the Pan Amount |
Definition at line 350 of file figureAxesWrapper.py.
00350 : 00351 00352 if frm is None or to is None: return 00353 00354 startX, startY = self.axes.transData.inverse_xy_tup( (frm.x, frm.y) ) 00355 endX, endY = self.axes.transData.inverse_xy_tup( (to.x, to.y) ) 00356 #MH##startX, startY = self.axes.transData.inverted().transform( (frm.x, frm.y) ) 00357 #MH##endX, endY = self.axes.transData.inverted().transform( (to.x, to.y) ) 00358 00359 dx = endX - startX 00360 dy = endY - startY 00361 00362 panXmin = self.currentXAxis[0] - dx 00363 panXmax = self.currentXAxis[1] - dx 00364 00365 panYmin = self.currentYAxis[0] + dy 00366 panYmax = self.currentYAxis[1] + dy 00367 00368 # don't pan beyond the original map boundaries 00369 if panXmin < self.fullXAxis[0] or panXmax > self.fullXAxis[1]: 00370 if (panXmin < self.fullXAxis[0]): 00371 panXmin = self.fullXAxis[0] 00372 panXmax = self.currentXAxis[1] + (panXmin - self.currentXAxis[0]) 00373 else: 00374 panXmax = self.fullXAxis[1] 00375 panXmin = self.currentXAxis[0] + (panXmax - self.currentXAxis[1]) 00376 00377 if panYmin < self.fullYAxis[0] or panYmax > self.fullYAxis[1]: 00378 if (panYmin < self.fullYAxis[0]): 00379 panYmin = self.fullYAxis[0] 00380 panYmax = self.currentYAxis[1] + (panYmin - self.currentYAxis[0]) 00381 else: 00382 panYmax = self.fullYAxis[1] 00383 panYmin = self.currentYAxis[0] + (panYmax - self.currentYAxis[1]) 00384 00385 00386 self.axes.set_xlim((panXmin, panXmax)) 00387 self.axes.set_ylim((panYmin, panYmax)) 00388 00389 self.currentXAxis = tuple((panXmin, panXmax)) 00390 self.currentYAxis = tuple((panYmin, panYmax)) 00391 00392 00393
| def objects.gui.figureAxesWrapper.figureAxesWrapper.resetCurrentZoom | ( | self | ) |
Reset the Zoom values (Part of the map's redraw cycle).
Definition at line 342 of file figureAxesWrapper.py.
00342 : 00343 self.axes.set_xlim(self.currentXAxis) 00344 self.axes.set_ylim(self.currentYAxis) 00345 00346 ## Pan to a new location screen location
| def objects.gui.figureAxesWrapper.figureAxesWrapper.resetZoom | ( | self | ) |
Initialize Zoom values (during map initialization).
Definition at line 333 of file figureAxesWrapper.py.
00333 : 00334 self.axes.set_xlim(self.fullXAxis) 00335 self.axes.set_ylim(self.fullYAxis) 00336 00337 self.currentXAxis = tuple(self.fullXAxis) 00338 self.currentYAxis = tuple(self.fullYAxis) 00339 00340 ## Reset the Zoom values (Part of the map's redraw cycle)
| def objects.gui.figureAxesWrapper.figureAxesWrapper.setCurrentXYLim | ( | self, | ||
| xlim, | ||||
| ylim | ||||
| ) |
Sets the new zoom values expressed in terms of new Figure Axes values.
| xlim | new X Axes value | |
| ylim | new Y Axes value |
Definition at line 82 of file figureAxesWrapper.py.
00082 : 00083 self.currentXAxis = xlim 00084 self.currentYAxis = ylim 00085 00086 self.axes.set_xlim(xlim) 00087 self.axes.set_ylim(ylim) 00088 ## sets the minimum zoom values. These are the Axes values which are used to determine
| def objects.gui.figureAxesWrapper.figureAxesWrapper.setFullXYLim | ( | self, | ||
| xlim, | ||||
| ylim | ||||
| ) |
sets the minimum zoom values.
These are the Axes values which are used to determine when you are zoomed out all the way
| xlim | new X Axes limit | |
| ylim | new Y Axes limit |
Definition at line 93 of file figureAxesWrapper.py.
00093 : 00094 self.fullXAxis = xlim 00095 self.fullYAxis = ylim 00096 ## Returns the minimum zoom value. I.e the "Zoomed all the way out" value.
| def objects.gui.figureAxesWrapper.figureAxesWrapper.zoomIn | ( | self, | ||
| canavas | ||||
| ) |
Zoom in using some fixed amount.
The lack of a from/to rectangle means that we are zooming straight in (i.e like when using the mouse scroll)
| canavas | Canavas object whose aspect ratio we are trying to preserve |
Definition at line 242 of file figureAxesWrapper.py.
00242 : 00243 xLim, yLim = self.getCurrentXYLim() 00244 00245 xLen = abs(xLim[1] - xLim[0]) 00246 yLen = abs(yLim[1] - yLim[0]) 00247 00248 # let's try a 20% zoom in factor 00249 xDelta = (xLen * 0.2) / 2 00250 yDelta = (yLen * 0.2) / 2 00251 00252 self.setCurrentXYLim((xLim[0] + xDelta, xLim[1] - xDelta),(yLim[0] + yDelta, yLim[1] - yDelta)) 00253 self.adjustAxisToCanavas(canavas) 00254 00255 00256 ## Zoom out using some fixed amount. The lack of a from/to rectangle means that we are zooming straight out
| def objects.gui.figureAxesWrapper.figureAxesWrapper.zoomOut | ( | self, | ||
| canavas | ||||
| ) |
Zoom out using some fixed amount.
The lack of a from/to rectangle means that we are zooming straight out (i.e like when using the mouse scroll)
| canavas | Canavas object whose aspect ratio we are trying to preserve |
Definition at line 260 of file figureAxesWrapper.py.
00260 : 00261 00262 #xLim = self.fullXAxis 00263 #yLim = self.fullYAxis 00264 00265 xLim, yLim = self.getCurrentXYLim() 00266 00267 xLen = abs(xLim[1] - xLim[0]) 00268 yLen = abs(yLim[1] - yLim[0]) 00269 00270 # let's try a 20% zoom in factor 00271 xDelta = (xLen * 0.2) / 2 00272 yDelta = (yLen * 0.2) / 2 00273 00274 # check to see how much I can really zoom out 00275 canExpandLeft = (xLim[0] - xDelta) >= self.fullXAxis[0] 00276 canExpandRight = (xLim[1] + xDelta) <= self.fullXAxis[1] 00277 canExpandBottom = (yLim[0] - yDelta) >= self.fullYAxis[0] 00278 canExpandTop = (yLim[1] + yDelta) <= self.fullYAxis[1] 00279 00280 xMin, xMax, yMin, yMax = 0, 0, 0, 0 00281 00282 if canExpandLeft and canExpandRight: 00283 xMin = xLim[0] - xDelta 00284 xMax = xLim[1] + xDelta 00285 00286 elif not canExpandLeft and not canExpandRight: 00287 xMin = self.fullXAxis[0] 00288 xMax = self.fullXAxis[1] 00289 00290 elif not canExpandLeft and canExpandRight: 00291 extraSpace = abs(xLim[0] - xDelta) 00292 xMin = self.fullXAxis[0] 00293 xMax = xLim[1] + xDelta + extraSpace 00294 if xMax > self.fullXAxis[1]: xMax = self.fullXAxis[1] 00295 00296 else: 00297 extraSpace = abs(self.fullXAxis[1] - (xLim[1] + xDelta)) 00298 xMin = xLim[0] - xDelta - extraSpace 00299 if xMin < self.fullXAxis[0]: xMin = self.fullXAxis[0] 00300 xMax = self.fullXAxis[1] 00301 00302 00303 if canExpandBottom and canExpandTop: 00304 yMin = yLim[0] - yDelta 00305 yMax = yLim[1] + yDelta 00306 00307 elif not canExpandBottom and not canExpandTop: 00308 yMin = self.fullYAxis[0] 00309 yMax = self.fullYAxis[1] 00310 00311 elif not canExpandBottom and canExpandTop: 00312 extraSpace = abs(yLim[0] - yDelta) 00313 yMin = self.fullYAxis[0] 00314 yMax = yLim[1] + yDelta + extraSpace 00315 if yMax > self.fullYAxis[1]: yMax = self.fullYAxis[1] 00316 00317 else: 00318 extraSpace = abs(self.fullYAxis[1] - (yLim[1] + yDelta)) 00319 yMin = yLim[0] - yDelta - extraSpace 00320 if yMin < self.fullYAxis[0]: yMin = self.fullYAxis[0] 00321 yMax = self.fullYAxis[1] 00322 00323 00324 00325 00326 self.setCurrentXYLim((xMin, xMax), (yMin, yMax)) 00327 self.adjustAxisToCanavas(canavas) 00328 00329 00330 00331 ## Initialize Zoom values (during map initialization)
Definition at line 29 of file figureAxesWrapper.py.
Definition at line 32 of file figureAxesWrapper.py.
Definition at line 33 of file figureAxesWrapper.py.
Definition at line 36 of file figureAxesWrapper.py.
Definition at line 37 of file figureAxesWrapper.py.
1.5.8