Changeset 3e001f9 in sasview for sansguiframe/src
- Timestamp:
- Apr 6, 2013 1:36:03 PM (12 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:
- 4bdd4fdb
- Parents:
- cb270ad2
- Location:
- sansguiframe/src/sans/guiframe/local_perspectives/plotting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter1D.py
r318b5bbb r3e001f9 93 93 ## Default locations 94 94 #self._default_save_location = os.getcwd() 95 self.size = None 95 self.size = None 96 self.vl_ind = 0 96 97 ## Graph 97 98 #self.graph = Graph() … … 99 100 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 100 101 self.graph.render(self) 102 self.cursor_id = None 101 103 102 104 # In resizing event … … 217 219 wx.CallAfter(self.parent.disable_app_menu,self) 218 220 221 def on_plot_qrange(self, event=None): 222 """ 223 On Qmin Qmax vertical line event 224 """ 225 if event == None: 226 return 227 event.Skip() 228 active_ctrl = event.active 229 if active_ctrl == None: 230 return 231 if event.id in self.plots.keys(): 232 # Set line position and color 233 colors = ['red', 'purple'] 234 self.cursor_id = event.id 235 ctrl = event.ctrl 236 if self.ly == None: 237 self.ly = [] 238 for ind_ly in range(len(colors)): 239 self.ly.append(self.subplot.axvline(color=colors[ind_ly], 240 lw=2.5, alpha=0.7)) 241 self.ly[ind_ly].set_rasterized(True) 242 try: 243 # Display x,y in the status bar if possible 244 xval = float(active_ctrl.GetValue()) 245 position = self.get_data_xy_vals(xval) 246 if position != None: 247 wx.PostEvent(self.parent, StatusEvent(status=position)) 248 except: 249 pass 250 if not event.leftdown: 251 # text event 252 try: 253 is_moved = False 254 for idx in range(len(self.ly)): 255 val = float(ctrl[idx].GetValue()) 256 # check if vline moved 257 if self.ly[idx].get_xdata() != val: 258 self.ly[idx].set_xdata(val) 259 is_moved = True 260 if is_moved: 261 self.canvas.draw() 262 except: 263 pass 264 event.Skip() 265 return 266 self.q_ctrl = ctrl 267 try: 268 pos_x_min = float(self.q_ctrl[0].GetValue()) 269 except: 270 pos_x_min = xmin 271 try: 272 pos_x_max = float(self.q_ctrl[1].GetValue()) 273 except: 274 pos_x_max = xmax 275 pos_x = [pos_x_min, pos_x_max] 276 for ind_ly in range(len(colors)): 277 self.ly[ind_ly].set_color(colors[ind_ly]) 278 self.ly[ind_ly].set_xdata(pos_x[ind_ly]) 279 self.canvas.draw() 280 else: 281 self.q_ctrl = None 282 283 def get_data_xy_vals(self, xval): 284 """ 285 Get x, y data values near x = x_val 286 """ 287 try: 288 x_data = self.plots[self.cursor_id].x 289 y_data = self.plots[self.cursor_id].y 290 indx = self._find_nearest(x_data, xval) 291 pos_x = x_data[indx] 292 pos_y = y_data[indx] 293 position = str(pos_x), str(pos_y) 294 return position 295 except: 296 return None 297 298 def _find_nearest(self, array, value): 299 """ 300 Find and return the nearest value in array to the value. 301 Used in cusor_line() 302 :Param array: numpy array 303 :Param value: float 304 """ 305 idx = (numpy.abs(array - value)).argmin() 306 return int(idx)#array.flat[idx] 307 308 def _check_line_positions(self, pos_x=None, nop=None): 309 """ 310 Check vertical line positions 311 :Param pos_x: position of the current line [float] 312 :Param nop: number of plots [int] 313 """ 314 ly = self.ly 315 ly0x = ly[0].get_xdata() 316 ly1x = ly[1].get_xdata() 317 self.q_ctrl[0].SetBackgroundColour('white') 318 self.q_ctrl[1].SetBackgroundColour('white') 319 if ly0x >= ly1x: 320 if self.vl_ind == 0: 321 ly[1].set_xdata(pos_x) 322 ly[1].set_zorder(nop) 323 self.q_ctrl[1].SetValue(str(pos_x)) 324 self.q_ctrl[0].SetBackgroundColour('pink') 325 elif self.vl_ind == 1: 326 ly[0].set_xdata(pos_x) 327 ly[0].set_zorder(nop) 328 self.q_ctrl[0].SetValue(str(pos_x)) 329 self.q_ctrl[1].SetBackgroundColour('pink') 330 331 def _get_cusor_lines(self, event): 332 """ 333 Revmove or switch cursor line if drawn 334 :Param event: LeftClick mouse event 335 """ 336 ax = event.inaxes 337 dclick = event.action == 'dclick' 338 if ax == None or dclick: 339 # remove the vline 340 self._check_zoom_plot() 341 self.canvas.draw() 342 self.q_ctrl = None 343 return 344 if self.ly != None and event.xdata != None: 345 # Selecting a new line if cursor lines are displayed already 346 dqmin = math.fabs(event.xdata - self.ly[0].get_xdata()) 347 dqmax = math.fabs(event.xdata - self.ly[1].get_xdata()) 348 is_qmax = dqmin > dqmax 349 if is_qmax: 350 self.vl_ind = 1 351 else: 352 self.vl_ind = 0 353 354 def cusor_line(self, event): 355 """ 356 Move the cursor line to write Q range 357 """ 358 if self.q_ctrl == None: 359 return 360 #release a q range vline 361 if self.ly != None and not self.leftdown: 362 for ly in self.ly: 363 ly.set_alpha(0.7) 364 self.canvas.draw() 365 return 366 ax = event.inaxes 367 if ax == None or not hasattr(event, 'action'): 368 return 369 end_drag = event.action != 'drag' and event.xdata != None 370 nop = len(self.plots) 371 pos_x, pos_y = float(event.xdata), float(event.ydata) 372 try: 373 ly = self.ly 374 ly0x = ly[0].get_xdata() 375 ly1x = ly[1].get_xdata() 376 if ly0x == ly1x: 377 if ly[0].get_zorder() > ly[1].get_zorder(): 378 self.vl_ind = 0 379 else: 380 self.vl_ind = 1 381 vl_ind = self.vl_ind 382 x_data = self.plots[self.cursor_id].x 383 y_data = self.plots[self.cursor_id].y 384 xmin = x_data.min() 385 xmax = x_data.max() 386 indx = self._find_nearest(x_data, pos_x) 387 #pos_x = self._find_nearest(x_data, pos_x) 388 #indx = int(numpy.searchsorted(x_data, [pos_x])[0]) 389 # Need to hold LeftButton to drag 390 if end_drag: 391 if event.button: 392 self._check_line_positions(pos_x, nop) 393 return 394 if indx >= len(x_data): 395 indx = len(x_data) - 1 396 pos_x = x_data[indx] 397 pos_y = y_data[indx] 398 if xmin == ly1x: 399 vl_ind = 1 400 elif xmax == ly0x: 401 vl_ind = 0 402 else: 403 ly[vl_ind].set_xdata(pos_x) 404 ly[vl_ind].set_zorder(nop + 1) 405 self._check_line_positions(pos_x, nop) 406 ly[vl_ind].set_xdata(pos_x) 407 ly[vl_ind].set_alpha(1.0) 408 ly[vl_ind].set_zorder(nop + 1) 409 self.canvas.draw() 410 self.q_ctrl[vl_ind].SetValue(str(pos_x)) 411 except: 412 pass 413 219 414 def set_resizing(self, resizing=False): 220 415 """ … … 340 535 Display the position of the mouse on the statusbar 341 536 """ 537 self._get_cusor_lines(event) 538 ax = event.inaxes 342 539 PlotPanel.onLeftDown(self, event) 343 ax = event.inaxes 540 344 541 if ax != None: 345 542 try: -
sansguiframe/src/sans/guiframe/local_perspectives/plotting/Plotter2D.py
r657e52c r3e001f9 142 142 self.default_zmin_ctl = self.zmin_2D 143 143 self.default_zmax_ctl = self.zmax_2D 144 144 145 def on_plot_qrange(self, event=None): 146 """ 147 On Qmin Qmax vertical line event 148 """ 149 # Not implemented 150 if event == None: 151 return 152 event.Skip() 153 145 154 def onLeftDown(self, event): 146 155 """ -
sansguiframe/src/sans/guiframe/local_perspectives/plotting/plotting.py
r4752c31 r3e001f9 15 15 import sys 16 16 from sans.guiframe.events import EVT_NEW_PLOT 17 from sans.guiframe.events import EVT_PLOT_QRANGE 17 18 from sans.guiframe.events import StatusEvent 18 19 from sans.guiframe.events import DeletePlotPanelEvent … … 82 83 # Connect to plotting events 83 84 self.parent.Bind(EVT_NEW_PLOT, self._on_plot_event) 85 self.parent.Bind(EVT_PLOT_QRANGE, self._on_plot_qrange) 84 86 # We have no initial panels for this plug-in 85 87 return [] 86 88 89 def _on_plot_qrange(self, event= None): 90 """ 91 On Qmin Qmax vertical line event 92 """ 93 if event == None: 94 return 95 if event.id in self.plot_panels.keys(): 96 panel = self.plot_panels[event.id] 97 elif event.group_id in self.plot_panels.keys(): 98 panel = self.plot_panels[event.group_id] 99 else: 100 return 101 panel.on_plot_qrange(event) 102 87 103 def _on_show_panel(self, event): 88 104 """show plug-in panel"""
Note: See TracChangeset
for help on using the changeset viewer.