1 /* 2 * gretl -- Gnu Regression, Econometrics and Time-series Library 3 * Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #ifndef PLOTSPEC_H 21 #define PLOTSPEC_H 22 23 #define GP_BORDER_DEFAULT (-1) 24 #define LT_AUTO (-2) 25 26 typedef enum { 27 GP_STYLE_NONE, 28 GP_STYLE_LINES, 29 GP_STYLE_POINTS, 30 GP_STYLE_LINESPOINTS, 31 GP_STYLE_IMPULSES, 32 GP_STYLE_DOTS, 33 GP_STYLE_STEPS, 34 GP_STYLE_BOXES, 35 GP_STYLE_ERRORBARS, 36 GP_STYLE_FILLEDCURVE, 37 GP_STYLE_CANDLESTICKS, 38 GP_STYLE_AUTO 39 } GpLineStyle; 40 41 typedef enum { 42 GP_KEY_LEFT_TOP, 43 GP_KEY_RIGHT_TOP, 44 GP_KEY_LEFT_BOTTOM, 45 GP_KEY_RIGHT_BOTTOM, 46 GP_KEY_OUTSIDE, 47 GP_KEY_NONE 48 } GpKeyPos; 49 50 typedef enum { 51 GP_X_RANGE, 52 GP_Y_RANGE, 53 GP_Y2_RANGE, 54 GP_T_RANGE, 55 GP_X2_RANGE 56 } GpRange; 57 58 typedef struct gp_style_spec_ gp_style_spec; 59 60 struct gp_style_spec_ { 61 int id; 62 const char *name; 63 const char *trname; 64 }; 65 66 typedef struct gp_key_spec_ gp_key_spec; 67 68 struct gp_key_spec_ { 69 int id; 70 const char *str; 71 }; 72 73 typedef struct plotbars_ plotbars; 74 75 typedef enum { 76 GP_LINE_USER = 1 << 0, 77 GP_LINE_BOXDATA = 1 << 1, 78 GP_LINE_AUXDATA = 1 << 2 79 } gp_line_flags; 80 81 /* information about a line within a gnuplot graph */ 82 83 typedef struct { 84 int varnum; /* ID number of variable to plot */ 85 GpLineStyle style; /* lines, points, etc. */ 86 gchar *title; /* key or legend title */ 87 gchar *formula; /* expression to plot (rather than data) */ 88 char *ustr; /* custom 'using' string */ 89 int *mcols; /* data-matrix columns used */ 90 float pscale; /* scale factor for points */ 91 char rgb[8]; /* rgb color specification */ 92 char yaxis; /* 1 for left, 2 for right */ 93 int type; /* 1, 2, ... (style reference) */ 94 int ptype; /* point type */ 95 int dtype; /* dash type */ 96 float width; /* line width, default 1.0 */ 97 char ncols; /* number of data columns (0 for formula) */ 98 float whiskwidth; /* whiskerbar width (boxplots) */ 99 char flags; /* additional options */ 100 } GPT_LINE; 101 102 #define PLOT_LABEL_TEXT_LEN 31 103 104 typedef enum { 105 GP_JUST_LEFT, 106 GP_JUST_CENTER, 107 GP_JUST_RIGHT 108 } gp_just_codes; 109 110 typedef struct { 111 char text[PLOT_LABEL_TEXT_LEN + 1]; 112 double pos[2]; 113 int just; 114 } GPT_LABEL; 115 116 typedef enum { 117 GP_ARROW_HEAD = 1 << 0, 118 GP_ARROW_DOTS = 1 << 1 119 } gp_arrow_flags; 120 121 typedef struct { 122 double x0, y0, x1, y1; 123 int flags; 124 } GPT_ARROW; 125 126 /* "global" information concerning a gnuplot graph specification */ 127 128 struct GPT_SPEC_ { 129 FILE *fp; 130 char fname[MAXLEN]; /* for gui purposes */ 131 PlotType code; /* to deal with FREQ, FCAST... */ 132 GptFlags flags; /* bitwise OR of options */ 133 int heredata; /* plot file uses "heredoc" for data */ 134 FitType fit; /* type of fitted line shown */ 135 int nobs; /* number of observations */ 136 int okobs; /* number of fully valid observations */ 137 int datacols; /* number of data columns */ 138 int pd; /* frequency (time series data) */ 139 int nbars; /* number of time-series shaded bars */ 140 char xvarname[MAXDISP]; /* name of x variable */ 141 char yvarname[MAXDISP]; /* name of y variable */ 142 gchar *titles[5]; /* main, x, y, y2, x2 */ 143 double range[5][2]; /* axis range specifiers */ 144 double logbase[3]; /* axis log-scales base (0 for linear) */ 145 int keyspec; /* position of key (or none) */ 146 char timefmt[16]; /* time format, if applicable */ 147 char xfmt[16]; /* x-axis tic format */ 148 char xtics[64]; /* x-axis tic marks */ 149 char mxtics[4]; /* minor tics */ 150 char yfmt[16]; /* y-axis tic format */ 151 char ytics[64]; /* y-axis tic marks */ 152 char *xticstr; /* special xtics */ 153 char *x2ticstr; /* special x2tics */ 154 int termtype; /* gnuplot "terminal" code */ 155 int n_lines; /* number of lines */ 156 int samples; /* number of samples for parametric plots */ 157 int border; /* gnuplot border code */ 158 char border_lc[8]; /* border line color */ 159 int bmargin; /* bottom margin */ 160 float boxwidth; /* when using box style for frequency plots */ 161 float fillfrac; /* fraction for "set style fill solid" */ 162 GPT_LINE *lines; /* details on individual lines */ 163 char **literal; /* additional commands */ 164 int n_literal; /* number of the above */ 165 gretl_matrix *data; /* data to plot */ 166 char **markers; /* data-point markers (not always present) */ 167 int n_markers; /* number of such markers */ 168 GPT_LABEL *labels; /* textual labels written onto graph */ 169 int n_labels; /* number of the above */ 170 GPT_ARROW *arrows; /* arrows drawn onto graph */ 171 int n_arrows; /* number of the above */ 172 int *reglist; /* regression list for X-Y plot with fitted line */ 173 gretl_matrix *b_ols; /* coeffs for linear fit */ 174 gretl_matrix *b_quad; /* coeffs for quadratic fit */ 175 gretl_matrix *b_cub; /* coeffs for cubic fit */ 176 gretl_matrix *b_inv; /* coeffs for inverse fit */ 177 gretl_matrix *b_log; /* coeffs for semi-log fit */ 178 gretl_matrix *b_linlog; /* coeffs for linear-log fit */ 179 double scale; /* for GUI use */ 180 char *labeled; /* for GUI use */ 181 void *ptr; /* for GUI use */ 182 plotbars *bars; /* for GUI use */ 183 char *fontstr; /* for GUI use */ 184 gretl_matrix *auxdata; /* for GUI use */ 185 }; 186 187 GPT_SPEC *plotspec_new (void); 188 189 void plotspec_destroy (GPT_SPEC *spec); 190 191 void plotspec_label_init (GPT_LABEL *lbl); 192 193 int plotspec_add_line (GPT_SPEC *spec); 194 195 int plotspec_delete_line (GPT_SPEC *spec, int i); 196 197 int plotspec_max_line_width (GPT_SPEC *spec); 198 199 GPT_LINE *plotspec_clone_lines (GPT_SPEC *spec, int *err); 200 201 int plotspec_add_arrow (GPT_SPEC *spec); 202 203 int plotspec_delete_arrow (GPT_SPEC *spec, int i); 204 205 GPT_ARROW *plotspec_clone_arrows (GPT_SPEC *spec, int *err); 206 207 int plotspec_add_label (GPT_SPEC *spec); 208 209 int plotspec_delete_label (GPT_SPEC *spec, int i); 210 211 GPT_LABEL *plotspec_clone_labels (GPT_SPEC *spec, int *err); 212 213 int plotspec_print (GPT_SPEC *spec, FILE *fp); 214 215 int plotspec_add_fit (GPT_SPEC *spec, FitType f); 216 217 void print_auto_fit_string (FitType fit, FILE *fp); 218 219 int gp_line_data_columns (GPT_SPEC *spec, int i); 220 221 const char *gp_line_style_display_name (int t); 222 223 int gp_style_index_from_name (const char *s); 224 225 int gp_style_index_from_display_name (const char *s); 226 227 gp_style_spec *get_style_spec (int t); 228 229 int gp_keypos_from_name (const char *s); 230 231 int gp_keypos_from_display_name (const char *s); 232 233 gp_key_spec *get_keypos_spec (int t); 234 235 void print_keypos_string (int t, FILE *fp); 236 237 void set_plotfit_line (GPT_LINE *line, 238 FitType f, const double *b, 239 double x0, double pd); 240 241 int plotspec_add_bars_info (GPT_SPEC *spec, 242 double xmin, double xmax, 243 double ymin, double ymax, 244 const char *fname); 245 246 int plotspec_allocate_bars (GPT_SPEC *spec); 247 248 int plotspec_set_bar_info (GPT_SPEC *spec, int i, 249 double t1, double t2); 250 251 void plotspec_set_bars_limits (GPT_SPEC *spec, 252 double t1, double t2, 253 double ymin, double ymax); 254 255 void plotspec_remove_bars (GPT_SPEC *spec); 256 257 int plotspec_line_is_formula (const GPT_SPEC *spec, int i); 258 259 #endif /* PLOTSPEC_H */ 260