ScatterChartDataSet.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // ScatterChartDataSet.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 ScatterChartDataSet: LineScatterCandleRadarChartDataSet, IScatterChartDataSet
  14. {
  15. @objc(ScatterShape)
  16. public enum Shape: Int
  17. {
  18. case square
  19. case circle
  20. case triangle
  21. case cross
  22. case x
  23. case chevronUp
  24. case chevronDown
  25. }
  26. /// The size the scatter shape will have
  27. open var scatterShapeSize = CGFloat(10.0)
  28. /// The radius of the hole in the shape (applies to Square, Circle and Triangle)
  29. /// **default**: 0.0
  30. open var scatterShapeHoleRadius: CGFloat = 0.0
  31. /// Color for the hole in the shape. Setting to `nil` will behave as transparent.
  32. /// **default**: nil
  33. open var scatterShapeHoleColor: NSUIColor? = nil
  34. /// Sets the ScatterShape this DataSet should be drawn with.
  35. /// This will search for an available IShapeRenderer and set this renderer for the DataSet
  36. @objc open func setScatterShape(_ shape: Shape)
  37. {
  38. self.shapeRenderer = ScatterChartDataSet.renderer(forShape: shape)
  39. }
  40. /// The IShapeRenderer responsible for rendering this DataSet.
  41. /// This can also be used to set a custom IShapeRenderer aside from the default ones.
  42. /// **default**: `SquareShapeRenderer`
  43. open var shapeRenderer: IShapeRenderer? = SquareShapeRenderer()
  44. @objc open class func renderer(forShape shape: Shape) -> IShapeRenderer
  45. {
  46. switch shape
  47. {
  48. case .square: return SquareShapeRenderer()
  49. case .circle: return CircleShapeRenderer()
  50. case .triangle: return TriangleShapeRenderer()
  51. case .cross: return CrossShapeRenderer()
  52. case .x: return XShapeRenderer()
  53. case .chevronUp: return ChevronUpShapeRenderer()
  54. case .chevronDown: return ChevronDownShapeRenderer()
  55. }
  56. }
  57. // MARK: NSCopying
  58. open override func copy(with zone: NSZone? = nil) -> Any
  59. {
  60. let copy = super.copy(with: zone) as! ScatterChartDataSet
  61. copy.scatterShapeSize = scatterShapeSize
  62. copy.scatterShapeHoleRadius = scatterShapeHoleRadius
  63. copy.scatterShapeHoleColor = scatterShapeHoleColor
  64. copy.shapeRenderer = shapeRenderer
  65. return copy
  66. }
  67. }