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

swift 3.x -> New ChartMarker? #2369

Closed
NoctizJ opened this issue Apr 17, 2017 · 1 comment
Closed

swift 3.x -> New ChartMarker? #2369

NoctizJ opened this issue Apr 17, 2017 · 1 comment

Comments

@NoctizJ
Copy link

NoctizJ commented Apr 17, 2017

Xcode 8.3.1 force us to use swift 3.x. So I pull in Charts with 3.x version. I have a swift class that uses old ChartMarker after apple's wizard of convert swift version. It seems there is no longer ChartMarker in Swift 3.x. What is the equivalent of that, and could someone help me fix these piece of codes? Thank you in advance!

import Foundation
import UIKit;
import Charts;

open class BalloonMarker: ChartMarker
{
open var bounds = CGRect()
open var dates = NSArray()
open var values = NSArray()
fileprivate var referenceVal = Double()

fileprivate var _size: CGSize = CGSize()
fileprivate var tooltipView: TooltipView

public init(dates: NSArray, values: NSArray, bounds: CGRect, tooltipView: TooltipView)
{
self.tooltipView = tooltipView
_size = tooltipView.frame.size
super.init()

self.dates = dates
self.values = values
self.bounds = bounds
self.referenceVal = values.firstObject as! Double

}

open override var size: CGSize { return _size; }

open override func draw(context: CGContext, point: CGPoint)
{
var rect = CGRect(origin: point, size: self.tooltipView.bounds.size)
let midY = (self.bounds.origin.y + (self.bounds.size.height / 2))
let midX = (self.bounds.origin.x + (self.bounds.size.width / 2))
if (point.y > midY) {
rect.origin.y -= rect.size.height
}

if (point.x > midX) {
  rect.origin.x -= rect.size.width
}
self.tooltipView.frame = rect

}

open override func refreshContent(entry: ChartDataEntry, highlight: ChartHighlight)
{
let date = self.dates[entry.xIndex] as! NSString
let value = self.values[entry.xIndex] as! Double
self.tooltipView.setItemWithDate(date as String, withValue: value, withReferenceValue: self.referenceVal)
}
}

@fogisland
Copy link

ChartMarker has been re-written with swift3, try it:
https://github.com/danielgindi/Charts/blob/master/ChartsDemo/Classes/Components/BalloonMarker.swift

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

3 participants