Search in sources :

Example 1 with BubbleEntry

use of com.github.mikephil.charting.data.BubbleEntry in project MPAndroidChart by PhilJay.

the class BubbleChartRenderer method drawDataSet.

protected void drawDataSet(Canvas c, IBubbleDataSet dataSet) {
    Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
    float phaseY = mAnimator.getPhaseY();
    mXBounds.set(mChart, dataSet);
    sizeBuffer[0] = 0f;
    sizeBuffer[2] = 1f;
    trans.pointValuesToPixel(sizeBuffer);
    boolean normalizeSize = dataSet.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);
    for (int j = mXBounds.min; j <= mXBounds.range + mXBounds.min; j++) {
        final BubbleEntry entry = dataSet.getEntryForIndex(j);
        pointBuffer[0] = entry.getX();
        pointBuffer[1] = (entry.getY()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);
        float shapeHalf = getShapeSize(entry.getSize(), dataSet.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 color = dataSet.getColor((int) entry.getX());
        mRenderPaint.setColor(color);
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mRenderPaint);
    }
}
Also used : BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) Transformer(com.github.mikephil.charting.utils.Transformer)

Example 2 with BubbleEntry

use of com.github.mikephil.charting.data.BubbleEntry in project MPAndroidChart by PhilJay.

the class BubbleChartRenderer method drawHighlighted.

@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);
    }
}
Also used : BubbleData(com.github.mikephil.charting.data.BubbleData) IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) Highlight(com.github.mikephil.charting.highlight.Highlight) Transformer(com.github.mikephil.charting.utils.Transformer)

Example 3 with BubbleEntry

use of com.github.mikephil.charting.data.BubbleEntry in project MPAndroidChart by PhilJay.

the class BubbleChartActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    int count = mSeekBarX.getProgress();
    int range = mSeekBarY.getProgress();
    tvX.setText("" + count);
    tvY.setText("" + range);
    ArrayList<BubbleEntry> yVals1 = new ArrayList<BubbleEntry>();
    ArrayList<BubbleEntry> yVals2 = new ArrayList<BubbleEntry>();
    ArrayList<BubbleEntry> yVals3 = new ArrayList<BubbleEntry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        float size = (float) (Math.random() * range);
        yVals1.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
    }
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        float size = (float) (Math.random() * range);
        yVals2.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
    }
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        float size = (float) (Math.random() * range);
        yVals3.add(new BubbleEntry(i, val, size));
    }
    // create a dataset and give it a type
    BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
    set1.setDrawIcons(false);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
    set1.setDrawValues(true);
    BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
    set2.setDrawIcons(false);
    set2.setIconsOffset(new MPPointF(0, 15));
    set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
    set2.setDrawValues(true);
    BubbleDataSet set3 = new BubbleDataSet(yVals3, "DS 3");
    set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
    set3.setDrawValues(true);
    ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
    // add the datasets
    dataSets.add(set1);
    dataSets.add(set2);
    dataSets.add(set3);
    // create a data object with the datasets
    BubbleData data = new BubbleData(dataSets);
    data.setDrawValues(false);
    data.setValueTypeface(mTfLight);
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.WHITE);
    data.setHighlightCircleWidth(1.5f);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleData(com.github.mikephil.charting.data.BubbleData) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) MPPointF(com.github.mikephil.charting.utils.MPPointF) ArrayList(java.util.ArrayList) IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleDataSet(com.github.mikephil.charting.data.BubbleDataSet)

Example 4 with BubbleEntry

use of com.github.mikephil.charting.data.BubbleEntry in project MPAndroidChart by PhilJay.

the class CombinedChartActivity method generateBubbleData.

protected BubbleData generateBubbleData() {
    BubbleData bd = new BubbleData();
    ArrayList<BubbleEntry> entries = new ArrayList<BubbleEntry>();
    for (int index = 0; index < itemcount; index++) {
        float y = getRandom(10, 105);
        float size = getRandom(100, 105);
        entries.add(new BubbleEntry(index + 0.5f, y, size));
    }
    BubbleDataSet set = new BubbleDataSet(entries, "Bubble DataSet");
    set.setColors(ColorTemplate.VORDIPLOM_COLORS);
    set.setValueTextSize(10f);
    set.setValueTextColor(Color.WHITE);
    set.setHighlightCircleWidth(1.5f);
    set.setDrawValues(true);
    bd.addDataSet(set);
    return bd;
}
Also used : BubbleData(com.github.mikephil.charting.data.BubbleData) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) ArrayList(java.util.ArrayList) BubbleDataSet(com.github.mikephil.charting.data.BubbleDataSet)

Example 5 with BubbleEntry

use of com.github.mikephil.charting.data.BubbleEntry in project MPAndroidChart by PhilJay.

the class BubbleChartRenderer method drawValues.

@Override
public void drawValues(Canvas c) {
    BubbleData bubbleData = mChart.getBubbleData();
    if (bubbleData == null)
        return;
    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {
        final List<IBubbleDataSet> dataSets = bubbleData.getDataSets();
        float lineHeight = Utils.calcTextHeight(mValuePaint, "1");
        for (int i = 0; i < dataSets.size(); i++) {
            IBubbleDataSet dataSet = dataSets.get(i);
            if (!shouldDrawValues(dataSet))
                continue;
            // apply the text-styling defined by the DataSet
            applyValueTextStyle(dataSet);
            final float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
            final float phaseY = mAnimator.getPhaseY();
            mXBounds.set(mChart, dataSet);
            final float[] positions = mChart.getTransformer(dataSet.getAxisDependency()).generateTransformedValuesBubble(dataSet, phaseY, mXBounds.min, mXBounds.max);
            final float alpha = phaseX == 1 ? phaseY : phaseX;
            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) {
                int valueTextColor = dataSet.getValueTextColor(j / 2 + mXBounds.min);
                valueTextColor = Color.argb(Math.round(255.f * alpha), Color.red(valueTextColor), Color.green(valueTextColor), Color.blue(valueTextColor));
                float x = positions[j];
                float y = positions[j + 1];
                if (!mViewPortHandler.isInBoundsRight(x))
                    break;
                if ((!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)))
                    continue;
                BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x, y + (0.5f * lineHeight), valueTextColor);
                }
                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
                    Drawable icon = entry.getIcon();
                    Utils.drawImage(c, icon, (int) (x + iconsOffset.x), (int) (y + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
                }
            }
            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
Also used : BubbleData(com.github.mikephil.charting.data.BubbleData) IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) MPPointF(com.github.mikephil.charting.utils.MPPointF) Drawable(android.graphics.drawable.Drawable)

Aggregations

BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)5 BubbleData (com.github.mikephil.charting.data.BubbleData)4 IBubbleDataSet (com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet)3 BubbleDataSet (com.github.mikephil.charting.data.BubbleDataSet)2 MPPointF (com.github.mikephil.charting.utils.MPPointF)2 Transformer (com.github.mikephil.charting.utils.Transformer)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1