GesturableGraph is a library that expresses values in a graph based on user touch.
- iOS 13.0+
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Xcode 11+ is required to build SnapKit using Swift Package Manager.
To integrate SnapKit into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/ohdair/GesturableGraph")
]
If the graph has fewer than two elements, the GesturableGraph cannot be created and returns nil.
import GesturableGraph
class ViewController: UIViewController {
override func viewDidLoad() {
let data: [Double] = [3, 8, 7, 4, 6, 9, 11, 12, 8, 7, 6, 10]
guard let graphView = GesturableGraph(elements: data) else {
return
}
}
}
GesturableGraphEnable must be adopted to receive values for gestures. You can use the delegate pattern to receive GraphData.
class ViewController: UIViewController {
override func viewDidLoad() {
graphView.delegate = self
}
}
extension ViewController: GesturableGraphEnable {
func gesturableGraph(_ gesturableGraph: GesturableGraph, didTapWithData data: GraphData?) {
// You can use the data and present it in a UI.
}
}
![Group 6@2x](https://private-user-images.githubusercontent.com/79438622/278960226-64f65def-07b7-4f65-a6dd-f5865b40ddf7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyODY1MDIsIm5iZiI6MTcyMTI4NjIwMiwicGF0aCI6Ii83OTQzODYyMi8yNzg5NjAyMjYtNjRmNjVkZWYtMDdiNy00ZjY1LWE2ZGQtZjU4NjViNDBkZGY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE4VDA3MDMyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZmNTA4ZmQ4NDE5N2YwMTgyNmIwNzBmOWY0NWFkYTUzZDA4YmVkMWRiZTllMzU3MjhjMTM4MjZiMWZjN2ZkZWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.0YTvHNgcqzuUa6269x2r18EryTRj1OBflz9gc5d0wbA)
graph has 3 properties
- type
enum GraphType { case curve // default case straight }
- distribution
// aroundSpacing is that spacing at left/right spacing is 1/2 the size of the inner spacing. // evenSpacing is that inner spacing and left/right spacing are the same. enum Distribution { case equalSpacing // default case aroundSpacing case evenSpacing }
- padding
// Padding is a scaling factor for the height of the graph. struct Padding { var top: Double = 0.3 // default var bottom: Double = 0.3 // default }
enum UnitOfTime {
case seconds
case minutes
case hours // default
case days
case months
}
// position adjusts the position of axisY
// division display the label on the axisY axis by the value.
// decimalPlaces adjusts the position of the decimal point
struct AxisY {
var dataUnit: String = ""
var division: Int = 8
var decimalPlaces: Int = 0
var position: Position = .right
enum Position {
case left
case right
}
}
extraUnits only allows collection of images.
change the color and size property values.
- line
- point
- enableLine
- enablePoint
- area
struct GraphLine {
var width: Double
var color: UIColor
}
struct GraphPoint {
var width: Double
var color: UIColor
var isHidden: Bool
}
struct GraphEnablePoint {
var width: Double
var color: UIColor
}
struct GraphEnableLine {
var width: Double
var color: UIColor
}
struct GraphArea {
var gradientColors: [UIColor]
var isFill: Bool
}