From 453e521275caea727111b6098ba242666509f354 Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Tue, 15 Oct 2019 09:29:34 -0300 Subject: [PATCH 1/5] Added system dark mode support for primary label colors in the framework Moved Color to its own Platform file --- Charts.xcodeproj/project.pbxproj | 4 +++ .../PiePolylineChartViewController.swift | 2 +- .../Contents.swift | 2 +- .../LineChart.xcplaygroundpage/Contents.swift | 2 +- Source/Charts/Charts/ChartViewBase.swift | 2 +- Source/Charts/Components/AxisBase.swift | 2 +- Source/Charts/Components/ChartLimitLine.swift | 2 +- Source/Charts/Components/Description.swift | 2 +- Source/Charts/Components/Legend.swift | 2 +- .../Implementations/ChartBaseDataSet.swift | 4 +-- Source/Charts/Utils/Platform+Color.swift | 28 +++++++++++++++++++ Source/Charts/Utils/Platform.swift | 2 -- 12 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 Source/Charts/Utils/Platform+Color.swift diff --git a/Charts.xcodeproj/project.pbxproj b/Charts.xcodeproj/project.pbxproj index 6d11013875..d2177d5a48 100644 --- a/Charts.xcodeproj/project.pbxproj +++ b/Charts.xcodeproj/project.pbxproj @@ -124,6 +124,7 @@ 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 */; }; 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 */; }; @@ -289,6 +290,7 @@ C75935E899183DDFA181E2CC /* AxisRendererBase.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = AxisRendererBase.swift; path = Source/Charts/Renderers/AxisRendererBase.swift; sourceTree = ""; }; C8C9A105A7DB64F39DDA648B /* ComponentBase.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ComponentBase.swift; path = Source/Charts/Components/ComponentBase.swift; sourceTree = ""; }; C8FB6219B143F8F7DA762950 /* TriangleShapeRenderer.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TriangleShapeRenderer.swift; path = Source/Charts/Renderers/Scatter/TriangleShapeRenderer.swift; sourceTree = ""; }; + C9AA36092355F01F00C97D93 /* Platform+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Platform+Color.swift"; sourceTree = ""; }; C9FE42E868A225C116537368 /* ChartBaseDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ChartBaseDataSet.swift; path = Source/Charts/Data/Implementations/ChartBaseDataSet.swift; sourceTree = ""; }; CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ScatterChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/ScatterChartDataSet.swift; sourceTree = ""; }; D2E1819D72CD7B6C4A4E8048 /* LineChartTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = LineChartTests.swift; path = Tests/Charts/LineChartTests.swift; sourceTree = ""; }; @@ -590,6 +592,7 @@ 5A4CFFFB65819121595F06F1 /* Fill.swift */, 3ED23C354AFE81818D78E645 /* Platform.swift */, 97AD2D4520AF917100F9C24A /* Platform+Accessibility.swift */, + C9AA36092355F01F00C97D93 /* Platform+Color.swift */, FF475B9593B9898853814340 /* Transformer.swift */, 324C9127B53A8D39C8B49277 /* TransformerHorizontalBarChart.swift */, 72EAEBB7CF73E33565FC2896 /* ViewPortHandler.swift */, @@ -848,6 +851,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 */, diff --git a/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift b/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift index 75b5d99faf..307f7e8583 100644 --- a/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift +++ b/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift @@ -93,7 +93,7 @@ class PiePolylineChartViewController: DemoBaseViewController { pFormatter.percentSymbol = " %" data.setValueFormatter(DefaultValueFormatter(formatter: pFormatter)) data.setValueFont(.systemFont(ofSize: 11, weight: .light)) - data.setValueTextColor(.black) + data.setValueTextColor(.label) chartView.data = data chartView.highlightValues(nil) diff --git a/ChartsDemo-macOS/PlaygroundChart.playground/Pages/BubbleChart.xcplaygroundpage/Contents.swift b/ChartsDemo-macOS/PlaygroundChart.playground/Pages/BubbleChart.xcplaygroundpage/Contents.swift index 1e574aa7d4..eb872f2ede 100644 --- a/ChartsDemo-macOS/PlaygroundChart.playground/Pages/BubbleChart.xcplaygroundpage/Contents.swift +++ b/ChartsDemo-macOS/PlaygroundChart.playground/Pages/BubbleChart.xcplaygroundpage/Contents.swift @@ -59,7 +59,7 @@ for index in 0.. Date: Tue, 15 Oct 2019 09:50:01 -0300 Subject: [PATCH 2/5] Relocated color file --- Charts.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Charts.xcodeproj/project.pbxproj b/Charts.xcodeproj/project.pbxproj index d2177d5a48..d0be9ab202 100644 --- a/Charts.xcodeproj/project.pbxproj +++ b/Charts.xcodeproj/project.pbxproj @@ -290,7 +290,7 @@ C75935E899183DDFA181E2CC /* AxisRendererBase.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = AxisRendererBase.swift; path = Source/Charts/Renderers/AxisRendererBase.swift; sourceTree = ""; }; C8C9A105A7DB64F39DDA648B /* ComponentBase.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ComponentBase.swift; path = Source/Charts/Components/ComponentBase.swift; sourceTree = ""; }; C8FB6219B143F8F7DA762950 /* TriangleShapeRenderer.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = TriangleShapeRenderer.swift; path = Source/Charts/Renderers/Scatter/TriangleShapeRenderer.swift; sourceTree = ""; }; - C9AA36092355F01F00C97D93 /* Platform+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Platform+Color.swift"; sourceTree = ""; }; + C9AA36092355F01F00C97D93 /* Platform+Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Platform+Color.swift"; path = "Source/Charts/Utils/Platform+Color.swift"; sourceTree = ""; }; C9FE42E868A225C116537368 /* ChartBaseDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ChartBaseDataSet.swift; path = Source/Charts/Data/Implementations/ChartBaseDataSet.swift; sourceTree = ""; }; CB1DD1A0F64266A10EE94194 /* ScatterChartDataSet.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = ScatterChartDataSet.swift; path = Source/Charts/Data/Implementations/Standard/ScatterChartDataSet.swift; sourceTree = ""; }; D2E1819D72CD7B6C4A4E8048 /* LineChartTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = LineChartTests.swift; path = Tests/Charts/LineChartTests.swift; sourceTree = ""; }; From d994d8d8ae37fbc535581bd821cf1035fd6d1c80 Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Tue, 15 Oct 2019 11:10:45 -0300 Subject: [PATCH 3/5] Reverted demo change --- .../Swift/Demos/PiePolylineChartViewController.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift b/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift index 307f7e8583..a25000739b 100644 --- a/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift +++ b/ChartsDemo-iOS/Swift/Demos/PiePolylineChartViewController.swift @@ -6,9 +6,7 @@ // Copyright © 2017 jc. All rights reserved. // -#if canImport(UIKit) - import UIKit -#endif +import UIKit import Charts class PiePolylineChartViewController: DemoBaseViewController { @@ -93,7 +91,7 @@ class PiePolylineChartViewController: DemoBaseViewController { pFormatter.percentSymbol = " %" data.setValueFormatter(DefaultValueFormatter(formatter: pFormatter)) data.setValueFont(.systemFont(ofSize: 11, weight: .light)) - data.setValueTextColor(.label) + data.setValueTextColor(.black) chartView.data = data chartView.highlightValues(nil) From 2de3b5aa52451a93260f56ec8940e900e937e201 Mon Sep 17 00:00:00 2001 From: Xuan Date: Wed, 16 Oct 2019 08:48:57 +0800 Subject: [PATCH 4/5] Update Platform+Color.swift follow code style --- Source/Charts/Utils/Platform+Color.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Utils/Platform+Color.swift b/Source/Charts/Utils/Platform+Color.swift index fcee6bd64f..1d495574b9 100644 --- a/Source/Charts/Utils/Platform+Color.swift +++ b/Source/Charts/Utils/Platform+Color.swift @@ -9,7 +9,8 @@ import UIKit public typealias NSUIColor = UIColor -extension UIColor { +extension UIColor +{ @available(iOS, introduced: 8.0, obsoleted: 13.0) @available(tvOS, introduced: 9.0, obsoleted: 13.0) static var label: UIColor { .black } @@ -21,7 +22,8 @@ extension UIColor { import AppKit public typealias NSUIColor = NSColor -extension NSColor { +extension NSColor +{ @available(macOS, introduced: 10.11, obsoleted: 10.14) static var label: NSColor { .black } } From dbf90e3df7bae16547eba1d4338492ce42e4ed0d Mon Sep 17 00:00:00 2001 From: Jacob Christie Date: Wed, 16 Oct 2019 07:01:58 -0300 Subject: [PATCH 5/5] Code style fix --- Source/Charts/Charts/PieChartView.swift | 2 +- Source/Charts/Utils/Platform+Color.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Charts/Charts/PieChartView.swift b/Source/Charts/Charts/PieChartView.swift index bc6dc4124f..cf71be1bb6 100644 --- a/Source/Charts/Charts/PieChartView.swift +++ b/Source/Charts/Charts/PieChartView.swift @@ -363,7 +363,7 @@ open class PieChartView: PieRadarChartViewBase attrString = NSMutableAttributedString(string: newValue!) attrString?.setAttributes([ - .foregroundColor: NSUIColor.black, + .foregroundColor: NSUIColor.label, .font: NSUIFont.systemFont(ofSize: 12.0), .paragraphStyle: paragraphStyle ], range: NSMakeRange(0, attrString!.length)) diff --git a/Source/Charts/Utils/Platform+Color.swift b/Source/Charts/Utils/Platform+Color.swift index 1d495574b9..2372d88858 100644 --- a/Source/Charts/Utils/Platform+Color.swift +++ b/Source/Charts/Utils/Platform+Color.swift @@ -9,7 +9,7 @@ import UIKit public typealias NSUIColor = UIColor -extension UIColor +extension UIColor { @available(iOS, introduced: 8.0, obsoleted: 13.0) @available(tvOS, introduced: 9.0, obsoleted: 13.0) @@ -22,7 +22,7 @@ extension UIColor import AppKit public typealias NSUIColor = NSColor -extension NSColor +extension NSColor { @available(macOS, introduced: 10.11, obsoleted: 10.14) static var label: NSColor { .black }