diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/InteractiveCharts/LineChart/Helpers/LineView.swift	Mon Apr 26 19:02:46 2021 +0200
@@ -0,0 +1,36 @@
+//
+//  LineView.swift
+//  InteractiveCharts
+//
+//  Created by Dennis Concepción Martín on 26/4/21.
+//
+
+import SwiftUI
+
+struct LineView: View {
+    var data: [Double]
+    
+    var body: some View {
+        GeometryReader { proxy in
+            LinePath(data: data, width: proxy.size.width, height: proxy.size.height)
+                .stroke(colorLine(), lineWidth: 2)
+                .rotationEffect(.degrees(180), anchor: .center)
+                .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0))
+        }
+    }
+    
+    /*
+     Color path depending on data.
+     */
+    private func colorLine() -> Color {
+        var color = Color(.systemGreen)
+        
+        if data.first! > data.last! {
+            color = Color(.systemRed)
+        } else if data.first! == data.last! {
+            color = Color(.systemTeal)
+        }
+        
+        return color
+    }
+}