feat(Turnips): Chart - add fancy animation for minMax curves
MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/turnips/TurnipsView.swift
ACHNBrowserUI/ACHNBrowserUI/views/turnips/TurnipsView.swift
@@ -23,6 +23,11 @@ struct TurnipsView: View {
case .chart: return "Chart"
}
}
+
+ var isChart: Bool {
+ get { self == .chart }
+ set { }
+ }
}
private enum Sheet: String, Identifiable {
@@ -174,7 +179,10 @@ extension TurnipsView {
}
} else if turnipsDisplay == .chart {
if viewModel.predictions != nil {
- TurnipsChartView(predictions: viewModel.predictions!).padding(.top, 8)
+ TurnipsChartView(
+ predictions: viewModel.predictions!,
+ animateCurves: $turnipsDisplay.isChart
+ ).padding(.top, 8)
} else {
Text("Add your in game turnip prices to see the predictions chart")
.foregroundColor(.bell)

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartMinMaxCurves.swift
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartMinMaxCurves.swift
@@ -11,6 +11,12 @@ import Backend
struct TurnipsChartMinMaxCurves: Shape {
let predictions: TurnipPredictions
+ var animationStep: CGFloat = 1
+
+ var animatableData: CGFloat {
+ get { animationStep }
+ set { animationStep = newValue }
+ }
func path(in rect: CGRect) -> Path {
var path = Path()
@@ -26,7 +32,7 @@ struct TurnipsChartMinMaxCurves: Shape {
.enumerated()
.map({ offset, minValue in
let x = ratioX * CGFloat(offset)
- let y = ratioY * (maxY - CGFloat(minValue))
+ let y = ratioY * (maxY - CGFloat(minValue) * animationStep)
return CGPoint(x: x, y: y)
})
path.addHermiteCurvedLines(points: minPoints)
@@ -36,7 +42,7 @@ struct TurnipsChartMinMaxCurves: Shape {
.enumerated()
.map({ offset, maxValue in
let x = ratioX * CGFloat(offset)
- let y = ratioY * (maxY - CGFloat(maxValue))
+ let y = ratioY * (maxY - CGFloat(maxValue) * animationStep)
return CGPoint(x: x, y: y)
})
.reversed()
@@ -47,3 +53,26 @@ struct TurnipsChartMinMaxCurves: Shape {
return path
}
}
+
+struct TurnipsChartMinMaxCurves_Previews: PreviewProvider {
+ static var previews: some View {
+ Preview().padding()
+ }
+
+ private struct Preview: View {
+ @State private var animationStep: CGFloat = 1
+
+ var body: some View {
+ VStack {
+ TurnipsChartMinMaxCurves(
+ predictions: TurnipsChartView_Previews.predictions,
+ animationStep: animationStep
+ )
+ .foregroundColor(TurnipsChart.PredictionCurve.minMax.color)
+ .opacity(0.25)
+ .blendMode(.darken)
+ Slider(value: $animationStep, in: 0.1...1)
+ }
+ }
+ }
+}

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartView.swift
ACHNBrowserUI/ACHNBrowserUI/views/turnips/charts/TurnipsChartView.swift
@@ -13,6 +13,7 @@ struct TurnipsChartView: View {
typealias PredictionCurve = TurnipsChart.PredictionCurve
static let verticalLinesCount: CGFloat = 9
var predictions: TurnipPredictions
+ @Binding var animateCurves: Bool
@Environment(\.presentationMode) var presentation
var body: some View {
@@ -47,7 +48,7 @@ struct TurnipsChartView: View {
.foregroundColor(PredictionCurve.minBuyPrice.color)
.saturation(3)
.blendMode(.screen)
- TurnipsChartMinMaxCurves(predictions: predictions)
+ TurnipsChartMinMaxCurves(predictions: predictions, animationStep: animateCurves ? 1 : 0.1)
.foregroundColor(PredictionCurve.minMax.color)
.opacity(0.25)
.blendMode(.darken)
@@ -56,19 +57,24 @@ struct TurnipsChartView: View {
.foregroundColor(PredictionCurve.average.color)
.saturation(5)
.blendMode(.screen)
- }
+ }.animation(.spring())
}
}
struct TurnipsChartView_Previews: PreviewProvider {
static var previews: some View {
- TurnipsChartView(predictions: TurnipPredictions(
+ TurnipsChartView(
+ predictions: predictions,
+ animateCurves: .constant(true)
+ ).padding()
+ }
+
+ static let predictions = TurnipPredictions(
minBuyPrice: 83,
averagePrices: averagePrices,
minMax: minMax,
averageProfits: averageProfits
- )).padding()
- }
+ )
static let averagePrices = [89, 85, 88, 104, 110, 111, 111, 111, 106, 98, 82, 77]

feat(Turnips): Chart - add fancy animation for minMax curves