com.github.mikephil.charting.components.YAxis.AxisDependency Java Examples

The following examples show how to use com.github.mikephil.charting.components.YAxis.AxisDependency. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarLineChartBase.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example #2
Source File: BarLineChartBase.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: Utils.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example #5
Source File: BarLineChartBase.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: YAxisRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #7
Source File: ChartData.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #8
Source File: BarLineChartBase.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example #9
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example #10
Source File: YAxisRenderer.java    From iMoney with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #11
Source File: ChartData.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #12
Source File: RealtimeLineChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
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;
    }
 
Example #13
Source File: BarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@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);
}
 
Example #14
Source File: YAxisRenderer.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #15
Source File: YAxisRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example #16
Source File: HorizontalBarChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 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]);
}
 
Example #17
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example #18
Source File: BarChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the lowest x-index (value on the x-axis) that is still visible on the chart.
 * 
 * @return
 */
@Override
public int getLowestVisibleXIndex() {

	float step = mData.getDataSetCount();
	float div = (step <= 1) ? 1 : step + mData.getGroupSpace();

	float[] pts = new float[] { mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom() };

	getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
	return (int) ((pts[0] <= getXChartMin()) ? 0 : (pts[0] / div) + 1);
}
 
Example #19
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Returns the lowest x-index (value on the x-axis) that is still visible on
 * the chart.
 *
 * @return
 */
@Override
public float getLowestVisibleX() {
    getTransformer(AxisDependency.LEFT).getValuesByTouchPoint(mViewPortHandler.contentLeft(),
            mViewPortHandler.contentBottom(), posForGetLowestVisibleX);
    float result = (float) Math.max(mXAxis.mAxisMinimum, posForGetLowestVisibleX.x);
    return result;
}
 
Example #20
Source File: BarChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the highest x-index (value on the x-axis) that is still visible on the chart.
 * 
 * @return
 */
@Override
public int getHighestVisibleXIndex() {

	float step = mData.getDataSetCount();
	float div = (step <= 1) ? 1 : step + mData.getGroupSpace();

	float[] pts = new float[] { mViewPortHandler.contentRight(), mViewPortHandler.contentBottom() };

	getTransformer(AxisDependency.LEFT).pixelsToValue(pts);
	return (int) ((pts[0] >= getXChartMax()) ? getXChartMax() / div : (pts[0] / div));
}
 
Example #21
Source File: ChartData.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #22
Source File: ChartData.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the minimum y-value for the specified axis.
 *
 * @param axis
 * @return
 */
public float getYMin(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mLeftAxisMin;
    else
        return mRightAxisMin;
}
 
Example #23
Source File: ChartData.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the maximum y-value for the specified axis.
 *
 * @param axis
 * @return
 */
public float getYMax(AxisDependency axis) {
    if (axis == AxisDependency.LEFT)
        return mLeftAxisMax;
    else
        return mRightAxisMax;
}
 
Example #24
Source File: BarLineChartBase.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {

        PointD origin = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);

        Runnable job = new AnimatedZoomJob(mViewPortHandler, this, getTransformer(axis), getAxis(axis), mXAxis.getValues().size(), scaleX, scaleY, mViewPortHandler.getScaleX(), mViewPortHandler.getScaleY(), xValue, yValue, (float) origin.x, (float) origin.y, duration);
        addViewportJob(job);

    } else {
        Log.e(LOG_TAG, "Unable to execute zoomAndCenterAnimated(...) on API level < 11");
    }
}
 
Example #25
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 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
 */
protected T getFirstLeft(List<T> sets) {
    for (T dataSet : sets) {
        if (dataSet.getAxisDependency() == AxisDependency.LEFT) {
            return dataSet;
        }
    }
    return null;
}
 
Example #27
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 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();
        }
    }
}
 
Example #28
Source File: HorizontalBarChart.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public float getHighestVisibleX() {
    getTransformer(AxisDependency.LEFT).getValuesByTouchPoint(mViewPortHandler.contentLeft(),
            mViewPortHandler.contentTop(), posForGetHighestVisibleX);
    float result = (float) Math.min(mXAxis.mAxisMaximum, posForGetHighestVisibleX.y);
    return result;
}
 
Example #29
Source File: ChartData.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #30
Source File: ChartData.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * 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() {
    for (T dataSet : mDataSets) {
        if (dataSet.getAxisDependency() == AxisDependency.RIGHT)
            return dataSet;
    }

    return null;
}