-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRadarChartStyle.swift
92 lines (80 loc) · 2.48 KB
/
RadarChartStyle.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// RadarChartStyle.swift
// RadarChart
//
// Copyright © 2018 hajime-nakamura. All rights reserved.
//
import Foundation
import UIKit
public struct RadarChartStyle {
let color: UIColor
let backgroundColor: UIColor
let xAxis: Axis?
let yAxis: Axis?
let label: Label?
public init(
color: UIColor,
backgroundColor: UIColor,
xAxis: Axis? = nil,
yAxis: Axis? = nil,
label: Label? = nil) {
self.color = color
self.backgroundColor = backgroundColor
self.xAxis = xAxis
self.yAxis = yAxis
self.label = label
}
public struct Axis {
private static let defaultColor: UIColor = .black
private static let defaultWidth: CGFloat = 0
public let colors: [UIColor]
public let widths: [CGFloat]
public init(colors: [UIColor], widths: [CGFloat]) {
self.colors = colors
self.widths = widths
}
func color(for index: Int) -> UIColor {
if index > colors.count - 1 {
guard let last = colors.last else { return Axis.defaultColor }
return last
} else {
return colors[index]
}
}
func width(for index: Int) -> CGFloat {
if index > widths.count - 1 {
guard let last = widths.last else { return Axis.defaultWidth }
return last
} else {
return widths[index]
}
}
}
public struct Label {
static let defaultFontColor: UIColor = .black
static let defaultFontSize: CGFloat = 0
static let defaultLineSpacing: CGFloat = 0
static let defaultLetterSpacing: CGFloat = 0
static let defaultMargin: CGFloat = 0
public let fontName: String
public let fontColor: UIColor
public let fontSize: CGFloat
public let lineSpacing: CGFloat
public let letterSpacing: CGFloat
public let margin: CGFloat
public init(
fontName: String,
fontColor: UIColor,
fontSize: CGFloat,
lineSpacing: CGFloat,
letterSpacing: CGFloat,
margin: CGFloat) {
self.fontName = fontName
self.fontColor = fontColor
self.fontSize = fontSize
self.lineSpacing = lineSpacing
self.letterSpacing = letterSpacing
self.margin = margin
}
}
}