Skip to content

Commit 8b1a04e

Browse files
committed
Experimental styling and removal of cytoscape-node-edge-html-label
1 parent 0a8a9bc commit 8b1a04e

File tree

3 files changed

+14
-51
lines changed

3 files changed

+14
-51
lines changed

calm-hub-ui/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"cytoscape-cola": "^2.5.1",
2525
"cytoscape-dagre": "^2.5.0",
2626
"cytoscape-expand-collapse": "^4.1.1",
27-
"cytoscape-node-edge-html-label": "^1.0.6",
2827
"oidc-client": "^1.11.5",
2928
"react": "^18.2.0",
3029
"react-dom": "^18.2.0",

calm-hub-ui/src/visualizer/components/cytoscape-renderer/CytoscapeRenderer.tsx

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import './cytoscape.css';
22
import { useEffect, useRef } from 'react';
33
import cytoscape, { EdgeSingular, NodeSingular } from 'cytoscape';
4-
import nodeEdgeHtmlLabel from 'cytoscape-node-edge-html-label';
54
import expandCollapse from 'cytoscape-expand-collapse';
65
import { Edge, CalmNode } from '../../contracts/contracts.js';
76
import { LayoutCorrectionService } from '../../services/layout-correction-service.js';
87

98
// Initialize Cytoscape plugins
10-
nodeEdgeHtmlLabel(cytoscape);
119
expandCollapse(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

2525
export 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-
4434
function 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,

package-lock.json

Lines changed: 5 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)