11import { nodeTypes } from '../nodeDefinitions' ;
2+ import { getIconForNodeType } from '../components/ContextMenu' ;
23
34const FONT_FAMILY = "'Inter', sans-serif" ;
45
@@ -8,6 +9,7 @@ class Renderer {
89 this . isDarkTheme = isDarkTheme ;
910 this . isGridVisible = isGridVisible ;
1011 this . isNodeRoundingEnabled = isNodeRoundingEnabled ;
12+ this . renderDescription = false ;
1113 this . GRID_SIZE = 20 ;
1214 }
1315
@@ -51,8 +53,8 @@ class Renderer {
5153 const titleWidth = ctx . measureText ( node . type ) . width ;
5254
5355 ctx . font = `400 13px ${ FONT_FAMILY } ` ;
54- const descriptionLines = this . wrapText ( ctx , nodeType . description , 180 ) ;
55- const descriptionHeight = descriptionLines . length * 14 ;
56+ const descriptionLines = this . renderDescription ? this . wrapText ( ctx , nodeType . description , 180 ) : [ ] ;
57+ const descriptionHeight = this . renderDescription ? descriptionLines . length * 14 : 0 ;
5658
5759 const inputsHeight = nodeType . inputs . length * 20 ;
5860 const outputsHeight = nodeType . outputs . length * 20 ;
@@ -64,13 +66,13 @@ class Renderer {
6466 return height + ( isVisible ? 20 : 0 ) ;
6567 } , 0 ) : 0 ;
6668
67- const width = Math . max ( 200 , titleWidth + 20 , ...descriptionLines . map ( line => ctx . measureText ( line ) . width + 20 ) ) ;
69+ const width = Math . max ( 200 , titleWidth + 20 , ...( this . renderDescription ? descriptionLines . map ( line => ctx . measureText ( line ) . width + 20 ) : [ ] ) ) ;
6870 const height = 35 + descriptionHeight + Math . max ( inputsHeight , outputsHeight ) + propertiesHeight ;
6971
7072 return {
7173 width,
7274 height,
73- portStartY : 35 + descriptionHeight // This is the y-coordinate where ports start
75+ portStartY : 35 + descriptionHeight
7476 } ;
7577 }
7678
@@ -258,21 +260,33 @@ class Renderer {
258260
259261 let currentHeight = 0 ;
260262
261- // Node title
263+ // Node title with icon
262264 ctx . fillStyle = 'white' ;
263265 ctx . font = `600 14px ${ FONT_FAMILY } ` ;
264266 currentHeight += 20 ;
265- ctx . fillText ( node . type , node . x + 10 , node . y + currentHeight ) ;
266-
267- // Node description
268- ctx . font = `400 13px ${ FONT_FAMILY } ` ;
269- const descriptionLines = this . wrapText ( ctx , nodeType . description , width - 20 ) ;
270- descriptionLines . forEach ( ( line , index ) => {
271- currentHeight += 14 ;
272- ctx . fillText ( line , node . x + 10 , node . y + currentHeight + 3 ) ;
273- } ) ;
274-
275- currentHeight += 15 ; // Add some padding after description
267+
268+ // Draw icon using Font Awesome unicode
269+ const iconClass = getIconForNodeType ( node . type ) ;
270+ const iconUnicode = this . getIconUnicode ( iconClass ) ;
271+ ctx . font = `900 14px "Font Awesome 5 Free"` ;
272+ ctx . fillText ( iconUnicode , node . x + 10 , node . y + currentHeight ) ;
273+
274+ // Draw title after icon
275+ ctx . font = `600 14px ${ FONT_FAMILY } ` ;
276+ ctx . fillText ( node . type , node . x + 30 , node . y + currentHeight ) ;
277+
278+ // Node description - only render if renderDescription is true
279+ if ( this . renderDescription ) {
280+ ctx . font = `400 13px ${ FONT_FAMILY } ` ;
281+ const descriptionLines = this . wrapText ( ctx , nodeType . description , width - 20 ) ;
282+ descriptionLines . forEach ( ( line , index ) => {
283+ currentHeight += 14 ;
284+ ctx . fillText ( line , node . x + 10 , node . y + currentHeight + 3 ) ;
285+ } ) ;
286+ currentHeight += 15 ; // Add padding after description
287+ } else {
288+ currentHeight += 15 ; // Add minimal padding between title and ports
289+ }
276290
277291 // Input ports
278292 nodeType . inputs . forEach ( ( input , i ) => {
@@ -390,6 +404,32 @@ class Renderer {
390404 y + height < viewBounds . top - padding ||
391405 y > viewBounds . bottom + padding ) ;
392406 }
407+
408+ setRenderDescription ( renderDescription ) {
409+ this . renderDescription = renderDescription ;
410+ }
411+
412+ // Add this helper method to convert Font Awesome class names to unicode
413+ getIconUnicode ( iconClass ) {
414+ const iconMap = {
415+ 'fa-play' : '\uf04b' ,
416+ 'fa-terminal' : '\uf120' ,
417+ 'fa-cube' : '\uf1b2' ,
418+ 'fa-code' : '\uf121' ,
419+ 'fa-calculator' : '\uf1ec' ,
420+ 'fa-code-branch' : '\uf126' ,
421+ 'fa-sync' : '\uf021' ,
422+ 'fa-redo' : '\uf01e' ,
423+ 'fa-list' : '\uf03a' ,
424+ 'fa-globe' : '\uf0ac' ,
425+ 'fa-file-code' : '\uf1c9' ,
426+ 'fa-file-alt' : '\uf15c' ,
427+ 'fa-lock' : '\uf023' ,
428+ 'fa-unlock' : '\uf09c' ,
429+ 'fa-puzzle-piece' : '\uf12e'
430+ } ;
431+ return iconMap [ iconClass ] || iconMap [ 'fa-puzzle-piece' ] ;
432+ }
393433}
394434
395435export default Renderer ;
0 commit comments