Skip to content

Commit 34e7f44

Browse files
committed
drawBottomYLabelEntryEnabled
1 parent 8abe7e8 commit 34e7f44

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/components/YAxis.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*/
1919
public class YAxis extends AxisBase {
2020

21+
/**
22+
* indicates if the bottom y-label entry is drawn or not
23+
*/
24+
private boolean mDrawBottomYLabelEntry = true;
25+
2126
/**
2227
* indicates if the top y-label entry is drawn or not
2328
*/
@@ -168,6 +173,15 @@ public boolean isDrawTopYLabelEntryEnabled() {
168173
return mDrawTopYLabelEntry;
169174
}
170175

176+
/**
177+
* returns true if drawing the bottom y-axis label entry is enabled
178+
*
179+
* @return
180+
*/
181+
public boolean isDrawBottomYLabelEntryEnabled() {
182+
return mDrawBottomYLabelEntry;
183+
}
184+
171185
/**
172186
* set this to true to enable drawing the top y-label entry. Disabling this can be helpful
173187
* when the top y-label and

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ public void renderAxisLine(Canvas c) {
114114
*/
115115
protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) {
116116

117+
final int from = mYAxis.isDrawBottomYLabelEntryEnabled() ? 0 : 1;
118+
final int to = mYAxis.isDrawTopYLabelEntryEnabled()
119+
? mYAxis.mEntryCount
120+
: (mYAxis.mEntryCount - 1);
121+
117122
// draw
118-
for (int i = 0; i < mYAxis.mEntryCount; i++) {
123+
for (int i = from; i < to; i++) {
119124

120125
String text = mYAxis.getFormattedLabel(i);
121126

122-
if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1)
123-
return;
124-
125127
c.drawText(text, fixedPosition, positions[i * 2 + 1] + offset, mAxisLabelPaint);
126128
}
127129
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, flo
137137
mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
138138
mAxisLabelPaint.setColor(mYAxis.getTextColor());
139139

140-
for (int i = 0; i < mYAxis.mEntryCount; i++) {
140+
final int from = mYAxis.isDrawBottomYLabelEntryEnabled() ? 0 : 1;
141+
final int to = mYAxis.isDrawTopYLabelEntryEnabled()
142+
? mYAxis.mEntryCount
143+
: (mYAxis.mEntryCount - 1);
141144

142-
String text = mYAxis.getFormattedLabel(i);
145+
for (int i = from; i < to; i++) {
143146

144-
if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1)
145-
return;
147+
String text = mYAxis.getFormattedLabel(i);
146148

147149
c.drawText(text, positions[i * 2], fixedPosition - offset, mAxisLabelPaint);
148150
}

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererRadarChart.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public void renderAxisLabels(Canvas c) {
156156
MPPointF pOut = MPPointF.getInstance(0,0);
157157
float factor = mChart.getFactor();
158158

159-
int labelCount = mYAxis.mEntryCount;
159+
final int from = mYAxis.isDrawBottomYLabelEntryEnabled() ? 0 : 1;
160+
final int to = mYAxis.isDrawTopYLabelEntryEnabled()
161+
? mYAxis.mEntryCount
162+
: (mYAxis.mEntryCount - 1);
160163

161-
for (int j = 0; j < labelCount; j++) {
162-
163-
if (j == labelCount - 1 && mYAxis.isDrawTopYLabelEntryEnabled() == false)
164-
break;
164+
for (int j = from; j < to; j++) {
165165

166166
float r = (mYAxis.mEntries[j] - mYAxis.mAxisMinimum) * factor;
167167

0 commit comments

Comments
 (0)