Test axis renderer
This commit is contained in:
parent
084935d9e3
commit
66434c6a8e
4 changed files with 136 additions and 55 deletions
|
@ -115,40 +115,4 @@ public class XAxis extends AxisBase {
|
|||
public boolean isAvoidFirstLastClippingEnabled() {
|
||||
return mAvoidFirstLastClipping;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Sets the labels for this axis.
|
||||
// *
|
||||
// * @param values
|
||||
// */
|
||||
// public void setValues(List<XAxisValue> values) {
|
||||
// mValues = values;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the labels for this axis.
|
||||
// *
|
||||
// * @return
|
||||
// */
|
||||
// public List<XAxisValue> getValues() {
|
||||
// return mValues;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Adds a new xPx-yValue to the chart data.
|
||||
// *
|
||||
// * @param xVal
|
||||
// */
|
||||
// public void addXValue(XAxisValue xVal) {
|
||||
// mValues.add(xVal);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Removes the xPx-yValue at the specified index.
|
||||
// *
|
||||
// * @param index
|
||||
// */
|
||||
// public void removeXValue(int index) {
|
||||
// mValues.remove(index);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -51,21 +51,24 @@ public abstract class AxisRenderer extends Renderer {
|
|||
this.mTrans = trans;
|
||||
this.mAxis = axis;
|
||||
|
||||
mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
if(mTrans != null) {
|
||||
|
||||
mGridPaint = new Paint();
|
||||
mGridPaint.setColor(Color.GRAY);
|
||||
mGridPaint.setStrokeWidth(1f);
|
||||
mGridPaint.setStyle(Style.STROKE);
|
||||
mGridPaint.setAlpha(90);
|
||||
mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
mAxisLinePaint = new Paint();
|
||||
mAxisLinePaint.setColor(Color.BLACK);
|
||||
mAxisLinePaint.setStrokeWidth(1f);
|
||||
mAxisLinePaint.setStyle(Style.STROKE);
|
||||
mGridPaint = new Paint();
|
||||
mGridPaint.setColor(Color.GRAY);
|
||||
mGridPaint.setStrokeWidth(1f);
|
||||
mGridPaint.setStyle(Style.STROKE);
|
||||
mGridPaint.setAlpha(90);
|
||||
|
||||
mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mLimitLinePaint.setStyle(Paint.Style.STROKE);
|
||||
mAxisLinePaint = new Paint();
|
||||
mAxisLinePaint.setColor(Color.BLACK);
|
||||
mAxisLinePaint.setStrokeWidth(1f);
|
||||
mAxisLinePaint.setStyle(Style.STROKE);
|
||||
|
||||
mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mLimitLinePaint.setStyle(Paint.Style.STROKE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +119,7 @@ public abstract class AxisRenderer extends Renderer {
|
|||
|
||||
// calculate the starting and entry point of the yPx-labels (depending on
|
||||
// zoom / contentrect bounds)
|
||||
if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {
|
||||
if (mViewPortHandler != null && mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {
|
||||
|
||||
PointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
|
||||
PointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());
|
||||
|
|
|
@ -28,13 +28,16 @@ public class YAxisRenderer extends AxisRenderer {
|
|||
|
||||
this.mYAxis = yAxis;
|
||||
|
||||
mAxisLabelPaint.setColor(Color.BLACK);
|
||||
mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
|
||||
if(mTrans != null) {
|
||||
|
||||
mZeroLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mZeroLinePaint.setColor(Color.GRAY);
|
||||
mZeroLinePaint.setStrokeWidth(1f);
|
||||
mZeroLinePaint.setStyle(Paint.Style.STROKE);
|
||||
mAxisLabelPaint.setColor(Color.BLACK);
|
||||
mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
|
||||
|
||||
mZeroLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mZeroLinePaint.setColor(Color.GRAY);
|
||||
mZeroLinePaint.setStrokeWidth(1f);
|
||||
mZeroLinePaint.setStyle(Paint.Style.STROKE);
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package com.github.mikephil.charting.test;
|
||||
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.DataSet;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.ScatterDataSet;
|
||||
import com.github.mikephil.charting.renderer.AxisRenderer;
|
||||
import com.github.mikephil.charting.renderer.YAxisRenderer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by philipp on 31/05/16.
|
||||
*/
|
||||
public class AxisRendererTest {
|
||||
|
||||
|
||||
@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);
|
||||
assertEquals(20, entries[1] - entries[0], 0.01); // interval 20
|
||||
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);
|
||||
assertEquals(50, entries[1] - entries[0], 0.01); // interval 50
|
||||
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);
|
||||
assertEquals(25, entries[1] - entries[0], 0.01); // interval 25
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue