From 517d30a2bf71af3371728b301bb1156722bd01a9 Mon Sep 17 00:00:00 2001 From: Kai Scheffer Date: Wed, 4 Aug 2021 21:15:08 +0200 Subject: [PATCH 1/3] fix crash when there is no data in set --- .../Charts/Data/Implementations/Standard/ChartDataSet.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift index 96fc254475..0206523ade 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift @@ -215,7 +215,11 @@ open class ChartDataSet: ChartBaseDataSet rounding: ChartDataSetRounding) -> Int { var closest = partitioningIndex { $0.x >= xValue } - guard closest < endIndex else { return -1 } + if closest == endIndex && rounding != .up + { + closest = endIndex - 1 + } + guard closest < endIndex && closest >= startIndex else { return -1 } let closestXValue = self[closest].x From 932188944e54199fa4df9598b2028e3d90de4bef Mon Sep 17 00:00:00 2001 From: Kai Scheffer Date: Tue, 10 Aug 2021 23:14:09 +0200 Subject: [PATCH 2/3] 4.3 App Store --- Tests/ChartsTests/ChartDataTests.swift | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Tests/ChartsTests/ChartDataTests.swift b/Tests/ChartsTests/ChartDataTests.swift index a9c9e73758..bb33362829 100644 --- a/Tests/ChartsTests/ChartDataTests.swift +++ b/Tests/ChartsTests/ChartDataTests.swift @@ -89,7 +89,28 @@ class ChartDataTests: XCTestCase { let res = set.entriesForXValue(Double(1621860300)) let res2 = set.entriesForXValue(Double(1621860310)) - XCTAssertTrue(res?.advanced(by: 1) == res2) + XCTAssertTrue(res.first == set[slowMatch!]) + XCTAssertTrue(res2.first == nil) + + let up = set.entryIndex(x: set.last!.x + 1, closestToY: .nan, rounding: .up) + + XCTAssertTrue(up == -1) + + let upClosest = set.entryIndex(x: set.last!.x + 1 , closestToY: .nan, rounding: .closest) + + XCTAssertTrue(upClosest == set.endIndex - 1) + + let down = set.entryIndex(x: set.last!.x + 1, closestToY: .nan, rounding: .down) + + XCTAssertTrue(down == set.endIndex - 1) + + let minDown = set.entryIndex(x: set.first!.x - 1, closestToY: .nan, rounding: .down) + + XCTAssertTrue(minDown == -1) + + let minUp = set.entryIndex(x: set.first!.x - 1, closestToY: .nan, rounding: .up) + + XCTAssertTrue(minUp == 0) let closestIdx = set.entryIndex(x: Double(1621860310), closestToY: .nan, rounding: .closest) From 70e4dc39158780c008fce06515690959136e2102 Mon Sep 17 00:00:00 2001 From: Victor Barros Date: Mon, 10 Jan 2022 12:54:44 -0500 Subject: [PATCH 3/3] Upgrade swift-algorithms to 1.0.0 --- Package.resolved | 8 ++++---- Package.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Package.resolved b/Package.resolved index 27daaabac3..888ca3b156 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/apple/swift-algorithms", "state": { "branch": null, - "revision": "bb3bafeca0e164ece3403a9de646b7d38c07dd49", - "version": "0.0.2" + "revision": "b14b7f4c528c942f121c8b860b9410b2bf57825e", + "version": "1.0.0" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/apple/swift-numerics", "state": { "branch": null, - "revision": "6b24333510e9044cf4716a07bed65eeed6bc6393", - "version": "0.0.8" + "revision": "0a5bc04095a675662cf24757cc0640aa2204253b", + "version": "1.0.2" } } ] diff --git a/Package.swift b/Package.swift index 8b266f9287..b625ffd4ec 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,7 @@ let package = Package( targets: ["Charts"]) ], dependencies: [ - .package(url: "https://github.com/apple/swift-algorithms", from: "0.0.1") + .package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0") ], targets: [ .target(