-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathReferenceLines.swift
More file actions
105 lines (87 loc) · 4.67 KB
/
ReferenceLines.swift
File metadata and controls
105 lines (87 loc) · 4.67 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
import UIKit
// Currently just a simple data structure to hold the settings for the reference lines.
open class ReferenceLines {
// Reference Lines
// ###############
/// Whether or not to show the y-axis reference lines and labels.
@IBInspectable open var shouldShowReferenceLines: Bool = true
/// The colour for the reference lines.
@IBInspectable open var referenceLineColor: UIColor = UIColor.black
/// The thickness of the reference lines.
@IBInspectable open var referenceLineThickness: CGFloat = 0.5
@IBInspectable var referenceLinePosition_: Int {
get { return referenceLinePosition.rawValue }
set {
if let enumValue = ScrollableGraphViewReferenceLinePosition(rawValue: newValue) {
referenceLinePosition = enumValue
}
}
}
/// Where the labels should be displayed on the reference lines.
open var referenceLinePosition = ScrollableGraphViewReferenceLinePosition.left
@IBInspectable open var positionType = ReferenceLinePositioningType.relative
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
/// Whether or not to add units specified by the referenceLineUnits variable to the labels on the intermediate reference lines.
@IBInspectable open var shouldAddUnitsToIntermediateReferenceLineLabels: Bool = false
// Reference Line Labels
// #####################
/// The font to be used for the reference line labels.
open var referenceLineLabelFont = UIFont.systemFont(ofSize: 8)
/// The colour of the reference line labels.
@IBInspectable open var referenceLineLabelColor: UIColor = UIColor.black
/// Whether or not to show the units on the reference lines.
@IBInspectable open var shouldShowReferenceLineUnits: Bool = true
/// The units that the y-axis is in. This string is used for labels on the reference lines.
@IBInspectable open var referenceLineUnits: String?
/// The number of decimal places that should be shown on the reference line labels.
@IBInspectable open var referenceLineNumberOfDecimalPlaces: Int = 0
/// The NSNumberFormatterStyle that reference lines should use to display
@IBInspectable open var referenceLineNumberStyle: NumberFormatter.Style = .none
// Data Point Labels // TODO: Refactor these into their own settings and allow for more label options (positioning)
// ################################################################################################################
/// Whether or not to show the labels on the x-axis for each point.
@IBInspectable open var shouldShowLabels: Bool = true
/// How far from the "minimum" reference line the data point labels should be rendered.
@IBInspectable open var dataPointLabelTopMargin: CGFloat = 10
/// How far from the bottom of the view the data point labels should be rendered.
@IBInspectable open var dataPointLabelBottomMargin: CGFloat = 0
/// The font for the data point labels.
@IBInspectable open var dataPointLabelColor: UIColor = UIColor.black
/// The colour for the data point labels.
open var dataPointLabelFont: UIFont? = UIFont.systemFont(ofSize: 10)
/// Used to force the graph to show every n-th dataPoint label
@IBInspectable open var dataPointLabelsSparsity: Int = 1
public init() {
// Need this for external frameworks.
}
}
open class ReferenceLine {
public let position: Double
public let label: String?
public init(position: Double, label: String? = nil) {
self.position = position
self.label = label
}
}
@objc public enum ScrollableGraphViewReferenceLinePosition : Int {
case left
case right
case both
}
@objc public enum ReferenceLinePositioningType : Int {
case relative
case absolute
}
@objc public enum ScrollableGraphViewReferenceLineType : Int {
case cover
}