22// in batch display one just able to create images
33
44
5- import { version , HierarchyPainter , draw } from 'jsroot' ;
6-
5+ import { version , HierarchyPainter , draw , addDrawFunc } from 'jsroot' ;
6+ import { writeFileSync } from 'fs' ;
77
88console . log ( `JSROOT version ${ version } ` ) ;
99
@@ -14,22 +14,28 @@ const hp = new HierarchyPainter('hpainter');
1414hp . setDisplay ( 'batch' ) ;
1515
1616// catch draw function calls
17- hp . setDrawFunc ( ( dom , obj , opt ) => {
18- console . log ( `trying to draw ${ obj . _typename } ` ) ;
19- return draw ( dom , obj , opt ) ;
17+ addDrawFunc ( {
18+ name : '*' ,
19+ func : ( dom , obj , opt ) => {
20+ console . log ( `Actual draw of ${ obj . _typename } ` ) ;
21+ // if function return true no normal drawing will be performed
22+ // do not try to call `draw` function from here !!!
23+ // return true;
24+ }
2025} ) ;
2126
2227await hp . openRootFile ( 'https://root.cern/js/files/hsimple.root' ) ;
2328
2429// display of TH2 histogram
30+ console . log ( 'Invoke histogram drawing' ) ;
2531await hp . display ( 'hpxpy' ) ;
2632
2733await hp . expandItem ( 'ntuple' ) ;
2834
2935// invoking TTree::Draw
36+ console . log ( 'Invoke TLeaf drawing' ) ;
3037await hp . display ( 'ntuple/pz' ) ;
3138
32-
3339// should be BatchDisplay
3440const disp = hp . getDisplay ( ) ;
3541
@@ -38,5 +44,5 @@ for (let id = 0; id < disp.numFrames(); ++id) {
3844 console . log ( `Frame ${ id } create svg size ${ svg . length } ` ) ;
3945
4046 // one can save svg plain file
41- // writeFileSync(`frame${id}.svg`, svg);
47+ writeFileSync ( `frame${ id } .svg` , svg ) ;
4248}
0 commit comments