com.github.mikephil.charting.utils.Utils Java Examples

The following examples show how to use com.github.mikephil.charting.utils.Utils. 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: LineRadarRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * Draws the provided path in filled mode with the provided drawable.
 *
 * @param c
 * @param filledPath
 * @param drawable
 */
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {

    if (clipPathSupported()) {

        int save = c.save();
        c.clipPath(filledPath);

        drawable.setBounds((int) mViewPortHandler.contentLeft(),
                (int) mViewPortHandler.contentTop(),
                (int) mViewPortHandler.contentRight(),
                (int) mViewPortHandler.contentBottom());
        drawable.draw(c);

        c.restoreToCount(save);
    } else {
        throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
                "this code was run on API level " + Utils.getSDKInt() + ".");
    }
}
 
Example #2
Source File: Entry.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Compares value, xIndex and data of the entries. Returns true if entries
 * are equal in those points, false if not. Does not check by hash-code like
 * it's done by the "equals" method.
 *
 * @param e
 * @return
 */
public boolean equalTo(Entry e) {

    if (e == null) {
        return false;
    }

    if (e.getData() != this.getData()) {
        return false;
    }

    if (Math.abs(e.x - this.x) > Utils.FLOAT_EPSILON) {
        return false;
    }

    return !(Math.abs(e.getY() - this.getY()) > Utils.FLOAT_EPSILON);
}
 
Example #3
Source File: StackedBarsMarkerView.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {

    if (e instanceof BarEntry) {

        BarEntry be = (BarEntry) e;

        if(be.getYVals() != null) {

            // draw the stack value
            tvContent.setText(Utils.formatNumber(be.getYVals()[highlight.getStackIndex()], 0, true));
        } else {
            tvContent.setText(Utils.formatNumber(be.getY(), 0, true));
        }
    } else {

        tvContent.setText(Utils.formatNumber(e.getY(), 0, true));
    }

    super.refreshContent(e, highlight);
}
 
Example #4
Source File: PieChart.java    From Notification-Analyser with MIT License 6 votes vote down vote up
@Override
protected void init() {
    super.init();

    // // piechart has no offsets
    // mOffsetTop = 0;
    // mOffsetBottom = 0;
    // mOffsetLeft = 0;
    // mOffsetRight = 0;

    mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHolePaint.setColor(Color.WHITE);

    mCenterTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCenterTextPaint.setColor(Color.BLACK);
    mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
    mCenterTextPaint.setTextAlign(Align.CENTER);

    mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
    mValuePaint.setColor(Color.WHITE);
    mValuePaint.setTextAlign(Align.CENTER);

    // for the piechart, drawing values is enabled
    mDrawYValues = true;
}
 
Example #5
Source File: ChevronDownShapeRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler,
                 float posX, float posY, Paint renderPaint) {

    final float shapeHalf = dataSet.getScatterShapeSize() / 2f;

    renderPaint.setStyle(Paint.Style.STROKE);
    renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX + (2 * shapeHalf),
            posY,
            renderPaint);

    c.drawLine(
            posX,
            posY + (2 * shapeHalf),
            posX - (2 * shapeHalf),
            posY,
            renderPaint);
}
 
Example #6
Source File: XAxisRendererHorizontalBarChart.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public void computeAxis(float xValAverageLength, List<String> xValues) {
    
    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mXAxis.setValues(xValues);

    String longest = mXAxis.getLongestLabel();

    final FSize labelSize = Utils.calcTextSize(mAxisLabelPaint, longest);

    final float labelWidth = (int)(labelSize.width + mXAxis.getXOffset() * 3.5f);
    final float labelHeight = labelSize.height;

    final FSize labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
            labelSize.width,
            labelHeight,
            mXAxis.getLabelRotationAngle());

    mXAxis.mLabelWidth = Math.round(labelWidth);
    mXAxis.mLabelHeight = Math.round(labelHeight);
    mXAxis.mLabelRotatedWidth = (int)(labelRotatedSize.width + mXAxis.getXOffset() * 3.5f);
    mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);
}
 
Example #7
Source File: PieChartRenderer.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
public PieChartRenderer(PieChart chart, ChartAnimator animator,
                        ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHolePaint.setColor(Color.WHITE);
    mHolePaint.setStyle(Style.FILL);

    mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTransparentCirclePaint.setColor(Color.WHITE);
    mTransparentCirclePaint.setStyle(Style.FILL);
    mTransparentCirclePaint.setAlpha(105);

    mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mCenterTextPaint.setColor(Color.BLACK);
    mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));

    mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
    mValuePaint.setColor(Color.WHITE);
    mValuePaint.setTextAlign(Align.CENTER);

    mValueLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValueLinePaint.setStyle(Style.STROKE);
}
 
Example #8
Source File: Chart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * Calculates the required number of digits for the values that might be
 * drawn in the chart (if enabled), and creates the default-value-formatter
 */
protected void setupDefaultFormatter(float min, float max) {

    float reference = 0f;

    if (mData == null || mData.getEntryCount() < 2) {

        reference = Math.max(Math.abs(min), Math.abs(max));
    } else {
        reference = Math.abs(max - min);
    }

    int digits = Utils.getDecimals(reference);

    // setup the formatter with a new number of digits
    mDefaultValueFormatter.setup(digits);
}
 
Example #9
Source File: LineRadarRenderer.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the provided path in filled mode with the provided drawable.
 *
 * @param c
 * @param filledPath
 * @param drawable
 */
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {

    if (clipPathSupported()) {

        int save = c.save();
        c.clipPath(filledPath);

        drawable.setBounds((int) mViewPortHandler.contentLeft(),
                (int) mViewPortHandler.contentTop(),
                (int) mViewPortHandler.contentRight(),
                (int) mViewPortHandler.contentBottom());
        drawable.draw(c);

        c.restoreToCount(save);
    } else {
        throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
                "this code was run on API level " + Utils.getSDKInt() + ".");
    }
}
 
Example #10
Source File: XAxisRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
public void computeAxis(float xValMaximumLength, List<String> xValues) {

        mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
        mAxisLabelPaint.setTextSize(mXAxis.getTextSize());

        StringBuilder widthText = new StringBuilder();

        int xValChars = Math.round(xValMaximumLength);

        for (int i = 0; i < xValChars; i++) {
            widthText.append('h');
        }

        final FSize labelSize = Utils.calcTextSize(mAxisLabelPaint, widthText.toString());

        final float labelWidth = labelSize.width;
        final float labelHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");

        final FSize labelRotatedSize = Utils.getSizeOfRotatedRectangleByDegrees(
                labelWidth,
                labelHeight,
                mXAxis.getLabelRotationAngle());

        StringBuilder space = new StringBuilder();
        int xValSpaceChars = mXAxis.getSpaceBetweenLabels();

        for (int i = 0; i < xValSpaceChars; i++) {
            space.append('h');
        }

        final FSize spaceSize = Utils.calcTextSize(mAxisLabelPaint, space.toString());

        mXAxis.mLabelWidth = Math.round(labelWidth + spaceSize.width);
        mXAxis.mLabelHeight = Math.round(labelHeight);
        mXAxis.mLabelRotatedWidth = Math.round(labelRotatedSize.width + spaceSize.width);
        mXAxis.mLabelRotatedHeight = Math.round(labelRotatedSize.height);

        mXAxis.setValues(xValues);
    }
 
Example #11
Source File: ComponentBase.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * sets the size of the label text in density pixels min = 6f, max = 24f, default
 * 10f
 *
 * @param size the text size, in DP
 */
public void setTextSize(float size) {

    if (size > 24f) {
        size = 24f;
    }
    if (size < 6f) {
        size = 6f;
    }

    mTextSize = Utils.convertDpToPixel(size);
}
 
Example #12
Source File: ChevronDownShapeRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void renderShape(
        Canvas c, IScatterDataSet dataSet,
        ViewPortHandler mViewPortHandler, ScatterBuffer buffer, Paint mRenderPaint, final float shapeSize) {

    final float shapeHalf = shapeSize / 2f;

    mRenderPaint.setStyle(Paint.Style.STROKE);
    mRenderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));

    for (int i = 0; i < buffer.size(); i += 2) {

        if (!mViewPortHandler.isInBoundsRight(buffer.buffer[i]))
            break;

        if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[i])
                || !mViewPortHandler.isInBoundsY(buffer.buffer[i + 1]))
            continue;

        mRenderPaint.setColor(dataSet.getColor(i / 2));

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] + (2 * shapeHalf),
                buffer.buffer[i] + (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);

        c.drawLine(
                buffer.buffer[i],
                buffer.buffer[i + 1] + (2 * shapeHalf),
                buffer.buffer[i] - (2 * shapeHalf),
                buffer.buffer[i + 1],
                mRenderPaint);
    }

}
 
Example #13
Source File: Legend.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a custom legend's labels and colors arrays. The colors count should
 * match the labels count. * Each color is for the form drawn at the same
 * index. * A null label will start a group. * A ColorTemplate.COLOR_SKIP
 * color will avoid drawing a form This will disable the feature that
 * automatically calculates the legend labels and colors from the datasets.
 * Call resetCustom() to re-enable automatic calculation (and then
 * notifyDataSetChanged() is needed to auto-calculate the legend again)
 */
public void setCustom(List<Integer> colors, List<String> labels) {

    if (colors.size() != labels.size()) {
        throw new IllegalArgumentException(
                "colors array and labels array need to be of same size");
    }

    mColors = Utils.convertIntegers(colors);
    mLabels = Utils.convertStrings(labels);
    mIsLegendCustom = true;
}
 
Example #14
Source File: PieChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
public PieChartRenderer(PieChart chart, ChartAnimator animator,
                        ViewPortHandler viewPortHandler) {
    super(animator, viewPortHandler);
    mChart = chart;

    mHolePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHolePaint.setColor(Color.WHITE);
    mHolePaint.setStyle(Style.FILL);

    mTransparentCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTransparentCirclePaint.setColor(Color.WHITE);
    mTransparentCirclePaint.setStyle(Style.FILL);
    mTransparentCirclePaint.setAlpha(105);

    mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mCenterTextPaint.setColor(Color.BLACK);
    mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));

    mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
    mValuePaint.setColor(Color.BLACK);
    mValuePaint.setTextAlign(Align.CENTER);

    mEntryLabelsPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mEntryLabelsPaint.setColor(Color.BLACK);
    mEntryLabelsPaint.setTextAlign(Align.CENTER);
    mEntryLabelsPaint.setTextSize(Utils.convertDpToPixel(13f));

    mValueLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValueLinePaint.setStyle(Style.STROKE);
}
 
Example #15
Source File: Chart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int size = (int) Utils.convertDpToPixel(50f);
    setMeasuredDimension(
            Math.max(getSuggestedMinimumWidth(),
                    resolveSize(size,
                            widthMeasureSpec)),
            Math.max(getSuggestedMinimumHeight(),
                    resolveSize(size,
                            heightMeasureSpec)));
}
 
Example #16
Source File: YAxis.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * This is for HorizontalBarChart vertical spacing.
 *
 * @param p
 * @return
 */
public float getRequiredHeightSpace(Paint p) {

    p.setTextSize(mTextSize);

    String label = getLongestLabel();
    return (float) Utils.calcTextHeight(p, label) + getYOffset() * 2f;
}
 
Example #17
Source File: RadarChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    mYAxis = new YAxis(AxisDependency.LEFT);
    mXAxis = new XAxis();
    mXAxis.setSpaceBetweenLabels(0);

    mWebLineWidth = Utils.convertDpToPixel(1.5f);
    mInnerWebLineWidth = Utils.convertDpToPixel(0.75f);

    mRenderer = new RadarChartRenderer(this, mAnimator, mViewPortHandler);
    mYAxisRenderer = new YAxisRendererRadarChart(mViewPortHandler, mYAxis, this);
    mXAxisRenderer = new XAxisRendererRadarChart(mViewPortHandler, mXAxis, this);
}
 
Example #18
Source File: Legend.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/** default constructor */
public Legend() {

    mFormSize = Utils.convertDpToPixel(8f);
    mXEntrySpace = Utils.convertDpToPixel(6f);
    mYEntrySpace = Utils.convertDpToPixel(0f);
    mFormToTextSpace = Utils.convertDpToPixel(5f);
    mTextSize = Utils.convertDpToPixel(10f);
    mStackSpace = Utils.convertDpToPixel(3f);
    this.mXOffset = Utils.convertDpToPixel(5f);
    this.mYOffset = Utils.convertDpToPixel(3f); // 2
}
 
Example #19
Source File: Chart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a new data object for the chart. The data object contains all values
 * and information needed for displaying.
 *
 * @param data
 */
public void setData(T data) {

    if (data == null) {
        Log.e(LOG_TAG,
                "Cannot set data for chart. Provided data object is null.");
        return;
    }

    // LET THE CHART KNOW THERE IS DATA
    mOffsetsCalculated = false;
    mData = data;

    // calculate how many digits are needed
    calculateFormatter(data.getYMin(), data.getYMax());

    for (IDataSet set : mData.getDataSets()) {
        if (Utils.needsDefaultFormatter(set.getValueFormatter()))
            set.setValueFormatter(mDefaultFormatter);
    }

    // let the chart know there is new data
    notifyDataSetChanged();

    if (mLogEnabled)
        Log.i(LOG_TAG, "Data is set.");
}
 
Example #20
Source File: RealmLineRadarDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
/**
 * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
 * thinner line == better performance, thicker line == worse performance
 *
 * @param width
 */
public void setLineWidth(float width) {

    if (width < 0.2f)
        width = 0.2f;
    if (width > 10.0f)
        width = 10.0f;
    mLineWidth = Utils.convertDpToPixel(width);
}
 
Example #21
Source File: LineRadarDataSet.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
 * thinner line == better performance, thicker line == worse performance
 *
 * @param width
 */
public void setLineWidth(float width) {

    if (width < 0.2f)
        width = 0.2f;
    if (width > 10.0f)
        width = 10.0f;
    mLineWidth = Utils.convertDpToPixel(width);
}
 
Example #22
Source File: XAxisRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public XAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans) {
    super(viewPortHandler, trans, xAxis);

    this.mXAxis = xAxis;

    mAxisLabelPaint.setColor(Color.BLACK);
    mAxisLabelPaint.setTextAlign(Align.CENTER);
    mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));
}
 
Example #23
Source File: PieChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
protected float calculateMinimumRadiusForSpacedSlice(
        PointF center,
        float radius,
        float angle,
        float arcStartPointX,
        float arcStartPointY,
        float startAngle,
        float sweepAngle) {
    final float angleMiddle = startAngle + sweepAngle / 2.f;

    // Other point of the arc
    float arcEndPointX = center.x + radius * (float) Math.cos((startAngle + sweepAngle) * Utils.FDEG2RAD);
    float arcEndPointY = center.y + radius * (float) Math.sin((startAngle + sweepAngle) * Utils.FDEG2RAD);

    // Middle point on the arc
    float arcMidPointX = center.x + radius * (float) Math.cos(angleMiddle * Utils.FDEG2RAD);
    float arcMidPointY = center.y + radius * (float) Math.sin(angleMiddle * Utils.FDEG2RAD);

    // This is the base of the contained triangle
    double basePointsDistance = Math.sqrt(
            Math.pow(arcEndPointX - arcStartPointX, 2) +
                    Math.pow(arcEndPointY - arcStartPointY, 2));

    // After reducing space from both sides of the "slice",
    //   the angle of the contained triangle should stay the same.
    // So let's find out the height of that triangle.
    float containedTriangleHeight = (float) (basePointsDistance / 2.0 *
            Math.tan((180.0 - angle) / 2.0 * Utils.DEG2RAD));

    // Now we subtract that from the radius
    float spacedRadius = radius - containedTriangleHeight;

    // And now subtract the height of the arc that's between the triangle and the outer circle
    spacedRadius -= Math.sqrt(
            Math.pow(arcMidPointX - (arcEndPointX + arcStartPointX) / 2.f, 2) +
                    Math.pow(arcMidPointY - (arcEndPointY + arcStartPointY) / 2.f, 2));

    return spacedRadius;
}
 
Example #24
Source File: BarLineChartTouchListener.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * Constructor with initialization parameters.
 *
 * @param chart               instance of the chart
 * @param touchMatrix         the touch-matrix of the chart
 * @param dragTriggerDistance the minimum movement distance that will be interpreted as a "drag" gesture in dp (3dp equals
 *                            to about 9 pixels on a 5.5" FHD screen)
 */
public BarLineChartTouchListener(BarLineChartBase<? extends BarLineScatterCandleBubbleData<? extends
        IBarLineScatterCandleBubbleDataSet<? extends Entry>>> chart, Matrix touchMatrix, float dragTriggerDistance) {
    super(chart);
    this.mMatrix = touchMatrix;

    this.mDragTriggerDist = Utils.convertDpToPixel(dragTriggerDistance);

    this.mMinScalePointerDistance = Utils.convertDpToPixel(3.5f);
}
 
Example #25
Source File: BarLineChartTouchListener.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
public void computeScroll() {

        if (mDecelerationVelocity.x == 0.f && mDecelerationVelocity.y == 0.f)
            return; // There's no deceleration in progress

        final long currentTime = AnimationUtils.currentAnimationTimeMillis();

        mDecelerationVelocity.x *= mChart.getDragDecelerationFrictionCoef();
        mDecelerationVelocity.y *= mChart.getDragDecelerationFrictionCoef();

        final float timeInterval = (float) (currentTime - mDecelerationLastTime) / 1000.f;

        float distanceX = mDecelerationVelocity.x * timeInterval;
        float distanceY = mDecelerationVelocity.y * timeInterval;

        mDecelerationCurrentPoint.x += distanceX;
        mDecelerationCurrentPoint.y += distanceY;

        MotionEvent event = MotionEvent.obtain(currentTime, currentTime, MotionEvent.ACTION_MOVE, mDecelerationCurrentPoint.x, mDecelerationCurrentPoint.y, 0);
        performDrag(event);
        event.recycle();
        mMatrix = mChart.getViewPortHandler().refresh(mMatrix, mChart, false);

        mDecelerationLastTime = currentTime;

        if (Math.abs(mDecelerationVelocity.x) >= 0.01 || Math.abs(mDecelerationVelocity.y) >= 0.01)
            Utils.postInvalidateOnAnimation(mChart); // This causes computeScroll to fire, recommended for this by Google
        else {
            // Range might have changed, which means that Y-axis labels
            // could have changed in size, affecting Y-axis size.
            // So we need to recalculate offsets.
            mChart.calculateOffsets();
            mChart.postInvalidate();

            stopDeceleration();
        }
    }
 
Example #26
Source File: RealmLineRadarDataSet.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * set the line width of the chart (min = 0.2f, max = 10f); default 1f NOTE:
 * thinner line == better performance, thicker line == worse performance
 *
 * @param width
 */
public void setLineWidth(float width) {

    if (width < 0.2f)
        width = 0.2f;
    if (width > 10.0f)
        width = 10.0f;
    mLineWidth = Utils.convertDpToPixel(width);
}
 
Example #27
Source File: XAxisRendererRadarChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {

    if (!mXAxis.isEnabled() || !mXAxis.isDrawLabelsEnabled())
        return;

    final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
    final PointF drawLabelAnchor = new PointF(0.5f, 0.0f);

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
    mAxisLabelPaint.setColor(mXAxis.getTextColor());

    float sliceangle = mChart.getSliceAngle();

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

    PointF center = mChart.getCenterOffsets();

    int mod = mXAxis.mAxisLabelModulus;
    for (int i = 0; i < mXAxis.getValues().size(); i += mod) {
        String label = mXAxis.getValues().get(i);

        float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;

        PointF p = Utils.getPosition(center, mChart.getYRange() * factor
                + mXAxis.mLabelRotatedWidth / 2f, angle);

        drawLabel(c, label, i, p.x, p.y - mXAxis.mLabelRotatedHeight / 2.f,
                drawLabelAnchor, labelRotationAngleDegrees);
    }
}
 
Example #28
Source File: RadarChart.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * Calculates the required maximum y-value in order to be able to provide
 * the desired number of label entries and rounded label values.
 */
private void prepareYLabels() {

    int labelCount = mYLabels.getLabelCount();
    double range = mCurrentData.getYMax() - mYChartMin;

    double rawInterval = range / labelCount;
    double interval = Utils.roundToNextSignificant(rawInterval);
    double intervalMagnitude = Math.pow(10, (int) Math.log10(interval));
    int intervalSigDigit = (int) (interval / intervalMagnitude);
    if (intervalSigDigit > 5) {
        // Use one order of magnitude higher, to avoid intervals like 0.9 or
        // 90
        interval = Math.floor(10 * intervalMagnitude);
    }

    double first = Math.ceil(mYChartMin / interval) * interval;
    double last = Utils.nextUp(Math.floor(mCurrentData.getYMax() / interval) * interval);

    double f;
    int n = 0;
    for (f = first; f <= last; f += interval) {
        ++n;
    }

    mYLabels.mEntryCount = n;

    mYChartMax = (float) interval * n;

    // calc delta
    mDeltaY = Math.abs(mYChartMax - mYChartMin);
}
 
Example #29
Source File: PieChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public int getIndexForAngle(float angle) {

    // take the current angle of the chart into consideration
    float a = Utils.getNormalizedAngle(angle - getRotationAngle());

    for (int i = 0; i < mAbsoluteAngles.length; i++) {
        if (mAbsoluteAngles[i] > a)
            return i;
    }

    return -1; // return -1 if no index found
}
 
Example #30
Source File: BaseDataSet.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public ValueFormatter getValueFormatter() {
    if (needsFormatter()) {
        return Utils.getDefaultValueFormatter();
    }
    return mValueFormatter;
}