Skip to content

Commit 7140b8b

Browse files
AppPear“Andras
andauthored
feat: add animation toggle interface (#256)
Co-authored-by: “Andras <“[email protected]”>
1 parent 7fd5b18 commit 7140b8b

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

Sources/SwiftUICharts/Charts/LineChart/Extension/LineChart+Extension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ extension LineChart {
2121
self.chartProperties.lineStyle = style
2222
return self
2323
}
24+
25+
public func withAnimation(_ enabled: Bool) -> LineChart {
26+
self.chartProperties.animationEnabled = enabled
27+
return self
28+
}
2429
}

Sources/SwiftUICharts/Charts/LineChart/Line.swift

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,32 @@ public struct Line: View {
3333
geometry: geometry,
3434
backgroundColor: backgroundColor)
3535
}
36-
LineShapeView(chartData: chartData,
37-
chartProperties: chartProperties,
38-
geometry: geometry,
39-
style: style,
40-
trimTo: didCellAppear ? 1.0 : 0.0)
41-
.animation(Animation.easeIn(duration: 0.75))
42-
if self.showIndicator {
43-
IndicatorPoint()
44-
.position(self.getClosestPointOnPath(geometry: geometry,
45-
touchLocation: self.touchLocation))
46-
.toStandardCoordinateSystem()
47-
}
36+
lineShapeView(geometry: geometry)
4837
}
4938
.onAppear {
5039
didCellAppear = true
5140
}
5241
.onDisappear() {
5342
didCellAppear = false
5443
}
55-
// .gesture(DragGesture()
56-
// .onChanged({ value in
57-
// self.touchLocation = value.location
58-
// self.showIndicator = true
59-
// self.getClosestDataPoint(geometry: geometry, touchLocation: value.location)
60-
// })
61-
// .onEnded({ value in
62-
// self.touchLocation = .zero
63-
// self.showIndicator = false
64-
// })
65-
// )
44+
}
45+
}
46+
47+
@ViewBuilder
48+
private func lineShapeView(geometry: GeometryProxy) -> some View {
49+
if chartProperties.animationEnabled {
50+
LineShapeView(chartData: chartData,
51+
chartProperties: chartProperties,
52+
geometry: geometry,
53+
style: style,
54+
trimTo: didCellAppear ? 1.0 : 0.0)
55+
.animation(Animation.easeIn(duration: 0.75))
56+
} else {
57+
LineShapeView(chartData: chartData,
58+
chartProperties: chartProperties,
59+
geometry: geometry,
60+
style: style,
61+
trimTo: 1.0)
6662
}
6763
}
6864
}

Sources/SwiftUICharts/Charts/LineChart/Model/LineChartProperties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class LineChartProperties: ObservableObject {
66
@Published var showChartMarks: Bool = true
77
@Published var customChartMarksColors: ColorGradient?
88
@Published var lineStyle: LineStyle = .curved
9-
9+
@Published var animationEnabled: Bool = true
1010
public init() {
1111
// no-op
1212
}

0 commit comments

Comments
 (0)