1 package com.github.mikephil.charting.renderer.scatter; 2 3 import android.graphics.Canvas; 4 import android.graphics.Paint; 5 6 import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet; 7 import com.github.mikephil.charting.utils.ColorTemplate; 8 import com.github.mikephil.charting.utils.Utils; 9 import com.github.mikephil.charting.utils.ViewPortHandler; 10 11 /** 12 * Created by wajdic on 15/06/2016. 13 * Created at Time 09:08 14 */ 15 public class SquareShapeRenderer implements IShapeRenderer 16 { 17 18 19 @Override renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, float posX, float posY, Paint renderPaint)20 public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, 21 float posX, float posY, Paint renderPaint) { 22 23 final float shapeSize = dataSet.getScatterShapeSize(); 24 final float shapeHalf = shapeSize / 2f; 25 final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); 26 final float shapeHoleSize = shapeHoleSizeHalf * 2.f; 27 final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; 28 final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f; 29 30 final int shapeHoleColor = dataSet.getScatterShapeHoleColor(); 31 32 if (shapeSize > 0.0) { 33 renderPaint.setStyle(Paint.Style.STROKE); 34 renderPaint.setStrokeWidth(shapeStrokeSize); 35 36 c.drawRect(posX - shapeHoleSizeHalf - shapeStrokeSizeHalf, 37 posY - shapeHoleSizeHalf - shapeStrokeSizeHalf, 38 posX + shapeHoleSizeHalf + shapeStrokeSizeHalf, 39 posY + shapeHoleSizeHalf + shapeStrokeSizeHalf, 40 renderPaint); 41 42 if (shapeHoleColor != ColorTemplate.COLOR_NONE) { 43 renderPaint.setStyle(Paint.Style.FILL); 44 45 renderPaint.setColor(shapeHoleColor); 46 c.drawRect(posX - shapeHoleSizeHalf, 47 posY - shapeHoleSizeHalf, 48 posX + shapeHoleSizeHalf, 49 posY + shapeHoleSizeHalf, 50 renderPaint); 51 } 52 53 } else { 54 renderPaint.setStyle(Paint.Style.FILL); 55 56 c.drawRect(posX - shapeHalf, 57 posY - shapeHalf, 58 posX + shapeHalf, 59 posY + shapeHalf, 60 renderPaint); 61 } 62 } 63 } 64