Mercurial > hg > octave-lyh
comparison src/pt-plot.h @ 2124:97a566037a75
[project @ 1996-05-12 07:16:36 by jwe]
author | jwe |
---|---|
date | Sun, 12 May 1996 07:16:36 +0000 |
parents | bfb775fb6fe8 |
children | ceaecd0967f3 |
comparison
equal
deleted
inserted
replaced
2123:ee55d81f585a | 2124:97a566037a75 |
---|---|
37 class subplot_using; | 37 class subplot_using; |
38 class subplot_style; | 38 class subplot_style; |
39 class subplot; | 39 class subplot; |
40 class subplot_list; | 40 class subplot_list; |
41 | 41 |
42 class tree_walker; | |
43 | |
42 #include <string> | 44 #include <string> |
43 | 45 |
44 #include <SLList.h> | 46 #include <SLList.h> |
45 | 47 |
46 #include "dColVector.h" | 48 #include "dColVector.h" |
51 | 53 |
52 class | 54 class |
53 tree_plot_command : public tree_command | 55 tree_plot_command : public tree_command |
54 { | 56 { |
55 public: | 57 public: |
58 | |
56 tree_plot_command (subplot_list *plt = 0, plot_limits *rng = 0, int nd = 0) | 59 tree_plot_command (subplot_list *plt = 0, plot_limits *rng = 0, int nd = 0) |
57 : tree_command (), ndim (nd), range (rng), plot_list (plt) { } | 60 : tree_command (), ndim (nd), range (rng), plot_list (plt) { } |
58 | 61 |
59 ~tree_plot_command (void); | 62 ~tree_plot_command (void); |
60 | 63 |
61 void eval (void); | 64 void eval (void); |
62 | 65 |
63 void print_code (ostream& os); | 66 int num_dimensions (void) { return ndim; } |
64 | 67 |
65 private: | 68 plot_limits *limits (void) { return range; } |
69 | |
70 subplot_list *subplots (void) { return plot_list; } | |
71 | |
72 void accept (tree_walker& tw); | |
73 | |
74 private: | |
75 | |
76 // The number of dimensions. 1 indicates a replot command. | |
66 int ndim; | 77 int ndim; |
78 | |
79 // The data ranges for the plot. | |
67 plot_limits *range; | 80 plot_limits *range; |
81 | |
82 // The list of plots for this plot command. For example, the | |
83 // command "plot sin(x), cos(x)" has two subplot commands. | |
68 subplot_list *plot_list; | 84 subplot_list *plot_list; |
69 }; | 85 }; |
70 | 86 |
71 class | 87 class |
72 plot_limits : public tree_print_code | 88 plot_limits |
73 { | 89 { |
74 public: | 90 public: |
91 | |
75 plot_limits (plot_range *xlim = 0, plot_range *ylim = 0, | 92 plot_limits (plot_range *xlim = 0, plot_range *ylim = 0, |
76 plot_range *zlim = 0) | 93 plot_range *zlim = 0) |
77 : tree_print_code (), x_range (xlim), y_range (ylim), z_range (zlim) { } | 94 : x_range (xlim), y_range (ylim), z_range (zlim) { } |
78 | 95 |
79 ~plot_limits (void); | 96 ~plot_limits (void); |
80 | 97 |
81 void print (int ndim, ostrstream& plot_buf); | 98 void print (int ndim, ostrstream& plot_buf); |
82 | 99 |
83 void print_code (ostream& os); | 100 plot_range *x_limits (void) { return x_range; } |
84 | 101 plot_range *y_limits (void) { return y_range; } |
85 private: | 102 plot_range *z_limits (void) { return z_range; } |
103 | |
104 void accept (tree_walker& tw); | |
105 | |
106 private: | |
107 | |
108 // Specified limits of the x, y, and z axes we should display for | |
109 // this plot. | |
86 plot_range *x_range; | 110 plot_range *x_range; |
87 plot_range *y_range; | 111 plot_range *y_range; |
88 plot_range *z_range; | 112 plot_range *z_range; |
89 }; | 113 }; |
90 | 114 |
91 class | 115 class |
92 plot_range : public tree_print_code | 116 plot_range |
93 { | 117 { |
94 public: | 118 public: |
119 | |
95 plot_range (tree_expression *l = 0, tree_expression *u = 0) | 120 plot_range (tree_expression *l = 0, tree_expression *u = 0) |
96 : tree_print_code (), lower (l), upper (u) { } | 121 : lower (l), upper (u) { } |
97 | 122 |
98 ~plot_range (void); | 123 ~plot_range (void); |
99 | 124 |
100 void print (ostrstream& plot_buf); | 125 void print (ostrstream& plot_buf); |
101 | 126 |
102 void print_code (ostream& os); | 127 tree_expression *lower_bound (void) { return lower; } |
103 | 128 |
104 private: | 129 tree_expression *upper_bound (void) { return upper; } |
130 | |
131 void accept (tree_walker& tw); | |
132 | |
133 private: | |
134 | |
135 // A range can specify a lower or upper bound or both. If neither | |
136 // is specified, the range to display is determined from the data. | |
105 tree_expression *lower; | 137 tree_expression *lower; |
106 tree_expression *upper; | 138 tree_expression *upper; |
107 }; | 139 }; |
108 | 140 |
109 class | 141 class |
110 subplot_using : public tree_print_code | 142 subplot_using |
111 { | 143 { |
112 public: | 144 public: |
113 subplot_using (void) | 145 |
114 { | 146 subplot_using (tree_expression *fmt = 0) |
115 qualifier_count = 0; | 147 : qual_count (0), scanf_fmt (fmt), val (4, -1) |
116 x[0] = x[1] = x[2] = x[3] = 0; | 148 { |
117 scanf_fmt = 0; | 149 x[0] = x[1] = x[2] = x[3] = 0; |
118 } | 150 } |
119 | |
120 subplot_using (tree_expression *fmt) : val (4, -1) | |
121 { | |
122 qualifier_count = 0; | |
123 x[0] = x[1] = x[2] = x[3] = 0; | |
124 scanf_fmt = fmt; | |
125 } | |
126 | 151 |
127 ~subplot_using (void); | 152 ~subplot_using (void); |
128 | 153 |
129 subplot_using *set_format (tree_expression *fmt) | 154 subplot_using *set_format (tree_expression *fmt) |
130 { | 155 { |
132 return this; | 157 return this; |
133 } | 158 } |
134 | 159 |
135 subplot_using *add_qualifier (tree_expression *t) | 160 subplot_using *add_qualifier (tree_expression *t) |
136 { | 161 { |
137 if (qualifier_count < 4) | 162 if (qual_count < 4) |
138 x[qualifier_count] = t; | 163 x[qual_count] = t; |
139 | 164 |
140 qualifier_count++; | 165 qual_count++; |
141 | 166 |
142 return this; | 167 return this; |
143 } | 168 } |
144 | 169 |
145 int eval (int ndim, int n_max); | 170 int eval (int ndim, int n_max); |
146 | 171 |
147 ColumnVector values (int ndim, int n_max = 0); | 172 ColumnVector values (int ndim, int n_max = 0); |
148 | 173 |
149 int print (int ndim, int n_max, ostrstream& plot_buf); | 174 int print (int ndim, int n_max, ostrstream& plot_buf); |
150 | 175 |
151 void print_code (ostream& os); | 176 int qualifier_count (void) { return qual_count; } |
152 | 177 |
153 private: | 178 tree_expression **qualifiers (void) { return x; } |
154 int qualifier_count; | 179 |
180 tree_expression *scanf_format (void) { return scanf_fmt; } | |
181 | |
182 void accept (tree_walker& tw); | |
183 | |
184 private: | |
185 | |
186 // The number of using qualifiers (in "using 1:2", 1 and 2 are the | |
187 // qualifiers). | |
188 int qual_count; | |
189 | |
190 // An optional scanf-style format. This is parsed and stored but | |
191 // not currently used. | |
192 tree_expression *scanf_fmt; | |
193 | |
194 // This is a cache for evaluated versions of the qualifiers stored | |
195 // in x. | |
196 ColumnVector val; | |
197 | |
198 // A vector to hold using qualifiers. | |
155 tree_expression *x[4]; | 199 tree_expression *x[4]; |
156 tree_expression *scanf_fmt; | 200 }; |
157 ColumnVector val; | 201 |
158 }; | 202 class |
159 | 203 subplot_style |
160 class | 204 { |
161 subplot_style : public tree_print_code | 205 public: |
162 { | 206 |
163 public: | 207 subplot_style (const string& s = string (), |
164 subplot_style (void) | 208 tree_expression *lt = 0, tree_expression *pt = 0) |
165 : tree_print_code (), style (0), linetype (0), pointtype (0) { } | 209 : sp_style (s), sp_linetype (lt), sp_pointtype (pt) { } |
166 | |
167 subplot_style (const string& s); | |
168 subplot_style (const string& s, tree_expression *lt); | |
169 subplot_style (const string& s, tree_expression *lt, tree_expression *pt); | |
170 | 210 |
171 ~subplot_style (void); | 211 ~subplot_style (void); |
172 | 212 |
173 int print (ostrstream& plot_buf); | 213 int print (ostrstream& plot_buf); |
174 | 214 |
175 int errorbars (void); | 215 int errorbars (void); |
176 | 216 |
177 void print_code (ostream& os); | 217 string style (void) { return sp_style; } |
178 | 218 |
179 private: | 219 tree_expression *linetype (void) { return sp_linetype; } |
180 string style; | 220 |
181 tree_expression *linetype; | 221 tree_expression *pointtype (void) { return sp_pointtype; } |
182 tree_expression *pointtype; | 222 |
183 }; | 223 void accept (tree_walker& tw); |
184 | 224 |
185 class | 225 private: |
186 subplot : public tree_print_code | 226 |
187 { | 227 // The style we are using: `lines', `points', etc. |
188 public: | 228 string sp_style; |
229 | |
230 // The number of the line type to use. | |
231 tree_expression *sp_linetype; | |
232 | |
233 // The number of the point type to use. | |
234 tree_expression *sp_pointtype; | |
235 }; | |
236 | |
237 class | |
238 subplot | |
239 { | |
240 public: | |
241 | |
189 subplot (tree_expression *data = 0) | 242 subplot (tree_expression *data = 0) |
190 : tree_print_code (), plot_data (data), using_clause (0), | 243 : sp_plot_data (data), sp_using_clause (0), sp_title_clause (0), |
191 title_clause (0), style_clause (0) { } | 244 sp_style_clause (0) { } |
192 | 245 |
193 subplot (subplot_using *u, tree_expression *t, subplot_style *s) | 246 subplot (subplot_using *u, tree_expression *t, subplot_style *s) |
194 : tree_print_code (), plot_data (0), using_clause (u), | 247 : sp_plot_data (0), sp_using_clause (u), sp_title_clause (t), |
195 title_clause (t), style_clause (s) { } | 248 sp_style_clause (s) { } |
196 | 249 |
197 ~subplot (void); | 250 ~subplot (void); |
198 | 251 |
199 subplot *set_data (tree_expression *data) | 252 subplot *set_data (tree_expression *data) |
200 { | 253 { |
201 plot_data = data; | 254 sp_plot_data = data; |
202 return this; | 255 return this; |
203 } | 256 } |
204 | 257 |
205 octave_value extract_plot_data (int ndim, octave_value& data); | 258 octave_value extract_plot_data (int ndim, octave_value& data); |
206 | 259 |
207 int handle_plot_data (int ndim, ostrstream& plot_buf); | 260 int handle_plot_data (int ndim, ostrstream& plot_buf); |
208 | 261 |
209 int print (int ndim, ostrstream& plot_buf); | 262 int print (int ndim, ostrstream& plot_buf); |
210 | 263 |
211 void print_code (ostream& os); | 264 tree_expression *plot_data (void) { return sp_plot_data; } |
212 | 265 |
213 private: | 266 subplot_using *using_clause (void) { return sp_using_clause; } |
214 tree_expression *plot_data; | 267 |
215 subplot_using *using_clause; | 268 tree_expression *title_clause (void) { return sp_title_clause; } |
216 tree_expression *title_clause; | 269 |
217 subplot_style *style_clause; | 270 subplot_style *style_clause (void) { return sp_style_clause; } |
218 }; | 271 |
219 | 272 void accept (tree_walker& tw); |
220 class | 273 |
221 subplot_list : public SLList<subplot *>, public tree_print_code | 274 private: |
222 { | 275 |
223 public: | 276 // The data to plot. |
224 subplot_list (void) : SLList<subplot *> (), tree_print_code () { } | 277 tree_expression *sp_plot_data; |
225 | 278 |
226 subplot_list (subplot *t) : SLList<subplot *> (), tree_print_code () | 279 // The `using' option |
227 { append (t); } | 280 subplot_using *sp_using_clause; |
281 | |
282 // The `title' option | |
283 tree_expression *sp_title_clause; | |
284 | |
285 // The `style' option | |
286 subplot_style *sp_style_clause; | |
287 }; | |
288 | |
289 class | |
290 subplot_list : public SLList<subplot *> | |
291 { | |
292 public: | |
293 | |
294 subplot_list (void) | |
295 : SLList<subplot *> () { } | |
296 | |
297 subplot_list (subplot *t) | |
298 : SLList<subplot *> () { append (t); } | |
228 | 299 |
229 ~subplot_list (void); | 300 ~subplot_list (void); |
230 | 301 |
231 int print (int ndim, ostrstream& plot_buf); | 302 int print (int ndim, ostrstream& plot_buf); |
232 | 303 |
233 void print_code (ostream& os); | 304 void accept (tree_walker& tw); |
234 }; | 305 }; |
235 | 306 |
236 extern string save_in_tmp_file (octave_value& t, int ndim = 2, | 307 extern string save_in_tmp_file (octave_value& t, int ndim = 2, |
237 bool parametric = false); | 308 bool parametric = false); |
238 | 309 |