Skip to content

Commit

Permalink
FIxes for OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelspark committed Aug 30, 2016
1 parent a3c03c2 commit 3c01781
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 47 deletions.
2 changes: 2 additions & 0 deletions Charts/Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1527,6 +1528,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public class ChartViewBase: NSUIView, ChartDataProvider, ChartAnimatorDelegate
// 23 is the smallest recommended font size on the TV
font = NSUIFont.systemFont(ofSize: 23, weight: UIFontWeightMedium)
#else
font = NSUIFont.systemFont(ofSize: NSUIFont.systemFontSize)
font = NSUIFont.systemFont(ofSize: NSUIFont.nsuiSystemFontSize)
#endif
}

Expand Down
12 changes: 6 additions & 6 deletions Charts/Classes/Charts/PieRadarChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public class PieRadarChartViewBase: ChartViewBase
#endif

#if os(OSX)
public override func mouseDown(_ theEvent: NSEvent)
public override func mouseDown(with theEvent: NSEvent)
{
// if rotation by touch is enabled
if rotationEnabled
Expand All @@ -641,11 +641,11 @@ public class PieRadarChartViewBase: ChartViewBase

if !_isRotating
{
super.mouseDown(theEvent)
super.mouseDown(with: theEvent)
}
}

public override func mouseDragged(_ theEvent: NSEvent)
public override func mouseDragged(with theEvent: NSEvent)
{
if rotationEnabled
{
Expand All @@ -656,15 +656,15 @@ public class PieRadarChartViewBase: ChartViewBase

if !_isRotating
{
super.mouseDragged(theEvent)
super.mouseDragged(with: theEvent)
}
}

public override func mouseUp(_ theEvent: NSEvent)
public override func mouseUp(with theEvent: NSEvent)
{
if !_isRotating
{
super.mouseUp(theEvent)
super.mouseUp(with: theEvent)
}

if rotationEnabled
Expand Down
20 changes: 10 additions & 10 deletions Charts/Classes/Data/Implementations/Standard/ChartDataEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public class ChartDataEntry: NSObject

public override func isEqual(_ object: Any?) -> Bool
{
let object = object as? AnyObject
if (object === nil)
{
return false
}
if (!object!.isKind(of: type(of: self)))
if (object == nil)
{
return false
}

let object = object as AnyObject

if (!object.isKind(of: type(of: self)))
{
return false
}
Expand All @@ -68,12 +68,12 @@ public class ChartDataEntry: NSObject
return false
}

if (object!.xIndex != xIndex)
if (object.xIndex != xIndex)
{
return false
}

if (fabs(object!.value - value) > 0.00001)
if (fabs(object.value - value) > 0.00001)
{
return false
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Highlight/BarChartHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public class BarChartHighlighter: ChartHighlighter
self.chart?.getTransformer(ChartYAxis.AxisDependency.left).pixelToValue(&pt)
let xVal = Double(pt.x)

let setCount = barData.dataSetCount ?? 0
let setCount = barData.dataSetCount

// calculate how often the group-space appears
let steps = Int(xVal / (Double(setCount) + Double(barData.groupSpace)))
Expand Down
19 changes: 9 additions & 10 deletions Charts/Classes/Highlight/ChartHighlight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,39 @@ public class ChartHighlight: NSObject

public override func isEqual(_ object: Any?) -> Bool
{

let object = object as? AnyObject

if (object === nil)
if (object == nil)
{
return false
}

let object = object as AnyObject

if (!object!.isKind(of: type(of: self)))
if (!object.isKind(of: type(of: self)))
{
return false
}

if (object!.xIndex != _xIndex)
if (object.xIndex != _xIndex)
{
return false
}

if (object!.dataIndex != dataIndex)
if (object.dataIndex != dataIndex)
{
return false
}

if (object!.dataSetIndex != _dataSetIndex)
if (object.dataSetIndex != _dataSetIndex)
{
return false
}

if (object!.stackIndex != _stackIndex)
if (object.stackIndex != _stackIndex)
{
return false
}

if (object!.value != value)
if (object.value != value)
{
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class HorizontalBarChartHighlighter: BarChartHighlighter
self.chart?.getTransformer(ChartYAxis.AxisDependency.left).pixelToValue(&pt)
let yVal = Double(pt.y)

let setCount = barData.dataSetCount ?? 0
let setCount = barData.dataSetCount

// calculate how often the group-space appears
let steps = Int(yVal / (Double(setCount) + Double(barData.groupSpace)))
Expand Down
6 changes: 3 additions & 3 deletions Charts/Classes/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class LineChartRenderer: LineRadarChartRenderer
// the path for the cubic-spline
let cubicPath = CGMutablePath()

var valueToPixelMatrix = trans.valueToPixelMatrix
let valueToPixelMatrix = trans.valueToPixelMatrix

let size = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx)))

Expand Down Expand Up @@ -197,7 +197,7 @@ public class LineChartRenderer: LineRadarChartRenderer
// the path for the cubic-spline
let cubicPath = CGMutablePath()

var valueToPixelMatrix = trans.valueToPixelMatrix
let valueToPixelMatrix = trans.valueToPixelMatrix

let size = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx)))

Expand Down Expand Up @@ -475,7 +475,7 @@ public class LineChartRenderer: LineRadarChartRenderer
let phaseX = max(0.0, min(1.0, animator?.phaseX ?? 1.0))
let phaseY = animator?.phaseY ?? 1.0
let drawSteppedEnabled = dataSet.mode == .stepped
var matrix = matrix
let matrix = matrix

var e: ChartDataEntry!

Expand Down
30 changes: 24 additions & 6 deletions Charts/Classes/Utils/ChartPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
}

extension NSUIFont {
static var nsuiSystemFontSize: CGFloat {
return NSUIFont.systemFontSize
}
}

#endif

#if os(OSX)
Expand All @@ -221,6 +227,12 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
public typealias NSUIRotationGestureRecognizer = NSRotationGestureRecognizer
public typealias NSUIScreen = NSScreen

extension NSUIFont {
static var nsuiSystemFontSize: CGFloat {
return NSUIFont.systemFontSize()
}
}

/** On OS X there is no CADisplayLink. Use a 60 fps timer to render the animations. */
public class NSUIDisplayLink
{
Expand Down Expand Up @@ -251,7 +263,7 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
_self._target?.performSelector(onMainThread: _self._selector, with: _self, waitUntilDone: false)

return kCVReturnSuccess
}, UnsafeMutablePointer(unsafeAddress(of: self)))
}, Unmanaged.passUnretained(self).toOpaque())
}
else
{
Expand Down Expand Up @@ -503,9 +515,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple

func NSUIGraphicsPushContext(_ context: CGContext)
{
let address = unsafeAddress(of: context)
let ptr: UnsafeMutablePointer<CGContext> = UnsafeMutablePointer(UnsafePointer<CGContext>(address))
let cx = NSGraphicsContext(graphicsPort: ptr, flipped: true)
let address = Unmanaged.passUnretained(context).toOpaque()
let cx = NSGraphicsContext(graphicsPort: address, flipped: true)
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.setCurrent(cx)
}
Expand Down Expand Up @@ -550,8 +561,8 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple

let colorSpace = CGColorSpaceCreateDeviceRGB()
let ctx = CGContext(data: nil, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 4*width, space: colorSpace, bitmapInfo: (opaque ? CGImageAlphaInfo.noneSkipFirst.rawValue : CGImageAlphaInfo.premultipliedFirst.rawValue))
ctx?.concatCTM(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(height)))
ctx?.scale(x: scale, y: scale)
ctx?.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: CGFloat(height)))
ctx?.scaleBy(x: scale, y: scale)
NSUIGraphicsPushContext(ctx!)
}
}
Expand Down Expand Up @@ -586,6 +597,13 @@ types are aliased to either their UI* implementation (on iOS) or their NS* imple
return NSUIScreen.main()
}

extension NSParagraphStyle {
// This, oddly, is different on iOS (default is a static function on OS X)
static var `default`: NSParagraphStyle {
return NSParagraphStyle.default()
}
}

extension NSString {
/** On OS X, only size(withAttributes:) exists. It is expected that OSX will catch up and also change to
size(attributes:). For now, use this as proxy. */
Expand Down
15 changes: 7 additions & 8 deletions Charts/Classes/Utils/ChartSelectionDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,29 @@ public class ChartSelectionDetail: NSObject

public override func isEqual(_ object: Any?) -> Bool
{

let object = object as? AnyObject

if (object === nil)
if (object == nil)
{
return false
}

let object = object as AnyObject

if (!object!.isKind(of: type(of: self)))
if (!object.isKind(of: type(of: self)))
{
return false
}

if (object!.value != _value)
if (object.value != _value)
{
return false
}

if (object!.dataSetIndex != _dataSetIndex)
if (object.dataSetIndex != _dataSetIndex)
{
return false
}

if (object!.dataSet !== _dataSet)
if (object.dataSet !== _dataSet)
{
return false
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Utils/ChartUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public class ChartUtils
}
else
{
newArray.append(val as! NSObject)
newArray.append(NSString(string: val!))
}
}
return newArray
Expand Down

0 comments on commit 3c01781

Please sign in to comment.