diff --git a/Sources/SwiftUICharts/Base/Animatable/AnimatableVector.swift b/Sources/SwiftUICharts/Base/Animatable/AnimatableVector.swift new file mode 100644 index 00000000..e43ab719 --- /dev/null +++ b/Sources/SwiftUICharts/Base/Animatable/AnimatableVector.swift @@ -0,0 +1,36 @@ +import SwiftUI +import enum Accelerate.vDSP + +struct AnimatableVector: VectorArithmetic { + static var zero = AnimatableVector(values: [0.0]) + + static func + (lhs: AnimatableVector, rhs: AnimatableVector) -> AnimatableVector { + let count = min(lhs.values.count, rhs.values.count) + return AnimatableVector(values: vDSP.add(lhs.values[0.. AnimatableVector { + let count = min(lhs.values.count, rhs.values.count) + return AnimatableVector(values: vDSP.subtract(lhs.values[0.. Path { let path = Path.quadClosedCurvedPathWithPoints(points: data, step: CGPoint(x: 1.0, y: 1.0)) return path diff --git a/Sources/SwiftUICharts/Charts/LineChart/LineShape.swift b/Sources/SwiftUICharts/Charts/LineChart/LineShape.swift index 64fff658..72c08ee8 100644 --- a/Sources/SwiftUICharts/Charts/LineChart/LineShape.swift +++ b/Sources/SwiftUICharts/Charts/LineChart/LineShape.swift @@ -1,7 +1,13 @@ import SwiftUI -struct LineShape: Shape { +struct LineShape: Shape, Animatable { var data: [Double] + + var animatableData: AnimatableVector { + get { AnimatableVector(values: data) } + set { data = newValue.values } + } + func path(in rect: CGRect) -> Path { let path = Path.quadCurvedPathWithPoints(points: data, step: CGPoint(x: 1.0, y: 1.0)) return path