Java源码示例:com.github.mikephil.charting.components.YAxis.AxisDependency
示例1
@Override
public void renderAxisLine(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled())
return;
mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());
if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
c.drawLine(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
} else {
c.drawLine(mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
示例2
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// Saving current position of chart.
mOnSizeChangedBuffer[0] = mOnSizeChangedBuffer[1] = 0;
if (mKeepPositionOnRotation) {
mOnSizeChangedBuffer[0] = mViewPortHandler.contentLeft();
mOnSizeChangedBuffer[1] = mViewPortHandler.contentTop();
getTransformer(AxisDependency.LEFT).pixelsToValue(mOnSizeChangedBuffer);
}
//Superclass transforms chart.
super.onSizeChanged(w, h, oldw, oldh);
if (mKeepPositionOnRotation) {
//Restoring old position of chart.
getTransformer(AxisDependency.LEFT).pointValuesToPixel(mOnSizeChangedBuffer);
mViewPortHandler.centerViewPort(mOnSizeChangedBuffer, this);
} else {
mViewPortHandler.refresh(mViewPortHandler.getMatrixTouch(), this, true);
}
}
示例3
/**
* This will move the center of the current viewport to the specified
* x-value and y-value animated.
*
* @param xIndex
* @param yValue
* @param axis
* @param duration the duration of the animation in milliseconds
*/
@TargetApi(11)
public void centerViewToAnimated(float xIndex, float yValue, AxisDependency axis, long duration) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
PointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);
float valsInView = getDeltaY(axis) / mViewPortHandler.getScaleY();
float xsInView = getXAxis().getValues().size() / mViewPortHandler.getScaleX();
Runnable job = new AnimatedMoveViewJob(mViewPortHandler,
xIndex - xsInView / 2f, yValue + valsInView / 2f,
getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);
addViewportJob(job);
} else {
Log.e(LOG_TAG, "Unable to execute centerViewToAnimated(...) on API level < 11");
}
}
示例4
@Override
public void renderAxisLine(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled())
return;
mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());
if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
c.drawLine(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
} else {
c.drawLine(mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
示例5
/**
* Returns a recyclable MPPointF instance.
*
* @param e
* @param axis
* @return
*/
@Override
public MPPointF getPosition(Entry e, AxisDependency axis) {
if (e == null) {
return null;
}
float[] vals = mGetPositionBuffer;
vals[0] = e.getY();
vals[1] = e.getX();
getTransformer(axis).pointValuesToPixel(vals);
return MPPointF.getInstance(vals[0], vals[1]);
}
示例6
/**
* Returns the maximum y-value for the specified axis.
*
* @param axis
* @return
*/
public float getYMax(AxisDependency axis) {
if (axis == AxisDependency.LEFT) {
if (mLeftAxisMax == -Float.MAX_VALUE) {
return mRightAxisMax;
} else {
return mLeftAxisMax;
}
} else {
if (mRightAxisMax == -Float.MAX_VALUE) {
return mLeftAxisMax;
} else {
return mRightAxisMax;
}
}
}
示例7
@Override
public void renderAxisLine(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled()) {
return;
}
mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());
if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
c.drawLine(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
} else {
c.drawLine(mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
示例8
@Override
public void renderAxisLine(Canvas c) {
if (!mYAxis.isEnabled() || !mYAxis.isDrawAxisLineEnabled())
return;
mAxisLinePaint.setColor(mYAxis.getAxisLineColor());
mAxisLinePaint.setStrokeWidth(mYAxis.getAxisLineWidth());
if (mYAxis.getAxisDependency() == AxisDependency.LEFT) {
c.drawLine(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), mViewPortHandler.contentLeft(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
} else {
c.drawLine(mViewPortHandler.contentRight(), mViewPortHandler.contentTop(), mViewPortHandler.contentRight(),
mViewPortHandler.contentBottom(), mAxisLinePaint);
}
}
示例9
@Override
public void onValueSelected(Entry e, Highlight h) {
if (e == null)
return;
RectF bounds = onValueSelectedRectF;
chart.getBarBounds((BarEntry) e, bounds);
MPPointF position = chart.getPosition(e, AxisDependency.LEFT);
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
Log.i("x-index",
"low: " + chart.getLowestVisibleX() + ", high: "
+ chart.getHighestVisibleX());
MPPointF.recycleInstance(position);
}
示例10
private LineDataSet createSet() {
LineDataSet set = new LineDataSet(null, "Dynamic Data");
set.setAxisDependency(AxisDependency.LEFT);
set.setColor(ColorTemplate.getHoloBlue());
set.setCircleColor(Color.WHITE);
set.setLineWidth(2f);
set.setCircleRadius(4f);
set.setFillAlpha(65);
set.setFillColor(ColorTemplate.getHoloBlue());
set.setHighLightColor(Color.rgb(244, 117, 117));
set.setValueTextColor(Color.WHITE);
set.setValueTextSize(9f);
set.setDrawValues(false);
return set;
}
示例11
/**
* Adjusts the minimum and maximum values based on the given DataSet.
*
* @param d
*/
protected void calcMinMax(T d) {
if (mYMax < d.getYMax())
mYMax = d.getYMax();
if (mYMin > d.getYMin())
mYMin = d.getYMin();
if (mXMax < d.getXMax())
mXMax = d.getXMax();
if (mXMin > d.getXMin())
mXMin = d.getXMin();
if (d.getAxisDependency() == AxisDependency.LEFT) {
if (mLeftAxisMax < d.getYMax())
mLeftAxisMax = d.getYMax();
if (mLeftAxisMin > d.getYMin())
mLeftAxisMin = d.getYMin();
} else {
if (mRightAxisMax < d.getYMax())
mRightAxisMax = d.getYMax();
if (mRightAxisMin > d.getYMin())
mRightAxisMin = d.getYMin();
}
}
示例12
/**
* Zooms by the specified scale factor to the specified values on the specified axis.
*
* @param scaleX
* @param scaleY
* @param xValue
* @param yValue
* @param axis
* @param duration
*/
@TargetApi(11)
public void zoomAndCenterAnimated(float scaleX, float scaleY, float xValue, float yValue, AxisDependency axis,
long duration) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
MPPointD origin = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);
Runnable job = AnimatedZoomJob.getInstance(mViewPortHandler, this, getTransformer(axis), getAxis(axis), mXAxis
.mAxisRange, scaleX, scaleY, mViewPortHandler.getScaleX(), mViewPortHandler.getScaleY(),
xValue, yValue, (float) origin.x, (float) origin.y, duration);
addViewportJob(job);
MPPointD.recycleInstance(origin);
} else {
Log.e(LOG_TAG, "Unable to execute zoomAndCenterAnimated(...) on API level < 11");
}
}
示例13
/**
* This will move the left side of the current viewport to the specified x-position
* and center the viewport to the specified y-position animated.
* This also refreshes the chart by calling invalidate().
*
* @param xIndex
* @param yValue
* @param axis
* @param duration the duration of the animation in milliseconds
*/
@TargetApi(11)
public void moveViewToAnimated(float xIndex, float yValue, AxisDependency axis, long duration) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
PointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);
float valsInView = getDeltaY(axis) / mViewPortHandler.getScaleY();
Runnable job = new AnimatedMoveViewJob(mViewPortHandler, xIndex, yValue + valsInView / 2f,
getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);
addViewportJob(job);
} else {
Log.e(LOG_TAG, "Unable to execute moveViewToAnimated(...) on API level < 11");
}
}
示例14
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// Saving current position of chart.
float[] pts = new float[2];
if (mKeepPositionOnRotation) {
pts[0] = mViewPortHandler.contentLeft();
pts[1] = mViewPortHandler.contentTop();
getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
}
//Superclass transforms chart.
super.onSizeChanged(w, h, oldw, oldh);
if (mKeepPositionOnRotation) {
//Restoring old position of chart.
getTransformer(AxisDependency.LEFT).pointValuesToPixel(pts);
mViewPortHandler.centerViewPort(pts, this);
} else {
mViewPortHandler.refresh(mViewPortHandler.getMatrixTouch(), this, true);
}
}
示例15
/**
* Returns the minimum distance from a touch-y-value (in pixels) to the
* closest y-value (in pixels) that is displayed in the chart.
*
* @param valsAtIndex
* @param val
* @param axis
* @return
*/
public static float getMinimumDistance(List<SelectionDetail> valsAtIndex, float val,
AxisDependency axis) {
float distance = Float.MAX_VALUE;
for (int i = 0; i < valsAtIndex.size(); i++) {
SelectionDetail sel = valsAtIndex.get(i);
if (sel.dataSet.getAxisDependency() == axis) {
float cdistance = Math.abs((float) sel.val - val);
if (cdistance < distance) {
distance = cdistance;
}
}
}
return distance;
}
示例16
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// Saving current position of chart.
mOnSizeChangedBuffer[0] = mOnSizeChangedBuffer[1] = 0;
if (mKeepPositionOnRotation) {
mOnSizeChangedBuffer[0] = mViewPortHandler.contentLeft();
mOnSizeChangedBuffer[1] = mViewPortHandler.contentTop();
getTransformer(AxisDependency.LEFT).pixelsToValue(mOnSizeChangedBuffer);
}
//Superclass transforms chart.
super.onSizeChanged(w, h, oldw, oldh);
if (mKeepPositionOnRotation) {
//Restoring old position of chart.
getTransformer(AxisDependency.LEFT).pointValuesToPixel(mOnSizeChangedBuffer);
mViewPortHandler.centerViewPort(mOnSizeChangedBuffer, this);
} else {
mViewPortHandler.refresh(mViewPortHandler.getMatrixTouch(), this, true);
}
}
示例17
/**
* Adjusts the current minimum and maximum values based on the provided Entry object.
*
* @param e
* @param axis
*/
protected void calcMinMax(Entry e, AxisDependency axis) {
if (mYMax < e.getY())
mYMax = e.getY();
if (mYMin > e.getY())
mYMin = e.getY();
if (mXMax < e.getX())
mXMax = e.getX();
if (mXMin > e.getX())
mXMin = e.getX();
if (axis == AxisDependency.LEFT) {
if (mLeftAxisMax < e.getY())
mLeftAxisMax = e.getY();
if (mLeftAxisMin > e.getY())
mLeftAxisMin = e.getY();
} else {
if (mRightAxisMax < e.getY())
mRightAxisMax = e.getY();
if (mRightAxisMin > e.getY())
mRightAxisMin = e.getY();
}
}
示例18
/**
* Transforms the given chart values into pixels. This is the opposite
* method to getValuesByTouchPoint(...).
*
* @param x
* @param y
* @return
*/
public PointD getPixelsForValues(float x, float y, AxisDependency axis) {
float[] pts = new float[]{
x, y
};
getTransformer(axis).pointValuesToPixel(pts);
return new PointD(pts[0], pts[1]);
}
示例19
/**
* Returns the range of the specified axis.
*
* @param axis
* @return
*/
protected float getAxisRange(AxisDependency axis) {
if (axis == AxisDependency.LEFT)
return mAxisLeft.mAxisRange;
else
return mAxisRight.mAxisRange;
}
示例20
/**
* Returns the Transformer class that contains all matrices and is
* responsible for transforming values into pixels on the screen and
* backwards.
*
* @return
*/
@Override
public Transformer getTransformer(AxisDependency which) {
if (which == AxisDependency.LEFT) {
return mLeftAxisTransformer;
} else {
return mRightAxisTransformer;
}
}
示例21
/**
* This will move the center of the current viewport to the specified
* x-value and y-value.
* This also refreshes the chart by calling invalidate().
*
* @param xIndex
* @param yValue
* @param axis - which axis should be used as a reference for the y-axis
*/
public void centerViewTo(float xIndex, float yValue, AxisDependency axis) {
float valsInView = getDeltaY(axis) / mViewPortHandler.getScaleY();
float xsInView = getXAxis().getValues().size() / mViewPortHandler.getScaleX();
Runnable job = new MoveViewJob(mViewPortHandler,
xIndex - xsInView / 2f, yValue + valsInView / 2f,
getTransformer(axis), this);
addViewportJob(job);
}
示例22
/**
* Returns the first DataSet from the datasets-array that has it's dependency on the right axis.
* Returns null if no DataSet with right dependency could be found.
*
* @return
*/
public T getFirstRight(List<T> sets) {
for (T dataSet : sets) {
if (dataSet.getAxisDependency() == AxisDependency.RIGHT)
return dataSet;
}
return null;
}
示例23
/**
* Returns the minimum y-value for the specified axis.
*
* @param axis
* @return
*/
public float getYMin(AxisDependency axis) {
if (axis == AxisDependency.LEFT) {
if (mLeftAxisMin == Float.MAX_VALUE) {
return mRightAxisMin;
} else
return mLeftAxisMin;
} else {
if (mRightAxisMin == Float.MAX_VALUE) {
return mLeftAxisMin;
} else
return mRightAxisMin;
}
}
示例24
@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);
mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240)); // light
// grey
mBorderPaint = new Paint();
mBorderPaint.setStyle(Style.STROKE);
mBorderPaint.setColor(Color.BLACK);
mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
示例25
@Override
protected void calcMinMax() {
super.calcMinMax();
float minLeft = !Float.isNaN(mYAxis.getAxisMinValue())
? mYAxis.getAxisMinValue()
: mData.getYMin(AxisDependency.LEFT);
float maxLeft = !Float.isNaN(mYAxis.getAxisMaxValue())
? mYAxis.getAxisMaxValue()
: mData.getYMax(AxisDependency.LEFT);
mXChartMax = mData.getXVals().size() - 1;
mDeltaX = Math.abs(mXChartMax - mXChartMin);
float leftRange = Math.abs(maxLeft - minLeft);
float topSpaceLeft = leftRange / 100f * mYAxis.getSpaceTop();
float bottomSpaceLeft = leftRange / 100f * mYAxis.getSpaceBottom();
mXChartMax = mData.getXVals().size() - 1;
mDeltaX = Math.abs(mXChartMax - mXChartMin);
// Use the values as they are
mYAxis.mAxisMinimum = !Float.isNaN(mYAxis.getAxisMinValue())
? mYAxis.getAxisMinValue()
: (minLeft - bottomSpaceLeft);
mYAxis.mAxisMaximum = !Float.isNaN(mYAxis.getAxisMaxValue())
? mYAxis.getAxisMaxValue()
: (maxLeft + topSpaceLeft);
mYAxis.mAxisRange = Math.abs(mYAxis.mAxisMaximum - mYAxis.mAxisMinimum);
}
示例26
/**
* Returns the lowest x-index (value on the x-axis) that is still visible on
* the chart.
*
* @return
*/
@Override
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);
}
示例27
/**
* Returns the range of the specified axis.
*
* @param axis
* @return
*/
protected float getAxisRange(AxisDependency axis) {
if (axis == AxisDependency.LEFT) {
return mAxisLeft.mAxisRange;
} else {
return mAxisRight.mAxisRange;
}
}
示例28
/**
* Transforms the given chart values into pixels. This is the opposite
* method to getValuesByTouchPoint(...).
*
* @param x
* @param y
* @return
*/
public PointD getPixelsForValues(float x, float y, AxisDependency axis) {
float[] pts = new float[] {
x, y
};
getTransformer(axis).pointValuesToPixel(pts);
return new PointD(pts[0], pts[1]);
}
示例29
/**
* Returns the delta-y value (y-value range) of the specified axis.
*
* @param axis
* @return
*/
public float getDeltaY(AxisDependency axis) {
if (axis == AxisDependency.LEFT)
return mAxisLeft.mAxisRange;
else
return mAxisRight.mAxisRange;
}
示例30
/**
* Returns the first DataSet from the datasets-array that has it's dependency on the left axis.
* Returns null if no DataSet with left dependency could be found.
*
* @return
*/
public T getFirstLeft() {
for (T dataSet : mDataSets) {
if (dataSet.getAxisDependency() == AxisDependency.LEFT)
return dataSet;
}
return null;
}