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

Minor improvements in BalloonMarker.swift #2393

Merged
merged 2 commits into from
May 26, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions ChartsDemo/Classes/Components/BalloonMarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class BalloonMarker: MarkerImage
open var insets = UIEdgeInsets()
open var minimumSize = CGSize()

fileprivate var labelns: NSString?
fileprivate var label: String?
fileprivate var _labelSize: CGSize = CGSize()
fileprivate var _paragraphStyle: NSMutableParagraphStyle?
fileprivate var _drawAttributes = [String : AnyObject]()
Expand Down Expand Up @@ -51,10 +51,7 @@ open class BalloonMarker: MarkerImage

open override func draw(context: CGContext, point: CGPoint)
{
if labelns == nil
{
return
}
guard let label = label else { return }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing more indent here, please double check


let offset = self.offsetForDrawing(atPoint: point)
let size = self.size
Expand Down Expand Up @@ -105,7 +102,7 @@ open class BalloonMarker: MarkerImage

UIGraphicsPushContext(context)

labelns?.draw(in: rect, withAttributes: _drawAttributes)
label.draw(in: rect, withAttributes: _drawAttributes)

UIGraphicsPopContext()

Expand All @@ -117,16 +114,16 @@ open class BalloonMarker: MarkerImage
setLabel(String(entry.y))
}

open func setLabel(_ label: String)
open func setLabel(_ newLabel: String)
{
labelns = label as NSString
label = newLabel

_drawAttributes.removeAll()
_drawAttributes[NSFontAttributeName] = self.font
_drawAttributes[NSParagraphStyleAttributeName] = _paragraphStyle
_drawAttributes[NSForegroundColorAttributeName] = self.textColor

_labelSize = labelns?.size(attributes: _drawAttributes) ?? CGSize.zero
_labelSize = label?.size(attributes: _drawAttributes) ?? CGSize.zero

var size = CGSize()
size.width = _labelSize.width + self.insets.left + self.insets.right
Expand Down