@@ -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 = / n o d e \[ t o p o V i e w e r R o l e = " ( [ ^ " ] + ) " \] / ;
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