Compare commits

..

2 Commits

Author SHA1 Message Date
Andras Samu f426dbaada feat: add new axis interface (#253) 2022-10-24 16:07:28 +02:00
Samu Andras b48b701657 feat: new protocol for chained functions, and added support for explicit Y ranges. X coming as well 2022-09-29 19:05:28 +02:00
3 changed files with 24 additions and 25 deletions
@@ -21,9 +21,4 @@ extension LineChart {
self.chartProperties.lineStyle = style
return self
}
public func withAnimation(_ enabled: Bool) -> LineChart {
self.chartProperties.animationEnabled = enabled
return self
}
}
@@ -33,7 +33,18 @@ public struct Line: View {
geometry: geometry,
backgroundColor: backgroundColor)
}
lineShapeView(geometry: geometry)
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()
}
}
.onAppear {
didCellAppear = true
@@ -41,24 +52,17 @@ public struct Line: View {
.onDisappear() {
didCellAppear = 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)
// .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
// })
// )
}
}
}
@@ -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
}