Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.2
18 changes: 11 additions & 7 deletions TKRadarChart.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = Tbxark;
TargetAttributes = {
6A3F39B41DEB1E1A0067576C = {
Expand Down Expand Up @@ -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 = "";
};
Expand All @@ -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 = "";
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
107 changes: 64 additions & 43 deletions TKRadarChart/TKRadarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public struct TKRadarChartConfig {
showBgBorder: true,
fillArea: true,
clockwise: false,
autoCenterPoint: true)
autoCenterPoint: true,
showOuterCircle: false,
showInnerCircle: true)
}


Expand All @@ -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,
Expand All @@ -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
Expand All @@ -120,6 +126,8 @@ public struct TKRadarChartConfig {
self.fillArea = fillArea
self.clockwise = clockwise
self.autoCenterPoint = autoCenterPoint
self.showOuterCircle = showOuterCircle
self.showInnerCircle = showInnerCircle
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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){
Expand All @@ -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()
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion TKRadarChartDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down