Java Code Examples for com.github.mikephil.charting.highlight.Highlight#setDraw()

The following examples show how to use com.github.mikephil.charting.highlight.Highlight#setDraw() . 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: RadarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    float sliceangle = mChart.getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0, 0);

    RadarData radarData = mChart.getData();

    for (Highlight high : indices) {

        IRadarDataSet set = radarData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled()) {
            continue;
        }

        RadarEntry e = set.getEntryForIndex((int) high.getX());

        if (!isInBoundsX(e, set)) {
            continue;
        }

        float y = (e.getY() - mChart.getYChartMin());

        Utils.getPosition(center,
                y * factor * mAnimator.getPhaseY(),
                sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle(),
                pOut);

        high.setDraw(pOut.x, pOut.y);

        // draw the lines
        drawHighlightLines(c, pOut.x, pOut.y, set);

        if (set.isDrawHighlightCircleEnabled()) {

            if (!Float.isNaN(pOut.x) && !Float.isNaN(pOut.y)) {

                int strokeColor = set.getHighlightCircleStrokeColor();
                if (strokeColor == ColorTemplate.COLOR_NONE) {
                    strokeColor = set.getColor(0);
                }

                if (set.getHighlightCircleStrokeAlpha() < 255) {
                    strokeColor = ColorTemplate.colorWithAlpha(strokeColor, set.getHighlightCircleStrokeAlpha());
                }

                drawHighlightCircle(c,
                        pOut,
                        set.getHighlightCircleInnerRadius(),
                        set.getHighlightCircleOuterRadius(),
                        set.getHighlightCircleFillColor(),
                        strokeColor,
                        set.getHighlightCircleStrokeWidth());
            }
        }
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
 
Example 2
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    ScatterData scatterData = mChart.getScatterData();

    for (Highlight high : indices) {

        IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        final Entry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator
                .getPhaseY());

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 3
Source File: LineChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    LineData lineData = mChart.getLineData();

    for (Highlight high : indices) {

        ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        Entry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator
                .getPhaseY());

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 4
Source File: RadarChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    float sliceangle = mChart.getSliceAngle();

    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0,0);

    RadarData radarData = mChart.getData();

    for (Highlight high : indices) {

        IRadarDataSet set = radarData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        RadarEntry e = set.getEntryForIndex((int) high.getX());

        if (!isInBoundsX(e, set))
            continue;

        float y = (e.getY() - mChart.getYChartMin());

        Utils.getPosition(center,
                y * factor * mAnimator.getPhaseY(),
                sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle(),
                pOut);

        high.setDraw(pOut.x, pOut.y);

        // draw the lines
        drawHighlightLines(c, pOut.x, pOut.y, set);

        if (set.isDrawHighlightCircleEnabled()) {

            if (!Float.isNaN(pOut.x) && !Float.isNaN(pOut.y)) {

                int strokeColor = set.getHighlightCircleStrokeColor();
                if (strokeColor == ColorTemplate.COLOR_NONE) {
                    strokeColor = set.getColor(0);
                }

                if (set.getHighlightCircleStrokeAlpha() < 255) {
                    strokeColor = ColorTemplate.colorWithAlpha(strokeColor, set.getHighlightCircleStrokeAlpha());
                }

                drawHighlightCircle(c,
                        pOut,
                        set.getHighlightCircleInnerRadius(),
                        set.getHighlightCircleOuterRadius(),
                        set.getHighlightCircleFillColor(),
                        strokeColor,
                        set.getHighlightCircleStrokeWidth());
            }
        }
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
 
Example 5
Source File: BubbleChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

    float phaseY = mAnimator.getPhaseY();

    for (Highlight high : indices) {

        IBubbleDataSet set = bubbleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        final BubbleEntry entry = set.getEntryForXValue(high.getX(), high.getY());

        if (entry.getY() != high.getY())
            continue;

        if (!isInBoundsX(entry, set))
            continue;

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        sizeBuffer[0] = 0f;
        sizeBuffer[2] = 1f;

        trans.pointValuesToPixel(sizeBuffer);

        boolean normalizeSize = set.isNormalizeSizeEnabled();

        // calcualte the full width of 1 step on the x-axis
        final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
        final float maxBubbleHeight = Math.abs(
                mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
        final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);

        pointBuffer[0] = entry.getX();
        pointBuffer[1] = (entry.getY()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);

        high.setDraw(pointBuffer[0], pointBuffer[1]);

        float shapeHalf = getShapeSize(entry.getSize(),
                set.getMaxSize(),
                referenceSize,
                normalizeSize) / 2f;

        if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf)
                || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf))
            continue;

        if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf))
            continue;

        if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf))
            break;

        final int originalColor = set.getColor((int) entry.getX());

        Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor),
                Color.blue(originalColor), _hsvBuffer);
        _hsvBuffer[2] *= 0.5f;
        final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer);

        mHighlightPaint.setColor(color);
        mHighlightPaint.setStrokeWidth(set.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
 
Example 6
Source File: HorizontalBarChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerY(), bar.right);
}
 
Example 7
Source File: ScatterChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    ScatterData scatterData = mChart.getScatterData();

    for (Highlight high : indices) {

        IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        final Entry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator
                .getPhaseY());

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 8
Source File: HorizontalBarChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerY(), bar.right);
}
 
Example 9
Source File: HorizontalBarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerY(), bar.right);
}
 
Example 10
Source File: BubbleChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

    float phaseY = mAnimator.getPhaseY();

    for (Highlight high : indices) {

        IBubbleDataSet set = bubbleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        final BubbleEntry entry = set.getEntryForXValue(high.getX(), high.getY());

        if (entry.getY() != high.getY())
            continue;

        if (!isInBoundsX(entry, set))
            continue;

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        sizeBuffer[0] = 0f;
        sizeBuffer[2] = 1f;

        trans.pointValuesToPixel(sizeBuffer);

        boolean normalizeSize = set.isNormalizeSizeEnabled();

        // calcualte the full width of 1 step on the x-axis
        final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
        final float maxBubbleHeight = Math.abs(
                mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
        final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);

        pointBuffer[0] = entry.getX();
        pointBuffer[1] = (entry.getY()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);

        high.setDraw(pointBuffer[0], pointBuffer[1]);

        float shapeHalf = getShapeSize(entry.getSize(),
                set.getMaxSize(),
                referenceSize,
                normalizeSize) / 2f;

        if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf)
                || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf))
            continue;

        if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf))
            continue;

        if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf))
            break;

        final int originalColor = set.getColor((int) entry.getX());

        Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor),
                Color.blue(originalColor), _hsvBuffer);
        _hsvBuffer[2] *= 0.5f;
        final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer);

        mHighlightPaint.setColor(color);
        mHighlightPaint.setStrokeWidth(set.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
 
Example 11
Source File: BubbleChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

    float phaseY = mAnimator.getPhaseY();

    for (Highlight high : indices) {

        IBubbleDataSet set = bubbleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled()) {
            continue;
        }

        final BubbleEntry entry = set.getEntryForXValue(high.getX(), high.getY());

        if (entry.getY() != high.getY()) {
            continue;
        }

        if (!isInBoundsX(entry, set)) {
            continue;
        }

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        sizeBuffer[0] = 0f;
        sizeBuffer[2] = 1f;

        trans.pointValuesToPixel(sizeBuffer);

        boolean normalizeSize = set.isNormalizeSizeEnabled();

        // calcualte the full width of 1 step on the x-axis
        final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
        final float maxBubbleHeight = Math.abs(
                mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
        final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);

        pointBuffer[0] = entry.getX();
        pointBuffer[1] = (entry.getY()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);

        high.setDraw(pointBuffer[0], pointBuffer[1]);

        float shapeHalf = getShapeSize(entry.getSize(),
                set.getMaxSize(),
                referenceSize,
                normalizeSize) / 2f;

        if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf)
                || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf)) {
            continue;
        }

        if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) {
            continue;
        }

        if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) {
            break;
        }

        final int originalColor = set.getColor((int) entry.getX());

        Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor),
                Color.blue(originalColor), _hsvBuffer);
        _hsvBuffer[2] *= 0.5f;
        final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer);

        mHighlightPaint.setColor(color);
        mHighlightPaint.setStrokeWidth(set.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
 
Example 12
Source File: LineChartRenderer.java    From android-kline with Apache License 2.0 3 votes vote down vote up
@Override
    public void drawHighlighted(Canvas c, Highlight[] indices) {

        LineData lineData = mChart.getLineData();

        for (Highlight high : indices) {

            ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());

            if (set == null || !set.isHighlightEnabled())
                continue;

            Entry e = set.getEntryForXValue(high.getX(), high.getY());

            if (!isInBoundsX(e, set))
                continue;

            MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator
                    .getPhaseY());

            high.setDraw((float) pix.x, (float) pix.y);

            // draw the lines
            drawHighlightLines(c, (float) pix.x, (float) pix.y, set);

            // draw circle
//            drawCircle(c, high, (float) pix.x);
        }
    }
 
Example 13
Source File: CandleStickChartRenderer.java    From Ticket-Analysis with MIT License 3 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    CandleData candleData = mChart.getCandleData();

    for (Highlight high : indices) {

        ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        CandleEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        float lowValue = e.getLow() * mAnimator.getPhaseY();
        float highValue = e.getHigh() * mAnimator.getPhaseY();
        float y = (lowValue + highValue) / 2f;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), y);

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 14
Source File: CandleStickChartRenderer.java    From StockChart-MPAndroidChart with MIT License 3 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    CandleData candleData = mChart.getCandleData();

    for (Highlight high : indices) {

        ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled()) {
            continue;
        }

        CandleEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set)) {
            continue;
        }

        float lowValue = e.getLow() * mAnimator.getPhaseY();
        float highValue = e.getHigh() * mAnimator.getPhaseY();
        float y = (lowValue + highValue) / 2f;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), y);

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 15
Source File: LineChartRenderer.java    From StockChart-MPAndroidChart with MIT License 3 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    LineData lineData = mChart.getLineData();

    for (Highlight high : indices) {

        ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled()) {
            continue;
        }

        Entry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator
                .getPhaseY());

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 16
Source File: CandleStickChartRenderer.java    From android-kline with Apache License 2.0 3 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    CandleData candleData = mChart.getCandleData();

    for (Highlight high : indices) {

        ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        CandleEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        float lowValue = e.getLow() * mAnimator.getPhaseY();
        float highValue = e.getHigh() * mAnimator.getPhaseY();
        float y = (lowValue + highValue) / 2f;

        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), y);

        high.setDraw((float) pix.x, (float) pix.y);

        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
 
Example 17
Source File: BarChartRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the drawing position of the highlight object based on the riven bar-rect.
 *
 * @param high
 */
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerX(), bar.top);
}
 
Example 18
Source File: BarChartRenderer.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Sets the drawing position of the highlight object based on the riven bar-rect.
 * @param high
 */
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerX(), bar.top);
}
 
Example 19
Source File: BarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * Sets the drawing position of the highlight object based on the riven bar-rect.
 *
 * @param high
 */
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerX(), bar.top);
}
 
Example 20
Source File: BarChartRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the drawing position of the highlight object based on the riven bar-rect.
 * @param high
 */
protected void setHighlightDrawPos(Highlight high, RectF bar) {
    high.setDraw(bar.centerX(), bar.top);
}