From 217cf69fe9250e370f2108581c1ca7dd50dd9150 Mon Sep 17 00:00:00 2001 From: Kiara <68660034+DragonCat4012@users.noreply.github.com> Date: Thu, 9 Mar 2023 17:30:56 +0100 Subject: [PATCH] lienchart --- Calq.xcodeproj/project.pbxproj | 2 ++ CalqWidget/CalqWidget.swift | 33 +++++++++++++++++++++++++++++++++ CalqWidget/MediumBarChart.swift | 26 +++++++++++++++----------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/Calq.xcodeproj/project.pbxproj b/Calq.xcodeproj/project.pbxproj index 4c829d3..ae225b1 100644 --- a/Calq.xcodeproj/project.pbxproj +++ b/Calq.xcodeproj/project.pbxproj @@ -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 */ @@ -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 */, diff --git a/CalqWidget/CalqWidget.swift b/CalqWidget/CalqWidget.swift index 9eb4add..7c7f173 100644 --- a/CalqWidget/CalqWidget.swift +++ b/CalqWidget/CalqWidget.swift @@ -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" @@ -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 { @@ -73,6 +101,7 @@ struct CalqWidgetBundle: WidgetBundle { var body: some Widget{ CalqWidget() BarChartWidget() + lineWidget() } } @@ -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") } } diff --git a/CalqWidget/MediumBarChart.swift b/CalqWidget/MediumBarChart.swift index 537eb74..aa5699b 100644 --- a/CalqWidget/MediumBarChart.swift +++ b/CalqWidget/MediumBarChart.swift @@ -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 @@ -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() } }