diff --git a/Charts.xcodeproj/project.pbxproj b/Charts.xcodeproj/project.pbxproj index 743293bf34..304dbf0ade 100644 --- a/Charts.xcodeproj/project.pbxproj +++ b/Charts.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 53; objects = { /* Begin PBXBuildFile section */ @@ -14,6 +14,8 @@ 05253AFC448C107DEF54C2FE /* CombinedChartRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52265C1B343CCC41AF2300E3 /* CombinedChartRenderer.swift */; }; 0529DD51622C8769C1121F90 /* CrossShapeRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 823F7DB281C6C6F069A69605 /* CrossShapeRenderer.swift */; }; 0577C2B38BCE4C871F262714 /* AnimatedZoomViewJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C2EA58CB336967198D30D20 /* AnimatedZoomViewJob.swift */; }; + 063093AC2A323CE500216FFB /* Indexed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063093AB2A323CE400216FFB /* Indexed.swift */; }; + 063093AE2A323E5E00216FFB /* Partition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063093AD2A323E5E00216FFB /* Partition.swift */; }; 064989461F5C99C7006E8BB3 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064989451F5C99C7006E8BB3 /* Utilities.swift */; }; 06AB297F20FA726600BAD505 /* Highlighter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AB297E20FA726500BAD505 /* Highlighter.swift */; }; 0A772AEC08246FEC480673E5 /* PieRadarChartViewBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A6C9631C69B2D772BBD9232 /* PieRadarChartViewBase.swift */; }; @@ -29,7 +31,6 @@ 221CA2922588FCBC00C2DD1E /* Sequence+KeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 221CA2912588FCBC00C2DD1E /* Sequence+KeyPath.swift */; }; 2243BBFD1FF156EC00B49D0B /* EquatableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2243BBFB1FF156D000B49D0B /* EquatableTests.swift */; }; 22786E8525CD96620051335B /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 22786E8325CD96620051335B /* Media.xcassets */; }; - 228D56232554F27A00BEE75E /* Algorithms in Frameworks */ = {isa = PBXBuildFile; productRef = 228D56222554F27A00BEE75E /* Algorithms */; }; 22BBDA0825CC4C2F00435670 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 22BBDA0725CC4C2F00435670 /* SnapshotTesting */; }; 23649EFC635A76022F07FFA6 /* PieChartDataEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD02157CF8CEE1189BF681DA /* PieChartDataEntry.swift */; }; 23FA50B2730D8C7ACA091C4F /* BarChartRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F279974FE650E57A061B09 /* BarChartRenderer.swift */; }; @@ -179,6 +180,8 @@ 0216EDC6A1FE272F4EB19FCF /* DataRenderer.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = DataRenderer.swift; path = Source/Charts/Renderers/DataRenderer.swift; sourceTree = ""; }; 04F7B9DF1F2D66E7279771D4 /* PieRadarHighlighter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = PieRadarHighlighter.swift; path = Source/Charts/Highlight/PieRadarHighlighter.swift; sourceTree = ""; }; 0619A877C69A95ECCC440A44 /* LineChartView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = LineChartView.swift; path = Source/Charts/Charts/LineChartView.swift; sourceTree = ""; }; + 063093AB2A323CE400216FFB /* Indexed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Indexed.swift; sourceTree = ""; }; + 063093AD2A323E5E00216FFB /* Partition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Partition.swift; sourceTree = ""; }; 064989451F5C99C7006E8BB3 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; }; 06AB297E20FA726500BAD505 /* Highlighter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Highlighter.swift; path = Source/Charts/Highlight/Highlighter.swift; sourceTree = ""; }; 0BD9DF16AF59680A3BB49452 /* AxisValueFormatter.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = AxisValueFormatter.swift; path = Source/Charts/Formatters/AxisValueFormatter.swift; sourceTree = ""; }; @@ -347,7 +350,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 228D56232554F27A00BEE75E /* Algorithms in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -659,6 +661,8 @@ FF475B9593B9898853814340 /* Transformer.swift */, 324C9127B53A8D39C8B49277 /* TransformerHorizontalBarChart.swift */, 72EAEBB7CF73E33565FC2896 /* ViewPortHandler.swift */, + 063093AB2A323CE400216FFB /* Indexed.swift */, + 063093AD2A323E5E00216FFB /* Partition.swift */, ); name = Utils; sourceTree = ""; @@ -754,7 +758,6 @@ ); name = DGCharts; packageProductDependencies = ( - 228D56222554F27A00BEE75E /* Algorithms */, ); productName = Charts; productReference = 65AD9E95D9ED4DC0BD73A743 /* DGCharts.framework */; @@ -787,8 +790,9 @@ 193FC8DF32D250560C5F5D77 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 1400; + LastUpgradeCheck = 1430; TargetAttributes = { A58A4ED274A941CA248EA921 = { LastSwiftMigration = 1150; @@ -808,7 +812,6 @@ ); mainGroup = 865A1CF149F52850CAB7F177; packageReferences = ( - 228D56212554F27A00BEE75E /* XCRemoteSwiftPackageReference "swift-algorithms" */, 22BBDA0625CC4C2F00435670 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */, ); productRefGroup = AB2D554102718F209377399E /* Products */; @@ -864,6 +867,7 @@ DBC9DB402CC9BB84B76968C4 /* Description.swift in Sources */, 03960E8148C6AEDACE4B77CC /* Marker.swift in Sources */, ECE7EAE7179A7F57CE9BBD8F /* Legend.swift in Sources */, + 063093AE2A323E5E00216FFB /* Partition.swift in Sources */, C9F3DC272355F791000C3215 /* Platform+Gestures.swift in Sources */, C20A62D8CB9120523D5FB650 /* LegendEntry.swift in Sources */, 369DEB23452CB436A3A1A644 /* MarkerImage.swift in Sources */, @@ -913,6 +917,7 @@ FAAD9FF6565DED2652188584 /* PieChartDataSetProtocol.swift in Sources */, 83BBAF3EDC31FD452F8BF1DB /* RadarChartDataSetProtocol.swift in Sources */, 50476F8E6662CAFC1EFE0723 /* ScatterChartDataSetProtocol.swift in Sources */, + 063093AC2A323CE500216FFB /* Indexed.swift in Sources */, 97E033CC0ABEF0F448DAFA8E /* DataApproximator.swift in Sources */, 779B46E9F13A087BFA47D539 /* DefaultAxisValueFormatter.swift in Sources */, F744C510DA9B85C228BBB335 /* DefaultFillFormatter.swift in Sources */, @@ -1029,6 +1034,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; FRAMEWORK_VERSION = A; GCC_NO_COMMON_BLOCKS = YES; @@ -1040,8 +1046,10 @@ "@executable_path/../Frameworks", "@loader_path/Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 4.1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = com.dcg.Charts; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1219,6 +1227,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; FRAMEWORK_VERSION = A; GCC_NO_COMMON_BLOCKS = YES; @@ -1230,8 +1239,10 @@ "@executable_path/../Frameworks", "@loader_path/Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 4.1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.dcg.Charts; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1312,14 +1323,6 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 228D56212554F27A00BEE75E /* XCRemoteSwiftPackageReference "swift-algorithms" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/apple/swift-algorithms"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 1.0.0; - }; - }; 22BBDA0625CC4C2F00435670 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/pointfreeco/swift-snapshot-testing"; @@ -1331,11 +1334,6 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 228D56222554F27A00BEE75E /* Algorithms */ = { - isa = XCSwiftPackageProductDependency; - package = 228D56212554F27A00BEE75E /* XCRemoteSwiftPackageReference "swift-algorithms" */; - productName = Algorithms; - }; 22BBDA0725CC4C2F00435670 /* SnapshotTesting */ = { isa = XCSwiftPackageProductDependency; package = 22BBDA0625CC4C2F00435670 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */; diff --git a/Charts.xcodeproj/xcshareddata/xcschemes/DGCharts.xcscheme b/Charts.xcodeproj/xcshareddata/xcschemes/DGCharts.xcscheme index 29ebd62247..002c19ed9f 100644 --- a/Charts.xcodeproj/xcshareddata/xcschemes/DGCharts.xcscheme +++ b/Charts.xcodeproj/xcshareddata/xcschemes/DGCharts.xcscheme @@ -1,6 +1,6 @@ 1.0' end end diff --git a/Indexed.swift b/Indexed.swift new file mode 100644 index 0000000000..f7779539e2 --- /dev/null +++ b/Indexed.swift @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Algorithms open source project +// +// Copyright (c) 2020 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +/// A collection wrapper that iterates over the indices and elements of a +/// collection together. +struct IndexedCollection { + /// The base collection. + let base: Base + + init(base: Base) { + self.base = base + } +} + +extension IndexedCollection: Collection { + /// The element type for an `IndexedCollection` collection. + typealias Element = (index: Base.Index, element: Base.Element) + + var startIndex: Base.Index { + base.startIndex + } + + var endIndex: Base.Index { + base.endIndex + } + + subscript(position: Base.Index) -> Element { + (index: position, element: base[position]) + } + + func index(after i: Base.Index) -> Base.Index { + base.index(after: i) + } + + func index(_ i: Base.Index, offsetBy distance: Int) -> Base.Index { + base.index(i, offsetBy: distance) + } + + func index( + _ i: Base.Index, + offsetBy distance: Int, + limitedBy limit: Base.Index + ) -> Base.Index? { + base.index(i, offsetBy: distance, limitedBy: limit) + } + + func distance(from start: Base.Index, to end: Base.Index) -> Int { + base.distance(from: start, to: end) + } + + var indices: Base.Indices { + base.indices + } +} + +//extension IndexedCollection: BidirectionalCollection +// where Base: BidirectionalCollection +//{ +// func index(before i: Base.Index) -> Base.Index { +// base.index(before: i) +// } +//} +// +//extension IndexedCollection: RandomAccessCollection +// where Base: RandomAccessCollection {} +// +//extension IndexedCollection: LazySequenceProtocol, LazyCollectionProtocol +// where Base: LazySequenceProtocol {} + +//===----------------------------------------------------------------------===// +// indexed() +//===----------------------------------------------------------------------===// + +extension Collection { + /// Returns a collection of pairs *(i, x)*, where *i* represents an index of + /// the collection, and *x* represents an element. + /// + /// This example iterates over the indices and elements of a set, building an + /// array consisting of indices of names with five or fewer letters. + /// + /// let names: Set = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"] + /// var shorterIndices: [Set.Index] = [] + /// for (i, name) in names.indexed() { + /// if name.count <= 5 { + /// shorterIndices.append(i) + /// } + /// } + /// + /// Returns: A collection of paired indices and elements of this collection. + func indexed() -> IndexedCollection { + IndexedCollection(base: self) + } +} diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 888ca3b156..0000000000 --- a/Package.resolved +++ /dev/null @@ -1,25 +0,0 @@ -{ - "object": { - "pins": [ - { - "package": "swift-algorithms", - "repositoryURL": "https://github.com/apple/swift-algorithms", - "state": { - "branch": null, - "revision": "b14b7f4c528c942f121c8b860b9410b2bf57825e", - "version": "1.0.0" - } - }, - { - "package": "swift-numerics", - "repositoryURL": "https://github.com/apple/swift-numerics", - "state": { - "branch": null, - "revision": "0a5bc04095a675662cf24757cc0640aa2204253b", - "version": "1.0.2" - } - } - ] - }, - "version": 1 -} diff --git a/Package.swift b/Package.swift index 0c7ef485c3..85a790bbd1 100644 --- a/Package.swift +++ b/Package.swift @@ -18,13 +18,9 @@ let package = Package( type: .dynamic, targets: ["DGCharts"]) ], - dependencies: [ - .package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0") - ], targets: [ .target( name: "DGCharts", - dependencies: [.product(name: "Algorithms", package: "swift-algorithms")], path: "Source/Charts" ) ], diff --git a/Partition.swift b/Partition.swift new file mode 100644 index 0000000000..139f7e7349 --- /dev/null +++ b/Partition.swift @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Algorithms open source project +// +// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +// partitioningIndex(where:) +//===----------------------------------------------------------------------===// + +extension Collection { + /// Returns the start index of the partition of a collection that matches + /// the given predicate. + /// + /// The collection must already be partitioned according to the predicate. + /// That is, there should be an index `i` where for every element in + /// `collection[.. Bool + ) rethrows -> Index { + var n = count + var l = startIndex + + while n > 0 { + let half = n / 2 + let mid = index(l, offsetBy: half) + if try belongsInSecondPartition(self[mid]) { + n = half + } else { + l = index(after: mid) + n -= half + 1 + } + } + return l + } +} diff --git a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift index bf0c2ae8bf..6666f3192d 100644 --- a/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift +++ b/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift @@ -9,7 +9,6 @@ // https://github.com/danielgindi/Charts // -@_implementationOnly import Algorithms import Foundation /// Determines how to round DataSet index values for `ChartDataSet.entryIndex(x, rounding)` when an exact x-value is not found. diff --git a/Source/Charts/Highlight/ChartHighlighter.swift b/Source/Charts/Highlight/ChartHighlighter.swift index 26c4b94f3e..9918085f5f 100644 --- a/Source/Charts/Highlight/ChartHighlighter.swift +++ b/Source/Charts/Highlight/ChartHighlighter.swift @@ -9,7 +9,6 @@ // https://github.com/danielgindi/Charts // -@_implementationOnly import Algorithms import Foundation import CoreGraphics diff --git a/Source/Charts/Highlight/CombinedHighlighter.swift b/Source/Charts/Highlight/CombinedHighlighter.swift index 27d74012c6..08914c901f 100644 --- a/Source/Charts/Highlight/CombinedHighlighter.swift +++ b/Source/Charts/Highlight/CombinedHighlighter.swift @@ -9,7 +9,6 @@ // https://github.com/danielgindi/Charts // -@_implementationOnly import Algorithms import Foundation import CoreGraphics