From 0b0d7acc697181d47a66ee7b903d4d6716bcd0f0 Mon Sep 17 00:00:00 2001 From: Xuan Liu Date: Mon, 30 Mar 2020 15:06:37 +0800 Subject: [PATCH 1/2] Fix warnings for vars; Fix unused instants Remove a duplicated function NSUIMainScreen() --- Source/Charts/Renderers/PieChartRenderer.swift | 12 +++++------- .../Renderers/XAxisRendererHorizontalBarChart.swift | 2 +- Source/Charts/Renderers/YAxisRenderer.swift | 2 +- .../Renderers/YAxisRendererHorizontalBarChart.swift | 2 +- Source/Charts/Utils/Platform.swift | 9 ++------- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Source/Charts/Renderers/PieChartRenderer.swift b/Source/Charts/Renderers/PieChartRenderer.swift index 0985a3da8d..19ea0d4607 100644 --- a/Source/Charts/Renderers/PieChartRenderer.swift +++ b/Source/Charts/Renderers/PieChartRenderer.swift @@ -306,8 +306,8 @@ open class PieChartRenderer: DataRenderer // get whole the radius let radius = chart.radius let rotationAngle = chart.rotationAngle - var drawAngles = chart.drawAngles - var absoluteAngles = chart.absoluteAngles + let drawAngles = chart.drawAngles + let absoluteAngles = chart.absoluteAngles let phaseX = animator.phaseX let phaseY = animator.phaseY @@ -321,14 +321,12 @@ open class PieChartRenderer: DataRenderer let labelRadius = radius - labelRadiusOffset - var dataSets = data.dataSets + let dataSets = data.dataSets let yValueSum = (data as! PieChartData).yValueSum let drawEntryLabels = chart.isDrawEntryLabelsEnabled let usePercentValuesEnabled = chart.usePercentValuesEnabled - let entryLabelColor = chart.entryLabelColor - let entryLabelFont = chart.entryLabelFont var angle: CGFloat = 0.0 var xIndex = 0 @@ -353,7 +351,7 @@ open class PieChartRenderer: DataRenderer let yValuePosition = dataSet.yValuePosition let valueFont = dataSet.valueFont - let entryLabelFont = dataSet.entryLabelFont + let entryLabelFont = dataSet.entryLabelFont ?? chart.entryLabelFont let lineHeight = valueFont.lineHeight guard let formatter = dataSet.valueFormatter else { continue } @@ -399,7 +397,7 @@ open class PieChartRenderer: DataRenderer let drawYInside = drawValues && yValuePosition == .insideSlice let valueTextColor = dataSet.valueTextColorAt(j) - let entryLabelColor = dataSet.entryLabelColor + let entryLabelColor = dataSet.entryLabelColor ?? chart.entryLabelColor if drawXOutside || drawYOutside { diff --git a/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift b/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift index ce777746a0..86c569d9df 100644 --- a/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift +++ b/Source/Charts/Renderers/XAxisRendererHorizontalBarChart.swift @@ -251,7 +251,7 @@ open class XAxisRendererHorizontalBarChart: XAxisRenderer let transformer = self.transformer else { return } - var limitLines = xAxis.limitLines + let limitLines = xAxis.limitLines if limitLines.count == 0 { diff --git a/Source/Charts/Renderers/YAxisRenderer.swift b/Source/Charts/Renderers/YAxisRenderer.swift index 80b492d5ee..9d0017f494 100644 --- a/Source/Charts/Renderers/YAxisRenderer.swift +++ b/Source/Charts/Renderers/YAxisRenderer.swift @@ -287,7 +287,7 @@ open class YAxisRenderer: AxisRendererBase let transformer = self.transformer else { return } - var limitLines = yAxis.limitLines + let limitLines = yAxis.limitLines if limitLines.count == 0 { diff --git a/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift b/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift index aaf0cd2553..de4f65e522 100644 --- a/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererHorizontalBarChart.swift @@ -259,7 +259,7 @@ open class YAxisRendererHorizontalBarChart: YAxisRenderer let transformer = self.transformer else { return } - var limitLines = yAxis.limitLines + let limitLines = yAxis.limitLines if limitLines.count <= 0 { diff --git a/Source/Charts/Utils/Platform.swift b/Source/Charts/Utils/Platform.swift index 19fdbf7eec..b7a3da5e07 100644 --- a/Source/Charts/Utils/Platform.swift +++ b/Source/Charts/Utils/Platform.swift @@ -39,11 +39,6 @@ extension UIScreen } } -func NSUIMainScreen() -> NSUIScreen? -{ - return NSUIScreen.main -} - #endif #if os(OSX) @@ -237,9 +232,9 @@ extension NSScrollView } } +#endif + func NSUIMainScreen() -> NSUIScreen? { return NSUIScreen.main } - -#endif From 62e063cdaf3aaef6810f073586a3490dcdf1cd83 Mon Sep 17 00:00:00 2001 From: Xuan Liu Date: Wed, 1 Apr 2020 09:45:26 +0800 Subject: [PATCH 2/2] use extension to replace NSUIMainScreen() --- Source/Charts/Charts/ChartViewBase.swift | 2 +- Source/Charts/Utils/Platform.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index c453aced0c..0fccebc4d2 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -828,7 +828,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// - Returns: The bitmap that represents the chart. @objc open func getChartImage(transparent: Bool) -> NSUIImage? { - NSUIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque || !transparent, NSUIMainScreen()?.nsuiScale ?? 1.0) + NSUIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque || !transparent, NSUIScreen.nsuiMain?.nsuiScale ?? 1.0) guard let context = NSUIGraphicsGetCurrentContext() else { return nil } diff --git a/Source/Charts/Utils/Platform.swift b/Source/Charts/Utils/Platform.swift index b7a3da5e07..3722647d3d 100644 --- a/Source/Charts/Utils/Platform.swift +++ b/Source/Charts/Utils/Platform.swift @@ -234,7 +234,7 @@ extension NSScrollView #endif -func NSUIMainScreen() -> NSUIScreen? +extension NSUIScreen { - return NSUIScreen.main + class var nsuiMain: NSUIScreen? { .main } }