Skip to content

Commit 71e6f81

Browse files
committed
Rename label and richLabel modifiers to annotation
1 parent 3806700 commit 71e6f81

File tree

6 files changed

+33
-58
lines changed

6 files changed

+33
-58
lines changed

Examples/ForceDirectedGraphExample/ForceDirectedGraphExample/MermaidVisualization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct MermaidVisualization: View {
8888
.symbol(.circle)
8989
.symbolSize(radius: 16)
9090
.foregroundStyle(Color(white: 1.0, opacity: 0.0))
91-
.richLabel(node, alignment: .center, offset: .zero) {
91+
.annotation(node, alignment: .center, offset: .zero) {
9292
getLabel(node)
9393
}
9494
}

Examples/ForceDirectedGraphExample/ForceDirectedGraphExample/Miserables.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ struct MiserableGraph: View {
5252
.symbolSize(radius: 8.0)
5353
.foregroundStyle(colors[node.group % colors.count])
5454
.stroke()
55-
.richLabel(node.id, offset: .zero) {
56-
if (graphData.links.filter({ l in
57-
return l.source == node.id || l.target == node.id}
58-
).count > 12) {
55+
.annotation(node.id, offset: .zero) {
56+
let connections = graphData.links.count { $0.source == node.id || $0.target == node.id }
57+
58+
if connections > 12 {
5959
self.getLabel(node.id)
6060
}
6161
}
@@ -73,6 +73,10 @@ struct MiserableGraph: View {
7373
stiffness: .weightedByDegree { _, _ in 1.0}
7474
)
7575
}
76+
.graphOverlay(content: { proxy in
77+
Rectangle().fill(.clear).contentShape(Rectangle())
78+
.withGraphDragGesture(proxy, of: String.self)
79+
})
7680
.ignoresSafeArea()
7781
.toolbar {
7882
GraphStateToggle(graphStates: stateMixin)

Sources/Grape/Modifiers/Effects/GrapeEffect.Label.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33

44
extension GraphContentEffect {
55
@usableFromInline
6-
internal struct Label {
6+
internal struct TextAnnotation {
77

88
@usableFromInline
99
let text: Text?
@@ -27,7 +27,7 @@ extension GraphContentEffect {
2727
}
2828

2929
@usableFromInline
30-
internal struct RichLabel {
30+
internal struct ViewAnnotation {
3131

3232
@usableFromInline
3333
let view: AnyView
@@ -57,7 +57,7 @@ extension GraphContentEffect {
5757

5858
}
5959

60-
extension GraphContentEffect.Label: GraphContentModifier {
60+
extension GraphContentEffect.TextAnnotation: GraphContentModifier {
6161
@inlinable
6262
public func _into<NodeID>(
6363
_ context: inout _GraphRenderingContext<NodeID>
@@ -89,7 +89,7 @@ extension GraphContentEffect.Label: GraphContentModifier {
8989
}
9090
}
9191

92-
extension GraphContentEffect.RichLabel: GraphContentModifier {
92+
extension GraphContentEffect.ViewAnnotation: GraphContentModifier {
9393
@inlinable
9494
public func _into<NodeID>(
9595
_ context: inout _GraphRenderingContext<NodeID>

Sources/Grape/Modifiers/GraphContent+GraphContentModifiers.swift

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -50,82 +50,52 @@ extension GraphContent {
5050
}
5151

5252
@inlinable
53-
@available(*, deprecated, message: "use foregroundStyle(_:)")
54-
public func fill(_ shading: GraphicsContext.Shading) -> some GraphContent<NodeID> {
55-
return ModifiedGraphContent(self, GraphContentEffect.Shading(shading))
56-
}
57-
58-
@inlinable
59-
public func label(
53+
public func annotation(
6054
_ text: Text?, alignment: Alignment = .bottom, offset: CGVector = .zero
6155
) -> some GraphContent<NodeID> {
62-
6356
return ModifiedGraphContent(
64-
self, GraphContentEffect.Label(text, alignment: alignment, offset: offset))
57+
self, GraphContentEffect.TextAnnotation(text, alignment: alignment, offset: offset))
6558
}
6659

6760
@inlinable
68-
public func label(
61+
public func annotation(
6962
_ text: Text?, alignment: Alignment = .bottom, offset: SIMD2<Double> = .zero
7063
) -> some GraphContent<NodeID> {
71-
72-
return label(text, alignment: alignment, offset: offset.cgVector)
64+
return annotation(text, alignment: alignment, offset: offset.cgVector)
7365
}
7466

7567
@inlinable
76-
public func label(
68+
public func annotation(
7769
_ string: String?, alignment: Alignment = .bottom, offset: CGVector = .zero
7870
) -> some GraphContent<NodeID> {
7971
return ModifiedGraphContent(
80-
self, GraphContentEffect.Label(nil, alignment: alignment, offset: offset))
81-
}
82-
83-
@inlinable
84-
public func label(
85-
_ string: String?, alignment: Alignment = .bottom, offset: SIMD2<Double> = .zero
86-
) -> some GraphContent<NodeID> {
87-
return label(string, alignment: alignment, offset: offset.cgVector)
72+
self, GraphContentEffect.TextAnnotation(nil, alignment: alignment, offset: offset))
8873
}
8974

9075
@inlinable
91-
public func label(
92-
_ alignment: Alignment = .bottom, offset: CGVector = .zero,
76+
public func annotation(
77+
alignment: Alignment = .bottom,
78+
offset: CGVector = .zero,
9379
@ViewBuilder _ content: () -> Text?
9480
) -> some GraphContent<NodeID> {
95-
9681
return ModifiedGraphContent(
97-
self, GraphContentEffect.Label(content(), alignment: alignment, offset: offset))
82+
self, GraphContentEffect.TextAnnotation(content(), alignment: alignment, offset: offset))
9883
}
9984

100-
@inlinable
101-
public func label(
102-
alignment: Alignment = .bottom, offset: SIMD2<Double> = .zero,
103-
@ViewBuilder _ content: () -> Text?
104-
) -> some GraphContent<NodeID> {
105-
return label(alignment, offset: offset.cgVector, content)
106-
}
10785

10886
@inlinable
109-
public func richLabel(
87+
@_disfavoredOverload
88+
public func annotation(
11089
_ tag: String,
111-
_ alignment: Alignment = .bottom,
90+
alignment: Alignment = .bottom,
11291
offset: CGVector = .zero,
11392
@ViewBuilder _ content: () -> some View
11493
) -> some GraphContent<NodeID> {
11594
return ModifiedGraphContent(
116-
self, GraphContentEffect.RichLabel(tag, content(), alignment: alignment, offset: offset)
95+
self, GraphContentEffect.ViewAnnotation(tag, content(), alignment: alignment, offset: offset)
11796
)
11897
}
11998

120-
@inlinable
121-
public func richLabel(
122-
_ tag: String,
123-
alignment: Alignment = .bottom,
124-
offset: SIMD2<Double> = .zero,
125-
@ViewBuilder _ content: () -> some View
126-
) -> some GraphContent<NodeID> {
127-
return richLabel(tag, alignment, offset: offset.cgVector, content)
128-
}
12999

130100
/// Sets the stroke style for this graph content.
131101
///
@@ -134,6 +104,7 @@ extension GraphContent {
134104
/// - When a `.clip` color is applied to link marks, the stroke will not be drawn.
135105
/// - When a `nil` stroke style is applied to node marks, the stroke style will be the same as the default stroke style.
136106
@inlinable
107+
@_disfavoredOverload
137108
public func stroke(
138109
_ color: StrokeColor = .clip,
139110
_ strokeStyle: StrokeStyle? = nil

Sources/Grape/Views/ForceDirectedGraphModel.findNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import simd
66
extension ForceDirectedGraphModel {
77

88
@inlinable
9-
internal func findNodeFromRichLabel(
9+
internal func findNodeFromViewAnnotation(
1010
at locationInSimulationCoordinate: SIMD2<Double>
1111
) -> GraphRenderingStates<NodeID>.StateID? {
1212
for (symbolID, box) in rasterizedSymbols {

Sources/Grape/Views/ForceDirectedGraphModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ extension ForceDirectedGraphModel: _AnyGraphProxyProtocol {
4646
@inlinable
4747
public func node(at locationInViewportCoordinate: CGPoint) -> AnyHashable? {
4848

49-
// Find from rich label first
50-
if let nodeIDFromRichLabel = findNodeFromRichLabel(
49+
// Find from view annotation first
50+
if let nodeIDFromViewAnnotation = findNodeFromViewAnnotation(
5151
at: finalTransform.invert(locationInViewportCoordinate.simd)
5252
) {
53-
if case .node(let nodeID) = nodeIDFromRichLabel {
53+
if case .node(let nodeID) = nodeIDFromViewAnnotation {
5454
return AnyHashable(nodeID)
5555
}
5656
}
@@ -784,7 +784,7 @@ extension ForceDirectedGraphModel {
784784
)
785785
}
786786
debugPrint(
787-
"Graph state revived. Note this might cause expensive rerendering when combined with `richLabel` with unstable id."
787+
"Graph state revived. Note this might cause expensive rerendering when combined with `annotation` with non-text views and unstable id."
788788
)
789789
}
790790

0 commit comments

Comments
 (0)