Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aghead and agtail #105

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cgraph/cgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@ func (e *Edge) SetNode(v *Node) {
e.wasm.SetNode(v.getWasm())
}

func (e *Edge) Head() (*Node, error) {
n, err := e.wasm.Head(context.Background())
if err != nil {
return nil, err
}
return toNode(n), nil
}

func (e *Edge) Tail() (*Node, error) {
n, err := e.wasm.Tail(context.Background())
if err != nil {
return nil, err
}
return toNode(n), nil
}

func (c *CommonFields) Disc() *Disc {
return toDisc(c.wasm.GetDisc())
}
Expand Down
62 changes: 62 additions & 0 deletions graphviz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,65 @@ func TestNodeDegree(t *testing.T) {
}
}
}

func TestEdgeSourceAndTarget(t *testing.T) {
ctx := context.Background()
graph, err := graphviz.New(ctx)
if err != nil {
t.Fatalf("Error: %+v", err)
}

g, err := graph.Graph()
if err != nil {
t.Fatalf("Error: %+v", err)
}

nodeA, err := g.CreateNodeByName("a")
if err != nil {
t.Fatalf("Error: %+v", err)
}

nodeB, err := g.CreateNodeByName("b")
if err != nil {
t.Fatalf("Error: %+v", err)
}

edge, err := g.CreateEdgeByName("edge", nodeA, nodeB)
if err != nil {
t.Fatalf("Error: %+v", err)
}

head, err := edge.Head()
if err != nil {
t.Fatalf("Error: %+v", err)
}
if head == nil {
t.Fatalf("Source is nil")
}

headName, err := head.Name()
if err != nil {
t.Fatalf("Error: %+v", err)
}

if headName != "b" {
t.Fatalf("Expected source name to be 'b', got '%s'", headName)
}

target, err := edge.Tail()
if err != nil {
t.Fatalf("Error: %+v", err)
}
if target == nil {
t.Fatalf("Target is nil")
}

tailName, err := target.Name()
if err != nil {
t.Fatalf("Error: %+v", err)
}

if tailName != "a" {
t.Fatalf("Expected target name to be 'a', got '%s'", tailName)
}
}
20 changes: 20 additions & 0 deletions internal/wasm/bind.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions internal/wasm/bind.proto
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,26 @@ option (nori.file).export = {
pointer: 1
}
}
method {
recv: "Edge"
name: "head"
alias: "aghead"
return {
kind: STRUCT
ref: "Node"
pointer: 1
}
}
method {
recv: "Edge"
name: "tail"
alias: "agtail"
return {
kind: STRUCT
ref: "Node"
pointer: 1
}
}
method {
recv: "Graph"
name: "idEdge"
Expand Down
20 changes: 20 additions & 0 deletions internal/wasm/build/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,26 @@ void wasm_bridge_Graph_edge(void * _arg0, void * _arg1, void * _arg2, void * _ar
*_arg5 = v;
}

void wasm_bridge_Edge_head(void * _arg0, void ** _arg1) {
Agedge_t * arg0;
arg0 = (Agedge_t *)_arg0;
Agnode_t * ret = aghead(
arg0
);
Agnode_t * v = (Agnode_t *)ret;
*_arg1 = v;
}

void wasm_bridge_Edge_tail(void * _arg0, void ** _arg1) {
Agedge_t * arg0;
arg0 = (Agedge_t *)_arg0;
Agnode_t * ret = agtail(
arg0
);
Agnode_t * v = (Agnode_t *)ret;
*_arg1 = v;
}

void wasm_bridge_Graph_idEdge(void * _arg0, void * _arg1, void * _arg2, unsigned long long int _arg3, int _arg4, void ** _arg5) {
Agraph_t * arg0;
arg0 = (Agraph_t *)_arg0;
Expand Down
Binary file modified internal/wasm/graphviz.wasm
Binary file not shown.
Loading