MCPcopy Create free account
hub / github.com/adonovan/spaghetti / selectPkg

Function selectPkg

code.js:74–112  ·  view source on GitHub ↗
(json)

Source from the content-addressed store, hash-verified

72
73// selectPkg shows package info (if any) about the clicked node.
74function selectPkg(json) {
75 if (json.Package < 0) {
76 // Non-package "directory" node: clear the fields.
77 $('#pkgname').text("none")
78 $('#doc').text("")
79 $('#imports').html("")
80 $('#importedBy').html("")
81 $('#path').text("")
82 return
83 }
84
85 // A package node was selected.
86 var pkg = packages[json.Package]
87
88 // Show selected package.
89 $('#pkgname').text(pkg.PkgPath)
90
91 // Set link to Go package documentation.
92 $('#doc').html("<a title='doc' target='_blank' href='https://pkg.go.dev/" + pkg.PkgPath + "'><img src='https://pkg.go.dev/favicon.ico' width='16' height='16'/></a>")
93
94 // Show imports in a drop-down menu.
95 // Selecting an import acts like clicking on that package in the tree.
96 addImports($('#imports'), json.Imports)
97 addImports($('#importedBy'), json.ImportedBy)
98
99 // Show "break edges" buttons.
100 var html = ""
101 var path = [].concat(json.Path).reverse() // from root to selected package
102 for (var i in path) {
103 var p = packages[path[i]]
104 if (i > 0) {
105 html += "<button type='button' onclick='breakedge(" + path[i-1] + ", " + path[i] + ", false)'>break</button> "
106 + "<button type='button' onclick='breakedge(" + path[i-1] + ", " + path[i] + ", true)'>break all</button> "
107 + "⟶ "
108 }
109 html += "<code class='" + (json.Dominators.includes(path[i]) ? "dom" : "") + "'>" + p.PkgPath + "</code><br/>"
110 }
111 $('#path').html(html)
112}
113
114function breakedge(i, j, all) {
115 // Must reload the page since the graph has changed.

Callers 1

onDataFunction · 0.85

Calls 1

addImportsFunction · 0.85

Tested by

no test coverage detected