@@ -386,19 +386,32 @@ <h5 class="mb-0">
386386 data-parent ="#accordion "
387387 >
388388 < div class ="card-body ">
389- <!-- <div class="form-group">
390- <label for="colorMode">Color Mode</label>
391- <select id="colorMode" class="form-control form-control-sm skip"></select>
392- </div> -->
393389 < div class ="form-group ">
394- < label > Default Color</ label >
390+ < label for ="highlightMode "> Highlighting Example</ label >
391+ < select id ="highlightMode " class ="form-control form-control-sm skip ">
392+ < option value ="none "> No highlighting</ option >
393+ < option value ="leaves "> Highlight leaf nodes</ option >
394+ < option value ="monophyletic "> Highlight E. coli and Shigella branches+nodes</ option >
395+ </ select >
396+ </ div >
397+ < div class ="form-group ">
398+ < label > Default Node Color</ label >
395399 < input
396400 type ="color "
397- id ="defaultColor "
401+ id ="defaultNodeColor "
398402 class ="skip "
399403 value ="#4682B4 "
400404 >
401405 </ div >
406+ < div class ="form-group ">
407+ < label > Default Branch Color</ label >
408+ < input
409+ type ="color "
410+ id ="defaultBranchColor "
411+ class ="skip "
412+ value ="#cccccc "
413+ >
414+ </ div >
402415 < div class ="form-group ">
403416 < label > Highlight Color</ label >
404417 < input
@@ -408,13 +421,6 @@ <h5 class="mb-0">
408421 value ="#feb640 "
409422 >
410423 </ div >
411- < div class ="form-group ">
412- < div class ="switch ">
413- < label >
414- < input id ="highlightLeaves " type ="checkbox " class ="skip "> Highlight Leaves
415- </ label >
416- </ div >
417- </ div >
418424 </ div >
419425 </ div >
420426 </ div >
@@ -657,7 +663,7 @@ <h5 class="modal-title" id="exportModalLabel">Export</h5>
657663 fetch ( "life.nwk" ) . then ( response => response . text ( ) . then ( buildTree ) ) ;
658664 } ) ;
659665
660- [ "layout" , "mode" , "type" , "colorMode" ] . forEach ( thing => {
666+ [ "layout" , "mode" , "type" ] . forEach ( thing => {
661667 var title = "valid" + thing [ 0 ] . toUpperCase ( ) + thing . slice ( 1 ) + "s" ;
662668 d3 . select ( "#" + thing )
663669 . selectAll ( "option" )
@@ -683,8 +689,10 @@ <h5 class="modal-title" id="exportModalLabel">Export</h5>
683689 type : d3 . select ( "#type" ) . node ( ) . value ,
684690 colorOptions :
685691 {
686- colorMode : "list" ,
687- defaultColor : d3 . select ( "#defaultColor" ) . node ( ) . value ,
692+ nodeColorMode : "list" ,
693+ branchColorMode : "monophyletic" ,
694+ defaultNodeColor : d3 . select ( "#defaultNodeColor" ) . node ( ) . value ,
695+ defaultBranchColor : d3 . select ( "#defaultBranchColor" ) . node ( ) . value ,
688696 highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
689697 } ,
690698 leafNodes : d3 . select ( "#leafNodes" ) . node ( ) . checked ,
@@ -732,62 +740,86 @@ <h5 class="modal-title" id="exportModalLabel">Export</h5>
732740 tree . setAnimation ( cached ) ;
733741 } ) ;
734742
735- // might want this back when we have more color mode options
736- // for now, ill leave it out in favor of the highlight toggle
737- /* d3.select("#colorMode").on("input", function() {
738- // this could prove annoying, but ill leave it for now
739- if (this.value === "list") {
740- d3.select("#defaultColor").node().value = "#243127";
743+ // Checks if the given node, or all of its leaves, is an E. Coli or Shigella node.
744+ //
745+ // Parameters:
746+ // - node: The node to check.
747+ //
748+ // Returns:
749+ // - true if the node, or all of its leaves, is an E. Coli or Shigella node, false otherwise.
750+ isEColiOrShigellaNode = function ( node ) {
751+ // this bc its recursive and the children are organized differently
752+ let nodeData = node . __data__ ? node . __data__ . data : node ;
753+
754+ if ( nodeData . children . length === 0 ) {
755+ return nodeData . id . includes ( "Escherichia_coli" ) || nodeData . id . includes ( "Shigella" ) ;
741756 } else {
742- d3.select("#defaultColor").node().value = "#4682B4" ;
757+ return nodeData . children . every ( isEColiOrShigellaNode ) ;
743758 }
759+ }
744760
761+ d3 . select ( "#highlightMode" ) . on ( "input" , function ( ) {
762+ if ( this . value === "none" ) {
763+ tree . setColorOptions ( {
764+ nodeColorMode : "none" ,
765+ branchColorMode : "none" ,
766+ defaultNodeColor : d3 . select ( "#defaultNodeColor" ) . node ( ) . value ,
767+ defaultBranchColor : d3 . select ( "#defaultBranchColor" ) . node ( ) . value ,
768+ highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value
769+ } ) ;
770+ } else if ( this . value === "leaves" ) {
771+ tree . setColorOptions ( {
772+ nodeColorMode : "list" ,
773+ branchColorMode : "none" ,
774+ defaultNodeColor : d3 . select ( "#defaultNodeColor" ) . node ( ) . value ,
775+ defaultBranchColor : d3 . select ( "#defaultBranchColor" ) . node ( ) . value ,
776+ highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
777+ nodeList : tree . getNodeGUIDs ( true )
778+ } ) ;
779+ } else if ( this . value === "monophyletic" ) {
780+ tree . setColorOptions ( {
781+ nodeColorMode : "list" ,
782+ branchColorMode : "monophyletic" ,
783+ defaultNodeColor : d3 . select ( "#defaultNodeColor" ) . node ( ) . value ,
784+ defaultBranchColor : d3 . select ( "#defaultBranchColor" ) . node ( ) . value ,
785+ highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
786+ nodeList : tree . getNodeGUIDs ( false , isEColiOrShigellaNode )
787+ } )
788+ }
789+ } ) ;
790+
791+ d3 . select ( "#defaultNodeColor" ) . on ( "input" , function ( ) {
745792 tree . setColorOptions ( {
746- colorMode: this.value,
747- defaultColor: d3.select("#defaultColor").node().value,
748- highlightColor: d3.select("#highlightColor").node().value
793+ nodeColorMode : d3 . select ( "#highlightMode" ) . property ( "value" ) === "none" ? "none" : "list" ,
794+ branchColorMode : d3 . select ( "#highlightMode" ) . property ( "value" ) === "monophyletic" ? "monophyletic" : "none" ,
795+ defaultNodeColor : this . value ,
796+ defaultBranchColor : d3 . select ( "#defaultBranchColor" ) . node ( ) . value ,
797+ highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
798+ nodeList : d3 . select ( "#highlightMode" ) . property ( "value" ) === "monophyletic" ? tree . getNodeGUIDs ( false , isEColiOrShigellaNode ) : tree . getNodeGUIDs ( true )
749799 } ) ;
750800 } ) ;
751- */
752- d3 . select ( "#defaultColor " ) . on ( "input" , function ( ) {
801+
802+ d3 . select ( "#defaultBranchColor " ) . on ( "input" , function ( ) {
753803 tree . setColorOptions ( {
754- colorMode : d3 . select ( "#highlightLeaves" ) . node ( ) . value ? "list" : "none" ,
755- defaultColor : this . value ,
804+ nodeColorMode : d3 . select ( "#highlightMode" ) . property ( "value" ) === "none" ? "none" : "list" ,
805+ branchColorMode : d3 . select ( "#highlightMode" ) . property ( "value" ) === "monophyletic" ? "monophyletic" : "none" ,
806+ defaultNodeColor : d3 . select ( "#defaultNodeColor" ) . node ( ) . value ,
807+ defaultBranchColor : this . value ,
756808 highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
757- nodeList : tree . getNodeGUIDs ( true )
809+ nodeList : d3 . select ( "#highlightMode" ) . property ( "value" ) === "monophyletic" ? tree . getNodeGUIDs ( false , isEColiOrShigellaNode ) : tree . getNodeGUIDs ( true )
758810 } ) ;
759811 } ) ;
760812
761813 d3 . select ( "#highlightColor" ) . on ( "input" , function ( ) {
762- if ( ! d3 . select ( "#highlightLeaves" ) . property ( "checked" ) ) {
763- d3 . select ( "#highlightLeaves" ) . property ( "checked" , true ) ;
764- }
765814 tree . setColorOptions ( {
766- colorMode : d3 . select ( "#highlightLeaves" ) . node ( ) . value ? "list" : "none" ,
767- defaultColor : d3 . select ( "#defaultColor" ) . node ( ) . value ,
815+ nodeColorMode : d3 . select ( "#highlightMode" ) . property ( "value" ) === "none" ? "none" : "list" ,
816+ branchColorMode : d3 . select ( "#highlightMode" ) . property ( "value" ) === "monophyletic" ? "monophyletic" : "none" ,
817+ defaultNodeColor : d3 . select ( "#defaultNodeColor" ) . node ( ) . value ,
818+ defaultBranchColor : d3 . select ( "#defaultBranchColor" ) . node ( ) . value ,
768819 highlightColor : this . value ,
769- nodeList : tree . getNodeGUIDs ( true )
820+ nodeList : d3 . select ( "#highlightMode" ) . property ( "value" ) === "monophyletic" ? tree . getNodeGUIDs ( false , isEColiOrShigellaNode ) : tree . getNodeGUIDs ( true )
770821 } ) ;
771822 } ) ;
772-
773- d3 . select ( "#highlightLeaves" ) . on ( "input" , function ( ) {
774- // console.log("tree", tree.getNodeGUIDs(this.value));
775- if ( d3 . select ( "#highlightLeaves" ) . property ( "checked" ) ) {
776- tree . setColorOptions ( {
777- colorMode : "list" ,
778- defaultColor : d3 . select ( "#defaultColor" ) . node ( ) . value ,
779- highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
780- nodeList : tree . getNodeGUIDs ( true )
781- } )
782- } else {
783- tree . setColorOptions ( {
784- colorMode : "none" ,
785- defaultColor : d3 . select ( "#defaultColor" ) . node ( ) . value ,
786- highlightColor : d3 . select ( "#highlightColor" ) . node ( ) . value ,
787- nodeList : tree . getNodeGUIDs ( false )
788- } )
789- }
790- } ) ;
791823
792824 d3 . select ( "#branchNodeSize" ) . on ( "input" , function ( ) {
793825 tree . eachBranchNode ( ( node , data ) => {
0 commit comments