Files
lan-manager/web/node_modules/@antv/algorithm/es/adjacent-matrix.js
openclaw 0a5f6a8047 Initial commit: Lan-manager project code
- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs

Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
2026-04-20 00:52:58 +08:00

32 lines
811 B
JavaScript

var adjMatrix = function adjMatrix(graphData, directed) {
var nodes = graphData.nodes,
edges = graphData.edges;
var matrix = [];
// map node with index in data.nodes
var nodeMap = {};
if (!nodes) {
throw new Error("invalid nodes data!");
}
if (nodes) {
nodes.forEach(function (node, i) {
nodeMap[node.id] = i;
var row = [];
matrix.push(row);
});
}
if (edges) {
edges.forEach(function (edge) {
var source = edge.source,
target = edge.target;
var sIndex = nodeMap[source];
var tIndex = nodeMap[target];
if (!sIndex && sIndex !== 0 || !tIndex && tIndex !== 0) return;
matrix[sIndex][tIndex] = 1;
if (!directed) {
matrix[tIndex][sIndex] = 1;
}
});
}
return matrix;
};
export default adjMatrix;