Diffstat (limited to 'noncore/apps/checkbook/graph.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/graph.cpp | 17 |
1 files changed, 10 insertions, 7 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; |