Skip to content

Commit

Permalink
Revert "Machine updates (#355)"
Browse files Browse the repository at this point in the history
This reverts commit e631efa.
  • Loading branch information
jannisborn committed Oct 25, 2024
1 parent e631efa commit ba432fe
Show file tree
Hide file tree
Showing 10 changed files with 67,569 additions and 33,529 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:
- name: Check code formatting with black
run: black --check .

- name: Check code formatting with ruff
run: ruff format --check .

- name: Check sanity of json files
run: python .hooks/check_json.py

12 changes: 2 additions & 10 deletions PennyMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
8319D8D027414AC100E97D93 /* ZoomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8319D8CF27414AC100E97D93 /* ZoomViewController.swift */; };
837476502CADDAD800812146 /* StatisticsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8374764F2CADDAD800812146 /* StatisticsViewController.swift */; };
837476532CB0918000812146 /* DGCharts in Frameworks */ = {isa = PBXBuildFile; productRef = 837476522CB0918000812146 /* DGCharts */; };
837476552CB0918000812146 /* DGChartsDynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 837476542CB0918000812146 /* DGChartsDynamic */; };
839CF440267B78AB00E259D9 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839CF43F267B78AB00E259D9 /* SettingsViewController.swift */; };
83BAF44E2A792D45002365D2 /* ImagePickerHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83BAF44D2A792D45002365D2 /* ImagePickerHelper.swift */; };
83D226CD2620F4910050ED9E /* PinViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D226CC2620F4910050ED9E /* PinViewController.swift */; };
Expand Down Expand Up @@ -84,7 +83,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
837476552CB0918000812146 /* DGChartsDynamic in Frameworks */,
837476532CB0918000812146 /* DGCharts in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -197,7 +195,6 @@
name = PennyMe;
packageProductDependencies = (
837476522CB0918000812146 /* DGCharts */,
837476542CB0918000812146 /* DGChartsDynamic */,
);
productName = PennyMe;
productReference = 9F9F31A12300B40900C0E854 /* PennyMe.app */;
Expand Down Expand Up @@ -520,7 +517,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.16;
MARKETING_VERSION = 1.17;
PRODUCT_BUNDLE_IDENTIFIER = "PennyMe--com.de.pennyme";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
Expand All @@ -540,7 +537,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.16;
MARKETING_VERSION = 1.17;
PRODUCT_BUNDLE_IDENTIFIER = "PennyMe--com.de.pennyme";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
Expand Down Expand Up @@ -688,11 +685,6 @@
package = 837476512CB0918000812146 /* XCRemoteSwiftPackageReference "Charts" */;
productName = DGCharts;
};
837476542CB0918000812146 /* DGChartsDynamic */ = {
isa = XCSwiftPackageProductDependency;
package = 837476512CB0918000812146 /* XCRemoteSwiftPackageReference "Charts" */;
productName = DGChartsDynamic;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 9F9F31992300B40900C0E854 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "charts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/danielgindi/Charts",
"state" : {
"revision" : "dd9c72e3d7e751e769971092a6bd72d39198ae63",
"version" : "5.1.0"
}
}
],
"version" : 2
}
111 changes: 55 additions & 56 deletions PennyMe/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions PennyMe/StatisticsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@ class StatisticsViewController: UIViewController {

func setupBarChart(mode: String) {
// Sort the dictionary and get the top 5 countries
var topFiveCountries = visitedByArea.sorted { $0.value > $1.value }.prefix(5)//.reversed()
var topFiveCountries = visitedByArea.sorted { $0.value > $1.value }.prefix(5)
// if percent: sort by percentage
if mode != "absolute" {
// topFiveCountries = visitedByArea.sorted { ($0.value/machinesByArea[$0.key]!) > ($1.value/machinesByArea[$1.key]!) }.prefix(5).reversed()
// }
topFiveCountries = visitedByArea.sorted {
let percentage1 = Double($0.value) / Double(machinesByArea[$0.key] ?? 1)
let percentage2 = Double($1.value) / Double(machinesByArea[$1.key] ?? 1)
Expand All @@ -176,9 +174,10 @@ class StatisticsViewController: UIViewController {
// Create entries for the bar chart
var barChartEntries: [BarChartDataEntry] = []
var countryNames: [String] = []
var nameSizes: [String] = []

// Assign colors to each bar
var barColors: [UIColor] = [] // [.orange, .red, .purple, UIColor.systemBlue, UIColor.systemGreen]
var barColors: [UIColor] = []

for (index, country) in topFiveCountries.reversed().enumerated() {
var barValue: Double = 0
Expand All @@ -191,11 +190,24 @@ class StatisticsViewController: UIViewController {
let entry = BarChartDataEntry(x: Double(index), y: barValue)

barChartEntries.append(entry)

countryNames.append(country.key)
// add name
let name = country.key
let maxNameLength = 12 // Example threshold, adjust as needed
let formattedName = ((name.count > maxNameLength) && name.contains(" ")) ? insertLineBreaksInCountryName(name, maxLength: maxNameLength) : name
countryNames.append(formattedName)
// append size for scaling
nameSizes.append(contentsOf: formattedName.components(separatedBy: "\n"))
barColors.append(colorForValue(value: Int(barValue), mode: mode))
}

// Calculate the longest country name with line breaks and update padding accordingly
let longestName = nameSizes.max(by: { $1.count > $0.count }) ?? ""
let longestNameLength = longestName.count

// Adjust the left padding to accommodate the longest label
barChartView.extraLeftOffset = CGFloat(longestNameLength) * 2.0
// barChartView.extraRightOffset = 10.0

// Create the BarChartDataSet
let dataSet = BarChartDataSet(entries: barChartEntries, label: "Collected Pennies")
dataSet.colors = barColors
Expand All @@ -218,7 +230,10 @@ class StatisticsViewController: UIViewController {
barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: countryNames)
barChartView.xAxis.granularity = 1
barChartView.xAxis.labelPosition = .bottom // Horizontal bar chart has labels at the bottom

// Adjust the bar chart's font size to make room for two-line labels
barChartView.xAxis.granularityEnabled = true
barChartView.xAxis.wordWrapEnabled = true
barChartView.xAxis.avoidFirstLastClippingEnabled = true
// Increase font size of the x-axis (country labels)
barChartView.xAxis.labelFont = .systemFont(ofSize: 16)

Expand All @@ -240,6 +255,24 @@ class StatisticsViewController: UIViewController {
barChartView.notifyDataSetChanged()
}

func insertLineBreaksInCountryName(_ name: String, maxLength: Int) -> String {
// Split the string into chunks and insert line breaks at a reasonable spot
let words = name.split(separator: " ")
var currentLineLength = 0
var result = ""
// iterate over words
for word in words {
currentLineLength += word.count + 1 // +1 for space
if (currentLineLength > maxLength) && (result.count > 0) {
result += "\n" + word
currentLineLength = word.count
} else {
result += (result.isEmpty ? "" : " ") + word
}
}
return result
}

func colorForValue(value: Int, mode: String) -> UIColor {
// Define the minimum and maximum values for the range
let minValue = 1
Expand Down
Loading

0 comments on commit ba432fe

Please sign in to comment.