comparison Sources/InteractiveCharts/LineChart/Helpers/LineView.swift @ 20:24dfde3727c1 v0.2-alpha

Make variables and structures public
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 28 Apr 2021 20:24:54 +0200
parents 136de51a74f2
children
comparison
equal deleted inserted replaced
19:647d3a64ca3f 20:24dfde3727c1
12 var dates: [String]? 12 var dates: [String]?
13 var hours: [String]? 13 var hours: [String]?
14 14
15 @Binding var showingIndicators: Bool 15 @Binding var showingIndicators: Bool
16 @Binding var indexPosition: Int 16 @Binding var indexPosition: Int
17 @State private var IndicatorPointPosition: CGPoint = .zero 17 @State var IndicatorPointPosition: CGPoint = .zero
18 @State private var pathPoints = [CGPoint]() 18 @State var pathPoints = [CGPoint]()
19 19
20 public var body: some View { 20 public var body: some View {
21 ZStack { 21 ZStack {
22 GeometryReader { proxy in 22 GeometryReader { proxy in
23 LinePath(data: data, width: proxy.size.width, height: proxy.size.height, pathPoints: $pathPoints) 23 LinePath(data: data, width: proxy.size.width, height: proxy.size.height, pathPoints: $pathPoints)
53 } 53 }
54 54
55 /* 55 /*
56 Color path depending on data. 56 Color path depending on data.
57 */ 57 */
58 private func colorLine() -> Color { 58 public func colorLine() -> Color {
59 var color = Color(.systemGreen) 59 var color = Color(.systemGreen)
60 60
61 if data.first! > data.last! { 61 if data.first! > data.last! {
62 color = Color(.systemRed) 62 color = Color(.systemRed)
63 } else if data.first! == data.last! { 63 } else if data.first! == data.last! {
71 } 71 }
72 72
73 /* 73 /*
74 When the user drag on Path -> Modifiy indicator point to move it on the path accordingly 74 When the user drag on Path -> Modifiy indicator point to move it on the path accordingly
75 */ 75 */
76 private func dragGesture(_ longPressLocation: CGPoint) { 76 public func dragGesture(_ longPressLocation: CGPoint) {
77 let (closestXPoint, closestYPoint, yPointIndex) = getClosestValueFrom(longPressLocation, inData: pathPoints) 77 let (closestXPoint, closestYPoint, yPointIndex) = getClosestValueFrom(longPressLocation, inData: pathPoints)
78 self.IndicatorPointPosition.x = closestXPoint 78 self.IndicatorPointPosition.x = closestXPoint
79 self.IndicatorPointPosition.y = closestYPoint 79 self.IndicatorPointPosition.y = closestYPoint
80 self.showingIndicators = true 80 self.showingIndicators = true
81 self.indexPosition = yPointIndex 81 self.indexPosition = yPointIndex
83 83
84 /* 84 /*
85 First, search the closest X point in Path from the tapped location. 85 First, search the closest X point in Path from the tapped location.
86 Then, find the correspondent Y point in Path. 86 Then, find the correspondent Y point in Path.
87 */ 87 */
88 private func getClosestValueFrom(_ value: CGPoint, inData: [CGPoint]) -> (CGFloat, CGFloat, Int) { 88 public func getClosestValueFrom(_ value: CGPoint, inData: [CGPoint]) -> (CGFloat, CGFloat, Int) {
89 let touchPoint: (CGFloat, CGFloat) = (value.x, value.y) 89 let touchPoint: (CGFloat, CGFloat) = (value.x, value.y)
90 let xPathPoints = inData.map { $0.x } 90 let xPathPoints = inData.map { $0.x }
91 let yPathPoints = inData.map { $0.y } 91 let yPathPoints = inData.map { $0.y }
92 92
93 // Closest X value 93 // Closest X value