@@ -549,6 +549,8 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
549549 let isSearching = false
550550 let addSemanticSearch = false
551551 let searchString = ""
552+
553+ let searchTerms = [ ]
552554 let searchResults = 0
553555
554556 const radius = 7 ;
@@ -659,6 +661,26 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
659661 return linkedByIndex [ `${ b . id } ,${ a . id } ` ] ;
660662 }
661663
664+ function edgeBetweenSearchTerms ( sourceNode , targetNode ) {
665+ let found = false
666+ searchTerms . forEach ( element => {
667+ if ( ( sourceNode . id . toLowerCase ( ) . includes ( element ) ) && ( targetNode . id . toLowerCase ( ) . includes ( element ) ) ) {
668+ found = true
669+ }
670+ } ) ;
671+ return found
672+ }
673+
674+ function searchTermsIncludedInNodeTags ( sourceNode , targetNode ) {
675+ let found = false
676+ searchTerms . forEach ( element => {
677+ if ( ( stringIncludedInNodeTags ( element , sourceNode ) && stringIncludedInNodeTags ( element , targetNode ) ) ) {
678+ found = true
679+ }
680+ } ) ;
681+ return found
682+ }
683+
662684 /**
663685 * * MARK: - Drawing on canvas
664686 */
@@ -676,10 +698,9 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
676698 } else { // node search is active
677699
678700 if ( addSemanticSearch == true ) {
679- if ( // the edge is between two nodes that are included in the search
680- ( d . target . id . toLowerCase ( ) . includes ( searchString ) ) && ( d . source . id . toLowerCase ( ) . includes ( searchString ) ) ||
681- // the edge is between two nodes that includes the search in one of their semantic keywords
682- ( stringIncludedInNodeTags ( searchString , d . target ) && stringIncludedInNodeTags ( searchString , d . source ) ) )
701+
702+ // the edge is between two nodes that are included in the search OR the edge is between two nodes that includes the search in one of their semantic keywords
703+ if ( edgeBetweenSearchTerms ( d . source , d . target ) || searchTermsIncludedInNodeTags ( d . source , d . target ) )
683704 {
684705 context . strokeStyle = currentActiveEdgeColor
685706 context . fillStyle = currentActiveEdgeColor
@@ -690,7 +711,8 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
690711 // normal search without semantic
691712 } else {
692713 // the edge is between two nodes that are included in the search
693- if ( ( d . target . id . toLowerCase ( ) . includes ( searchString ) ) && ( d . source . id . toLowerCase ( ) . includes ( searchString ) ) ) {
714+ if ( edgeBetweenSearchTerms ( d . source , d . target ) )
715+ {
694716 context . strokeStyle = currentActiveEdgeColor
695717 context . fillStyle = currentActiveEdgeColor
696718 } else { // the edge is not connected to a node which is included in the search
@@ -725,66 +747,47 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
725747
726748 if ( closeNode != null && ( ( d . target . id == closeNode . id ) || ( d . source . id == closeNode . id ) ) ) { // draw an arrow if there is an edge that contains our hovered node
727749 drawArrowhead ( context , d . source , d . target , 5 )
728- } else if ( isSearching && ( ( d . target . id . toLowerCase ( ) . includes ( searchString ) ) && ( d . source . id . toLowerCase ( ) . includes ( searchString ) ) ) ) { // draw an arrow if searching is enabled and there's an egde between searched nodes
750+
751+ } else if ( isSearching && ( ( searchTermIncludedInNode ( d . target ) ) && ( searchTermIncludedInNode ( d . source ) ) ) ) { // draw an arrow if searching is enabled and there's an egde between searched nodes
729752 drawArrowhead ( context , d . source , d . target , 5 )
730- } else if ( d . source . id . toLowerCase ( ) in selectedNodesMap && d . target . id . toLowerCase ( ) in selectedNodesMap ) {
753+ }
754+
755+ else if ( d . source . id . toLowerCase ( ) in selectedNodesMap && d . target . id . toLowerCase ( ) in selectedNodesMap ) {
731756 drawArrowhead ( context , d . source , d . target , 5 )
732757 }
733758
734759 } ) ;
735760 }
736761
737- /**
738- * * MARK: - Drawing a heatmap
739- */
740-
741- function calculateHeatmapScore ( node ) {
742- let score = analysis_config [ 'heatmap' ] [ 'score' ] [ 'base' ]
743- let slocScore = 0
744- let fanoutScore = 0
745-
746- if ( analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'active' ] [ 'sloc' ] == true ) {
747- // add weighted sloc metric if present
748- if ( 'metric_sloc_in_entity' in node ) {
749- slocScore = node . metric_sloc_in_entity * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'sloc' ]
750- }
751- if ( 'metric_sloc_in_file' in node ) {
752- slocScore = node . metric_sloc_in_file * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'sloc' ]
753- }
754- }
755-
756- if ( analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'active' ] [ 'fan_out' ] == true ) {
757- // add weighted fan-out metric is present
758- if ( 'metric_fan_out_dependency_graph' in node ) {
759- fanoutScore = node . metric_fan_out_dependency_graph * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'fan_out' ]
760- }
761- if ( 'metric_fan_out_inheritance_graph' in node ) {
762- fanoutScore = node . metric_fan_out_inheritance_graph * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'fan_out' ]
763- }
764- if ( 'metric_fan_out_complete_graph' in node ) {
765- fanoutScore = node . metric_fan_out_complete_graph * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'fan_out' ]
762+ function normalSearch ( node ) {
763+ let found = false
764+ searchTerms . forEach ( element => {
765+ if ( node . id . toLowerCase ( ) . includes ( element ) ) {
766+ found = true
766767 }
767- }
768-
769- // limit the total score to the heatmap limit parameter, since the rendering seems to be buggy if this is exceeded
770- let totalScore = score + slocScore + fanoutScore
771- if ( totalScore > analysis_config [ 'heatmap' ] [ 'score' ] [ 'limit' ] ) {
772- totalScore = analysis_config [ 'heatmap' ] [ 'score' ] [ 'limit' ]
773- }
774-
775- return totalScore
768+ } ) ;
769+ return found
776770 }
777771
778- function drawHeatMap ( context ) {
779- heat . clear ( ) ;
780- currentGraph . nodes . forEach ( function ( node , i ) {
781- heat . add ( [ node . x , node . y , calculateHeatmapScore ( node ) ] )
782- } )
783-
784- heat . draw ( )
785-
786- // reset alpha from heatmap rendering
787- context . globalAlpha = 1 ;
772+ // the node is included in the current search OR if the search in included in one of the node's semantic tags
773+ function searchTermIncludedInNode ( node ) {
774+ let found = false
775+ searchTerms . forEach ( element => {
776+ if ( node . id . toLowerCase ( ) . includes ( element ) ) {
777+ found = true
778+ }
779+ } ) ;
780+ return found
781+ }
782+
783+ function searchTermIncludedInNodeTags ( node ) {
784+ let found = false
785+ searchTerms . forEach ( element => {
786+ if ( stringIncludedInNodeTags ( element , node ) ) {
787+ found = true
788+ }
789+ } ) ;
790+ return found
788791 }
789792
790793 function drawNodes ( context ) {
@@ -830,8 +833,8 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
830833
831834 } else { // searching for nodes
832835
833- // normal search
834- if ( addSemanticSearch == false && d . id . toLowerCase ( ) . includes ( searchString ) ) {
836+ // normal (non-semantic) search
837+ if ( addSemanticSearch == false && normalSearch ( d ) ) {
835838
836839 context . fillStyle = nodeColorByModularity ( d )
837840 context . strokeStyle = nodeStrokeStyle ;
@@ -843,10 +846,13 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
843846
844847 searchResults += 1
845848
846- } else if ( addSemanticSearch == true && ( d . id . toLowerCase ( ) . includes ( searchString ) || stringIncludedInNodeTags ( searchString , d ) ) ) { // add semantic search
849+ } else if ( addSemanticSearch == true && ( searchTermIncludedInNode ( d ) || searchTermIncludedInNodeTags ( d ) ) )
850+ // add semantic search
847851 // the node is included in the current search OR if the search in included in one of the node's semantic tags
848852 // draw a highlight circle behind the found node due to semantic search
849- if ( stringIncludedInNodeTags ( searchString , d ) ) {
853+ {
854+ if ( searchTermIncludedInNodeTags ( d ) )
855+ {
850856 context . fillStyle = currentActiveNodeLabelColor ;
851857 drawNodeLabel ( d . id , d . x + 14 , d . y - 7 )
852858
@@ -944,6 +950,60 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
944950 } ) ;
945951 }
946952
953+ /**
954+ * * MARK: - Drawing a heatmap
955+ */
956+
957+ function calculateHeatmapScore ( node ) {
958+ let score = analysis_config [ 'heatmap' ] [ 'score' ] [ 'base' ]
959+ let slocScore = 0
960+ let fanoutScore = 0
961+
962+ if ( analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'active' ] [ 'sloc' ] == true ) {
963+ // add weighted sloc metric if present
964+ if ( 'metric_sloc_in_entity' in node ) {
965+ slocScore = node . metric_sloc_in_entity * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'sloc' ]
966+ }
967+ if ( 'metric_sloc_in_file' in node ) {
968+ slocScore = node . metric_sloc_in_file * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'sloc' ]
969+ }
970+ }
971+
972+ if ( analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'active' ] [ 'fan_out' ] == true ) {
973+ // add weighted fan-out metric is present
974+ if ( 'metric_fan_out_dependency_graph' in node ) {
975+ fanoutScore = node . metric_fan_out_dependency_graph * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'fan_out' ]
976+ }
977+ if ( 'metric_fan_out_inheritance_graph' in node ) {
978+ fanoutScore = node . metric_fan_out_inheritance_graph * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'fan_out' ]
979+ }
980+ if ( 'metric_fan_out_complete_graph' in node ) {
981+ fanoutScore = node . metric_fan_out_complete_graph * analysis_config [ 'heatmap' ] [ 'metrics' ] [ 'weights' ] [ 'fan_out' ]
982+ }
983+ }
984+
985+ // limit the total score to the heatmap limit parameter, since the rendering seems to be buggy if this is exceeded
986+ let totalScore = score + slocScore + fanoutScore
987+ if ( totalScore > analysis_config [ 'heatmap' ] [ 'score' ] [ 'limit' ] ) {
988+ totalScore = analysis_config [ 'heatmap' ] [ 'score' ] [ 'limit' ]
989+ }
990+
991+ return totalScore
992+ }
993+
994+ function drawHeatMap ( context ) {
995+ heat . clear ( ) ;
996+ currentGraph . nodes . forEach ( function ( node , i ) {
997+ heat . add ( [ node . x , node . y , calculateHeatmapScore ( node ) ] )
998+ } )
999+
1000+ heat . draw ( )
1001+
1002+ // reset alpha from heatmap rendering
1003+ context . globalAlpha = 1 ;
1004+ }
1005+
1006+
9471007 function drawLink ( d ) {
9481008 context . moveTo ( d . source . x , d . source . y ) ;
9491009 context . lineTo ( d . target . x , d . target . y ) ;
@@ -1694,6 +1754,9 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
16941754 $ ( '#inputNodeSearch' ) . val ( '' )
16951755 $ ( '#inputNodeSearchLabel' ) . text ( 'Search inactive' )
16961756 searchString = ""
1757+
1758+ searchTerms = [ ]
1759+
16971760 isSearching = false
16981761 simulationUpdate ( )
16991762 }
@@ -1742,8 +1805,13 @@ <h5 class="modal-title" id="overallMetricsModalLabel">Overall metrics</h5>
17421805 $ ( '#inputNodeSearchLabel' ) . text ( 'Search inactive' )
17431806 $ ( '#inputNodeSearch' ) . on ( 'keyup change' , function ( ) {
17441807 searchString = $ ( this ) . val ( ) . toLowerCase ( )
1808+
1809+ searchTerms = searchString . split ( " " )
1810+ searchTerms = searchTerms . filter ( Boolean ) ;
1811+ // console.log(searchTerms)
1812+
17451813 searchResults = 0
1746- if ( searchString . length > 0 ) {
1814+ if ( searchString . length > 0 && searchTerms . length > 0 ) {
17471815 isSearching = true
17481816 simulationUpdate ( )
17491817 $ ( '#inputNodeSearchLabel' ) . text ( searchResults + ' nodes found' )
0 commit comments