forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleDataSet.java
More file actions
156 lines (115 loc) · 3.53 KB
/
BubbleDataSet.java
File metadata and controls
156 lines (115 loc) · 3.53 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
package com.github.mikephil.charting.data;
import android.graphics.Color;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class BubbleDataSet extends BarLineScatterCandleDataSet<BubbleEntry> {
// NOTE: Do not initialize these, as the calcMinMax is called by the super,
// and the initializers are called after that and can reset the values
protected float mXMax;
protected float mXMin;
protected float mMaxSize;
private float mHighlightCircleWidth = 2.5f;
public BubbleDataSet(List<BubbleEntry> yVals, String label) {
super(yVals, label);
}
/**
* Sets the width of the circle that surrounds the bubble when highlighted,
* in dp.
*
* @param width
*/
public void setHighlightCircleWidth(float width) {
mHighlightCircleWidth = Utils.convertDpToPixel(width);
}
public float getHighlightCircleWidth() {
return mHighlightCircleWidth;
}
/**
* Sets a color with a specific alpha value.
* @param color
* @param alpha from 0-255
*/
public void setColor(int color, int alpha) {
super.setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}
@Override
protected void calcMinMax(int start, int end) {
if (mYVals.size() == 0)
return;
final List<BubbleEntry> entries = getYVals();
int endValue;
if (end == 0)
endValue = mYVals.size() - 1;
else
endValue = end;
mLastStart = start;
mLastEnd = endValue;
mYMin = yMin(entries.get(start));
mYMax = yMax(entries.get(start));
// need chart width to guess this properly
for (int i = start; i <= endValue; i++) {
final BubbleEntry entry = entries.get(i);
final float ymin = yMin(entry);
final float ymax = yMax(entry);
if (ymin < mYMin)
{
mYMin = ymin;
}
if (ymax > mYMax)
{
mYMax = ymax;
}
final float xmin = xMin(entry);
final float xmax = xMax(entry);
if (xmin < mXMin)
{
mXMin = xmin;
}
if (xmax > mXMax)
{
mXMax = xmax;
}
final float size = largestSize(entry);
if (size > mMaxSize)
{
mMaxSize = size;
}
}
}
@Override
public DataSet<BubbleEntry> copy() {
List<BubbleEntry> yVals = new ArrayList<BubbleEntry>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(mYVals.get(i).copy());
}
BubbleDataSet copied = new BubbleDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mHighLightColor = mHighLightColor;
return copied;
}
public float getXMax() {
return mXMax;
}
public float getXMin() {
return mXMin;
}
public float getMaxSize() {
return mMaxSize;
}
private float yMin(BubbleEntry entry) {
return entry.getVal();
}
private float yMax(BubbleEntry entry) {
return entry.getVal();
}
private float xMin(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float xMax(BubbleEntry entry) {
return (float) entry.getXIndex();
}
private float largestSize(BubbleEntry entry) {
return entry.getSize();
}
}