You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.1KB

  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. /* \file
  28. Fl_Chart widget . */
  29. #ifndef Fl_Chart_H
  30. #define Fl_Chart_H
  31. #ifndef Fl_Widget_H
  32. #include "Fl_Widget.H"
  33. #endif
  34. // values for type()
  35. #define FL_BAR_CHART 0 /**< type() for Bar Chart variant */
  36. #define FL_HORBAR_CHART 1 /**< type() for Horizontal Bar Chart variant */
  37. #define FL_LINE_CHART 2 /**< type() for Line Chart variant */
  38. #define FL_FILL_CHART 3 /**< type() for Fill Line Chart variant */
  39. #define FL_SPIKE_CHART 4 /**< type() for Spike Chart variant */
  40. #define FL_PIE_CHART 5 /**< type() for Pie Chart variant */
  41. #define FL_SPECIALPIE_CHART 6 /**< type() for Special Pie Chart variant */
  42. #define FL_FILLED_CHART FL_FILL_CHART /**< for compatibility */
  43. #define FL_CHART_MAX 128 /**< max entries per chart */
  44. #define FL_CHART_LABEL_MAX 18 /**< max label length for entry */
  45. /** For internal use only */
  46. struct FL_CHART_ENTRY {
  47. float val; /**< For internal use only. */
  48. unsigned col; /**< For internal use only. */
  49. char str[FL_CHART_LABEL_MAX+1]; /**< For internal use only. */
  50. };
  51. /**
  52. \class Fl_Chart
  53. \brief Fl_Chart displays simple charts.
  54. It is provided for Forms compatibility.
  55. \image html charts.png
  56. \image latex charts.png "Fl_Chart" width=10cm
  57. \todo Refactor Fl_Chart::type() information.
  58. The type of an Fl_Chart object can be set using type(uchar t) to:
  59. \li \c FL_BAR_CHART: Each sample value is drawn as a vertical bar.
  60. \li \c FL_FILLED_CHART: The chart is filled from the bottom of the graph
  61. to the sample values.
  62. \li \c FL_HORBAR_CHART: Each sample value is drawn as a horizontal bar.
  63. \li \c FL_LINE_CHART: The chart is drawn as a polyline with vertices at
  64. each sample value.
  65. \li \c FL_PIE_CHART: A pie chart is drawn with each sample value being
  66. drawn as a proportionate slice in the circle.
  67. \li \c FL_SPECIALPIE_CHART: Like \c FL_PIE_CHART, but the first slice is
  68. separated from the pie.
  69. \li \c FL_SPIKE_CHART: Each sample value is drawn as a vertical line.
  70. */
  71. class FL_EXPORT Fl_Chart : public Fl_Widget {
  72. int numb;
  73. int maxnumb;
  74. int sizenumb;
  75. FL_CHART_ENTRY *entries;
  76. double min,max;
  77. uchar autosize_;
  78. Fl_Font textfont_;
  79. Fl_Fontsize textsize_;
  80. Fl_Color textcolor_;
  81. protected:
  82. void draw();
  83. public:
  84. Fl_Chart(int X, int Y, int W, int H, const char *L = 0);
  85. ~Fl_Chart();
  86. void clear();
  87. void add(double val, const char *str = 0, unsigned col = 0);
  88. void insert(int ind, double val, const char *str = 0, unsigned col = 0);
  89. void replace(int ind, double val, const char *str = 0, unsigned col = 0);
  90. /**
  91. Gets the lower and upper bounds of the chart values.
  92. \param[out] a, b are set to lower, upper
  93. */
  94. void bounds(double *a,double *b) const {*a = min; *b = max;}
  95. void bounds(double a,double b);
  96. /**
  97. Returns the number of data values in the chart.
  98. */
  99. int size() const {return numb;}
  100. void size(int W, int H) { Fl_Widget::size(W, H); }
  101. /**
  102. Gets the maximum number of data values for a chart.
  103. */
  104. int maxsize() const {return maxnumb;}
  105. void maxsize(int m);
  106. /** Gets the chart's text font */
  107. Fl_Font textfont() const {return textfont_;}
  108. /** Sets the chart's text font to \p s. */
  109. void textfont(Fl_Font s) {textfont_ = s;}
  110. /** Gets the chart's text size */
  111. Fl_Fontsize textsize() const {return textsize_;}
  112. /** gets the chart's text size to \p s. */
  113. void textsize(Fl_Fontsize s) {textsize_ = s;}
  114. /** Gets the chart's text color */
  115. Fl_Color textcolor() const {return textcolor_;}
  116. /** gets the chart's text color to \p n. */
  117. void textcolor(Fl_Color n) {textcolor_ = n;}
  118. /**
  119. Get whether the chart will automatically adjust the bounds of the chart.
  120. \returns non-zero if auto-sizing is enabled and zero if disabled.
  121. */
  122. uchar autosize() const {return autosize_;}
  123. /**
  124. Set whether the chart will automatically adjust the bounds of the chart.
  125. \param[in] n non-zero to enable automatic resizing, zero to disable.
  126. */
  127. void autosize(uchar n) {autosize_ = n;}
  128. };
  129. #endif
  130. //
  131. // End of "$Id: Fl_Chart.H 7981 2010-12-08 23:53:04Z greg.ercolano $".
  132. //