GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add half line width to clipping rect of grid/limit lines (Closes #2081) · FlyingAndroid/MPAndroidChart@7747c34

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • MPChartLib/src/main/java/com/github/mikephil/charting
    • charts
      • BarLineChartBase.java
    • renderer
      • XAxisRenderer.java
      • XAxisRendererHorizontalBarChart.java
      • YAxisRenderer.java
      • YAxisRendererHorizontalBarChart.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java
+5-11Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ protected void onDraw(Canvas canvas) {
222222
}
223223
}
224224

225-
// make sure the graph values and grid cannot be drawn outside the
226-
// content-rect
227-
int clipRestoreCount = canvas.save();
228-
canvas.clipRect(mViewPortHandler.getContentRect());
229-
230225
mXAxisRenderer.renderGridLines(canvas);
231226
mAxisRendererLeft.renderGridLines(canvas);
232227
mAxisRendererRight.renderGridLines(canvas);
@@ -240,6 +235,10 @@ protected void onDraw(Canvas canvas) {
240235
if (mAxisRight.isDrawLimitLinesBehindDataEnabled())
241236
mAxisRendererRight.renderLimitLines(canvas);
242237

238+
// make sure the data cannot be drawn outside the content-rect
239+
int clipRestoreCount = canvas.save();
240+
canvas.clipRect(mViewPortHandler.getContentRect());
241+
243242
mRenderer.drawData(canvas);
244243

245244
// if highlighting is enabled
@@ -251,9 +250,6 @@ protected void onDraw(Canvas canvas) {
251250

252251
mRenderer.drawExtras(canvas);
253252

254-
clipRestoreCount = canvas.save();
255-
canvas.clipRect(mViewPortHandler.getContentRect());
256-
257253
if (!mXAxis.isDrawLimitLinesBehindDataEnabled())
258254
mXAxisRenderer.renderLimitLines(canvas);
259255

@@ -262,9 +258,7 @@ protected void onDraw(Canvas canvas) {
262258

263259
if (!mAxisRight.isDrawLimitLinesBehindDataEnabled())
264260
mAxisRendererRight.renderLimitLines(canvas);
265-
266-
canvas.restoreToCount(clipRestoreCount);
267-
261+
268262
mXAxisRenderer.renderAxisLabels(canvas);
269263
mAxisRendererLeft.renderAxisLabels(canvas);
270264
mAxisRendererRight.renderAxisLabels(canvas);
Collapse file

‎MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java‎

Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.graphics.Paint;
77
import android.graphics.Paint.Align;
88
import android.graphics.Path;
9+
import android.graphics.RectF;
910

1011
import com.github.mikephil.charting.components.LimitLine;
1112
import com.github.mikephil.charting.components.XAxis;
@@ -236,6 +237,9 @@ public void renderGridLines(Canvas c) {
236237
if (!mXAxis.isDrawGridLinesEnabled() || !mXAxis.isEnabled())
237238
return;
238239

240+
int clipRestoreCount = c.save();
241+
c.clipRect(getGridClippingRect());
242+
239243
if(mRenderGridLinesBuffer.length != mAxis.mEntryCount * 2){
240244
mRenderGridLinesBuffer = new float[mXAxis.mEntryCount * 2];
241245
}
@@ -257,6 +261,16 @@ public void renderGridLines(Canvas c) {
257261

258262
drawGridLine(c, positions[i], positions[i + 1], gridLinePath);
259263
}
264+
265+
c.restoreToCount(clipRestoreCount);
266+
}
267+
268+
protected RectF mGridClippingRect = new RectF();
269+
270+
public RectF getGridClippingRect() {
271+
mGridClippingRect.set(mViewPortHandler.getContentRect());
272+
mGridClippingRect.inset(-mAxis.getGridLineWidth() / 2.f, 0.f);
273+
return mGridClippingRect;
260274
}
261275

262276
/**
@@ -279,6 +293,8 @@ protected void drawGridLine(Canvas c, float x, float y, Path gridLinePath) {
279293
}
280294

281295
protected float[] mRenderLimitLinesBuffer = new float[2];
296+
protected RectF mLimitLineClippingRect = new RectF();
297+
282298
/**
283299
* Draws the LimitLines associated with this axis to the screen.
284300
*
@@ -303,13 +319,20 @@ public void renderLimitLines(Canvas c) {
303319
if (!l.isEnabled())
304320
continue;
305321

322+
int clipRestoreCount = c.save();
323+
mLimitLineClippingRect.set(mViewPortHandler.getContentRect());
324+
mLimitLineClippingRect.inset(-l.getLineWidth() / 2.f, 0.f);
325+
c.clipRect(mLimitLineClippingRect);
326+
306327
position[0] = l.getLimit();
307328
position[1] = 0.f;
308329

309330
mTrans.pointValuesToPixel(position);
310331

311332
renderLimitLineLine(c, l, position);
312333
renderLimitLineLabel(c, l, position, 2.f + l.getYOffset());
334+
335+
c.restoreToCount(clipRestoreCount);
313336
}
314337
}
315338

Collapse file

‎MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java‎

Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Paint;
66
import android.graphics.Paint.Align;
77
import android.graphics.Path;
8+
import android.graphics.RectF;
89

910
import com.github.mikephil.charting.charts.BarChart;
1011
import com.github.mikephil.charting.components.LimitLine;
@@ -161,6 +162,13 @@ protected void drawLabels(Canvas c, float pos, MPPointF anchor) {
161162
}
162163
}
163164

165+
@Override
166+
public RectF getGridClippingRect() {
167+
mGridClippingRect.set(mViewPortHandler.getContentRect());
168+
mGridClippingRect.inset(0.f, -mAxis.getGridLineWidth() / 2.f);
169+
return mGridClippingRect;
170+
}
171+
164172
@Override
165173
protected void drawGridLine(Canvas c, float x, float y, Path gridLinePath) {
166174

@@ -228,6 +236,11 @@ public void renderLimitLines(Canvas c) {
228236
if(!l.isEnabled())
229237
continue;
230238

239+
int clipRestoreCount = c.save();
240+
mLimitLineClippingRect.set(mViewPortHandler.getContentRect());
241+
mLimitLineClippingRect.inset(0.f, -l.getLineWidth() / 2.f);
242+
c.clipRect(mLimitLineClippingRect);
243+
231244
mLimitLinePaint.setStyle(Paint.Style.STROKE);
232245
mLimitLinePaint.setColor(l.getLineColor());
233246
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
@@ -290,6 +303,8 @@ public void renderLimitLines(Canvas c) {
290303
pts[1] + yOffset, mLimitLinePaint);
291304
}
292305
}
306+
307+
c.restoreToCount(clipRestoreCount);
293308
}
294309
}
295310
}
Collapse file

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

Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRenderer.java
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Paint;
66
import android.graphics.Paint.Align;
77
import android.graphics.Path;
8+
import android.graphics.RectF;
89

910
import com.github.mikephil.charting.components.LimitLine;
1011
import com.github.mikephil.charting.components.YAxis;
@@ -134,6 +135,9 @@ public void renderGridLines(Canvas c) {
134135

135136
if (mYAxis.isDrawGridLinesEnabled()) {
136137

138+
int clipRestoreCount = c.save();
139+
c.clipRect(getGridClippingRect());
140+
137141
float[] positions = getTransformedPositions();
138142

139143
mGridPaint.setColor(mYAxis.getGridColor());
@@ -150,13 +154,23 @@ public void renderGridLines(Canvas c) {
150154
c.drawPath(linePath(gridLinePath, i, positions), mGridPaint);
151155
gridLinePath.reset();
152156
}
157+
158+
c.restoreToCount(clipRestoreCount);
153159
}
154160

155161
if (mYAxis.isDrawZeroLineEnabled()) {
156162
drawZeroLine(c);
157163
}
158164
}
159165

166+
protected RectF mGridClippingRect = new RectF();
167+
168+
public RectF getGridClippingRect() {
169+
mGridClippingRect.set(mViewPortHandler.getContentRect());
170+
mGridClippingRect.inset(0.f, -mAxis.getGridLineWidth() / 2.f);
171+
return mGridClippingRect;
172+
}
173+
160174
/**
161175
* Calculates the path for a grid line.
162176
*
@@ -220,6 +234,7 @@ protected void drawZeroLine(Canvas c) {
220234

221235
protected Path mRenderLimitLines = new Path();
222236
protected float[] mRenderLimitLinesBuffer = new float[2];
237+
protected RectF mLimitLineClippingRect = new RectF();
223238
/**
224239
* Draws the LimitLines associated with this axis to the screen.
225240
*
@@ -246,6 +261,11 @@ public void renderLimitLines(Canvas c) {
246261
if (!l.isEnabled())
247262
continue;
248263

264+
int clipRestoreCount = c.save();
265+
mLimitLineClippingRect.set(mViewPortHandler.getContentRect());
266+
mLimitLineClippingRect.inset(0.f, -l.getLineWidth() / 2.f);
267+
c.clipRect(mLimitLineClippingRect);
268+
249269
mLimitLinePaint.setStyle(Paint.Style.STROKE);
250270
mLimitLinePaint.setColor(l.getLineColor());
251271
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
@@ -309,6 +329,8 @@ public void renderLimitLines(Canvas c) {
309329
pts[1] + yOffset, mLimitLinePaint);
310330
}
311331
}
332+
333+
c.restoreToCount(clipRestoreCount);
312334
}
313335
}
314336
}
Collapse file

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

Copy file name to clipboardExpand all lines: MPChartLib/src/main/java/com/github/mikephil/charting/renderer/YAxisRendererHorizontalBarChart.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Paint;
66
import android.graphics.Paint.Align;
77
import android.graphics.Path;
8+
import android.graphics.RectF;
89

910
import com.github.mikephil.charting.components.LimitLine;
1011
import com.github.mikephil.charting.components.YAxis;
@@ -164,6 +165,13 @@ protected float[] getTransformedPositions() {
164165
return positions;
165166
}
166167

168+
@Override
169+
public RectF getGridClippingRect() {
170+
mGridClippingRect.set(mViewPortHandler.getContentRect());
171+
mGridClippingRect.inset(-mAxis.getGridLineWidth() / 2.f, 0.f);
172+
return mGridClippingRect;
173+
}
174+
167175
@Override
168176
protected Path linePath(Path p, int i, float[] positions) {
169177

@@ -225,6 +233,11 @@ public void renderLimitLines(Canvas c) {
225233
if (!l.isEnabled())
226234
continue;
227235

236+
int clipRestoreCount = c.save();
237+
mLimitLineClippingRect.set(mViewPortHandler.getContentRect());
238+
mLimitLineClippingRect.inset(-l.getLineWidth() / 2.f, 0.f);
239+
c.clipRect(mLimitLineClippingRect);
240+
228241
pts[0] = l.getLimit();
229242
pts[2] = l.getLimit();
230243

@@ -281,6 +294,8 @@ public void renderLimitLines(Canvas c) {
281294
c.drawText(label, pts[0] - xOffset, mViewPortHandler.contentBottom() - yOffset, mLimitLinePaint);
282295
}
283296
}
297+
298+
c.restoreToCount(clipRestoreCount);
284299
}
285300
}
286301
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.