Skip to content

Commit dce5626

Browse files
author
Howard Wang
committed
Update example
1 parent d86ed72 commit dce5626

File tree

11 files changed

+83
-348
lines changed

11 files changed

+83
-348
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ DerivedData/
1616
*.perspectivev3
1717
!default.perspectivev3
1818
xcuserdata/
19+
.DS_Store
1920

2021
## Other
2122
*.moved-aside

HamsterUIKit.xcodeproj/project.pbxproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
709A438D1EA3262C0076CED4 /* HamsterUIKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 709A438C1EA3262C0076CED4 /* HamsterUIKitTests.swift */; };
3232
709A438F1EA3262C0076CED4 /* HamsterUIKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 709A43811EA3262C0076CED4 /* HamsterUIKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
3333
709A43A81EA3AECA0076CED4 /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 709A43A71EA3AECA0076CED4 /* Extension.swift */; };
34-
70A10E311F006D82001B68F5 /* HamsCoachMarkArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A10E301F006D82001B68F5 /* HamsCoachMarkArea.swift */; };
35-
70D9A8241EF76991009AAB7D /* HamsCoachMark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70D9A8231EF76991009AAB7D /* HamsCoachMark.swift */; };
36-
70D9A8281EF772CE009AAB7D /* CoachMarkController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70D9A8271EF772CE009AAB7D /* CoachMarkController.swift */; };
3734
/* End PBXBuildFile section */
3835

3936
/* Begin PBXContainerItemProxy section */
@@ -95,9 +92,6 @@
9592
709A438C1EA3262C0076CED4 /* HamsterUIKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HamsterUIKitTests.swift; sourceTree = "<group>"; };
9693
709A438E1EA3262C0076CED4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9794
709A43A71EA3AECA0076CED4 /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
98-
70A10E301F006D82001B68F5 /* HamsCoachMarkArea.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HamsCoachMarkArea.swift; sourceTree = "<group>"; };
99-
70D9A8231EF76991009AAB7D /* HamsCoachMark.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HamsCoachMark.swift; sourceTree = "<group>"; };
100-
70D9A8271EF772CE009AAB7D /* CoachMarkController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoachMarkController.swift; sourceTree = "<group>"; };
10195
/* End PBXFileReference section */
10296

10397
/* Begin PBXFrameworksBuildPhase section */
@@ -138,7 +132,6 @@
138132
7011FE141EB2EC8F00157E9B /* LaunchScreen.storyboard */,
139133
7011FE171EB2EC8F00157E9B /* Info.plist */,
140134
7037D1341EB64AD800B8CB00 /* HelloBarChartViewController.swift */,
141-
70D9A8271EF772CE009AAB7D /* CoachMarkController.swift */,
142135
);
143136
path = HamsterUIKitExample;
144137
sourceTree = "<group>";
@@ -177,8 +170,6 @@
177170
701480071EAD36330065F8BF /* HamsIndexPath.swift */,
178171
7011FE221EB2F4F700157E9B /* HamsLabelStyle.swift */,
179172
7011FE2B1EB4036700157E9B /* HamsChartBase.swift */,
180-
70D9A8231EF76991009AAB7D /* HamsCoachMark.swift */,
181-
70A10E301F006D82001B68F5 /* HamsCoachMarkArea.swift */,
182173
);
183174
path = HamsterUIKit;
184175
sourceTree = "<group>";
@@ -353,7 +344,6 @@
353344
isa = PBXSourcesBuildPhase;
354345
buildActionMask = 2147483647;
355346
files = (
356-
70D9A8281EF772CE009AAB7D /* CoachMarkController.swift in Sources */,
357347
7011FE0C1EB2EC8F00157E9B /* AppDelegate.swift in Sources */,
358348
7011FE251EB39B3A00157E9B /* HamsCurveChartController.swift in Sources */,
359349
7037D1351EB64AD800B8CB00 /* HelloBarChartViewController.swift in Sources */,
@@ -365,14 +355,12 @@
365355
isa = PBXSourcesBuildPhase;
366356
buildActionMask = 2147483647;
367357
files = (
368-
70D9A8241EF76991009AAB7D /* HamsCoachMark.swift in Sources */,
369358
709A43A81EA3AECA0076CED4 /* Extension.swift in Sources */,
370359
701480061EAD35E00065F8BF /* HamsBackgoundStyle.swift in Sources */,
371360
701480041EAD34AB0065F8BF /* HamsCurveChartPoint.swift in Sources */,
372361
706153271EAFDA690078250E /* HamsBarChartRect.swift in Sources */,
373362
7011FE2C1EB4036700157E9B /* HamsChartBase.swift in Sources */,
374363
7011FE231EB2F4F700157E9B /* HamsLabelStyle.swift in Sources */,
375-
70A10E311F006D82001B68F5 /* HamsCoachMarkArea.swift in Sources */,
376364
701480081EAD36330065F8BF /* HamsIndexPath.swift in Sources */,
377365
70147FFF1EAD34030065F8BF /* ChartsCore.swift in Sources */,
378366
706153231EAFA7B90078250E /* HamsBarChart.swift in Sources */,

HamsterUIKit/ChartsCore.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ open class ChartsCore {
2626
return chartHeight - topBorder - bottomBorder
2727
}
2828

29-
open var max: CGFloat {
30-
return getY(by: values.max()!)
31-
}
32-
33-
open var min: CGFloat {
34-
return getY(by: values.min()!)
35-
}
29+
open lazy var max: CGFloat = {
30+
return self.getY(by: self.values.max()!)
31+
}()
32+
33+
open lazy var min: CGFloat = {
34+
return self.getY(by: self.values.min()!)
35+
}()
3636

3737
public init(with points: [CGFloat], frameSize:CGSize) {
3838
values = points

HamsterUIKit/HamsCoachMark.swift

Lines changed: 0 additions & 127 deletions
This file was deleted.

HamsterUIKit/HamsCoachMarkArea.swift

Lines changed: 0 additions & 34 deletions
This file was deleted.

HamsterUIKit/HamsCurveChart.swift

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,41 +118,46 @@ open class HamsCurveChart: HamsChartBase {
118118
delegate?.curveChart!(self, configureForCharts: currentChart)
119119
super.update()
120120

121-
if numberOfValues > 0 {
122-
for i in 0..<numberOfValues(in: currentChart) {
123-
let curveChartPoint = dataSource?.curveChart(self, pointForChart: HamsIndexPath(column: i, view: currentChart))
124-
chartValues.append((curveChartPoint?.pointValue)!)
125-
}
126-
if chartValues.max() == 0 {
127-
isDataEmpty = true
128-
} else {
129-
isDataEmpty = false
130-
}
131-
} else {
132-
chartValues = [0, 0]
133-
isDataEmpty = true
134-
}
135-
136-
if let val = value(type: startPoint, left: true) {
137-
chartValues = [val] + chartValues
138-
}
139-
140-
if let val = value(type: endPoint, left: false) {
141-
chartValues = chartValues + [val]
142-
}
143-
numberOfValues = chartValues.count
144-
121+
updateData()
122+
145123
let contentOffsets = ChartOffset(top: offsets.top + chartHeaderHeight + gapBtwPointAndValue + labelHeight + 20,
146124
bottom: offsets.bottom + chartFooterHeight,
147125
column: offsets.column,
148126
horizon: offsets.horizon)
149127
quadCurve = QuadCurveAlgorithm(with: chartValues, frameSize: frame.size, offsets: contentOffsets)
150-
128+
151129
quadCurve.maxValue = maximum
152130
labelWidth = quadCurve.unitWidth
153131
setLabels()
154132
}
155133

134+
fileprivate func updateData() {
135+
if numberOfValues > 0 {
136+
for i in 0..<numberOfValues(in: currentChart) {
137+
let curveChartPoint = dataSource?.curveChart(self, pointForChart: HamsIndexPath(column: i, view: currentChart))
138+
chartValues.append((curveChartPoint?.pointValue)!)
139+
}
140+
141+
if chartValues.max() == 0 {
142+
isDataEmpty = true
143+
} else {
144+
isDataEmpty = false
145+
}
146+
} else {
147+
chartValues = [0, 0]
148+
isDataEmpty = true
149+
}
150+
151+
if let val = value(type: startPoint, left: true) {
152+
chartValues = [val] + chartValues
153+
}
154+
155+
if let val = value(type: endPoint, left: false) {
156+
chartValues = chartValues + [val]
157+
}
158+
numberOfValues = chartValues.count
159+
}
160+
156161
override open func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
157162
super.beginTracking(touch, with: event)
158163
touchedPoint = touch.location(in: self)
@@ -230,13 +235,13 @@ open class HamsCurveChart: HamsChartBase {
230235
let height = frame.height
231236

232237
let graphPath = quadCurve.quadCurvePath
233-
graphPath.addLine(to: CGPoint(
238+
graphPath?.addLine(to: CGPoint(
234239
x: quadCurve.getX(by: chartValues.count - 1),
235240
y:height))
236-
graphPath.addLine(to: CGPoint(
241+
graphPath?.addLine(to: CGPoint(
237242
x:quadCurve.getX(by: 0),
238243
y:height))
239-
graphPath.close()
244+
graphPath?.close()
240245

241246

242247
switch filledStyle! {
@@ -250,7 +255,7 @@ open class HamsCurveChart: HamsChartBase {
250255
colors: colors as CFArray,
251256
locations: colorLocations)
252257

253-
ctx.addPath(graphPath.cgPath)
258+
ctx.addPath((graphPath?.cgPath)!)
254259
ctx.clip()
255260
var startPoint = CGPoint.zero
256261
if quadCurve.maxValue == 0{
@@ -266,7 +271,7 @@ open class HamsCurveChart: HamsChartBase {
266271
case .plain(let color):
267272
defaultColor = color
268273
color.setFill()
269-
graphPath.fill()
274+
graphPath?.fill()
270275
}
271276

272277
}

HamsterUIKit/HamsIndexPath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open class HamsIndexPath {
1818
/// method to create a HamsIndexPath
1919
public init(column: Int, view: Int) {
2020
_column = column
21-
_chart = chart
21+
_chart = view
2222
}
2323

2424
open var column: Int { return _column }

0 commit comments

Comments
 (0)