From 57d6c2a755124feb0fdb048651fb3cce5c8540c5 Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 29 Dec 2019 15:04:39 +0100 Subject: [PATCH 01/10] Added labels to reference lines --- .../Drawing/ReferenceLineDrawingView.swift | 43 +++++++++++-------- Classes/Reference/ReferenceLines.swift | 23 ++++++++-- GraphView/GraphView.xcodeproj/project.pbxproj | 10 +++-- GraphView/GraphViewCode/Examples.swift | 12 +++++- README.md | 12 +++++- 5 files changed, 70 insertions(+), 30 deletions(-) diff --git a/Classes/Drawing/ReferenceLineDrawingView.swift b/Classes/Drawing/ReferenceLineDrawingView.swift index 827ebad..7dbfa26 100644 --- a/Classes/Drawing/ReferenceLineDrawingView.swift +++ b/Classes/Drawing/ReferenceLineDrawingView.swift @@ -93,9 +93,9 @@ internal class ReferenceLineDrawingView : UIView { switch(settings.positionType) { case .relative: - createReferenceLines(in: initialRect, atRelativePositions: self.settings.relativePositions, forPath: referenceLinePath) + createReferenceLines(in: initialRect, relativeLines: self.settings.relativeLines, forPath: referenceLinePath) case .absolute: - createReferenceLines(in: initialRect, atAbsolutePositions: self.settings.absolutePositions, forPath: referenceLinePath) + createReferenceLines(in: initialRect, absoluteLines: self.settings.absoluteLines, forPath: referenceLinePath) } return referenceLinePath @@ -110,54 +110,61 @@ internal class ReferenceLineDrawingView : UIView { return numberFormatter } - private func createReferenceLines(in rect: CGRect, atRelativePositions relativePositions: [Double], forPath path: UIBezierPath) { + private func createReferenceLines(in rect: CGRect, relativeLines: [ReferenceLine], forPath path: UIBezierPath) { let height = rect.size.height - var relativePositions = relativePositions + var relativeLines = relativeLines // If we are including the min and max already need to make sure we don't redraw them. if(self.settings.includeMinMax) { - relativePositions = relativePositions.filter({ (x:Double) -> Bool in - return (x != 0 && x != 1) + relativeLines = relativeLines.filter({ (x: ReferenceLine) -> Bool in + return (x.position != 0 && x.position != 1) }) } - for relativePosition in relativePositions { + for relativeLine in relativeLines { - let yPosition = height * CGFloat(1 - relativePosition) + let yPosition = height * CGFloat(1 - relativeLine.position) let lineStart = CGPoint(x: 0, y: rect.origin.y + yPosition) let lineEnd = CGPoint(x: lineStart.x + lineWidth, y: lineStart.y) - createReferenceLineFrom(from: lineStart, to: lineEnd, in: path) + createReferenceLineFrom(from: lineStart, to: lineEnd, in: path, withLabel: relativeLine.label) } } - private func createReferenceLines(in rect: CGRect, atAbsolutePositions absolutePositions: [Double], forPath path: UIBezierPath) { + private func createReferenceLines(in rect: CGRect, absoluteLines: [ReferenceLine], forPath path: UIBezierPath) { - for absolutePosition in absolutePositions { + for absoluteLine in absoluteLines { - let yPosition = calculateYPositionForYAxisValue(value: absolutePosition) + let yPosition = calculateYPositionForYAxisValue(value: absoluteLine.position) - // don't need to add rect.origin.y to yPosition like we do for relativePositions, + // don't need to add rect.origin.y to yPosition like we do for relativeLines, // as we calculate the position for the y axis value in the previous line, // this already takes into account margins, etc. let lineStart = CGPoint(x: 0, y: yPosition) let lineEnd = CGPoint(x: lineStart.x + lineWidth, y: lineStart.y) - createReferenceLineFrom(from: lineStart, to: lineEnd, in: path) + createReferenceLineFrom(from: lineStart, to: lineEnd, in: path, withLabel: absoluteLine.label) } } - private func createReferenceLineFrom(from lineStart: CGPoint, to lineEnd: CGPoint, in path: UIBezierPath) { + private func createReferenceLineFrom(from lineStart: CGPoint, to lineEnd: CGPoint, in path: UIBezierPath, withLabel label: String?) { if(self.settings.shouldAddLabelsToIntermediateReferenceLines) { let value = calculateYAxisValue(for: lineStart) let numberFormatter = referenceNumberFormatter() - var valueString = numberFormatter.string(from: value as NSNumber)! - if(self.settings.shouldAddUnitsToIntermediateReferenceLineLabels) { - valueString += " \(units)" + var valueString: String + + if let label = label { + valueString = label + } else { + valueString = numberFormatter.string(from: value as NSNumber)! + + if(self.settings.shouldAddUnitsToIntermediateReferenceLineLabels) { + valueString += " \(units)" + } } addLine(withTag: valueString, from: lineStart, to: lineEnd, in: path) diff --git a/Classes/Reference/ReferenceLines.swift b/Classes/Reference/ReferenceLines.swift index 38f12aa..eba6f6a 100644 --- a/Classes/Reference/ReferenceLines.swift +++ b/Classes/Reference/ReferenceLines.swift @@ -26,9 +26,17 @@ open class ReferenceLines { open var referenceLinePosition = ScrollableGraphViewReferenceLinePosition.left @IBInspectable open var positionType = ReferenceLinePositioningType.relative - @IBInspectable open var relativePositions: [Double] = [0.25, 0.5, 0.75] - @IBInspectable open var absolutePositions: [Double] = [25, 50, 75] - @IBInspectable open var includeMinMax: Bool = true + + open var relativeLines: [ReferenceLine] = [ReferenceLine(position: 0, label: "start"), + ReferenceLine(position: 0.25, label: "a"), + ReferenceLine(position: 0.5, label: "b"), + ReferenceLine(position: 0.75, label: "c"), + ReferenceLine(position: 1, label: "end")] + open var absoluteLines: [ReferenceLine] = [ReferenceLine(position: 25), + ReferenceLine(position: 50), + ReferenceLine(position: 75)] + + @IBInspectable open var includeMinMax: Bool = false /// Whether or not to add labels to the intermediate reference lines. @IBInspectable open var shouldAddLabelsToIntermediateReferenceLines: Bool = true @@ -72,7 +80,14 @@ open class ReferenceLines { // Need this for external frameworks. } } - +open class ReferenceLine { + let position: Double + let label: String? + init(position: Double, label: String? = nil) { + self.position = position + self.label = label + } +} @objc public enum ScrollableGraphViewReferenceLinePosition : Int { case left diff --git a/GraphView/GraphView.xcodeproj/project.pbxproj b/GraphView/GraphView.xcodeproj/project.pbxproj index e2372b3..cdb4dea 100644 --- a/GraphView/GraphView.xcodeproj/project.pbxproj +++ b/GraphView/GraphView.xcodeproj/project.pbxproj @@ -287,6 +287,7 @@ TargetAttributes = { 2918399D1C72E6A400753A45 = { CreatedOnToolsVersion = 7.2.1; + DevelopmentTeam = 5AGVYV3GTD; LastSwiftMigration = 1000; }; }; @@ -296,6 +297,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -505,11 +507,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 5AGVYV3GTD; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode; + PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewCode; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_VERSION = 4.2; @@ -522,11 +524,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 5AGVYV3GTD; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode; + PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewCode; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_VERSION = 4.2; diff --git a/GraphView/GraphViewCode/Examples.swift b/GraphView/GraphViewCode/Examples.swift index aacf13b..4e97c50 100644 --- a/GraphView/GraphViewCode/Examples.swift +++ b/GraphView/GraphViewCode/Examples.swift @@ -141,7 +141,12 @@ class Examples : ScrollableGraphViewDataSource { referenceLines.referenceLineLabelFont = UIFont.boldSystemFont(ofSize: 8) referenceLines.referenceLineColor = UIColor.white.withAlphaComponent(0.2) referenceLines.referenceLineLabelColor = UIColor.white - referenceLines.relativePositions = [0, 0.2, 0.4, 0.6, 0.8, 1] + referenceLines.relativeLines = [ReferenceLine(position: 0), + ReferenceLine(position: 0.2), + ReferenceLine(position: 0.4), + ReferenceLine(position: 0.6), + ReferenceLine(position: 0.8), + ReferenceLine(position: 1)] referenceLines.dataPointLabelColor = UIColor.white.withAlphaComponent(1) @@ -257,7 +262,10 @@ class Examples : ScrollableGraphViewDataSource { referenceLines.positionType = .absolute // Reference lines will be shown at these values on the y-axis. - referenceLines.absolutePositions = [10, 20, 25, 30] + referenceLines.absoluteLines = [ReferenceLine(position: 10), + ReferenceLine(position: 20), + ReferenceLine(position: 25), + ReferenceLine(position: 30)] referenceLines.includeMinMax = false referenceLines.dataPointLabelColor = UIColor.white.withAlphaComponent(0.5) diff --git a/README.md b/README.md index dfe2dba..3ec1574 100644 --- a/README.md +++ b/README.md @@ -364,7 +364,10 @@ referenceLines.referenceLineLabelColor = UIColor.white referenceLines.positionType = .absolute // Reference lines will be shown at these values on the y-axis. -referenceLines.absolutePositions = [10, 20, 25, 30] +referenceLines.absoluteLines = [ReferenceLine(position: 10), + ReferenceLine(position: 20), + ReferenceLine(position: 25), + ReferenceLine(position: 30)] referenceLines.includeMinMax = false referenceLines.dataPointLabelColor = UIColor.white.withAlphaComponent(0.5) @@ -554,7 +557,12 @@ let referenceLines = ReferenceLines() referenceLines.referenceLineLabelFont = UIFont.boldSystemFont(ofSize: 8) referenceLines.referenceLineColor = UIColor.white.withAlphaComponent(0.2) referenceLines.referenceLineLabelColor = UIColor.white -referenceLines.relativePositions = [0, 0.2, 0.4, 0.6, 0.8, 1] +referenceLines.relativeLines = [ReferenceLine(position: 0), + ReferenceLine(position: 0.2), + ReferenceLine(position: 0.4), + ReferenceLine(position: 0.6), + ReferenceLine(position: 0.8), + ReferenceLine(position: 1)] referenceLines.dataPointLabelColor = UIColor.white.withAlphaComponent(1) From 9eefacfe77fc70112cdaf974f6f8e330d3790d1a Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 29 Dec 2019 15:05:58 +0100 Subject: [PATCH 02/10] Swift 5 support --- Classes/Plots/Plot.swift | 2 +- Classes/Reference/LabelPool.swift | 2 +- GraphView/GraphView.xcodeproj/project.pbxproj | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Classes/Plots/Plot.swift b/Classes/Plots/Plot.swift index 580bbe8..7b34420 100644 --- a/Classes/Plots/Plot.swift +++ b/Classes/Plots/Plot.swift @@ -103,7 +103,7 @@ open class Plot { } private func dequeue(animation: GraphPointAnimation) { - if let index = currentAnimations.index(of: animation) { + if let index = currentAnimations.firstIndex(of: animation) { currentAnimations.remove(at: index) } diff --git a/Classes/Reference/LabelPool.swift b/Classes/Reference/LabelPool.swift index 9dde79c..de07ac9 100644 --- a/Classes/Reference/LabelPool.swift +++ b/Classes/Reference/LabelPool.swift @@ -29,7 +29,7 @@ internal class LabelPool { else { label = UILabel() labels.append(label) - let newLabelIndex = labels.index(of: label)! + let newLabelIndex = labels.firstIndex(of: label)! relations[pointIndex] = newLabelIndex } diff --git a/GraphView/GraphView.xcodeproj/project.pbxproj b/GraphView/GraphView.xcodeproj/project.pbxproj index cdb4dea..2d67a66 100644 --- a/GraphView/GraphView.xcodeproj/project.pbxproj +++ b/GraphView/GraphView.xcodeproj/project.pbxproj @@ -288,16 +288,15 @@ 2918399D1C72E6A400753A45 = { CreatedOnToolsVersion = 7.2.1; DevelopmentTeam = 5AGVYV3GTD; - LastSwiftMigration = 1000; + LastSwiftMigration = 1130; }; }; }; buildConfigurationList = 291839991C72E6A400753A45 /* Build configuration list for PBXProject "GraphView" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( - English, en, Base, ); @@ -514,7 +513,7 @@ PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewCode; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -531,7 +530,7 @@ PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewCode; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; From de44911d015563941a1d30169b7c94c6aac4fd06 Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 29 Dec 2019 15:13:00 +0100 Subject: [PATCH 03/10] Added swift package manager support --- Package.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..d622024 --- /dev/null +++ b/Package.swift @@ -0,0 +1,11 @@ +// swift-tools-version:5.0 +// +import PackageDescription + +let package = Package(name: "ScrollableGraphView", + platforms: [.iOS(.v8)], + products: [.library(name: "ScrollableGraphView", + targets: ["ScrollableGraphView"])], + targets: [.target(name: "ScrollableGraphView", + path: "Classes")], + swiftLanguageVersions: [.v5]) From cad79864d95dfde704bed8ded5b62867a269bddf Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 29 Dec 2019 15:17:33 +0100 Subject: [PATCH 04/10] GraphViewIB converted to Swift 5 --- GraphView/GraphView.xcodeproj/project.pbxproj | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/GraphView/GraphView.xcodeproj/project.pbxproj b/GraphView/GraphView.xcodeproj/project.pbxproj index 2d67a66..399f49f 100644 --- a/GraphView/GraphView.xcodeproj/project.pbxproj +++ b/GraphView/GraphView.xcodeproj/project.pbxproj @@ -290,6 +290,10 @@ DevelopmentTeam = 5AGVYV3GTD; LastSwiftMigration = 1130; }; + E10847832129DC60009A9586 = { + DevelopmentTeam = 5AGVYV3GTD; + LastSwiftMigration = 1130; + }; }; }; buildConfigurationList = 291839991C72E6A400753A45 /* Build configuration list for PBXProject "GraphView" */; @@ -540,14 +544,15 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 5AGVYV3GTD; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewIB; + PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewIB; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -557,14 +562,15 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 5AGVYV3GTD; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewIB; + PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewIB; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; From 8b22e81c04e5ceb7d9759354550735bfbeeb3873 Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 29 Dec 2019 15:35:27 +0100 Subject: [PATCH 05/10] Changed visibility of ReferenceLine to public --- Classes/Reference/ReferenceLines.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/Reference/ReferenceLines.swift b/Classes/Reference/ReferenceLines.swift index eba6f6a..bf24dd6 100644 --- a/Classes/Reference/ReferenceLines.swift +++ b/Classes/Reference/ReferenceLines.swift @@ -81,9 +81,9 @@ open class ReferenceLines { } } open class ReferenceLine { - let position: Double - let label: String? - init(position: Double, label: String? = nil) { + public let position: Double + public let label: String? + public init(position: Double, label: String? = nil) { self.position = position self.label = label } From 5fef79ae4bb56275239b6d580a76fbbd9af888b2 Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 29 Dec 2019 16:32:08 +0100 Subject: [PATCH 06/10] Reset bundle identifier. --- GraphView/GraphView.xcodeproj/project.pbxproj | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/GraphView/GraphView.xcodeproj/project.pbxproj b/GraphView/GraphView.xcodeproj/project.pbxproj index 399f49f..ac94ede 100644 --- a/GraphView/GraphView.xcodeproj/project.pbxproj +++ b/GraphView/GraphView.xcodeproj/project.pbxproj @@ -287,11 +287,9 @@ TargetAttributes = { 2918399D1C72E6A400753A45 = { CreatedOnToolsVersion = 7.2.1; - DevelopmentTeam = 5AGVYV3GTD; LastSwiftMigration = 1130; }; E10847832129DC60009A9586 = { - DevelopmentTeam = 5AGVYV3GTD; LastSwiftMigration = 1130; }; }; @@ -510,11 +508,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = 5AGVYV3GTD; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewCode; + PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_VERSION = 5.0; @@ -527,11 +525,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = 5AGVYV3GTD; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewCode; + PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewCode; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_VERSION = 5.0; @@ -544,11 +542,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = 5AGVYV3GTD; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewIB; + PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewIB; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_VERSION = 5.0; @@ -562,11 +560,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = 5AGVYV3GTD; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GraphView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = it.gzaccaroni.GraphViewIB; + PRODUCT_BUNDLE_IDENTIFIER = com.ios.GraphViewIB; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SWIFT_VERSION = 5.0; From db2e635b6a7d79f3b0ec8abbbd1bdaa33a6682ee Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Thu, 6 Feb 2020 19:03:08 +0100 Subject: [PATCH 07/10] Required constructors added to Drawing Layers. --- Classes/Drawing/BarDrawingLayer.swift | 3 +++ Classes/Drawing/DotDrawingLayer.swift | 4 ++++ Classes/Drawing/FillDrawingLayer.swift | 5 ++++- Classes/Drawing/GradientDrawingLayer.swift | 8 +++++++- Classes/Drawing/LineDrawingLayer.swift | 8 +++++++- Classes/Drawing/ScrollableGraphViewDrawingLayer.swift | 3 +++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Classes/Drawing/BarDrawingLayer.swift b/Classes/Drawing/BarDrawingLayer.swift index 8b9b74d..1705a43 100644 --- a/Classes/Drawing/BarDrawingLayer.swift +++ b/Classes/Drawing/BarDrawingLayer.swift @@ -8,6 +8,9 @@ internal class BarDrawingLayer: ScrollableGraphViewDrawingLayer { private var barWidth: CGFloat = 4 private var shouldRoundCorners = false + override init(layer: Any) { + super.init(layer: layer) + } init(frame: CGRect, barWidth: CGFloat, barColor: UIColor, barLineWidth: CGFloat, barLineColor: UIColor, shouldRoundCorners: Bool) { super.init(viewportWidth: frame.size.width, viewportHeight: frame.size.height) diff --git a/Classes/Drawing/DotDrawingLayer.swift b/Classes/Drawing/DotDrawingLayer.swift index 9f2f4a0..15ecd6b 100644 --- a/Classes/Drawing/DotDrawingLayer.swift +++ b/Classes/Drawing/DotDrawingLayer.swift @@ -9,6 +9,10 @@ internal class DotDrawingLayer: ScrollableGraphViewDrawingLayer { private var customDataPointPath: ((_ centre: CGPoint) -> UIBezierPath)? + override init(layer: Any) { + super.init(layer: layer) + } + init(frame: CGRect, fillColor: UIColor, dataPointType: ScrollableGraphViewDataPointType, dataPointSize: CGFloat, customDataPointPath: ((_ centre: CGPoint) -> UIBezierPath)? = nil) { self.dataPointType = dataPointType diff --git a/Classes/Drawing/FillDrawingLayer.swift b/Classes/Drawing/FillDrawingLayer.swift index 97b3c29..04b3ae7 100644 --- a/Classes/Drawing/FillDrawingLayer.swift +++ b/Classes/Drawing/FillDrawingLayer.swift @@ -5,8 +5,11 @@ internal class FillDrawingLayer : ScrollableGraphViewDrawingLayer { // Fills are only used with lineplots and we need // to know what the line looks like. - private var lineDrawingLayer: LineDrawingLayer + private var lineDrawingLayer: LineDrawingLayer! + override init(layer: Any) { + super.init(layer: layer) + } init(frame: CGRect, fillColor: UIColor, lineDrawingLayer: LineDrawingLayer) { self.lineDrawingLayer = lineDrawingLayer diff --git a/Classes/Drawing/GradientDrawingLayer.swift b/Classes/Drawing/GradientDrawingLayer.swift index 319fa5c..ff77d91 100644 --- a/Classes/Drawing/GradientDrawingLayer.swift +++ b/Classes/Drawing/GradientDrawingLayer.swift @@ -9,7 +9,7 @@ internal class GradientDrawingLayer : ScrollableGraphViewDrawingLayer { // Gradient fills are only used with lineplots and we need // to know what the line looks like. - private var lineDrawingLayer: LineDrawingLayer + private var lineDrawingLayer: LineDrawingLayer! lazy private var gradientMask: CAShapeLayer = ({ let mask = CAShapeLayer() @@ -34,6 +34,12 @@ internal class GradientDrawingLayer : ScrollableGraphViewDrawingLayer { addMaskLayer() self.setNeedsDisplay() } + override init(layer: Any) { + self.startColor = UIColor.black + self.endColor = UIColor.black + self.gradientType = .linear + super.init(layer: layer) + } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") diff --git a/Classes/Drawing/LineDrawingLayer.swift b/Classes/Drawing/LineDrawingLayer.swift index 373a3cb..9798df0 100644 --- a/Classes/Drawing/LineDrawingLayer.swift +++ b/Classes/Drawing/LineDrawingLayer.swift @@ -30,7 +30,13 @@ internal class LineDrawingLayer : ScrollableGraphViewDrawingLayer { required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + override init(layer: Any) { + // Default values + lineStyle = .smooth + shouldFill = false + lineCurviness = 1.0 + super.init(layer: layer) + } internal func createLinePath() -> UIBezierPath { guard let owner = owner else { diff --git a/Classes/Drawing/ScrollableGraphViewDrawingLayer.swift b/Classes/Drawing/ScrollableGraphViewDrawingLayer.swift index 864e346..82e16c5 100644 --- a/Classes/Drawing/ScrollableGraphViewDrawingLayer.swift +++ b/Classes/Drawing/ScrollableGraphViewDrawingLayer.swift @@ -27,6 +27,9 @@ internal class ScrollableGraphViewDrawingLayer : CAShapeLayer { setup() } + override init(layer: Any) { + super.init() + } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") From 1bec9e653cd3507f9083d382c1df792d17a370de Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Thu, 6 Feb 2020 19:04:08 +0100 Subject: [PATCH 08/10] Removed public modifier from extension declaration. --- Classes/ScrollableGraphView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/ScrollableGraphView.swift b/Classes/ScrollableGraphView.swift index 9dc5d18..56e4064 100644 --- a/Classes/ScrollableGraphView.swift +++ b/Classes/ScrollableGraphView.swift @@ -981,7 +981,7 @@ fileprivate class SGVQueue { // We have to be our own data source for interface builder. #if TARGET_INTERFACE_BUILDER -public extension ScrollableGraphView : ScrollableGraphViewDataSource { +extension ScrollableGraphView : ScrollableGraphViewDataSource { var numberOfDisplayItems: Int { get { From 1f2a1a4c02582ff2524a36db58a972321205d676 Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Thu, 26 Mar 2020 18:20:02 +0100 Subject: [PATCH 09/10] Set swift package manager library type to dynamic. --- Package.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Package.swift b/Package.swift index d622024..72c033c 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,7 @@ import PackageDescription let package = Package(name: "ScrollableGraphView", platforms: [.iOS(.v8)], products: [.library(name: "ScrollableGraphView", + type: .dynamic, targets: ["ScrollableGraphView"])], targets: [.target(name: "ScrollableGraphView", path: "Classes")], From 34e045aac37fe977d2c7e191e9efd40b11f230c4 Mon Sep 17 00:00:00 2001 From: Giulio Zaccaroni Date: Sun, 3 May 2020 14:53:26 +0200 Subject: [PATCH 10/10] Removed package manager library type --- Package.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Package.swift b/Package.swift index 72c033c..d622024 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,6 @@ import PackageDescription let package = Package(name: "ScrollableGraphView", platforms: [.iOS(.v8)], products: [.library(name: "ScrollableGraphView", - type: .dynamic, targets: ["ScrollableGraphView"])], targets: [.target(name: "ScrollableGraphView", path: "Classes")],