Skip to content

Commit eb85808

Browse files
authored
Merge pull request #163 from asadarafat/topoeditor-layout-manager
Topoeditor layout manager
2 parents f75ce06 + 387966f commit eb85808

File tree

9 files changed

+1587
-487
lines changed

9 files changed

+1587
-487
lines changed

package-lock.json

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

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,21 @@
179179
"category": "Containerlab",
180180
"icon": "$(info)"
181181
},
182-
{
183-
"command": "containerlab.lab.graph.drawio.horizontal",
184-
"title": "Graph (draw.io, Horizontal)",
185-
"category": "Containerlab"
186-
},
187-
{
188-
"command": "containerlab.lab.graph.drawio.vertical",
189-
"title": "Graph (draw.io, Vertical)",
190-
"category": "Containerlab"
191-
},
192-
{
193-
"command": "containerlab.lab.graph.drawio.interactive",
194-
"title": "Graph (draw.io, Interactive)",
195-
"category": "Containerlab"
196-
},
182+
{
183+
"command": "containerlab.lab.graph.drawio.horizontal",
184+
"title": "Graph (draw.io, Horizontal)",
185+
"category": "Containerlab"
186+
},
187+
{
188+
"command": "containerlab.lab.graph.drawio.vertical",
189+
"title": "Graph (draw.io, Vertical)",
190+
"category": "Containerlab"
191+
},
192+
{
193+
"command": "containerlab.lab.graph.drawio.interactive",
194+
"title": "Graph (draw.io, Interactive)",
195+
"category": "Containerlab"
196+
},
197197
{
198198
"command": "containerlab.lab.graph.topoViewer",
199199
"title": "Graph (TopoViewer)",
@@ -1044,6 +1044,7 @@
10441044
"@types/vscode": "^1.100.0",
10451045
"@typescript-eslint/eslint-plugin": "^8.32.1",
10461046
"@typescript-eslint/parser": "^8.32.1",
1047+
"@vscode/vsce": "^3.5.0",
10471048
"chai": "^5.2.0",
10481049
"chai-as-promised": "^8.0.1",
10491050
"chai-http": "^5.1.2",
@@ -1066,14 +1067,14 @@
10661067
"@types/cytoscape": "^3.21.9",
10671068
"@types/sinon": "^17.0.4",
10681069
"@types/sinon-chai": "^4.0.0",
1069-
"@vscode/vsce": "^3.5.0",
10701070
"ajv": "^8.17.1",
10711071
"ajv-formats": "^3.0.1",
10721072
"cytoscape": "^3.32.0",
10731073
"cytoscape-cola": "^2.5.1",
10741074
"cytoscape-cxtmenu": "^3.5.0",
10751075
"cytoscape-edgehandles": "^4.0.1",
10761076
"cytoscape-grid-guide": "^2.3.3",
1077+
"cytoscape-leaf": "^1.2.4",
10771078
"js-yaml": "^4.1.0",
10781079
"socket.io": "^4.8.1",
10791080
"ts-loader": "^9.5.2",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'cytoscape-leaf';

src/topoViewer/webview-ui/html-static/css/style.css

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ body {
6464
#cy {
6565
width: 100%;
6666
height: 100%;
67-
padding-bottom: 50px;
67+
padding-top: 10px;
68+
padding-bottom: 0px;
6869
position: absolute;
6970
z-index: 1;
7071
/* Background */
@@ -73,7 +74,8 @@ body {
7374
#cy-leaflet {
7475
width: 100%;
7576
height: 100%;
76-
padding-bottom: 50px;
77+
padding-top: 10px;
78+
padding-bottom: 0px;
7779
position: absolute;
7880
z-index: 0;
7981
/* Background */
@@ -537,6 +539,15 @@ body {
537539
/* Initially hidden */
538540
}
539541

542+
.select.is-small select {
543+
font-size: 0.75rem;
544+
padding-top: 0.4em;
545+
padding-bottom: 0.4em;
546+
line-height: 1.2;
547+
}
548+
549+
550+
540551
/* Editor Container
541552
-------------------------------------------------- */
542553
#editor-container {
@@ -593,12 +604,12 @@ body {
593604
background-color: rgba(24, 24, 24, 1);
594605
}
595606

596-
.panel-block {
607+
.panel {
608+
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.4);
597609
background-color: rgba(40, 40, 40, 1);
598610
}
599611

600-
.panel {
601-
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.4);
612+
.panel-block {
602613
background-color: rgba(40, 40, 40, 1);
603614
}
604615

@@ -670,13 +681,12 @@ body {
670681
background-color: rgba(70, 86, 246, 1);
671682
}
672683

673-
.panel-block {
674-
background-color: white;
684+
.panel {
675685
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
686+
background-color: white;
676687
}
677688

678-
.panel {
679-
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
689+
.panel-block {
680690
background-color: white;
681691
}
682692

src/topoViewerEditor/webview-ui/managerCytoscapeStyle.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import cytoscape from 'cytoscape';
55
/**
66
* Cytoscape styles for VS Code deployment.
77
*/
8-
export const cytoscapeStylesForVscode = [
8+
const cytoscapeStylesBase = [
99
{
1010
selector: "core",
1111
style: {
@@ -435,22 +435,55 @@ export const cytoscapeStylesForVscode = [
435435
}
436436
];
437437

438+
/**
439+
* Returns a cloned Cytoscape style array adjusted for the given theme.
440+
* When `theme` is "light" group nodes appear darker with higher opacity.
441+
*/
442+
export function getCytoscapeStyles(theme: 'light' | 'dark') {
443+
return cytoscapeStylesBase.map((def: any) => {
444+
const clone: any = { selector: def.selector, style: { ...(def.style || {}) } };
445+
if (def.selector === 'node[topoViewerRole="group"]') {
446+
if (theme === 'light') {
447+
clone.style['background-color'] = '#a6a6a6';
448+
clone.style['background-opacity'] = '0.4';
449+
clone.style['border-width'] = '0.5px';
450+
clone.style['border-color'] = '#aaaaaa';
451+
} else {
452+
clone.style['background-color'] = '#d9d9d9';
453+
clone.style['background-opacity'] = '0.2';
454+
}
455+
}
456+
return clone;
457+
});
458+
}
459+
438460
/**
439461
* Loads and applies Cytoscape styles to the provided Cytoscape instance.
440462
*
441463
* This method removes existing inline styles and applies the predefined VS Code styles.
442464
*
443465
* @param cy - The Cytoscape instance to style.
444466
*/
445-
export default async function loadCytoStyle(cy: cytoscape.Core): Promise<void> {
467+
export default async function loadCytoStyle(
468+
cy: cytoscape.Core,
469+
theme?: 'light' | 'dark'
470+
): Promise<void> {
446471
try {
447472
// Remove any existing inline styles.
448473
cy.nodes().removeStyle();
449474
cy.edges().removeStyle();
450475

451-
// Apply the predefined VS Code styles.
452-
cy.style().fromJson(cytoscapeStylesForVscode).update();
476+
const engine = (window as any).topoViewerEditorEngine;
477+
const forced = engine?.layoutAlgoManager?.geoTheme;
478+
const selectedTheme = theme || forced || (engine?.detectColorScheme?.() || 'light');
479+
const styles = getCytoscapeStyles(selectedTheme === 'light' ? 'light' : 'dark');
480+
cy.style().fromJson(styles).update();
453481
console.info("Cytoscape styles applied successfully.");
482+
483+
const layoutMgr = (window as any).topoViewerEditorEngine?.layoutAlgoManager;
484+
if (layoutMgr?.isGeoMapInitialized) {
485+
layoutMgr.applyGeoScale(true);
486+
}
454487
} catch (error) {
455488
console.error("Error applying Cytoscape styles:", error);
456489
}
@@ -469,7 +502,7 @@ export function extractNodeIcons(): string[] {
469502
const nodeTypes: string[] = [];
470503
const regex = /node\[topoViewerRole="([^"]+)"\]/;
471504

472-
for (const styleDef of cytoscapeStylesForVscode) {
505+
for (const styleDef of cytoscapeStylesBase) {
473506
if (typeof styleDef.selector === 'string') {
474507
const match = styleDef.selector.match(regex);
475508
if (match && match[1]) {

0 commit comments

Comments
 (0)