Changeset 0e553fd in sasview for plottools/src/danse
- Timestamp:
- Jan 4, 2012 12:35:21 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 8542bf3
- Parents:
- e38e335
- Location:
- plottools/src/danse/common/plottools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
plottools/src/danse/common/plottools/PlotPanel.py
r8d27cac r0e553fd 119 119 wx.Panel.__init__(self, parent, id=id, **kwargs) 120 120 self.parent = parent 121 self.gotLegend = 0 #to begin, legend is not picked. 122 self.legend_pos_loc = None 123 self.legend = None 124 self.line_collections_list = [] 121 125 self.figure = Figure(None, dpi, linewidth=2.0) 122 126 self.color = '#b3b3b3' … … 126 130 #self.SetBackgroundColour(parent.GetBackgroundColour()) 127 131 self._resizeflag = True 128 self._Set Size()132 self._SetInitialSize() 129 133 self.subplot = self.figure.add_subplot(111) 130 134 self.figure.subplots_adjust(left=0.2, bottom=.2) … … 178 182 self.canvas.mpl_connect('motion_notify_event', self.onMouseMotion) 179 183 self.canvas.mpl_connect('button_press_event', self.onLeftDown) 184 self.canvas.mpl_connect('pick_event', self.onPick) 180 185 self.canvas.mpl_connect('button_release_event', self.onLeftUp) 186 181 187 wx.EVT_RIGHT_DOWN(self, self.onLeftDown) 182 188 # to turn axis off whenn resizing the panel … … 192 198 self.connect = BindArtist(self.subplot.figure) 193 199 #self.selected_plottable = None 194 200 195 201 # new data for the fit 196 202 self.fit_result = Data1D(x=[], y=[], dy=None) … … 264 270 # let canvas know about axes 265 271 self.canvas.set_panel(self) 266 #Bind focus to change the border color 272 273 #Bind focus to change the border color 267 274 self.canvas.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) 268 275 self.canvas.Bind(wx.EVT_KILL_FOCUS, self.on_kill_focus) 269 276 277 def _SetInitialSize(self,): 278 """ 279 """ 280 pixels = self.parent.GetClientSize() 281 self.canvas.SetSize(pixels) 282 self.figure.set_size_inches( (pixels[0])/self.figure.get_dpi(), 283 (pixels[1])/self.figure.get_dpi(), forward=True ) 284 270 285 def On_Paint(self, event): 271 286 """ … … 369 384 self.mousemotion = False 370 385 self.leftup = True 371 386 387 #release the legend 388 if self.gotLegend == 1: 389 self.gotLegend = 0 390 self.set_legend_alpha(1) 391 392 def set_legend_alpha(self, alpha=1): 393 """ 394 Set legend alpha 395 """ 396 if self.legend != None: 397 self.legend.legendPatch.set_alpha(alpha) 398 399 def onPick(self, event): 400 """ 401 On pick legend 402 """ 403 legend = self.legend 404 if event.artist == legend: 405 #gets the box of the legend. 406 bbox = self.legend.get_window_extent() 407 #get mouse coordinates at time of pick. 408 self.mouse_x = event.mouseevent.x 409 self.mouse_y = event.mouseevent.y 410 #get legend coordinates at time of pick. 411 self.legend_x = bbox.xmin 412 self.legend_y = bbox.ymin 413 #indicates we picked up the legend. 414 self.gotLegend = 1 415 self.set_legend_alpha(0.5) 416 417 418 def _on_legend_motion(self, event): 419 """ 420 On legend in motion 421 """ 422 ax = event.inaxes 423 if ax == None: 424 return 425 # Event occurred inside a plotting area 426 lo_x, hi_x = ax.get_xlim() 427 lo_y, hi_y = ax.get_ylim() 428 # How much the mouse moved. 429 x = mouse_diff_x = self.mouse_x - event.x 430 y = mouse_diff_y = self.mouse_y - event.y 431 # Put back inside 432 if x < lo_x: 433 x = lo_x 434 if x > hi_x: 435 x = hi_x 436 if y < lo_y: 437 y = lo_y 438 if y> hi_y: 439 y = hi_y 440 # Move the legend from its previous location by that same amount 441 loc_in_canvas = self.legend_x - mouse_diff_x, \ 442 self.legend_y - mouse_diff_y 443 # Transform into legend coordinate system 444 trans_axes = self.legend.parent.transAxes.inverted() 445 loc_in_norm_axes = trans_axes.transform_point(loc_in_canvas) 446 self.legend_pos_loc = tuple(loc_in_norm_axes) 447 self.legend._loc = self.legend_pos_loc 448 self.resizing = True 449 self.canvas.set_resizing(self.resizing) 450 self.canvas.draw() 451 372 452 def onMouseMotion(self, event): 373 453 """ … … 377 457 378 458 """ 459 if self.gotLegend == 1: 460 self._on_legend_motion(event) 461 return 379 462 if self.enable_toolbar: 380 463 #Disable dragging without the toolbar to allow zooming with toolbar … … 400 483 else:# no dragging is perform elsewhere 401 484 self._dragHelper(0,0) 485 402 486 403 487 def _offset_graph(self): … … 701 785 """ 702 786 if not pixels: 703 pixels = self.GetClientSize()787 pixels = tuple(self.GetClientSize()) 704 788 self.canvas.SetSize(pixels) 705 self.figure.set_size_inches( pixels[0]/self.figure.get_dpi(),706 pixels[1]/self.figure.get_dpi())789 self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(), 790 float( pixels[1] )/self.figure.get_dpi() ) 707 791 708 792 def draw(self): … … 713 797 self.figure.canvas.draw_idle() 714 798 799 800 #pick up the legend patch 801 def legend_picker(self, legend, event): 802 return self.legend.legendPatch.contains(event) 715 803 716 804 def get_loc_label(self): … … 846 934 key=operator.itemgetter(1)) 847 935 handles2, labels2 = zip(*hl) 848 self.subplot.legend(handles2, labels2, 936 self.line_collections_list = handles2 937 self.legend = self.subplot.legend(handles2, labels2, 849 938 prop=FontProperties(size=10), numpoints=1, 850 939 handletextsep=.05, loc=self.legendLoc) 940 if self.legend != None: 941 self.legend.set_picker(self.legend_picker) 942 self.legend.set_axes(self.subplot) 851 943 852 944 self.subplot.figure.canvas.draw_idle() … … 862 954 863 955 self.legendLoc = label 956 self.legend_pos_loc = None 864 957 # sort them by labels 865 958 handles, labels = self.subplot.get_legend_handles_labels() … … 867 960 key=operator.itemgetter(1)) 868 961 handles2, labels2 = zip(*hl) 869 self.subplot.legend(handles2, labels2, 962 self.line_collections_list = handles2 963 self.legend = self.subplot.legend(handles2, labels2, 870 964 prop=FontProperties(size=10), numpoints=1, 871 965 handletextsep=.05, loc=self.legendLoc) 966 if self.legend != None: 967 self.legend.set_picker(self.legend_picker) 968 self.legend.set_axes(self.subplot) 872 969 self.subplot.figure.canvas.draw_idle() 873 970 #self._onEVT_FUNC_PROPERTY() … … 1118 1215 key=operator.itemgetter(1)) 1119 1216 handles2, labels2 = zip(*hl) 1120 leg = ax.legend(handles2, labels2, numpoints=1, 1217 self.line_collections_list = handles2 1218 self.legend = ax.legend(handles2, labels2, numpoints=1, 1121 1219 prop=FontProperties(size=10), 1122 1220 handletextsep=.05, loc=self.legendLoc) 1221 if self.legend != None: 1222 self.legend.set_picker(self.legend_picker) 1223 self.legend.set_axes(self.subplot) 1224 1123 1225 except: 1124 leg= ax.legend(prop=FontProperties(size=10), numpoints=1,1226 self.legend = ax.legend(prop=FontProperties(size=10), numpoints=1, 1125 1227 handletextsep=.05, loc=self.legendLoc) 1126 1228 1127 1229 def xaxis(self, label, units, font=None, color='black'): 1128 1230 """xaxis label and units. … … 1636 1738 if(self.yLabel == "y*x^(4)"): 1637 1739 item.transformY(transform.toYX4, transform.errToYX4) 1638 xunits = convertUnit(4, xunits)1740 xunits = convertUnit(4, self.xaxis_unit) 1639 1741 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname,xname), 1640 1742 "%s%s" % (yunits,xunits)) … … 1647 1749 item.transformY(transform.toLogXY, transform.errToLogXY) 1648 1750 self.graph._yaxis_transformed("\ln (%s \ \ %s)" % (yname,xname), 1649 "%s%s" % (yunits, xunits))1751 "%s%s" % (yunits, self.xaxis_unit)) 1650 1752 if(self.yLabel == "ln(y*x^(2))"): 1651 1753 item.transformY( transform.toLogYX2, transform.errToLogYX2) 1652 xunits = convertUnit(2, xunits)1754 xunits = convertUnit(2, self.xaxis_unit) 1653 1755 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname,xname), 1654 1756 "%s%s" % (yunits,xunits)) 1655 1757 if(self.yLabel == "ln(y*x^(4))"): 1656 1758 item.transformY(transform.toLogYX4, transform.errToLogYX4) 1657 xunits = convertUnit(4, xunits)1759 xunits = convertUnit(4, self.xaxis_unit) 1658 1760 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname,xname), 1659 1761 "%s%s" % (yunits,xunits)) 1660 1762 if(self.yLabel == "log10(y*x^(4))"): 1661 1763 item.transformY(transform.toYX4, transform.errToYX4) 1662 xunits = convertUnit(4, xunits)1764 xunits = convertUnit(4, self.xaxis_unit) 1663 1765 _yscale = 'log' 1664 1766 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname,xname), -
plottools/src/danse/common/plottools/binder.py
r82a54b8 r0e553fd 68 68 69 69 # Turn off picker if it hasn't already been done 70 try:71 canvas.mpl_disconnect(canvas.button_pick_id)72 canvas.mpl_disconnect(canvas.scroll_pick_id)73 except:74 pass70 #try: 71 # canvas.mpl_disconnect(canvas.button_pick_id) 72 # canvas.mpl_disconnect(canvas.scroll_pick_id) 73 #except: 74 # pass 75 75 self._current = None 76 76 self._actions = {} -
plottools/src/danse/common/plottools/canvas.py
r82a54b8 r0e553fd 148 148 """ 149 149 self.panel.subplot.grid(self.panel.grid_on) 150 if self.panel.legend_pos_loc: 151 self.panel.legend._loc = self.panel.legend_pos_loc 150 152 self.idletimer.Restart(5, *args, **kwargs) # Delay by 5 ms 151 153 … … 182 184 self.resizing = resizing 183 185 self.panel.set_resizing(False) 184 186 185 187 def draw(self, drawDC=None): 186 188 """
Note: See TracChangeset
for help on using the changeset viewer.