@@ -277,7 +277,7 @@ grapher.Node = class {
277
277
}
278
278
279
279
list ( ) {
280
- const block = new grapher . Node . List ( ) ;
280
+ const block = new grapher . ArgumentList ( ) ;
281
281
this . _blocks . push ( block ) ;
282
282
return block ;
283
283
}
@@ -524,17 +524,19 @@ grapher.Node.Header.Entry = class {
524
524
}
525
525
} ;
526
526
527
- grapher . Node . List = class {
527
+ grapher . ArgumentList = class {
528
528
529
529
constructor ( ) {
530
530
this . _items = [ ] ;
531
531
this . _events = { } ;
532
532
}
533
533
534
- add ( name , value , tooltip , separator ) {
535
- const item = new grapher . Node . List . Item ( name , value , tooltip , separator ) ;
536
- this . _items . push ( item ) ;
537
- return item ;
534
+ argument ( name , value ) {
535
+ return new grapher . Argument ( name , value ) ;
536
+ }
537
+
538
+ add ( value ) {
539
+ this . _items . push ( value ) ;
538
540
}
539
541
540
542
on ( event , callback ) {
@@ -553,7 +555,7 @@ grapher.Node.List = class {
553
555
build ( document , parent ) {
554
556
this . _document = document ;
555
557
this . element = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' ) ;
556
- this . element . setAttribute ( 'class' , 'node-attribute -list' ) ;
558
+ this . element . setAttribute ( 'class' , 'node-argument -list' ) ;
557
559
if ( this . _events . click ) {
558
560
this . element . addEventListener ( 'click' , ( e ) => {
559
561
e . stopPropagation ( ) ;
@@ -564,38 +566,7 @@ grapher.Node.List = class {
564
566
this . element . appendChild ( this . background ) ;
565
567
parent . appendChild ( this . element ) ;
566
568
for ( const item of this . _items ) {
567
- const group = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' ) ;
568
- group . setAttribute ( 'class' , 'node-attribute' ) ;
569
- const text = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'text' ) ;
570
- text . setAttribute ( 'xml:space' , 'preserve' ) ;
571
- if ( item . tooltip ) {
572
- const title = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'title' ) ;
573
- title . textContent = item . tooltip ;
574
- text . appendChild ( title ) ;
575
- }
576
- const colon = item . type === 'node' || item . type === 'node[]' ;
577
- const name = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'tspan' ) ;
578
- name . textContent = colon ? `${ item . name } :` : item . name ;
579
- if ( item . separator . trim ( ) !== '=' && ! colon ) {
580
- name . style . fontWeight = 'bold' ;
581
- }
582
- text . appendChild ( name ) ;
583
- group . appendChild ( text ) ;
584
- this . element . appendChild ( group ) ;
585
- item . group = group ;
586
- item . text = text ;
587
- if ( item . type === 'node' ) {
588
- const node = item . value ;
589
- node . build ( document , item . group ) ;
590
- } else if ( item . type === 'node[]' ) {
591
- for ( const node of item . value ) {
592
- node . build ( document , item . group ) ;
593
- }
594
- } else {
595
- const tspan = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'tspan' ) ;
596
- tspan . textContent = item . separator + item . value ;
597
- item . text . appendChild ( tspan ) ;
598
- }
569
+ item . build ( document , this . element ) ;
599
570
}
600
571
if ( ! this . first ) {
601
572
this . line = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'line' ) ;
@@ -697,19 +668,59 @@ grapher.Node.List = class {
697
668
}
698
669
} ;
699
670
700
- grapher . Node . List . Item = class {
671
+ grapher . Argument = class {
701
672
702
- constructor ( name , value , tooltip , separator ) {
673
+ constructor ( name , value ) {
703
674
this . name = name ;
704
675
this . value = value ;
705
- this . tooltip = tooltip ;
706
- this . separator = separator ;
707
676
if ( value instanceof grapher . Node ) {
708
677
this . type = 'node' ;
709
678
} else if ( Array . isArray ( value ) && value . every ( ( value ) => value instanceof grapher . Node ) ) {
710
679
this . type = 'node[]' ;
711
680
}
712
681
}
682
+
683
+ build ( document , parent ) {
684
+ const group = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'g' ) ;
685
+ group . setAttribute ( 'class' , 'node-argument' ) ;
686
+ const text = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'text' ) ;
687
+ text . setAttribute ( 'xml:space' , 'preserve' ) ;
688
+ if ( this . tooltip ) {
689
+ const title = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'title' ) ;
690
+ title . textContent = this . tooltip ;
691
+ text . appendChild ( title ) ;
692
+ }
693
+ const colon = this . type === 'node' || this . type === 'node[]' ;
694
+ const name = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'tspan' ) ;
695
+ name . textContent = colon ? `${ this . name } :` : this . name ;
696
+ if ( this . separator && this . separator . trim ( ) !== '=' && ! colon ) {
697
+ name . style . fontWeight = 'bold' ;
698
+ }
699
+ text . appendChild ( name ) ;
700
+ group . appendChild ( text ) ;
701
+ parent . appendChild ( group ) ;
702
+ this . group = group ;
703
+ this . text = text ;
704
+ switch ( this . type ) {
705
+ case 'node' : {
706
+ const node = this . value ;
707
+ node . build ( document , this . group ) ;
708
+ break ;
709
+ }
710
+ case 'node[]' : {
711
+ for ( const node of this . value ) {
712
+ node . build ( document , this . group ) ;
713
+ }
714
+ break ;
715
+ }
716
+ default : {
717
+ const tspan = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'tspan' ) ;
718
+ tspan . textContent = ( this . separator || '' ) + this . value ;
719
+ this . text . appendChild ( tspan ) ;
720
+ break ;
721
+ }
722
+ }
723
+ }
713
724
} ;
714
725
715
726
grapher . Node . Canvas = class {
@@ -947,4 +958,4 @@ grapher.Edge.Path = class {
947
958
}
948
959
} ;
949
960
950
- export const { Graph, Node, Edge } = grapher ;
961
+ export const { Graph, Node, Edge, Argument } = grapher ;
0 commit comments