diff --git a/Package.resolved b/Package.resolved index 7a717a9..2b476d5 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,22 @@ { "object": { "pins": [ + { + "package": "swift-numerics", + "repositoryURL": "https://github.com/apple/swift-numerics", + "state": { + "branch": null, + "revision": "0a5bc04095a675662cf24757cc0640aa2204253b", + "version": "1.0.2" + } + }, { "package": "SwiftViz", "repositoryURL": "https://github.com/swiftviz/SwiftViz", "state": { - "branch": null, - "revision": "771f8a76bc1b6880cc3b4ab1c03b21bd9cd3333b", - "version": "0.1.9" + "branch": "APIiteration", + "revision": "df713665fc46917ec4b439bd6b2d8a4892cb0ec1", + "version": null } }, { diff --git a/Package.swift b/Package.swift index e4f9e47..778bfc9 100644 --- a/Package.swift +++ b/Package.swift @@ -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: [ diff --git a/Sources/SwiftUIViz/HorizontalAxisView.swift b/Sources/SwiftUIViz/HorizontalAxisView.swift index 41998a6..72c3de5 100644 --- a/Sources/SwiftUIViz/HorizontalAxisView.swift +++ b/Sources/SwiftUIViz/HorizontalAxisView.swift @@ -9,7 +9,7 @@ import SwiftUI import SwiftViz -public struct HorizontalAxisView: View { +public struct HorizontalAxisView: View where ScaleType.InputType == Double, ScaleType.OutputType == Float { let leftInset: CGFloat let rightInset: CGFloat var scale: ScaleType @@ -19,15 +19,15 @@ public struct HorizontalAxisView: View { self.scale = scale } - func tickList(geometry: GeometryProxy) -> [ScaleType.TickType] { + func tickList(geometry: GeometryProxy) -> [Tick] 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]() } - 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 { @@ -46,8 +46,8 @@ public struct HorizontalAxisView: 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() } @@ -63,12 +63,12 @@ public struct HorizontalAxisView: 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) diff --git a/Sources/SwiftUIViz/HorizontalBandView.swift b/Sources/SwiftUIViz/HorizontalBandView.swift index cf264a4..ea94655 100644 --- a/Sources/SwiftUIViz/HorizontalBandView.swift +++ b/Sources/SwiftUIViz/HorizontalBandView.swift @@ -9,19 +9,19 @@ import SwiftUI import SwiftViz -public struct HorizontalBandView: View { +public struct HorizontalBandView: 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(geometry: GeometryProxy) -> [Tick] 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 { @@ -33,8 +33,8 @@ public struct HorizontalBandView: 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) } @@ -49,15 +49,15 @@ public struct HorizontalBandView: 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() } diff --git a/Sources/SwiftUIViz/VerticalAxisView.swift b/Sources/SwiftUIViz/VerticalAxisView.swift index f6a5df5..29ae2c0 100644 --- a/Sources/SwiftUIViz/VerticalAxisView.swift +++ b/Sources/SwiftUIViz/VerticalAxisView.swift @@ -9,7 +9,7 @@ import SwiftUI import SwiftViz -public struct VerticalAxisView: View { +public struct VerticalAxisView: View where ScaleType.InputType == Double, ScaleType.OutputType == Float { let topInset: CGFloat let bottomInset: CGFloat let leftOffset: CGFloat @@ -24,15 +24,15 @@ public struct VerticalAxisView: View { tickLength = 5 } - func tickList(geometry: GeometryProxy) -> [ScaleType.TickType] { + func tickList(geometry: GeometryProxy) -> [Tick] 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]() } - 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 { @@ -48,8 +48,8 @@ public struct VerticalAxisView: 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 @@ -63,10 +63,10 @@ public struct VerticalAxisView: 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) } } diff --git a/Tests/SwiftUIVizTests/HorizontalAxisViewTests.swift b/Tests/SwiftUIVizTests/HorizontalAxisViewTests.swift index 3e48a09..4716aca 100644 --- a/Tests/SwiftUIVizTests/HorizontalAxisViewTests.swift +++ b/Tests/SwiftUIVizTests/HorizontalAxisViewTests.swift @@ -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) diff --git a/Tests/SwiftUIVizTests/HorizontalBandViewTests.swift b/Tests/SwiftUIVizTests/HorizontalBandViewTests.swift index e41777a..a9ed3c7 100644 --- a/Tests/SwiftUIVizTests/HorizontalBandViewTests.swift +++ b/Tests/SwiftUIVizTests/HorizontalBandViewTests.swift @@ -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) } } diff --git a/Tests/SwiftUIVizTests/VerticalAxisViewTests.swift b/Tests/SwiftUIVizTests/VerticalAxisViewTests.swift index f16ccc6..2bf2e9c 100644 --- a/Tests/SwiftUIVizTests/VerticalAxisViewTests.swift +++ b/Tests/SwiftUIVizTests/VerticalAxisViewTests.swift @@ -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) } }