1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-26 16:55:09 +01:00
mastodon-app-ufficiale-ipho.../WidgetExtension/LightChart/LightChart.swift
2023-01-30 15:28:16 +01:00

53 lines
1.9 KiB
Swift

import SwiftUI
public struct LightChartView: View {
private let data: [Double]
private let type: ChartType
private let visualType: ChartVisualType
private let offset: Double
private let currentValueLineType: CurrentValueLineType
public init(data: [Double],
type: ChartType = .line,
visualType: ChartVisualType = .outline(color: .red, lineWidth: 2),
offset: Double = 0,
currentValueLineType: CurrentValueLineType = .none) {
self.data = data
self.type = type
self.visualType = visualType
self.offset = offset
self.currentValueLineType = currentValueLineType
}
public var body: some View {
GeometryReader { reader in
chart(withFrame: CGRect(x: 0,
y: 0,
width: reader.frame(in: .local).width ,
height: reader.frame(in: .local).height))
}
}
private func chart(withFrame frame: CGRect) -> AnyView {
switch type {
case .line:
return AnyView(
LineChart(data: data,
frame: frame,
visualType: visualType,
offset: offset,
currentValueLineType: currentValueLineType)
)
case .curved:
return AnyView(
CurvedChart(data: data,
frame: frame,
visualType: visualType,
offset: offset,
currentValueLineType: currentValueLineType)
)
}
}
}