Mercurial > public > stock-charts
comparison Sources/StockCharts/LineChart/Helpers/LineView.swift @ 108:f53d8b9ca92b
Custom style implemented
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sun, 04 Jul 2021 16:40:24 +0100 |
parents | 0c0d38dca6d8 |
children | 5057c45046c1 |
comparison
equal
deleted
inserted
replaced
107:b0c81b2e624d | 108:f53d8b9ca92b |
---|---|
10 public struct LineView: View { | 10 public struct LineView: View { |
11 public var data: [Double] | 11 public var data: [Double] |
12 public var dates: [String]? | 12 public var dates: [String]? |
13 public var hours: [String]? | 13 public var hours: [String]? |
14 public var dragGesture: Bool? | 14 public var dragGesture: Bool? |
15 public var style: LineChartStyle | |
15 | 16 |
16 @Binding var showingIndicators: Bool | 17 @Binding var showingIndicators: Bool |
17 @Binding var indexPosition: Int | 18 @Binding var indexPosition: Int |
18 @State var IndicatorPointPosition: CGPoint = .zero | 19 @State var IndicatorPointPosition: CGPoint = .zero |
19 @State var pathPoints = [CGPoint]() | 20 @State var pathPoints = [CGPoint]() |
24 LinePath(data: data, width: proxy.size.width, height: proxy.size.height, pathPoints: $pathPoints) | 25 LinePath(data: data, width: proxy.size.width, height: proxy.size.height, pathPoints: $pathPoints) |
25 .stroke(colorLine(), lineWidth: 2) | 26 .stroke(colorLine(), lineWidth: 2) |
26 } | 27 } |
27 | 28 |
28 if showingIndicators { | 29 if showingIndicators { |
29 IndicatorPoint() | 30 IndicatorPoint(style: style) |
30 .position(x: IndicatorPointPosition.x, y: IndicatorPointPosition.y) | 31 .position(x: IndicatorPointPosition.x, y: IndicatorPointPosition.y) |
31 } | 32 } |
32 } | 33 } |
33 .rotationEffect(.degrees(180), anchor: .center) | 34 .rotationEffect(.degrees(180), anchor: .center) |
34 .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0)) | 35 .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0)) |
56 | 57 |
57 /* | 58 /* |
58 Color path depending on data. | 59 Color path depending on data. |
59 */ | 60 */ |
60 public func colorLine() -> Color { | 61 public func colorLine() -> Color { |
61 var color = Color.green | 62 var color = style.uptrendLineColor |
62 | 63 |
63 if showingIndicators { | 64 if showingIndicators { |
64 color = Color.blue | 65 color = style.showingIndicatorLineColor |
65 } else if data.first! > data.last! { | 66 } else if data.first! > data.last! { |
66 color = Color.red | 67 color = style.downtrendLineColor |
67 } else if data.first! == data.last! { | 68 } else if data.first! == data.last! { |
68 color = Color.blue | 69 color = style.flatTrendLineColor |
69 } | 70 } |
70 | 71 |
71 return color | 72 return color |
72 } | 73 } |
73 | 74 |