Skip to content

Commit

Permalink
Update graph.js
Browse files Browse the repository at this point in the history
  • Loading branch information
imaitland authored Feb 7, 2024
1 parent 55c8bcf commit 3d2a92c
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,6 @@ const Graph = ForceGraph()(document.getElementById("graph"))
.nodeVal("val")
.nodeLabel("title")
.nodeAutoColorBy("id")
.nodeCanvasObject((node, ctx, globalScale) => {
let label = emojimode ? node.icon : node.title;
let fontSize = emojimode ? 26 : 5;

ctx.font = `${fontSize}px Sans-Serif`;

//const textWidth = ctx.measureText(node_dimensions).width;
const textWidth = ctx.measureText(label).width;
const bckgDimensions = [textWidth, fontSize].map((n) => n + fontSize * 0.2); // some padding

ctx.fillStyle = "rgba(255, 255, 255, 0.0)";

ctx.fillRect(
node.x - bckgDimensions[0] / 2,
node.y - bckgDimensions[1] / 2,
...bckgDimensions
);

ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = node.color;
ctx.fillText(label, node.x, node.y);

node.__bckgDimensions = bckgDimensions; // to re-use in nodePointerAreaPaint
})
.nodePointerAreaPaint((node, color, ctx) => {
ctx.fillStyle = color;
const bckgDimensions = node.__bckgDimensions;
bckgDimensions &&
ctx.fillRect(
node.x - bckgDimensions[0] / 2,
node.y - bckgDimensions[1] / 2,
...bckgDimensions
);
})
.linkSource("source")
.linkTarget("target")
.linkWidth(1.3)
Expand Down

0 comments on commit 3d2a92c

Please sign in to comment.