Skip to content

Commit

Permalink
Merge pull request #873 from danielgindi/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
PhilJay committed Jul 19, 2015
2 parents 5ac58fc + 1f571a3 commit 10f3076
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 55 deletions.
30 changes: 15 additions & 15 deletions MPChartLib/src/com/github/mikephil/charting/buffer/BarBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,39 @@ public void feed(List<BarEntry> entries) {

} else {

float allPos = e.getPositiveSum();
float allNeg = e.getNegativeSum();
float posY = 0f;
float negY = 0f;
float yStart = 0f;

// fill the stack
for (int k = 0; k < vals.length; k++) {

float value = vals[k];

if(value >= 0f) {

allPos -= value;
y = value + allPos;
y = posY;
yStart = posY + value;
posY = yStart;
} else {
allNeg -= Math.abs(value);
y = value + allNeg;
y = negY;
yStart = negY + value;
negY = yStart;
}

float left = x - barWidth + barSpaceHalf;
float right = x + barWidth - barSpaceHalf;
float bottom, top;
if (mInverted) {
bottom = y >= 0 ? y : 0;
top = y <= 0 ? y : 0;
bottom = y >= yStart ? y : yStart;
top = y <= yStart ? y : yStart;
} else {
top = y >= 0 ? y : 0;
bottom = y <= 0 ? y : 0;
top = y >= yStart ? y : yStart;
bottom = y <= yStart ? y : yStart;
}

// multiply the height of the rect with the phase
if (top > 0)
top *= phaseY;
else
bottom *= phaseY;
top *= phaseY;
bottom *= phaseY;

addBar(left, top, right, bottom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,39 @@ public void feed(List<BarEntry> entries) {

} else {

float allPos = e.getPositiveSum();
float allNeg = e.getNegativeSum();
float posY = 0f;
float negY = 0f;
float yStart = 0f;

// fill the stack
for (int k = 0; k < vals.length; k++) {

float value = vals[k];

if(value >= 0f) {

allPos -= value;
y = value + allPos;
y = posY;
yStart = posY + value;
posY = yStart;
} else {
allNeg -= Math.abs(value);
y = value + allNeg;
y = negY;
yStart = negY + value;
negY = yStart;
}

float bottom = x - barWidth + barSpaceHalf;
float top = x + barWidth - barSpaceHalf;
float left, right;
if (mInverted) {
left = y >= 0 ? y : 0;
right = y <= 0 ? y : 0;
left = y >= yStart ? y : yStart;
right = y <= yStart ? y : yStart;
} else {
right = y >= 0 ? y : 0;
left = y <= 0 ? y : 0;
right = y >= yStart ? y : yStart;
left = y <= yStart ? y : yStart;
}

// multiply the height of the rect with the phase
if (right > 0)
right *= phaseY;
else
left *= phaseY;
right *= phaseY;
left *= phaseY;

addBar(left, top, right, bottom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,25 @@ protected void calcMinMax() {
.getAxisMinValue() : minRight - bottomSpaceRight;

// consider starting at zero (0)
if (mAxisLeft.isStartAtZeroEnabled())
mAxisLeft.mAxisMinimum = 0f;
if (mAxisLeft.isStartAtZeroEnabled()) {
if (mAxisLeft.mAxisMinimum < 0f && mAxisLeft.mAxisMaximum < 0f) {
// If the values are all negative, let's stay in the negative zone
mAxisLeft.mAxisMaximum = 0f;
} else {
// We have positive values, stay in the positive zone
mAxisLeft.mAxisMinimum = 0f;
}
}

if (mAxisRight.isStartAtZeroEnabled())
mAxisRight.mAxisMinimum = 0f;
if (mAxisRight.isStartAtZeroEnabled()) {
if (mAxisRight.mAxisMinimum < 0.0 && mAxisRight.mAxisMaximum < 0.0) {
// If the values are all negative, let's stay in the negative zone
mAxisRight.mAxisMaximum = 0f;
} else {
// We have positive values, stay in the positive zone
mAxisRight.mAxisMinimum = 0f;
}
}

mAxisLeft.mAxisRange = Math.abs(mAxisLeft.mAxisMaximum - mAxisLeft.mAxisMinimum);
mAxisRight.mAxisRange = Math.abs(mAxisRight.mAxisMaximum - mAxisRight.mAxisMinimum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void calcMinMax(int start, int end) {
mLastEnd = end;

mYMin = Float.MAX_VALUE;
mYMax = -Float.MIN_VALUE;
mYMax = -Float.MAX_VALUE;

for (int i = 0; i < mDataSets.size(); i++) {

Expand Down
10 changes: 6 additions & 4 deletions MPChartLib/src/com/github/mikephil/charting/data/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,23 @@ public void notifyDataSetChanged() {
* calc minimum and maximum y value
*/
protected void calcMinMax(int start, int end) {
if (mYVals.size() == 0)
final int yValCount = mYVals.size();

if (yValCount == 0)
return;

int endValue;

if (end == 0)
endValue = mYVals.size() - 1;
if (end == 0 || end >= yValCount)
endValue = yValCount - 1;
else
endValue = end;

mLastStart = start;
mLastEnd = endValue;

mYMin = Float.MAX_VALUE;
mYMax = -Float.MIN_VALUE;
mYMax = -Float.MAX_VALUE;

for (int i = start; i <= endValue; i++) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,21 @@ public void drawValues(Canvas c) {
} else {

float[] transformed = new float[vals.length * 2];
float allPos = e.getPositiveSum();
float allNeg = e.getNegativeSum();

float posY = 0f;
float negY = 0f;

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

float value = vals[idx];
float y;

if(value >= 0f) {

allPos -= value;
y = value + allPos;
if (value >= 0f) {
posY += value;
y = posY;
} else {
allNeg -= Math.abs(value);
y = value + allNeg;
negY += value;
y = negY;
}

transformed[k + 1] = y * mAnimator.getPhaseY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,21 @@ public void drawValues(Canvas c) {
} else {

float[] transformed = new float[vals.length * 2];
float allPos = e.getPositiveSum();
float allNeg = e.getNegativeSum();

float posY = 0f;
float negY = 0f;

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

float value = vals[idx];
float y;

if(value >= 0f) {

allPos -= value;
y = value + allPos;
if (value >= 0f) {
posY += value;
y = posY;
} else {
allNeg -= Math.abs(value);
y = value + allNeg;
negY += value;
y = negY;
}

transformed[k] = y * mAnimator.getPhaseY();
Expand Down

0 comments on commit 10f3076

Please sign in to comment.