com.github.mikephil.charting.data.BubbleEntry Java Examples

The following examples show how to use com.github.mikephil.charting.data.BubbleEntry. 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: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private BubbleData generateBubbleData() {

        BubbleData bd = new BubbleData();

        ArrayList<BubbleEntry> entries = new ArrayList<>();

        for (int index = 0; index < count; 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;
    }
 
Example #2
Source File: BubbleChartManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@Override
BubbleEntry createEntry(ReadableArray yValues, int index) {
    if (!ReadableType.Map.equals(yValues.getType(index))) {
        throw new IllegalArgumentException("Invalid BubbleEntry data");
    }

    ReadableMap entry = yValues.getMap(index);
    if(!BridgeUtils.validate(entry, ReadableType.Number, "value") ||
            !BridgeUtils.validate(entry, ReadableType.Number, "size")) {
        throw new IllegalArgumentException("Invalid BubbleEntry data");
    }

    float value = (float) entry.getDouble("value");
    float size = (float) entry.getDouble("size");

    return new BubbleEntry(index, value, size);
}
 
Example #3
Source File: CombinedChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected BubbleData generateBubbleData() {

        BubbleData bd = new BubbleData();

        ArrayList<BubbleEntry> entries = new ArrayList<BubbleEntry>();

        for (int index = 0; index < itemcount; index++) {
            float rnd = getRandom(20, 30);
            entries.add(new BubbleEntry(index, rnd, rnd));
        }

        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;
    }
 
Example #4
Source File: RealmBubbleDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
@Override
protected void calcMinMax(BubbleEntry e) {
    super.calcMinMax(e);

    final float size = e.getSize();

    if (size > mMaxSize) {
        mMaxSize = size;
    }
}
 
Example #5
Source File: RealmBubbleDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
@Override
public BubbleEntry buildEntryFromResultObject(T realmObject, float x) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    return new BubbleEntry(
            mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField),
            dynamicObject.getFloat(mYValuesField),
            dynamicObject.getFloat(mSizeField));
}
 
Example #6
Source File: BubbleChartManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
@Override
void dataSetConfig(IDataSet<BubbleEntry> dataSet, ReadableMap config) {
    BubbleDataSet bubbleDataSet = (BubbleDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(bubbleDataSet, config);
    ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(bubbleDataSet, config);

    // BubbleDataSet only config
    if (BridgeUtils.validate(config, ReadableType.Number, "highlightCircleWidth")) {
        bubbleDataSet.setHighlightCircleWidth((float) config.getDouble("highlightCircleWidth"));
    }
}
 
Example #7
Source File: RealmBubbleDataSet.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public BubbleEntry buildEntryFromResultObject(T realmObject, int xIndex) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    return new BubbleEntry(
            mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField),
            dynamicObject.getFloat(mValuesField),
            dynamicObject.getFloat(mSizeField));
}
 
Example #8
Source File: RealmBubbleDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private float xMax(BubbleEntry entry) {
    return (float) entry.getXIndex();
}
 
Example #9
Source File: RealmBubbleDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private float largestSize(BubbleEntry entry) {
    return entry.getSize();
}
 
Example #10
Source File: BubbleChartRenderer.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

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

    for (Highlight indice : indices) {

        IBubbleDataSet dataSet = bubbleData.getDataSetByIndex(indice.getDataSetIndex());

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

        BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX);
        BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX);

        int minx = dataSet.getEntryIndex(entryFrom);
        int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount());

        final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(indice);
        if (entry == null || entry.getXIndex() != indice.getXIndex())
            continue;

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

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

        trans.pointValuesToPixel(sizeBuffer);

        // 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] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx;
        pointBuffer[1] = (float) (entry.getVal()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);

        float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize) / 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;

        if (indice.getXIndex() < minx || indice.getXIndex() >= maxx)
            continue;

        final int originalColor = dataSet.getColor(entry.getXIndex());

        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(dataSet.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
 
Example #11
Source File: RealmBubbleDataSet.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
private float yMin(BubbleEntry entry) {
    return entry.getVal();
}
 
Example #12
Source File: RealmBubbleDataSet.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
private float yMax(BubbleEntry entry) {
    return entry.getVal();
}
 
Example #13
Source File: RealmBubbleDataSet.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
private float xMin(BubbleEntry entry) {
    return (float) entry.getXIndex();
}
 
Example #14
Source File: RealmBubbleDataSet.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
private float xMax(BubbleEntry entry) {
    return (float) entry.getXIndex();
}
 
Example #15
Source File: RealmBubbleDataSet.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
private float largestSize(BubbleEntry entry) {
    return entry.getSize();
}
 
Example #16
Source File: BubbleChartRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

    float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX()));
    float phaseY = mAnimator.getPhaseY();

    for (Highlight high : indices) {

        final int minDataSetIndex = high.getDataSetIndex() == -1
                ? 0
                : high.getDataSetIndex();
        final int maxDataSetIndex = high.getDataSetIndex() == -1
                ? bubbleData.getDataSetCount()
                : (high.getDataSetIndex() + 1);
        if (maxDataSetIndex - minDataSetIndex < 1) continue;

        for (int dataSetIndex = minDataSetIndex;
             dataSetIndex < maxDataSetIndex;
             dataSetIndex++) {

            IBubbleDataSet dataSet = bubbleData.getDataSetByIndex(dataSetIndex);

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

            final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(high);
            if (entry == null || entry.getXIndex() != high.getXIndex())
                continue;

            BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX);
            BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX);

            int minx = dataSet.getEntryIndex(entryFrom);
            int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount());

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

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

            pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx;
            pointBuffer[1] = (float) (entry.getVal()) * 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;

            if (high.getXIndex() < minx || high.getXIndex() >= maxx)
                continue;

            final int originalColor = dataSet.getColor(entry.getXIndex());

            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(dataSet.getHighlightCircleWidth());
            c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
        }
    }
}
 
Example #17
Source File: BubbleChartManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
@Override
IDataSet createDataSet(ArrayList<BubbleEntry> entries, String label) {
    return new BubbleDataSet(entries, label);
}
 
Example #18
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 #19
Source File: BubbleChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

    int count = seekBarX.getProgress();
    int range = seekBarY.getProgress();

    tvX.setText(String.valueOf(count));
    tvY.setText(String.valueOf(range));

    ArrayList<BubbleEntry> values1 = new ArrayList<>();
    ArrayList<BubbleEntry> values2 = new ArrayList<>();
    ArrayList<BubbleEntry> values3 = new ArrayList<>();

    for (int i = 0; i < count; i++) {
        values1.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
        values2.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range), getResources().getDrawable(R.drawable.star)));
        values3.add(new BubbleEntry(i, (float) (Math.random() * range), (float) (Math.random() * range)));
    }

    // create a dataset and give it a type
    BubbleDataSet set1 = new BubbleDataSet(values1, "DS 1");
    set1.setDrawIcons(false);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
    set1.setDrawValues(true);

    BubbleDataSet set2 = new BubbleDataSet(values2, "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(values3, "DS 3");
    set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
    set3.setDrawValues(true);

    ArrayList<IBubbleDataSet> dataSets = new ArrayList<>();
    dataSets.add(set1); // add the data sets
    dataSets.add(set2);
    dataSets.add(set3);

    // create a data object with the data sets
    BubbleData data = new BubbleData(dataSets);
    data.setDrawValues(false);
    data.setValueTypeface(tfLight);
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.WHITE);
    data.setHighlightCircleWidth(1.5f);

    chart.setData(data);
    chart.invalidate();
}
 
Example #20
Source File: RealmBubbleDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private float yMax(BubbleEntry entry) {
    return entry.getVal();
}
 
Example #21
Source File: RealmBubbleDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private float yMin(BubbleEntry entry) {
    return entry.getVal();
}
 
Example #22
Source File: BubbleChartRenderer.java    From iMoney with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

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

    for (Highlight indice : indices) {

        BubbleDataSet dataSet = bubbleData.getDataSetByIndex(indice.getDataSetIndex());

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

        Entry entryFrom = dataSet.getEntryForXIndex(mMinX);
        Entry entryTo = dataSet.getEntryForXIndex(mMaxX);

        int minx = dataSet.getEntryPosition(entryFrom);
        int maxx = Math.min(dataSet.getEntryPosition(entryTo) + 1, dataSet.getEntryCount());

        final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(indice);
        if (entry == null || entry.getXIndex() != indice.getXIndex())
            continue;

        Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
        
        sizeBuffer[0] = 0f;
        sizeBuffer[2] = 1f;

        trans.pointValuesToPixel(sizeBuffer);
        
        // 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] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx;
        pointBuffer[1] = (float) (entry.getVal()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);

        float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize) / 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;

        if (indice.getXIndex() < minx || indice.getXIndex() >= maxx)
            continue;

        final int originalColor = dataSet.getColor(entry.getXIndex());

        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(dataSet.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
 
Example #23
Source File: BubbleChartRenderer.java    From Ticket-Analysis 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 #24
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 #25
Source File: RealmBubbleDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private float xMin(BubbleEntry entry) {
    return (float) entry.getXIndex();
}
 
Example #26
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 #27
Source File: BubbleChartRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
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);
        }
    }
 
Example #28
Source File: BubbleChartRenderer.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
protected void drawDataSet(Canvas c, IBubbleDataSet dataSet) {

        if (dataSet.getEntryCount() < 1)
            return;

        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);
        }
    }
 
Example #29
Source File: BubbleChartRenderer.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
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);
        }
    }
 
Example #30
Source File: BubbleChartRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
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);
        }
    }