Skip to content

Commit

Permalink
Redesign with map views
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Sep 24, 2023
1 parent 5b0aa9b commit 7506e93
Show file tree
Hide file tree
Showing 69 changed files with 3,290 additions and 10,157 deletions.
11,979 changes: 2,383 additions & 9,596 deletions notebooks/NE sqlite.ipynb

Large diffs are not rendered by default.

120 changes: 82 additions & 38 deletions seelog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions seelog.xcodeproj/xcshareddata/xcschemes/seelog.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
22 changes: 20 additions & 2 deletions seelog/Helpers/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Helpers {
}
return String(usv)
} else {
return country
return ""
}
}

Expand Down Expand Up @@ -253,7 +253,15 @@ class Helpers {
)
}

static func formatNumber(_ num: Double) ->String{
static func formatNumber(_ num: Int) ->String {
return NumberFormatter.localizedString(from: NSNumber(value: num), number: NumberFormatter.Style.decimal)
}

static func formatNumber(_ num: Double) ->String {
return NumberFormatter.localizedString(from: NSNumber(value: num), number: NumberFormatter.Style.decimal)
}

static func formatShortNumber(_ num: Double) ->String {
let thousandNum = num / 1000
let millionNum = num / 1000000
if num >= 1000 && num < 1000000 {
Expand Down Expand Up @@ -356,4 +364,14 @@ class Helpers {
} != nil
}

static func intersects(mapRegion1: MKCoordinateRegion, mapRegion2: MKCoordinateRegion) -> Bool {
let mapPolygons1 = Helpers.toPolygons(mapRegion: mapRegion1)
let mapPolygons2 = Helpers.toPolygons(mapRegion: mapRegion2)
return mapPolygons1.first { p1 in
mapPolygons2.first { p2 in
return (try? p1.intersects(p2)) ?? false
} != nil
} != nil
}

}
2 changes: 0 additions & 2 deletions seelog/Helpers/VisitPeriodManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class VisitPeriodManager {
return visitPeriods?.filter({ period -> Bool in
let correctCategory = currentTab == .places ||
(period.type == .country && currentTab == .countries) ||
(period.type == .state && currentTab == .states) ||
(period.type == .city && currentTab == .cities) ||
(period.type == .timezone && currentTab == .timezones) ||
(period.type == .continent && currentTab == .continents)

Expand Down
2 changes: 1 addition & 1 deletion seelog/Initialization/DatabaseCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import CoreData

class DatabaseCreator {
static let currentDatabaseVersion: Double = 1.3
static let currentDatabaseVersion: Double = 1.4

static func create(container: NSPersistentContainer) {
let databaseVersionKey = "app.seelog.databaseversion"
Expand Down
1 change: 1 addition & 0 deletions seelog/Models/City.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
struct City: Identifiable, Trippable {
var id: Int64 { return cityInfo.cityKey }
var name: String { return cityInfo.name }
var nameWithFlag: String { return "🌆 " + name }
var cityInfo: CityInfo
var model: DomainModel

Expand Down
17 changes: 15 additions & 2 deletions seelog/Models/Continent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ struct Continent: Identifiable, Trippable, Drawable {
var id: String { return continentInfo.name }
var _id: String { return id }
var name: String { return continentInfo.name }
var flag: String {
switch name {
case "Africa": return "🌍"
case "Asia": return "🌏"
case "Australia": return "🌏"
case "Europe": return "🌍"
case "North America": return "🌎"
case "South America": return "🌎"
default: return "🌍"
}
}
var nameWithFlag: String { return flag + " " + name }
var continentInfo: ContinentInfo
var model: DomainModel
var coordinateRegion: MKCoordinateRegion { return continentInfo.geometryDescription.coordinateRegion }

var cities: [City] { return model.cities.filter { $0.cityInfo.continent == self.id } }
var countries: [Country] { return model.countries.filter { $0.countryInfo.continent == self.id } }
Expand All @@ -28,13 +41,13 @@ struct Continent: Identifiable, Trippable, Drawable {
func info(year: Int?) -> TextInfo {
let link = ViewLink.continent(self)
if !visited(year: year) {
return TextInfo(id: id, link: link, heading: continentInfo.name, status: .notVisited, enabled: false)
return TextInfo(id: id, link: link, heading: nameWithFlag, status: .notVisited, enabled: false)
}

return TextInfo(
id: id,
link: link,
heading: continentInfo.name,
heading: nameWithFlag,
status: status(year: year),
body: [
stayDurationInfo(year: year)
Expand Down
5 changes: 4 additions & 1 deletion seelog/Models/Country.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import MapKit
struct Country: Identifiable, Trippable, Drawable {
var id: String { return countryInfo.countryKey }
var _id: String { return id }
var coordinateRegion: MKCoordinateRegion { return countryInfo.geometry(zoomType: .far).coordinateRegion }
var name: String { return countryInfo.name }
var flag: String { return Helpers.flag(country: countryInfo.countryKey) }
var nameWithFlag: String { return flag + " " + name }
var countryInfo: CountryInfo
var model: DomainModel

Expand Down Expand Up @@ -45,7 +48,7 @@ struct Country: Identifiable, Trippable, Drawable {
return TextInfo(
id: id,
link: link,
heading: countryInfo.name,
heading: nameWithFlag,
status: status(year: year),
body: [
stayDurationInfo(year: year),
Expand Down
1 change: 1 addition & 0 deletions seelog/Models/Drawable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MapKit

protocol Drawable {
var _id: String { get }
var coordinateRegion: MKCoordinateRegion { get }
func polygons(zoomType: ZoomType) -> [Polygon]
func intersects(mapRegion: MKCoordinateRegion) -> Bool
}
7 changes: 7 additions & 0 deletions seelog/Models/GeometryDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ struct GeometryDescription {
return nil
}

var coordinateRegion: MKCoordinateRegion {
let span = MKCoordinateSpan(latitudeDelta: maxLatitude - minLatitude, longitudeDelta: maxLongitude - minLongitude)
let center = CLLocationCoordinate2D(latitude: (maxLatitude - span.latitudeDelta / 2), longitude: maxLongitude - span.longitudeDelta / 2)

return MKCoordinateRegion(center: center, span: span)
}

var boundingRect: Polygon? {
guard let envelope = try? geometry?.minimumRotatedRectangle() else { return nil }
switch envelope {
Expand Down
2 changes: 2 additions & 0 deletions seelog/Models/Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ struct Region: Identifiable, Trippable, Drawable {
var id: String { return stateInfo.stateKey }
var _id: String { return id }
var name: String { return stateInfo.name }
var nameWithFlag: String { return "\(country.flag) \(name)" }
var stateInfo: StateInfo
var model: DomainModel
var coordinateRegion: MKCoordinateRegion { return stateInfo.geometry(zoomType: .far).coordinateRegion }

var cities: [City] { return model.cities.filter { city in city.cityInfo.stateKey == self.id } }
var country: Country { return model.country(id: stateInfo.countryKey) }
Expand Down
5 changes: 3 additions & 2 deletions seelog/Models/SeenGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ struct SeenGeometry: Identifiable {

func polygons(zoomType: ZoomType) -> [Polygon] {
let positions = zoomType == .far ? higherLevelPositions : positions
let polygons = positions.map { $0.polygon }.filter({ $0 != nil }).map({ $0! })
let polygons = positions.compactMap { $0.polygon }

let heatmap = MultiPolygon(polygons: polygons)

guard let buffered = try? heatmap.buffer(by: 0.05) else { return [] }
guard let buffered = try? heatmap.buffer(by: 0.0) else { return heatmap.polygons }

let processedHeatmap = Helpers.convexHeatmap(heatmap: buffered)

Expand Down
2 changes: 2 additions & 0 deletions seelog/Models/Timezone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ struct Timezone: Identifiable, Trippable, Drawable {
var id: Int32 { return timezoneInfo.timezoneId }
var _id: String { return "\(id)" }
var name: String { return timezoneInfo.name }
var nameWithFlag: String { return name }
var timezoneInfo: TimezoneInfo
var coordinateRegion: MKCoordinateRegion { return timezoneInfo.geometryDescription.coordinateRegion }

var stayDurationByYear: [Int: Int]
var trips: [Trip]
Expand Down
5 changes: 5 additions & 0 deletions seelog/Models/Trippable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum Status {

protocol Trippable {
var name: String { get }
var nameWithFlag: String { get }
var trips: [Trip] { get }
var tripsByYear: [Int: [Trip]] { get }
var stayDuration: Int { get }
Expand Down Expand Up @@ -171,6 +172,10 @@ extension Trippable {
// how many years did you return
return sentences.joined(separator: " ")
}

func isNew(year: Int?) -> Bool {
return isFirstYear(year ?? Date().year())
}

func status(year: Int?) -> Status {
let stayDuration = stayDurationForYear(year)
Expand Down
1 change: 1 addition & 0 deletions seelog/Models/World.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
struct World: Identifiable, Trippable {
var id: String { get { return "world" } }
var name: String { return "World" }
var nameWithFlag: String { return name }

var stayDurationByYear: [Int: Int]
var trips: [Trip]
Expand Down
26 changes: 14 additions & 12 deletions seelog/Services/TextInfoGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

class TextInfoGenerator {

static func travelledDistance(model: DomainModel, year: Int?) -> [TextInfo] {
static func travelledDistance(model: DomainModel, year: Int?) -> TextInfo {
var body: [String] = []
let distanceRounded = model.seenGeometry(year: year)?.travelledDistanceRounded ?? 0
let distance = model.seenGeometry(year: year)?.travelledDistance ?? 0
Expand All @@ -20,24 +20,22 @@ class TextInfoGenerator {
if distance >= earthCircumference {
let times = Int(round(distance / earthCircumference))
body.append(
"That's \(times) times around the Earth!"
"That's \(format(times)) times around the Earth!"
)
} else if distance >= newYorkToBoston / 2 {
let times = Int(round(distance / newYorkToBoston))
body.append(
"That's \(times) times from Boston to New York!"
"That's \(format(times)) times from Boston to New York!"
)
}

return [
TextInfo(
id: "distance",
link: .none,
heading: "Travelled \(distanceRounded) km",
status: .visited,
body: body
)
]
return TextInfo(
id: "distance",
link: .none,
heading: "Travelled \(format(distanceRounded)) km",
status: .visited,
body: body
)
}

static func countriesHome(model: DomainModel, year: Int?) -> [TextInfo] {
Expand Down Expand Up @@ -215,5 +213,9 @@ class TextInfoGenerator {

return descriptions
}

private static func format(_ number: Int) -> String {
return NumberFormatter.localizedString(from: NSNumber(value: number), number: NumberFormatter.Style.decimal)
}

}
13 changes: 9 additions & 4 deletions seelog/Views/Charts/CitiesBarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import SwiftUI

struct CitiesBarChartView: View {
@EnvironmentObject var viewState: ViewState
@ObservedObject var selectedYearState = SelectedYearState()
@ObservedObject var selectedYearState: SelectedYearState

var yearStats: [(year: Int, count: Int)] { get { return viewState.model.cityYearCounts } }
var totalCount: Int { get { return viewState.model.citiesForYear(nil).count } }

var body: some View {
BarChartView(showCounts: true, yearStats: yearStats, total: totalCount)
BarChartView(
selectedYearState: selectedYearState,
showCounts: true,
yearStats: yearStats,
total: totalCount
)
}
}

struct CitiesBarChartView_Previews: PreviewProvider {
static var previews: some View {
let model = simulatedDomainModel()

return CitiesBarChartView().environmentObject(ViewState(model: model))
.environmentObject(SelectedYearState())
return CitiesBarChartView(selectedYearState: SelectedYearState())
.environmentObject(ViewState(model: model))
}
}
12 changes: 8 additions & 4 deletions seelog/Views/Charts/ContinentsBarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ import SwiftUI

struct ContinentsBarChartView: View {
@EnvironmentObject var viewState: ViewState
@ObservedObject var selectedYearState = SelectedYearState()
@ObservedObject var selectedYearState: SelectedYearState

var yearStats: [(year: Int, count: Int)] { get { return viewState.model.continentYearCounts } }
var totalCount: Int { get { return viewState.model.continentsForYear(nil).count } }

var body: some View {
BarChartView(showCounts: true, yearStats: yearStats, total: totalCount)
BarChartView(
selectedYearState: selectedYearState,
showCounts: true,
yearStats: yearStats,
total: totalCount
)
}
}

struct ContinentsBarChartView_Previews: PreviewProvider {
static var previews: some View {
let model = simulatedDomainModel()

return ContinentsBarChartView()
return ContinentsBarChartView(selectedYearState: SelectedYearState())
.environmentObject(ViewState(model: model))
.environmentObject(SelectedYearState())
}
}
13 changes: 9 additions & 4 deletions seelog/Views/Charts/CountriesBarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import SwiftUI

struct CountriesBarChartView: View {
@EnvironmentObject var viewState: ViewState
@ObservedObject var selectedYearState = SelectedYearState()
@ObservedObject var selectedYearState: SelectedYearState

var yearStats: [(year: Int, count: Int)] { get { return viewState.model.countryYearCounts } }
var totalCount: Int { get { return viewState.model.countriesForYear(nil).count } }

var body: some View {
BarChartView(showCounts: true, yearStats: yearStats, total: totalCount)
BarChartView(
selectedYearState: selectedYearState,
showCounts: true,
yearStats: yearStats,
total: totalCount
)
}
}

struct CountriesBarChartView_Previews: PreviewProvider {
static var previews: some View {
let model = simulatedDomainModel()

return CountriesBarChartView().environmentObject(ViewState(model: model))
.environmentObject(SelectedYearState())
return CountriesBarChartView(selectedYearState: SelectedYearState())
.environmentObject(ViewState(model: model))
}
}
12 changes: 8 additions & 4 deletions seelog/Views/Charts/TimezonesBarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ import SwiftUI

struct TimezonesBarChartView: View {
@EnvironmentObject var viewState: ViewState
@ObservedObject var selectedYearState = SelectedYearState()
@ObservedObject var selectedYearState: SelectedYearState

var yearStats: [(year: Int, count: Int)] { get { return viewState.model.timezonesYearCounts } }
var totalCount: Int { get { return viewState.model.timezonesForYear(nil).count } }

var body: some View {
BarChartView(showCounts: true, yearStats: yearStats, total: totalCount)
BarChartView(
selectedYearState: selectedYearState,
showCounts: true,
yearStats: yearStats,
total: totalCount
)
}
}

struct TimezonesBarChartView_Previews: PreviewProvider {
static var previews: some View {
let model = simulatedDomainModel()

return TimezonesBarChartView()
return TimezonesBarChartView(selectedYearState: SelectedYearState())
.environmentObject(ViewState(model: model))
.environmentObject(SelectedYearState())
}
}
Loading

0 comments on commit 7506e93

Please sign in to comment.