Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.
Open
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
15 changes: 12 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/swiftviz/SwiftViz", from: "0.0.0"),
.package(url: "https://github.com/swiftviz/SwiftViz", branch: "APIiteration"),
// .package(url: "https://github.com/swiftviz/SwiftViz", from: "0.0.0"),
.package(url: "https://github.com/nalexn/ViewInspector", from: "0.0.0"),
],
targets: [
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftUIViz/HorizontalAxisView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import SwiftUI
import SwiftViz

public struct HorizontalAxisView<ScaleType: Scale>: View {
public struct HorizontalAxisView<ScaleType: TickScale>: View where ScaleType.InputType == Double, ScaleType.OutputType == Float {
let leftInset: CGFloat
let rightInset: CGFloat
var scale: ScaleType
Expand All @@ -19,15 +19,15 @@ public struct HorizontalAxisView<ScaleType: Scale>: View {
self.scale = scale
}

func tickList(geometry: GeometryProxy) -> [ScaleType.TickType] {
func tickList<InputType, OutputType>(geometry: GeometryProxy) -> [Tick<InputType, OutputType>] where ScaleType.InputType == InputType, ScaleType.OutputType == OutputType {
// protect against Preview sending in stupid values
// of geometry that can't be made into a reasonable range
// otherwise the next line will crash preview...
if geometry.size.width < leftInset + rightInset {
return [ScaleType.TickType]()
return [Tick<InputType, OutputType>]()
}
let geometryRange = 0.0 ... CGFloat(geometry.size.width - leftInset - rightInset)
return scale.ticks(count: 10, range: geometryRange)
let upperBound = Float(geometry.size.width - leftInset - rightInset)
return scale.ticks(rangeLower: 0.0, rangeHigher: upperBound)
}

public var body: some View {
Expand All @@ -46,8 +46,8 @@ public struct HorizontalAxisView<ScaleType: Scale>: View {

// draw each tick in the line
for tick in self.tickList(geometry: geometry) {
path.move(to: CGPoint(x: tick.rangeLocation + self.leftInset, y: 3))
path.addLine(to: CGPoint(x: tick.rangeLocation + self.leftInset, y: 8))
path.move(to: CGPoint(x: CGFloat(tick.rangeLocation) + self.leftInset, y: 3))
path.addLine(to: CGPoint(x: CGFloat(tick.rangeLocation) + self.leftInset, y: 8))
}
}.stroke()
}
Expand All @@ -63,12 +63,12 @@ public struct HorizontalAxisView<ScaleType: Scale>: View {
struct HorizontalAxisView_Previews: PreviewProvider {
static var previews: some View {
Group {
HorizontalAxisView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false),
HorizontalAxisView(scale: LinearScale.create(0 ... 5.0),
leftInset: 25.0,
rightInset: 25.0)
.frame(width: 400, height: 50, alignment: .center)

HorizontalAxisView(scale: LogScale(domain: 1 ... 10.0, isClamped: false),
HorizontalAxisView(scale: LogScale.DoubleScale(from: 0, to: 10),
leftInset: 25.0,
rightInset: 25.0)
.frame(width: 400, height: 50, alignment: .center)
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftUIViz/HorizontalBandView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import SwiftUI
import SwiftViz

public struct HorizontalBandView<ScaleType: Scale>: View {
public struct HorizontalBandView<ScaleType: TickScale>: View where ScaleType.InputType == Double, ScaleType.OutputType == Float {
var scale: ScaleType

init(scale: ScaleType) {
self.scale = scale
}

func tickList(geometry: GeometryProxy) -> [ScaleType.TickType] {
func tickList<InputType, OutputType>(geometry: GeometryProxy) -> [Tick<InputType, OutputType>] where ScaleType.InputType == InputType, ScaleType.OutputType == OutputType {
// protect against Preview sending in stupid values
// of geometry that can't be made into a reasonable range
// otherwise the next line will crash preview...
let geometryRange = 0.0 ... CGFloat(geometry.size.width)
return scale.ticks(count: 10, range: geometryRange)
let upperBound = Float(geometry.size.width)
return scale.ticks(rangeLower: 0.0, rangeHigher: upperBound)
}

public var body: some View {
Expand All @@ -33,8 +33,8 @@ public struct HorizontalBandView<ScaleType: Scale>: View {
Path { path in
// draw each tick in the line
for tick in self.tickList(geometry: geometry) {
path.move(to: CGPoint(x: tick.rangeLocation, y: 0))
path.addLine(to: CGPoint(x: tick.rangeLocation, y: geometry.size.height))
path.move(to: CGPoint(x: CGFloat(tick.rangeLocation), y: 0))
path.addLine(to: CGPoint(x: CGFloat(tick.rangeLocation), y: geometry.size.height))
}
}.stroke(lineWidth: 0.5)
}
Expand All @@ -49,15 +49,15 @@ public struct HorizontalBandView<ScaleType: Scale>: View {
struct HorizontalBandView_Previews: PreviewProvider {
static var previews: some View {
Group {
HorizontalBandView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false))
HorizontalBandView(scale: LinearScale.create(0 ... 5.0))
.frame(width: 400, height: 50, alignment: .center)
.padding()

HorizontalBandView(scale: LogScale(domain: 1 ... 10.0, isClamped: false))
HorizontalBandView(scale: LogScale.DoubleScale(from: 0, to: 10))
.frame(width: 400, height: 50, alignment: .center)
.padding()

HorizontalBandView(scale: LogScale(domain: 0.1 ... 100.0, isClamped: false))
HorizontalBandView(scale: LogScale.DoubleScale(from: 0.1, to: 100.0))
.frame(width: 400, height: 50, alignment: .center)
.padding()
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftUIViz/VerticalAxisView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import SwiftUI
import SwiftViz

public struct VerticalAxisView<ScaleType: Scale>: View {
public struct VerticalAxisView<ScaleType: TickScale>: View where ScaleType.InputType == Double, ScaleType.OutputType == Float {
let topInset: CGFloat
let bottomInset: CGFloat
let leftOffset: CGFloat
Expand All @@ -24,15 +24,15 @@ public struct VerticalAxisView<ScaleType: Scale>: View {
tickLength = 5
}

func tickList(geometry: GeometryProxy) -> [ScaleType.TickType] {
func tickList<InputType, OutputType>(geometry: GeometryProxy) -> [Tick<InputType, OutputType>] where ScaleType.InputType == InputType, ScaleType.OutputType == OutputType {
// protect against Preview sending in stupid values
// of geometry that can't be made into a reasonable range
// otherwise the next line will crash preview...
if geometry.size.width < topInset + bottomInset {
return [ScaleType.TickType]()
return [Tick<InputType, OutputType>]()
}
let geometryRange = 0.0 ... CGFloat(geometry.size.height - topInset - bottomInset)
return scale.ticks(count: 10, range: geometryRange)
let upperBound = Float(geometry.size.height - topInset - bottomInset)
return scale.ticks(rangeLower: 0, rangeHigher: upperBound)
}

public var body: some View {
Expand All @@ -48,8 +48,8 @@ public struct VerticalAxisView<ScaleType: Scale>: View {
path.addLine(to: CGPoint(x: self.leftOffset + self.tickLength, y: geometry.size.height - self.bottomInset))

for tick in self.tickList(geometry: geometry) {
path.move(to: CGPoint(x: self.leftOffset, y: tick.rangeLocation + self.topInset))
path.addLine(to: CGPoint(x: self.leftOffset + self.tickLength, y: tick.rangeLocation + self.topInset))
path.move(to: CGPoint(x: self.leftOffset, y: CGFloat(tick.rangeLocation) + self.topInset))
path.addLine(to: CGPoint(x: self.leftOffset + self.tickLength, y: CGFloat(tick.rangeLocation) + self.topInset))
}
}.stroke()
// ForEach(self.tickList(geometry: geometry)) { tickStruct in
Expand All @@ -63,10 +63,10 @@ public struct VerticalAxisView<ScaleType: Scale>: View {
struct VerticalAxisView_Previews: PreviewProvider {
static var previews: some View {
Group {
VerticalAxisView(scale: LinearScale(domain: 0 ... 1.0, isClamped: false))
VerticalAxisView(scale: LinearScale.create(0 ... 1.0))
.frame(width: 100, height: 400, alignment: .center)

VerticalAxisView(scale: LogScale(domain: 1 ... 10.0, isClamped: false))
VerticalAxisView(scale: LogScale.DoubleScale(from: 0, to: 10, transform: .none))
.frame(width: 100, height: 400, alignment: .center)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftUIVizTests/HorizontalAxisViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension HorizontalAxisView: Inspectable {}

final class HorizontalAxisViewTests: XCTestCase {
func testHorizontalAxisView_init() throws {
let exampleView = HorizontalAxisView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false),
let exampleView = HorizontalAxisView(scale: LinearScale.create(0 ... 5.0),
leftInset: 25.0,
rightInset: 25.0)
let path = try exampleView.inspect().geometryReader().zStack().shape(0)
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftUIVizTests/HorizontalBandViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension HorizontalBandView: Inspectable {}

final class HorizontalBandViewTests: XCTestCase {
func testHorizontalBandView_init() throws {
let exampleView = HorizontalBandView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false))
let exampleView = HorizontalBandView(scale: LinearScale.create(0 ... 5.0))
XCTAssertNotNil(exampleView)
}
}
2 changes: 1 addition & 1 deletion Tests/SwiftUIVizTests/VerticalAxisViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension VerticalAxisView: Inspectable {}

final class VerticalAxisViewTests: XCTestCase {
func testVerticalAxisView_init() throws {
let exampleView = VerticalAxisView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false))
let exampleView = VerticalAxisView(scale: LinearScale.create(0 ... 5.0))
XCTAssertNotNil(exampleView)
}
}