Skip to content

Commit

Permalink
Add @GraphContentBuilder<NodeID> to graph content body
Browse files Browse the repository at this point in the history
  • Loading branch information
li3zhen1 committed Jan 14, 2025
1 parent 962016a commit 1b8799e
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 42 deletions.
3 changes: 2 additions & 1 deletion Sources/Grape/Contents/AnyGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ public struct AnyGraphContent<NodeID: Hashable>: GraphContent {
self.storage = storage
}


@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}

@inlinable
Expand Down
15 changes: 0 additions & 15 deletions Sources/Grape/Contents/CompositedGraphContent.swift

This file was deleted.

1 change: 1 addition & 0 deletions Sources/Grape/Contents/GraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public protocol GraphContent<NodeID> {
func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>)

@inlinable
@GraphContentBuilder<NodeID>
var body: Body { get }
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Grape/Contents/LinkMark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ public struct LinkMark<NodeID: Hashable>: GraphContent & Identifiable {

@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}

// public enum LabelDisplayStrategy {
// case auto
// case specified(Bool)
Expand Down
5 changes: 3 additions & 2 deletions Sources/Grape/Contents/ModifiedGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ extension ModifiedGraphContent: GraphContent {
modifier._exit(&context)
}

@inlinable

@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}
}
4 changes: 2 additions & 2 deletions Sources/Grape/Contents/NodeMark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public struct NodeMark<NodeID: Hashable>: GraphContent, Identifiable, Equatable

@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}

@inlinable
public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>) {
context.nodeOperations.append(
Expand Down
3 changes: 2 additions & 1 deletion Sources/Grape/Contents/_ArrayGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ where C: GraphContent {
self.storage = storage
}


@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}

@inlinable
Expand Down
5 changes: 3 additions & 2 deletions Sources/Grape/Contents/_ConditionalGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ where C1: GraphContent, C2: GraphContent, C1.NodeID == C2.NodeID {
self.storage = storage
}

@inlinable

@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}

@inlinable
Expand Down
10 changes: 5 additions & 5 deletions Sources/Grape/Contents/_EmptyGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
struct _EmptyGraphContent<NodeID: Hashable>: GraphContent {
@inlinable
public init() {

}
@inlinable
public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>) {

}

@inlinable
@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}
}
}
15 changes: 13 additions & 2 deletions Sources/Grape/Contents/_IdentifiableNever.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
public enum _IdentifiableNever<ID: Hashable> { }
public enum _IdentifiableNever<ID: Hashable> {
@usableFromInline
internal init() {
fatalError()
}
}


@inlinable
public func _fatalError<ID>(of identityType: ID) -> _IdentifiableNever<ID> where ID: Hashable {
_IdentifiableNever<ID>()
}

extension _IdentifiableNever: GraphContent {
public typealias NodeID = ID

@inlinable
public var body: Self {
fatalError()
_IdentifiableNever<ID>()
}

@inlinable
Expand Down
5 changes: 3 additions & 2 deletions Sources/Grape/Contents/_OptionalGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ where C: GraphContent {
}
}

@inlinable

@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}
}
3 changes: 2 additions & 1 deletion Sources/Grape/Contents/_PairedGraphContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ where C1: GraphContent, C2: GraphContent, NodeID: Hashable, C1.NodeID == NodeID,
}



@inlinable
public var body: _IdentifiableNever<NodeID> {
fatalError()
_IdentifiableNever<_>()
}
}
27 changes: 21 additions & 6 deletions Tests/GrapeTests/ContentBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,31 @@ final class ContentBuilderTests: XCTestCase {
}

func testForEach() {
let _ = [
let arr = [
ID(id: 0),
ID(id: 1),
ID(id: 2),
]

// let _ = buildGraph {
// ForEach(data: arr) { i in
// NodeMark(id: i.id)
// }
// }
let _ = buildGraph {
Series(arr) { i in
NodeMark(id: i.id)
}
}
}

func testComposing() {
struct MyGraphContent: GraphContent {
var body: some GraphContent<Int> {
NodeMark(id: 1)
AnnotationNodeMark(id: 3, radius: 4.0) {
EmptyView()
}
}
}

let _ = buildGraph {
MyGraphContent()
}
}
}
3 changes: 1 addition & 2 deletions Tests/GrapeTests/GraphContentBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ final class GraphContentBuilderTests: XCTestCase {

}

struct MyGraphComponent: GraphComponent {
typealias NodeID = Int
struct MyGraphComponent: GraphContent {
var body: some GraphContent<Int> {
NodeMark(id: 0)
// .opacity(0.6)
Expand Down

0 comments on commit 1b8799e

Please sign in to comment.