Mercurial > public > stock-charts
comparison InteractiveCharts/LineChart/Helpers/LineView.swift @ 5:f828c7c408d4
Add source code
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Mon, 26 Apr 2021 19:02:46 +0200 |
parents | |
children | 959175ee5ebd |
comparison
equal
deleted
inserted
replaced
4:fd3fb56afc53 | 5:f828c7c408d4 |
---|---|
1 // | |
2 // LineView.swift | |
3 // InteractiveCharts | |
4 // | |
5 // Created by Dennis Concepción Martín on 26/4/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct LineView: View { | |
11 var data: [Double] | |
12 | |
13 var body: some View { | |
14 GeometryReader { proxy in | |
15 LinePath(data: data, width: proxy.size.width, height: proxy.size.height) | |
16 .stroke(colorLine(), lineWidth: 2) | |
17 .rotationEffect(.degrees(180), anchor: .center) | |
18 .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0)) | |
19 } | |
20 } | |
21 | |
22 /* | |
23 Color path depending on data. | |
24 */ | |
25 private func colorLine() -> Color { | |
26 var color = Color(.systemGreen) | |
27 | |
28 if data.first! > data.last! { | |
29 color = Color(.systemRed) | |
30 } else if data.first! == data.last! { | |
31 color = Color(.systemTeal) | |
32 } | |
33 | |
34 return color | |
35 } | |
36 } |