From c6150042174ae0d6c9014802b7b02ccce4f5aa06 Mon Sep 17 00:00:00 2001 From: Roberto Estrada Date: Fri, 13 Oct 2017 14:21:59 +0200 Subject: [PATCH 1/2] 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. --- 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 55276007ec..b4805303d2 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 = Int(2) { + didSet { axisMinLabels = axisMinLabels > 0 ? axisMinLabels : oldValue } + } + + /// The maximum number of labels on the axis + @objc open var axisMaxLabels: Int = 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 From d26acd056a09bcb9775648386a5eda15f5776c4c Mon Sep 17 00:00:00 2001 From: Roberto Estrada Date: Mon, 8 Jan 2018 09:59:26 +0100 Subject: [PATCH 2/2] Type inference was enough to declare 'axisMinLabels' and 'axisMaxLabels' properties --- Source/Charts/Components/AxisBase.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Charts/Components/AxisBase.swift b/Source/Charts/Components/AxisBase.swift index b4805303d2..638d735aa5 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -214,12 +214,12 @@ open class AxisBase: ComponentBase @objc open var axisRange = Double(0) /// The minumum number of labels on the axis - @objc open var axisMinLabels: Int = Int(2) { + @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 = Int(25) { + @objc open var axisMaxLabels = Int(25) { didSet { axisMinLabels = axisMaxLabels > 0 ? axisMaxLabels : oldValue } }