Skip to content

Commit 922ea80

Browse files
committed
feat: setClipDataToContent
1 parent 865f9e5 commit 922ea80

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/charting/charts/BarLineChartBase.ts

+33-6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
8282

8383
protected mClipValuesToContent = false;
8484

85+
protected mClipDataToContent = false;
86+
8587
protected mDrawHighlight = true;
8688

8789
/**
@@ -209,9 +211,13 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
209211
if (rightLimitEnabled && this.mAxisRight.isDrawLimitLinesBehindDataEnabled()) this.mAxisRendererRight.renderLimitLines(canvas);
210212

211213
// make sure the data cannot be drawn outside the content-rect
212-
let clipRestoreCount = canvas.save();
213-
canvas.clipRect(this.mViewPortHandler.getContentRect());
214-
this.mRenderer.drawData(canvas);
214+
if (this.isClipDataToContentEnabled()) {
215+
canvas.save();
216+
canvas.clipRect(this.mViewPortHandler.getContentRect());
217+
this.mRenderer.drawData(canvas);
218+
} else {
219+
this.mRenderer.drawData(canvas);
220+
}
215221

216222
if (!this.mXAxis.isDrawGridLinesBehindDataEnabled()) this.mXAxisRenderer.renderGridLines(canvas);
217223

@@ -225,7 +231,9 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
225231
}
226232

227233
// Removes clipping rectangle
228-
canvas.restoreToCount(clipRestoreCount);
234+
if (this.isClipDataToContentEnabled()) {
235+
canvas.restore();
236+
}
229237

230238
this.mRenderer.drawExtras(canvas);
231239

@@ -240,12 +248,11 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
240248
this.mAxisRendererRight.renderAxisLabels(canvas);
241249

242250
if (this.isClipValuesToContentEnabled()) {
243-
clipRestoreCount = canvas.save();
251+
canvas.save();
244252
canvas.clipRect(this.mViewPortHandler.getContentRect());
245253

246254
this.mRenderer.drawValues(canvas);
247255

248-
// canvas.restoreToCount(clipRestoreCount);
249256
canvas.restore();
250257
} else {
251258
this.mRenderer.drawValues(canvas);
@@ -1207,6 +1214,26 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
12071214
return this.mClipValuesToContent;
12081215
}
12091216

1217+
/**
1218+
* When enabled, the data will be clipped to contentRect,
1219+
* otherwise they can bleed outside the content rect.
1220+
*
1221+
* @param enabled
1222+
*/
1223+
public setClipDataToContent(enabled) {
1224+
this.mClipDataToContent = enabled;
1225+
}
1226+
1227+
/**
1228+
* When enabled, the data will be clipped to contentRect,
1229+
* otherwise they can bleed outside the content rect.
1230+
*
1231+
* @return
1232+
*/
1233+
public isClipDataToContentEnabled() {
1234+
return this.mClipDataToContent;
1235+
}
1236+
12101237
public setDrawHighlight(enabled) {
12111238
this.mDrawHighlight = enabled;
12121239
}

0 commit comments

Comments
 (0)