From 3dc39c4f98cc182071567747ec05d3cb2534d98b Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:13:41 +0800 Subject: [PATCH 1/8] refactor: remove _highlightPerTapEnabled --- Source/Charts/Charts/ChartViewBase.swift | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index b8e6fc1f4a..3325950f19 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -72,9 +72,6 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } } - /// Flag that indicates if highlighting per tap (touch) is enabled - private var _highlightPerTapEnabled = true - /// If set to true, chart continues to scroll after touch up @objc open var dragDecelerationEnabled = true @@ -337,12 +334,8 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// Set this to false to prevent values from being highlighted by tap gesture. /// Values can still be highlighted via drag or programmatically. /// **default**: true - @objc open var highlightPerTapEnabled: Bool - { - get { return _highlightPerTapEnabled } - set { _highlightPerTapEnabled = newValue } - } - + @objc open var highlightPerTapEnabled: Bool = true + /// `true` if values can be highlighted via tap gesture, `false` ifnot. @objc open var isHighLightPerTapEnabled: Bool { From dcbd32a8864c4f73dd4ff69b31ee91e8fc67d6a5 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:15:07 +0800 Subject: [PATCH 2/8] refactor: remove _drawUnitInChart --- Source/Charts/Charts/ChartViewBase.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 3325950f19..2e97bf754e 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -75,10 +75,6 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// If set to true, chart continues to scroll after touch up @objc open var dragDecelerationEnabled = true - /// if true, units are drawn next to the values in the chart - // TODO: This is used nowhere and can't be used by a consumer. Can we remove this property? - internal var _drawUnitInChart = false - /// The object representing the labels on the x-axis @objc open internal(set) lazy var xAxis = XAxis() From f6c0455385659518c88e36258d0aa9f07ddceee4 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:18:01 +0800 Subject: [PATCH 3/8] refactor: remove interceptTouchEvents --- Source/Charts/Charts/ChartViewBase.swift | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 2e97bf754e..db4d5e76a0 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -135,9 +135,6 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// The marker that is displayed when a value is clicked on the chart @objc open var marker: Marker? - // TODO: There is no way to modify this value. Should it exist? - private let interceptTouchEvents = false - /// An extra offset to be appended to the viewport's top @objc open var extraTopOffset: CGFloat = 0.0 @@ -884,33 +881,21 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate open override func nsuiTouchesBegan(_ touches: Set, withEvent event: NSUIEvent?) { - if !interceptTouchEvents - { - super.nsuiTouchesBegan(touches, withEvent: event) - } + super.nsuiTouchesBegan(touches, withEvent: event) } open override func nsuiTouchesMoved(_ touches: Set, withEvent event: NSUIEvent?) { - if !interceptTouchEvents - { - super.nsuiTouchesMoved(touches, withEvent: event) - } + super.nsuiTouchesMoved(touches, withEvent: event) } open override func nsuiTouchesEnded(_ touches: Set, withEvent event: NSUIEvent?) { - if !interceptTouchEvents - { - super.nsuiTouchesEnded(touches, withEvent: event) - } + super.nsuiTouchesEnded(touches, withEvent: event) } open override func nsuiTouchesCancelled(_ touches: Set?, withEvent event: NSUIEvent?) { - if !interceptTouchEvents - { - super.nsuiTouchesCancelled(touches, withEvent: event) - } + super.nsuiTouchesCancelled(touches, withEvent: event) } } From f8e4547d818a06d87997c98479ef166d18ef1f27 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:22:27 +0800 Subject: [PATCH 4/8] refactor: use abs --- Source/Charts/Charts/ChartViewBase.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index db4d5e76a0..0ea02e7b8c 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -238,13 +238,11 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate if let data = data , data.entryCount >= 2 { - reference = fabs(max - min) + reference = abs(max - min) } else { - let absMin = fabs(min) - let absMax = fabs(max) - reference = absMin > absMax ? absMin : absMax + reference = Swift.max(abs(min), abs(max)) } From 7649850bf38050af08b74e1c5e3b148ddef49f5d Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:24:02 +0800 Subject: [PATCH 5/8] refactor: optional chaining --- Source/Charts/Charts/ChartViewBase.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 0ea02e7b8c..e1b19c39fd 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -256,8 +256,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate open override func draw(_ rect: CGRect) { - let optionalContext = NSUIGraphicsGetCurrentContext() - guard let context = optionalContext else { return } + guard let context = NSUIGraphicsGetCurrentContext() else { return } if data === nil && !noDataText.isEmpty { From c814196d300ce3de9512cb2c503861b5f5e7d697 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:25:15 +0800 Subject: [PATCH 6/8] refactor: use first --- Source/Charts/Charts/ChartViewBase.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index e1b19c39fd..8c2de2b623 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -349,10 +349,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate // set the indices to highlight highlighted = highs ?? [] - lastHighlighted = highlighted.isEmpty - ? nil - : highlighted[0] - + lastHighlighted = highlighted.first // redraw the chart setNeedsDisplay() From c65ff58f6301fbd99f4efdd22f942e92c3da45a6 Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:27:18 +0800 Subject: [PATCH 7/8] refactor: use bounds directly --- Source/Charts/Charts/ChartViewBase.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index 8c2de2b623..efe098c2da 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -681,7 +681,6 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate /// The center point of the chart (the whole View) in pixels. @objc open var midPoint: CGPoint { - let bounds = self.bounds return CGPoint(x: bounds.origin.x + bounds.size.width / 2.0, y: bounds.origin.y + bounds.size.height / 2.0) } From cbbcbdb89423490a870e1242c121867a401b63fe Mon Sep 17 00:00:00 2001 From: nuomi1 Date: Sat, 19 Dec 2020 11:36:01 +0800 Subject: [PATCH 8/8] refactor: use max and min --- Source/Charts/Charts/ChartViewBase.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Source/Charts/Charts/ChartViewBase.swift b/Source/Charts/Charts/ChartViewBase.swift index efe098c2da..f28b34c28d 100644 --- a/Source/Charts/Charts/ChartViewBase.swift +++ b/Source/Charts/Charts/ChartViewBase.swift @@ -838,12 +838,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate } set { - switch newValue - { - case ..<0.0: _dragDecelerationFrictionCoef = 0 - case 1.0...: _dragDecelerationFrictionCoef = 0.999 - default: _dragDecelerationFrictionCoef = newValue - } + _dragDecelerationFrictionCoef = max(0, min(newValue, 0.999)) } } private var _dragDecelerationFrictionCoef: CGFloat = 0.9