1 /*****************************************************************************
5 ** Purpose: Header file for EZplot library
7 ** This is part of the CTSim program
8 ** Copyright (c) 1983-2001 Kevin Rosenberg
10 ** $Id: ezplot.h,v 1.25 2001/01/28 19:10:18 kevin Exp $
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
34 #include "ctsupport.h"
45 EZPlotCurve (const double* x, const double* y, int n);
50 //----------------------------------------------------------------------
52 //----------------------------------------------------------------------
56 LINEAR = 1, // linear axis
57 LOG, // logrithmic axis
58 NOAXIS, // don't plot axis
91 INSIDE = 1, // values of o_legendbox
97 struct KeywordCodeTable {
102 /*-----------------------------------------------------------------------------
106 * i_ Internal variable
109 * Normal variable that is user modifiable
110 * These variables must always have a valid value
112 * Variables controlling devices
113 * clr_ Color variable
114 * Holds a color value
115 * c_ Character string variable
116 * Contains a character string
118 * User modifiable variable associated with the set variable (s_)
119 * These variables do not always have a valid value
120 * These variables change assumption EZPLOT makes about the plot
122 * TRUE if associated value variable (v_) has been set by the user
123 *---------------------------------------------------------------------------*/
127 typedef std::vector<EZPlotCurve*>::iterator EZPlotCurveIterator;
128 typedef std::vector<EZPlotCurve*>::const_iterator EZPlotCurveConstIterator;
133 //----------------------------------------------------------------------
135 //----------------------------------------------------------------------
211 static const struct KeywordCodeTable m_sKeywords[];
212 static const int NKEYS;
214 std::vector<class EZPlotCurve*> m_vecCurves;
215 std::vector<int> m_veciColor;
216 std::vector<bool> m_vecbColorSet;
217 std::vector<int> m_veciSymbol;
218 std::vector<bool> m_vecbSymbolSet;
219 std::vector<int> m_veciSymbolFreq;
220 std::vector<bool> m_vecbSymbolFreqSet;
221 std::vector<int> m_veciLinestyle;
222 std::vector<bool> m_vecbLinestyleSet;
223 std::vector<std::string> m_vecsLegend;
224 std::vector<bool> m_vecbLegendSet;
226 int getColor (unsigned int iCurve) const;
227 int getSymbol (unsigned int iCurve) const;
228 const std::string* getLegend (unsigned int iCurve) const;
229 int getSymbolFreq (unsigned int iCurve) const;
230 int getLinestyle (unsigned int iCurve) const;
232 void setColor (unsigned int iCurve, int iColor);
233 void setSymbol (unsigned int iCurve, int iSymbol);
234 void setSymbolFreq (unsigned int iCurve, int iSymbolFreq);
235 void setLinestyle (unsigned int iCurve, int iLinestyle);
236 void setLegend (unsigned int iCurve, const std::string& strLegend);
237 void setLegend (unsigned int iCurve, const char* const pszLegend);
242 int clr_axis; // color of all axis lines
243 int clr_title; // color of main title
244 int clr_label; // color of axis labels
245 int clr_legend; // color of legend box
246 int clr_grid; // color of grid lines
247 int clr_number; // color of axis number labels
250 double o_xporigin, o_yporigin; // origin of plot frame in NDC
251 double o_xlength, o_ylength; // length of plot frame in NDC
253 std::string c_xlabel; // label for x axis
254 std::string c_ylabel; // label for y axis
255 std::string c_title; // title to print above graph
257 int o_linestyle, o_color; // style to use for curves all subsequent curves to EZPLOT
258 int o_xaxis, o_yaxis; // Specifies where axis & labels are drawn
259 bool o_grid; // Flag to draw a grid at major ticks
260 bool o_box; // Flag to draw a box around the graph
262 int o_xticks, o_yticks; // direction to draw tick marks
263 bool o_xtlabel, o_ytlabel; // TRUE if label tick marks
265 int o_xmajortick, o_ymajortick; // number of major ticks to draw
266 int o_xminortick, o_yminortick; // number of minor ticks between major ticks
268 int o_symbol; // Symbol type, (0 = no symbol)
269 int o_symfreq; // frequency to draw symbols at curve points
271 int o_legendbox; // controls whether legend is inside or outside of the axis extents
272 int o_tag; // controls whether to draw tag at end of axes
274 // VALUE & SET variables
275 double v_xmin, v_xmax, v_ymin, v_ymax; // user supplied axis endpoints
276 bool s_xmin, s_xmax, s_ymin, s_ymax; // TRUE is endpoint has been set
277 double v_xtitle, v_ytitle; // NDC position to plot title
278 bool s_xtitle, s_ytitle; // TRUE if set position for title
279 double v_xcross, v_ycross; // position that axes cross
280 bool s_xcross, s_ycross; // TRUE if set axes cross position
281 double v_xlegend, v_ylegend; // upper-left position of legend box in NDC
282 bool s_xlegend, s_ylegend; // TRUE if set position of legend box
283 int v_lxfrac, v_lyfrac; // number of digits to right of decimal place
284 bool s_lxfrac, s_lyfrac; // TRUE if set number of fractional digits
285 double v_textsize; // size of text in NDC
286 bool s_textsize; // TRUE if user set size of text
289 double charheight; // Height of characters in NDC
290 double charwidth; // Height of characters in NDC
291 double xp_min, xp_max, yp_min, yp_max; // boundry of plot frame in NDC
292 double xa_min, xa_max, ya_min, ya_max; // extent of axes in NDC
293 double xgw_min, xgw_max, ygw_min, ygw_max; // boundary of graph in input coords
294 double xgn_min, xgn_max, ygn_min, ygn_max; // boundy of graph in NDC
295 double xt_min, xt_max, yt_min, yt_max; // boundary of axis ticks
296 double xl_min, xl_max, yl_min, yl_max; // boundary of legend box
297 double title_row; // y-coord of title row
298 double xtl_ofs; // Offset y-coord of x tick labels from axis
299 double ytl_ofs; // Offset x-coord of y tick labels from axis
300 double xlbl_row; // row of x label in world coord
301 double ylbl_col; // column of y label in world coord
302 double xw_tickinc, yw_tickinc; // increment between major ticks in WC
303 double xn_tickinc, yn_tickinc; // increment between major ticks in NDC
304 int x_nint, y_nint; // number of intervals along x & y axes
305 int x_fldwid, x_frac; // numeric field sizes & number of digits
306 int y_fldwid, y_frac; // in fraction of number, used for printf()
307 double xtl_wid, ytl_wid; // length of ticks labels in NDC
308 double tl_height; // height of tick labels in NDC
309 char x_numfmt[20]; // format to print x tick labels
310 char y_numfmt[20]; // format to print y tick labels
312 double m_dVP_xmin, m_dVP_ymin;
313 double m_dVP_xmax, m_dVP_ymax;
314 double m_dVP_xscale, m_dVP_yscale;
315 double m_xWorldScale, m_yWorldScale;
318 void symbol (int sym, double symwidth, double symheight);
319 void make_numfmt(char *fmtstr, int *fldwid, int *nfrac, double min, double max, int nint);
320 int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp);
327 bool ezcmd (const char* const comm);
329 void bad_option(char *opt);
330 void initPlotSettings();
332 void initKeywords ();
334 double convertWorldToNDC_X (double x)
335 { return xgn_min + (x - xgw_min) * m_xWorldScale; }
337 double convertWorldToNDC_Y (double y)
338 { return ygn_min + (y - ygw_min) * m_yWorldScale; }
344 bool ezset (const std::string& command);
345 bool ezset (const char* const command);
347 void addCurve (const float* x, const double* y, int num);
348 void addCurve (const double* x, const float* y, int num);
349 void addCurve (const double* x, const double* y, int num);
350 void addCurve (const double* y, int n);
351 void addCurve (const float* y, int n);
353 void plot (SGP* pSGP);