Skip to content

Commit

Permalink
Give the users customizable axis label limits (Fixes ChartsOrg#2085) (C…
Browse files Browse the repository at this point in the history
…hartsOrg#2894)

* Give the users customizable axis label limits (Fixes ChartsOrg#2085)

This change adds the ability to users to override the imposed limitation of at least 2 labels per axis and at most 25 labels per axis at their own risk. By default these customizable limits are hardcoded to the previous limits, at least 2 labels, at most 25.

* Type inference was enough to declare 'axisMinLabels' and 'axisMaxLabels' properties
  • Loading branch information
igzrobertoestrada authored and Konstantin Zyrianov committed Feb 20, 2018
1 parent e8523ae commit fa04509
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Source/Charts/Components/AxisBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ open class AxisBase: ComponentBase
/// the total range of values this axis covers
@objc open var axisRange = Double(0)

/// The minumum number of labels on the axis
@objc open var axisMinLabels = Int(2) {
didSet { axisMinLabels = axisMinLabels > 0 ? axisMinLabels : oldValue }
}

/// The maximum number of labels on the axis
@objc open var axisMaxLabels = Int(25) {
didSet { axisMinLabels = axisMaxLabels > 0 ? axisMaxLabels : oldValue }
}

/// the number of label entries the axis should have
/// max = 25,
/// min = 2,
Expand All @@ -227,13 +237,13 @@ open class AxisBase: ComponentBase
{
_labelCount = newValue

if _labelCount > 25
if _labelCount > axisMaxLabels
{
_labelCount = 25
_labelCount = axisMaxLabels
}
if _labelCount < 2
if _labelCount < axisMinLabels
{
_labelCount = 2
_labelCount = axisMinLabels
}

forceLabelsEnabled = false
Expand Down

0 comments on commit fa04509

Please sign in to comment.