Compare commits

..

1 Commits

Author SHA1 Message Date
Samu Andras ddba612198 feat: add new axis interface 2022-10-24 15:50:17 +02:00
4 changed files with 15 additions and 5 deletions
@@ -201,7 +201,7 @@ extension Path {
let convertedXValues = data.map { CGFloat($0.0) * rect.width }
let convertedYPoints = data.map { CGFloat($0.1) * rect.height }
path.move(to: .zero)
path.move(to: CGPoint(x: convertedXValues[0], y: 0))
var point1 = CGPoint(x: convertedXValues[0], y: convertedYPoints[0])
path.addLine(to: point1)
for pointIndex in 1..<data.count {
@@ -11,8 +11,9 @@ extension LineChart {
return self
}
public func showChartMarks(_ show: Bool) -> LineChart {
public func showChartMarks(_ show: Bool, with color: ColorGradient? = nil) -> LineChart {
self.chartProperties.showChartMarks = show
self.chartProperties.customChartMarksColors = color
return self
}
@@ -13,6 +13,16 @@ struct LineShapeView: View, Animatable {
set { trimTo = Double(newValue) }
}
var chartMarkColor: LinearGradient {
if let customColor = chartProperties.customChartMarksColors {
return customColor.linearGradient(from: .leading, to: .trailing)
}
return LinearGradient(gradient: style.foregroundColor.first?.gradient ?? ColorGradient.orangeBright.gradient,
startPoint: .leading,
endPoint: .trailing)
}
var body: some View {
ZStack {
LineShape(data: chartData.normalisedData, lineStyle: chartProperties.lineStyle)
@@ -28,9 +38,7 @@ struct LineShapeView: View, Animatable {
MarkerShape(data: chartData.normalisedData)
.trim(from: 0, to: CGFloat(trimTo))
.fill(.white,
strokeBorder: LinearGradient(gradient: style.foregroundColor.first?.gradient ?? ColorGradient.orangeBright.gradient,
startPoint: .leading,
endPoint: .trailing),
strokeBorder: chartMarkColor,
lineWidth: chartProperties.lineWidth)
.rotationEffect(.degrees(180), anchor: .center)
.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
@@ -4,6 +4,7 @@ public class LineChartProperties: ObservableObject {
@Published var lineWidth: CGFloat = 2.0
@Published var backgroundGradient: ColorGradient?
@Published var showChartMarks: Bool = true
@Published var customChartMarksColors: ColorGradient?
@Published var lineStyle: LineStyle = .curved
public init() {