Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
adjusted grade colors (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich authored Oct 17, 2020
1 parent 460241f commit c633884
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
4 changes: 4 additions & 0 deletions TUM Campus App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
22AE458A247AF15600CE5B29 /* RoomCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AE4589247AF15600CE5B29 /* RoomCell.swift */; };
22AE458C247AF82300CE5B29 /* RoomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AE458B247AF82300CE5B29 /* RoomViewController.swift */; };
22AE458E247B214200CE5B29 /* MapCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AE458D247B214200CE5B29 /* MapCell.swift */; };
22AF6F30253B6F5200375627 /* GradeColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AF6F2F253B6F5200375627 /* GradeColors.swift */; };
22B00AF021D9458600E65C86 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B00AEF21D9458600E65C86 /* LoginViewController.swift */; };
22B00B0021DD878000E65C86 /* TUMOnlineAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B00AFF21DD878000E65C86 /* TUMOnlineAPI.swift */; };
22B8E7BA2389C91600CFEDEE /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B8E7B92389C91600CFEDEE /* ProfileTableViewController.swift */; };
Expand Down Expand Up @@ -276,6 +277,7 @@
22AE4589247AF15600CE5B29 /* RoomCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomCell.swift; sourceTree = "<group>"; };
22AE458B247AF82300CE5B29 /* RoomViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomViewController.swift; sourceTree = "<group>"; };
22AE458D247B214200CE5B29 /* MapCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapCell.swift; sourceTree = "<group>"; };
22AF6F2F253B6F5200375627 /* GradeColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradeColors.swift; sourceTree = "<group>"; };
22B00AEF21D9458600E65C86 /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
22B00AFF21DD878000E65C86 /* TUMOnlineAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TUMOnlineAPI.swift; sourceTree = "<group>"; };
22B09090250A94FF007A6470 /* TUM_Campus_App_v2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = TUM_Campus_App_v2.xcdatamodel; sourceTree = "<group>"; };
Expand Down Expand Up @@ -437,6 +439,7 @@
isa = PBXGroup;
children = (
22692D9A221E1618002C5720 /* Grade.swift */,
22AF6F2F253B6F5200375627 /* GradeColors.swift */,
2283061E24A539E5000A10CD /* GradeChartViewModel.swift */,
2269BB2B24A405B70011F9DF /* GradeCollectionViewController.swift */,
2269BB2D24A406B10011F9DF /* GradeCollectionViewCell.swift */,
Expand Down Expand Up @@ -1022,6 +1025,7 @@
224CB3672225A7F00002945A /* StudyRoomAttribute.swift in Sources */,
227395B524B4ABF20024CD21 /* MovieDetailCell.swift in Sources */,
222470D824632F8200B196B6 /* MenuCollectionViewController.swift in Sources */,
22AF6F30253B6F5200375627 /* GradeColors.swift in Sources */,
22B9D63A22207BA100854D55 /* Tuition.swift in Sources */,
22EDE42524B0B13500DBEC03 /* PersonDetailCollectionViewController.swift in Sources */,
22B9D64B2220B8DC00854D55 /* TUMSexyAPI.swift in Sources */,
Expand Down
14 changes: 2 additions & 12 deletions TUM Campus App/Grades/GradeChartViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,8 @@ struct GradeChartViewModel: Hashable {
for grade in gradeMap.enumerated() {
let entry = BarChartDataEntry(x: Double(grade.offset), y: Double(grade.element.value))
dataEntries.append(entry)
switch grade.element.key {
case 1.0..<2.0:
colors.append(.systemGreen)
case 2.0..<3.0:
colors.append(.systemYellow)
case 3.0...4.0:
colors.append(.systemOrange)
case 4.3...5.0:
colors.append(.systemRed)
default:
colors.append(.systemGray)
}
let grade = Double(truncating: grade.element.key as NSNumber)
colors.append(GradeColor.color(for: grade))
}

let dataSet = BarChartDataSet(entries: dataEntries)
Expand Down
17 changes: 2 additions & 15 deletions TUM Campus App/Grades/GradeCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,8 @@ final class GradeCollectionViewCell: UICollectionViewCell {
lvNumberLabel.text = grade.lvNumber
examinerLabel.text = grade.examiner
modusLabel.text = grade.modus?.components(separatedBy: " ").first
if let gradeValue = Double(grade.grade?.replacingOccurrences(of: ",", with: ".") ?? "") {
switch gradeValue {
case 1.0..<2.0:
blockView.backgroundColor = UIColor.systemGreen
case 2.0..<3.0:
blockView.backgroundColor = UIColor.systemYellow
case 3.0...4.0:
blockView.backgroundColor = UIColor.systemOrange
case 4.3...5.0:
blockView.backgroundColor = UIColor.systemRed
default:
blockView.backgroundColor = UIColor.systemGray
}
}
let inset = CGFloat(10)
blockView.backgroundColor = GradeColor.color(for: Double(grade.grade?.replacingOccurrences(of: ",", with: ".") ?? ""))
let inset: CGFloat = 10
NSLayoutConstraint.activate([
seperatorView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: inset),
seperatorView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
Expand Down
29 changes: 29 additions & 0 deletions TUM Campus App/Grades/GradeColors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GradeColors.swift
// TUMCampusApp
//
// Created by Tim Gymnich on 17.10.20.
// Copyright © 2020 TUM. All rights reserved.
//

import UIKit

struct GradeColor {

static func color(for grade: Double?) -> UIColor {
guard let grade = grade else { return #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1) }
switch grade {
case 1.0..<1.4: return #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
case 1.4..<1.8: return #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)
case 1.8..<2.1: return #colorLiteral(red: 0.5843137503, green: 0.8235294223, blue: 0.4196078479, alpha: 1)
case 2.1..<2.4: return #colorLiteral(red: 0.9999201894, green: 0.9686740041, blue: 0.4901453257, alpha: 1)
case 2.4..<2.8: return #colorLiteral(red: 0.9999290109, green: 0.9333780408, blue: 0.4587783813, alpha: 1)
case 2.8..<3.0: return #colorLiteral(red: 0.9999423623, green: 0.8745500445, blue: 0.000174792207, alpha: 1)
case 3.0..<3.4: return #colorLiteral(red: 0.9686274529, green: 0.78039217, blue: 0.3450980484, alpha: 1)
case 3.4..<3.8: return #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)
case 3.8..<4.0: return #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1)
case 4.0...5.0: return #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)
default: return #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
}
}
}

0 comments on commit c633884

Please sign in to comment.