use of com.github.mikephil.charting.renderer.YAxisRenderer in project MPAndroidChart by PhilJay.
the class BarLineChartBase method init.
@Override
protected void init() {
super.init();
mAxisLeft = new YAxis(AxisDependency.LEFT);
mAxisRight = new YAxis(AxisDependency.RIGHT);
mLeftAxisTransformer = new Transformer(mViewPortHandler);
mRightAxisTransformer = new Transformer(mViewPortHandler);
mAxisRendererLeft = new YAxisRenderer(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
mAxisRendererRight = new YAxisRenderer(mViewPortHandler, mAxisRight, mRightAxisTransformer);
mXAxisRenderer = new XAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);
setHighlighter(new ChartHighlighter(this));
mChartTouchListener = new BarLineChartTouchListener(this, mViewPortHandler.getMatrixTouch(), 3f);
mGridBackgroundPaint = new Paint();
mGridBackgroundPaint.setStyle(Style.FILL);
// mGridBackgroundPaint.setColor(Color.WHITE);
// light
mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240));
// grey
mBorderPaint = new Paint();
mBorderPaint.setStyle(Style.STROKE);
mBorderPaint.setColor(Color.BLACK);
mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
use of com.github.mikephil.charting.renderer.YAxisRenderer in project MPAndroidChart by PhilJay.
the class AxisRendererTest method testComputeAxisValues.
@Test
public void testComputeAxisValues() {
YAxis yAxis = new YAxis();
yAxis.setLabelCount(6);
AxisRenderer renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(0, 100, false);
float[] entries = yAxis.mEntries;
assertEquals(6, entries.length);
// interval 20
assertEquals(20, entries[1] - entries[0], 0.01);
assertEquals(0, entries[0], 0.01);
assertEquals(100, entries[entries.length - 1], 0.01);
yAxis = new YAxis();
yAxis.setLabelCount(6);
yAxis.setGranularity(50f);
renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(0, 100, false);
entries = yAxis.mEntries;
assertEquals(3, entries.length);
// interval 50
assertEquals(50, entries[1] - entries[0], 0.01);
assertEquals(0, entries[0], 0.01);
assertEquals(100, entries[entries.length - 1], 0.01);
yAxis = new YAxis();
yAxis.setLabelCount(5, true);
renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(0, 100, false);
entries = yAxis.mEntries;
assertEquals(5, entries.length);
// interval 25
assertEquals(25, entries[1] - entries[0], 0.01);
assertEquals(0, entries[0], 0.01);
assertEquals(100, entries[entries.length - 1], 0.01);
yAxis = new YAxis();
yAxis.setLabelCount(5, true);
renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(0, 0.01f, false);
entries = yAxis.mEntries;
assertEquals(5, entries.length);
assertEquals(0.0025, entries[1] - entries[0], 0.0001);
assertEquals(0, entries[0], 0.0001);
assertEquals(0.01, entries[entries.length - 1], 0.0001);
yAxis = new YAxis();
yAxis.setLabelCount(5, false);
renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(0, 0.01f, false);
entries = yAxis.mEntries;
assertEquals(5, entries.length);
assertEquals(0.0020, entries[1] - entries[0], 0.0001);
assertEquals(0, entries[0], 0.0001);
assertEquals(0.0080, entries[entries.length - 1], 0.0001);
yAxis = new YAxis();
yAxis.setLabelCount(6);
renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(-50, 50, false);
entries = yAxis.mEntries;
assertEquals(5, entries.length);
assertEquals(-40, entries[0], 0.0001);
assertEquals(0, entries[2], 0.0001);
assertEquals(40, entries[entries.length - 1], 0.0001);
yAxis = new YAxis();
yAxis.setLabelCount(6);
renderer = new YAxisRenderer(null, yAxis, null);
renderer.computeAxis(-50, 100, false);
entries = yAxis.mEntries;
assertEquals(5, entries.length);
assertEquals(-30, entries[0], 0.0001);
assertEquals(30, entries[2], 0.0001);
assertEquals(90, entries[entries.length - 1], 0.0001);
}
Aggregations