changeset 180:0df6396f7e28

Test charts
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 21 Feb 2021 17:38:49 +0100
parents 46299426d953
children 9533f6a60531
files LazyBear/Functions/Normalize.swift LazyBear/Tests/ChartTests.swift
diffstat 2 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear/Functions/Normalize.swift	Sun Feb 21 17:38:41 2021 +0100
+++ b/LazyBear/Functions/Normalize.swift	Sun Feb 21 17:38:49 2021 +0100
@@ -5,16 +5,17 @@
 //  Created by Dennis Concepción Martín on 20/2/21.
 //
 
-import SwiftUI
+import Foundation
 
-struct Normalize: View {
-    var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+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
 }
-
-struct Normalize_Previews: PreviewProvider {
-    static var previews: some View {
-        Normalize()
-    }
-}
--- a/LazyBear/Tests/ChartTests.swift	Sun Feb 21 17:38:41 2021 +0100
+++ b/LazyBear/Tests/ChartTests.swift	Sun Feb 21 17:38:49 2021 +0100
@@ -6,10 +6,17 @@
 //
 
 import SwiftUI
+import Charts
 
 struct ChartTests: View {
     var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+        let someData: [Double] = [50.0, 49.1, 1.4, 120.4, 523.30]
+        Chart(data: normalize(someData))
+            .chartStyle(
+                AreaChartStyle(.quadCurve, fill:
+                    LinearGradient(gradient: .init(colors: [Color.blue.opacity(0.2), Color.blue.opacity(0.05)]), startPoint: .top, endPoint: .bottom)
+                )
+            )
     }
 }