comparison Sources/InteractiveCharts/LineChart/Helpers/LinePath.swift @ 18:136de51a74f2

Change struct to public
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 28 Apr 2021 20:05:00 +0200
parents edf2bfcd8d97
children
comparison
equal deleted inserted replaced
17:c0c129bdf65d 18:136de51a74f2
5 // Created by Dennis Concepción Martín on 26/4/21. 5 // Created by Dennis Concepción Martín on 26/4/21.
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct LinePath: Shape { 10 public struct LinePath: Shape {
11 var data: [Double] 11 var data: [Double]
12 var (width, height): (CGFloat, CGFloat) 12 var (width, height): (CGFloat, CGFloat)
13 @Binding var pathPoints: [CGPoint] 13 @Binding var pathPoints: [CGPoint]
14 14
15 func path(in rect: CGRect) -> Path { 15 public func path(in rect: CGRect) -> Path {
16 var path = Path() 16 var path = Path()
17 17
18 let normalizedData = normalize(data) 18 let normalizedData = normalize(data)
19 let widthBetweenDataPoints = Double(width) / Double(normalizedData.count - 1) // Remove first point 19 let widthBetweenDataPoints = Double(width) / Double(normalizedData.count - 1) // Remove first point
20 let initialPoint = normalizedData[0] * Double(height) 20 let initialPoint = normalizedData[0] * Double(height)
36 } 36 }
37 37
38 /* 38 /*
39 Get data -> normalize it -> 0 <= output <= 1 39 Get data -> normalize it -> 0 <= output <= 1
40 */ 40 */
41 func normalize(_ data: [Double]) -> [Double] { 41 public func normalize(_ data: [Double]) -> [Double] {
42 var normalData = [Double]() 42 var normalData = [Double]()
43 let min = data.min()! 43 let min = data.min()!
44 let max = data.max()! 44 let max = data.max()!
45 45
46 for value in data { 46 for value in data {