Files
SwiftUI/Examples/Animating Views And Transitions/StartingPoint/Landmarks/Landmarks/Supporting Views/GraphCapsule.swift
T
2019-06-06 22:24:34 +03:00

39 lines
913 B
Swift
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
See LICENSE folder for this samples licensing information.
Abstract:
A single line in the graph.
*/
import SwiftUI
struct GraphCapsule: View {
var index: Int
var height: Length
var range: Range<Double>
var overallRange: Range<Double>
var heightRatio: Length {
max(Length(magnitude(of: range) / magnitude(of: overallRange)), 0.15)
}
var offsetRatio: Length {
Length((range.lowerBound - overallRange.lowerBound) / magnitude(of: overallRange))
}
var body: some View {
Capsule()
.fill(Color.white)
.frame(height: height * heightRatio, alignment: .bottom)
.offset(x: 0, y: height * -offsetRatio)
}
}
#if DEBUG
struct GraphCapsule_Previews: PreviewProvider {
static var previews: some View {
GraphCapsule(index: 0, height: 150, range: 10..<50, overallRange: 0..<100)
}
}
#endif