Skip to content
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
23 changes: 17 additions & 6 deletions dixhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
//go:embed static
var staticFS embed.FS

//go:embed template.html
var legacyTemplate string

// Server provides HTTP endpoints to visualize dependency relationships
type Server struct {
dix *dix.Dix
Expand Down Expand Up @@ -153,6 +156,7 @@ func (s *Server) setupRoutes() {
if err == nil {
s.mux.Handle(base+"/static/", http.StripPrefix(base+"/static/", http.FileServer(http.FS(staticRoot))))
}
s.mux.HandleFunc(base+"/next", s.HandleNextIndex)
s.mux.HandleFunc(base+"/api/search", s.HandleSearch)
s.mux.HandleFunc(base+"/api/modules", s.HandleModules)
s.mux.HandleFunc(base+"/api/ego", s.HandleEgo)
Expand Down Expand Up @@ -307,6 +311,18 @@ func atoiOr(s string, def int) int {
return def
}

// HandleNextIndex 服务五视图实验版 UI(/next)。
func (s *Server) HandleNextIndex(w http.ResponseWriter, r *http.Request) {
index, err := fs.ReadFile(staticFS, "static/index.html")
if err != nil {
http.Error(w, "index not found", http.StatusInternalServerError)
return
}
html := strings.ReplaceAll(string(index), "__DIX_BASE_PATH__", s.basePath)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, html)
}

// ServeHTTP implements http.Handler interface
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.mux.ServeHTTP(w, r)
Expand All @@ -321,12 +337,7 @@ func (s *Server) ListenAndServe(addr string) error {
func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
index, err := fs.ReadFile(staticFS, "static/index.html")
if err != nil {
http.Error(w, "index not found", http.StatusInternalServerError)
return
}
html := strings.ReplaceAll(string(index), "__DIX_BASE_PATH__", s.basePath)
html := strings.ReplaceAll(legacyTemplate, "__DIX_BASE_PATH__", s.basePath)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, html)
}
Expand Down
6 changes: 4 additions & 2 deletions dixhttp/static/js/views/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ DIX.views = DIX.views || {};

// ---------- 全局图构建(移植自旧版 renderGraph) ----------
function buildGlobal() {
const { providers, edges } = state.allData;
if (!state.allData) return { nodes: [], edges: [] };
const providers = state.allData.providers || [];
const edges = state.allData.edges || [];
const nodes = [], gedges = [];
const nodeMap = new Map();
const addType = label => {
Expand Down Expand Up @@ -291,7 +293,7 @@ DIX.views = DIX.views || {};
async function redraw() {
const canvas = document.getElementById("graph-canvas");
try {
if (state.mode !== "modules") await loadData();
await loadData(); // 详情抽屉也依赖 allData,所有模式都预载
let graph;
if (state.mode === "modules") {
graph = await buildModules();
Expand Down
2 changes: 1 addition & 1 deletion dixhttp/static/js/views/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DIX.views.search = {
box.querySelectorAll("button[data-i]").forEach(btn => {
btn.addEventListener("click", () => {
const h = hits[Number(btn.dataset.i)];
if (h.kind !== "type") return;
// SearchHit 的 label 即该依赖的类型名(provider 节点为其输出类型),可直接作邻域中心
location.hash = "#/graph?center=" + encodeURIComponent(h.label);
});
});
Expand Down
Loading
Loading