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

Errors when importing BalloonMarker #2928

Closed
jack-blackson opened this issue Oct 30, 2017 · 8 comments
Closed

Errors when importing BalloonMarker #2928

jack-blackson opened this issue Oct 30, 2017 · 8 comments

Comments

@jack-blackson
Copy link

Hey!

I imported the BalloonMarker.swift file into my project. when trying to build, I get several errors:

grafik

Is this anything I am doing wrong? When I deactivate those lines, I get a black marker with no content in it.

Thanks,
Jack

@liuxuan30
Copy link
Member

update your xcode.

@jack-blackson
Copy link
Author

Thanks for the answer. I checked my xcode version, and I have Version 9.1 (9B55)...and still get the error. I use the charts pod, and copied the code for the balloonmarker manually from the demo component here on github. Am I missing something?

@coolcool1994
Copy link

You need to set the swift language to swift 4 from Swift 3.2 in Charts project (11/7/2017).

@jack-blackson
Copy link
Author

@coolcool1994 I have set it like this. You mean in Build Settings -> Swift language version, right? Or do I have to change it somewhere else too?

@coolcool1994
Copy link

coolcool1994 commented Nov 12, 2017

If you are using Cocoapod, you need to go to the workspace of your project, then click blue Pod file in the file navigator in the left. Once you click Pod, you need to select Charts in the center panel. There you change the Build Setting -> Swift language for THAT SPECIFIC PROJECT, and make that Swift 4 (as of 11/2017). This is different than just doing Build Settings -> Swift in your own project, okay?

@jack-blackson
Copy link
Author

You mean this, right? This is already set to Swift 4. I am also able to run Charts in general - just those three lines show an error and I can not build a project with them.
grafik

@coolcool1994
Copy link

coolcool1994 commented Nov 12, 2017

YES! That's right. After I did that the newest Charts Pod project worked for me. I can suggest you reinstall the Charts Project once again and check its latest version if this doesn't work. Because it worked for me.

@MateusLB
Copy link

MateusLB commented Mar 8, 2018

I found the old version, work in swift 3
`import Foundation
import Charts
import UIKit

open class BalloonMarker: MarkerImage
{
open var color: UIColor?
open var arrowSize = CGSize(width: 15, height: 11)
open var font: UIFont?
open var textColor: UIColor?
open var insets = UIEdgeInsets()
open var minimumSize = CGSize()

fileprivate var label: String?
fileprivate var _labelSize: CGSize = CGSize()
fileprivate var _paragraphStyle: NSMutableParagraphStyle?
fileprivate var _drawAttributes = [String : AnyObject]()

public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets)
{
    super.init()
    
    self.color = color
    self.font = font
    self.textColor = textColor
    self.insets = insets
    
    _paragraphStyle = NSParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle
    _paragraphStyle?.alignment = .center
}

open override func offsetForDrawing(atPoint point: CGPoint) -> CGPoint
{
    let size = self.size
    var point = point
    point.x -= size.width / 2.0
    point.y -= size.height
    return super.offsetForDrawing(atPoint: point)
}

open override func draw(context: CGContext, point: CGPoint)
{
    guard let label = label else { return }
    
    let offset = self.offsetForDrawing(atPoint: point)
    let size = self.size
    
    var rect = CGRect(
        origin: CGPoint(
            x: point.x + offset.x,
            y: point.y + offset.y),
        size: size)
    rect.origin.x -= size.width / 2.0
    rect.origin.y -= size.height
    
    context.saveGState()
    
    if let color = color
    {
        context.setFillColor(color.cgColor)
        context.beginPath()
        context.move(to: CGPoint(
            x: rect.origin.x,
            y: rect.origin.y))
        context.addLine(to: CGPoint(
            x: rect.origin.x + rect.size.width,
            y: rect.origin.y))
        context.addLine(to: CGPoint(
            x: rect.origin.x + rect.size.width,
            y: rect.origin.y + rect.size.height - arrowSize.height))
        context.addLine(to: CGPoint(
            x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0,
            y: rect.origin.y + rect.size.height - arrowSize.height))
        context.addLine(to: CGPoint(
            x: rect.origin.x + rect.size.width / 2.0,
            y: rect.origin.y + rect.size.height))
        context.addLine(to: CGPoint(
            x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0,
            y: rect.origin.y + rect.size.height - arrowSize.height))
        context.addLine(to: CGPoint(
            x: rect.origin.x,
            y: rect.origin.y + rect.size.height - arrowSize.height))
        context.addLine(to: CGPoint(
            x: rect.origin.x,
            y: rect.origin.y))
        context.fillPath()
    }
    
    rect.origin.y += self.insets.top
    rect.size.height -= self.insets.top + self.insets.bottom
    
    UIGraphicsPushContext(context)
    
    label.draw(in: rect, withAttributes: _drawAttributes)
    
    UIGraphicsPopContext()
    
    context.restoreGState()
}

open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
{
    setLabel(String(entry.y))
}

open func setLabel(_ newLabel: String)
{
    label = newLabel
    
    _drawAttributes.removeAll()
    _drawAttributes[NSFontAttributeName] = self.font
    _drawAttributes[NSParagraphStyleAttributeName] = _paragraphStyle
    _drawAttributes[NSForegroundColorAttributeName] = self.textColor
    
    _labelSize = label?.size(attributes: _drawAttributes) ?? CGSize.zero
    
    var size = CGSize()
    size.width = _labelSize.width + self.insets.left + self.insets.right
    size.height = _labelSize.height + self.insets.top + self.insets.bottom
    size.width = max(minimumSize.width, size.width)
    size.height = max(minimumSize.height, size.height)
    self.size = size
}

}
`

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

4 participants