Skip to content

Commit e3490f3

Browse files
igzrobertoestradaphilipengberg
authored andcommitted
Give the users customizable axis label limits (Fixes ChartsOrg#2085) (ChartsOrg#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
1 parent 8302bd2 commit e3490f3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Source/Charts/Components/AxisBase.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ open class AxisBase: ComponentBase
213213
/// the total range of values this axis covers
214214
@objc open var axisRange = Double(0)
215215

216+
/// The minumum number of labels on the axis
217+
@objc open var axisMinLabels = Int(2) {
218+
didSet { axisMinLabels = axisMinLabels > 0 ? axisMinLabels : oldValue }
219+
}
220+
221+
/// The maximum number of labels on the axis
222+
@objc open var axisMaxLabels = Int(25) {
223+
didSet { axisMinLabels = axisMaxLabels > 0 ? axisMaxLabels : oldValue }
224+
}
225+
216226
/// the number of label entries the axis should have
217227
/// max = 25,
218228
/// min = 2,
@@ -228,13 +238,13 @@ open class AxisBase: ComponentBase
228238
{
229239
_labelCount = newValue
230240

231-
if _labelCount > 25
241+
if _labelCount > axisMaxLabels
232242
{
233-
_labelCount = 25
243+
_labelCount = axisMaxLabels
234244
}
235-
if _labelCount < 2
245+
if _labelCount < axisMinLabels
236246
{
237-
_labelCount = 2
247+
_labelCount = axisMinLabels
238248
}
239249

240250
forceLabelsEnabled = false

0 commit comments

Comments
 (0)