[3a39c2e] | 1 | """ |
---|
| 2 | Test application that uses plottools |
---|
| 3 | |
---|
| 4 | An application required by the REFL group and mainly test the Chisq class. |
---|
| 5 | |
---|
| 6 | The following is a checklist of functionality to look for while testing: |
---|
| 7 | 1- Start the application: |
---|
| 8 | the graph should have theory curve, experimental data, chisq |
---|
| 9 | with a white background. |
---|
| 10 | |
---|
| 11 | 2- Hovering over any plotted data will highlight the whole data set |
---|
| 12 | or line in yellow. |
---|
| 13 | |
---|
| 14 | 3- Left-clicking on the graph and dragging will drag the graph. |
---|
| 15 | |
---|
| 16 | 4- Using the mouse wheel will zoom in and out of the graph. |
---|
| 17 | |
---|
| 18 | 5- Right-clicking on the graph when no curve is highlighted will |
---|
| 19 | pop up the context menu: |
---|
| 20 | - 'Save image' will pop up a save dialog to save an image. |
---|
| 21 | - 'Reset graph' will reset the graph to its original appearance after it |
---|
| 22 | has been dragged around or zoomed in or out. |
---|
| 23 | - 'Change scale' will pop up a scale dialog with which the axes can |
---|
| 24 | be transformed. Each transformation choice should work. |
---|
| 25 | |
---|
| 26 | """ |
---|
| 27 | |
---|
| 28 | import wx |
---|
[d7bb526] | 29 | from sas.sasgui.plottools.PlotPanel import PlotPanel |
---|
| 30 | from sas.sasgui.plottools.plottables import Plottable, Graph, Data1D, Theory1D |
---|
[3a39c2e] | 31 | import sys |
---|
[9a5097c] | 32 | import numpy as np |
---|
[3a39c2e] | 33 | |
---|
| 34 | |
---|
| 35 | class ReflPlotPanel(PlotPanel): |
---|
| 36 | |
---|
| 37 | def __init__(self, parent, id = -1, |
---|
| 38 | color = None, |
---|
| 39 | dpi = None, |
---|
| 40 | **kwargs): |
---|
| 41 | PlotPanel.__init__(self, parent, id=id, color=color, |
---|
| 42 | dpi=dpi, **kwargs) |
---|
| 43 | |
---|
| 44 | # Keep track of the parent Frame |
---|
| 45 | self.parent = parent |
---|
| 46 | |
---|
| 47 | # Internal list of plottable names (because graph |
---|
| 48 | # doesn't have a dictionary of handles for the plottables) |
---|
| 49 | self.plots = {} |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | def onContextMenu(self, event): |
---|
| 53 | """ |
---|
| 54 | Default context menu for a plot panel |
---|
| 55 | """ |
---|
| 56 | # Slicer plot popup menu |
---|
| 57 | id = wx.NewId() |
---|
| 58 | _menu = wx.Menu() |
---|
| 59 | _menu.Append(id,'&Save image', 'Save image as PNG') |
---|
| 60 | wx.EVT_MENU(self, id, self.onSaveImage) |
---|
| 61 | |
---|
| 62 | _menu.AppendSeparator() |
---|
| 63 | id = wx.NewId() |
---|
| 64 | _menu.Append(id, '&Change scale') |
---|
| 65 | wx.EVT_MENU(self, id, self._onProperties) |
---|
| 66 | |
---|
| 67 | id = wx.NewId() |
---|
| 68 | _menu.Append(id, '&Reset Graph') |
---|
| 69 | wx.EVT_MENU(self, id, self.onResetGraph) |
---|
| 70 | |
---|
| 71 | pos = event.GetPosition() |
---|
| 72 | pos = self.ScreenToClient(pos) |
---|
| 73 | self.PopupMenu(_menu, pos) |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | # --------------------------------------------------------------- |
---|
| 77 | def sample_graph(): |
---|
| 78 | # Construct a simple graph |
---|
| 79 | if False: |
---|
[9a5097c] | 80 | x = np.array([1,2,3,4,5,6],'d') |
---|
| 81 | y = np.array([4,5,26,5,4,-1],'d') |
---|
| 82 | dy = np.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) |
---|
[3a39c2e] | 83 | else: |
---|
[9a5097c] | 84 | x = np.linspace(0,2.0, 50) |
---|
| 85 | y = np.sin(2*np.pi*x*2.8) |
---|
| 86 | dy = np.sqrt(100*np.abs(y))/100 |
---|
[3a39c2e] | 87 | |
---|
[c10d9d6c] | 88 | from sas.sasgui.plottools.plottables import Data1D, Theory1D, Chisq , Graph |
---|
[3a39c2e] | 89 | data = Data1D(x,y,dy=dy) |
---|
| 90 | data.xaxis('distance', 'm') |
---|
| 91 | data.yaxis('time', 's') |
---|
| 92 | graph = Graph() |
---|
| 93 | graph.title('Walking Results') |
---|
| 94 | graph.add(data) |
---|
| 95 | graph.add( Theory1D(x,y,dy=dy)) |
---|
| 96 | graph.add( Chisq( 1.0 ) ) |
---|
| 97 | return graph |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | def demo_plotter(graph): |
---|
| 101 | # Make a frame to show it |
---|
| 102 | app = wx.PySimpleApp() |
---|
| 103 | frame = wx.Frame(None,-1,'Plottables') |
---|
| 104 | plotter = ReflPlotPanel(frame) |
---|
| 105 | frame.Show() |
---|
| 106 | |
---|
| 107 | # render the graph to the pylab plotter |
---|
| 108 | graph.render(plotter) |
---|
| 109 | |
---|
| 110 | app.MainLoop() |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | if __name__ == "__main__": |
---|
| 114 | pass |
---|
| 115 | demo_plotter(sample_graph()) |
---|
| 116 | |
---|
| 117 | |
---|