Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit dae8ef0

Browse files
committed
updating to match API updates in SwiftViz
1 parent 0ed2072 commit dae8ef0

File tree

8 files changed

+45
-35
lines changed

8 files changed

+45
-35
lines changed

Package.resolved

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ let package = Package(
1717
],
1818
dependencies: [
1919
// Dependencies declare other packages that this package depends on.
20-
.package(url: "https://github.com/swiftviz/SwiftViz", from: "0.0.0"),
20+
.package(url: "https://github.com/swiftviz/SwiftViz", branch: "APIiteration"),
21+
// .package(url: "https://github.com/swiftviz/SwiftViz", from: "0.0.0"),
2122
.package(url: "https://github.com/nalexn/ViewInspector", from: "0.0.0"),
2223
],
2324
targets: [

Sources/SwiftUIViz/HorizontalAxisView.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import SwiftUI
1010
import SwiftViz
1111

12-
public struct HorizontalAxisView<ScaleType: Scale>: View {
12+
public struct HorizontalAxisView<ScaleType: Scale>: View where ScaleType.InputType == Double, ScaleType.OutputType == Float {
1313
let leftInset: CGFloat
1414
let rightInset: CGFloat
1515
var scale: ScaleType
@@ -19,15 +19,15 @@ public struct HorizontalAxisView<ScaleType: Scale>: View {
1919
self.scale = scale
2020
}
2121

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

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

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

71-
HorizontalAxisView(scale: LogScale(domain: 1 ... 10.0, isClamped: false),
71+
HorizontalAxisView(scale: LogScale.DoubleScale(from: 0, to: 10),
7272
leftInset: 25.0,
7373
rightInset: 25.0)
7474
.frame(width: 400, height: 50, alignment: .center)

Sources/SwiftUIViz/HorizontalBandView.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
import SwiftUI
1010
import SwiftViz
1111

12-
public struct HorizontalBandView<ScaleType: Scale>: View {
12+
public struct HorizontalBandView<ScaleType: Scale>: View where ScaleType.InputType == Double, ScaleType.OutputType == Float {
1313
var scale: ScaleType
1414

1515
init(scale: ScaleType) {
1616
self.scale = scale
1717
}
1818

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

2727
public var body: some View {
@@ -33,8 +33,8 @@ public struct HorizontalBandView<ScaleType: Scale>: View {
3333
Path { path in
3434
// draw each tick in the line
3535
for tick in self.tickList(geometry: geometry) {
36-
path.move(to: CGPoint(x: tick.rangeLocation, y: 0))
37-
path.addLine(to: CGPoint(x: tick.rangeLocation, y: geometry.size.height))
36+
path.move(to: CGPoint(x: CGFloat(tick.rangeLocation), y: 0))
37+
path.addLine(to: CGPoint(x: CGFloat(tick.rangeLocation), y: geometry.size.height))
3838
}
3939
}.stroke(lineWidth: 0.5)
4040
}
@@ -49,15 +49,15 @@ public struct HorizontalBandView<ScaleType: Scale>: View {
4949
struct HorizontalBandView_Previews: PreviewProvider {
5050
static var previews: some View {
5151
Group {
52-
HorizontalBandView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false))
52+
HorizontalBandView(scale: LinearScale.create(0 ... 5.0))
5353
.frame(width: 400, height: 50, alignment: .center)
5454
.padding()
5555

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

60-
HorizontalBandView(scale: LogScale(domain: 0.1 ... 100.0, isClamped: false))
60+
HorizontalBandView(scale: LogScale.DoubleScale(from: 0.1, to: 100.0))
6161
.frame(width: 400, height: 50, alignment: .center)
6262
.padding()
6363
}

Sources/SwiftUIViz/VerticalAxisView.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import SwiftUI
1010
import SwiftViz
1111

12-
public struct VerticalAxisView<ScaleType: Scale>: View {
12+
public struct VerticalAxisView<ScaleType: Scale>: View where ScaleType.InputType == Double, ScaleType.OutputType == Float {
1313
let topInset: CGFloat
1414
let bottomInset: CGFloat
1515
let leftOffset: CGFloat
@@ -23,16 +23,16 @@ public struct VerticalAxisView<ScaleType: Scale>: View {
2323
leftOffset = 30
2424
tickLength = 5
2525
}
26-
27-
func tickList(geometry: GeometryProxy) -> [ScaleType.TickType] {
26+
27+
func tickList<InputType, OutputType>(geometry: GeometryProxy) -> [Tick<InputType, OutputType>] where ScaleType.InputType == InputType, ScaleType.OutputType == OutputType {
2828
// protect against Preview sending in stupid values
2929
// of geometry that can't be made into a reasonable range
3030
// otherwise the next line will crash preview...
3131
if geometry.size.width < topInset + bottomInset {
32-
return [ScaleType.TickType]()
32+
return [Tick<InputType, OutputType>]()
3333
}
34-
let geometryRange = 0.0 ... CGFloat(geometry.size.height - topInset - bottomInset)
35-
return scale.ticks(count: 10, range: geometryRange)
34+
let upperBound = Float(geometry.size.height - topInset - bottomInset)
35+
return scale.ticks(rangeLower: 0, rangeHigher: upperBound)
3636
}
3737

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

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

69-
VerticalAxisView(scale: LogScale(domain: 1 ... 10.0, isClamped: false))
69+
VerticalAxisView(scale: LogScale.DoubleScale(from: 0, to: 10, transform: .none))
7070
.frame(width: 100, height: 400, alignment: .center)
7171
}
7272
}

Tests/SwiftUIVizTests/HorizontalAxisViewTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension HorizontalAxisView: Inspectable {}
1717

1818
final class HorizontalAxisViewTests: XCTestCase {
1919
func testHorizontalAxisView_init() throws {
20-
let exampleView = HorizontalAxisView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false),
20+
let exampleView = HorizontalAxisView(scale: LinearScale.create(0 ... 5.0),
2121
leftInset: 25.0,
2222
rightInset: 25.0)
2323
let path = try exampleView.inspect().geometryReader().zStack().shape(0)

Tests/SwiftUIVizTests/HorizontalBandViewTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension HorizontalBandView: Inspectable {}
1717

1818
final class HorizontalBandViewTests: XCTestCase {
1919
func testHorizontalBandView_init() throws {
20-
let exampleView = HorizontalBandView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false))
20+
let exampleView = HorizontalBandView(scale: LinearScale.create(0 ... 5.0))
2121
XCTAssertNotNil(exampleView)
2222
}
2323
}

Tests/SwiftUIVizTests/VerticalAxisViewTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension VerticalAxisView: Inspectable {}
1717

1818
final class VerticalAxisViewTests: XCTestCase {
1919
func testVerticalAxisView_init() throws {
20-
let exampleView = VerticalAxisView(scale: LinearScale(domain: 0 ... 5.0, isClamped: false))
20+
let exampleView = VerticalAxisView(scale: LinearScale.create(0 ... 5.0))
2121
XCTAssertNotNil(exampleView)
2222
}
2323
}

0 commit comments

Comments
 (0)