Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if I want to set the RadarLabel like this! #524

Closed
JasonSZL opened this issue Nov 2, 2015 · 4 comments
Closed

if I want to set the RadarLabel like this! #524

JasonSZL opened this issue Nov 2, 2015 · 4 comments

Comments

@JasonSZL
Copy link

JasonSZL commented Nov 2, 2015

if I want to set the RadarLabel like this!
public override func renderAxisLabels(context context: CGContext)
{
if (!_xAxis.isEnabled || !_xAxis.isDrawLabelsEnabled)
{
return
}

    let labelFont = _xAxis.labelFont
    let labelTextColor = _xAxis.labelTextColor
    let labelRotationAngleRadians = _xAxis.labelRotationAngle * ChartUtils.Math.FDEG2RAD
    let drawLabelAnchor = CGPoint(x: 0.5, y: 0.0)

    let sliceangle = _chart.sliceAngle

    // calculate the factor that is needed for transforming the value to pixels
    let factor = _chart.factor

    let center = _chart.centerOffsets

    let modulus = _xAxis.axisLabelModulus
    for var i = 0, count = _xAxis.values.count; i < count; i += modulus
    {
        let label = _xAxis.values[i]

        if (label == nil)
        {
            continue
        }
        if (_xAxis.labelPosition == .Top)
        {

        }
        let angle = (sliceangle * CGFloat(i) + _chart.rotationAngle) % 360.0


        let p = ChartUtils.getPosition(center: center, dist: CGFloat(_chart.yRange) * factor + _xAxis.labelRotatedWidth / 2.0, angle: angle)
        if(angle == 270){
            drawLabel(context: context, label: label!, xIndex: i, x: p.x, y: p.y - _xAxis.labelRotatedHeight / 2.0 - 100, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14), NSForegroundColorAttributeName: UIColor.greenColor()], anchor: drawLabelAnchor, angleRadians: labelRotationAngleRadians)

// drawLabel(context: context, label: label!, xIndex: i, x: p.x, y: p.y - _xAxis.labelRotatedHeight / 2.0, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor], anchor: drawLabelAnchor, angleRadians: labelRotationAngleRadians)
}else{

            drawLabel(context: context, label: label!, xIndex: i, x: p.x, y: p.y - _xAxis.labelRotatedHeight / 2.0, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor], anchor: drawLabelAnchor, angleRadians: labelRotationAngleRadians)
        }


    }
}

the QUESTION is 👍
the labelRotatedHeight and the Label color is changed, but when the RadarView Rotating! the Label will be reDraw and the setting is Invalid.

so where is the method of the label redraw and how could i setting?
thank u very much!

@liuxuan30
Copy link
Member

it's in drawRect: either figure out a way to dynamicly change your setting or disable the redrawLabels if you detect it's rotating, or just disable the rotate

    public override func drawRect(rect: CGRect)
    {
        super.drawRect(rect)

        if (_dataNotSet)
        {
            return
        }

        let optionalContext = UIGraphicsGetCurrentContext()
        guard let context = optionalContext else { return }

        _xAxisRenderer?.renderAxisLabels(context: context)

@JasonSZL
Copy link
Author

JasonSZL commented Nov 3, 2015

I want when it Rotating and the color and position of the TOP Label be changed only. but there have some Automatic calculation bothers me ,

@liuxuan30
Copy link
Member

I guess you have to write your own logic for what you want. If something bothers you, just override the method and take what you need.

@JasonSZL
Copy link
Author

JasonSZL commented Nov 3, 2015

thank u very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants