當前位置: 首頁>>代碼示例>>Java>>正文


Java Highlight.getXIndex方法代碼示例

本文整理匯總了Java中com.github.mikephil.charting.highlight.Highlight.getXIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Highlight.getXIndex方法的具體用法?Java Highlight.getXIndex怎麽用?Java Highlight.getXIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.mikephil.charting.highlight.Highlight的用法示例。


在下文中一共展示了Highlight.getXIndex方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: highlightValue

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
/**
 * Highlights the value selected by touch gesture. Unlike
 * highlightValues(...), this generates a callback to the
 * OnChartValueSelectedListener.
 *
 * @param high         - the highlight object
 * @param callListener - call the listener
 */
public void highlightValue(Highlight high, boolean callListener) {

    Entry e = null;

    if (high == null)
        mIndicesToHighlight = null;
    else {

        if (mLogEnabled)
            Log.i(LOG_TAG, "Highlighted: " + high.toString());

        e = mData.getEntryForHighlight(high);
        if (e == null || e.getXIndex() != high.getXIndex()) {
            mIndicesToHighlight = null;
            high = null;
        } else {
            // set the indices to highlight
            mIndicesToHighlight = new Highlight[]{
                    high
            };
        }
    }

    if (callListener && mSelectionListener != null) {

        if (!valuesToHighlight())
            mSelectionListener.onNothingSelected();
        else {
            // notify the listener
            mSelectionListener.onValueSelected(e, high.getDataSetIndex(), high);
        }
    }
    // redraw the chart
    invalidate();
}
 
開發者ID:rahulmaddineni,項目名稱:Stayfit,代碼行數:44,代碼來源:Chart.java

示例2: highlightTouch

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
/**
 * Highlights the value selected by touch gesture. Unlike
 * highlightValues(...), this generates a callback to the
 * OnChartValueSelectedListener.
 *
 * @param high
 */
public void highlightTouch(Highlight high) {

    Entry e = null;

    if (high == null)
        mIndicesToHightlight = null;
    else {

        if (mLogEnabled)
            Log.i(LOG_TAG, "Highlighted: " + high.toString());

        e = mData.getEntryForHighlight(high);
        if (e == null || e.getXIndex() != high.getXIndex()) {
            mIndicesToHightlight = null;
            high = null;
        }
        else {
            // set the indices to highlight
            mIndicesToHightlight = new Highlight[] {
                    high
            };
        }
    }

    // redraw the chart
    invalidate();

    if (mSelectionListener != null) {

        if (!valuesToHighlight())
            mSelectionListener.onNothingSelected();
        else {
            // notify the listener
            mSelectionListener.onValueSelected(e, high.getDataSetIndex(), high);
        }
    }
}
 
開發者ID:xinpengfei520,項目名稱:P2P,代碼行數:45,代碼來源:Chart.java

示例3: drawMarkers

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
/**
 * draws all MarkerViews on the highlighted positions
 */
protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight())
        return;

    for (int i = 0; i < mIndicesToHighlight.length; i++) {

        Highlight highlight = mIndicesToHighlight[i];
        int xIndex = highlight.getXIndex();
        int dataSetIndex = highlight.getDataSetIndex();

        if (xIndex <= mDeltaX && xIndex <= mDeltaX * mAnimator.getPhaseX()) {

            Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);

            // make sure entry not null
            if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex())
                continue;

            float[] pos = getMarkerPosition(e, highlight);

            // check bounds
            if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
                continue;

            // callbacks to update the content
            mMarkerView.refreshContent(e, highlight);

            // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
            // MeasureSpec.UNSPECIFIED),
            // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
            // mMarkerView.getMeasuredHeight());
            // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);

            mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
                    mMarkerView.getMeasuredHeight());

            if (pos[1] - mMarkerView.getHeight() <= 0) {
                float y = mMarkerView.getHeight() - pos[1];
                mMarkerView.draw(canvas, pos[0], pos[1] + y);
            } else {
                mMarkerView.draw(canvas, pos[0], pos[1]);
            }
        }
    }
}
 
開發者ID:rahulmaddineni,項目名稱:Stayfit,代碼行數:54,代碼來源:Chart.java

示例4: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:rahulmaddineni,項目名稱:Stayfit,代碼行數:69,代碼來源:BubbleChartRenderer.java

示例5: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    int setCount = mChart.getBarData().getDataSetCount();

    for (int i = 0; i < indices.length; i++) {

        Highlight h = indices[i];
        int index = h.getXIndex();

        int dataSetIndex = h.getDataSetIndex();
        IBarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex);

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

        float barspaceHalf = set.getBarSpace() / 2f;
        
        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());

        // check outofbounds
        if (index >= 0
                && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) {

            BarEntry e = set.getEntryForXIndex(index);

            if (e == null || e.getXIndex() != index)
                continue;

            float groupspace = mChart.getBarData().getGroupSpace();
            boolean isStack = h.getStackIndex() < 0 ? false : true;

            // calculate the correct x-position
            float x = index * setCount + dataSetIndex + groupspace / 2f
                    + groupspace * index;

            final float y1;
            final float y2;

            if (isStack) {
                y1 = h.getRange().from;
                y2 = h.getRange().to;
            } else {
                y1 = e.getVal();
                y2 = 0.f;
            }

            prepareBarHighlight(x, y1, y2, barspaceHalf, trans);

            c.drawRect(mBarRect, mHighlightPaint);

            if (mChart.isDrawHighlightArrowEnabled()) {

                mHighlightPaint.setAlpha(255);

                // distance between highlight arrow and bar
                float offsetY = mAnimator.getPhaseY() * 0.07f;

                float[] values = new float[9];
                trans.getPixelToValueMatrix().getValues(values);
                final float xToYRel = Math.abs(values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]);

                final float arrowWidth = set.getBarSpace() / 2.f;
                final float arrowHeight = arrowWidth * xToYRel;

                final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY();

                Path arrow = new Path();
                arrow.moveTo(x + 0.4f, yArrow + offsetY);
                arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight);
                arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight);

                trans.pathValueToPixel(arrow);
                c.drawPath(arrow, mHighlightPaint);
            }
        }
    }
}
 
開發者ID:rahulmaddineni,項目名稱:Stayfit,代碼行數:82,代碼來源:BarChartRenderer.java

示例6: drawMarkers

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
/**
 * draws all MarkerViews on the highlighted positions
 */
protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight())
        return;

    for (int i = 0; i < mIndicesToHighlight.length; i++) {

        Highlight highlight = mIndicesToHighlight[i];
        int xIndex = highlight.getXIndex();
        int dataSetIndex = highlight.getDataSetIndex();

        float deltaX = mXAxis != null 
            ? mXAxis.mAxisRange
            : ((mData == null ? 0.f : mData.getXValCount()) - 1.f);

        if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) {

            Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);

            // make sure entry not null
            if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex())
                continue;

            float[] pos = getMarkerPosition(e, highlight);

            // check bounds
            if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
                continue;

            // callbacks to update the content
            mMarkerView.refreshContent(e, highlight);

            // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
            // MeasureSpec.UNSPECIFIED),
            // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
            // mMarkerView.getMeasuredHeight());
            // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);

            mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
                    mMarkerView.getMeasuredHeight());

            if (pos[1] - mMarkerView.getHeight() <= 0) {
                float y = mMarkerView.getHeight() - pos[1];
                mMarkerView.draw(canvas, pos[0], pos[1] + y);
            } else {
                mMarkerView.draw(canvas, pos[0], pos[1]);
            }
        }
    }
}
 
開發者ID:pencil-box,項目名稱:NetKnight,代碼行數:58,代碼來源:Chart.java

示例7: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    LineData lineData = mChart.getLineData();

    for (Highlight high : indices) {

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

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

            ILineDataSet set = lineData.getDataSetByIndex(dataSetIndex);

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

            int xIndex = high.getXIndex(); // get the
            // x-position

            if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
                continue;

            final float yVal = set.getYValForXIndex(xIndex);
            if (Float.isNaN(yVal))
                continue;

            float y = yVal * mAnimator.getPhaseY(); // get
            // the
            // y-position

            float[] pts = new float[]{
                    xIndex, y
            };

            mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);

            // draw the lines
            drawHighlightLines(c, pts, set);
        }
    }
}
 
開發者ID:pencil-box,項目名稱:NetKnight,代碼行數:50,代碼來源:LineChartRenderer.java

示例8: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    CandleData candleData = mChart.getCandleData();

    for (Highlight high : indices) {

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

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

            int xIndex = high.getXIndex(); // get the
            // x-position

            ICandleDataSet set = mChart.getCandleData().getDataSetByIndex(dataSetIndex);

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

            CandleEntry e = set.getEntryForXIndex(xIndex);

            if (e == null || e.getXIndex() != xIndex)
                continue;

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

            float[] pts = new float[]{
                    xIndex, y
            };

            mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);

            // draw the lines
            drawHighlightLines(c, pts, set);
        }
    }
}
 
開發者ID:pencil-box,項目名稱:NetKnight,代碼行數:48,代碼來源:CandleStickChartRenderer.java

示例9: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    ScatterData scatterData = mChart.getScatterData();

    for (Highlight high : indices) {

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

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

            IScatterDataSet set = scatterData.getDataSetByIndex(dataSetIndex);

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

            int xIndex = high.getXIndex(); // get the
            // x-position


            if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
                continue;

            final float yVal = set.getYValForXIndex(xIndex);
            if (Float.isNaN(yVal))
                continue;

            float y = yVal * mAnimator.getPhaseY();

            float[] pts = new float[]{
                    xIndex, y
            };

            mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);

            // draw the lines
            drawHighlightLines(c, pts, set);
        }
    }
}
 
開發者ID:pencil-box,項目名稱:NetKnight,代碼行數:49,代碼來源:ScatterChartRenderer.java

示例10: drawMarkers

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
/**
 * draws all MarkerViews on the highlighted positions
 */
protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight())
        return;

    for (int i = 0; i < mIndicesToHightlight.length; i++) {

        Highlight highlight = mIndicesToHightlight[i];
        int xIndex = highlight.getXIndex();
        int dataSetIndex = highlight.getDataSetIndex();

        if (xIndex <= mDeltaX && xIndex <= mDeltaX * mAnimator.getPhaseX()) {

            Entry e = mData.getEntryForHighlight(mIndicesToHightlight[i]);

            // make sure entry not null
            if (e == null || e.getXIndex() != mIndicesToHightlight[i].getXIndex())
                continue;

            float[] pos = getMarkerPosition(e, highlight);

            // check bounds
            if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
                continue;

            // callbacks to update the content
            mMarkerView.refreshContent(e, highlight);

            // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
            // MeasureSpec.UNSPECIFIED),
            // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
            // mMarkerView.getMeasuredHeight());
            // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);

            mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
                    mMarkerView.getMeasuredHeight());

            if (pos[1] - mMarkerView.getHeight() <= 0) {
                float y = mMarkerView.getHeight() - pos[1];
                mMarkerView.draw(canvas, pos[0], pos[1] + y);
            } else {
                mMarkerView.draw(canvas, pos[0], pos[1]);
            }
        }
    }
}
 
開發者ID:xinpengfei520,項目名稱:P2P,代碼行數:54,代碼來源:Chart.java

示例11: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:xinpengfei520,項目名稱:P2P,代碼行數:69,代碼來源:BubbleChartRenderer.java

示例12: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    int setCount = mChart.getBarData().getDataSetCount();

    for (int i = 0; i < indices.length; i++) {

        Highlight h = indices[i];
        int index = h.getXIndex();

        int dataSetIndex = h.getDataSetIndex();
        BarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex);

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

        float barspaceHalf = set.getBarSpace() / 2f;
        
        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());

        // check outofbounds
        if (index >= 0
                && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) {

            BarEntry e = set.getEntryForXIndex(index);

            if (e == null || e.getXIndex() != index)
                continue;

            float groupspace = mChart.getBarData().getGroupSpace();
            boolean isStack = h.getStackIndex() < 0 ? false : true;

            // calculate the correct x-position
            float x = index * setCount + dataSetIndex + groupspace / 2f
                    + groupspace * index;

            final float y1;
            final float y2;

            if (isStack) {
                y1 = h.getRange().from;
                y2 = h.getRange().to;
            } else {
                y1 = e.getVal();
                y2 = 0.f;
            }

            prepareBarHighlight(x, y1, y2, barspaceHalf, trans);

            c.drawRect(mBarRect, mHighlightPaint);

            if (mChart.isDrawHighlightArrowEnabled()) {

                mHighlightPaint.setAlpha(255);

                // distance between highlight arrow and bar
                float offsetY = mAnimator.getPhaseY() * 0.07f;

                float[] values = new float[9];
                trans.getPixelToValueMatrix().getValues(values);
                final float xToYRel = Math.abs(values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]);

                final float arrowWidth = set.getBarSpace() / 2.f;
                final float arrowHeight = arrowWidth * xToYRel;

                final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY();

                Path arrow = new Path();
                arrow.moveTo(x + 0.4f, yArrow + offsetY);
                arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight);
                arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight);

                trans.pathValueToPixel(arrow);
                c.drawPath(arrow, mHighlightPaint);
            }
        }
    }
}
 
開發者ID:xinpengfei520,項目名稱:P2P,代碼行數:82,代碼來源:BarChartRenderer.java

示例13: drawHighlighted

import com.github.mikephil.charting.highlight.Highlight; //導入方法依賴的package包/類
@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 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);

        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] = 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 (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);
    }
}
 
開發者ID:muyoumumumu,項目名稱:QuShuChe,代碼行數:71,代碼來源:BubbleChartRenderer.java


注:本文中的com.github.mikephil.charting.highlight.Highlight.getXIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。