summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/graph.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/graph.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/graph.cpp17
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
@@ -79,23 +79,23 @@ void Graph::initGraph()
79 // Any common stuff here (titles, ???) 79 // Any common stuff here (titles, ???)
80 80
81 switch ( data->graphType() ) 81 switch ( data->graphType() )
82 { 82 {
83 case GraphInfo::BarChart : 83 case GraphInfo::BarChart :
84 { 84 {
85 drawBarChart( width(), height(), data->maxValue() ); 85 drawBarChart( width(), height(), data->maxValue(), data->minValue() );
86 } 86 }
87 break; 87 break;
88 case GraphInfo::PieChart : 88 case GraphInfo::PieChart :
89 { 89 {
90 drawPieChart( width(), height(), data->totalValue() ); 90 drawPieChart( width(), height(), data->totalValue() );
91 } 91 }
92 }; 92 };
93} 93}
94 94
95void Graph::drawBarChart( int width, int height, float max ) 95void Graph::drawBarChart( int width, int height, float max, float min )
96{ 96{
97 QPainter p( &graph ); 97 QPainter p( &graph );
98 98
99 // Try to set the font size smaller for text 99 // Try to set the font size smaller for text
100 QFont f = font(); 100 QFont f = font();
101 f.setPointSize( 8 ); 101 f.setPointSize( 8 );
@@ -108,21 +108,24 @@ void Graph::drawBarChart( int width, int height, float max )
108 int fh = fm.height(); 108 int fh = fm.height();
109 int fw; 109 int fw;
110 110
111 QColor c( 0, 0, 255); 111 QColor c( 0, 0, 255);
112 p.setBrush( c ); 112 p.setBrush( c );
113 113
114 if ( min > 0 )
115 min = 0.0;
116
117 int bw = ( width - width / 4 ) / n;
118 int hoffset = int( ( height - height / 4 - 1 ) * ( min * -1 ) / ( max - min ) );
114 for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() ) 119 for (DataPointInfo *dp = data->firstDataPoint(); dp; dp = data->nextDataPoint() )
115 { 120 {
116 int bw = ( width - width / 4 - x ) / ( n - i ); 121 int bh = int( ( height - height / 4 - 1 ) * dp->value() / ( max - min ) );
117 int bh = int( ( height - height / 4 - 1 ) * dp->value() / max ); 122 p.drawRect( width / 8 + x, height - height / 8 - 1 - hoffset - bh, bw, bh );
118 p.drawRect( width / 8 + x, height - height / 8 - 1 - bh, bw, bh );
119 fw = fm.width( dp->label() ); 123 fw = fm.width( dp->label() );
120 p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8, fw, 124 p.drawText( width / 8 + x - fw / 2 + bw / 2, height - height / 8 - hoffset, fw,
121 fh + height / 8, AlignTop | AlignHCenter, dp->label() ); 125 fh + height / 8, AlignTop | AlignHCenter, dp->label() );
122 // WordBreak | AlignTop | AlignHCenter, dp->label() );
123 i++; 126 i++;
124 x += bw; 127 x += bw;
125 } 128 }
126} 129}
127 130
128void Graph::drawPieChart( int width, int height, float sum ) 131void Graph::drawPieChart( int width, int height, float sum )