CocoaPods trunk is moving to be read-only. Read more on the blog, there are 2 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Jun 2017 |
| SwiftSwift Version | 3.0 |
| SPMSupports SPM | ✓ |
Maintained by Marek Lisik.
MRLCircleChart is a small pie/circle chart UI component written in Swift. Aims to take care of most of the work for you (just pass in a data source and configure the view) at the expense of customizability.
Chart‘s DataSource is comprised of an array of Segments and a maxValue property that functions as a reference for Segments angle values. You can easily map your source values to [Segment], then initialize a data source conforming to the MRLCircleChart.DataSource protocol, and pass this to the Chart:
struct DataSource: MRLCircleChart.DataSource {
// protocol conformance
}
let segments = [90, 80, 60].map {
Segment(value: $0, description: "\($0)")
}
chart.dataSource = DataSource(items: segments, maxValue: 250)
All customization you need can be done via InterfaceBuilder, through the following IBDesignable properties:
If you are laying out your Chart without IB, these are also readily available.
@IBInspectable public var lineWidth: CGFloat = 25
@IBInspectable public var padding: CGFloat = 0
@IBInspectable public var chartBackgroundColor: UIColor = UIColor(white: 0.7, alpha: 0.26)
@IBInspectable public var beginColor: UIColor? = UIColor.beginColor()
@IBInspectable public var endColor: UIColor? = UIColor.endColor()See the entire documentation on Cocoadocs.
Beyond customization, the main public APIs revolve around modifying and updating the available data.
public mutating func remove(index: Int) -> MRLCircleChart.Segment?
public mutating func insert(item: MRLCircleChart.Segment, index: Int)
public mutating func append(item: MRLCircleChart.Segment)
public mutating func empty()final public func reloadData(animated animated: Bool = true, completion: () -> () = {})
public func empty(animated animated: Bool = true, color: UIColor? = nil)
public func select(index selectIndex: Int)
public func deselect(index index: Int)Two callbacks are available for user interaction events: when a segment is selected and when it’s deselected.
chart.selectHandler = {
index in print("selected \(index)")
}
chart.deselectHandler = {
index in print("deselected \(index)")
}To run the example project, clone the repo, and run pod install from the Example directory first, or run pod try MRLCircleChart to check it with a temporary clone.
MRLCircleChart is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "MRLCircleChart"If you’d like to help out, check open tickets on waffle.io. There’s no roadmap for the project yet, but pull requests are welcome (whether you want to clean up, fix or add something), and so are feature requests.
mlisik, [email protected]
MRLCircleChart is available under the MIT license. See the LICENSE file for more info.