diff --git a/Sources/SwiftUICharts/Charts/LineChart/Extension/LineChart+Extension.swift b/Sources/SwiftUICharts/Charts/LineChart/Extension/LineChart+Extension.swift index 1b2c30b4..03920e1e 100644 --- a/Sources/SwiftUICharts/Charts/LineChart/Extension/LineChart+Extension.swift +++ b/Sources/SwiftUICharts/Charts/LineChart/Extension/LineChart+Extension.swift @@ -21,4 +21,9 @@ extension LineChart { self.chartProperties.lineStyle = style return self } + + public func withAnimation(_ enabled: Bool) -> LineChart { + self.chartProperties.animationEnabled = enabled + return self + } } diff --git a/Sources/SwiftUICharts/Charts/LineChart/Line.swift b/Sources/SwiftUICharts/Charts/LineChart/Line.swift index ca2b7cfc..2e2fc214 100644 --- a/Sources/SwiftUICharts/Charts/LineChart/Line.swift +++ b/Sources/SwiftUICharts/Charts/LineChart/Line.swift @@ -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) } } } diff --git a/Sources/SwiftUICharts/Charts/LineChart/Model/LineChartProperties.swift b/Sources/SwiftUICharts/Charts/LineChart/Model/LineChartProperties.swift index 59cc9060..24893be2 100644 --- a/Sources/SwiftUICharts/Charts/LineChart/Model/LineChartProperties.swift +++ b/Sources/SwiftUICharts/Charts/LineChart/Model/LineChartProperties.swift @@ -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 }