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
8 changes: 3 additions & 5 deletions TKRadarChart.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
6A3F39B41DEB1E1A0067576C = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = 858CBVXSWP;
LastSwiftMigration = 0900;
LastSwiftMigration = 1010;
ProvisioningStyle = Automatic;
};
6A415EEF1DEB1DAC001DBF69 = {
Expand Down Expand Up @@ -299,8 +299,7 @@
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -326,8 +325,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.play.TKRadarChart;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down
25 changes: 20 additions & 5 deletions TKRadarChart/TKRadarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public class TKRadarChart: UIView, TKRadarChartDelegate {
centerPoint = CGPoint.zero
configuration = TKRadarChartConfig.defaultConfig()
super.init(coder: aDecoder)
centerPoint = CGPoint(x: frame.width/2, y: frame.height/2)
// 解决视图不居中问题
centerPoint = CGPoint(x: frame.size.width/2+frame.origin.x, y: frame.size.height/2+frame.origin.y)
backgroundColor = UIColor.clear
}

Expand All @@ -185,6 +186,20 @@ public class TKRadarChart: UIView, TKRadarChartDelegate {
let numOfRow = dataSource.numberOfRowForRadarChart(self)

guard numOfRow > 0 else { return }
// 如果maxValue为默认值则从数据源中找到真正的maxValue
if configuration.maxValue == 5 {
let numOfSection = dataSource.numberOfSectionForRadarChart(self)
var max = configuration.maxValue
for section in 0..<numOfSection {
for row in 0..<numOfRow {
let value = dataSource.valueOfSectionForRadarChart(withRow: row, section: section)
if value > max {
max = value
}
}
}
configuration.maxValue = max
}

let textFont = delegate.fontOfTitleForRadarChart(self)
let numOfSetp = max(dataSource.numberOfStepForRadarChart(self), 1)
Expand All @@ -205,7 +220,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 +230,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 Down