Skip to content

Commit

Permalink
Correctly position 0 in stacked bar
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Dec 19, 2016
1 parent d5e5ec3 commit ccf6b7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ public void feed(IBarDataSet data) {

float value = vals[k];

if (value >= 0f) {
if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) {
// Take care of the situation of a 0.0 value, which overlaps a non-zero bar
y = value;
yStart = y;
} else if (value >= 0.0f) {
y = posY;
yStart = posY + value;
posY = yStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ public void drawValues(Canvas c) {
float value = vals[idx];
float y;

if (value >= 0f) {
if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) {
// Take care of the situation of a 0.0 value, which overlaps a non-zero bar
y = value;
} else if (value >= 0.0f) {
posY += value;
y = posY;
} else {
Expand All @@ -307,8 +310,12 @@ public void drawValues(Canvas c) {

for (int k = 0; k < transformed.length; k += 2) {

final float val = vals[k / 2];
final boolean drawBelow =
(val == 0.0f && negY == 0.0f && posY > 0.0f) ||
val < 0.0f;
float y = transformed[k + 1]
+ (vals[k / 2] >= 0 ? posOffset : negOffset);
+ (drawBelow ? negOffset : posOffset);

if (!mViewPortHandler.isInBoundsRight(x))
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ public void drawValues(Canvas c) {
float value = vals[idx];
float y;

if (value >= 0f) {
if (value == 0.0f && (posY == 0.0f || negY == 0.0f)) {
// Take care of the situation of a 0.0 value, which overlaps a non-zero bar
y = value;
} else if (value >= 0.0f) {
posY += value;
y = posY;
} else {
Expand All @@ -279,7 +282,7 @@ public void drawValues(Canvas c) {

for (int k = 0; k < transformed.length; k += 2) {

float val = vals[k / 2];
final float val = vals[k / 2];
String formattedValue = formatter.getFormattedValue(val, e, i, mViewPortHandler);

// calculate the correct offset depending on the draw position of the value
Expand All @@ -292,8 +295,12 @@ public void drawValues(Canvas c) {
negOffset = -negOffset - valueTextWidth;
}

final boolean drawBelow =
(val == 0.0f && negY == 0.0f && posY > 0.0f) ||
val < 0.0f;

float x = transformed[k]
+ (val >= 0 ? posOffset : negOffset);
+ (drawBelow ? negOffset : posOffset);
float y = (buffer.buffer[bufferIndex + 1] + buffer.buffer[bufferIndex + 3]) / 2f;

if (!mViewPortHandler.isInBoundsTop(y))
Expand Down

0 comments on commit ccf6b7e

Please sign in to comment.