Java Code Examples for com.github.mikephil.charting.utils.MPPointF

The following examples show how to use com.github.mikephil.charting.utils.MPPointF. These examples are extracted from open source projects. 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 Project: SEAL-Demo   Source File: PredictionsFragment.java    License: MIT License 6 votes vote down vote up
/**
 * Updates the data in the pie chart with all the runs.
 */
private void updatePieChart() {
    ArrayList<PieEntry> entries = filterPieEntries();
    PieDataSet dataSet = new PieDataSet(entries, "Predictions");
    dataSet.setDrawIcons(false);
    dataSet.setSliceSpace(2f);
    dataSet.setIconsOffset(new MPPointF(0, 40));
    dataSet.setSelectionShift(5f);
    dataSet.setColors(new int[]{R.color.classification_low_intensity, R.color.classification_medium_intensity, R.color.classification_high_intensity}, getActivity());
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(22f);
    data.setValueTextColor(Color.WHITE);
    mChart.setData(data);
    mChart.invalidate();
}
 
Example 2
Source Project: StockChart-MPAndroidChart   Source File: BarLineChartBase.java    License: MIT License 6 votes vote down vote up
/**
 * Zooms in by 1.4f, into the charts center.
 */
public void zoomIn() {

    MPPointF center = mViewPortHandler.getContentCenter();

    mViewPortHandler.zoomIn(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

    MPPointF.recycleInstance(center);

    // 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.
    calculateOffsets();
    postInvalidate();
}
 
Example 3
Source Project: StockChart-MPAndroidChart   Source File: BarLineChartBase.java    License: MIT License 6 votes vote down vote up
/**
 * Zooms out by 0.7f, from the charts center.
 */
public void zoomOut() {

    MPPointF center = mViewPortHandler.getContentCenter();

    mViewPortHandler.zoomOut(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

    MPPointF.recycleInstance(center);

    // 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.
    calculateOffsets();
    postInvalidate();
}
 
Example 4
Source Project: StockChart-MPAndroidChart   Source File: HorizontalBarChart.java    License: MIT License 6 votes vote down vote up
/**
 * Returns a recyclable MPPointF instance.
 *
 * @param e
 * @param axis
 * @return
 */
@Override
public MPPointF getPosition(Entry e, AxisDependency axis) {

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

    float[] vals = mGetPositionBuffer;
    vals[0] = e.getY();
    vals[1] = e.getX();

    getTransformer(axis).pointValuesToPixel(vals);

    return MPPointF.getInstance(vals[0], vals[1]);
}
 
Example 5
Source Project: Ticket-Analysis   Source File: Chart.java    License: MIT License 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    // super.onDraw(canvas);

    if (mData == null) {

        boolean hasText = !TextUtils.isEmpty(mNoDataText);

        if (hasText) {
            MPPointF c = getCenter();
            canvas.drawText(mNoDataText, c.x, c.y, mInfoPaint);
        }

        return;
    }

    if (!mOffsetsCalculated) {

        calculateOffsets();
        mOffsetsCalculated = true;
    }
}
 
Example 6
Source Project: Ticket-Analysis   Source File: BarLineChartBase.java    License: MIT License 6 votes vote down vote up
/**
 * Zooms in by 1.4f, into the charts center.
 */
public void zoomIn() {

    MPPointF center = mViewPortHandler.getContentCenter();

    mViewPortHandler.zoomIn(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

    MPPointF.recycleInstance(center);

    // 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.
    calculateOffsets();
    postInvalidate();
}
 
Example 7
Source Project: android-kline   Source File: MarkerView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example 8
Source Project: Ticket-Analysis   Source File: MarkerView.java    License: MIT License 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example 9
Source Project: Ticket-Analysis   Source File: BarLineChartBase.java    License: MIT License 6 votes vote down vote up
/**
 * Zooms out by 0.7f, from the charts center.
 */
public void zoomOut() {

    MPPointF center = mViewPortHandler.getContentCenter();

    mViewPortHandler.zoomOut(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);

    MPPointF.recycleInstance(center);

    // 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.
    calculateOffsets();
    postInvalidate();
}
 
Example 10
Source Project: StockChart-MPAndroidChart   Source File: MarkerView.java    License: MIT License 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = -posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = -posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example 11
Source Project: Ticket-Analysis   Source File: Chart.java    License: MIT License 5 votes vote down vote up
/**
 * Draws the description text in the bottom right corner of the chart (per default)
 */
protected void drawDescription(Canvas c) {

    // check if description should be drawn
    if (mDescription != null && mDescription.isEnabled()) {

        MPPointF position = mDescription.getPosition();

        mDescPaint.setTypeface(mDescription.getTypeface());
        mDescPaint.setTextSize(mDescription.getTextSize());
        mDescPaint.setColor(mDescription.getTextColor());
        mDescPaint.setTextAlign(mDescription.getTextAlign());

        float x, y;

        // if no position specified, draw on default position
        if (position == null) {
            x = getWidth() - mViewPortHandler.offsetRight() - mDescription.getXOffset();
            y = getHeight() - mViewPortHandler.offsetBottom() - mDescription.getYOffset();
        } else {
            x = position.x;
            y = position.y;
        }

        c.drawText(mDescription.getText(), x, y, mDescPaint);
    }
}
 
Example 12
Source Project: Ticket-Analysis   Source File: MarkerView.java    License: MIT License 5 votes vote down vote up
@Override
public void draw(Canvas canvas, float posX, float posY) {

    MPPointF offset = getOffsetForDrawingAtPoint(posX, posY);

    int saveId = canvas.save();
    // translate to the correct position and draw
    canvas.translate(posX + offset.x, posY + offset.y);
    draw(canvas);
    canvas.restoreToCount(saveId);
}
 
Example 13
Source Project: android-kline   Source File: HorizontalBarChart.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a recyclable MPPointF instance.
 *
 * @param e
 * @param axis
 * @return
 */
@Override
public MPPointF getPosition(Entry e, AxisDependency axis) {

    if (e == null)
        return null;

    float[] vals = mGetPositionBuffer;
    vals[0] = e.getY();
    vals[1] = e.getX();

    getTransformer(axis).pointValuesToPixel(vals);

    return MPPointF.getInstance(vals[0], vals[1]);
}
 
Example 14
Source Project: Ticket-Analysis   Source File: HorizontalBarChart.java    License: MIT License 5 votes vote down vote up
/**
 * Returns a recyclable MPPointF instance.
 *
 * @param e
 * @param axis
 * @return
 */
@Override
public MPPointF getPosition(Entry e, AxisDependency axis) {

    if (e == null)
        return null;

    float[] vals = mGetPositionBuffer;
    vals[0] = e.getY();
    vals[1] = e.getX();

    getTransformer(axis).pointValuesToPixel(vals);

    return MPPointF.getInstance(vals[0], vals[1]);
}
 
Example 15
Source Project: StockChart-MPAndroidChart   Source File: BarLineChartBase.java    License: MIT License 5 votes vote down vote up
/**
 * Zooms to the center of the chart with the given scale factor.
 *
 * @param scaleX
 * @param scaleY
 */
public void zoomToCenter(float scaleX, float scaleY) {

    MPPointF center = getCenterOffsets();

    Matrix save = mZoomMatrixBuffer;
    mViewPortHandler.zoom(scaleX, scaleY, center.x, -center.y, save);
    mViewPortHandler.refresh(save, this, false);
}
 
Example 16
Source Project: android-kline   Source File: BarLineChartTouchListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines the center point between two pointer touch points.
 *
 * @param point
 * @param event
 */
private static void midPoint(MPPointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1);
    float y = event.getY(0) + event.getY(1);
    point.x = (x / 2f);
    point.y = (y / 2f);
}
 
Example 17
Source Project: OpenLibre   Source File: DateTimeMarkerView.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
    MPPointF offset = getOffset();

    offset.x = max(offset.x, - posX);
    offset.y = max(offset.y, - posY);

    Chart chart = getChartView();
    if (chart != null) {
        offset.x = min(offset.x, chart.getWidth() - posX - getWidth());
        offset.y = min(offset.y, chart.getHeight() - posY - getHeight());
    }

    return offset;
}
 
Example 18
Source Project: android-kline   Source File: XAxisRendererRadarChart.java    License: 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 MPPointF drawLabelAnchor = MPPointF.getInstance(0.5f, 0.25f);

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

    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0,0);
    for (int i = 0; i < mChart.getData().getMaxEntryCountSet().getEntryCount(); i++) {

        String label = mXAxis.getValueFormatter().getFormattedValue(i, mXAxis);

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

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

        drawLabel(c, label, pOut.x, pOut.y - mXAxis.mLabelRotatedHeight / 2.f,
                drawLabelAnchor, labelRotationAngleDegrees);
    }

    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
    MPPointF.recycleInstance(drawLabelAnchor);
}
 
Example 19
Source Project: android-kline   Source File: Description.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets a custom position for the description text in pixels on the screen.
 *
 * @param x - xcoordinate
 * @param y - ycoordinate
 */
public void setPosition(float x, float y) {
    if (mPosition == null) {
        mPosition = MPPointF.getInstance(x, y);
    } else {
        mPosition.x = x;
        mPosition.y = y;
    }
}
 
Example 20
Source Project: StockChart-MPAndroidChart   Source File: RadarChartRenderer.java    License: MIT License 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
Example 21
Source Project: StockChart-MPAndroidChart   Source File: PieChartRenderer.java    License: MIT License 5 votes vote down vote up
protected float calculateMinimumRadiusForSpacedSlice(
        MPPointF 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 22
Source Project: Ticket-Analysis   Source File: MarkerImage.java    License: MIT License 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = mSize.width;
    float height = mSize.height;

    if (width == 0.f && mDrawable != null) {
        width = mDrawable.getIntrinsicWidth();
    }
    if (height == 0.f && mDrawable != null) {
        height = mDrawable.getIntrinsicHeight();
    }

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example 23
Source Project: Ticket-Analysis   Source File: RadarChartRenderer.java    License: MIT License 5 votes vote down vote up
public void drawHighlightCircle(Canvas c,
                                MPPointF point,
                                float innerRadius,
                                float outerRadius,
                                int fillColor,
                                int strokeColor,
                                float strokeWidth) {
    c.save();

    outerRadius = Utils.convertDpToPixel(outerRadius);
    innerRadius = Utils.convertDpToPixel(innerRadius);

    if (fillColor != ColorTemplate.COLOR_NONE) {
        Path p = mDrawHighlightCirclePathBuffer;
        p.reset();
        p.addCircle(point.x, point.y, outerRadius, Path.Direction.CW);
        if (innerRadius > 0.f) {
            p.addCircle(point.x, point.y, innerRadius, Path.Direction.CCW);
        }
        mHighlightCirclePaint.setColor(fillColor);
        mHighlightCirclePaint.setStyle(Paint.Style.FILL);
        c.drawPath(p, mHighlightCirclePaint);
    }

    if (strokeColor != ColorTemplate.COLOR_NONE) {
        mHighlightCirclePaint.setColor(strokeColor);
        mHighlightCirclePaint.setStyle(Paint.Style.STROKE);
        mHighlightCirclePaint.setStrokeWidth(Utils.convertDpToPixel(strokeWidth));
        c.drawCircle(point.x, point.y, outerRadius, mHighlightCirclePaint);
    }

    c.restore();
}
 
Example 24
Source Project: android-kline   Source File: PieChartRenderer.java    License: Apache License 2.0 5 votes vote down vote up
protected float calculateMinimumRadiusForSpacedSlice(
        MPPointF 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 25
Source Project: StockChart-MPAndroidChart   Source File: Description.java    License: MIT License 5 votes vote down vote up
/**
 * Sets a custom position for the description text in pixels on the screen.
 *
 * @param x - xcoordinate
 * @param y - ycoordinate
 */
public void setPosition(float x, float y) {
    if (mPosition == null) {
        mPosition = MPPointF.getInstance(x, y);
    } else {
        mPosition.x = x;
        mPosition.y = y;
    }
}
 
Example 26
Source Project: Ticket-Analysis   Source File: Description.java    License: MIT License 5 votes vote down vote up
/**
 * Sets a custom position for the description text in pixels on the screen.
 *
 * @param x - xcoordinate
 * @param y - ycoordinate
 */
public void setPosition(float x, float y) {
    if (mPosition == null) {
        mPosition = MPPointF.getInstance(x, y);
    } else {
        mPosition.x = x;
        mPosition.y = y;
    }
}
 
Example 27
Source Project: StockChart-MPAndroidChart   Source File: MarkerImage.java    License: MIT License 5 votes vote down vote up
@Override
public void draw(Canvas canvas, float posX, float posY) {

    if (mDrawable == null) {
        return;
    }

    MPPointF offset = getOffsetForDrawingAtPoint(posX, posY);

    float width = mSize.width;
    float height = mSize.height;

    if (width == 0.f && mDrawable != null) {
        width = mDrawable.getIntrinsicWidth();
    }
    if (height == 0.f && mDrawable != null) {
        height = mDrawable.getIntrinsicHeight();
    }

    mDrawable.copyBounds(mDrawableBoundsCache);
    mDrawable.setBounds(
            mDrawableBoundsCache.left,
            mDrawableBoundsCache.top,
            mDrawableBoundsCache.left + (int) width,
            mDrawableBoundsCache.top + (int) height);

    int saveId = canvas.save();
    // translate to the correct position and draw
    canvas.translate(posX + offset.x, posY + offset.y);
    mDrawable.draw(canvas);
    canvas.restoreToCount(saveId);

    mDrawable.setBounds(mDrawableBoundsCache);
}
 
Example 28
Source Project: android-kline   Source File: MarkerImage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = mSize.width;
    float height = mSize.height;

    if (width == 0.f && mDrawable != null) {
        width = mDrawable.getIntrinsicWidth();
    }
    if (height == 0.f && mDrawable != null) {
        height = mDrawable.getIntrinsicHeight();
    }

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example 29
Source Project: Ticket-Analysis   Source File: PieChart.java    License: MIT License 5 votes vote down vote up
@Override
protected float[] getMarkerPosition(Highlight highlight) {

    MPPointF center = getCenterCircleBox();
    float r = getRadius();

    float off = r / 10f * 3.6f;

    if (isDrawHoleEnabled()) {
        off = (r - (r / 100f * getHoleRadius())) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    float rotationAngle = getRotationAngle();

    int entryIndex = (int) highlight.getX();

    // offset needed to center the drawn text in the slice
    float offset = mDrawAngles[entryIndex] / 2;

    // calculate the text position
    float x = (float) (r
            * Math.cos(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset)
            * mAnimator.getPhaseY())) + center.x);
    float y = (float) (r
            * Math.sin(Math.toRadians((rotationAngle + mAbsoluteAngles[entryIndex] - offset)
            * mAnimator.getPhaseY())) + center.y);

    MPPointF.recycleInstance(center);
    return new float[]{x, y};
}
 
Example 30
Source Project: Ticket-Analysis   Source File: PieRadarChartBase.java    License: MIT License 5 votes vote down vote up
/**
 * Returns the distance of a certain point on the chart to the center of the
 * chart.
 *
 * @param x
 * @param y
 * @return
 */
public float distanceToCenter(float x, float y) {

    MPPointF c = getCenterOffsets();

    float dist = 0f;

    float xDist = 0f;
    float yDist = 0f;

    if (x > c.x) {
        xDist = x - c.x;
    } else {
        xDist = c.x - x;
    }

    if (y > c.y) {
        yDist = y - c.y;
    } else {
        yDist = c.y - y;
    }

    // pythagoras
    dist = (float) Math.sqrt(Math.pow(xDist, 2.0) + Math.pow(yDist, 2.0));

    MPPointF.recycleInstance(c);

    return dist;
}