summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/graph.cpp17
-rw-r--r--noncore/apps/checkbook/graph.h2
-rw-r--r--noncore/apps/checkbook/graphinfo.cpp13
-rw-r--r--noncore/apps/checkbook/graphinfo.h3
4 files changed, 26 insertions, 9 deletions
diff --git a/noncore/apps/checkbook/graph.cpp b/noncore/apps/checkbook/graph.cpp
index 389972e..72da738 100644
--- a/noncore/apps/checkbook/graph.cpp
+++ b/noncore/apps/checkbook/graph.cpp
@@ -61,86 +61,89 @@ void Graph::paintEvent( QPaintEvent * )
drawGraph( FALSE );
}
void Graph::resizeEvent( QResizeEvent * )
{
drawGraph( TRUE );
}
void Graph::initGraph()
{
graph.resize( width(), height() );
graph.fill( QColor( 255, 255, 255 ) );
if ( !data )
{
return;
}
// Any common stuff here (titles, ???)
switch ( data->graphType() )
{
case GraphInfo::BarChart :
{
- drawBarChart( width(), height(), data->maxValue() );
+ drawBarChart( width(), height(), data->maxValue(), data->minValue() );
}
break;
case GraphInfo::PieChart :
{
drawPieChart( width(), height(), data->totalValue() );
}
};
}
-void Graph::drawBarChart( int width, int height, float max )
+void Graph::drawBarChart( int width, int height, float max, float min )
{
QPainter p( &graph );
// Try to set the font size smaller for text
QFont f = font();
f.setPointSize( 8 );
p.setFont( f );
int x = 0;
int i = 0;
int n = data->numberDataPoints();
QFontMetrics fm=fontMetrics();
int fh = fm.height();
int fw;
QColor c( 0, 0, 255);
p.setBrush( c );
+ if ( min > 0 )
+ min = 0.0;
+
+ int bw = ( width - width / 4 ) / n;
+ int hoffset = int( ( height - height / 4 - 1 ) * ( min * -1 ) / ( max - min ) );
for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() )
{
- int bw = ( width - width / 4 - x ) / ( n - i );
- int bh = int( ( height - height / 4 - 1 ) * dp->value() / max );
- p.drawRect( width / 8 + x, height - height / 8 - 1 - bh, bw, bh );
+ int bh = int( ( height - height / 4 - 1 ) * dp->value() / ( max - min ) );
+ p.drawRect( width / 8 + x, height - height / 8 - 1 - hoffset - bh, bw, bh );
fw = fm.width( dp->label() );
- p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8, fw,
+ p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8 - hoffset, fw,
fh + height / 8, AlignTop | AlignHCenter, dp->label() );
-// WordBreak | AlignTop | AlignHCenter, dp->label() );
i++;
x += bw;
}
}
void Graph::drawPieChart( int width, int height, float sum )
{
QPainter p( &graph );
// Try to set the font size smaller for text
QFont f = font();
f.setPointSize( 8 );
p.setFont( f );
int n = data->numberDataPoints();
int apos = -90 * 16;
int xd = width - width / 5;
int yd = height - height / 5;
int i = 0;
QColor c;
diff --git a/noncore/apps/checkbook/graph.h b/noncore/apps/checkbook/graph.h
index 340e910..616cbb6 100644
--- a/noncore/apps/checkbook/graph.h
+++ b/noncore/apps/checkbook/graph.h
@@ -35,29 +35,29 @@
class GraphInfo;
class QPainter;
class Graph : public QWidget
{
Q_OBJECT
public:
Graph( QWidget * = 0x0, GraphInfo * = 0x0, const QString & = 0x0, int = 0 );
void setGraphInfo( GraphInfo * );
void drawGraph( bool = FALSE );
protected:
void paintEvent( QPaintEvent * );
void resizeEvent( QResizeEvent * );
private:
GraphInfo *data;
QPixmap graph;
void initGraph();
- void drawBarChart( int, int, float );
+ void drawBarChart( int, int, float, float );
void drawPieChart( int, int, float );
};
#endif
diff --git a/noncore/apps/checkbook/graphinfo.cpp b/noncore/apps/checkbook/graphinfo.cpp
index fec6896..5b72c80 100644
--- a/noncore/apps/checkbook/graphinfo.cpp
+++ b/noncore/apps/checkbook/graphinfo.cpp
@@ -76,48 +76,61 @@ DataPointInfo *GraphInfo::firstDataPoint()
DataPointInfo *GraphInfo::nextDataPoint()
{
return( d->next() );
}
int GraphInfo::numberDataPoints()
{
return( d->count() );
}
float GraphInfo::maxValue()
{
float max = 0.0;
for ( DataPointInfo *data = d->first(); data; data = d->next() )
{
if ( data->value() > max )
{
max = data->value();
}
}
return max;
}
+float GraphInfo::minValue()
+{
+ float min = 0.0;
+ for ( DataPointInfo *data = d->first(); data; data = d->next() )
+ {
+ if ( data->value() < min )
+ {
+ min = data->value();
+ }
+ }
+ return min;
+}
+
float GraphInfo::totalValue()
{
float sum = 0.0;
for ( DataPointInfo *data = d->first(); data; data = d->next() )
{
sum += data->value();
}
return sum;
}
void GraphInfo::setGraphTitle( const QString &title )
{
gt = title;
}
void GraphInfo::setXAxisTitle( const QString &xtitle )
{
xt = xtitle;
}
void GraphInfo::setYAxisTitle( const QString &ytitle )
{
yt = ytitle;
}
diff --git a/noncore/apps/checkbook/graphinfo.h b/noncore/apps/checkbook/graphinfo.h
index 41927b4..f7842c6 100644
--- a/noncore/apps/checkbook/graphinfo.h
+++ b/noncore/apps/checkbook/graphinfo.h
@@ -21,68 +21,69 @@
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef GRAPHINFO_H
#define GRAPHINFO_H
#include <qlist.h>
#include <qstringlist.h>
class DataPointInfo
{
public:
DataPointInfo()
: l( 0x0 ), v( 0.0 ) {}
DataPointInfo( const QString &label, float value )
: l( label ), v( value ) {}
const QString &label() { return l; }
float value() { return v; }
-
+
void addToValue( float value ) { v += value; }
private:
QString l;
float v;
};
typedef QList<DataPointInfo> DataPointList;
class GraphInfo
{
public:
enum GraphType { BarChart, PieChart };
GraphInfo( GraphType = BarChart, DataPointList * = 0x0,
const QString & = 0x0, const QString & = 0x0, const QString & = 0x0 );
~GraphInfo();
GraphInfo::GraphType graphType();
void setGraphType( GraphType );
DataPointList *dataPoints();
void setDataPoints( DataPointList * );
DataPointInfo *firstDataPoint();
DataPointInfo *nextDataPoint();
int numberDataPoints();
float maxValue();
+ float minValue();
float totalValue();
void setGraphTitle( const QString & );
void setXAxisTitle( const QString & );
void setYAxisTitle( const QString & );
private:
GraphType t;
DataPointList *d;
QString gt;
QString xt;
QString yt;
};
#endif