@@ -16,7 +16,10 @@ public struct LineView: View {
1616 public var darkModeStyle : ChartStyle
1717 public var valueSpecifier : String
1818 public var legendSpecifier : String
19-
19+ public var xAxisData : [ CustomStringConvertible ] ?
20+
21+
22+
2023 @Environment ( \. colorScheme) var colorScheme : ColorScheme
2124 @State private var showLegend = false
2225 @State private var dragLocation : CGPoint = . zero
@@ -31,7 +34,9 @@ public struct LineView: View {
3134 legend: String ? = nil ,
3235 style: ChartStyle = Styles . lineChartStyleOne,
3336 valueSpecifier: String ? = " %.1f " ,
34- legendSpecifier: String ? = " %.2f " ) {
37+ legendSpecifier: String ? = " %.2f " ,
38+ xAxisData: [ CustomStringConvertible ] ? = nil ,
39+ ) {
3540
3641 self . data = ChartData ( points: data)
3742 self . title = title
@@ -40,6 +45,7 @@ public struct LineView: View {
4045 self . valueSpecifier = valueSpecifier!
4146 self . legendSpecifier = legendSpecifier!
4247 self . darkModeStyle = style. darkModeStyle != nil ? style. darkModeStyle! : Styles . lineViewDarkMode
48+ self . xAxisData = xAxisData
4349 }
4450
4551 public var body : some View {
@@ -86,7 +92,8 @@ public struct LineView: View {
8692 }
8793 . frame ( width: geometry. frame ( in: . local) . size. width, height: 240 )
8894 . offset ( x: 0 , y: 40 )
89- MagnifierRect ( currentNumber: self . $currentDataNumber, valueSpecifier: self . valueSpecifier)
95+ // MagnifierRect(currentNumber: self.$currentDataNumber, valueSpecifier: self.valueSpecifier)
96+ MagnifierRect ( currentNumber: self . $currentDataNumber, currentXValue: self . $currentXValue, valueSpecifier: self . valueSpecifier)
9097 . opacity ( self . opacity)
9198 . offset ( x: self . dragLocation. x - geometry. frame ( in: . local) . size. width/ 2 , y: 36 )
9299 }
@@ -116,6 +123,11 @@ public struct LineView: View {
116123 let index : Int = Int ( floor ( ( toPoint. x- 15 ) / stepWidth) )
117124 if ( index >= 0 && index < points. count) {
118125 self . currentDataNumber = points [ index]
126+ if let xAxisData = xAxisData,
127+ ( index >= 0 && index < xAxisData. count)
128+ {
129+ self . currentXValue = xAxisData [ index]
130+ }
119131 return CGPoint ( x: CGFloat ( index) * stepWidth, y: CGFloat ( points [ index] ) * stepHeight)
120132 }
121133 return . zero
0 commit comments