Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
fc2ee488
Commit
fc2ee488
authored
Feb 27, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to show additional graph line
parent
4782e52f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
35 deletions
+50
-35
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+1
-1
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
1Weather/UI/Helpers/GraphLine.swift
+7
-7
1Weather/UI/Helpers/GraphView.swift
+2
-2
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/CityForecastTimePeriodCell.swift
+26
-21
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/PeriodForecastButton.swift
+2
-2
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
+12
-2
No files found.
1Weather.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
fc2ee488
...
...
@@ -7,7 +7,7 @@
<
k
e
y
>
1Weather.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
3
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
PG
(
Playground
)
1.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
...
...
1Weather.xcworkspace/xcuserdata/dstepanets.xcuserdatad/UserInterfaceState.xcuserstate
View file @
fc2ee488
No preview for this file type
1Weather/UI/Helpers/GraphLine.swift
View file @
fc2ee488
...
...
@@ -15,7 +15,7 @@ struct LineDot {
struct
GraphLine
{
//Private
private
static
let
cubicCurveAlgorithm
=
CubicCurveAlgorithm
()
private
let
cubicCurveAlgorithm
=
CubicCurveAlgorithm
()
private
let
kIntersectAccuracy
:
CGFloat
=
2
private
var
points
=
[
CGPoint
]()
private
let
settings
:
GraphLineSettings
...
...
@@ -56,8 +56,8 @@ struct GraphLine {
private
mutating
func
linePath
(
from
points
:[
CGPoint
])
->
UIBezierPath
{
let
path
=
UIBezierPath
()
let
startPoint
=
CGPoint
(
x
:
0
,
y
:
self
.
onGetGraphRect
()
.
height
)
let
endPoint
=
CGPoint
(
x
:
self
.
onGetGraphRect
()
.
width
,
y
:
self
.
onGetGraphRect
()
.
height
)
let
startPoint
=
CGPoint
(
x
:
0
,
y
:
points
.
first
?
.
y
??
0
)
let
endPoint
=
CGPoint
(
x
:
self
.
onGetGraphRect
()
.
width
,
y
:
points
.
last
?
.
y
??
0
)
var
pointsToAdd
=
[
CGPoint
]()
pointsToAdd
.
append
(
startPoint
)
...
...
@@ -70,13 +70,13 @@ struct GraphLine {
return
path
}
let
controlPoints
=
GraphLine
.
cubicCurveAlgorithm
.
controlPointsFromPoints
(
dataPoints
:
pointsToAdd
)
let
controlPoints
=
cubicCurveAlgorithm
.
controlPointsFromPoints
(
dataPoints
:
pointsToAdd
)
for
index
in
1
..<
pointsToAdd
.
count
{
sections
.
append
(
.
init
(
p0
:
pointsToAdd
[
index
-
1
],
p1
:
controlPoints
[
index
-
1
]
.
controlPoint1
,
p2
:
controlPoints
[
index
-
1
]
.
controlPoint2
,
p3
:
pointsToAdd
[
index
]))
path
.
addCurve
(
to
:
pointsToAdd
[
index
],
controlPoint1
:
controlPoints
[
index
-
1
]
.
controlPoint1
,
controlPoint2
:
controlPoints
[
index
-
1
]
.
controlPoint2
)
...
...
@@ -136,11 +136,11 @@ struct GraphLine {
func
tintDotAt
(
point
:
CGPoint
)
{
lineDots
.
forEach
{
$0
.
shape
.
strokeColor
=
ThemeManager
.
currentTheme
.
graphC
olor
.
cgColor
$0
.
shape
.
strokeColor
=
settings
.
c
olor
.
cgColor
}
guard
let
dotToTint
=
(
lineDots
.
first
{
$0
.
center
==
point
})
else
{
return
}
dotToTint
.
shape
.
strokeColor
=
ThemeManager
.
currentTheme
.
graphT
intColor
.
cgColor
dotToTint
.
shape
.
strokeColor
=
settings
.
t
intColor
.
cgColor
}
mutating
func
updateWith
(
points
:[
CGPoint
])
{
...
...
1Weather/UI/Helpers/GraphView.swift
View file @
fc2ee488
...
...
@@ -11,13 +11,13 @@ import BezierKit
class
GraphView
:
UIView
{
//Private
private
let
mainLineSettings
=
GraphLineSettings
(
lineWidth
:
3
,
dotRadius
:
3
,
dotRadius
:
2.5
,
dotLineWidth
:
2
,
color
:
ThemeManager
.
currentTheme
.
graphColor
,
tintColor
:
ThemeManager
.
currentTheme
.
graphTintColor
)
private
let
additionalLineSettings
=
GraphLineSettings
(
lineWidth
:
2
,
dotRadius
:
2
,
dotLineWidth
:
1
/
UIScreen
.
main
.
scale
,
dotLineWidth
:
1
,
color
:
UIColor
(
hex
:
0xa4a4a4
)
.
withAlphaComponent
(
0.7
),
tintColor
:
UIColor
(
hex
:
0x434343
)
.
withAlphaComponent
(
0.7
))
...
...
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/CityForecastTimePeriodCell.swift
View file @
fc2ee488
...
...
@@ -27,14 +27,14 @@ class CityForecastTimePeriodCell: UITableViewCell {
private
var
maxTempGraphPoints
=
[
CGPoint
]()
private
var
minTempGraphPoints
=
[
CGPoint
]()
private
let
graphView
=
GraphView
()
private
let
dayTemps
=
[
DayTemp
(
min
:
8
,
max
:
17
),
DayTemp
(
min
:
9
,
max
:
17
),
DayTemp
(
min
:
7
,
max
:
18
),
DayTemp
(
min
:
7
,
max
:
17
),
DayTemp
(
min
:
8
,
max
:
17
),
DayTemp
(
min
:
8
,
max
:
18
),
DayTemp
(
min
:
9
,
max
:
18
),
DayTemp
(
min
:
8
,
max
:
16
)]
private
let
dayTemps
=
[
DayTemp
(
min
:
-
23
,
max
:
-
13
),
DayTemp
(
min
:
-
19
,
max
:
-
12
),
DayTemp
(
min
:
-
12
,
max
:
-
10
),
DayTemp
(
min
:
-
10
,
max
:
-
3
),
DayTemp
(
min
:
-
7
,
max
:
-
3
),
DayTemp
(
min
:
-
11
,
max
:
-
1
),
DayTemp
(
min
:
-
14
,
max
:
-
5
),
DayTemp
(
min
:
-
15
,
max
:
-
7
)]
private
var
graphIsDrawn
=
false
override
init
(
style
:
UITableViewCell
.
CellStyle
,
reuseIdentifier
:
String
?)
{
...
...
@@ -100,31 +100,36 @@ class CityForecastTimePeriodCell: UITableViewCell {
self
.
maxTempGraphPoints
.
removeAll
()
self
.
minTempGraphPoints
.
removeAll
()
let
maxTemp
=
CGFloat
(
dayTemps
.
map
{
$0
.
max
}
.
max
()
??
0
)
let
minTemp
=
CGFloat
(
dayTemps
.
map
{
$0
.
min
}
.
min
()
??
0
)
let
maxTemps
=
dayTemps
.
map
{
$0
.
max
}
let
topMaxTemp
=
maxTemps
.
max
()
??
0
let
minTemps
=
dayTemps
.
map
{
$0
.
min
}
let
topMinTemp
=
minTemps
.
max
()
??
0
for
index
in
0
..<
dayTemps
.
count
{
guard
let
stackButton
=
stackView
.
arrangedSubviews
[
index
]
as?
PeriodForecastButton
else
{
continue
}
let
buttonRightSide
=
stackButton
.
frame
.
origin
.
x
+
stackButton
.
bounds
.
width
let
buttonCenterX
=
(
buttonRightSide
+
stackButton
.
frame
.
origin
.
x
)
/
2
let
numberOfLevels
=
maxTemp
-
minTemp
let
levelHeight
=
(
graphView
.
frame
.
height
/
numberOfLevels
)
.
rounded
(
.
down
)
var
maxPointLevel
=
(
maxTemp
-
dayTemps
[
index
]
.
max
)
*
levelHeight
var
minPointLevel
=
(
minTemp
+
dayTemps
[
index
]
.
min
)
*
levelHeight
//Add points offset at cirle radius if needed
maxPointLevel
=
max
(
maxPointLevel
,
5
)
maxPointLevel
=
min
(
maxPointLevel
,
graphView
.
frame
.
height
-
5
)
let
maxTempLevelsCount
=
CGFloat
(
Set
(
maxTemps
)
.
count
)
let
minTempLevelsCount
=
CGFloat
(
Set
(
minTemps
)
.
count
)
let
totalLevels
=
maxTempLevelsCount
+
minTempLevelsCount
let
levelHeight
=
(
graphView
.
frame
.
height
/
CGFloat
(
totalLevels
))
.
rounded
(
.
down
)
let
maxTempFrame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
graphView
.
frame
.
width
,
height
:
maxTempLevelsCount
*
levelHeight
)
let
minTempFrame
=
CGRect
(
x
:
0
,
y
:
maxTempFrame
.
height
,
width
:
graphView
.
frame
.
width
,
height
:
minTempLevelsCount
*
levelHeight
)
minPointLevel
=
min
(
minPointLevel
,
5
)
minPointLevel
=
max
(
minPointLevel
,
graphView
.
frame
.
height
-
5
)
//Max
var
maxPointLevel
=
maxTempFrame
.
origin
.
y
+
((
topMaxTemp
-
maxTemps
[
index
])
*
levelHeight
)
+
levelHeight
maxPointLevel
=
min
(
maxPointLevel
,
maxTempFrame
.
height
+
5
)
//Min
var
minPointLevel
=
minTempFrame
.
origin
.
y
+
((
topMinTemp
-
minTemps
[
index
])
*
levelHeight
)
+
levelHeight
minPointLevel
=
min
(
minPointLevel
,
minTempFrame
.
height
+
minTempFrame
.
origin
.
y
-
5
)
maxTempGraphPoints
.
append
(
.
init
(
x
:
buttonCenterX
,
y
:
maxPointLevel
))
minTempGraphPoints
.
append
(
.
init
(
x
:
buttonCenterX
,
y
:
minPointLevel
))
}
print
(
"break"
)
}
@objc
private
func
handleConditionButton
(
button
:
PeriodForecastButton
)
{
...
...
1Weather/UI/View controllers/Today/Cells/CityForecastTimePeriod/PeriodForecastButton.swift
View file @
fc2ee488
...
...
@@ -9,7 +9,7 @@ import UIKit
class
PeriodForecastButton
:
UIControl
{
//Private
private
let
kGraphInset
:
CGFloat
=
4
private
let
kGraphInset
:
CGFloat
=
10
private
let
forecastImageView
=
UIImageView
()
private
let
tempLabel
=
UILabel
()
private
let
indicatorImageView
=
UIImageView
()
...
...
@@ -24,7 +24,7 @@ class PeriodForecastButton: UIControl {
return
.
init
(
x
:
0
,
y
:
topInset
,
width
:
self
.
bounds
.
width
,
height
:
self
.
minTempLabel
.
frame
.
origin
.
y
-
topInset
-
kGraphInse
t
)
height
:
self
.
minTempLabel
.
frame
.
origin
.
y
-
self
.
tempLabel
.
frame
.
origin
.
y
-
tempLabel
.
frame
.
heigh
t
)
}
override
init
(
frame
:
CGRect
)
{
...
...
Pods/Pods.xcodeproj/xcuserdata/dstepanets.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
fc2ee488
...
...
@@ -18,6 +18,11 @@
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
1
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
Cirque.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
4
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
Localize-Swift.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
isShown
<
/k
e
y
>
...
...
@@ -25,19 +30,24 @@
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
2
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
Localize-Swift.xcscheme_
^#
shared
#^
_
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
5
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
Pods-1Weather.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
isShown
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
3
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
1
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
k
e
y
>
SnapKit.xcscheme
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
isShown
<
/k
e
y
>
<
fa
ls
e
/
>
<
k
e
y
>
orderHint
<
/k
e
y
>
<
int
e
g
e
r
>
4
<
/int
e
g
e
r
>
<
int
e
g
e
r
>
2
<
/int
e
g
e
r
>
<
/
d
i
c
t
>
<
/
d
i
c
t
>
<
k
e
y
>
SuppressBuildableAutocreation
<
/k
e
y
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment