11import './cytoscape.css' ;
22import { useEffect , useRef } from 'react' ;
33import cytoscape , { EdgeSingular , NodeSingular } from 'cytoscape' ;
4- import nodeEdgeHtmlLabel from 'cytoscape-node-edge-html-label' ;
54import expandCollapse from 'cytoscape-expand-collapse' ;
65import { Edge , CalmNode } from '../../contracts/contracts.js' ;
76import { LayoutCorrectionService } from '../../services/layout-correction-service.js' ;
87
98// Initialize Cytoscape plugins
10- nodeEdgeHtmlLabel ( cytoscape ) ;
119expandCollapse ( cytoscape ) ;
1210
1311// Layout configuration
@@ -21,6 +19,8 @@ const breadthFirstLayout = {
2119 padding : 30 ,
2220 spacingFactor : 1.25 ,
2321} ;
22+ // Text font size for node and edge labels
23+ const textFontSize = '20px' ;
2424
2525export interface CytoscapeRendererProps {
2626 isNodeDescActive : boolean ;
@@ -31,16 +31,6 @@ export interface CytoscapeRendererProps {
3131 edgeClickedCallback : ( x : CalmNode [ 'data' ] | Edge [ 'data' ] ) => void ;
3232}
3333
34- function getNodeLabelTemplateGenerator ( selected : boolean , includeDescription : boolean ) {
35- return ( data : CalmNode [ 'data' ] ) => `
36- <div class="node element ${ selected ? 'selected-node' : '' } ">
37- <p class="title">${ data . label } </p>
38- <p class="type">${ data . type } </p>
39- <p class="description">${ includeDescription ? data . description : '' } </p>
40- </div>
41- ` ;
42- }
43-
4434function getEdgeStyle ( showDescription : boolean ) : cytoscape . Css . Edge {
4535 return {
4636 width : 2 ,
@@ -51,6 +41,7 @@ function getEdgeStyle(showDescription: boolean): cytoscape.Css.Edge {
5141 'text-background-color' : 'white' ,
5242 'text-background-opacity' : 1 ,
5343 'text-background-padding' : '5px' ,
44+ 'font-size' : textFontSize ,
5445 } ;
5546}
5647
@@ -64,6 +55,11 @@ function getNodeStyle(showDescription: boolean): cytoscape.Css.Node {
6455 'text-wrap' : 'wrap' ,
6556 'text-max-width' : '180px' ,
6657 'font-family' : 'Arial' ,
58+ 'background-color' : '#f5f5f5' ,
59+ 'border-color' : 'black' ,
60+ 'border-width' : 1 ,
61+ 'padding' : '10px' ,
62+ 'font-size' : textFontSize ,
6763 width : '200px' ,
6864 height : 'label' ,
6965 shape : 'rectangle' ,
@@ -102,6 +98,7 @@ export function CytoscapeRenderer({
10298 selector : ':parent' ,
10399 style : {
104100 label : 'data(label)' ,
101+ "background-color" : 'white' ,
105102 } ,
106103 } ,
107104 ] ,
@@ -121,23 +118,6 @@ export function CytoscapeRenderer({
121118 edgeClickedCallback ( edge ?. data ( ) ) ;
122119 } ) ;
123120
124- // This function comes from a plugin which doesn't have proper types, which is why the hacky casting is needed
125- // eslint-disable-next-line @typescript-eslint/no-explicit-any
126- ( cy as unknown as any ) . nodeHtmlLabel ( [
127- {
128- query : '.node' ,
129- valign : 'top' ,
130- valignBox : 'top' ,
131- tpl : getNodeLabelTemplateGenerator ( false , isNodeDescActive ) ,
132- } ,
133- {
134- query : '.node:selected' ,
135- valign : 'top' ,
136- valignBox : 'top' ,
137- tpl : getNodeLabelTemplateGenerator ( true , isNodeDescActive ) ,
138- } ,
139- ] ) ;
140-
141121 layoutCorrectionService . calculateAndUpdateNodePositions ( cy , nodes ) ;
142122 } , [
143123 nodes ,
0 commit comments