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

The following examples show how to use com.github.mikephil.charting.utils.ViewPortHandler. These examples are extracted from open source projects. 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 Project: NetKnight   Source File: BarLineChartTouchListener.java    License: 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 Project: Ticket-Analysis   Source File: AxisRenderer.java    License: 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 3
Source Project: NetKnight   Source File: AxisRenderer.java    License: 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 4
Source Project: android-kline   Source File: StackedValueFormatter.java    License: 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 5
Source Project: Ticket-Analysis   Source File: CrossShapeRenderer.java    License: 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 6
Source Project: android-kline   Source File: ChevronDownShapeRenderer.java    License: 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 7
Source Project: StockChart-MPAndroidChart   Source File: DataRenderer.java    License: 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 8
Source Project: StockChart-MPAndroidChart   Source File: YAxisRenderer.java    License: 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 9
Source Project: Ticket-Analysis   Source File: XShapeRenderer.java    License: 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 10
Source Project: iMoney   Source File: BarLineChartTouchListener.java    License: 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 11
Source Project: Ticket-Analysis   Source File: DataRenderer.java    License: 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 Project: Ticket-Analysis   Source File: BarLineChartTouchListener.java    License: 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 Project: iMoney   Source File: RadarChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
public RadarChartRenderer(RadarChart chart, ChartAnimator animator,
                          ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHighlightPaint.setStyle(Paint.Style.STROKE);
    mHighlightPaint.setStrokeWidth(2f);
    mHighlightPaint.setColor(Color.rgb(255, 187, 115));

    mWebPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mWebPaint.setStyle(Paint.Style.STROKE);
}
 
Example 14
Source Project: Ticket-Analysis   Source File: ZoomJob.java    License: 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 15
Source Project: android-kline   Source File: ViewPortJob.java    License: 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 Project: android-kline   Source File: LineChartRenderer.java    License: 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 Project: NetKnight   Source File: ZoomJob.java    License: 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 18
Source Project: Stayfit   Source File: CombinedChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates the renderers needed for this combined-renderer in the required order. Also takes the DrawOrder into
 * consideration.
 *
 * @param chart
 * @param animator
 * @param viewPortHandler
 */
protected void createRenderers(CombinedChart chart, ChartAnimator animator, ViewPortHandler viewPortHandler) {

    mRenderers = new ArrayList<DataRenderer>();

    DrawOrder[] orders = chart.getDrawOrder();

    for (DrawOrder order : orders) {

        switch (order) {
            case BAR:
                if (chart.getBarData() != null)
                    mRenderers.add(new BarChartRenderer(chart, animator, viewPortHandler));
                break;
            case BUBBLE:
                if (chart.getBubbleData() != null)
                    mRenderers.add(new BubbleChartRenderer(chart, animator, viewPortHandler));
                break;
            case LINE:
                if (chart.getLineData() != null)
                    mRenderers.add(new LineChartRenderer(chart, animator, viewPortHandler));
                break;
            case CANDLE:
                if (chart.getCandleData() != null)
                    mRenderers.add(new CandleStickChartRenderer(chart, animator, viewPortHandler));
                break;
            case SCATTER:
                if (chart.getScatterData() != null)
                    mRenderers.add(new ScatterChartRenderer(chart, animator, viewPortHandler));
                break;
        }
    }
}
 
Example 19
Source Project: NetKnight   Source File: XShapeRenderer.java    License: 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 20
Source Project: iMoney   Source File: DefaultValueFormatter.java    License: 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 Project: iMoney   Source File: MoveViewJob.java    License: 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 Project: NetKnight   Source File: LegendRenderer.java    License: 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 23
Source Project: iMoney   Source File: XAxisRenderer.java    License: 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 24
Source Project: iMoney   Source File: ScatterChartRenderer.java    License: 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 25
Source Project: Ticket-Analysis   Source File: AnimatedZoomJob.java    License: 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 26
Source Project: Ticket-Analysis   Source File: AnimatedMoveViewJob.java    License: 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 27
Source Project: android-kline   Source File: DefaultValueFormatter.java    License: 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 28
Source Project: Ticket-Analysis   Source File: ZoomJob.java    License: 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 29
Source Project: StockChart-MPAndroidChart   Source File: ZoomJob.java    License: 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 30
Source Project: StockChart-MPAndroidChart   Source File: ViewPortJob.java    License: 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;

}