Swiftpack.co - heestand-xyz/Trails as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by heestand-xyz.
heestand-xyz/Trails 1.2.0
Trails of values over time in SwiftUI
⭐️ 15
🕓 41 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/heestand-xyz/Trails.git", from: "1.2.0")

Trails

works on iOS, tvOS, watchOS and macOS

Install

Swift Package

.package(url: "https://github.com/hexagons/Trails.git", from: "1.1.1")

Setup

import SwiftUI
import Trails
struct ContentView: View {
    var main: Main = Main()
    var body: some View {
        TrailsView(trailer: main.trailer)
    }
}
class Main {
    
    let trailer: Trailer
    
    init() {
        
        let trailCount: Int = 3
        let seconds: Double = 10.0
        trailer = Trailer(count: trailCount,
                          duration: seconds)
        trailer.circlesActive = true
        
        startTimer()
        
    }
    
    func startTimer()  {
        
        let startDate: Date = Date()
        let timer: Timer = Timer(timeInterval: 0.5, repeats: true) { _ in
            let time: Double = -startDate.timeIntervalSinceNow
            let valueA: Double = cos(time)
            let valueB: Double = cos(time + (.pi * 2) * (1.0 / 3.0))
            let valueC: Double = cos(time + (.pi * 2) * (2.0 / 3.0))
            self.trailer.add(valueA, at: 0)
            self.trailer.add(valueB, at: 1)
            self.trailer.add(valueC, at: 2)
        }
        RunLoop.current.add(timer, forMode: .common)
        
    }
}

Properties

trailer.duration = 10.0

duration is in seconds

.duration can be changed while running

values added longer ago than the duration will be removed

trailer.circlesActive = true

.circlesActive default is false

trailer.circleBorder = false
trailer.circleRadius = 2.0

.circleBorder default is true

.circleRadius default is 3.0

trailer.lineWidth = 3.0

.lineWidth default is 1.0

trailer.colorsActive = false

when count is 1, .colorsActive is false by default

when count is 2 or more, .colorsActive is true by default

trailer.hues = [0.0, 0.1, 0.2]

the number of hues must match the count passed to Trailer

.hues is "rainbow" by default

a hue is a value between 0.0 and 1.0, low values: red to green, middle values: green to blue, high values: blue to red

trailer.colorBlend = false

when .colorBlend is false the lines will not be blended. this option is visible when a lot of lines overlap

when .colorBlend is true, light mode blends with .multiply, dark mode blends with .lighten

.colorBlend is true by default

trailer.drawValueEndLines = false

.drawValueEndLines is true by default

trailer.drawValueBackground = false

.drawValueBackground is true by default on iOS and watchOS can be useful to turn to false if your background is transparent

trailer.drawDefaultTextBackground = false

.drawValueBackground is true by default on iOS and watchOS can be useful to turn to false if your background is transparent

trailer.fontSize = 12.0

.fontSize is 8.0 by default

trailer.leftSpacing = 10.0
trailer.rightSpacing = 10.0

.leftSpacing and .rightSpacing is 20.0 by default

Mock

To repilcate the randomness seen in the gifs in the top of this readme, use this code:

let trailer: Trailer = TrailerMock.make()

provided by TrailerMock.swift

GitHub

link
Stars: 15
Last commit: 5 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics