Skip to content

Commit 387966f

Browse files
committed
create layout manager in topoeditor
1 parent 276f498 commit 387966f

File tree

6 files changed

+504
-61
lines changed

6 files changed

+504
-61
lines changed

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

Lines changed: 10 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 */
@@ -602,12 +604,12 @@ body {
602604
background-color: rgba(24, 24, 24, 1);
603605
}
604606

605-
.panel-block {
607+
.panel {
608+
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.4);
606609
background-color: rgba(40, 40, 40, 1);
607610
}
608611

609-
.panel {
610-
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.4);
612+
.panel-block {
611613
background-color: rgba(40, 40, 40, 1);
612614
}
613615

@@ -679,13 +681,12 @@ body {
679681
background-color: rgba(70, 86, 246, 1);
680682
}
681683

682-
.panel-block {
683-
background-color: white;
684+
.panel {
684685
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
686+
background-color: white;
685687
}
686688

687-
.panel {
688-
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
689+
.panel-block {
689690
background-color: white;
690691
}
691692

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)