CandleChartDataSet.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // CandleChartDataSet.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. open class CandleChartDataSet: LineScatterCandleRadarChartDataSet, CandleChartDataSetProtocol
  14. {
  15. public required init()
  16. {
  17. super.init()
  18. }
  19. public override init(entries: [ChartDataEntry], label: String)
  20. {
  21. super.init(entries: entries, label: label)
  22. }
  23. // MARK: - Data functions and accessors
  24. open override func calcMinMax(entry e: ChartDataEntry)
  25. {
  26. guard let e = e as? CandleChartDataEntry
  27. else { return }
  28. _yMin = Swift.min(e.low, _yMin)
  29. _yMax = Swift.max(e.high, _yMax)
  30. calcMinMaxX(entry: e)
  31. }
  32. open override func calcMinMaxY(entry e: ChartDataEntry)
  33. {
  34. guard let e = e as? CandleChartDataEntry
  35. else { return }
  36. _yMin = Swift.min(e.low, _yMin)
  37. _yMax = Swift.max(e.high, _yMin)
  38. _yMin = Swift.min(e.low, _yMax)
  39. _yMax = Swift.max(e.high, _yMax)
  40. }
  41. // MARK: - Styling functions and accessors
  42. /// the space between the candle entries
  43. ///
  44. /// **default**: 0.1 (10%)
  45. private var _barSpace: CGFloat = 0.1
  46. /// the space that is left out on the left and right side of each candle,
  47. /// **default**: 0.1 (10%), max 0.45, min 0.0
  48. open var barSpace: CGFloat
  49. {
  50. get
  51. {
  52. return _barSpace
  53. }
  54. set
  55. {
  56. _barSpace = newValue.clamped(to: 0...0.45)
  57. }
  58. }
  59. /// should the candle bars show?
  60. /// when false, only "ticks" will show
  61. ///
  62. /// **default**: true
  63. open var showCandleBar: Bool = true
  64. /// the width of the candle-shadow-line in pixels.
  65. ///
  66. /// **default**: 1.5
  67. open var shadowWidth = CGFloat(1.5)
  68. /// the color of the shadow line
  69. open var shadowColor: NSUIColor?
  70. /// use candle color for the shadow
  71. open var shadowColorSameAsCandle = false
  72. /// Is the shadow color same as the candle color?
  73. open var isShadowColorSameAsCandle: Bool { return shadowColorSameAsCandle }
  74. /// color for open == close
  75. open var neutralColor: NSUIColor?
  76. /// color for open > close
  77. open var increasingColor: NSUIColor?
  78. /// color for open < close
  79. open var decreasingColor: NSUIColor?
  80. /// Are increasing values drawn as filled?
  81. /// increasing candlesticks are traditionally hollow
  82. open var increasingFilled = false
  83. /// Are increasing values drawn as filled?
  84. open var isIncreasingFilled: Bool { return increasingFilled }
  85. /// Are decreasing values drawn as filled?
  86. /// descreasing candlesticks are traditionally filled
  87. open var decreasingFilled = true
  88. /// Are decreasing values drawn as filled?
  89. open var isDecreasingFilled: Bool { return decreasingFilled }
  90. }