Skip to content

Commit

Permalink
lienchart
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonCat4012 committed Mar 9, 2023
1 parent db42bf7 commit 217cf69
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Calq.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
F1C04B5029BA363A00DAC128 /* JSONUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD81F6822759091600B4A43B /* JSONUtil.swift */; };
F1C04B5229BA376800DAC128 /* MediumBarChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C04B5129BA376800DAC128 /* MediumBarChart.swift */; };
F1C04B5429BA3E2D00DAC128 /* SmallCircleChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1C04B5329BA3E2D00DAC128 /* SmallCircleChart.swift */; };
F1C04B5529BA3EAB00DAC128 /* LineChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0B86D327667E3F00DCC61F /* LineChart.swift */; };
F1E8BFE329900C5500486A6D /* CircleChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1E8BFE229900C5500486A6D /* CircleChart.swift */; };
F1F568C8298DA72100227F88 /* ImpactSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1F568C7298DA72100227F88 /* ImpactSegment.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -532,6 +533,7 @@
files = (
F19B10A129AF726600B11C82 /* UserTest+CoreDataClass.swift in Sources */,
F1B0B17129968E6C00F3D1FD /* ColorExtension.swift in Sources */,
F1C04B5529BA3EAB00DAC128 /* LineChart.swift in Sources */,
F19B109D29AF726600B11C82 /* AppSettings+CoreDataClass.swift in Sources */,
DD4F97A927515CCA00D3CC57 /* CoreDataStack.swift in Sources */,
F19B109F29AF726600B11C82 /* AppSettings+CoreDataProperties.swift in Sources */,
Expand Down
33 changes: 33 additions & 0 deletions CalqWidget/CalqWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ private struct CalqWidgetEntryView: View {
}
}

private struct CalqWidgetEntryView2: View {
var entry: SimpleEntry
let subjects = Util.getAllSubjects()

var body: some View {
GeometryReader{geo in
if(subjects.isEmpty){
EmptyMediumView()
} else {
LineChart(subjects: Binding.constant(subjects), heigth: geo.size.height - 50)
.padding()
}
}
}
}

struct CalqWidget: Widget {
let kind: String = "AverageWidget"

Expand All @@ -50,6 +66,18 @@ struct CalqWidget: Widget {
}
}

struct lineWidget: Widget {
let kind: String = "LineChartWidget"

var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
CalqWidgetEntryView2(entry: entry)
}
.configurationDisplayName("Liniendiagramm")
.description("Notenverlauf aller Fächer")
.supportedFamilies([.systemMedium])
}
}

//MARK: Medium BarChart Widget
struct BarChartWidget: Widget {
Expand All @@ -73,6 +101,7 @@ struct CalqWidgetBundle: WidgetBundle {
var body: some Widget{
CalqWidget()
BarChartWidget()
lineWidget()
}
}

Expand All @@ -86,5 +115,9 @@ struct widgets_Previews: PreviewProvider {
CalqWidgetEntryView(entry: SimpleEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .systemSmall))
.previewDisplayName("CircleChart")

CalqWidgetEntryView2(entry: SimpleEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .systemMedium))
.previewDisplayName("LineChart")
}
}
26 changes: 15 additions & 11 deletions CalqWidget/MediumBarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct BarChartWidgetView: View {
let fullHeigth = geo.size.height - 30
VStack(alignment: .center) {
if subjects.isEmpty {
emptyView(width: geo.size.width - 20)
EmptyMediumView()
} else {
HStack{
ForEach(subjects, id: \.self) { subj in
Expand All @@ -41,15 +41,19 @@ struct BarChartWidgetView: View {
}.padding(10)
}
}

@ViewBuilder
func emptyView(width: CGFloat) -> some View {
Spacer()
HStack{
Image(systemName: "exclamationmark.triangle.fill").foregroundColor(.red)
Text("Du hast noch keine Noten hinzugefügt qwq").multilineTextAlignment(.center)
Image(systemName: "exclamationmark.triangle.fill").foregroundColor(.red)
}.frame(width: width)
Spacer()
}

struct EmptyMediumView: View {
var body: some View {
VStack {
Spacer()
HStack{
Image(systemName: "exclamationmark.triangle.fill").foregroundColor(.red)
Text("Du hast noch keine Noten hinzugefügt qwq").multilineTextAlignment(.center)
Image(systemName: "exclamationmark.triangle.fill").foregroundColor(.red)
}
Spacer()
}
.padding()
}
}

0 comments on commit 217cf69

Please sign in to comment.