Open chaitali-pathak opened 4 years ago
I am not able to align text nodes. I have used const paintRing1 = useCallback((node, ctx, globalScale) => { // add ring just for highlighted nodes // debugger; ctx.beginPath(); ctx.arc(node.x, node.y, NODE_R 1.1, 0, 2 Math.PI, false); ctx.fillStyle = node === hoverNode ? 'black' : 'black'; if ((props.hideLabels) && node.x < 0) { return } const label = ${node.name}; const fontSize = 10 / globalScale; ctx.font = ${fontSize}px MarsCentra-Book; ctx.textBaseline = 'middle'; ctx.textAlign = 'start'; ctx.fillStyle = 'red'; //node.color; ctx.fillText(label, node.x, node.y + 15); // node.opacity = 0.4
${node.name}
${fontSize}px MarsCentra-Book
}, [hoverNode,highlightLinks]);
this as my NodeCanvasObject and nodeCanvasObjectMode={()=>"after"} What should I do to align my text nodes ? @vasturiano Please help me
@chaitali-pathak if you wish to center the text horizontally you can do ctx.textAlign = 'center'. https://www.w3schools.com/tags/canvas_textalign.asp
ctx.textAlign = 'center'
I am not able to align text nodes. I have used const paintRing1 = useCallback((node, ctx, globalScale) => { // add ring just for highlighted nodes // debugger; ctx.beginPath(); ctx.arc(node.x, node.y, NODE_R 1.1, 0, 2 Math.PI, false); ctx.fillStyle = node === hoverNode ? 'black' : 'black'; if ((props.hideLabels) && node.x < 0) { return } const label =
${node.name}
; const fontSize = 10 / globalScale; ctx.font =${fontSize}px MarsCentra-Book
; ctx.textBaseline = 'middle'; ctx.textAlign = 'start'; ctx.fillStyle = 'red'; //node.color; ctx.fillText(label, node.x, node.y + 15); // node.opacity = 0.4this as my NodeCanvasObject and nodeCanvasObjectMode={()=>"after"} What should I do to align my text nodes ? @vasturiano Please help me