@@ -87,7 +87,8 @@ import UIKit
8787 public var dataPointLabelBottomMargin : CGFloat = 0
8888 public var dataPointLabelColor = UIColor . blackColor ( )
8989 public var dataPointLabelFont : UIFont ? = UIFont . systemFontOfSize ( 10 )
90-
90+ public var dataPointLabelsSparsity : Int = 1 // Used to force the graph to show every n-th dataPoint label (by default displaying every label)
91+
9192 // MARK: - Private State
9293 // #####################
9394
@@ -760,15 +761,17 @@ import UIKit
760761 // If the active points (the points we can actually see) change, then we need to update the path.
761762 private func activePointsDidChange( ) {
762763
763- let deactivatedPoints = determineDeactivatedPoints ( )
764- let activatedPoints = determineActivatedPoints ( )
765-
766- updatePaths ( )
767- if ( shouldShowLabels) {
768- updateLabels ( deactivatedPoints, activatedPoints)
769- }
770- }
771-
764+ let deactivatedPoints = determineDeactivatedPoints ( )
765+ let activatedPoints = determineActivatedPoints ( )
766+
767+ updatePaths ( )
768+ if ( shouldShowLabels) {
769+ let deactivatedLabelPoints = filterPointsForLabels ( fromPoints: deactivatedPoints)
770+ let activatedLabelPoints = filterPointsForLabels ( fromPoints: activatedPoints)
771+ updateLabels ( deactivatedLabelPoints, activatedLabelPoints)
772+ }
773+ }
774+
772775 private func rangeDidChange( ) {
773776
774777 // If shouldAnimateOnAdapt is enabled it will kickoff any animations that need to occur.
@@ -882,7 +885,15 @@ import UIKit
882885 }
883886 return set
884887 }
888+
889+ private func filterPointsForLabels( fromPoints points: [ Int ] ) -> [ Int ] {
885890
891+ if ( self . dataPointLabelsSparsity == 1 ) {
892+ return points
893+ }
894+ return points. filter ( { $0 % self . dataPointLabelsSparsity == 0 } )
895+ }
896+
886897 private func startAnimations( withStaggerValue stagger: Double = 0 ) {
887898
888899 var pointsToAnimate = 0 ..< 0
0 commit comments