Skip to content

Commit

Permalink
Fix scatter shape size bug
Browse files Browse the repository at this point in the history
Scatter shape sizes were not converted from dp to pixels
in the shape renderers so they were drawn at inconsistent
size on different density screens.
  • Loading branch information
Tyler Voskuilen authored and hannesa2 committed Jan 9, 2023
1 parent 5699181 commit 94d0fbe
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.renderer.scatter.IShapeRenderer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;

/**
Expand All @@ -18,7 +19,7 @@ public class CustomScatterShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeHalf = dataSet.getScatterShapeSize() / 2f;
final float shapeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeSize()) / 2f;

c.drawLine(
posX - shapeHalf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ChevronDownShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeHalf = dataSet.getScatterShapeSize() / 2f;
final float shapeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeSize()) / 2f;

renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ChevronUpShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeHalf = dataSet.getScatterShapeSize() / 2f;
final float shapeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeSize()) / 2f;

renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CircleShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeSize = dataSet.getScatterShapeSize();
final float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CrossShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeHalf = dataSet.getScatterShapeSize() / 2f;
final float shapeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeSize()) / 2f;

renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SquareShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeSize = dataSet.getScatterShapeSize();
final float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TriangleShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeSize = dataSet.getScatterShapeSize();
final float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class XShapeRenderer implements IShapeRenderer
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeHalf = dataSet.getScatterShapeSize() / 2f;
final float shapeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeSize()) / 2f;

renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
Expand Down

0 comments on commit 94d0fbe

Please sign in to comment.