ChartLimitLine.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // ChartLimitLine.swift
  3. // Charts
  4. //
  5. // Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
  6. // A port of MPAndroidChart for iOS
  7. // Licensed under Apache License 2.0
  8. //
  9. // https://github.com/danielgindi/Charts
  10. //
  11. import Foundation
  12. import CoreGraphics
  13. /// The limit line is an additional feature for all Line, Bar and ScatterCharts.
  14. /// It allows the displaying of an additional line in the chart that marks a certain maximum / limit on the specified axis (x- or y-axis).
  15. open class ChartLimitLine: ComponentBase
  16. {
  17. @objc(ChartLimitLabelPosition)
  18. public enum LabelPosition: Int
  19. {
  20. case leftTop
  21. case leftBottom
  22. case rightTop
  23. case rightBottom
  24. }
  25. /// limit / maximum (the y-value or xIndex)
  26. @objc open var limit = Double(0.0)
  27. private var _lineWidth = CGFloat(2.0)
  28. @objc open var lineColor = NSUIColor(red: 237.0/255.0, green: 91.0/255.0, blue: 91.0/255.0, alpha: 1.0)
  29. @objc open var lineDashPhase = CGFloat(0.0)
  30. @objc open var lineDashLengths: [CGFloat]?
  31. @objc open var valueTextColor = NSUIColor.labelOrBlack
  32. @objc open var valueFont = NSUIFont.systemFont(ofSize: 13.0)
  33. @objc open var drawLabelEnabled = true
  34. @objc open var label = ""
  35. @objc open var labelPosition = LabelPosition.rightTop
  36. public override init()
  37. {
  38. super.init()
  39. }
  40. @objc public init(limit: Double)
  41. {
  42. super.init()
  43. self.limit = limit
  44. }
  45. @objc public init(limit: Double, label: String)
  46. {
  47. super.init()
  48. self.limit = limit
  49. self.label = label
  50. }
  51. /// set the line width of the chart (min = 0.2, max = 12); default 2
  52. @objc open var lineWidth: CGFloat
  53. {
  54. get
  55. {
  56. return _lineWidth
  57. }
  58. set
  59. {
  60. _lineWidth = newValue.clamped(to: 0.2...12)
  61. }
  62. }
  63. }