Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dup code corinna #5239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .idea/runConfigurations/MPChartExample.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,22 @@
import android.graphics.Canvas;
import android.graphics.Paint;

import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;

/**
* Created by wajdic on 15/06/2016.
* Created at Time 09:08
*/
public class CircleShapeRenderer implements IShapeRenderer
public class CircleShapeRenderer extends ShapeRenderer
{

@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeSize = dataSet.getScatterShapeSize();
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;

final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

if (shapeSize > 0.0) {
renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(shapeStrokeSize);

c.drawCircle(
posX,
posY,
shapeHoleSizeHalf + shapeStrokeSizeHalf,
renderPaint);

if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
renderPaint.setStyle(Paint.Style.FILL);

renderPaint.setColor(shapeHoleColor);
c.drawCircle(
posX,
posY,
shapeHoleSizeHalf,
renderPaint);
}
} else {
renderPaint.setStyle(Paint.Style.FILL);

c.drawCircle(
posX,
posY,
shapeHalf,
renderPaint);
}
protected void render(Canvas c, float shapeHoleSizeHalf, float shapeStrokeSizeHalf,
Paint renderPaint, float x, float y) {
renderHole(c, shapeHoleSizeHalf, renderPaint, x, y);
}

@Override
protected void renderHole(Canvas c, float radius, Paint renderPaint, float x, float y) {
c.drawCircle(x, y, radius, renderPaint);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.github.mikephil.charting.renderer.scatter;

import android.graphics.Canvas;
import android.graphics.Paint;

import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;

public abstract class ShapeRenderer implements IShapeRenderer {

@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, float posX, float posY, Paint renderPaint) {

final float shapeSize = dataSet.getScatterShapeSize();
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;

final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

if (shapeSize > 0.0) {
renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(shapeStrokeSize);

render(c, shapeHoleSizeHalf,shapeStrokeSizeHalf, renderPaint, posX, posY);

if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
renderPaint.setStyle(Paint.Style.FILL);

renderPaint.setColor(shapeHoleColor);
renderHole(c, shapeHoleSizeHalf, renderPaint, posX, posY);
}
} else {
renderPaint.setStyle(Paint.Style.FILL);
renderHole(c, shapeHoleSizeHalf, renderPaint, posX, posY);
}

}

protected abstract void render(Canvas c, float shapeHoleSizeHalf, float shapeStrokeSizeHalf,
Paint renderPaint, float x, float y);

protected abstract void renderHole(Canvas c, float radius, Paint renderPaint,
float x, float y);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,34 @@
import android.graphics.Canvas;
import android.graphics.Paint;

import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;

/**
* Created by wajdic on 15/06/2016.
* Created at Time 09:08
*/
public class SquareShapeRenderer implements IShapeRenderer
public class SquareShapeRenderer extends ShapeRenderer
{


@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
float posX, float posY, Paint renderPaint) {

final float shapeSize = dataSet.getScatterShapeSize();
final float shapeHalf = shapeSize / 2f;
final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f;

final int shapeHoleColor = dataSet.getScatterShapeHoleColor();

if (shapeSize > 0.0) {
renderPaint.setStyle(Paint.Style.STROKE);
renderPaint.setStrokeWidth(shapeStrokeSize);

c.drawRect(posX - shapeHoleSizeHalf - shapeStrokeSizeHalf,
posY - shapeHoleSizeHalf - shapeStrokeSizeHalf,
posX + shapeHoleSizeHalf + shapeStrokeSizeHalf,
posY + shapeHoleSizeHalf + shapeStrokeSizeHalf,
renderPaint);

if (shapeHoleColor != ColorTemplate.COLOR_NONE) {
renderPaint.setStyle(Paint.Style.FILL);

renderPaint.setColor(shapeHoleColor);
c.drawRect(posX - shapeHoleSizeHalf,
posY - shapeHoleSizeHalf,
posX + shapeHoleSizeHalf,
posY + shapeHoleSizeHalf,
renderPaint);
}
protected void render(Canvas c, float shapeHoleSizeHalf, float shapeStrokeSizeHalf, Paint renderPaint, float x, float y) {
drawRect(c, shapeHoleSizeHalf - shapeStrokeSizeHalf,
shapeHoleSizeHalf + shapeStrokeSizeHalf,
renderPaint, x, y);
}

} else {
renderPaint.setStyle(Paint.Style.FILL);
@Override
protected void renderHole(Canvas c, float radius, Paint renderPaint, float x, float y) {
drawRect(c, radius, radius, renderPaint, x, y);
}

c.drawRect(posX - shapeHalf,
posY - shapeHalf,
posX + shapeHalf,
posY + shapeHalf,
renderPaint);
}
private void drawRect(Canvas c, float offsetTopLeft, float offsetBottomRight,
Paint renderPaint, float x, float y){
c.drawRect(
x-offsetTopLeft,
y-offsetTopLeft,
x+offsetBottomRight,
y+offsetBottomRight,
renderPaint
);
}
}