1- import { AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , EventEmitter , Input , OnDestroy , OnInit , Output } from '@angular/core' ;
1+ import { AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , effect , EventEmitter , Input , OnDestroy , Output } from '@angular/core' ;
22import cytoscape from "cytoscape" ;
33import fcose from "cytoscape-fcose" ;
44import { saveAs } from "file-saver" ;
55import { SettingsService } from "../../settings.service" ;
66import { ThemeService } from "../../theme.service" ;
7- import { Subject , takeUntil } from "rxjs" ;
87
98cytoscape . use ( fcose ) ;
109
@@ -15,8 +14,7 @@ cytoscape.use(fcose);
1514 standalone : false ,
1615 changeDetection : ChangeDetectionStrategy . OnPush
1716} )
18- export class CytoplotComponent implements OnInit , AfterViewInit , OnDestroy {
19- private destroy$ = new Subject < void > ( ) ;
17+ export class CytoplotComponent implements AfterViewInit , OnDestroy {
2018 private _dimensions = { width : 700 , height : 700 }
2119 @Output ( ) clickedID = new EventEmitter < string > ( )
2220 @Output ( ) ready = new EventEmitter < boolean > ( )
@@ -37,29 +35,30 @@ export class CytoplotComponent implements OnInit, AfterViewInit, OnDestroy {
3735 if ( this . _drawData ) {
3836 if ( this . _drawData . data . length > 2 ) {
3937 this . componentID = this . _drawData . id
38+ this . hidden = false
39+ this . cdr . markForCheck ( )
4040 setTimeout ( ( ) => {
4141 this . draw ( )
4242 } , 3000 )
4343 }
4444 }
4545 }
4646
47- constructor ( private settings : SettingsService , private themeService : ThemeService , private cdr : ChangeDetectorRef ) { }
48-
49- ngOnInit ( ) : void {
50- this . themeService . beforeThemeChange$ . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => {
51- this . hidden = true ;
52- if ( this . cy ) {
53- this . cy . destroy ( ) ;
54- this . cy = null ;
47+ constructor ( private settings : SettingsService , private themeService : ThemeService , private cdr : ChangeDetectorRef ) {
48+ effect ( ( ) => {
49+ const counter = this . themeService . beforeThemeChange ( ) ;
50+ if ( counter > 0 ) {
51+ this . hidden = true ;
52+ if ( this . cy ) {
53+ this . cy . destroy ( ) ;
54+ this . cy = null ;
55+ }
56+ this . cdr . markForCheck ( ) ;
5557 }
56- this . cdr . markForCheck ( ) ;
5758 } ) ;
5859 }
5960
6061 ngOnDestroy ( ) : void {
61- this . destroy$ . next ( ) ;
62- this . destroy$ . complete ( ) ;
6362 if ( this . cy ) {
6463 this . cy . destroy ( ) ;
6564 this . cy = null ;
@@ -70,11 +69,12 @@ export class CytoplotComponent implements OnInit, AfterViewInit, OnDestroy {
7069 }
7170
7271 draw ( ) {
73- console . log ( this . _drawData )
7472 const container = document . getElementById ( this . _drawData . id )
75- container ?. style . setProperty ( "width" , this . _dimensions . width + "px" )
76- container ?. style . setProperty ( "height" , this . _dimensions . height + "px" )
77- console . log ( container )
73+ if ( ! container ) {
74+ return
75+ }
76+ container . style . setProperty ( "width" , this . _dimensions . width + "px" )
77+ container . style . setProperty ( "height" , this . _dimensions . height + "px" )
7878 const ad = this
7979 if ( ! this . cy ) {
8080 this . cy = cytoscape (
0 commit comments