78 lines
2.0 KiB
JavaScript
78 lines
2.0 KiB
JavaScript
/*
|
|
// generate-graph-data.js
|
|
|
|
import fs from "fs";
|
|
import { buildGraphImpl } from "./methods/buildGraph.js";
|
|
import { analyzeGraph } from "./methods/analyzeGraph.js";
|
|
|
|
const flows = JSON.parse(fs.readFileSync("flows.json", "utf8"));
|
|
const statusMap = JSON.parse(fs.readFileSync("status.json", "utf8"));
|
|
|
|
const graph = buildGraphImpl(flows, statusMap);
|
|
const analysis = analyzeGraph(graph);
|
|
|
|
fs.writeFileSync(
|
|
"graph-data.js",
|
|
`const graphData = ${JSON.stringify(analysis, null, 2)};`
|
|
);
|
|
|
|
console.log("graph-data.js written");
|
|
*/
|
|
|
|
|
|
|
|
//@6
|
|
/*
|
|
Write out to: `graph-data.js`
|
|
Consumed by : `graph.html`
|
|
*/
|
|
|
|
import fs from "fs";
|
|
import { buildGraph } from "./graph-utils.js";
|
|
|
|
const g = buildGraph(); // your internal graph object
|
|
|
|
const nodes = [];
|
|
for (const [id, info] of g.nodes) {
|
|
nodes.push({
|
|
id,
|
|
label: info.label,
|
|
baseColor: info.types.has("form") ? "#cc5500"
|
|
: info.types.has("link") ? "#00aa44"
|
|
: "#0077cc",
|
|
fullUrl: info.fullUrl,
|
|
cluster: info.cluster,
|
|
types: [...info.types]
|
|
});
|
|
}
|
|
|
|
const edges = g.edges.map((e, i) => ({
|
|
id: "e" + i,
|
|
from: e.from,
|
|
to: e.to,
|
|
type: e.type
|
|
}));
|
|
|
|
// ----------------------------------------------------
|
|
// PATCH: add BROKEN_LINKS to the generated output
|
|
// ----------------------------------------------------
|
|
const out = `
|
|
const NODES = ${JSON.stringify(nodes, null, 2)};
|
|
const EDGES = ${JSON.stringify(edges, null, 2)};
|
|
const DEAD_ENDS = ${JSON.stringify(g.deadEnds, null, 2)};
|
|
const PAGE_RANK = ${JSON.stringify(g.pageRank, null, 2)};
|
|
const CYCLES = ${JSON.stringify(g.cycles, null, 2)};
|
|
const CYCLES_SET = new Set(CYCLES.flat());
|
|
const TOP_RANK_THRESHOLD = ${g.rankThreshold};
|
|
const BROKEN_LINKS = ${JSON.stringify(g.brokenLinks, null, 2)};
|
|
const NODE_INFO = {};
|
|
NODES.forEach(n => NODE_INFO[n.id] = n);
|
|
`;
|
|
|
|
fs.writeFileSync("graph-data.js", out);
|
|
console.log("graph-data.js written");
|
|
console.log("");
|
|
console.log("NEXT STEPS..");
|
|
console.log("open graph.html (to view graph , can view in browser from file explorer too)");
|
|
|