Skip to content

Commit

Permalink
graph fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
esusslin committed Mar 20, 2017
1 parent 4f2ed49 commit 5f3d20b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 46 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion LazyWalker/LazyWalker/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES" initialViewController="JWt-ZT-DKb">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES" initialViewController="YpY-gy-hGb">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down
5 changes: 5 additions & 0 deletions LazyWalker/LazyWalker/globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ var thirdCoords = [CGPoint]()
var fourthCoords = [CGPoint]()
var fifthCoords = [CGPoint]()

var elevationRange = [Double]()

var minElevation = Double()
var maxElevation = Double()

//var pointsAry = [CGPoint]()
39 changes: 25 additions & 14 deletions LazyWalker/LazyWalker/lines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extension mapVC {

func addGraphicSubview(index: String) {




let num = Int(index)!
Expand All @@ -83,6 +84,11 @@ func addGraphicSubview(index: String) {
var customView = LineChart()
customView.data = nil

customView.xMin = 0.0
customView.xMax = 0.0
customView.yMin = 0.0
customView.yMax = 0.0

var color = UIColor()

if num == 0 {
Expand All @@ -109,46 +115,49 @@ func addGraphicSubview(index: String) {
pointsAry = fifthCoords
color = .red
}



// for point in pointsAry {
// let dot = (point[0] as! Double, point[1] as! Double)
// pointArr.append(dot as! (Double, Double))
// }
//

let screenSize: CGRect = UIScreen.main.bounds

let width = self.view.frame.size.width
let height = self.view.frame.size.height
let sortedAscend = ascend.sorted()

customView.frame = CGRect.init(x: 0, y: height - 200, width: screenSize.width - 30, height: 85)
customView.frame = CGRect.init(x: 0, y: height - 230, width: screenSize.width - 30, height: 100)

customView.backgroundColor = UIColor.white.withAlphaComponent(0.2)
customView.center.x = self.view.center.x
customView.layer.cornerRadius = customView.frame.size.width / 16

let xmaximum = pointsAry[pointsAry.count - 1]

print(xmaximum.x)

customView.lineColor = color
customView.showPoints = false
customView.axisColor = .gray
customView.axisLineWidth = 1
customView.yMin = CGFloat(sortedAscend[0] - 10)
customView.xMax = CGFloat(totalDistanceOverall)
customView.yMax = CGFloat(sortedAscend[sortedAscend.count - 1] + 10)
customView.yMin = CGFloat(minElevation)
customView.xMin = 0.0
customView.xMax = CGFloat(xmaximum.x)
// customView.xMax = CGFloat(4000)
customView.yMax = CGFloat(maxElevation + 10)
customView.data = pointsAry
customView.tag = 100

print("TOTAL DISTANCE OVERALL")
print(customView.xMax)

// customView.setAxisRange(xMin: 0.0, xMax: customView.xMax, yMin: customView.yMin, yMax: customView.xMax )

print(customView.data?.count)
print(customView.yMin)
print(customView.yMax)


self.mapView.addSubview(customView)
}

func removeSubview() {
print("Start remove sibview")
print("Start remove subview")
if let viewWithTag = self.view.viewWithTag(100) {
viewWithTag.removeFromSuperview()
}else{
Expand Down Expand Up @@ -224,6 +233,8 @@ func addGraphicSubview(index: String) {

let point = CGPoint(x: distanceCounter, y: htAry[index])

print(point)

if id == "0" {
firstCoords.append(point)
}
Expand Down
60 changes: 29 additions & 31 deletions LazyWalker/LazyWalker/mapVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
override func viewDidLoad() {
super.viewDidLoad()

reset()

setLocation()

searchController = UISearchController(searchResultsController: resultsViewController)
Expand Down Expand Up @@ -194,7 +196,7 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
let theString = "https://graphhopper.com/api/1/route?point=" + pointstring + "&vehicle=foot&locale=en&elevation=true&points_encoded=false&ch.disable=true&heading=1&algorithm=alternative_route&alternative_route.max_paths=20&alternative_route.max_weight_factor=4&alternative_route.max_share_factor=2&key=a67e19cf-291b-492b-b380-68405b49e910"
//
print(theString)

var allPathElevations = [Double]()

Alamofire.request(theString).responseJSON { response in

Expand All @@ -214,6 +216,8 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV

let points = path["points"] as? [String:Any]
let coords = points?["coordinates"] as! NSArray!

// allPathElevations.append(coords[2])

var elevations = [Double]()

Expand All @@ -226,11 +230,19 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
}

self.flattestRoute()

self.findRange()
}

}
}

func findRange() {

let sortedRange = elevationRange.sorted()
minElevation = sortedRange[0]
maxElevation = sortedRange[sortedRange.count - 1]

}


func flattestRoute() {
Expand Down Expand Up @@ -265,6 +277,8 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
// FIRST:
let flattest = ascend.index(of: sortedAscend[0])!
printLine(index: flattest, id: "0")

findRange()

}

Expand All @@ -277,6 +291,9 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
let path = paths[index]

let points = path["points"]! as! AnyObject!



let coords = points?["coordinates"] as! NSArray!

self.distanceElevation(points: coords!, id: id)
Expand All @@ -285,6 +302,11 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
for coord in coords! {

let coordAry = coord as! NSArray

let elevation = coordAry[2]

elevationRange.append(elevation as! Double)

let lat = coordAry[1]
let lng = coordAry[0]

Expand All @@ -302,7 +324,12 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV

}



totalDistanceOverall = self.distance(linecoords.first!, linecoords.last!)

print("TOTAL DISTANCE")
print(totalDistanceOverall)


for (index, _) in linecoords.enumerated() {
Expand Down Expand Up @@ -471,14 +498,6 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV


removeSubview()
// for v in self.customView.subviews{
//
// v.removeFromSuperview()
// self.customView.data = nil
// }

// self.customView.data = nil



let poly = mapView.annotations?.filter { annotation in
Expand Down Expand Up @@ -643,27 +662,6 @@ class mapVC: UIViewController, MGLMapViewDelegate, UISearchBarDelegate, UITableV
return heading
}

// ///// TABLEVIEW STUFF
//
//
// func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell,
// forRowAt indexPath: IndexPath) {
// cell.backgroundColor = UIColor.clear
// }
//
//
// func numberOfSections(in tableView: UITableView) -> Int {
// // #warning Incomplete implementation, return the number of sections
// return 0
// }
//
// func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// // #warning Incomplete implementation, return the number of rows
// return 0
// }
//

////////////////////


// MAP CAMERA
Expand Down

0 comments on commit 5f3d20b

Please sign in to comment.