Skip to content

Commit 5a028c5

Browse files
committed
Merge pull request #987 from danielgindi/improvements-and-bugfixes
Improvements and bugfixes
2 parents 8c5e694 + f9d8e36 commit 5a028c5

File tree

10 files changed

+34
-27
lines changed

10 files changed

+34
-27
lines changed

MPChartLib/src/com/github/mikephil/charting/charts/PieChart.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,27 @@ public void calculateOffsets() {
125125
return;
126126

127127
float diameter = getDiameter();
128-
float boxSize = diameter / 2f;
128+
float radius = diameter / 2f;
129129

130130
PointF c = getCenterOffsets();
131131

132+
final List<PieDataSet> dataSets = mData.getDataSets();
133+
134+
float maxShift = 0.f;
135+
for (int i = 0; i < dataSets.size(); i++) {
136+
final float shift = dataSets.get(i).getSelectionShift();
137+
if (shift > maxShift)
138+
maxShift = shift;
139+
}
140+
141+
final float halfMaxShift = maxShift / 2.f;
142+
132143
// create the circle box that will contain the pie-chart (the bounds of
133144
// the pie-chart)
134-
mCircleBox.set(c.x - boxSize, c.y - boxSize,
135-
c.x + boxSize, c.y + boxSize);
145+
mCircleBox.set(c.x - radius + halfMaxShift,
146+
c.y - radius + halfMaxShift,
147+
c.x + radius - halfMaxShift,
148+
c.y + radius - halfMaxShift);
136149
}
137150

138151
@Override

MPChartLib/src/com/github/mikephil/charting/data/CandleDataSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected void calcMinMax(int start, int end) {
7979

8080
int endValue;
8181

82-
if (end == 0)
82+
if (end == 0 || end >= mYVals.size())
8383
endValue = mYVals.size() - 1;
8484
else
8585
endValue = end;

MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void drawData(Canvas c) {
7171

7272
BarDataSet set = barData.getDataSetByIndex(i);
7373

74-
if (set.isVisible()) {
74+
if (set.isVisible() && set.getEntryCount() > 0) {
7575
drawDataSet(c, set, i);
7676
}
7777
}
@@ -187,7 +187,7 @@ public void drawValues(Canvas c) {
187187

188188
BarDataSet dataSet = dataSets.get(i);
189189

190-
if (!dataSet.isDrawValuesEnabled())
190+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
191191
continue;
192192

193193
// apply the text-styling defined by the DataSet

MPChartLib/src/com/github/mikephil/charting/renderer/BubbleChartRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void drawData(Canvas c) {
4949

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

52-
if (set.isVisible())
52+
if (set.isVisible() && set.getEntryCount() > 0)
5353
drawDataSet(c, set);
5454
}
5555
}
@@ -133,7 +133,7 @@ public void drawValues(Canvas c) {
133133

134134
for (BubbleDataSet dataSet : dataSets) {
135135

136-
if (!dataSet.isDrawValuesEnabled())
136+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
137137
continue;
138138

139139
// apply the text-styling defined by the DataSet

MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void drawData(Canvas c) {
5353

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

56-
if (set.isVisible())
56+
if (set.isVisible() && set.getEntryCount() > 0)
5757
drawDataSet(c, set);
5858
}
5959
}
@@ -69,11 +69,8 @@ protected void drawDataSet(Canvas c, CandleDataSet dataSet) {
6969

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

72-
Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
73-
Entry entryTo = dataSet.getEntryForXIndex(mMaxX);
74-
75-
int minx = Math.max(dataSet.getEntryPosition(entryFrom), 0);
76-
int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, entries.size());
72+
int minx = Math.max(mMinX, 0);
73+
int maxx = Math.min(mMaxX + 1, entries.size());
7774

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

234231
CandleDataSet dataSet = dataSets.get(i);
235232

236-
if (!dataSet.isDrawValuesEnabled())
233+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
237234
continue;
238235

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

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

246-
Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
247-
Entry entryTo = dataSet.getEntryForXIndex(mMaxX);
248-
249-
int minx = Math.max(dataSet.getEntryPosition(entryFrom), 0);
250-
int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, entries.size());
243+
int minx = Math.max(mMinX, 0);
244+
int maxx = Math.min(mMaxX + 1, entries.size());
251245

252246
float[] positions = trans.generateTransformedValuesCandle(
253247
entries, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx);

MPChartLib/src/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void drawValues(Canvas c) {
107107

108108
BarDataSet dataSet = dataSets.get(i);
109109

110-
if (!dataSet.isDrawValuesEnabled())
110+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
111111
continue;
112112

113113
boolean isInverted = mChart.isInverted(dataSet.getAxisDependency());

MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void drawData(Canvas c) {
9494

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

97-
if (set.isVisible())
97+
if (set.isVisible() && set.getEntryCount() > 0)
9898
drawDataSet(c, set);
9999
}
100100

@@ -410,7 +410,7 @@ public void drawValues(Canvas c) {
410410

411411
LineDataSet dataSet = dataSets.get(i);
412412

413-
if (!dataSet.isDrawValuesEnabled())
413+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
414414
continue;
415415

416416
// apply the text-styling defined by the DataSet

MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void drawData(Canvas c) {
117117

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

120-
if (set.isVisible())
120+
if (set.isVisible() && set.getEntryCount() > 0)
121121
drawDataSet(c, set);
122122
}
123123
}

MPChartLib/src/com/github/mikephil/charting/renderer/RadarChartRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void drawData(Canvas c) {
5656

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

59-
if (set.isVisible())
59+
if (set.isVisible() && set.getEntryCount() > 0)
6060
drawDataSet(c, set);
6161
}
6262
}
@@ -131,7 +131,7 @@ public void drawValues(Canvas c) {
131131

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

134-
if (!dataSet.isDrawValuesEnabled())
134+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
135135
continue;
136136

137137
// apply the text-styling defined by the DataSet

MPChartLib/src/com/github/mikephil/charting/renderer/ScatterChartRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void drawValues(Canvas c) {
209209

210210
ScatterDataSet dataSet = dataSets.get(i);
211211

212-
if (!dataSet.isDrawValuesEnabled())
212+
if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0)
213213
continue;
214214

215215
// apply the text-styling defined by the DataSet

0 commit comments

Comments
 (0)