changeset 270:350d33e2cc2d

Add Tests chart
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 14 Mar 2021 13:25:09 +0100
parents 1836c369cbc4
children e1610b54015d
files LazyBear/Tests/DemoChart.swift
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear/Tests/DemoChart.swift	Sun Mar 14 13:25:02 2021 +0100
+++ b/LazyBear/Tests/DemoChart.swift	Sun Mar 14 13:25:09 2021 +0100
@@ -8,8 +8,31 @@
 import SwiftUI
 
 struct DemoChart: View {
+    let sampleData: [Double] = [10, 11.2, 13.4, 10.2, 13.4, 12.4, 15.6, 18.7, 20.9, 21.2, 10.3]
+
     var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+        let normalizedData = normalize(sampleData)
+        Path { path in
+            path.move(to: CGPoint(x: 0, y: 0))
+            for point in normalizedData {
+                path.addLine(to: CGPoint(x: 1, y: point))
+            }
+            
+        }
+        .fill(Color.green)
+    }
+    
+    func normalize(_ data: [Double]) -> [Double] {
+        var normalData = [Double]()
+        let min = data.min()!
+        let max = data.max()!
+        
+        for value in data {
+            let normal = (value - min) / (max - min)
+            normalData.append(normal)
+        }
+        
+        return normalData
     }
 }