Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthewjselby/swiftuilinegraph
A smooth line graph written in SwiftUI
https://github.com/matthewjselby/swiftuilinegraph
Last synced: 1 day ago
JSON representation
A smooth line graph written in SwiftUI
- Host: GitHub
- URL: https://github.com/matthewjselby/swiftuilinegraph
- Owner: matthewjselby
- Created: 2020-07-08T19:36:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T20:22:41.000Z (over 4 years ago)
- Last Synced: 2023-12-31T23:21:19.674Z (11 months ago)
- Language: Swift
- Size: 73.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SwiftUILineGraph
A smooth line graph written in SwiftUIGiven an array of CGPoints:
```swift
[
CGPoint(x: 1, y: 1),
CGPoint(x: 2, y: 40),
CGPoint(x: 3, y: 10),
CGPoint(x: 6, y: 27),
CGPoint(x: 10, y: 50),
CGPoint(x: 12, y: 30)
]
```The LineGraph component will provide a smoothed line graph (smoothing based on Catmull-Rom splines) - credit to [André Lind](https://github.com/andrelind) for some of the base Catmull-Rom [code](https://github.com/andrelind/swift-catmullrom):
![screenshot](SmoothLineGraph/Github/screenshot.png)
Usage:
```swift
LineGraph(points: [
CGPoint(x: 1, y: 5),
CGPoint(x: 2, y: 40),
CGPoint(x: 3, y: 20),
CGPoint(x: 6, y: 27),
CGPoint(x: 8, y: 100),
CGPoint(x: 11, y: 70)
])
```
A frame can be specified if desired:```swift
LineGraph(points: [
CGPoint(x: 1, y: 5),
CGPoint(x: 2, y: 40),
CGPoint(x: 3, y: 20),
CGPoint(x: 6, y: 27),
CGPoint(x: 8, y: 100),
CGPoint(x: 11, y: 70)
]).frame(width: 300, height: 100, alignment: .center)
```The graph automatically adjusts to draw within the frame. The minimum value will be drawn at the bottom of the frame, while the maximum value will be drawn at the top of the frame.
TODO:
- [ ] Support negative values
- [ ] Support optional data labels for axes
- [ ] Add parameter for stroke color and width
- [ ] Add optional parameter for under-graph fill color