Skip to content

Commit

Permalink
Add option to disable clipping data to contentRect
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 23, 2020
1 parent 7306d3f commit 4c470a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleBubbleData<

protected boolean mClipValuesToContent = false;

protected boolean mClipDataToContent = true;

/**
* Sets the minimum offset (padding) around the chart, defaults to 15
*/
Expand Down Expand Up @@ -230,9 +232,12 @@ protected void onDraw(Canvas canvas) {
if (mAxisRight.isEnabled() && mAxisRight.isDrawLimitLinesBehindDataEnabled())
mAxisRendererRight.renderLimitLines(canvas);

// make sure the data cannot be drawn outside the content-rect
int clipRestoreCount = canvas.save();
canvas.clipRect(mViewPortHandler.getContentRect());

if (isClipDataToContentEnabled()) {
// make sure the data cannot be drawn outside the content-rect
canvas.clipRect(mViewPortHandler.getContentRect());
}

mRenderer.drawData(canvas);

Expand Down Expand Up @@ -1228,6 +1233,17 @@ public void setClipValuesToContent(boolean enabled) {
mClipValuesToContent = enabled;
}

/**
* When disabled, the data and/or highlights will not be clipped to contentRect. Disabling this option can
* be useful, when the data lies fully within the content rect, but is drawn in such a way (such as thick lines)
* that there is unwanted clipping.
*
* @param enabled
*/
public void setClipDataToContent(boolean enabled) {
mClipDataToContent = enabled;
}

/**
* When enabled, the values will be clipped to contentRect,
* otherwise they can bleed outside the content rect.
Expand All @@ -1238,6 +1254,17 @@ public boolean isClipValuesToContentEnabled() {
return mClipValuesToContent;
}

/**
* When disabled, the data and/or highlights will not be clipped to contentRect. Disabling this option can
* be useful, when the data lies fully within the content rect, but is drawn in such a way (such as thick lines)
* that there is unwanted clipping.
*
* @return
*/
public boolean isClipDataToContentEnabled() {
return mClipDataToContent;
}

/**
* Sets the width of the border lines in dp.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<IPieDataSet> getDataSets() {
Log.e("MPAndroidChart",
"Found multiple data sets while pie chart only allows one");
}

return dataSets;
}

Expand Down

0 comments on commit 4c470a8

Please sign in to comment.