Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed appearing animation
  • Loading branch information
AppPear committed Jun 21, 2020
commit 73331b76c4be3bd34c7518459c7f60447b77c8be
20 changes: 12 additions & 8 deletions Sources/SwiftUICharts/Charts/BarChart/BarChartCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct BarChartCell: View {
return Double(width)/(Double(numberOfDataPoints) * 1.5)
}

@State var scaleValue: Double = 0
@State var firstDisplay: Bool = true

public init( value: Double,
index: Int = 0,
Expand All @@ -32,13 +32,17 @@ public struct BarChartCell: View {
ZStack {
RoundedRectangle(cornerRadius: 4)
.fill(gradientColor.linearGradient(from: .bottom, to: .top))
}
.frame(width: CGFloat(self.cellWidth))
.scaleEffect(CGSize(width: 1, height: self.value), anchor: .bottom)
.onAppear {
self.scaleValue = self.value
}
.animation(Animation.spring().delay(self.touchLocation < 0 ? Double(self.index) * 0.04 : 0))
}
.frame(width: CGFloat(self.cellWidth))
.scaleEffect(CGSize(width: 1, height: self.firstDisplay ? 0.0 : self.value), anchor: .bottom)
.onAppear {
self.firstDisplay = false
}
.onDisappear {
self.firstDisplay = true
}
.transition(.slide)
.animation(Animation.spring().delay(self.touchLocation < 0 || !firstDisplay ? Double(self.index) * 0.04 : 0))
}
}

Expand Down
19 changes: 9 additions & 10 deletions Sources/SwiftUICharts/Charts/BarChart/BarChartRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ public struct BarChartRow: View {
HStack(alignment: .bottom,
spacing: (geometry.frame(in: .local).width - Constant.spacing) / CGFloat(self.chartData.data.count * 3)) {
ForEach(0..<self.chartData.data.count, id: \.self) { index in
BarChartCell(value: self.normalizedValue(index: index),
index: index,
width: Float(geometry.frame(in: .local).width - Constant.spacing),
numberOfDataPoints: self.chartData.data.count,
gradientColor: self.style.foregroundColor.rotate(for: index),
touchLocation: self.touchLocation)
.scaleEffect(self.getScaleSize(touchLocation: self.touchLocation, index: index), anchor: .bottom)
.animation(.spring())
}.onReceive(self.chartData.objectWillChange) { _ in
print("new data")
BarChartCell(value: self.normalizedValue(index: index),
index: index,
width: Float(geometry.frame(in: .local).width - Constant.spacing),
numberOfDataPoints: self.chartData.data.count,
gradientColor: self.style.foregroundColor.rotate(for: index),
touchLocation: self.touchLocation)
.scaleEffect(self.getScaleSize(touchLocation: self.touchLocation, index: index), anchor: .bottom)
.animation(Animation.easeIn(duration: 0.2))
}
// .drawingGroup()
}
.padding([.top, .leading, .trailing], 10)
.gesture(DragGesture()
Expand Down