@@ -452,26 +452,96 @@ export function createVisualization() {
452452 /* handler functions */
453453 /* -------------------------------------------------------------------------- */
454454
455+ // Helper function to detect active tab and get appropriate taxonomy
456+ function getActiveTaxonomy ( ) {
457+ const elements = document . getElementsByName ( "tab" )
458+ for ( let i = 0 ; i < elements . length ; i ++ ) {
459+ if ( elements . item ( i ) . checked ) {
460+ if ( elements . item ( i ) . value === "interaction" ) {
461+ return {
462+ root : window . interactionRoot ,
463+ isInteraction : true
464+ }
465+ }
466+ }
467+ }
468+ return {
469+ root : window . root ,
470+ isInteraction : false
471+ }
472+ }
473+
455474 document . getElementById ( "reset" ) . addEventListener ( "click" , ( ) => {
456- focusNode ( window . root )
475+ const { root, isInteraction } = getActiveTaxonomy ( )
476+ if ( isInteraction && window . interactionRoot ) {
477+ // Import and use interaction taxonomy's focusNode
478+ import ( "./interaction_taxonomy_visualizer.js" ) . then ( module => {
479+ // The focusNode function is internal, so we'll trigger a refresh instead
480+ module . refreshInteractionVisualize ( )
481+ } )
482+ } else {
483+ focusNode ( root )
484+ }
457485 } )
458486
459487 document . getElementById ( "allExpand" ) . addEventListener ( "click" , ( ) => {
460- handleExpand ( window . root )
461- update ( null , window . root )
462- focusNode ( window . root )
488+ const { root, isInteraction } = getActiveTaxonomy ( )
489+ if ( isInteraction && window . interactionRoot ) {
490+ // Import interaction taxonomy functions
491+ import ( "./interaction_taxonomy_visualizer.js" ) . then ( module => {
492+ // We need to access the internal functions, so let's trigger a manual expand
493+ function expandAll ( d ) {
494+ if ( d . _children ) {
495+ d . children = d . _children
496+ }
497+ var children = d . children ? d . children : d . _children
498+ if ( children ) children . forEach ( expandAll )
499+ }
500+ expandAll ( window . interactionRoot )
501+ module . refreshInteractionVisualize ( )
502+ } )
503+ } else {
504+ handleExpand ( root )
505+ update ( null , root )
506+ focusNode ( root )
507+ }
463508 } )
464509
465510 document . getElementById ( "allCollapse" ) . addEventListener ( "click" , ( ) => {
466- window . root . x0 = dy / 2
467- window . root . y0 = 0
468- window . root . descendants ( ) . forEach ( ( d , i ) => {
469- d . id = i
470- d . _children = d . children
471- } )
472- window . root . children . forEach ( handleCollapse )
473- update ( null , window . root )
474- focusNode ( window . root )
511+ const { root, isInteraction } = getActiveTaxonomy ( )
512+ if ( isInteraction && window . interactionRoot ) {
513+ // Import interaction taxonomy functions
514+ import ( "./interaction_taxonomy_visualizer.js" ) . then ( module => {
515+ // Reset and collapse interaction taxonomy
516+ window . interactionRoot . x0 = dy / 2
517+ window . interactionRoot . y0 = 0
518+ window . interactionRoot . descendants ( ) . forEach ( ( d , i ) => {
519+ d . id = i
520+ d . _children = d . children
521+ } )
522+ function collapseAll ( d ) {
523+ if ( d . children ) {
524+ d . _children = d . children
525+ d . _children . forEach ( collapseAll )
526+ d . children = null
527+ }
528+ }
529+ if ( window . interactionRoot . children ) {
530+ window . interactionRoot . children . forEach ( collapseAll )
531+ }
532+ module . refreshInteractionVisualize ( )
533+ } )
534+ } else {
535+ root . x0 = dy / 2
536+ root . y0 = 0
537+ root . descendants ( ) . forEach ( ( d , i ) => {
538+ d . id = i
539+ d . _children = d . children
540+ } )
541+ root . children . forEach ( handleCollapse )
542+ update ( null , root )
543+ focusNode ( root )
544+ }
475545 } )
476546}
477547
0 commit comments