Files
comaps/iphone/Chart/Chart/ChartData/ChartData.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

51 lines
1.1 KiB
Swift

import UIKit
public enum ChartType {
case regular
case percentage
}
public enum ChartLineType: String {
case line
case lineArea
}
public protocol ChartFormatter {
func xAxisString(from value: Double) -> String
func yAxisString(from value: Double) -> String
func yAxisLowerBound(from value: CGFloat) -> CGFloat
func yAxisUpperBound(from value: CGFloat) -> CGFloat
func yAxisSteps(lowerBound: CGFloat, upperBound: CGFloat) -> [CGFloat]
}
public protocol ChartData {
var xAxisValues: [Double] { get }
var lines: [ChartLine] { get }
var type: ChartType { get }
}
public protocol ChartLine {
var values: [ChartValue] { get }
var color: UIColor { get }
var type: ChartLineType { get }
}
public struct ChartValue {
let x: CGFloat
let y: CGFloat
public init(xValues: CGFloat, y: CGFloat) {
self.x = xValues
self.y = y
}
}
extension Array where Element == ChartValue {
var maxDistance: CGFloat { return map { $0.x }.max() ?? 0 }
func altitude(at relativeDistance: CGFloat) -> CGFloat {
guard let distance = last?.x else { return 0 }
return first { $0.x >= distance * relativeDistance }?.y ?? 0
}
}