forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHorizontalBarBuffer.java
More file actions
140 lines (100 loc) · 4.47 KB
/
HorizontalBarBuffer.java
File metadata and controls
140 lines (100 loc) · 4.47 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
package com.github.mikephil.charting.buffer;
import com.github.mikephil.charting.data.BarEntry;
import java.util.List;
public class HorizontalBarBuffer extends BarBuffer {
public HorizontalBarBuffer(int size, float groupspace, int dataSetCount, boolean containsStacks) {
super(size, groupspace, dataSetCount, containsStacks);
}
@Override
public void feed(List<BarEntry> entries) {
float size = entries.size() * phaseX;
int dataSetOffset = (mDataSetCount - 1);
float barSpaceHalf = mBarSpace / 2f;
float groupSpaceHalf = mGroupSpace / 2f;
float barWidth = 0.5f;
for (int i = 0; i < size; i++) {
BarEntry e = entries.get(i);
// calculate the x-position, depending on datasetcount
float x = e.getXIndex() + i * dataSetOffset + mDataSetIndex
+ mGroupSpace * i + groupSpaceHalf;
float y = e.getVal();
float[] vals = e.getVals();
if(mInverted) { // inverted axis
if (!mContainsStacks || vals == null) {
float bottom = x - barWidth + barSpaceHalf;
float top = x + barWidth - barSpaceHalf;
float left = y >= 0 ? y : 0;
float right = y <= 0 ? y : 0;
// multiply the height of the rect with the phase
if (right > 0)
right *= phaseY;
else
left *= phaseY;
addBar(left, top, right, bottom);
} else {
float allPos = e.getPositiveSum();
float allNeg = e.getNegativeSum();
// fill the stack
for (int k = 0; k < vals.length; k++) {
float value = vals[k];
if(value >= 0f) {
allPos -= value;
y = value + allPos;
} else {
allNeg -= Math.abs(value);
y = value + allNeg;
}
float bottom = x - barWidth + barSpaceHalf;
float top = x + barWidth - barSpaceHalf;
float left = y >= 0 ? y : 0;
float right = y <= 0 ? y : 0;
// multiply the height of the rect with the phase
if (right > 0)
right *= phaseY;
else
left *= phaseY;
addBar(left, top, right, bottom);
}
}
} else { // not inverted
if (!mContainsStacks || vals == null) {
float bottom = x - barWidth + barSpaceHalf;
float top = x + barWidth - barSpaceHalf;
float right = y >= 0 ? y : 0;
float left = y <= 0 ? y : 0;
// multiply the height of the rect with the phase
if (right > 0)
right *= phaseY;
else
left *= phaseY;
addBar(left, top, right, bottom);
} else {
float allPos = e.getPositiveSum();
float allNeg = e.getNegativeSum();
// fill the stack
for (int k = 0; k < vals.length; k++) {
float value = vals[k];
if(value >= 0f) {
allPos -= value;
y = value + allPos;
} else {
allNeg -= Math.abs(value);
y = value + allNeg;
}
float bottom = x - barWidth + barSpaceHalf;
float top = x + barWidth - barSpaceHalf;
float right = y >= 0 ? y : 0;
float left = y <= 0 ? y : 0;
// multiply the height of the rect with the phase
if (right > 0)
right *= phaseY;
else
left *= phaseY;
addBar(left, top, right, bottom);
}
}
}
}
reset();
}
}