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

The following examples show how to use com.github.mikephil.charting.utils.ViewPortHandler. 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: BarLineChartTouchListener.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * returns the correct translation depending on the provided x and y touch
 * points
 *
 * @param x
 * @param y
 * @return
 */
public PointF getTrans(float x, float y) {

    ViewPortHandler vph = mChart.getViewPortHandler();

    float xTrans = x - vph.offsetLeft();
    float yTrans = 0f;

    // check if axis is inverted
    if (mChart.isAnyAxisInverted() && mClosestDataSetToTouch != null
            && mChart.isInverted(mClosestDataSetToTouch.getAxisDependency())) {
        yTrans = -(y - vph.offsetTop());
    } else {
        yTrans = -(mChart.getMeasuredHeight() - y - vph.offsetBottom());
    }

    return new PointF(xTrans, yTrans);
}
 
Example #2
Source File: ChevronDownShapeRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                 float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);
}
 
Example #3
Source File: DataRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
    super(viewPortHandler);
    this.mAnimator = animator;

    mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRenderPaint.setStyle(Style.FILL);

    mDrawPaint = new Paint(Paint.DITHER_FLAG);

    mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValuePaint.setColor(Color.rgb(63, 63, 63));
    mValuePaint.setTextAlign(Align.CENTER);
    mValuePaint.setTextSize(Utils.convertDpToPixel(9f));

    mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHighlightPaint.setStyle(Paint.Style.STROKE);
    mHighlightPaint.setStrokeWidth(2f);
    mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
 
Example #4
Source File: CrossShapeRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY,
            posX + shapeHalf,
            posY,
            renderPaint);
    c.drawLine(
            posX,
            posY - shapeHalf,
            posX,
            posY + shapeHalf,
            renderPaint);

}
 
Example #5
Source File: YAxisRenderer.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) {
    super(viewPortHandler, trans, yAxis);

    this.mYAxis = yAxis;

    if (mViewPortHandler != null) {

        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);
    }
}
 
Example #6
Source File: XShapeRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                        float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX - shapeHalf,
            posY - shapeHalf,
            posX + shapeHalf,
            posY + shapeHalf,
            renderPaint);
    c.drawLine(
            posX + shapeHalf,
            posY - shapeHalf,
            posX - shapeHalf,
            posY + shapeHalf,
            renderPaint);

}
 
Example #7
Source File: StackedValueFormatter.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    if (!mDrawWholeStack && entry instanceof BarEntry) {

        BarEntry barEntry = (BarEntry) entry;
        float[] vals = barEntry.getYVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(barEntry.getY()) + mAppendix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mAppendix;
}
 
Example #8
Source File: BarLineChartTouchListener.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * returns the correct translation depending on the provided x and y touch
 * points
 * 
 * @param x
 * @param y
 * @return
 */
public PointF getTrans(float x, float y) {

    ViewPortHandler vph = mChart.getViewPortHandler();

    float xTrans = x - vph.offsetLeft();
    float yTrans = 0f;

    // check if axis is inverted
    if (mChart.isAnyAxisInverted() && mClosestDataSetToTouch != null
            && mChart.isInverted(mClosestDataSetToTouch.getAxisDependency())) {
        yTrans = -(y - vph.offsetTop());
    } else {
        yTrans = -(mChart.getMeasuredHeight() - y - vph.offsetBottom());
    }

    return new PointF(xTrans, yTrans);
}
 
Example #9
Source File: AxisRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans) {
       super(viewPortHandler);

       this.mTrans = trans;

       mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

       mGridPaint = new Paint();
       mGridPaint.setColor(Color.GRAY);
       mGridPaint.setStrokeWidth(1f);
       mGridPaint.setStyle(Style.STROKE);
       mGridPaint.setAlpha(90);

       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);
}
 
Example #10
Source File: AxisRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public AxisRenderer(ViewPortHandler viewPortHandler, Transformer trans, AxisBase axis) {
    super(viewPortHandler);

    this.mTrans = trans;
    this.mAxis = axis;

    if(mViewPortHandler != null) {

        mAxisLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

        mGridPaint = new Paint();
        mGridPaint.setColor(Color.GRAY);
        mGridPaint.setStrokeWidth(1f);
        mGridPaint.setStyle(Style.STROKE);
        mGridPaint.setAlpha(90);

        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);
    }
}
 
Example #11
Source File: DataRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
    super(viewPortHandler);
    this.mAnimator = animator;

    mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRenderPaint.setStyle(Style.FILL);

    mDrawPaint = new Paint(Paint.DITHER_FLAG);

    mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValuePaint.setColor(Color.rgb(63, 63, 63));
    mValuePaint.setTextAlign(Align.CENTER);
    mValuePaint.setTextSize(Utils.convertDpToPixel(9f));

    mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHighlightPaint.setStyle(Paint.Style.STROKE);
    mHighlightPaint.setStrokeWidth(2f);
    mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
 
Example #12
Source File: BarLineChartTouchListener.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Returns a recyclable MPPointF instance.
 * returns the correct translation depending on the provided x and y touch
 * points
 *
 * @param x
 * @param y
 * @return
 */
public MPPointF getTrans(float x, float y) {

    ViewPortHandler vph = mChart.getViewPortHandler();

    float xTrans = x - vph.offsetLeft();
    float yTrans = 0f;

    // check if axis is inverted
    if (inverted()) {
        yTrans = -(y - vph.offsetTop());
    } else {
        yTrans = -(mChart.getMeasuredHeight() - y - vph.offsetBottom());
    }

    return MPPointF.getInstance(xTrans, yTrans);
}
 
Example #13
Source File: LegendRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
public LegendRenderer(ViewPortHandler viewPortHandler, Legend legend) {
    super(viewPortHandler);

    this.mLegend = legend;

    mLegendLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendLabelPaint.setTextSize(Utils.convertDpToPixel(9f));
    mLegendLabelPaint.setTextAlign(Align.LEFT);

    mLegendFormPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLegendFormPaint.setStyle(Paint.Style.FILL);
    mLegendFormPaint.setStrokeWidth(3f);
}
 
Example #14
Source File: ZoomJob.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans, YAxis.AxisDependency axis, View v) {
    super(viewPortHandler, xValue, yValue, trans, v);

    this.scaleX = scaleX;
    this.scaleY = scaleY;
    this.axisDependency = axis;
}
 
Example #15
Source File: ViewPortJob.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public ViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue,
                   Transformer trans, View v) {

    this.mViewPortHandler = viewPortHandler;
    this.xValue = xValue;
    this.yValue = yValue;
    this.mTrans = trans;
    this.view = v;

}
 
Example #16
Source File: LineChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public LineChartRenderer(LineDataProvider chart, ChartAnimator animator,
                         ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mCirclePaintInner = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaintInner.setStyle(Paint.Style.FILL);
    mCirclePaintInner.setColor(Color.WHITE);
}
 
Example #17
Source File: ZoomJob.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public static ZoomJob getInstance(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue,
                                  Transformer trans, YAxis.AxisDependency axis, View v) {
    ZoomJob result = pool.get();
    result.xValue = xValue;
    result.yValue = yValue;
    result.scaleX = scaleX;
    result.scaleY = scaleY;
    result.mViewPortHandler = viewPortHandler;
    result.mTrans = trans;
    result.axisDependency = axis;
    result.view = v;
    return result;
}
 
Example #18
Source File: XShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
        c.drawLine(
                buffer.buffer[i] + shapeHalf,
                buffer.buffer[i + 1] - shapeHalf,
                buffer.buffer[i] - shapeHalf,
                buffer.buffer[i + 1] + shapeHalf,
                mRenderPaint);
    }

}
 
Example #19
Source File: AnimatedZoomJob.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public static AnimatedZoomJob getInstance(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xAxisRange, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) {
    AnimatedZoomJob result = pool.get();
    result.mViewPortHandler = viewPortHandler;
    result.xValue = scaleX;
    result.yValue = scaleY;
    result.mTrans = trans;
    result.view = v;
    result.xOrigin = xOrigin;
    result.yOrigin = yOrigin;
    result.resetAnimator();
    result.animator.setDuration(duration);
    return result;
}
 
Example #20
Source File: DefaultValueFormatter.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    // put more logic here ...
    // avoid memory allocations here (for performance reasons)

    return mFormat.format(value);
}
 
Example #21
Source File: MoveViewJob.java    From iMoney with Apache License 2.0 5 votes vote down vote up
public MoveViewJob(ViewPortHandler viewPortHandler, float xIndex, float yValue,
        Transformer trans, View v) {

    this.mViewPortHandler = viewPortHandler;
    this.xIndex = xIndex;
    this.yValue = yValue;
    this.mTrans = trans;
    this.view = v;
}
 
Example #22
Source File: AnimatedZoomJob.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public AnimatedZoomJob(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xValCount, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) {
    super(viewPortHandler, scaleX, scaleY, trans, v, xOrigin, yOrigin, duration);

    this.zoomCenterX = zoomCenterX;
    this.zoomCenterY = zoomCenterY;
    this.zoomOriginX = zoomOriginX;
    this.zoomOriginY = zoomOriginY;
    this.animator.addListener(this);
    this.yAxis = axis;
    this.xValCount = xValCount;
}
 
Example #23
Source File: ViewPortJob.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
public ViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue,
                   Transformer trans, View v) {

    this.mViewPortHandler = viewPortHandler;
    this.xValue = xValue;
    this.yValue = yValue;
    this.mTrans = trans;
    this.view = v;

}
 
Example #24
Source File: XAxisRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
public XAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans) {
    super(viewPortHandler, trans);

    this.mXAxis = xAxis;

    mAxisLabelPaint.setColor(Color.BLACK);
    mAxisLabelPaint.setTextAlign(Align.CENTER);
    mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
}
 
Example #25
Source File: ScatterChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
public ScatterChartRenderer(ScatterDataProvider chart, ChartAnimator animator,
        ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
 
Example #26
Source File: LineChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public LineChartRenderer(LineDataProvider chart, ChartAnimator animator,
                         ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mCirclePaintInner = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaintInner.setStyle(Paint.Style.FILL);
    mCirclePaintInner.setColor(Color.WHITE);
}
 
Example #27
Source File: AnimatedMoveViewJob.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public static AnimatedMoveViewJob getInstance(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration){
    AnimatedMoveViewJob result = pool.get();
    result.mViewPortHandler = viewPortHandler;
    result.xValue = xValue;
    result.yValue = yValue;
    result.mTrans = trans;
    result.view = v;
    result.xOrigin = xOrigin;
    result.yOrigin = yOrigin;
    //result.resetAnimator();
    result.animator.setDuration(duration);
    return result;
}
 
Example #28
Source File: DefaultValueFormatter.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    // put more logic here ...
    // avoid memory allocations here (for performance reasons)

    return mFormat.format(value);
}
 
Example #29
Source File: ZoomJob.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public ZoomJob(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue, Transformer trans,
               YAxis.AxisDependency axis, View v) {
    super(viewPortHandler, xValue, yValue, trans, v);

    this.scaleX = scaleX;
    this.scaleY = scaleY;
    this.axisDependency = axis;
}
 
Example #30
Source File: ZoomJob.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
public static ZoomJob getInstance(ViewPortHandler viewPortHandler, float scaleX, float scaleY, float xValue, float yValue,
                                  Transformer trans, YAxis.AxisDependency axis, View v) {
    ZoomJob result = pool.get();
    result.xValue = xValue;
    result.yValue = yValue;
    result.scaleX = scaleX;
    result.scaleY = scaleY;
    result.mViewPortHandler = viewPortHandler;
    result.mTrans = trans;
    result.axisDependency = axis;
    result.view = v;
    return result;
}