From 1064dfde7bc75b2bd153c91dfba8e2ea576ccb6d 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 22722c9935..ecd7093b53 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -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, @@ -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