Skip to content

Commit 4a816c2

Browse files
committed
cleaned up chart selection with a function
1 parent e52f4f5 commit 4a816c2

2 files changed

Lines changed: 28 additions & 31 deletions

File tree

Infini-iOS/View Components/Chart View Components/BatteryChart.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,30 @@ struct BatteryChart: View {
2626
}
2727
}
2828

29+
func setGraphType(data: LineChartData) -> some View {
30+
if batChartFill {
31+
return AnyView(FilledLineChart(chartData: data))
32+
} else {
33+
return AnyView(LineChart(chartData: data))
34+
}
35+
}
2936

3037
var body: some View {
3138
let chartStyle = LineChartStyle(infoBoxPlacement: .floating, baseline: .minimumWithMaximum(of: 0), topLine: .maximum(of: 100))
3239
let data = LineChartData(dataSets: LineDataSet(
3340
dataPoints: ChartManager.shared.convert(results: chartPoints),
3441
style: setLineStyle()),
42+
metadata: ChartMetadata(title: " ", subtitle: " "),
3543
chartStyle: chartStyle
3644
)
3745

3846
if chartPoints.count > 1 {
39-
if batChartFill {
40-
FilledLineChart(chartData: data)
41-
.animation(.easeIn)
42-
.floatingInfoBox(chartData: data)
43-
.touchOverlay(chartData: data, unit: .suffix(of: "%"))
44-
.yAxisLabels(chartData: data)
45-
.padding()
46-
} else {
47-
LineChart(chartData: data)
48-
.animation(.easeIn)
49-
.floatingInfoBox(chartData: data)
50-
.touchOverlay(chartData: data, unit: .suffix(of: "%"))
51-
.yAxisLabels(chartData: data)
52-
.padding()
53-
}
47+
setGraphType(data: data)
48+
.animation(.easeIn)
49+
.floatingInfoBox(chartData: data)
50+
.touchOverlay(chartData: data, unit: .suffix(of: "%"))
51+
.yAxisLabels(chartData: data)
52+
.padding()
5453
} else {
5554
VStack (alignment: .center) {
5655
Spacer()

Infini-iOS/View Components/Chart View Components/HeartChart.swift

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ struct HeartChart: View {
2929
}
3030
}
3131

32+
func setGraphType(data: LineChartData) -> some View {
33+
if heartChartFill {
34+
return AnyView(FilledLineChart(chartData: data))
35+
} else {
36+
return AnyView(LineChart(chartData: data))
37+
}
38+
}
3239

3340
var body: some View {
3441
let chartStyle = LineChartStyle(infoBoxPlacement: .floating, baseline: .minimumWithMaximum(of: 50), topLine: .maximum(of: 160))
@@ -39,22 +46,13 @@ struct HeartChart: View {
3946
)
4047

4148
if chartPoints.count > 1 {
42-
if heartChartFill {
43-
FilledLineChart(chartData: data)
44-
.animation(.easeIn)
45-
.floatingInfoBox(chartData: data)
46-
.touchOverlay(chartData: data, unit: .suffix(of: "BPM"))
47-
.yAxisLabels(chartData: data)
48-
.padding()
49-
50-
} else {
51-
LineChart(chartData: data)
52-
.animation(.easeIn)
53-
.floatingInfoBox(chartData: data)
54-
.touchOverlay(chartData: data, unit: .suffix(of: "BPM"))
55-
.yAxisLabels(chartData: data)
56-
.padding()
57-
}
49+
setGraphType(data: data)
50+
.animation(.easeIn)
51+
.floatingInfoBox(chartData: data)
52+
.touchOverlay(chartData: data, unit: .suffix(of: "BPM"))
53+
.yAxisLabels(chartData: data)
54+
.xAxisLabels(chartData: data)
55+
.padding()
5856
} else {
5957
VStack (alignment: .center) {
6058
Spacer()

0 commit comments

Comments
 (0)