Skip to content

Commit

Permalink
feat: add animation toggle interface (#256)
Browse files Browse the repository at this point in the history
Co-authored-by: “Andras <“andras.samu@supercharge.io”>
  • Loading branch information
AppPear and “Andras committed Nov 26, 2022
1 parent 7fd5b18 commit 7140b8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ extension LineChart {
self.chartProperties.lineStyle = style
return self
}

public func withAnimation(_ enabled: Bool) -> LineChart {
self.chartProperties.animationEnabled = enabled
return self
}
}
42 changes: 19 additions & 23 deletions Sources/SwiftUICharts/Charts/LineChart/Line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,32 @@ 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
}
.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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 7140b8b

Please sign in to comment.