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

The following examples show how to use com.github.mikephil.charting.utils.Transformer. 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: StockChart-MPAndroidChart   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 2
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 3
Source Project: Ticket-Analysis   Source File: LineChartRenderer.java    License: MIT License 6 votes vote down vote up
protected void drawCubicFill(Canvas c, ILineDataSet dataSet, Path spline, Transformer trans, XBounds bounds) {

        float fillMin = dataSet.getFillFormatter()
                .getFillLinePosition(dataSet, mChart);

        spline.lineTo(dataSet.getEntryForIndex(bounds.min + bounds.range).getX(), fillMin);
        spline.lineTo(dataSet.getEntryForIndex(bounds.min).getX(), fillMin);
        spline.close();

        trans.pathValueToPixel(spline);

        final Drawable drawable = dataSet.getFillDrawable();
        if (drawable != null) {

            drawFilledPath(c, spline, drawable);
        } else {

            drawFilledPath(c, spline, dataSet.getFillColor(), dataSet.getFillAlpha());
        }
    }
 
Example 4
Source Project: NetKnight   Source File: LineChartRenderer.java    License: Apache License 2.0 6 votes vote down vote up
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, int minx,
                              int maxx,
                              Transformer trans) {

    Path filled = generateFilledPath(
            dataSet, minx, maxx);

    trans.pathValueToPixel(filled);

    final Drawable drawable = dataSet.getFillDrawable();
    if (drawable != null) {

        drawFilledPath(c, filled, drawable);
    } else {

        drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
    }
}
 
Example 5
Source Project: android-kline   Source File: AxisRenderer.java    License: Apache License 2.0 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 6
Source Project: NetKnight   Source File: YAxisRenderer.java    License: Apache License 2.0 5 votes vote down vote up
public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) {
    super(viewPortHandler, trans);

    this.mYAxis = yAxis;

    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 7
Source Project: android-kline   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 8
Source Project: StockChart-MPAndroidChart   Source File: BarChartRenderer.java    License: MIT License 5 votes vote down vote up
protected void prepareBarHighlight(float x, float y1, float y2, float barWidthHalf, Transformer trans) {

        float left = x - barWidthHalf;
        float right = x + barWidthHalf;
        float top = y1;
        float bottom = y2;

        mBarRect.set(left, top, right, bottom);

        trans.rectToPixelPhase(mBarRect, mAnimator.getPhaseY());
    }
 
Example 9
Source Project: Stayfit   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 10
Source Project: android-kline   Source File: AnimatedZoomJob.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public AnimatedZoomJob(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) {
    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.xAxisRange = xAxisRange;
}
 
Example 11
@Override
protected void prepareBarHighlight(float x, float y1, float y2, float barWidthHalf, Transformer trans) {

    float top = x - barWidthHalf;
    float bottom = x + barWidthHalf;
    float left = y1;
    float right = y2;

    mBarRect.set(left, top, right, bottom);

    trans.rectToPixelPhaseHorizontal(mBarRect, mAnimator.getPhaseY());
}
 
Example 12
Source Project: android-kline   Source File: LineChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Draws a filled linear path on the canvas.
 *
 * @param c
 * @param dataSet
 * @param trans
 * @param bounds
 */
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, XBounds bounds) {

    final Path filled = mGenerateFilledPathBuffer;

    final int startingIndex = bounds.min;
    final int endingIndex = bounds.range + bounds.min;
    final int indexInterval = 128;

    int currentStartIndex = 0;
    int currentEndIndex = indexInterval;
    int iterations = 0;

    // Doing this iteratively in order to avoid OutOfMemory errors that can happen on large bounds sets.
    do {
        currentStartIndex = startingIndex + (iterations * indexInterval);
        currentEndIndex = currentStartIndex + indexInterval;
        currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex;

        if (currentStartIndex <= currentEndIndex) {
            generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled);

            trans.pathValueToPixel(filled);

            final Drawable drawable = dataSet.getFillDrawable();
            if (drawable != null) {

                drawFilledPath(c, filled, drawable);
            } else {

                drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
            }
        }

        iterations++;

    } while (currentStartIndex <= currentEndIndex);

}
 
Example 13
Source Project: Stayfit   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 14
Source Project: StockChart-MPAndroidChart   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 15
Source Project: android-kline   Source File: AnimatedZoomJob.java    License: Apache License 2.0 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 16
Source Project: StockChart-MPAndroidChart   Source File: AnimatedZoomJob.java    License: MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
public AnimatedZoomJob(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) {
    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.xAxisRange = xAxisRange;
}
 
Example 17
Source Project: StockChart-MPAndroidChart   Source File: AnimatedViewPortJob.java    License: MIT License 5 votes vote down vote up
public AnimatedViewPortJob(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v, float xOrigin, float yOrigin, long duration) {
    super(viewPortHandler, xValue, yValue, trans, v);
    this.xOrigin = xOrigin;
    this.yOrigin = yOrigin;
    animator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f);
    animator.setDuration(duration);
    animator.addUpdateListener(this);
    animator.addListener(this);
}
 
Example 18
Source Project: StockChart-MPAndroidChart   Source File: MoveViewJob.java    License: MIT License 5 votes vote down vote up
public static MoveViewJob getInstance(ViewPortHandler viewPortHandler, float xValue, float yValue, Transformer trans, View v) {
    MoveViewJob result = pool.get();
    result.mViewPortHandler = viewPortHandler;
    result.xValue = xValue;
    result.yValue = yValue;
    result.mTrans = trans;
    result.view = v;
    return result;
}
 
Example 19
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 20
Source Project: Ticket-Analysis   Source File: BarLineChartBase.java    License: MIT License 5 votes vote down vote up
@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));
}
 
Example 21
Source Project: Ticket-Analysis   Source File: LineChartRenderer.java    License: MIT License 5 votes vote down vote up
/**
 * Draws a filled linear path on the canvas.
 *
 * @param c
 * @param dataSet
 * @param trans
 * @param bounds
 */
protected void drawLinearFill(Canvas c, ILineDataSet dataSet, Transformer trans, XBounds bounds) {

    final Path filled = mGenerateFilledPathBuffer;

    final int startingIndex = bounds.min;
    final int endingIndex = bounds.range + bounds.min;
    final int indexInterval = 128;

    int currentStartIndex = 0;
    int currentEndIndex = indexInterval;
    int iterations = 0;

    // Doing this iteratively in order to avoid OutOfMemory errors that can happen on large bounds sets.
    do {
        currentStartIndex = startingIndex + (iterations * indexInterval);
        currentEndIndex = currentStartIndex + indexInterval;
        currentEndIndex = currentEndIndex > endingIndex ? endingIndex : currentEndIndex;

        if (currentStartIndex <= currentEndIndex) {
            generateFilledPath(dataSet, currentStartIndex, currentEndIndex, filled);

            trans.pathValueToPixel(filled);

            final Drawable drawable = dataSet.getFillDrawable();
            if (drawable != null) {

                drawFilledPath(c, filled, drawable);
            } else {

                drawFilledPath(c, filled, dataSet.getFillColor(), dataSet.getFillAlpha());
            }
        }

        iterations++;

    } while (currentStartIndex <= currentEndIndex);

}
 
Example 22
Source Project: Stayfit   Source File: BarLineChartBase.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    mAxisLeft = new YAxis(AxisDependency.LEFT);
    mAxisRight = new YAxis(AxisDependency.RIGHT);

    mXAxis = new XAxis();

    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());

    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));
}
 
Example 23
Source Project: Ticket-Analysis   Source File: XAxisRenderer.java    License: MIT License 5 votes vote down vote up
public XAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans) {
    super(viewPortHandler, trans, xAxis);

    this.mXAxis = xAxis;

    mAxisLabelPaint.setColor(Color.BLACK);
    mAxisLabelPaint.setTextAlign(Align.CENTER);
    mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
}
 
Example 24
Source Project: iMoney   Source File: YAxisRenderer.java    License: Apache License 2.0 5 votes vote down vote up
public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) {
    super(viewPortHandler, trans);

    this.mYAxis = yAxis;

    mAxisLabelPaint.setColor(Color.BLACK);
    mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
}
 
Example 25
Source Project: Ticket-Analysis   Source File: HorizontalBarChartRenderer.java    License: MIT License 5 votes vote down vote up
@Override
protected void prepareBarHighlight(float x, float y1, float y2, float barWidthHalf, Transformer trans) {

    float top = x - barWidthHalf;
    float bottom = x + barWidthHalf;
    float left = y1;
    float right = y2;

    mBarRect.set(left, top, right, bottom);

    trans.rectToPixelPhaseHorizontal(mBarRect, mAnimator.getPhaseY());
}
 
Example 26
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 27
Source Project: Ticket-Analysis   Source File: AnimatedZoomJob.java    License: MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
public AnimatedZoomJob(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) {
    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.xAxisRange = xAxisRange;
}
 
Example 28
Source Project: android-kline   Source File: BarLineChartBase.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 29
public YAxisRendererKline(ViewPortHandler viewPortHandler, MyYAxis yAxis, Transformer trans) {
    super(viewPortHandler, yAxis, trans);
    mYAxis = yAxis;
}
 
Example 30
Source Project: iMoney   Source File: YAxisRendererHorizontalBarChart.java    License: Apache License 2.0 4 votes vote down vote up
public YAxisRendererHorizontalBarChart(ViewPortHandler viewPortHandler, YAxis yAxis,
        Transformer trans) {
    super(viewPortHandler, yAxis, trans);
    
    mLimitLinePaint.setTextAlign(Align.LEFT);
}