File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -265,19 +265,19 @@ export default function GraphView({
265265 textY = rotatedY ;
266266 }
267267
268- // Get text width
269- const label = graph . LabelsMap . get ( link . label ) !
270- let { textWidth } = label
271-
272- if ( ! textWidth ) {
273- textWidth = ctx . measureText ( link . label ) . width ;
274- graph . LabelsMap . set ( link . label , { ...label , textWidth } )
275- }
276-
277268 // Setup text properties to measure background size
278269 ctx . font = '2px Arial' ;
279270 const padding = 0.5 ;
280- const textHeight = 2 ; // Approximate height for 2px font
271+ // Get text width and height
272+ const label = graph . LabelsMap . get ( link . label ) !
273+ let { textWidth, textHeight } = label
274+
275+ if ( ! textWidth || ! textHeight ) {
276+ const { width, actualBoundingBoxAscent, actualBoundingBoxDescent } = ctx . measureText ( link . label )
277+ textWidth = width
278+ textHeight = actualBoundingBoxAscent + actualBoundingBoxDescent
279+ graph . LabelsMap . set ( link . label , { ...label , textWidth, textHeight } )
280+ }
281281
282282 // Save the current context state
283283 ctx . save ( ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export interface Category {
1414export interface Label {
1515 name : string ,
1616 textWidth : number ,
17+ textHeight : number ,
1718}
1819
1920export type Node = NodeObject < {
@@ -225,7 +226,7 @@ export class Graph {
225226
226227 let label = this . labelsMap . get ( edgeData . relation )
227228 if ( ! label ) {
228- label = { name : edgeData . relation , textWidth : 0 }
229+ label = { name : edgeData . relation , textWidth : 0 , textHeight : 0 }
229230 this . labelsMap . set ( edgeData . relation , label )
230231 this . labels . push ( label )
231232 }
You can’t perform that action at this time.
0 commit comments