Skip to content

Commit a285f63

Browse files
author
Andris
committed
Made most of the public attribute properties as IBInspectable
For enums additional Int properties were created to allow setting them in IB.
1 parent cf8e849 commit a285f63

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

Classes/ScrollableGraphView.swift

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,139 +12,158 @@ import UIKit
1212
// ###########
1313

1414
/// Specifies how thick the graph of the line is. In points.
15-
public var lineWidth: CGFloat = 2
15+
@IBInspectable public var lineWidth: CGFloat = 2
1616
/// The color of the graph line. UIColor.
17-
public var lineColor = UIColor.blackColor()
17+
// We must not use type inferring here or else the property won't show up in IB
18+
@IBInspectable public var lineColor: UIColor = UIColor.blackColor()
19+
20+
@IBInspectable var lineStyle_: Int {
21+
get { return lineStyle.rawValue }
22+
set {
23+
if let enumValue = ScrollableGraphViewLineStyle(rawValue: newValue) {
24+
lineStyle = enumValue
25+
}
26+
}
27+
}
1828
/// Whether or not the line should be rendered using bezier curves are straight lines.
1929
public var lineStyle = ScrollableGraphViewLineStyle.Straight
2030
/// How each segment in the line should connect. Takes any of the Core Animation LineJoin values.
2131
public var lineJoin = kCALineJoinRound
2232
/// The line caps. Takes any of the Core Animation LineCap values.
2333
public var lineCap = kCALineCapRound
24-
public var lineCurviness: CGFloat = 0.5
34+
@IBInspectable public var lineCurviness: CGFloat = 0.5
2535

2636
// Bar styles
2737
// ##########
2838

2939
/// Whether bars should be drawn or not. If you want a bar graph, this should be set to true.
30-
public var shouldDrawBarLayer = false
40+
@IBInspectable public var shouldDrawBarLayer: Bool = false
3141
/// The width of an individual bar on the graph.
32-
public var barWidth: CGFloat = 25;
42+
@IBInspectable public var barWidth: CGFloat = 25;
3343
/// The actual colour of the bar.
34-
public var barColor = UIColor.grayColor()
44+
@IBInspectable public var barColor: UIColor = UIColor.grayColor()
3545
/// The width of the outline of the bar
36-
public var barLineWidth: CGFloat = 1
46+
@IBInspectable public var barLineWidth: CGFloat = 1
3747
/// The colour of the bar outline
38-
public var barLineColor = UIColor.darkGrayColor()
48+
@IBInspectable public var barLineColor: UIColor = UIColor.darkGrayColor()
3949

4050
// Fill Styles
4151
// ###########
4252

4353
/// The background colour for the entire graph view, not just the plotted graph.
44-
public var backgroundFillColor = UIColor.whiteColor()
54+
@IBInspectable public var backgroundFillColor: UIColor = UIColor.whiteColor()
4555

4656
/// Specifies whether or not the plotted graph should be filled with a colour or gradient.
47-
public var shouldFill = false
57+
@IBInspectable public var shouldFill: Bool = false
58+
59+
@IBInspectable var fillType_: Int {
60+
get { return fillType.rawValue }
61+
set {
62+
if let enumValue = ScrollableGraphViewFillType(rawValue: newValue) {
63+
fillType = enumValue
64+
}
65+
}
66+
}
4867
/// Specifies whether to fill the graph with a solid colour or gradient.
4968
public var fillType = ScrollableGraphViewFillType.Solid
5069
/// If fillType is set to .Solid then this colour will be used to fill the graph.
51-
public var fillColor = UIColor.blackColor()
70+
@IBInspectable public var fillColor: UIColor = UIColor.blackColor()
5271
/// If fillType is set to .Gradient then this will be the starting colour for the gradient.
53-
public var fillGradientStartColor = UIColor.whiteColor()
72+
@IBInspectable public var fillGradientStartColor: UIColor = UIColor.whiteColor()
5473
/// If fillType is set to .Gradient, then this will be the ending colour for the gradient.
55-
public var fillGradientEndColor = UIColor.blackColor()
74+
@IBInspectable public var fillGradientEndColor: UIColor = UIColor.blackColor()
5675
/// If fillType is set to .Gradient, then this defines whether the gradient is rendered as a linear gradient or radial gradient.
5776
public var fillGradientType = ScrollableGraphViewGradientType.Linear
5877

5978
// Spacing
6079
// #######
6180

6281
/// How far the "maximum" reference line is from the top of the view's frame. In points.
63-
public var topMargin: CGFloat = 10
82+
@IBInspectable public var topMargin: CGFloat = 10
6483
/// How far the "minimum" reference line is from the bottom of the view's frame. In points.
65-
public var bottomMargin: CGFloat = 10
84+
@IBInspectable public var bottomMargin: CGFloat = 10
6685
/// How far the first point on the graph should be placed from the left hand side of the view.
67-
public var leftmostPointPadding: CGFloat = 50
86+
@IBInspectable public var leftmostPointPadding: CGFloat = 50
6887
/// How far the final point on the graph should be placed from the right hand side of the view.
69-
public var rightmostPointPadding: CGFloat = 50
88+
@IBInspectable public var rightmostPointPadding: CGFloat = 50
7089
/// How much space should be between each data point.
71-
public var dataPointSpacing: CGFloat = 40
90+
@IBInspectable public var dataPointSpacing: CGFloat = 40
7291
/// Which side of the graph the user is expected to scroll from.
7392
public var direction = ScrollableGraphViewDirection.LeftToRight
7493

7594
// Graph Range
7695
// ###########
7796

7897
/// If this is set to true, then the range will automatically be detected from the data the graph is given.
79-
public var shouldAutomaticallyDetectRange = false
98+
@IBInspectable public var shouldAutomaticallyDetectRange: Bool = false
8099
/// Forces the graph's minimum to always be zero. Used in conjunction with shouldAutomaticallyDetectRange or shouldAdaptRange, if you want to force the minimum to stay at 0 rather than the detected minimum.
81-
public var shouldRangeAlwaysStartAtZero = false // Used in conjunction with shouldAutomaticallyDetectRange, if you want to force the min to stay at 0.
100+
@IBInspectable public var shouldRangeAlwaysStartAtZero: Bool = false // Used in conjunction with shouldAutomaticallyDetectRange, if you want to force the min to stay at 0.
82101
/// The minimum value for the y-axis. This is ignored when shouldAutomaticallyDetectRange or shouldAdaptRange = true
83-
public var rangeMin: Double = 0
102+
@IBInspectable public var rangeMin: Double = 0
84103
/// The maximum value for the y-axis. This is ignored when shouldAutomaticallyDetectRange or shouldAdaptRange = true
85-
public var rangeMax: Double = 100
104+
@IBInspectable public var rangeMax: Double = 100
86105

87106
// Data Point Drawing
88107
// ##################
89108

90109
/// Whether or not to draw a symbol for each data point.
91-
public var shouldDrawDataPoint = true
110+
@IBInspectable public var shouldDrawDataPoint: Bool = true
92111
/// The shape to draw for each data point.
93112
public var dataPointType = ScrollableGraphViewDataPointType.Circle
94113
/// The size of the shape to draw for each data point.
95-
public var dataPointSize: CGFloat = 5
114+
@IBInspectable public var dataPointSize: CGFloat = 5
96115
/// The colour with which to fill the shape.
97-
public var dataPointFillColor: UIColor = UIColor.blackColor()
116+
@IBInspectable public var dataPointFillColor: UIColor = UIColor.blackColor()
98117
/// If dataPointType is set to .Custom then you,can provide a closure to create any kind of shape you would like to be displayed instead of just a circle or square. The closure takes a CGPoint which is the centre of the shape and it should return a complete UIBezierPath.
99118
public var customDataPointPath: ((centre: CGPoint) -> UIBezierPath)?
100119

101120
// Adapting & Animations
102121
// #####################
103122

104123
/// Whether or not the y-axis' range should adapt to the points that are visible on screen. This means if there are only 5 points visible on screen at any given time, the maximum on the y-axis will be the maximum of those 5 points. This is updated automatically as the user scrolls along the graph.
105-
public var shouldAdaptRange = false
124+
@IBInspectable public var shouldAdaptRange: Bool = false
106125
/// If shouldAdaptRange is set to true then this specifies whether or not the points on the graph should animate to their new positions. Default is set to true.
107-
public var shouldAnimateOnAdapt = true
126+
@IBInspectable public var shouldAnimateOnAdapt: Bool = true
108127
/// How long the animation should take. Affects both the startup animation and the animation when the range of the y-axis adapts to onscreen points.
109-
public var animationDuration: Double = 1
128+
@IBInspectable public var animationDuration: Double = 1
110129
/// The animation style.
111130
public var adaptAnimationType = ScrollableGraphViewAnimationType.EaseOut
112131
/// If adaptAnimationType is set to .Custom, then this is the easing function you would like applied for the animation.
113132
public var customAnimationEasingFunction: ((t: Double) -> Double)?
114133
/// Whether or not the graph should animate to their positions when the graph is first displayed.
115-
public var shouldAnimateOnStartup = true
134+
@IBInspectable public var shouldAnimateOnStartup: Bool = true
116135

117136
// Reference Lines
118137
// ###############
119138

120139
/// Whether or not to show the y-axis reference lines and labels.
121-
public var shouldShowReferenceLines = true
140+
@IBInspectable public var shouldShowReferenceLines: Bool = true
122141
/// The colour for the reference lines.
123-
public var referenceLineColor = UIColor.blackColor()
142+
@IBInspectable public var referenceLineColor: UIColor = UIColor.blackColor()
124143
/// The thickness of the reference lines.
125-
public var referenceLineThickness: CGFloat = 0.5
144+
@IBInspectable public var referenceLineThickness: CGFloat = 0.5
126145
/// Where the labels should be displayed on the reference lines.
127146
public var referenceLinePosition = ScrollableGraphViewReferenceLinePosition.Left
128147
/// The type of reference lines. Currently only .Cover is available.
129148
public var referenceLineType = ScrollableGraphViewReferenceLineType.Cover
130149

131150
/// How many reference lines should be between the minimum and maximum reference lines. If you want a total of 4 reference lines, you would set this to 2. This can be set to 0 for no intermediate reference lines.This can be used to create reference lines at specific intervals. If the desired result is to have a reference line at every 10 units on the y-axis, you could, for example, set rangeMax to 100, rangeMin to 0 and numberOfIntermediateReferenceLines to 9.
132-
public var numberOfIntermediateReferenceLines: Int = 3
151+
@IBInspectable public var numberOfIntermediateReferenceLines: Int = 3
133152
/// Whether or not to add labels to the intermediate reference lines.
134-
public var shouldAddLabelsToIntermediateReferenceLines = true
153+
@IBInspectable public var shouldAddLabelsToIntermediateReferenceLines: Bool = true
135154
/// Whether or not to add units specified by the referenceLineUnits variable to the labels on the intermediate reference lines.
136-
public var shouldAddUnitsToIntermediateReferenceLineLabels = false
155+
@IBInspectable public var shouldAddUnitsToIntermediateReferenceLineLabels: Bool = false
137156

138157
// Reference Line Labels
139158
// #####################
140159

141160
/// The font to be used for the reference line labels.
142161
public var referenceLineLabelFont = UIFont.systemFontOfSize(8)
143162
/// The colour of the reference line labels.
144-
public var referenceLineLabelColor = UIColor.blackColor()
163+
@IBInspectable public var referenceLineLabelColor: UIColor = UIColor.blackColor()
145164

146165
/// Whether or not to show the units on the reference lines.
147-
public var shouldShowReferenceLineUnits = true
166+
@IBInspectable public var shouldShowReferenceLineUnits: Bool = true
148167
/// The units that the y-axis is in. This string is used for labels on the reference lines.
149168
public var referenceLineUnits: String?
150169
/// The number of decimal places that should be shown on the reference line labels.
@@ -154,13 +173,13 @@ import UIKit
154173
// #################
155174

156175
/// Whether or not to show the labels on the x-axis for each point.
157-
public var shouldShowLabels = true
176+
@IBInspectable public var shouldShowLabels: Bool = true
158177
/// How far from the "minimum" reference line the data point labels should be rendered.
159-
public var dataPointLabelTopMargin: CGFloat = 10
178+
@IBInspectable public var dataPointLabelTopMargin: CGFloat = 10
160179
/// How far from the bottom of the view the data point labels should be rendered.
161180
public var dataPointLabelBottomMargin: CGFloat = 0
162181
/// The font for the data point labels.
163-
public var dataPointLabelColor = UIColor.blackColor()
182+
@IBInspectable public var dataPointLabelColor: UIColor = UIColor.blackColor()
164183
/// The colour for the data point labels.
165184
public var dataPointLabelFont: UIFont? = UIFont.systemFontOfSize(10)
166185
/// Used to force the graph to show every n-th dataPoint label

0 commit comments

Comments
 (0)