1
2 """Plots a collection of timelines"""
3
4 from PyFoam.ThirdParty.Gnuplot import Gnuplot,Data
5
6 from PyFoam.Basics.CustomPlotInfo import readCustomPlotInfo,CustomPlotInfo
7
8 from PyFoam.Error import warning
9
10 from GeneralPlotTimelines import GeneralPlotTimelines
11
12 from os import uname
13
15 """This class opens a gnuplot window and plots a timelines-collection in it"""
16
17 terminalNr=1
18
19 - def __init__(self,
20 timelines,
21 custom,
22 showWindow=True,
23 registry=None):
24 """@param timelines: The timelines object
25 @type timelines: TimeLineCollection
26 @param custom: A CustomplotInfo-object. Values in this object usually override the
27 other options
28 """
29
30 GeneralPlotTimelines.__init__(self,timelines,custom,showWindow=showWindow,registry=registry)
31 Gnuplot.__init__(self,persist=self.spec.persist)
32
33 self.itemlist=[]
34
35 if self.spec.start or self.spec.end:
36 rng="["
37 if self.spec.start:
38 rng+=str(self.spec.start)
39 rng+=":"
40 if self.spec.end:
41 rng+=str(self.spec.end)
42 rng+="]"
43 self.set_string("xrange "+rng)
44
45 if len(self.alternate)>0:
46 self.set_string("y2tics")
47
48 try:
49 if self.spec.logscale:
50 self.set_string("logscale y")
51 except AttributeError:
52 pass
53
54 try:
55 if self.spec.ylabel:
56 self.set_string('ylabel "'+self.spec.ylabel+'"')
57 except AttributeError:
58 pass
59
60 try:
61 if self.spec.y2label:
62 self.set_string('y2label "'+self.spec.y2label+'"')
63 except AttributeError:
64 pass
65
66 if self.spec.raiseit:
67 x11addition=" raise"
68 else:
69 x11addition=" noraise"
70
71 if uname()[0]=="Darwin":
72 self.set_string("terminal x11"+x11addition)
73
74 GnuplotTimelines.terminalNr+=1
75 else:
76 self.set_string("terminal x11"+x11addition)
77
78 self.with_=self.spec.with_
79
80 self.redo()
81
82 - def buildData(self,times,name,title,lastValid):
83 """Build the implementation specific data
84 @param times: The vector of times for which data exists
85 @param name: the name under which the data is stored in the timeline
86 @param title: the title under which this will be displayed"""
87
88 tm=times
89 dt=self.data.getValues(name)
90 if len(tm)>0 and not lastValid:
91 tm=tm[:-1]
92 dt=dt[:-1]
93
94 if len(dt)>0:
95 it=Data(tm,dt,title=title,with_=self.with_)
96
97 if name in self.alternate:
98 it.set_option(axes="x1y2")
99
100 self.itemlist.append(it)
101
103 """Prepare the plotting window"""
104 self.itemlist=[]
105
107 """Replot the whole data"""
108
109 self.replot()
110
112 """Sets the title"""
113
114 self.title(title)
115
117 """Sets the label on the first Y-Axis"""
118
119 self.set_string('ylabel "%s"' % title)
120
122 """Sets the label on the second Y-Axis"""
123
124 self.set_string('y2label "%s"' % title)
125
127 """Write the contents of the plot to disk
128 @param filename: Name of the file without type extension
129 @param form: String describing the format"""
130
131 if form=="png":
132 self.hardcopy(terminal="png",filename=filename+".png",color=True,small=True)
133 elif form=="pdf":
134 self.hardcopy(terminal="pdf",filename=filename+".pdf",color=True)
135 elif form=="svg":
136 self.hardcopy(terminal="svg",filename=filename+".svg")
137 elif form=="postscript":
138 self.hardcopy(terminal="postscript",filename=filename+".ps",color=True)
139 elif form=="eps":
140 self.hardcopy(terminal="postscript",filename=filename+".eps",color=True,eps=True)
141 else:
142 warning("Hardcopy format",form,"unknown. Falling back to postscript")
143 self.hardcopy(filename=filename+".ps",color=True)
144