@@ -6,14 +6,15 @@ import SwiftUI
6
6
@MainActor
7
7
public protocol _AnyGraphProxyProtocol {
8
8
@inlinable
9
- func locateNode (
9
+ func node (
10
10
at locationInViewportCoordinate: CGPoint
11
11
) -> AnyHashable ?
12
12
13
-
13
+ @inlinable
14
+ func node< ID: Hashable > ( of type: ID . Type , at locationInViewportCoordinate: CGPoint ) -> ID ?
14
15
15
16
@inlinable
16
- func setNodeFixation( nodeID: some Hashable , fixation: CGPoint ? , minimumAlpha: Double )
17
+ func setNodeFixation< ID : Hashable > ( nodeID: ID , fixation: CGPoint ? , minimumAlpha: Double )
17
18
18
19
@inlinable
19
20
var kineticAlpha : Double { get nonmutating set }
@@ -32,8 +33,18 @@ public protocol _AnyGraphProxyProtocol {
32
33
}
33
34
34
35
extension ForceDirectedGraphModel : _AnyGraphProxyProtocol {
36
+
35
37
@inlinable
36
- public func locateNode( at locationInViewportCoordinate: CGPoint ) -> AnyHashable ? {
38
+ public func node< ID> ( of type: ID . Type , at locationInViewportCoordinate: CGPoint ) -> ID ? where ID: Hashable {
39
+ if type. self == NodeID . self {
40
+ return findNode ( at: locationInViewportCoordinate) as! ID ?
41
+ } else {
42
+ return nil
43
+ }
44
+ }
45
+
46
+ @inlinable
47
+ public func node( at locationInViewportCoordinate: CGPoint ) -> AnyHashable ? {
37
48
38
49
// Find from rich label first
39
50
if let nodeIDFromRichLabel = findNodeFromRichLabel (
@@ -52,7 +63,7 @@ extension ForceDirectedGraphModel: _AnyGraphProxyProtocol {
52
63
}
53
64
54
65
@inlinable
55
- public func setNodeFixation( nodeID: some Hashable , fixation: CGPoint ? , minimumAlpha: Double ) {
66
+ public func setNodeFixation< ID > ( nodeID: ID , fixation: CGPoint ? , minimumAlpha: Double ) {
56
67
guard let nodeID = nodeID as? NodeID else {
57
68
return
58
69
}
@@ -201,7 +212,7 @@ public final class ForceDirectedGraphModel<NodeID: Hashable> {
201
212
let ticksPerSecond : Double
202
213
203
214
@usableFromInline
204
- // @MainActor
215
+ @MainActor
205
216
var scheduledTimer : Timer ? = nil
206
217
207
218
@usableFromInline
@@ -329,6 +340,7 @@ public final class ForceDirectedGraphModel<NodeID: Hashable> {
329
340
@inlinable
330
341
deinit {
331
342
print ( " deinit " )
343
+
332
344
let _ = MainActor . assumeIsolated {
333
345
scheduledTimer? . invalidate ( )
334
346
}
@@ -604,11 +616,11 @@ extension ForceDirectedGraphModel {
604
616
width: physicalWidth, height: physicalHeight)
605
617
606
618
let rect = CGRect (
607
- x: center. x + offset. x + textImageOffset. x, // - physicalWidth / 2,
608
- y: - center . y - offset . y - textImageOffset. y, // - physicalHeight
609
- width: physicalWidth,
610
- height: physicalHeight
611
- )
619
+ x: center. x + offset. x + textImageOffset. x, // - physicalWidth / 2,
620
+ y: - center . y - offset . y - textImageOffset. y, // - physicalHeight
621
+ width: physicalWidth,
622
+ height: physicalHeight
623
+ )
612
624
cgContext. draw (
613
625
rasterizedSymbol,
614
626
in: rect
@@ -658,11 +670,11 @@ extension ForceDirectedGraphModel {
658
670
width: physicalWidth, height: physicalHeight)
659
671
660
672
let rect = CGRect (
661
- x: pos. x + offset. x + textImageOffset. x, // - physicalWidth / 2,
662
- y: - pos . y - offset . y - textImageOffset. y, // - physicalHeight
663
- width: physicalWidth,
664
- height: physicalHeight
665
- )
673
+ x: pos. x + offset. x + textImageOffset. x, // - physicalWidth / 2,
674
+ y: - pos . y - offset . y - textImageOffset. y, // - physicalHeight
675
+ width: physicalWidth,
676
+ height: physicalHeight
677
+ )
666
678
667
679
cgContext. draw (
668
680
rasterizedSymbol,
@@ -692,7 +704,6 @@ extension ForceDirectedGraphModel {
692
704
let textImageOffset = textOffsetParams. alignment. textImageOffsetInCGContext (
693
705
width: physicalWidth, height: physicalHeight)
694
706
695
-
696
707
let rect = CGRect (
697
708
x: center. x + offset. x + textImageOffset. x, // - physicalWidth / 2,
698
709
y: - center . y - offset . y - textImageOffset. y, // - physicalHeight
0 commit comments