Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 99 documentation #159

Merged
merged 7 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/SwiftUICharts/Base/CardView/CardView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

/// View containing data and some kind of chart content
public struct CardView<Content: View>: View, ChartBase {
public var chartData = ChartData()
let content: () -> Content
Expand All @@ -8,11 +9,18 @@ public struct CardView<Content: View>: View, ChartBase {

@EnvironmentObject var style: ChartStyle

/// Initialize with view options and a nested `ViewBuilder`
/// - Parameters:
/// - showShadow: should card have a rounded-rectangle shadow around it
/// - content: <#content description#>
public init(showShadow: Bool = true, @ViewBuilder content: @escaping () -> Content) {
self.showShadow = showShadow
self.content = content
}

/// The content and behavior of the `CardView`.
///
///
public var body: some View {
ZStack{
if showShadow {
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftUICharts/Base/Chart/ChartBase.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

/// Protocol for any type of chart, to get access to underlying data
public protocol ChartBase {
var chartData: ChartData { get }
}
3 changes: 3 additions & 0 deletions Sources/SwiftUICharts/Base/Chart/ChartData.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import SwiftUI

/// An observable wrapper for an array of data for use in any chart
public class ChartData: ObservableObject {
@Published public var data: [Double] = []

/// Initialize with data array
/// - Parameter data: Array of `Double`
public init(_ data: [Double]) {
self.data = data
}
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftUICharts/Base/Chart/ChartValue.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

/// Representation of a single data point in a chart that is being observed
public class ChartValue: ObservableObject {
@Published var currentValue: Double = 0
@Published var interactionInProgress: Bool = false
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftUICharts/Base/Extensions/Array+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Foundation

extension Array where Element == ColorGradient {

/// <#Description#>
/// - Parameter index: offset in data table
/// - Returns: <#description#>
func rotate(for index: Int) -> ColorGradient {
if self.isEmpty {
return ColorGradient.orangeBright
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftUICharts/Base/Extensions/CGPoint+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import SwiftUI

extension CGPoint {

/// Calculate X and Y delta for each data point, based on data min/max and enclosing frame.
/// - Parameters:
/// - frame: Rectangle of enclosing frame
/// - data: array of `Double`
/// - Returns: X and Y delta as a `CGPoint`
static func getStep(frame: CGRect, data: [Double]) -> CGPoint {
let padding: CGFloat = 30.0

Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftUICharts/Base/Extensions/CGRect+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Foundation
import SwiftUI

extension CGRect {
// Return the coordinate for a rectangle center

/// Midpoint of rectangle
/// - Returns: the coordinate for a rectangle center
public var mid: CGPoint {
return CGPoint(x: self.midX, y: self.midY)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import SwiftUI

extension View where Self: ChartBase {

/// Set data for a chart
/// - Parameter data: array of `Double`
/// - Returns: modified `View` with data attached
public func data(_ data: [Double]) -> some View {
chartData.data = data
return self
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftUICharts/Base/Extensions/Color+Extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import SwiftUI

extension Color {
/// Create a `Color` from a hexadecimal representation
/// - Parameter hexString: 3, 6, or 8-character string, with optional (ignored) punctuation such as "#"
init(hexString: String) {
let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
var int = UInt64()
Expand Down
Loading