DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // "$Id: Fl_Chart.H 7981 2010-12-08 23:53:04Z greg.ercolano $" |
| 3 | // |
| 4 | // Forms chart header file for the Fast Light Tool Kit (FLTK). |
| 5 | // |
| 6 | // Copyright 1998-2010 by Bill Spitzak and others. |
| 7 | // |
| 8 | // This library is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU Library General Public |
| 10 | // License as published by the Free Software Foundation; either |
| 11 | // version 2 of the License, or (at your option) any later version. |
| 12 | // |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // Library General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU Library General Public |
| 19 | // License along with this library; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 21 | // USA. |
| 22 | // |
| 23 | // Please report all bugs and problems on the following page: |
| 24 | // |
| 25 | // http://www.fltk.org/str.php |
| 26 | // |
| 27 | |
| 28 | /* \file |
| 29 | Fl_Chart widget . */ |
| 30 | |
| 31 | #ifndef Fl_Chart_H |
| 32 | #define Fl_Chart_H |
| 33 | |
| 34 | #ifndef Fl_Widget_H |
| 35 | #include "Fl_Widget.H" |
| 36 | #endif |
| 37 | |
| 38 | // values for type() |
| 39 | #define FL_BAR_CHART 0 /**< type() for Bar Chart variant */ |
| 40 | #define FL_HORBAR_CHART 1 /**< type() for Horizontal Bar Chart variant */ |
| 41 | #define FL_LINE_CHART 2 /**< type() for Line Chart variant */ |
| 42 | #define FL_FILL_CHART 3 /**< type() for Fill Line Chart variant */ |
| 43 | #define FL_SPIKE_CHART 4 /**< type() for Spike Chart variant */ |
| 44 | #define FL_PIE_CHART 5 /**< type() for Pie Chart variant */ |
| 45 | #define FL_SPECIALPIE_CHART 6 /**< type() for Special Pie Chart variant */ |
| 46 | |
| 47 | #define FL_FILLED_CHART FL_FILL_CHART /**< for compatibility */ |
| 48 | |
| 49 | #define FL_CHART_MAX 128 /**< max entries per chart */ |
| 50 | #define FL_CHART_LABEL_MAX 18 /**< max label length for entry */ |
| 51 | |
| 52 | /** For internal use only */ |
| 53 | struct FL_CHART_ENTRY { |
| 54 | float val; /**< For internal use only. */ |
| 55 | unsigned col; /**< For internal use only. */ |
| 56 | char str[FL_CHART_LABEL_MAX+1]; /**< For internal use only. */ |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | \class Fl_Chart |
| 61 | \brief Fl_Chart displays simple charts. |
| 62 | It is provided for Forms compatibility. |
| 63 | |
| 64 | \image html charts.png |
| 65 | \image latex charts.png "Fl_Chart" width=10cm |
| 66 | \todo Refactor Fl_Chart::type() information. |
| 67 | |
| 68 | The type of an Fl_Chart object can be set using type(uchar t) to: |
| 69 | \li \c FL_BAR_CHART: Each sample value is drawn as a vertical bar. |
| 70 | \li \c FL_FILLED_CHART: The chart is filled from the bottom of the graph |
| 71 | to the sample values. |
| 72 | \li \c FL_HORBAR_CHART: Each sample value is drawn as a horizontal bar. |
| 73 | \li \c FL_LINE_CHART: The chart is drawn as a polyline with vertices at |
| 74 | each sample value. |
| 75 | \li \c FL_PIE_CHART: A pie chart is drawn with each sample value being |
| 76 | drawn as a proportionate slice in the circle. |
| 77 | \li \c FL_SPECIALPIE_CHART: Like \c FL_PIE_CHART, but the first slice is |
| 78 | separated from the pie. |
| 79 | \li \c FL_SPIKE_CHART: Each sample value is drawn as a vertical line. |
| 80 | */ |
| 81 | class FL_EXPORT Fl_Chart : public Fl_Widget { |
| 82 | int numb; |
| 83 | int maxnumb; |
| 84 | int sizenumb; |
| 85 | FL_CHART_ENTRY *entries; |
| 86 | double min,max; |
| 87 | uchar autosize_; |
| 88 | Fl_Font textfont_; |
| 89 | Fl_Fontsize textsize_; |
| 90 | Fl_Color textcolor_; |
| 91 | protected: |
| 92 | void draw(); |
| 93 | public: |
| 94 | Fl_Chart(int X, int Y, int W, int H, const char *L = 0); |
| 95 | |
| 96 | ~Fl_Chart(); |
| 97 | |
| 98 | void clear(); |
| 99 | |
| 100 | void add(double val, const char *str = 0, unsigned col = 0); |
| 101 | |
| 102 | void insert(int ind, double val, const char *str = 0, unsigned col = 0); |
| 103 | |
| 104 | void replace(int ind, double val, const char *str = 0, unsigned col = 0); |
| 105 | |
| 106 | /** |
| 107 | Gets the lower and upper bounds of the chart values. |
| 108 | \param[out] a, b are set to lower, upper |
| 109 | */ |
| 110 | void bounds(double *a,double *b) const {*a = min; *b = max;} |
| 111 | |
| 112 | void bounds(double a,double b); |
| 113 | |
| 114 | /** |
| 115 | Returns the number of data values in the chart. |
| 116 | */ |
| 117 | int size() const {return numb;} |
| 118 | |
| 119 | void size(int W, int H) { Fl_Widget::size(W, H); } |
| 120 | |
| 121 | /** |
| 122 | Gets the maximum number of data values for a chart. |
| 123 | */ |
| 124 | int maxsize() const {return maxnumb;} |
| 125 | |
| 126 | void maxsize(int m); |
| 127 | |
| 128 | /** Gets the chart's text font */ |
| 129 | Fl_Font textfont() const {return textfont_;} |
| 130 | /** Sets the chart's text font to \p s. */ |
| 131 | void textfont(Fl_Font s) {textfont_ = s;} |
| 132 | |
| 133 | /** Gets the chart's text size */ |
| 134 | Fl_Fontsize textsize() const {return textsize_;} |
| 135 | /** gets the chart's text size to \p s. */ |
| 136 | void textsize(Fl_Fontsize s) {textsize_ = s;} |
| 137 | |
| 138 | /** Gets the chart's text color */ |
| 139 | Fl_Color textcolor() const {return textcolor_;} |
| 140 | /** gets the chart's text color to \p n. */ |
| 141 | void textcolor(Fl_Color n) {textcolor_ = n;} |
| 142 | |
| 143 | /** |
| 144 | Get whether the chart will automatically adjust the bounds of the chart. |
| 145 | \returns non-zero if auto-sizing is enabled and zero if disabled. |
| 146 | */ |
| 147 | uchar autosize() const {return autosize_;} |
| 148 | |
| 149 | /** |
| 150 | Set whether the chart will automatically adjust the bounds of the chart. |
| 151 | \param[in] n non-zero to enable automatic resizing, zero to disable. |
| 152 | */ |
| 153 | void autosize(uchar n) {autosize_ = n;} |
| 154 | }; |
| 155 | |
| 156 | #endif |
| 157 | |
| 158 | // |
| 159 | // End of "$Id: Fl_Chart.H 7981 2010-12-08 23:53:04Z greg.ercolano $". |
| 160 | // |