Skip to content

Commit

Permalink
Platform separation (#4178)
Browse files Browse the repository at this point in the history
* Added system dark mode support for primary label colors in the framework

Moved Color to its own Platform file

* Relocated color file

* Reverted demo change

* Separated `Platform` into multiple files for better organization

* Updated from master
  • Loading branch information
jjatie authored and liuxuan30 committed Nov 8, 2019
1 parent a5fda8f commit b630e88
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 429 deletions.
16 changes: 16 additions & 0 deletions Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
C33E1AF5471A60BA42DAF52E /* RadarHighlighter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F368CF209744D8F3B85B1028 /* RadarHighlighter.swift */; };
C3F0DDB7F0A922F0BB7EDB8A /* IBarChartDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A53A9E42FC07FFDACA937C1 /* IBarChartDataSet.swift */; };
C7B150D740255670DEB9F455 /* Charts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65AD9E95D9ED4DC0BD73A743 /* Charts.framework */; };
C9AA360A2355F01F00C97D93 /* Platform+Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9AA36092355F01F00C97D93 /* Platform+Color.swift */; };
C9F3DC262355F791000C3215 /* Platform+Graphics.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F3DC242355F791000C3215 /* Platform+Graphics.swift */; };
C9F3DC272355F791000C3215 /* Platform+Gestures.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F3DC252355F791000C3215 /* Platform+Gestures.swift */; };
C9F3DC292355FA2F000C3215 /* Platform+Touch Handling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F3DC282355FA2F000C3215 /* Platform+Touch Handling.swift */; };
CB785FE9B6B312408D17BC3B /* ChartUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FDA09EF973925A110506799 /* ChartUtils.swift */; };
CC7F8198A13249B5DEBBF25E /* AnimatedViewPortJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710D7C9B2F1DB4A331EE405A /* AnimatedViewPortJob.swift */; };
CEF68F42A5390A73113F3663 /* Renderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F66B32AD8A878CBD6DB6ED2 /* Renderer.swift */; };
Expand Down Expand Up @@ -289,6 +293,10 @@
C75935E899183DDFA181E2CC /* AxisRendererBase.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = AxisRendererBase.swift; path = Source/Charts/Renderers/AxisRendererBase.swift; sourceTree = "<group>"; };
C8C9A105A7DB64F39DDA648B /* ComponentBase.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ComponentBase.swift; path = Source/Charts/Components/ComponentBase.swift; sourceTree = "<group>"; };
C8FB6219B143F8F7DA762950 /* TriangleShapeRenderer.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TriangleShapeRenderer.swift; path = Source/Charts/Renderers/Scatter/TriangleShapeRenderer.swift; sourceTree = "<group>"; };
C9AA36092355F01F00C97D93 /* Platform+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Platform+Color.swift"; path = "Source/Charts/Utils/Platform+Color.swift"; sourceTree = "<group>"; };
C9F3DC242355F791000C3215 /* Platform+Graphics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Platform+Graphics.swift"; path = "Source/Charts/Utils/Platform+Graphics.swift"; sourceTree = "<group>"; };
C9F3DC252355F791000C3215 /* Platform+Gestures.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Platform+Gestures.swift"; path = "Source/Charts/Utils/Platform+Gestures.swift"; sourceTree = "<group>"; };
C9F3DC282355FA2F000C3215 /* Platform+Touch Handling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Platform+Touch Handling.swift"; path = "Source/Charts/Utils/Platform+Touch Handling.swift"; sourceTree = "<group>"; };
C9FE42E868A225C116537368 /* ChartBaseDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ChartBaseDataSet.swift; path = Source/Charts/Data/Implementations/ChartBaseDataSet.swift; sourceTree = "<group>"; };
CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ScatterChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/ScatterChartDataSet.swift; sourceTree = "<group>"; };
D2E1819D72CD7B6C4A4E8048 /* LineChartTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = LineChartTests.swift; path = Tests/Charts/LineChartTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -590,6 +598,10 @@
5A4CFFFB65819121595F06F1 /* Fill.swift */,
3ED23C354AFE81818D78E645 /* Platform.swift */,
97AD2D4520AF917100F9C24A /* Platform+Accessibility.swift */,
C9AA36092355F01F00C97D93 /* Platform+Color.swift */,
C9F3DC252355F791000C3215 /* Platform+Gestures.swift */,
C9F3DC242355F791000C3215 /* Platform+Graphics.swift */,
C9F3DC282355FA2F000C3215 /* Platform+Touch Handling.swift */,
FF475B9593B9898853814340 /* Transformer.swift */,
324C9127B53A8D39C8B49277 /* TransformerHorizontalBarChart.swift */,
72EAEBB7CF73E33565FC2896 /* ViewPortHandler.swift */,
Expand Down Expand Up @@ -839,6 +851,7 @@
DBC9DB402CC9BB84B76968C4 /* Description.swift in Sources */,
03960E8148C6AEDACE4B77CC /* IMarker.swift in Sources */,
ECE7EAE7179A7F57CE9BBD8F /* Legend.swift in Sources */,
C9F3DC272355F791000C3215 /* Platform+Gestures.swift in Sources */,
C20A62D8CB9120523D5FB650 /* LegendEntry.swift in Sources */,
369DEB23452CB436A3A1A644 /* MarkerImage.swift in Sources */,
9360348A04723E653FBC8B18 /* MarkerView.swift in Sources */,
Expand All @@ -848,6 +861,7 @@
3395682A1E27756651FF6F4D /* BarChartData.swift in Sources */,
45C459FA25DFCBE62FA6A06C /* BarChartDataEntry.swift in Sources */,
17E994DA88777AA1D8CCFC58 /* BarChartDataSet.swift in Sources */,
C9AA360A2355F01F00C97D93 /* Platform+Color.swift in Sources */,
7C9CE6718D18859A35146098 /* BarLineScatterCandleBubbleChartData.swift in Sources */,
53A91F6F86740E26FE733639 /* BarLineScatterCandleBubbleChartDataSet.swift in Sources */,
E68CA3DC66EB638C956E09B8 /* BubbleChartData.swift in Sources */,
Expand Down Expand Up @@ -893,6 +907,7 @@
B6C9F450D937B87224D29D5C /* IFillFormatter.swift in Sources */,
967EE2EDDE3337C5C4337C59 /* IndexAxisValueFormatter.swift in Sources */,
A40ACF0CCE96EEE104B0463D /* IValueFormatter.swift in Sources */,
C9F3DC262355F791000C3215 /* Platform+Graphics.swift in Sources */,
3CBE95F1E9394FA08CDCF31E /* BarHighlighter.swift in Sources */,
D326491E8BCDE54A0921E137 /* ChartHighlighter.swift in Sources */,
64FA1EDB4DC1F65727D52D10 /* CombinedHighlighter.swift in Sources */,
Expand All @@ -908,6 +923,7 @@
4272DA5D44AF7DA05A5A8287 /* BubbleChartDataProvider.swift in Sources */,
30DCC4BAA5601B154ABADA13 /* CandleChartDataProvider.swift in Sources */,
FD37AAC0270F390FFC470A65 /* ChartDataProvider.swift in Sources */,
C9F3DC292355FA2F000C3215 /* Platform+Touch Handling.swift in Sources */,
65EA404AE098EBCE8D5DE04B /* CombinedChartDataProvider.swift in Sources */,
2BA03CEC36BADCF682F1328B /* LineChartDataProvider.swift in Sources */,
0511E43EF3FD2CDE7F7F15DB /* ScatterChartDataProvider.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
// Copyright © 2017 jc. All rights reserved.
//

#if canImport(UIKit)
import UIKit
#endif
import UIKit
import Charts

class PiePolylineChartViewController: DemoBaseViewController {
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
@objc open var noDataFont = NSUIFont.systemFont(ofSize: 12)

/// color of the no data text
@objc open var noDataTextColor: NSUIColor = NSUIColor.labelOrBlack
@objc open var noDataTextColor: NSUIColor = .labelOrBlack

/// alignment of the no data text
@objc open var noDataTextAlignment: NSTextAlignment = .left
Expand Down
4 changes: 2 additions & 2 deletions Source/Charts/Data/Implementations/ChartBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class ChartBaseDataSet: NSObject, IChartDataSet, NSCopying

// default color
colors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0))
valueColors.append(NSUIColor.labelOrBlack)
valueColors.append(.labelOrBlack)
}

@objc public init(label: String?)
Expand All @@ -30,7 +30,7 @@ open class ChartBaseDataSet: NSObject, IChartDataSet, NSCopying

// default color
colors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0))
valueColors.append(NSUIColor.labelOrBlack)
valueColors.append(.labelOrBlack)

self.label = label
}
Expand Down
53 changes: 53 additions & 0 deletions Source/Charts/Utils/Platform+Color.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Platform+Color.swift
// Charts
//
// Created by Jacob Christie on 2019-10-15.
//

#if canImport(UIKit)
import UIKit

public typealias NSUIColor = UIColor
private func fetchLabelColor() -> UIColor
{
if #available(iOS 13, tvOS 13, *)
{
return .label
}
else
{
return .black
}
}
private let labelColor: UIColor = fetchLabelColor()

extension UIColor
{
static var labelOrBlack: UIColor { labelColor }
}
#endif

#if canImport(AppKit)

import AppKit

public typealias NSUIColor = NSColor
private func fetchLabelColor() -> NSColor
{
if #available(macOS 10.14, *)
{
return .labelColor
}
else
{
return .black
}
}
private let labelColor: NSColor = fetchLabelColor()

extension NSColor
{
static var labelOrBlack: NSColor { labelColor }
}
#endif
168 changes: 168 additions & 0 deletions Source/Charts/Utils/Platform+Gestures.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
//
// Platform+Gestures.swift
//
//
// Created by Jacob Christie on 2019-10-15.
//

// MARK: - UIKit
#if canImport(UIKit)
import UIKit

public typealias NSUIGestureRecognizer = UIGestureRecognizer
public typealias NSUIGestureRecognizerState = UIGestureRecognizer.State
public typealias NSUIGestureRecognizerDelegate = UIGestureRecognizerDelegate
public typealias NSUITapGestureRecognizer = UITapGestureRecognizer
public typealias NSUIPanGestureRecognizer = UIPanGestureRecognizer

extension NSUITapGestureRecognizer
{
@objc final func nsuiNumberOfTouches() -> Int
{
return numberOfTouches
}

@objc final var nsuiNumberOfTapsRequired: Int
{
get
{
return self.numberOfTapsRequired
}
set
{
self.numberOfTapsRequired = newValue
}
}
}

extension NSUIPanGestureRecognizer
{
@objc final func nsuiNumberOfTouches() -> Int
{
return numberOfTouches
}

@objc final func nsuiLocationOfTouch(_ touch: Int, inView: UIView?) -> CGPoint
{
return super.location(ofTouch: touch, in: inView)
}
}

#if !os(tvOS)
public typealias NSUIPinchGestureRecognizer = UIPinchGestureRecognizer
public typealias NSUIRotationGestureRecognizer = UIRotationGestureRecognizer

extension NSUIRotationGestureRecognizer
{
@objc final var nsuiRotation: CGFloat
{
get { return rotation }
set { rotation = newValue }
}
}

extension NSUIPinchGestureRecognizer
{
@objc final var nsuiScale: CGFloat
{
get
{
return scale
}
set
{
scale = newValue
}
}

@objc final func nsuiLocationOfTouch(_ touch: Int, inView: UIView?) -> CGPoint
{
return super.location(ofTouch: touch, in: inView)
}
}
#endif
#endif

// MARK: - AppKit
#if canImport(AppKit)
import AppKit

public typealias NSUIGestureRecognizer = NSGestureRecognizer
public typealias NSUIGestureRecognizerState = NSGestureRecognizer.State
public typealias NSUIGestureRecognizerDelegate = NSGestureRecognizerDelegate
public typealias NSUITapGestureRecognizer = NSClickGestureRecognizer
public typealias NSUIPanGestureRecognizer = NSPanGestureRecognizer
public typealias NSUIPinchGestureRecognizer = NSMagnificationGestureRecognizer
public typealias NSUIRotationGestureRecognizer = NSRotationGestureRecognizer

/** The 'tap' gesture is mapped to clicks. */
extension NSUITapGestureRecognizer
{
final func nsuiNumberOfTouches() -> Int
{
return 1
}

final var nsuiNumberOfTapsRequired: Int
{
get
{
return self.numberOfClicksRequired
}
set
{
self.numberOfClicksRequired = newValue
}
}
}

extension NSUIPanGestureRecognizer
{
final func nsuiNumberOfTouches() -> Int
{
return 1
}

/// FIXME: Currently there are no more than 1 touch in OSX gestures, and not way to create custom touch gestures.
final func nsuiLocationOfTouch(_ touch: Int, inView: NSView?) -> NSPoint
{
return super.location(in: inView)
}
}

extension NSUIRotationGestureRecognizer
{
/// FIXME: Currently there are no velocities in OSX gestures, and not way to create custom touch gestures.
final var velocity: CGFloat
{
return 0.1
}

final var nsuiRotation: CGFloat
{
get { return -rotation }
set { rotation = -newValue }
}
}

extension NSUIPinchGestureRecognizer
{
final var nsuiScale: CGFloat
{
get
{
return magnification + 1.0
}
set
{
magnification = newValue - 1.0
}
}

/// FIXME: Currently there are no more than 1 touch in OSX gestures, and not way to create custom touch gestures.
final func nsuiLocationOfTouch(_ touch: Int, inView view: NSView?) -> NSPoint
{
return super.location(in: view)
}
}
#endif
Loading

0 comments on commit b630e88

Please sign in to comment.