ScatterDataSet.java
4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.charts.ScatterChart;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
import com.github.mikephil.charting.renderer.scatter.ChevronDownShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.ChevronUpShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.CircleShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.CrossShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.IShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.SquareShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.TriangleShapeRenderer;
import com.github.mikephil.charting.renderer.scatter.XShapeRenderer;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.util.ArrayList;
import java.util.List;
public class ScatterDataSet extends LineScatterCandleRadarDataSet<Entry> implements IScatterDataSet {
/**
* the size the scattershape will have, in density pixels
*/
private float mShapeSize = 15f;
/**
* Renderer responsible for rendering this DataSet, default: square
*/
protected IShapeRenderer mShapeRenderer = new SquareShapeRenderer();
/**
* The radius of the hole in the shape (applies to Square, Circle and Triangle)
* - default: 0.0
*/
private float mScatterShapeHoleRadius = 0f;
/**
* Color for the hole in the shape.
* Setting to `ColorTemplate.COLOR_NONE` will behave as transparent.
* - default: ColorTemplate.COLOR_NONE
*/
private int mScatterShapeHoleColor = ColorTemplate.COLOR_NONE;
public ScatterDataSet(List<Entry> yVals, String label) {
super(yVals, label);
}
@Override
public DataSet<Entry> copy() {
List<Entry> entries = new ArrayList<Entry>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
}
ScatterDataSet copied = new ScatterDataSet(entries, getLabel());
copy(copied);
return copied;
}
protected void copy(ScatterDataSet scatterDataSet) {
super.copy(scatterDataSet);
scatterDataSet.mShapeSize = mShapeSize;
scatterDataSet.mShapeRenderer = mShapeRenderer;
scatterDataSet.mScatterShapeHoleRadius = mScatterShapeHoleRadius;
scatterDataSet.mScatterShapeHoleColor = mScatterShapeHoleColor;
}
/**
* Sets the size in density pixels the drawn scattershape will have. This
* only applies for non custom shapes.
*
* @param size
*/
public void setScatterShapeSize(float size) {
mShapeSize = size;
}
@Override
public float getScatterShapeSize() {
return mShapeSize;
}
/**
* Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this
* renderer for the DataSet.
*
* @param shape
*/
public void setScatterShape(ScatterChart.ScatterShape shape) {
mShapeRenderer = getRendererForShape(shape);
}
/**
* Sets a new IShapeRenderer responsible for drawing this DataSet.
* This can also be used to set a custom IShapeRenderer aside from the default ones.
*
* @param shapeRenderer
*/
public void setShapeRenderer(IShapeRenderer shapeRenderer) {
mShapeRenderer = shapeRenderer;
}
@Override
public IShapeRenderer getShapeRenderer() {
return mShapeRenderer;
}
/**
* Sets the radius of the hole in the shape (applies to Square, Circle and Triangle)
* Set this to <= 0 to remove holes.
*
* @param holeRadius
*/
public void setScatterShapeHoleRadius(float holeRadius) {
mScatterShapeHoleRadius = holeRadius;
}
@Override
public float getScatterShapeHoleRadius() {
return mScatterShapeHoleRadius;
}
/**
* Sets the color for the hole in the shape.
*
* @param holeColor
*/
public void setScatterShapeHoleColor(int holeColor) {
mScatterShapeHoleColor = holeColor;
}
@Override
public int getScatterShapeHoleColor() {
return mScatterShapeHoleColor;
}
public static IShapeRenderer getRendererForShape(ScatterChart.ScatterShape shape) {
switch (shape) {
case SQUARE:
return new SquareShapeRenderer();
case CIRCLE:
return new CircleShapeRenderer();
case TRIANGLE:
return new TriangleShapeRenderer();
case CROSS:
return new CrossShapeRenderer();
case X:
return new XShapeRenderer();
case CHEVRON_UP:
return new ChevronUpShapeRenderer();
case CHEVRON_DOWN:
return new ChevronDownShapeRenderer();
}
return null;
}
}