1- import { Component , ElementRef , Input , Output , ViewChild , EventEmitter } from "@angular/core" ;
1+ import { Component , ElementRef , Input , Output , ViewChild , EventEmitter , ChangeDetectorRef } from '@angular/core' ;
2+ import { CommonModule } from "@angular/common" ;
3+ import { BehaviorSubject , Subject } from "rxjs" ;
24
35interface Dimensions {
46 width ?: number ;
@@ -28,7 +30,7 @@ export class TableauTerm {
2830 idxText ?: ElementRef < SVGTextElement > ;
2931
3032 @ViewChild ( 'termText' )
31- termText ! : ElementRef < SVGTextElement > ;
33+ termText ? : ElementRef < SVGTextElement > ;
3234
3335 @ViewChild ( 'labelText' )
3436 labelText ?: ElementRef < SVGTextElement > ;
@@ -47,8 +49,8 @@ export class TableauTerm {
4749 this . idxW = this . idxText ? this . idxText . nativeElement . getComputedTextLength ( ) + this . padding : 0 ;
4850 this . labelW = this . labelText ? this . labelText . nativeElement . getComputedTextLength ( ) + this . padding : 0 ;
4951 this . termX = this . idxW ;
50- this . labelX = this . termX + this . termText . nativeElement . getComputedTextLength ( ) + this . padding ;
51- this . totalW = this . labelW + this . idxW + this . termText . nativeElement . getComputedTextLength ( ) ;
52+ this . labelX = this . termText ? this . termX + this . termText . nativeElement . getComputedTextLength ( ) + this . padding : 0 ;
53+ this . totalW = this . termText ? this . labelW + this . idxW + this . termText . nativeElement . getComputedTextLength ( ) : 0 ;
5254
5355 this . onSize . emit ( { width : this . totalW } ) ;
5456 }
@@ -113,18 +115,26 @@ export class TableauTree {
113115@Component ( {
114116 selector : "la-tableau-svg" ,
115117 standalone : true ,
116- imports : [ TableauTree ] ,
118+ imports : [ CommonModule , TableauTree ] ,
117119 templateUrl : "./tableau-svg.component.svg" ,
118120 styleUrl : "./tableau-svg.component.scss" ,
119121} )
120122export class TableauSVG {
121123
122- treeDimensions : Dimensions = { width : 0 , height : 0 } ;
124+ treeDimensions$ : Subject < Dimensions > = new Subject ( ) ;
125+ treeDimensions : Dimensions = { width :0 , height : 0 } ;
126+
127+ constructor ( private cdref : ChangeDetectorRef ) { }
123128
124129 onTreeSize ( size : Dimensions ) {
125130 this . treeDimensions = size ;
126131 }
127132
133+ ngAfterViewChecked ( ) {
134+ this . treeDimensions$ . next ( this . treeDimensions ) ;
135+ this . cdref . detectChanges ( ) ;
136+ }
137+
128138 tree : any = {
129139 nodes : [
130140 { idx : 1 , term : 'every@man@(be@work)' } ,
0 commit comments