Skip to content

Change position of Label Text to end of progress of each SeriesItem #46

@liauli

Description

@liauli

Hi, I tried to open the project and tweak the position of the label so it can follow the position of the end of each seriesitem. currently, it will follow the middle position and located in the middle.

I think this code affected the position, but still not sure how I can achieve what I need:


public RectF draw(@NonNull Canvas canvas, @NonNull RectF rect,
                      float percentAngle, float percentComplete, float positionValue) {
        if (!mVisible) {
            return null;
        }

        float radius = rect.width() / 2;
        float radians = ((360f * percentAngle)-90) * (float) (Math.PI / 180f);

        float xVal = (float) Math.cos(radians) * radius + rect.centerX();
        float yVal = (float) Math.sin(radians) * radius + rect.centerY();

        final float halfWidth = (mTextBounds.width() / 2) + mBufferX;
        final float halfHeight = (mTextBounds.height() / 2) + mBufferY;
        if (0 > xVal - halfWidth) {
            xVal = halfWidth;
        }
        if (canvas.getWidth() < xVal + halfWidth) {
            xVal = canvas.getWidth() - halfWidth;
        }
        if (0 > yVal - halfHeight) {
            yVal = halfHeight;
        }
        if (canvas.getHeight() < yVal + halfHeight) {
            yVal = canvas.getHeight() - halfHeight;
        }

        mTextDraw.set(xVal - halfWidth,
                yVal - halfHeight,
                xVal + halfWidth,
                yVal + halfHeight);

        canvas.drawRoundRect(
                mTextDraw,
                10f, 10f, mPaintBack);

        yVal -= mTextCenter;
        canvas.drawText(getDisplayString(percentComplete, positionValue), xVal, yVal, mPaintText);

        return mTextDraw;
    }

here's illustration what I want to achieve:
image

thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions