@@ -90,6 +90,11 @@ open class Chart: UIControl {
90
90
*/
91
91
open var xLabelsOrientation : ChartLabelOrientation = . horizontal
92
92
93
+ /**
94
+ Skip the last x-label. Setting this to false may make the label overflow the frame width.
95
+ */
96
+ open var xLabelsSkipLast : Bool = true
97
+
93
98
/**
94
99
Values to display as labels of the y-axis. If not specified, will display the
95
100
lowest, the middle and the highest values.
@@ -561,9 +566,9 @@ open class Chart: UIControl {
561
566
562
567
let scaled = scaleValuesOnXAxis ( labels)
563
568
let padding : CGFloat = 5
564
-
565
569
scaled. enumerated ( ) . forEach { ( i, value) in
566
570
let x = CGFloat ( value)
571
+ let isLastLabel = x == drawingWidth
567
572
568
573
// Add vertical grid for each label, except axes on the left and right
569
574
@@ -573,7 +578,7 @@ open class Chart: UIControl {
573
578
context. strokePath ( )
574
579
}
575
580
576
- if x == drawingWidth {
581
+ if xLabelsSkipLast && isLastLabel {
577
582
// Do not add label at the most right position
578
583
return
579
584
}
@@ -590,8 +595,8 @@ open class Chart: UIControl {
590
595
label. frame. origin. y += topInset
591
596
if xLabelsOrientation == . horizontal {
592
597
// Add left padding
593
- label. frame. origin. x += padding
594
598
label. frame. origin. y -= ( label. frame. height - bottomInset) / 2
599
+ label. frame. origin. x += padding
595
600
596
601
// Set label's text alignment
597
602
label. frame. size. width = ( drawingWidth / CGFloat( labels. count) ) - padding * 2
@@ -609,12 +614,11 @@ open class Chart: UIControl {
609
614
label. frame. origin. x += ( ( drawingWidth / CGFloat( labels. count) ) / 2 ) - ( label. frame. size. width / 2 )
610
615
} else {
611
616
// Give some space from the vertical line
612
- label. frame. origin. x += 4
617
+ label. frame. origin. x += padding
613
618
}
614
619
}
615
620
616
621
self . addSubview ( label)
617
-
618
622
}
619
623
620
624
}
0 commit comments