author | drw <drw> | 2004-03-30 17:49:34 (UTC) |
---|---|---|
committer | drw <drw> | 2004-03-30 17:49:34 (UTC) |
commit | c74a24cbd04cb74d832908eb2b373aed7b3cea71 (patch) (unidiff) | |
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 | |||
@@ -84,3 +84,3 @@ void Graph::initGraph() | |||
84 | { | 84 | { |
85 | drawBarChart( width(), height(), data->maxValue() ); | 85 | drawBarChart( width(), height(), data->maxValue(), data->minValue() ); |
86 | } | 86 | } |
@@ -94,3 +94,3 @@ void Graph::initGraph() | |||
94 | 94 | ||
95 | void Graph::drawBarChart( int width, int height, float max ) | 95 | void Graph::drawBarChart( int width, int height, float max, float min ) |
96 | { | 96 | { |
@@ -113,11 +113,14 @@ void Graph::drawBarChart( int width, int height, float max ) | |||
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++; |
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 | |||
@@ -58,3 +58,3 @@ class Graph : public QWidget | |||
58 | void initGraph(); | 58 | void initGraph(); |
59 | void drawBarChart( int, int, float ); | 59 | void drawBarChart( int, int, float, float ); |
60 | void drawPieChart( int, int, float ); | 60 | 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 | |||
@@ -99,2 +99,15 @@ float GraphInfo::maxValue() | |||
99 | 99 | ||
100 | float GraphInfo::minValue() | ||
101 | { | ||
102 | float min = 0.0; | ||
103 | for ( DataPointInfo *data = d->first(); data; data = d->next() ) | ||
104 | { | ||
105 | if ( data->value() < min ) | ||
106 | { | ||
107 | min = data->value(); | ||
108 | } | ||
109 | } | ||
110 | return min; | ||
111 | } | ||
112 | |||
100 | float GraphInfo::totalValue() | 113 | 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 | |||
@@ -44,3 +44,3 @@ class DataPointInfo | |||
44 | float value() { return v; } | 44 | float value() { return v; } |
45 | 45 | ||
46 | void addToValue( float value ) { v += value; } | 46 | void addToValue( float value ) { v += value; } |
@@ -73,2 +73,3 @@ class GraphInfo | |||
73 | float maxValue(); | 73 | float maxValue(); |
74 | float minValue(); | ||
74 | float totalValue(); | 75 | float totalValue(); |