• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.github.mikephil.charting.renderer.scatter;
2 
3 import android.graphics.Canvas;
4 import android.graphics.Paint;
5 import android.graphics.Path;
6 
7 import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
8 import com.github.mikephil.charting.utils.ColorTemplate;
9 import com.github.mikephil.charting.utils.Utils;
10 import com.github.mikephil.charting.utils.ViewPortHandler;
11 
12 /**
13  * Created by wajdic on 15/06/2016.
14  * Created at Time 09:08
15  */
16 public class TriangleShapeRenderer implements IShapeRenderer
17 {
18 
19     protected Path mTrianglePathBuffer = new Path();
20 
21     @Override
renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, float posX, float posY, Paint renderPaint)22     public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
23                             float posX, float posY, Paint renderPaint) {
24 
25         final float shapeSize = dataSet.getScatterShapeSize();
26         final float shapeHalf = shapeSize / 2f;
27         final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius());
28         final float shapeHoleSize = shapeHoleSizeHalf * 2.f;
29         final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f;
30 
31         final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
32 
33         renderPaint.setStyle(Paint.Style.FILL);
34 
35         // create a triangle path
36         Path tri = mTrianglePathBuffer;
37         tri.reset();
38 
39         tri.moveTo(posX, posY - shapeHalf);
40         tri.lineTo(posX + shapeHalf, posY + shapeHalf);
41         tri.lineTo(posX - shapeHalf, posY + shapeHalf);
42 
43         if (shapeSize > 0.0) {
44             tri.lineTo(posX, posY - shapeHalf);
45 
46             tri.moveTo(posX - shapeHalf + shapeStrokeSize,
47                     posY + shapeHalf - shapeStrokeSize);
48             tri.lineTo(posX + shapeHalf - shapeStrokeSize,
49                     posY + shapeHalf - shapeStrokeSize);
50             tri.lineTo(posX,
51                     posY - shapeHalf + shapeStrokeSize);
52             tri.lineTo(posX - shapeHalf + shapeStrokeSize,
53                     posY + shapeHalf - shapeStrokeSize);
54         }
55 
56         tri.close();
57 
58         c.drawPath(tri, renderPaint);
59         tri.reset();
60 
61         if (shapeSize > 0.0 &&
62                 shapeHoleColor != ColorTemplate.COLOR_NONE) {
63 
64             renderPaint.setColor(shapeHoleColor);
65 
66             tri.moveTo(posX,
67                     posY - shapeHalf + shapeStrokeSize);
68             tri.lineTo(posX + shapeHalf - shapeStrokeSize,
69                     posY + shapeHalf - shapeStrokeSize);
70             tri.lineTo(posX - shapeHalf + shapeStrokeSize,
71                     posY + shapeHalf - shapeStrokeSize);
72             tri.close();
73 
74             c.drawPath(tri, renderPaint);
75             tri.reset();
76         }
77 
78     }
79 
80 }