Skip to content

Commit

Permalink
Issue 99 documentation (#159)
Browse files Browse the repository at this point in the history
* Starting on filling in documentation.

* First pass on most/all files

* more descriptions filled in

* Some documentation but TBH the author would be better suited to explain how this works!

* more basic stuff filled in

* Add a description and bunch of discussion text for most of the view `body` declarations

* more explanations

Co-authored-by: Dan Wood <danwood@users.noreply.github.com>
  • Loading branch information
danwood and danwood authored Aug 24, 2020
1 parent ed01f53 commit 51db5a0
Show file tree
Hide file tree
Showing 25 changed files with 338 additions and 46 deletions.
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

0 comments on commit 51db5a0

Please sign in to comment.