From e3490f3add777690a6260c4fe1b937e0ac9deb11 Mon Sep 17 00:00:00 2001 From: Roberto Estrada Date: Tue, 9 Jan 2018 02:09:28 +0100 Subject: [PATCH] Give the users customizable axis label limits (Fixes #2085) (#2894) * Give the users customizable axis label limits (Fixes #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 --- Source/Charts/Components/AxisBase.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Source/Charts/Components/AxisBase.swift b/Source/Charts/Components/AxisBase.swift index 8753d948fd..d9a9e8fb2f 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -213,6 +213,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, @@ -228,13 +238,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