Compare commits

...

2 Commits

Author SHA1 Message Date
Samu Andras b7f1adb9d2 fix: remove UIColors which caused CI build errors 2022-09-03 18:57:39 +02:00
Andras Samu bd29afc4c9 fix: BarChartCellShape to handle negative numbers correctly (#250) 2022-09-03 18:55:59 +02:00
2 changed files with 18 additions and 13 deletions
@@ -39,13 +39,13 @@ public struct ChartLabel: View {
private var labelPadding: EdgeInsets {
switch labelType {
case .title:
return EdgeInsets(top: 16.0, leading: 8.0, bottom: 0.0, trailing: 8.0)
return EdgeInsets(top: 16.0, leading: 0, bottom: 0.0, trailing: 8.0)
case .legend:
return EdgeInsets(top: 4.0, leading: 8.0, bottom: 0.0, trailing: 8.0)
return EdgeInsets(top: 4.0, leading: 0, bottom: 0.0, trailing: 8.0)
case .subTitle:
return EdgeInsets(top: 8.0, leading: 8.0, bottom: 0.0, trailing: 8.0)
return EdgeInsets(top: 8.0, leading: 0, bottom: 0.0, trailing: 8.0)
case .largeTitle:
return EdgeInsets(top: 24.0, leading: 8.0, bottom: 0.0, trailing: 8.0)
return EdgeInsets(top: 24.0, leading: 0, bottom: 0.0, trailing: 8.0)
case .custom(_, let padding, _):
return padding
}
@@ -59,13 +59,13 @@ public struct ChartLabel: View {
private var labelColor: Color {
switch labelType {
case .title:
return Color(UIColor.label)
return Color.primary
case .legend:
return Color(UIColor.secondaryLabel)
return Color.secondary
case .subTitle:
return Color(UIColor.label)
return Color.primary
case .largeTitle:
return Color(UIColor.label)
return Color.primary
case .custom(_, _, let color):
return color
}
@@ -3,6 +3,7 @@ import SwiftUI
struct BarChartCellShape: Shape, Animatable {
var value: Double
var cornerRadius: CGFloat = 6.0
var animatableData: CGFloat {
get { CGFloat(value) }
set { value = Double(newValue) }
@@ -16,14 +17,14 @@ struct BarChartCellShape: Shape, Animatable {
path.addArc(center: CGPoint(x: cornerRadius, y: adjustedOriginY + cornerRadius),
radius: cornerRadius,
startAngle: Angle(radians: Double.pi),
endAngle: Angle(radians: -Double.pi/2),
clockwise: false)
path.addLine(to: CGPoint(x: rect.width - cornerRadius, y: adjustedOriginY))
endAngle: Angle(radians: value < 0 ? Double.pi/2 : -Double.pi/2),
clockwise: value < 0 ? true : false)
path.addLine(to: CGPoint(x: rect.width - cornerRadius, y: value < 0 ? adjustedOriginY + 2 * cornerRadius : adjustedOriginY))
path.addArc(center: CGPoint(x: rect.width - cornerRadius, y: adjustedOriginY + cornerRadius),
radius: cornerRadius,
startAngle: Angle(radians: -Double.pi/2),
startAngle: Angle(radians: value < 0 ? Double.pi/2 : -Double.pi/2),
endAngle: Angle(radians: 0),
clockwise: false)
clockwise: value < 0 ? true : false)
path.addLine(to: CGPoint(x: rect.width, y: rect.height))
path.closeSubpath()
@@ -39,6 +40,10 @@ struct BarChartCellShape_Previews: PreviewProvider {
BarChartCellShape(value: 0.3)
.fill(Color.blue)
BarChartCellShape(value: -0.3)
.fill(Color.blue)
.offset(x: 0, y: -600)
}
}
}