2 // "$Id: Fl_Chart.H 7981 2010-12-08 23:53:04Z greg.ercolano $"
4 // Forms chart header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
35 #include "Fl_Widget.H"
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 */
47 #define FL_FILLED_CHART FL_FILL_CHART /**< for compatibility */
49 #define FL_CHART_MAX 128 /**< max entries per chart */
50 #define FL_CHART_LABEL_MAX 18 /**< max label length for entry */
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. */
61 \brief Fl_Chart displays simple charts.
62 It is provided for Forms compatibility.
64 \image html charts.png
65 \image latex charts.png "Fl_Chart" width=10cm
66 \todo Refactor Fl_Chart::type() information.
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
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
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.
81 class FL_EXPORT Fl_Chart : public Fl_Widget {
85 FL_CHART_ENTRY *entries;
89 Fl_Fontsize textsize_;
94 Fl_Chart(int X, int Y, int W, int H, const char *L = 0);
100 void add(double val, const char *str = 0, unsigned col = 0);
102 void insert(int ind, double val, const char *str = 0, unsigned col = 0);
104 void replace(int ind, double val, const char *str = 0, unsigned col = 0);
107 Gets the lower and upper bounds of the chart values.
108 \param[out] a, b are set to lower, upper
110 void bounds(double *a,double *b) const {*a = min; *b = max;}
112 void bounds(double a,double b);
115 Returns the number of data values in the chart.
117 int size() const {return numb;}
119 void size(int W, int H) { Fl_Widget::size(W, H); }
122 Gets the maximum number of data values for a chart.
124 int maxsize() const {return maxnumb;}
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;}
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;}
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;}
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.
147 uchar autosize() const {return autosize_;}
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.
153 void autosize(uchar n) {autosize_ = n;}
159 // End of "$Id: Fl_Chart.H 7981 2010-12-08 23:53:04Z greg.ercolano $".