Skip to content

Commit

Permalink
Merge pull request #987 from danielgindi/improvements-and-bugfixes
Browse files Browse the repository at this point in the history
Improvements and bugfixes
  • Loading branch information
PhilJay committed Sep 3, 2015
2 parents 8c5e694 + f9d8e36 commit 5a028c5
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 27 deletions.
19 changes: 16 additions & 3 deletions MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,27 @@ public void calculateOffsets() {
return;

float diameter = getDiameter();
float boxSize = diameter / 2f;
float radius = diameter / 2f;

PointF c = getCenterOffsets();

final List<PieDataSet> dataSets = mData.getDataSets();

float maxShift = 0.f;
for (int i = 0; i < dataSets.size(); i++) {
final float shift = dataSets.get(i).getSelectionShift();
if (shift > maxShift)
maxShift = shift;
}

final float halfMaxShift = maxShift / 2.f;

// create the circle box that will contain the pie-chart (the bounds of
// the pie-chart)
mCircleBox.set(c.x - boxSize, c.y - boxSize,
c.x + boxSize, c.y + boxSize);
mCircleBox.set(c.x - radius + halfMaxShift,
c.y - radius + halfMaxShift,
c.x + radius - halfMaxShift,
c.y + radius - halfMaxShift);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void calcMinMax(int start, int end) {

int endValue;

if (end == 0)
if (end == 0 || end >= mYVals.size())
endValue = mYVals.size() - 1;
else
endValue = end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void drawData(Canvas c) {

BarDataSet set = barData.getDataSetByIndex(i);

if (set.isVisible()) {
if (set.isVisible() && set.getEntryCount() > 0) {
drawDataSet(c, set, i);
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public void drawValues(Canvas c) {

BarDataSet dataSet = dataSets.get(i);

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

// apply the text-styling defined by the DataSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void drawData(Canvas c) {

for (BubbleDataSet set : bubbleData.getDataSets()) {

if (set.isVisible())
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public void drawValues(Canvas c) {

for (BubbleDataSet dataSet : dataSets) {

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

// apply the text-styling defined by the DataSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void drawData(Canvas c) {

for (CandleDataSet set : candleData.getDataSets()) {

if (set.isVisible())
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
Expand All @@ -69,11 +69,8 @@ protected void drawDataSet(Canvas c, CandleDataSet dataSet) {

List<CandleEntry> entries = dataSet.getYVals();

Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX);

int minx = Math.max(dataSet.getEntryPosition(entryFrom), 0);
int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, entries.size());
int minx = Math.max(mMinX, 0);
int maxx = Math.min(mMaxX + 1, entries.size());

int range = (maxx - minx) * 4;
int to = (int)Math.ceil((maxx - minx) * phaseX + minx);
Expand Down Expand Up @@ -233,7 +230,7 @@ public void drawValues(Canvas c) {

CandleDataSet dataSet = dataSets.get(i);

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

// apply the text-styling defined by the DataSet
Expand All @@ -243,11 +240,8 @@ public void drawValues(Canvas c) {

List<CandleEntry> entries = dataSet.getYVals();

Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
Entry entryTo = dataSet.getEntryForXIndex(mMaxX);

int minx = Math.max(dataSet.getEntryPosition(entryFrom), 0);
int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, entries.size());
int minx = Math.max(mMinX, 0);
int maxx = Math.min(mMaxX + 1, entries.size());

float[] positions = trans.generateTransformedValuesCandle(
entries, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void drawValues(Canvas c) {

BarDataSet dataSet = dataSets.get(i);

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

boolean isInverted = mChart.isInverted(dataSet.getAxisDependency());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void drawData(Canvas c) {

for (LineDataSet set : lineData.getDataSets()) {

if (set.isVisible())
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}

Expand Down Expand Up @@ -410,7 +410,7 @@ public void drawValues(Canvas c) {

LineDataSet dataSet = dataSets.get(i);

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

// apply the text-styling defined by the DataSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void drawData(Canvas c) {

for (PieDataSet set : pieData.getDataSets()) {

if (set.isVisible())
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void drawData(Canvas c) {

for (RadarDataSet set : radarData.getDataSets()) {

if (set.isVisible())
if (set.isVisible() && set.getEntryCount() > 0)
drawDataSet(c, set);
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public void drawValues(Canvas c) {

RadarDataSet dataSet = mChart.getData().getDataSetByIndex(i);

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

// apply the text-styling defined by the DataSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void drawValues(Canvas c) {

ScatterDataSet dataSet = dataSets.get(i);

if (!dataSet.isDrawValuesEnabled())
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
continue;

// apply the text-styling defined by the DataSet
Expand Down

0 comments on commit 5a028c5

Please sign in to comment.