1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// IndexAxisValueFormatter.swift
// Charts
//
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
// A port of MPAndroidChart for iOS
// Licensed under Apache License 2.0
//
// https://github.com/danielgindi/Charts
//
import Foundation
/// This formatter is used for passing an array of x-axis labels, on whole x steps.
@objc(ChartIndexAxisValueFormatter)
open class IndexAxisValueFormatter: NSObject, IAxisValueFormatter
{
private var _values: [String] = [String]()
private var _valueCount: Int = 0
@objc public var values: [String]
{
get
{
return _values
}
set
{
_values = newValue
_valueCount = _values.count
}
}
public override init()
{
super.init()
}
@objc public init(values: [String])
{
super.init()
self.values = values
}
@objc public static func with(values: [String]) -> IndexAxisValueFormatter?
{
return IndexAxisValueFormatter(values: values)
}
open func stringForValue(_ value: Double,
axis: AxisBase?) -> String
{
let index = Int(value.rounded())
guard values.indices.contains(index), index == Int(value) else { return "" }
return _values[index]
}
}