author | drw <drw> | 2004-03-30 17:49:34 (UTC) |
---|---|---|
committer | drw <drw> | 2004-03-30 17:49:34 (UTC) |
commit | c74a24cbd04cb74d832908eb2b373aed7b3cea71 (patch) (side-by-side diff) | |
tree | 3ea474f4c8fa64495b8e0604f34ae5a1bd55ac56 | |
parent | 2e5d236b647b1747dca61486ecdd85c8f3869487 (diff) | |
download | opie-c74a24cbd04cb74d832908eb2b373aed7b3cea71.zip opie-c74a24cbd04cb74d832908eb2b373aed7b3cea71.tar.gz opie-c74a24cbd04cb74d832908eb2b373aed7b3cea71.tar.bz2 |
Fix drawing of account balance graph when balance < 0.0
-rw-r--r-- | noncore/apps/checkbook/graph.cpp | 17 | ||||
-rw-r--r-- | noncore/apps/checkbook/graph.h | 2 | ||||
-rw-r--r-- | noncore/apps/checkbook/graphinfo.cpp | 13 | ||||
-rw-r--r-- | noncore/apps/checkbook/graphinfo.h | 3 |
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 @@ -83,5 +83,5 @@ void Graph::initGraph() case GraphInfo::BarChart : { - drawBarChart( width(), height(), data->maxValue() ); + drawBarChart( width(), height(), data->maxValue(), data->minValue() ); } break; @@ -93,5 +93,5 @@ void Graph::initGraph() } -void Graph::drawBarChart( int width, int height, float max ) +void Graph::drawBarChart( int width, int height, float max, float min ) { QPainter p( &graph ); @@ -112,13 +112,16 @@ void Graph::drawBarChart( int width, int height, float max ) 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; 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 @@ -57,5 +57,5 @@ class Graph : public QWidget void initGraph(); - void drawBarChart( int, int, float ); + void drawBarChart( int, int, float, float ); void drawPieChart( int, int, float ); }; 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 @@ -98,4 +98,17 @@ float GraphInfo::maxValue() } +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() { 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 @@ -43,5 +43,5 @@ class DataPointInfo const QString &label() { return l; } float value() { return v; } - + void addToValue( float value ) { v += value; } @@ -72,4 +72,5 @@ class GraphInfo float maxValue(); + float minValue(); float totalValue(); |