ValueFormatter.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // ValueFormatter.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. /// Interface that allows custom formatting of all values inside the chart before they are drawn to the screen.
  13. ///
  14. /// Simply create your own formatting class and let it implement ValueFormatter. Then override the stringForValue()
  15. /// method and return whatever you want.
  16. @objc(ChartValueFormatter)
  17. public protocol ValueFormatter: class
  18. {
  19. /// Called when a value (from labels inside the chart) is formatted before being drawn.
  20. ///
  21. /// For performance reasons, avoid excessive calculations and memory allocations inside this method.
  22. ///
  23. /// - Parameters:
  24. /// - value: The value to be formatted
  25. /// - dataSetIndex: The index of the DataSet the entry in focus belongs to
  26. /// - viewPortHandler: provides information about the current chart state (scale, translation, ...)
  27. /// - Returns: The formatted label ready to be drawn
  28. func stringForValue(_ value: Double,
  29. entry: ChartDataEntry,
  30. dataSetIndex: Int,
  31. viewPortHandler: ViewPortHandler?) -> String
  32. }