Fl_Chart.H 4.8 KB

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