Skip to content

Commit 8045d64

Browse files
committed
Added clipValuesToContent property for clipping values
1 parent 6a5580b commit 8045d64

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<
9797

9898
protected boolean mDrawBorders = false;
9999

100+
protected boolean mClipValuesToContent = false;
101+
100102
/**
101103
* Sets the minimum offset (padding) around the chart, defaults to 15
102104
*/
@@ -248,7 +250,16 @@ protected void onDraw(Canvas canvas) {
248250
mAxisRendererLeft.renderAxisLabels(canvas);
249251
mAxisRendererRight.renderAxisLabels(canvas);
250252

251-
mRenderer.drawValues(canvas);
253+
if (isClipValuesToContentEnabled()) {
254+
clipRestoreCount = canvas.save();
255+
canvas.clipRect(mViewPortHandler.getContentRect());
256+
257+
mRenderer.drawValues(canvas);
258+
259+
canvas.restoreToCount(clipRestoreCount);
260+
} else {
261+
mRenderer.drawValues(canvas);
262+
}
252263

253264
mLegendRenderer.renderLegend(canvas);
254265

@@ -1151,6 +1162,26 @@ public void setDrawBorders(boolean enabled) {
11511162
mDrawBorders = enabled;
11521163
}
11531164

1165+
/**
1166+
* When enabled, the values will be clipped to contentRect,
1167+
* otherwise they can bleed outside the content rect.
1168+
*
1169+
* @param enabled
1170+
*/
1171+
public void setClipValuesToContent(boolean enabled) {
1172+
mClipValuesToContent = enabled;
1173+
}
1174+
1175+
/**
1176+
* When enabled, the values will be clipped to contentRect,
1177+
* otherwise they can bleed outside the content rect.
1178+
*
1179+
* @return
1180+
*/
1181+
public boolean isClipValuesToContentEnabled() {
1182+
return mClipValuesToContent;
1183+
}
1184+
11541185
/**
11551186
* Sets the width of the border lines in dp.
11561187
*

0 commit comments

Comments
 (0)