diff --git a/.swift-version b/.swift-version index 5186d07..bf77d54 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 +4.2 diff --git a/TKRadarChart.xcodeproj/project.pbxproj b/TKRadarChart.xcodeproj/project.pbxproj index 687094a..3ffdb78 100644 --- a/TKRadarChart.xcodeproj/project.pbxproj +++ b/TKRadarChart.xcodeproj/project.pbxproj @@ -174,7 +174,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = Tbxark; TargetAttributes = { 6A3F39B41DEB1E1A0067576C = { @@ -299,8 +299,8 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -326,8 +326,8 @@ PRODUCT_BUNDLE_IDENTIFIER = com.play.TKRadarChart; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -347,7 +347,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.play.TKRadarChartDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -364,7 +364,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.play.TKRadarChartDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -381,12 +381,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -435,12 +437,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/TKRadarChart/TKRadarChart.swift b/TKRadarChart/TKRadarChart.swift index 7d2be1a..e34f9ef 100644 --- a/TKRadarChart/TKRadarChart.swift +++ b/TKRadarChart/TKRadarChart.swift @@ -76,7 +76,9 @@ public struct TKRadarChartConfig { showBgBorder: true, fillArea: true, clockwise: false, - autoCenterPoint: true) + autoCenterPoint: true, + showOuterCircle: false, + showInnerCircle: true) } @@ -94,6 +96,8 @@ public struct TKRadarChartConfig { public var fillArea: Bool public var clockwise: Bool public var autoCenterPoint: Bool + public var showOuterCircle: Bool + public var showInnerCircle: Bool public init(radius: CGFloat, @@ -107,7 +111,9 @@ public struct TKRadarChartConfig { showBgBorder: Bool, fillArea: Bool, clockwise: Bool, - autoCenterPoint: Bool) { + autoCenterPoint: Bool, + showOuterCircle: Bool, + showInnerCircle: Bool) { self.radius = radius self.minValue = minValue self.maxValue = maxValue @@ -120,6 +126,8 @@ public struct TKRadarChartConfig { self.fillArea = fillArea self.clockwise = clockwise self.autoCenterPoint = autoCenterPoint + self.showOuterCircle = showOuterCircle + self.showInnerCircle = showInnerCircle } } @@ -205,7 +213,7 @@ public class TKRadarChart: UIView, TKRadarChartDelegate { let title = dataSource.titleOfRowForRadarChart(self, row: index) let pointOnEdge = CGPoint(x: centerPoint.x - radius * sin(i * perAngle), y: centerPoint.y - radius * cos(i * perAngle)) - let attributeTextSize = (title as NSString).size(withAttributes: [NSAttributedStringKey.font: textFont]) + let attributeTextSize = (title as NSString).size(withAttributes: [NSAttributedString.Key.font: textFont]) let width = attributeTextSize.width let xOffset = pointOnEdge.x >= centerPoint .x ? width / 2.0 + padding : -width / 2.0 - padding @@ -215,9 +223,9 @@ public class TKRadarChart: UIView, TKRadarChartDelegate { let paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle paragraphStyle.alignment = .center paragraphStyle.lineBreakMode = .byClipping - let attributes = [NSAttributedStringKey.font: textFont, - NSAttributedStringKey.paragraphStyle: paragraphStyle, - NSAttributedStringKey.foregroundColor: titleColor] + let attributes = [NSAttributedString.Key.font: textFont, + NSAttributedString.Key.paragraphStyle: paragraphStyle, + NSAttributedString.Key.foregroundColor: titleColor] /// Fix title offset if index == 0 || (numOfRow%2 == 0 && index == numOfRow/2){ @@ -228,45 +236,57 @@ public class TKRadarChart: UIView, TKRadarChartDelegate { (title as NSString).draw(in: rect, withAttributes: attributes) } - + if configuration.showOuterCircle { + context.saveGState() + lineColor.setStroke() + let cirlePath = UIBezierPath(arcCenter: centerPoint, radius: radius, startAngle: 0, endAngle: CGFloat(2.0 * Double.pi), clockwise: true) + cirlePath.lineWidth = configuration.borderWidth + if configuration.showBgBorder { + cirlePath.stroke() + } + context.restoreGState() + } + /// Draw the background rectangle - context.saveGState() - lineColor.setStroke() - for stepTemp in 1...numOfSetp { - let step = numOfSetp - stepTemp + 1 - let fillColor = delegate.colorOfFillStepForRadarChart(self, step: step) - - let scale = CGFloat(step)/CGFloat(numOfSetp) - let innserRadius = scale * radius - let path = UIBezierPath() - for index in 0...numOfRow { - let i = CGFloat(index) - if index == 0 { - let x = centerPoint.x - let y = centerPoint.y - innserRadius - path.move(to: CGPoint(x: x, y: y)) - } else if index == numOfRow { - let x = centerPoint.x - let y = centerPoint.y - innserRadius - path.addLine(to: CGPoint(x: x, y: y)) - }else { - let x = centerPoint.x - innserRadius * sin(i * perAngle) - let y = centerPoint.y - innserRadius * cos(i * perAngle) - path.addLine(to: CGPoint(x: x, y: y)) + if configuration.showInnerCircle { + context.saveGState() + lineColor.setStroke() + + for stepTemp in 1...numOfSetp { + let step = numOfSetp - stepTemp + 1 + let fillColor = delegate.colorOfFillStepForRadarChart(self, step: step) + + let scale = CGFloat(step)/CGFloat(numOfSetp) + let innserRadius = scale * radius + let path = UIBezierPath() + for index in 0...numOfRow { + let i = CGFloat(index) + if index == 0 { + let x = centerPoint.x + let y = centerPoint.y - innserRadius + path.move(to: CGPoint(x: x, y: y)) + } else if index == numOfRow { + let x = centerPoint.x + let y = centerPoint.y - innserRadius + path.addLine(to: CGPoint(x: x, y: y)) + }else { + let x = centerPoint.x - innserRadius * sin(i * perAngle) + let y = centerPoint.y - innserRadius * cos(i * perAngle) + path.addLine(to: CGPoint(x: x, y: y)) + } + } + + path.close() + fillColor.setFill() + + path.lineWidth = configuration.borderWidth + path.fill() + if configuration.showBgBorder { + path.stroke() } } - - path.close() - fillColor.setFill() - - path.lineWidth = configuration.borderWidth - path.fill() - if configuration.showBgBorder { - path.stroke() - } + context.restoreGState() } - context.restoreGState() - /// Draw the background line lineColor.setStroke() @@ -314,11 +334,12 @@ public class TKRadarChart: UIView, TKRadarChartDelegate { let y = centerPoint.y - (value - minValue) / (maxValue - minValue) * radius path.addLine(to: CGPoint(x: x, y: y)) - + path.close() + fillColor.setFill() borderColor.setStroke() - path.lineWidth = 2 + path.lineWidth = configuration.borderWidth if configuration.fillArea { path.fill() } diff --git a/TKRadarChartDemo/AppDelegate.swift b/TKRadarChartDemo/AppDelegate.swift index 17c7156..2ba0bed 100644 --- a/TKRadarChartDemo/AppDelegate.swift +++ b/TKRadarChartDemo/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true }