feat: add animation toggle interface
This commit is contained in:
@@ -21,4 +21,9 @@ extension LineChart {
|
||||
self.chartProperties.lineStyle = style
|
||||
return self
|
||||
}
|
||||
|
||||
public func withAnimation(_ enabled: Bool) -> LineChart {
|
||||
self.chartProperties.animationEnabled = enabled
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,18 +33,7 @@ public struct Line: View {
|
||||
geometry: geometry,
|
||||
backgroundColor: backgroundColor)
|
||||
}
|
||||
LineShapeView(chartData: chartData,
|
||||
chartProperties: chartProperties,
|
||||
geometry: geometry,
|
||||
style: style,
|
||||
trimTo: didCellAppear ? 1.0 : 0.0)
|
||||
.animation(Animation.easeIn(duration: 0.75))
|
||||
if self.showIndicator {
|
||||
IndicatorPoint()
|
||||
.position(self.getClosestPointOnPath(geometry: geometry,
|
||||
touchLocation: self.touchLocation))
|
||||
.toStandardCoordinateSystem()
|
||||
}
|
||||
lineShapeView(geometry: geometry)
|
||||
}
|
||||
.onAppear {
|
||||
didCellAppear = true
|
||||
@@ -52,17 +41,24 @@ public struct Line: View {
|
||||
.onDisappear() {
|
||||
didCellAppear = false
|
||||
}
|
||||
// .gesture(DragGesture()
|
||||
// .onChanged({ value in
|
||||
// self.touchLocation = value.location
|
||||
// self.showIndicator = true
|
||||
// self.getClosestDataPoint(geometry: geometry, touchLocation: value.location)
|
||||
// })
|
||||
// .onEnded({ value in
|
||||
// self.touchLocation = .zero
|
||||
// self.showIndicator = false
|
||||
// })
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func lineShapeView(geometry: GeometryProxy) -> some View {
|
||||
if chartProperties.animationEnabled {
|
||||
LineShapeView(chartData: chartData,
|
||||
chartProperties: chartProperties,
|
||||
geometry: geometry,
|
||||
style: style,
|
||||
trimTo: didCellAppear ? 1.0 : 0.0)
|
||||
.animation(Animation.easeIn(duration: 0.75))
|
||||
} else {
|
||||
LineShapeView(chartData: chartData,
|
||||
chartProperties: chartProperties,
|
||||
geometry: geometry,
|
||||
style: style,
|
||||
trimTo: 1.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ public class LineChartProperties: ObservableObject {
|
||||
@Published var showChartMarks: Bool = true
|
||||
@Published var customChartMarksColors: ColorGradient?
|
||||
@Published var lineStyle: LineStyle = .curved
|
||||
|
||||
@Published var animationEnabled: Bool = true
|
||||
public init() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user