com.github.mikephil.charting.utils.MPPointD Java Examples

The following examples show how to use com.github.mikephil.charting.utils.MPPointD. 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: YAxisRendererHorizontalBarChart.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
protected void drawZeroLine(Canvas c) {

    int clipRestoreCount = c.save();
    mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
    mZeroLineClippingRect.inset(-mYAxis.getZeroLineWidth(), 0.f);
    c.clipRect(mLimitLineClippingRect);

    // draw zero line
    MPPointD pos = mTrans.getPixelForValues(0f, 0f);

    mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
    mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());

    Path zeroLinePath = mDrawZeroLinePathBuffer;
    zeroLinePath.reset();

    zeroLinePath.moveTo((float) pos.x - 1, mViewPortHandler.contentTop());
    zeroLinePath.lineTo((float) pos.x - 1, mViewPortHandler.contentBottom());

    // draw a path because lines don't support dashing on lower android versions
    c.drawPath(zeroLinePath, mZeroLinePaint);

    c.restoreToCount(clipRestoreCount);
}
 
Example #2
Source File: YAxisRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the zero line.
 */
protected void drawZeroLine(Canvas c) {

    int clipRestoreCount = c.save();
    mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
    mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth());
    c.clipRect(mZeroLineClippingRect);

    // draw zero line
    MPPointD pos = mTrans.getPixelForValues(0f, 0f);

    mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
    mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());

    Path zeroLinePath = mDrawZeroLinePath;
    zeroLinePath.reset();

    zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y);
    zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y);

    // draw a path because lines don't support dashing on lower android versions
    c.drawPath(zeroLinePath, mZeroLinePaint);

    c.restoreToCount(clipRestoreCount);
}
 
Example #3
Source File: YAxisRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Draws the zero line.
 */
protected void drawZeroLine(Canvas c) {

    int clipRestoreCount = c.save();
    mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
    mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth());
    c.clipRect(mZeroLineClippingRect);

    // draw zero line
    MPPointD pos = mTrans.getPixelForValues(0f, 0f);

    mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
    mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());

    Path zeroLinePath = mDrawZeroLinePath;
    zeroLinePath.reset();

    zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y);
    zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y);

    // draw a path because lines don't support dashing on lower android versions
    c.drawPath(zeroLinePath, mZeroLinePaint);

    c.restoreToCount(clipRestoreCount);
}
 
Example #4
Source File: HorizontalBarHighlighter.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

	BarData barData = mChart.getBarData();

	MPPointD pos = getValsForTouch(y, x);

	Highlight high = getHighlightForX((float) pos.y, y, x);
	if (high == null)
		return null;

	IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
	if (set.isStacked()) {

		return getStackedHighlight(high,
				set,
				(float) pos.y,
				(float) pos.x);
	}

	MPPointD.recycleInstance(pos);

	return high;
}
 
Example #5
Source File: AxisRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the axis values.
 *
 * @param min - the minimum value in the data object for this axis
 * @param max - the maximum value in the data object for this axis
 */
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler != null && mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());

        if (!inverted) {

            min = (float) p2.y;
            max = (float) p1.y;
        } else {

            min = (float) p1.y;
            max = (float) p2.y;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #6
Source File: AxisRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Computes the axis values.
 *
 * @param min - the minimum value in the data object for this axis
 * @param max - the maximum value in the data object for this axis
 */
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler != null && mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());

        if (!inverted) {

            min = (float) p2.y;
            max = (float) p1.y;
        } else {

            min = (float) p1.y;
            max = (float) p2.y;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #7
Source File: XAxisRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutX()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentRight(), mViewPortHandler.contentTop());

        if (inverted) {

            min = (float) p2.x;
            max = (float) p1.x;
        } else {

            min = (float) p1.x;
            max = (float) p2.x;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #8
Source File: XAxisRendererHorizontalBarChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());

        if (inverted) {

            min = (float) p2.y;
            max = (float) p1.y;
        } else {

            min = (float) p1.y;
            max = (float) p2.y;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #9
Source File: YAxisRendererHorizontalBarChart.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawZeroLine(Canvas c) {

    int clipRestoreCount = c.save();
    mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
    mZeroLineClippingRect.inset(-mYAxis.getZeroLineWidth(), 0.f);
    c.clipRect(mLimitLineClippingRect);

    // draw zero line
    MPPointD pos = mTrans.getPixelForValues(0f, 0f);

    mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
    mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());

    Path zeroLinePath = mDrawZeroLinePathBuffer;
    zeroLinePath.reset();

    zeroLinePath.moveTo((float) pos.x - 1, mViewPortHandler.contentTop());
    zeroLinePath.lineTo((float) pos.x - 1, mViewPortHandler.contentBottom());

    // draw a path because lines don't support dashing on lower android versions
    c.drawPath(zeroLinePath, mZeroLinePaint);

    c.restoreToCount(clipRestoreCount);
}
 
Example #10
Source File: BarHighlighter.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);

    if(high == null) {
        return null;
    }

    MPPointD pos = getValsForTouch(x, y);

    BarData barData = mChart.getBarData();

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.x,
                (float) pos.y);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #11
Source File: BarLineChartBase.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * This will move the center of the current viewport to the specified
 * x and y value animated.
 *
 * @param xValue
 * @param yValue
 * @param axis
 * @param duration the duration of the animation in milliseconds
 */
@TargetApi(11)
public void centerViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {

    MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);

    float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();
    float xInView = getXAxis().mAxisRange / mViewPortHandler.getScaleX();

    Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler,
            xValue - xInView / 2f, yValue + yInView / 2f,
            getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);

    addViewportJob(job);

    MPPointD.recycleInstance(bounds);
}
 
Example #12
Source File: YAxisRendererHorizontalBarChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
protected void drawZeroLine(Canvas c) {

    int clipRestoreCount = c.save();
    mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
    mZeroLineClippingRect.inset(-mYAxis.getZeroLineWidth(), 0.f);
    c.clipRect(mLimitLineClippingRect);

    // draw zero line
    MPPointD pos = mTrans.getPixelForValues(0f, 0f);

    mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
    mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());

    Path zeroLinePath = mDrawZeroLinePathBuffer;
    zeroLinePath.reset();

    zeroLinePath.moveTo((float) pos.x - 1, mViewPortHandler.contentTop());
    zeroLinePath.lineTo((float) pos.x - 1, mViewPortHandler.contentBottom());

    // draw a path because lines don't support dashing on lower android versions
    c.drawPath(zeroLinePath, mZeroLinePaint);

    c.restoreToCount(clipRestoreCount);
}
 
Example #13
Source File: BarHighlighter.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);

    if(high == null) {
        return null;
    }

    MPPointD pos = getValsForTouch(x, y);

    BarData barData = mChart.getBarData();

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.x,
                (float) pos.y);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #14
Source File: XAxisRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutX()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentRight(), mViewPortHandler.contentTop());

        if (inverted) {

            min = (float) p2.x;
            max = (float) p1.x;
        } else {

            min = (float) p1.x;
            max = (float) p2.x;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #15
Source File: BarLineChartBase.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * This will move the center of the current viewport to the specified
 * x and y value animated.
 *
 * @param xValue
 * @param yValue
 * @param axis
 * @param duration the duration of the animation in milliseconds
 */
@TargetApi(11)
public void centerViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {

    if (android.os.Build.VERSION.SDK_INT >= 11) {

        MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);

        float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();
        float xInView = getXAxis().mAxisRange / mViewPortHandler.getScaleX();

        Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler,
                xValue - xInView / 2f, yValue + yInView / 2f,
                getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);

        addViewportJob(job);

        MPPointD.recycleInstance(bounds);
    } else {
        Log.e(LOG_TAG, "Unable to execute centerViewToAnimated(...) on API level < 11");
    }
}
 
Example #16
Source File: BarLineChartBase.java    From android-kline 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-value
 * and center the viewport to the y value animated.
 * This also refreshes the chart by calling invalidate().
 *
 * @param xValue
 * @param yValue
 * @param axis
 * @param duration the duration of the animation in milliseconds
 */
@TargetApi(11)
public void moveViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {

    if (android.os.Build.VERSION.SDK_INT >= 11) {

        MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);

        float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();

        Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler, xValue, yValue + yInView / 2f,
                getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);

        addViewportJob(job);

        MPPointD.recycleInstance(bounds);
    } else {
        Log.e(LOG_TAG, "Unable to execute moveViewToAnimated(...) on API level < 11");
    }
}
 
Example #17
Source File: HorizontalBarHighlighter.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

    BarData barData = mChart.getBarData();

    MPPointD pos = getValsForTouch(y, x);

    Highlight high = getHighlightForX((float) pos.y, y, x);
    if (high == null) {
        return null;
    }

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.y,
                (float) pos.x);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #18
Source File: BarLineChartBase.java    From android-kline with Apache License 2.0 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 #19
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 #20
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * This will move the left side of the current viewport to the specified x-value
 * and center the viewport to the y value animated.
 * This also refreshes the chart by calling invalidate().
 *
 * @param xValue
 * @param yValue
 * @param axis
 * @param duration the duration of the animation in milliseconds
 */
@TargetApi(11)
public void moveViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {

    if (android.os.Build.VERSION.SDK_INT >= 11) {

        MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);

        float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();

        Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler, xValue, yValue + yInView / 2f,
                getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);

        addViewportJob(job);

        MPPointD.recycleInstance(bounds);
    } else {
        Log.e(LOG_TAG, "Unable to execute moveViewToAnimated(...) on API level < 11");
    }
}
 
Example #21
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * This will move the center of the current viewport to the specified
 * x and y value animated.
 *
 * @param xValue
 * @param yValue
 * @param axis
 * @param duration the duration of the animation in milliseconds
 */
@TargetApi(11)
public void centerViewToAnimated(float xValue, float yValue, AxisDependency axis, long duration) {

    if (android.os.Build.VERSION.SDK_INT >= 11) {

        MPPointD bounds = getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop(), axis);

        float yInView = getAxisRange(axis) / mViewPortHandler.getScaleY();
        float xInView = getXAxis().mAxisRange / mViewPortHandler.getScaleX();

        Runnable job = AnimatedMoveViewJob.getInstance(mViewPortHandler,
                xValue - xInView / 2f, yValue + yInView / 2f,
                getTransformer(axis), this, (float) bounds.x, (float) bounds.y, duration);

        addViewportJob(job);

        MPPointD.recycleInstance(bounds);
    } else {
        Log.e(LOG_TAG, "Unable to execute centerViewToAnimated(...) on API level < 11");
    }
}
 
Example #22
Source File: HorizontalBarHighlighter.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

	BarData barData = mChart.getBarData();

	MPPointD pos = getValsForTouch(y, x);

	Highlight high = getHighlightForX((float) pos.y, y, x);
	if (high == null)
		return null;

	IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
	if (set.isStacked()) {

		return getStackedHighlight(high,
				set,
				(float) pos.y,
				(float) pos.x);
	}

	MPPointD.recycleInstance(pos);

	return high;
}
 
Example #23
Source File: XAxisRendererHorizontalBarChart.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());

        if (inverted) {

            min = (float) p2.y;
            max = (float) p1.y;
        } else {

            min = (float) p1.y;
            max = (float) p2.y;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #24
Source File: XAxisRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutX()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentRight(), mViewPortHandler.contentTop());

        if (inverted) {

            min = (float) p2.x;
            max = (float) p1.x;
        } else {

            min = (float) p1.x;
            max = (float) p2.x;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #25
Source File: AxisRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Computes the axis values.
 *
 * @param min - the minimum value in the data object for this axis
 * @param max - the maximum value in the data object for this axis
 */
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler != null && mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());

        if (!inverted) {

            min = (float) p2.y;
            max = (float) p1.y;
        } else {

            min = (float) p1.y;
            max = (float) p2.y;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #26
Source File: YAxisRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Draws the zero line.
 */
protected void drawZeroLine(Canvas c) {

    int clipRestoreCount = c.save();
    mZeroLineClippingRect.set(mViewPortHandler.getContentRect());
    mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth());
    c.clipRect(mZeroLineClippingRect);

    // draw zero line
    MPPointD pos = mTrans.getPixelForValues(0f, 0f);

    mZeroLinePaint.setColor(mYAxis.getZeroLineColor());
    mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth());

    Path zeroLinePath = mDrawZeroLinePath;
    zeroLinePath.reset();

    zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y);
    zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y);

    // draw a path because lines don't support dashing on lower android versions
    c.drawPath(zeroLinePath, mZeroLinePaint);

    c.restoreToCount(clipRestoreCount);
}
 
Example #27
Source File: BarHighlighter.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {
    Highlight high = super.getHighlight(x, y);

    if(high == null) {
        return null;
    }

    MPPointD pos = getValsForTouch(x, y);

    BarData barData = mChart.getBarData();

    IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
    if (set.isStacked()) {

        return getStackedHighlight(high,
                set,
                (float) pos.x,
                (float) pos.y);
    }

    MPPointD.recycleInstance(pos);

    return high;
}
 
Example #28
Source File: XAxisRendererHorizontalBarChart.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void computeAxis(float min, float max, boolean inverted) {

    // calculate the starting and entry point of the y-labels (depending on
    // zoom / contentrect bounds)
    if (mViewPortHandler.contentWidth() > 10 && !mViewPortHandler.isFullyZoomedOutY()) {

        MPPointD p1 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentBottom());
        MPPointD p2 = mTrans.getValuesByTouchPoint(mViewPortHandler.contentLeft(), mViewPortHandler.contentTop());

        if (inverted) {

            min = (float) p2.y;
            max = (float) p1.y;
        } else {

            min = (float) p1.y;
            max = (float) p2.y;
        }

        MPPointD.recycleInstance(p1);
        MPPointD.recycleInstance(p2);
    }

    computeAxisValues(min, max);
}
 
Example #29
Source File: BarHighlighter.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been
 * selected.
 *
 * @param high the Highlight to work with looking for stacked values
 * @param set
 * @param xVal
 * @param yVal
 * @return
 */
public Highlight getStackedHighlight(Highlight high, IBarDataSet set, float xVal, float yVal) {

    BarEntry entry = set.getEntryForXValue(xVal, yVal);

    if (entry == null)
        return null;

    // not stacked
    if (entry.getYVals() == null) {
        return high;
    } else {
        Range[] ranges = entry.getRanges();

        if (ranges.length > 0) {
            int stackIndex = getClosestStackIndex(ranges, yVal);

            MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(high.getX(), ranges[stackIndex].to);

            Highlight stackedHigh = new Highlight(
                    entry.getX(),
                    entry.getY(),
                    (float) pixels.x,
                    (float) pixels.y,
                    high.getDataSetIndex(),
                    stackIndex,
                    high.getAxis()
            );

            MPPointD.recycleInstance(pixels);

            return stackedHigh;
        }
    }

    return null;
}
 
Example #30
Source File: ChartHighlighter.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public Highlight getHighlight(float x, float y) {

    MPPointD pos = getValsForTouch(x, y);
    float xVal = (float) pos.x;
    MPPointD.recycleInstance(pos);

    Highlight high = getHighlightForX(xVal, x, y);
    return high;
}