Changeset 570a58f9 in sasview for src/sas/qtgui
- Timestamp:
- Jan 6, 2017 3:40:05 AM (8 years ago)
- Branches:
- 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
- Children:
- fed94a2
- Parents:
- aadf0af1
- git-author:
- Piotr Rozyczko <rozyczko@…> (01/06/17 03:31:10)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (01/06/17 03:40:05)
- Location:
- src/sas/qtgui
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/GuiUtils.py
raadf0af1 r570a58f9 693 693 """ 694 694 return item.child(0).data().toPyObject() 695 696 def formatNumber(value, high=False): 697 """ 698 Return a float in a standardized, human-readable formatted string. 699 This is used to output readable (e.g. x.xxxe-y) values to the panel. 700 """ 701 try: 702 value = float(value) 703 except: 704 output = "NaN" 705 return output.lstrip().rstrip() 706 707 if high: 708 output = "%-6.4g" % value 709 710 else: 711 output = "%-5.3g" % value 712 return output.lstrip().rstrip() -
src/sas/qtgui/Plotter.py
raadf0af1 r570a58f9 12 12 from sas.qtgui.AddText import AddText 13 13 from sas.qtgui.SetGraphRange import SetGraphRange 14 from sas.qtgui.LinearFit import LinearFit 14 15 15 16 class PlotterWidget(PlotterBase): … … 19 20 def __init__(self, parent=None, manager=None, quickplot=False): 20 21 super(PlotterWidget, self).__init__(parent, manager=manager, quickplot=quickplot) 22 21 23 self.parent = parent 22 24 self.addText = AddText(self) … … 27 29 # Simple window for data display 28 30 self.txt_widget = QtGui.QTextEdit(None) 31 32 self.xLogLabel = "log10(x)" 33 self.yLogLabel = "log10(y)" 34 35 # Data container for the linear fit 36 self.fit_result = Data1D(x=[], y=[], dy=None) 37 self.fit_result.symbol = 13 38 self.fit_result.name = "Fit" 39 40 # Add a slot for receiving update signal from LinearFit 41 # NEW style signals - don't work! 42 #self.updatePlot = QtCore.pyqtSignal(tuple) 43 #self.updatePlot.connect(self.updateWithData) 44 # OLD style signals - work perfectly 45 QtCore.QObject.connect(self, QtCore.SIGNAL('updatePlot'), self.onFitDisplay) 29 46 30 47 @property … … 48 65 self.data = data 49 66 assert(self._data) 67 68 is_fit = (self._data.id=="fit") 50 69 51 70 # Shortcut for an axis … … 87 106 88 107 # Current labels for axes 89 ax.set_ylabel(self.y_label) 90 ax.set_xlabel(self.x_label) 108 if self.y_label and not is_fit: 109 ax.set_ylabel(self.y_label) 110 if self.x_label and not is_fit: 111 ax.set_xlabel(self.x_label) 91 112 92 113 # Title only for regular charts 93 if not self.quickplot :114 if not self.quickplot and not is_fit: 94 115 ax.set_title(label=self._title) 95 116 … … 161 182 if plot.id != 'fit': 162 183 self.actionLinearFit = plot_menu.addAction('&Linear Fit') 163 self.actionLinearFit.triggered.connect(self.onLinearFit) 184 self.actionLinearFit.triggered.connect( 185 functools.partial(self.onLinearFit, id)) 164 186 plot_menu.addSeparator() 165 187 … … 209 231 """ 210 232 if self.properties.exec_() == QtGui.QDialog.Accepted: 211 xLabel, yLabel = self.properties.getValues()212 self.xyTransform( xLabel, yLabel)233 self.xLogLabel, self.yLogLabel = self.properties.getValues() 234 self.xyTransform(self.xLogLabel, self.yLogLabel) 213 235 214 236 def onModifyGraph(self): … … 319 341 GuiUtils.saveData1D(plot_data) 320 342 321 def onLinearFit(self ):343 def onLinearFit(self, id): 322 344 """ 323 345 Creates and displays a simple linear fit for the selected plot 324 346 """ 325 pass 347 selected_plot = self.plot_dict[id] 348 349 maxrange = (min(selected_plot.x), max(selected_plot.x)) 350 fitrange = self.ax.get_xlim() 351 352 fit_dialog = LinearFit(parent=self, 353 data=selected_plot, 354 max_range=maxrange, 355 fit_range=fitrange, 356 xlabel=self.xLogLabel, 357 ylabel=self.yLogLabel) 358 if fit_dialog.exec_() == QtGui.QDialog.Accepted: 359 return 326 360 327 361 def onRemovePlot(self, id): 328 362 """ 363 Responds to the plot delete action 364 """ 365 self.removePlot(id) 366 367 if len(self.plot_dict) == 0: 368 # last plot: graph is empty must be the panel must be destroyed 369 self.parent.close() 370 371 def removePlot(self, id): 372 """ 329 373 Deletes the selected plot from the chart 330 374 """ 375 if id not in self.plot_dict: 376 return 377 331 378 selected_plot = self.plot_dict[id] 332 379 … … 341 388 if ids != id: 342 389 self.plot(data=plot_dict[ids], hide_error=plot_dict[ids].hide_error) 343 344 if len(self.plot_dict) == 0:345 # last plot: graph is empty must be the panel must be destroyed346 self.parent.close()347 390 348 391 def onFreeze(self, id): … … 387 430 Transforms x and y in View and set the scale 388 431 """ 389 # Clear the plot first 390 plt.cla() 391 self.ax.cla() 392 393 new_xlabel, new_ylabel, xscale, yscale = GuiUtils.xyTransform(self.data, xLabel, yLabel) 394 self.xscale = xscale 395 self.yscale = yscale 396 self.xLabel = new_xlabel 397 self.yLabel = new_ylabel 398 399 # Plot the updated chart 400 self.plot(marker='o', linestyle='') 432 # Transform all the plots on the chart 433 for id in self.plot_dict.keys(): 434 current_plot = self.plot_dict[id] 435 if current_plot.id == "fit": 436 self.removePlot(id) 437 continue 438 new_xlabel, new_ylabel, xscale, yscale =\ 439 GuiUtils.xyTransform(current_plot, xLabel, yLabel) 440 self.xscale = xscale 441 self.yscale = yscale 442 self.xLabel = new_xlabel 443 self.yLabel = new_ylabel 444 # Plot the updated chart 445 self.removePlot(id) 446 self.plot(data=current_plot, marker='o', linestyle='') 447 448 pass # debug hook 449 450 def onFitDisplay(self, fit_data): 451 """ 452 Add a linear fitting line to the chart 453 """ 454 # Create new data structure with fitting result 455 tempx = fit_data[0] 456 tempy = fit_data[1] 457 self.fit_result.x = [] 458 self.fit_result.y = [] 459 self.fit_result.x = tempx 460 self.fit_result.y = tempy 461 self.fit_result.dx = None 462 self.fit_result.dy = None 463 464 #Remove another Fit, if exists 465 self.removePlot("fit") 466 467 self.fit_result.reset_view() 468 #self.offset_graph() 469 470 # Set plot properties 471 self.fit_result.id = 'fit' 472 self.fit_result.title = 'Fit' 473 self.fit_result.name = 'Fit' 474 475 # Plot the line 476 self.plot(data=self.fit_result, marker='', linestyle='solid', hide_error=True) 401 477 402 478 -
src/sas/qtgui/PlotterBase.py
raadf0af1 r570a58f9 58 58 59 59 # Mouse click related 60 self._scale_xlo = None 61 self._scale_xhi = None 62 self._scale_ylo = None 63 self._scale_yhi = None 60 64 self.x_click = None 61 65 self.y_click = None … … 70 74 # Pre-define the Scale properties dialog 71 75 self.properties = ScaleProperties(self, 72 73 76 init_scale_x=self.x_label, 77 init_scale_y=self.y_label) 74 78 75 79 # default color map … … 460 464 # Notify the listeners about a new graph title 461 465 self.manager.communicator.activeGraphName.emit((current_title, title)) 466 467 def offset_graph(self): 468 """ 469 Zoom and offset the graph to the last known settings 470 """ 471 for ax in self.axes: 472 if self._scale_xhi is not None and self._scale_xlo is not None: 473 ax.set_xlim(self._scale_xlo, self._scale_xhi) 474 if self._scale_yhi is not None and self._scale_ylo is not None: 475 ax.set_ylim(self._scale_ylo, self._scale_yhi)
Note: See TracChangeset
for help on using the changeset viewer.