comparison Sources/StockCharts/LineChart/Helpers/LineView.swift @ 116:5057c45046c1

Add default initializers
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Mon, 09 Aug 2021 16:32:45 +0100
parents f53d8b9ca92b
children
comparison
equal deleted inserted replaced
115:f90a675e5e95 116:5057c45046c1
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 public struct LineView: View { 10 public struct LineView: View {
11 public var data: [Double] 11 public var lineChartController: LineChartController
12 public var dates: [String]?
13 public var hours: [String]?
14 public var dragGesture: Bool?
15 public var style: LineChartStyle
16 12
17 @Binding var showingIndicators: Bool 13 @Binding var showingIndicators: Bool
18 @Binding var indexPosition: Int 14 @Binding var indexPosition: Int
19 @State var IndicatorPointPosition: CGPoint = .zero 15 @State var IndicatorPointPosition: CGPoint = .zero
20 @State var pathPoints = [CGPoint]() 16 @State var pathPoints = [CGPoint]()
21 17
22 public var body: some View { 18 public var body: some View {
23 ZStack { 19 ZStack {
24 GeometryReader { proxy in 20 GeometryReader { proxy in
25 LinePath(data: data, width: proxy.size.width, height: proxy.size.height, pathPoints: $pathPoints) 21 LinePath(data: lineChartController.prices, width: proxy.size.width, height: proxy.size.height, pathPoints: $pathPoints)
26 .stroke(colorLine(), lineWidth: 2) 22 .stroke(colorLine(), lineWidth: 2)
27 } 23 }
28 24
29 if showingIndicators { 25 if showingIndicators {
30 IndicatorPoint(style: style) 26 IndicatorPoint(lineChartController: lineChartController)
31 .position(x: IndicatorPointPosition.x, y: IndicatorPointPosition.y) 27 .position(x: IndicatorPointPosition.x, y: IndicatorPointPosition.y)
32 } 28 }
33 } 29 }
34 .rotationEffect(.degrees(180), anchor: .center) 30 .rotationEffect(.degrees(180), anchor: .center)
35 .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0)) 31 .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0))
36 .contentShape(Rectangle()) // Control tappable area 32 .contentShape(Rectangle()) // Control tappable area
37 .gesture(dragGesture ?? true ? 33 .gesture(lineChartController.dragGesture ?
38 LongPressGesture(minimumDuration: 0.2) 34 LongPressGesture(minimumDuration: 0.2)
39 .sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .local)) 35 .sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .local))
40 .onChanged({ value in // Get value of the gesture 36 .onChanged({ value in // Get value of the gesture
41 switch value { 37 switch value {
42 case .second(true, let drag): 38 case .second(true, let drag):
57 53
58 /* 54 /*
59 Color path depending on data. 55 Color path depending on data.
60 */ 56 */
61 public func colorLine() -> Color { 57 public func colorLine() -> Color {
62 var color = style.uptrendLineColor 58 var color = lineChartController.uptrendLineColor
63 59
64 if showingIndicators { 60 if showingIndicators {
65 color = style.showingIndicatorLineColor 61 color = lineChartController.showingIndicatorLineColor
66 } else if data.first! > data.last! { 62 } else if lineChartController.prices.first! > lineChartController.prices.last! {
67 color = style.downtrendLineColor 63 color = lineChartController.downtrendLineColor
68 } else if data.first! == data.last! { 64 } else if lineChartController.prices.first! == lineChartController.prices.last! {
69 color = style.flatTrendLineColor 65 color = lineChartController.flatTrendLineColor
70 } 66 }
71 67
72 return color 68 return color
73 } 69 }
74 70