QtiPlot  0.9.8.2
BoxCurve.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : BoxCurve.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Box curve
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef BOXCURVE_H
00030 #define BOXCURVE_H
00031 
00032 #include "PlotCurve.h"
00033 #include <qwt_plot.h>
00034 #include <qwt_symbol.h>
00035 
00037 class BoxCurve: public DataCurve
00038 {
00039 public:
00040     enum BoxStyle{NoBox, Rect, Diamond, WindBox, Notch};
00041     enum Range{None, SD, SE, r25_75, r10_90, r5_95, r1_99, MinMax, UserDef};
00042     enum LabelsDisplayPolicy{Percentage, Value, PercentageValue, ValuePercentage};
00043 
00044     BoxCurve(Table *t, const QString& name, int startRow = 0, int endRow = -1);
00045 
00046     void copy(BoxCurve *b);
00047 
00048     virtual QwtDoubleRect boundingRect() const;
00049 
00050     QwtSymbol::Style minStyle(){return min_style;};
00051     void setMinStyle(QwtSymbol::Style s){min_style = s;};
00052 
00053     QwtSymbol::Style maxStyle(){return max_style;};
00054     void setMaxStyle(QwtSymbol::Style s){max_style = s;};
00055 
00056     void setMeanStyle(QwtSymbol::Style s){mean_style = s;};
00057     QwtSymbol::Style meanStyle(){return mean_style;};
00058 
00059     void setP99Style(QwtSymbol::Style s){p99_style = s;};
00060     QwtSymbol::Style p99Style(){return p99_style;};
00061 
00062     void setP1Style(QwtSymbol::Style s){p1_style = s;};
00063     QwtSymbol::Style p1Style(){return p1_style;};
00064 
00065     int boxStyle(){return b_style;};
00066     void setBoxStyle(int style);
00067 
00068     int boxWidth(){return b_width;};
00069     void setBoxWidth(int width){b_width=width;};
00070 
00071     double boxRange(){return b_coeff;};
00072     int boxRangeType(){return b_range;};
00073     void setBoxRange(int type, double coeff);
00074 
00075     double whiskersRange(){return w_coeff;};
00076     int whiskersRangeType(){return w_range;};
00077     void setWhiskersRange(int type, double coeff = 0.0);
00078 
00079     LabelsDisplayPolicy labelsDisplayPolicy(){return d_labels_display;};
00080     void setLabelsDisplayPolicy(const LabelsDisplayPolicy& policy);
00081 
00082     bool hasBoxLabels(){return d_box_labels;};
00083     void showBoxLabels(bool on = true);
00084 
00085     bool hasWhiskerLabels(){return d_whiskers_labels;};
00086     void showWhiskerLabels(bool on = true);
00087 
00088     void loadData();
00089 
00090     QString statistics();
00091 
00092     double median(){return quantile(0.5);};
00093     double quantile(double f);
00094 
00095 private:
00096     void draw(QPainter *painter,const QwtScaleMap &xMap,
00097         const QwtScaleMap &yMap, int from, int to) const;
00098     void drawBox(QPainter *painter, const QwtScaleMap &xMap,
00099                 const QwtScaleMap &yMap, double *dat, int size) const;
00100     void drawSymbols(QPainter *painter, const QwtScaleMap &xMap,
00101                 const QwtScaleMap &yMap, double *dat, int size) const;
00102 
00103     double* statisticValues();
00104     QString labelText(int index, double val);
00105     QString labelPercentage(int index);
00106     void createLabel(double val);
00107     virtual void loadLabels();
00108     void updateLabels(bool updateText = true);
00109     void updateLabelsPosition(){updateLabels(false);};
00110 
00111     QwtSymbol::Style min_style;
00112     QwtSymbol::Style max_style;
00113     QwtSymbol::Style mean_style;
00114     QwtSymbol::Style p99_style;
00115     QwtSymbol::Style p1_style;
00116     double b_coeff;
00117     double w_coeff;
00118     int b_range;
00119     int w_range;
00120     int b_style;
00121     int b_width;
00122     bool d_box_labels;
00123     bool d_whiskers_labels;
00124     LabelsDisplayPolicy d_labels_display;
00125 };
00126 
00127 
00129 class QwtSingleArrayData: public QwtData
00130 {
00131 public:
00132     QwtSingleArrayData(const double x, QwtArray<double> y, size_t)
00133     {
00134         d_y = y;
00135         d_x = x;
00136     };
00137 
00138     virtual QwtData *copy() const{return new QwtSingleArrayData(d_x, d_y, size());};
00139 
00140     virtual size_t size() const{return d_y.size();};
00141     virtual double x(size_t) const{return d_x;};
00142     virtual double y(size_t i) const{return d_y[int(i)];};
00143 
00144 private:
00145     QwtArray<double> d_y;
00146     double d_x;
00147 };
00148 
00149 #endif