Skip to content

Commit 674cd8b

Browse files
committed
Major bugfixes, fixed issue concerning x-axis labels jumping.
1 parent a74d1d7 commit 674cd8b

17 files changed

Lines changed: 133 additions & 66 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
189189

190190
ArrayList<String> xVals = new ArrayList<String>();
191191
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
192-
xVals.add((i + 1990) + "");
192+
xVals.add((i) + "");
193193
}
194194

195195
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
4848

4949
// draw bars behind lines
5050
mChart.setDrawOrder(new DrawOrder[] {
51-
DrawOrder.BAR, DrawOrder.LINE
51+
DrawOrder.BAR, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
5252
});
5353

5454
YAxis rightAxis = mChart.getAxisRight();

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.util.AttributeSet;
77
import android.util.Log;
88

9+
import com.github.mikephil.charting.components.YAxis.AxisDependency;
910
import com.github.mikephil.charting.data.BarData;
1011
import com.github.mikephil.charting.data.BarDataSet;
1112
import com.github.mikephil.charting.data.BarEntry;
@@ -325,4 +326,44 @@ public boolean isDrawBarShadowEnabled() {
325326
public BarData getBarData() {
326327
return mData;
327328
}
329+
330+
/**
331+
* Returns the lowest x-index (value on the x-axis) that is still visible on
332+
* the chart.
333+
*
334+
* @return
335+
*/
336+
@Override
337+
public int getLowestVisibleXIndex() {
338+
339+
float step = mData.getDataSetCount();
340+
float div = (step <= 1) ? 1 : step + mData.getGroupSpace();
341+
342+
float[] pts = new float[] {
343+
mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom()
344+
};
345+
346+
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
347+
return (int) (((pts[0] <= 0) ? 0 : ((pts[0])) / div) + 1);
348+
}
349+
350+
/**
351+
* Returns the highest x-index (value on the x-axis) that is still visible
352+
* on the chart.
353+
*
354+
* @return
355+
*/
356+
@Override
357+
public int getHighestVisibleXIndex() {
358+
359+
float step = mData.getDataSetCount();
360+
float div = (step <= 1) ? 1 : step + mData.getGroupSpace();
361+
362+
float[] pts = new float[] {
363+
mViewPortHandler.contentRight(), mViewPortHandler.contentBottom()
364+
};
365+
366+
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
367+
return (int) ((pts[0] >= getXChartMax()) ? getXChartMax() / div : (pts[0] / div));
368+
}
328369
}

MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,11 @@ protected void onDraw(Canvas canvas) {
176176

177177
long starttime = System.currentTimeMillis();
178178

179-
// // if data filtering is enabled
180-
// if (mFilterData) {
181-
// mData = getFilteredData();
182-
//
183-
// Log.i(LOG_TAG, "FilterTime: " + (System.currentTimeMillis() -
184-
// starttime) + " ms");
185-
// starttime = System.currentTimeMillis();
186-
// } else {
187-
// mData = getData();
188-
// // Log.i(LOG_TAG, "Filtering disabled.");
189-
// }
190-
191179
if (mXAxis.isAdjustXLabelsEnabled())
192180
calcModulus();
181+
182+
mXAxisRenderer.calcXBounds(this, mXAxis.mAxisLabelModulus);
183+
mRenderer.calcXBounds(this, mXAxis.mAxisLabelModulus);
193184

194185
// execute all drawing commands
195186
drawGridBackground(canvas);
@@ -248,14 +239,11 @@ protected void onDraw(Canvas canvas) {
248239
mRenderer.drawValues(canvas);
249240

250241
mLegendRenderer.renderLegend(canvas);
251-
// drawLegend();
252242

253243
drawMarkers(canvas);
254244

255245
drawDescription(canvas);
256246

257-
// canvas.drawBitmap(mDrawBitmap, 0, 0, mDrawPaint);
258-
259247
if (mLogEnabled) {
260248
long drawtime = (System.currentTimeMillis() - starttime);
261249
totalTime += drawtime;
@@ -1167,6 +1155,7 @@ public BarLineScatterCandleDataSet<? extends Entry> getDataSetByTouchPoint(float
11671155
*
11681156
* @return
11691157
*/
1158+
@Override
11701159
public int getLowestVisibleXIndex() {
11711160
float[] pts = new float[] {
11721161
mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom()
@@ -1181,6 +1170,7 @@ public int getLowestVisibleXIndex() {
11811170
*
11821171
* @return
11831172
*/
1173+
@Override
11841174
public int getHighestVisibleXIndex() {
11851175
float[] pts = new float[] {
11861176
mViewPortHandler.contentRight(), mViewPortHandler.contentBottom()

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,44 @@ public Highlight getHighlightByTouchPoint(float x, float y) {
222222

223223
return getHighlight(pts[1], pts[0]);
224224
}
225+
226+
/**
227+
* Returns the lowest x-index (value on the x-axis) that is still visible on
228+
* the chart.
229+
*
230+
* @return
231+
*/
232+
@Override
233+
public int getLowestVisibleXIndex() {
234+
235+
float step = mData.getDataSetCount();
236+
float div = (step <= 1) ? 1 : step + mData.getGroupSpace();
237+
238+
float[] pts = new float[] {
239+
mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom()
240+
};
241+
242+
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
243+
return (int) (((pts[1] <= 0) ? 0 : ((pts[1])) / div) + 1);
244+
}
245+
246+
/**
247+
* Returns the highest x-index (value on the x-axis) that is still visible
248+
* on the chart.
249+
*
250+
* @return
251+
*/
252+
@Override
253+
public int getHighestVisibleXIndex() {
254+
255+
float step = mData.getDataSetCount();
256+
float div = (step <= 1) ? 1 : step + mData.getGroupSpace();
257+
258+
float[] pts = new float[] {
259+
mViewPortHandler.contentLeft(), mViewPortHandler.contentTop()
260+
};
261+
262+
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
263+
return (int) ((pts[1] >= getXChartMax()) ? getXChartMax() / div : (pts[1] / div));
264+
}
225265
}

MPChartLib/src/com/github/mikephil/charting/interfaces/BarLineScatterCandleDataProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ public interface BarLineScatterCandleDataProvider extends ChartInterface {
88
public Transformer getTransformer(AxisDependency axis);
99
public int getMaxVisibleCount();
1010
public boolean isInverted(AxisDependency axis);
11+
12+
public int getLowestVisibleXIndex();
13+
public int getHighestVisibleXIndex();
1114
}

MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public void drawData(Canvas c) {
7979
protected void drawDataSet(Canvas c, BarDataSet dataSet, int index) {
8080

8181
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
82-
calcXBounds(trans);
8382

8483
mShadowPaint.setColor(dataSet.getBarShadowColor());
8584

MPChartLib/src/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public void drawData(Canvas c) {
6262
protected void drawDataSet(Canvas c, CandleDataSet dataSet) {
6363

6464
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
65-
calcXBounds(trans);
6665

6766
float phaseX = mAnimator.getPhaseX();
6867
float phaseY = mAnimator.getPhaseY();
@@ -288,7 +287,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
288287
};
289288

290289
float[] horPts = new float[] {
291-
0, low, mChart.getXChartMax(), low, 0, high, mChart.getXChartMax(), high
290+
mChart.getXChartMin(), low, mChart.getXChartMax(), low, mChart.getXChartMin(), high, mChart.getXChartMax(), high
292291
};
293292

294293
mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(vertPts);

MPChartLib/src/com/github/mikephil/charting/renderer/CombinedChartRenderer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.github.mikephil.charting.animation.ChartAnimator;
77
import com.github.mikephil.charting.charts.CombinedChart;
88
import com.github.mikephil.charting.charts.CombinedChart.DrawOrder;
9+
import com.github.mikephil.charting.interfaces.BarLineScatterCandleDataProvider;
910
import com.github.mikephil.charting.utils.Highlight;
1011
import com.github.mikephil.charting.utils.ViewPortHandler;
1112

@@ -100,6 +101,12 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
100101
renderer.drawHighlighted(c, indices);
101102
}
102103

104+
@Override
105+
public void calcXBounds(BarLineScatterCandleDataProvider chart, int xAxisModulus) {
106+
for (DataRenderer renderer : mRenderers)
107+
renderer.calcXBounds(chart, xAxisModulus);
108+
}
109+
103110
/**
104111
* Returns the sub-renderer object at the specified index.
105112
*

MPChartLib/src/com/github/mikephil/charting/renderer/DataRenderer.java

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

1616
public abstract class DataRenderer extends Renderer {
1717

18+
/** the animator object used to perform animations on the chart data */
1819
protected ChartAnimator mAnimator;
1920

2021
/** main paint object used for rendering */
@@ -93,6 +94,11 @@ protected void applyValueTextStyle(DataSet<?> set) {
9394
mValuePaint.setTextSize(set.getValueTextSize());
9495
}
9596

97+
/**
98+
* Initializes the buffers used for rendering with a new size. Since this
99+
* method performs memory allocations, it should only be called if
100+
* necessary.
101+
*/
96102
public abstract void initBuffers();
97103

98104
public abstract void drawData(Canvas c);

0 commit comments

Comments
 (0)