Skip to content

Commit e2ccaf3

Browse files
committed
Remove barspace from BarDataSet
1 parent 1bf2948 commit e2ccaf3

14 files changed

Lines changed: 21 additions & 99 deletions

File tree

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ private void setData(int count) {
229229
mChart.notifyDataSetChanged();
230230
} else {
231231
set = new BarDataSet(entries, "Sinus Function");
232-
set.setBarSpace(40f);
233232
set.setColor(Color.rgb(240, 120, 124));
234233
}
235234

236235
BarData data = new BarData(xVals, set);
237236
data.setValueTextSize(10f);
238237
data.setValueTypeface(mTf);
239238
data.setDrawValues(false);
239+
data.setBarWidth(0.8f);
240240

241241
mChart.setData(data);
242242
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ private void setData(List<Data> dataList) {
119119
mChart.notifyDataSetChanged();
120120
} else {
121121
set = new BarDataSet(values, "Values");
122-
set.setBarSpace(40f);
123122
set.setColors(colors);
124123
set.setValueTextColors(colors);
125124

126125
BarData data = new BarData(dates, set);
127126
data.setValueTextSize(13f);
128127
data.setValueTypeface(mTf);
129128
data.setValueFormatter(new ValueFormatter());
129+
data.setBarWidth(0.8f);
130130

131131
mChart.setData(data);
132132
mChart.invalidate();

MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ private BarData generateData(int cnt) {
135135
entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
136136
}
137137

138-
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
139-
d.setBarSpace(20f);
138+
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
140139
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
141140
d.setBarShadowColor(Color.rgb(203, 203, 203));
142141

143142
ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
144143
sets.add(d);
145144

146145
BarData cd = new BarData(getMonths(), sets);
146+
cd.setBarWidth(0.9f);
147147
return cd;
148148
}
149149
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ private BarData generateDataBar(int cnt) {
143143
}
144144

145145
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
146-
d.setBarSpace(20f);
147146
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
148147
d.setHighLightAlpha(255);
149148

150149
BarData cd = new BarData(getMonths(), d);
150+
cd.setBarWidth(0.9f);
151151
return cd;
152152
}
153153

MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ protected void onCreate(Bundle savedInstanceState) {
9696
set.setValueFormatter(new CustomFormatter());
9797
set.setValueTextSize(7f);
9898
set.setAxisDependency(YAxis.AxisDependency.RIGHT);
99-
set.setBarSpace(40f);
10099
set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)});
101100
set.setStackLabels(new String[]{
102101
"Men", "Women"
@@ -110,6 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
110109
}
111110

112111
BarData data = new BarData(xVals, set);
112+
data.setBarWidth(0.8f);
113113
mChart.setData(data);
114114
mChart.invalidate();
115115
}

MPChartLib/src/main/java/com/github/mikephil/charting/buffer/BarBuffer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
public class BarBuffer extends AbstractBuffer<IBarDataSet> {
88

9-
protected float mBarSpace = 0f;
109
protected float mGroupSpace = 0f;
1110
protected int mDataSetIndex = 0;
1211
protected int mDataSetCount = 1;
@@ -27,10 +26,6 @@ public void setBarWidth(float barWidth) {
2726
this.mBarWidth = barWidth;
2827
}
2928

30-
public void setBarSpace(float barspace) {
31-
this.mBarSpace = barspace;
32-
}
33-
3429
public void setDataSet(int index) {
3530
this.mDataSetIndex = index;
3631
}

MPChartLib/src/main/java/com/github/mikephil/charting/buffer/HorizontalBarBuffer.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,23 @@ public HorizontalBarBuffer(int size, float groupspace, int dataSetCount, boolean
1414
public void feed(IBarDataSet data) {
1515

1616
float size = data.getEntryCount() * phaseX;
17-
18-
int dataSetOffset = (mDataSetCount - 1);
19-
float barSpaceHalf = mBarSpace / 2f;
20-
float groupSpaceHalf = mGroupSpace / 2f;
21-
float barWidth = 0.5f;
17+
float barWidthHalf = mBarWidth / 2f;
2218

2319
for (int i = 0; i < size; i++) {
2420

2521
BarEntry e = data.getEntryForIndex(i);
2622

27-
// calculate the xPx-position, depending on datasetcount
28-
float x = e.getX() + e.getX() * dataSetOffset + mDataSetIndex
29-
+ mGroupSpace * e.getX() + groupSpaceHalf;
23+
if(e == null)
24+
continue;
25+
26+
float x = e.getX();
3027
float y = e.getY();
3128
float[] vals = e.getYVals();
3229

3330
if (!mContainsStacks || vals == null) {
3431

35-
float bottom = x - barWidth + barSpaceHalf;
36-
float top = x + barWidth - barSpaceHalf;
32+
float top = x - barWidthHalf;
33+
float bottom = x + barWidthHalf;
3734
float left, right;
3835
if (mInverted) {
3936
left = y >= 0 ? y : 0;
@@ -72,8 +69,8 @@ public void feed(IBarDataSet data) {
7269
negY += Math.abs(value);
7370
}
7471

75-
float bottom = x - barWidth + barSpaceHalf;
76-
float top = x + barWidth - barSpaceHalf;
72+
float top = x - barWidthHalf;
73+
float bottom = x + barWidthHalf;
7774
float left, right;
7875
if (mInverted) {
7976
left = y >= yStart ? y : yStart;

MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarChart.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ public RectF getBarBounds(BarEntry e) {
106106
if (set == null)
107107
return null;
108108

109-
float barspace = set.getBarSpace();
110109
float y = e.getY();
111110
float x = e.getX();
112111

113-
float barWidth = 0.5f;
112+
float barWidth = mData.getBarWidth();
114113

115-
float spaceHalf = barspace / 2f;
116-
float left = x - barWidth + spaceHalf;
117-
float right = x + barWidth - spaceHalf;
114+
float left = x - barWidth / 2f;
115+
float right = x + barWidth / 2f;
118116
float top = y >= 0 ? y : 0;
119117
float bottom = y <= 0 ? y : 0;
120118

MPChartLib/src/main/java/com/github/mikephil/charting/charts/HorizontalBarChart.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,13 @@ public RectF getBarBounds(BarEntry e) {
152152
if (set == null)
153153
return null;
154154

155-
float barspace = set.getBarSpace();
156155
float y = e.getY();
157156
float x = e.getX();
158157

159-
float spaceHalf = barspace / 2f;
158+
float barWidth = mData.getBarWidth();
160159

161-
float top = x - 0.5f + spaceHalf;
162-
float bottom = x + 0.5f - spaceHalf;
160+
float top = x - barWidth / 2f;
161+
float bottom = x + barWidth / 2f;
163162
float left = y >= 0 ? y : 0;
164163
float right = y <= 0 ? y : 0;
165164

MPChartLib/src/main/java/com/github/mikephil/charting/data/BarDataSet.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
public class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> implements IBarDataSet {
1212

13-
/**
14-
* space indicator between the bars 0.1f == 10 %
15-
*/
16-
private float mBarSpace = 0.15f;
17-
1813
/**
1914
* the maximum number of bars that are stacked upon each other, this yValue
2015
* is calculated from the Entries that are added to the DataSet
@@ -68,7 +63,6 @@ public DataSet<BarEntry> copy() {
6863
BarDataSet copied = new BarDataSet(yVals, getLabel());
6964
copied.mColors = mColors;
7065
copied.mStackSize = mStackSize;
71-
copied.mBarSpace = mBarSpace;
7266
copied.mBarShadowColor = mBarShadowColor;
7367
copied.mStackLabels = mStackLabels;
7468
copied.mHighLightColor = mHighLightColor;
@@ -185,30 +179,6 @@ public int getEntryCountStacks() {
185179
return mEntryCountStacks;
186180
}
187181

188-
/**
189-
* returns the space between bars in percent of the whole width of one yValue
190-
*
191-
* @return
192-
*/
193-
public float getBarSpacePercent() {
194-
return mBarSpace * 100f;
195-
}
196-
197-
@Override
198-
public float getBarSpace() {
199-
return mBarSpace;
200-
}
201-
202-
/**
203-
* Sets the space between the bars in values (not pixels).
204-
* Default 0.15f
205-
*
206-
* @param barSpace
207-
*/
208-
public void setBarSpace(float barSpace) {
209-
mBarSpace = barSpace;
210-
}
211-
212182
/**
213183
* Sets the color used for drawing the bar-shadows. The bar shadows is a
214184
* surface behind the bar that indicates the maximum yValue. Don't for get to

0 commit comments

Comments
 (0)