Java Code Examples for com.github.mikephil.charting.utils.Utils#drawImage()

The following examples show how to use com.github.mikephil.charting.utils.Utils#drawImage() . 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 drawValues(Canvas c) {

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    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);
    MPPointF pIcon = MPPointF.getInstance(0, 0);

    float yoffset = Utils.convertDpToPixel(5f);

    for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {

        IRadarDataSet dataSet = mChart.getData().getDataSetByIndex(i);

        if (!shouldDrawValues(dataSet)) {
            continue;
        }

        // apply the text-styling defined by the DataSet
        applyValueTextStyle(dataSet);

        ValueFormatter formatter = dataSet.getValueFormatter();

        MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
        iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
        iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

        for (int j = 0; j < dataSet.getEntryCount(); j++) {

            RadarEntry entry = dataSet.getEntryForIndex(j);

            Utils.getPosition(
                    center,
                    (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
                    sliceangle * j * phaseX + mChart.getRotationAngle(),
                    pOut);

            if (dataSet.isDrawValuesEnabled()) {
                drawValue(c, formatter.getRadarLabel(entry), pOut.x, pOut.y - yoffset, dataSet.getValueTextColor(j));
            }

            if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                Drawable icon = entry.getIcon();

                Utils.getPosition(
                        center,
                        (entry.getY()) * factor * phaseY + iconsOffset.y,
                        sliceangle * j * phaseX + mChart.getRotationAngle(),
                        pIcon);

                //noinspection SuspiciousNameCombination
                pIcon.y += iconsOffset.x;

                Utils.drawImage(
                        c,
                        icon,
                        (int) pIcon.x,
                        (int) pIcon.y,
                        icon.getIntrinsicWidth(),
                        icon.getIntrinsicHeight());
            }
        }

        MPPointF.recycleInstance(iconsOffset);
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
    MPPointF.recycleInstance(pIcon);
}
 
Example 2
Source File: ScatterChartRenderer.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {

        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();

        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {

            IScatterDataSet dataSet = dataSets.get(i);

            if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1)
                continue;

            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);

            mXBounds.set(mChart, dataSet);

            float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
                    .generateTransformedValuesScatter(dataSet,
                            mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

            float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());

            ValueFormatter formatter = dataSet.getValueFormatter();

            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

            for (int j = 0; j < positions.length; j += 2) {

                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;

                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j])
                        || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;

                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c, formatter.getPointLabel(entry), positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }

                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                    Drawable icon = entry.getIcon();

                    Utils.drawImage(
                            c,
                            icon,
                            (int) (positions[j] + iconsOffset.x),
                            (int) (positions[j + 1] + iconsOffset.y),
                            icon.getIntrinsicWidth(),
                            icon.getIntrinsicHeight());
                }
            }

            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
 
Example 3
Source File: RadarChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    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);
    MPPointF pIcon = MPPointF.getInstance(0,0);

    float yoffset = Utils.convertDpToPixel(5f);

    for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {

        IRadarDataSet dataSet = mChart.getData().getDataSetByIndex(i);

        if (!shouldDrawValues(dataSet))
            continue;

        // apply the text-styling defined by the DataSet
        applyValueTextStyle(dataSet);

        MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
        iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
        iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

        for (int j = 0; j < dataSet.getEntryCount(); j++) {

            RadarEntry entry = dataSet.getEntryForIndex(j);

             Utils.getPosition(
                     center,
                     (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
                     sliceangle * j * phaseX + mChart.getRotationAngle(),
                     pOut);

            if (dataSet.isDrawValuesEnabled()) {
                drawValue(c,
                        dataSet.getValueFormatter(),
                        entry.getY(),
                        entry,
                        i,
                        pOut.x,
                        pOut.y - yoffset,
                        dataSet.getValueTextColor
                                (j));
            }

            if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                Drawable icon = entry.getIcon();

                Utils.getPosition(
                        center,
                        (entry.getY()) * factor * phaseY + iconsOffset.y,
                        sliceangle * j * phaseX + mChart.getRotationAngle(),
                        pIcon);

                //noinspection SuspiciousNameCombination
                pIcon.y += iconsOffset.x;

                Utils.drawImage(
                        c,
                        icon,
                        (int)pIcon.x,
                        (int)pIcon.y,
                        icon.getIntrinsicWidth(),
                        icon.getIntrinsicHeight());
            }
        }

        MPPointF.recycleInstance(iconsOffset);
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
    MPPointF.recycleInstance(pIcon);
}
 
Example 4
Source File: ScatterChartRenderer.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {

        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();

        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {

            IScatterDataSet dataSet = dataSets.get(i);

            if (!shouldDrawValues(dataSet))
                continue;

            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);

            mXBounds.set(mChart, dataSet);

            float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
                    .generateTransformedValuesScatter(dataSet,
                            mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

            float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());

            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

            for (int j = 0; j < positions.length; j += 2) {

                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;

                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j])
                        || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;

                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c,
                            dataSet.getValueFormatter(),
                            entry.getY(),
                            entry,
                            i,
                            positions[j],
                            positions[j + 1] - shapeSize,
                            dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }

                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                    Drawable icon = entry.getIcon();

                    Utils.drawImage(
                            c,
                            icon,
                            (int)(positions[j] + iconsOffset.x),
                            (int)(positions[j + 1] + iconsOffset.y),
                            icon.getIntrinsicWidth(),
                            icon.getIntrinsicHeight());
                }
            }

            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
 
Example 5
Source File: RadarChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    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);
    MPPointF pIcon = MPPointF.getInstance(0,0);

    float yoffset = Utils.convertDpToPixel(5f);

    for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {

        IRadarDataSet dataSet = mChart.getData().getDataSetByIndex(i);

        if (!shouldDrawValues(dataSet))
            continue;

        // apply the text-styling defined by the DataSet
        applyValueTextStyle(dataSet);

        MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
        iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
        iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

        for (int j = 0; j < dataSet.getEntryCount(); j++) {

            RadarEntry entry = dataSet.getEntryForIndex(j);

             Utils.getPosition(
                     center,
                     (entry.getY() - mChart.getYChartMin()) * factor * phaseY,
                     sliceangle * j * phaseX + mChart.getRotationAngle(),
                     pOut);

            if (dataSet.isDrawValuesEnabled()) {
                drawValue(c,
                        dataSet.getValueFormatter(),
                        entry.getY(),
                        entry,
                        i,
                        pOut.x,
                        pOut.y - yoffset,
                        dataSet.getValueTextColor
                                (j));
            }

            if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                Drawable icon = entry.getIcon();

                Utils.getPosition(
                        center,
                        (entry.getY()) * factor * phaseY + iconsOffset.y,
                        sliceangle * j * phaseX + mChart.getRotationAngle(),
                        pIcon);

                //noinspection SuspiciousNameCombination
                pIcon.y += iconsOffset.x;

                Utils.drawImage(
                        c,
                        icon,
                        (int)pIcon.x,
                        (int)pIcon.y,
                        icon.getIntrinsicWidth(),
                        icon.getIntrinsicHeight());
            }
        }

        MPPointF.recycleInstance(iconsOffset);
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
    MPPointF.recycleInstance(pIcon);
}
 
Example 6
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {

        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();

        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {

            IScatterDataSet dataSet = dataSets.get(i);

            if (!shouldDrawValues(dataSet))
                continue;

            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);

            mXBounds.set(mChart, dataSet);

            float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
                    .generateTransformedValuesScatter(dataSet,
                            mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

            float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());

            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

            for (int j = 0; j < positions.length; j += 2) {

                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;

                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j])
                        || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;

                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c,
                            dataSet.getValueFormatter(),
                            entry.getY(),
                            entry,
                            i,
                            positions[j],
                            positions[j + 1] - shapeSize,
                            dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }

                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                    Drawable icon = entry.getIcon();

                    Utils.drawImage(
                            c,
                            icon,
                            (int)(positions[j] + iconsOffset.x),
                            (int)(positions[j + 1] + iconsOffset.y),
                            icon.getIntrinsicWidth(),
                            icon.getIntrinsicHeight());
                }
            }

            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
 
Example 7
Source File: ScatterChartRenderer.java    From android-kline with Apache License 2.0 4 votes vote down vote up
@Override
public void drawValues(Canvas c) {

    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {

        List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();

        for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {

            IScatterDataSet dataSet = dataSets.get(i);

            if (!shouldDrawValues(dataSet))
                continue;

            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);

            mXBounds.set(mChart, dataSet);

            float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
                    .generateTransformedValuesScatter(dataSet,
                            mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);

            float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());

            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);

            for (int j = 0; j < positions.length; j += 2) {

                if (!mViewPortHandler.isInBoundsRight(positions[j]))
                    break;

                // make sure the lines don't do shitty things outside bounds
                if ((!mViewPortHandler.isInBoundsLeft(positions[j])
                        || !mViewPortHandler.isInBoundsY(positions[j + 1])))
                    continue;

                Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);

                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c,
                            dataSet.getValueFormatter(),
                            entry.getY(),
                            entry,
                            i,
                            positions[j],
                            positions[j + 1] - shapeSize,
                            dataSet.getValueTextColor(j / 2 + mXBounds.min));
                }

                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {

                    Drawable icon = entry.getIcon();

                    Utils.drawImage(
                            c,
                            icon,
                            (int)(positions[j] + iconsOffset.x),
                            (int)(positions[j + 1] + iconsOffset.y),
                            icon.getIntrinsicWidth(),
                            icon.getIntrinsicHeight());
                }
            }

            MPPointF.recycleInstance(iconsOffset);
        }
    }
}