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

Can't set hole color to nil for Pie Chart #646

Closed
benpackard opened this issue Jan 3, 2016 · 6 comments
Closed

Can't set hole color to nil for Pie Chart #646

benpackard opened this issue Jan 3, 2016 · 6 comments
Labels

Comments

@benpackard
Copy link

For a transparent hole, it is recommended to:

*Note: Use holeTransparent with holeColor = nil to make the hole transparent.*```

However, the following set up causes a crash:

pieChart.holeTransparent = true
pieChart.holeColor = nil

Looking at the implementation, the holeColor is explicitly unwrapped, presumably because of the check for nil that precedes it. However, the explicit unwrapping is not in scope of the check:

if (holeColor !== nil && holeColor != UIColor.clearColor())
            {
                // draw the hole-circle
                CGContextSetFillColorWithColor(context, holeColor!.CGColor)
                CGContextFillEllipseInRect(context, CGRect(x: center.x - holeRadius, y: center.y - holeRadius, width: holeRadius * 2.0, height: holeRadius * 2.0))
            }

            // only draw the circle if it can be seen (not covered by the hole)
            if (transparentCircleRadiusPercent > holeRadiusPercent)
            {
                let alpha = holeAlpha * _animator.phaseX * _animator.phaseY
                let secondHoleRadius = radius * transparentCircleRadiusPercent

                // make transparent
                CGContextSetFillColorWithColor(context, holeColor!.colorWithAlphaComponent(alpha).CGColor)

                // draw the transparent-circle
                CGContextFillEllipseInRect(context, CGRect(x: center.x - secondHoleRadius, y: center.y - secondHoleRadius, width: secondHoleRadius * 2.0, height: secondHoleRadius * 2.0))
            }

Temporary workaround:

pieChart.holeColor = UIColor.clearColor()

@danielgindi
Copy link
Collaborator

You are correct :-)
There are still some !s hanging around from the early days of Swift when it wasn't that clear how much unsafe is that !...
Most of them are gone now, thank god!

@benpackard
Copy link
Author

I think you mean

If let god = god {
    thank(god)
}

Looking forward to testing it out!

@pmairoldi
Copy link
Collaborator

😂

@danielgindi
Copy link
Collaborator

That's a syntax error, should be lowerCase if ;-)

@ais9226
Copy link

ais9226 commented Sep 12, 2018

I need to include a color shadow inside piechart( like holecolor) corresponding to a particular slice. how can i do that?

@jesuasir007
Copy link

how to implement the label instant to create an image in a pie chart
swift 4

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

No branches or pull requests

6 participants