Added methods for getting highest and lowest visible x-index.

This commit is contained in:
Philipp Jahoda 2015-03-19 21:37:19 +01:00
parent 4bd9efc1e9
commit 304415a84c
4 changed files with 30 additions and 1 deletions

View file

@ -378,6 +378,7 @@ public class LineChartActivity1 extends DemoBase implements OnSeekBarChangeListe
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
Log.i("Entry selected", e.toString());
Log.i("", "low: " + mChart.getLowestVisibleXIndex() + ", high: " + mChart.getHighestVisibleXIndex());
}
@Override

View file

@ -190,7 +190,7 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleData<? exte
mAxisRendererLeft.computeAxis(mAxisLeft.mAxisMinimum, mAxisLeft.mAxisMaximum);
if (mAxisRight.isEnabled())
mAxisRendererRight.computeAxis(mAxisRight.mAxisMinimum, mAxisRight.mAxisMaximum);
mXAxisRenderer.renderAxisLine(canvas);
mAxisRendererLeft.renderAxisLine(canvas);
mAxisRendererRight.renderAxisLine(canvas);
@ -1064,6 +1064,34 @@ public abstract class BarLineChartBase<T extends BarLineScatterCandleData<? exte
return null;
}
/**
* Returns the lowest x-index (value on the x-axis) that is still visible on
* the chart.
*
* @return
*/
public int getLowestVisibleXIndex() {
float[] pts = new float[] {
mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom()
};
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
return (pts[0] <= 0) ? 0 : (int) (pts[0] + 1);
}
/**
* Returns the highest x-index (value on the x-axis) that is still visible
* on the chart.
*
* @return
*/
public int getHighestVisibleXIndex() {
float[] pts = new float[] {
mViewPortHandler.contentRight(), mViewPortHandler.contentBottom()
};
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
return (pts[0] >= mData.getXValCount()) ? mData.getXValCount() - 1 : (int) pts[0];
}
/**
* returns the current x-scale factor
*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.