@@ -668,6 +668,14 @@ MOD.Hook("INITIALIZE", () => {
668
668
UDATA . HandleMessage ( "AUTOCOMPLETE_SELECT" , function ( data ) {
669
669
m_HandleAutoCompleteSelect ( data ) ;
670
670
} ) ;
671
+
672
+ /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
673
+ /*/ FILTER is called by FiltersPanel when user has updated filter.
674
+ /*/
675
+ UDATA . HandleMessage ( "FILTER" , function ( data ) {
676
+ m_HandleFilter ( data ) ;
677
+ } ) ;
678
+
671
679
} ) ; // end UNISYS_INIT
672
680
673
681
function m_HandleAutoCompleteSelect ( data ) {
@@ -677,6 +685,21 @@ function m_HandleAutoCompleteSelect(data) {
677
685
} ) ;
678
686
}
679
687
688
+ /**
689
+ *
690
+ * @param {object } filter {name, type, value}
691
+ *
692
+ */
693
+ function m_HandleFilter ( filter ) {
694
+ console . log ( 'HandleFilter!' , filter ) ;
695
+
696
+ // Filter Nodes and Edges
697
+ let marked = { isFilteredOut : true } ;
698
+ let normal = { isFilteredOut : false } ;
699
+ m_SetMatchingByNodeLabel ( filter . value , marked , normal ) ;
700
+ UDATA . SetAppState ( "D3DATA" , D3DATA ) ;
701
+ }
702
+
680
703
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
681
704
/*/ lifecycle RESET handler
682
705
/*/
@@ -843,6 +866,61 @@ function m_SetMatchingNodesByLabel(str = "", yes = {}, no = {}) {
843
866
} ) ;
844
867
return returnMatches ;
845
868
}
869
+ /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
870
+ /*/ Set nodes & EDGES that PARTIALLY match 'str' to 'yes' props.
871
+ All others nodes are set to 'no' props. Return matches.
872
+ Optionally resets all the NON matching nodes as well.
873
+
874
+ Edges are matched if they link to the node.
875
+ /*/
876
+ function m_SetMatchingByNodeLabel ( str = "" , yes = { } , no = { } ) {
877
+ let returnMatches = [ ] ;
878
+ str = u_EscapeRegexChars ( str . trim ( ) ) ;
879
+ if ( str === "" ) return undefined ;
880
+ const regex = new RegExp ( /*'^'+*/ str , "i" ) ;
881
+ // First find the nodes
882
+ D3DATA . nodes . forEach ( node => {
883
+ if ( regex . test ( node . label ) ) {
884
+ for ( let key in yes ) node [ key ] = yes [ key ] ;
885
+ returnMatches . push ( node ) ;
886
+ } else {
887
+ for ( let key in no ) node [ key ] = no [ key ] ;
888
+ }
889
+ } ) ;
890
+ // Then hide all related edges
891
+ m_SetMatchingEdgesByNodes ( returnMatches , yes , no ) ;
892
+ return returnMatches ;
893
+ }
894
+
895
+ /**
896
+ * Set edges that link to any node in nodeIDs to 'yes' props.
897
+ * All others nodes are set to 'no' props. Return matches.
898
+ *
899
+ * We set look for ALL nodes at once otherwise, one node can unset
900
+ * antoher node.
901
+ *
902
+ * This is a specialized function because edges need to be matched
903
+ * against both source and target.
904
+ *
905
+ * @param {Array } nodes Array of node objects
906
+ * @param {Object } yes e.g. marked = { isFilteredOut: true };
907
+ * @param {Object } no e.g. normal = { isFilteredOut: false };
908
+ */
909
+ function m_SetMatchingEdgesByNodes ( nodes , yes = { } , no = { } ) {
910
+ const nodeIDs = nodes . map ( node => node . id ) ;
911
+ let returnMatches = [ ] ;
912
+ D3DATA . edges . forEach ( edge => {
913
+ if ( nodeIDs . includes ( edge . source . id ) || nodeIDs . includes ( edge . target . id ) ) {
914
+ for ( let key in yes ) edge [ key ] = yes [ key ] ;
915
+ returnMatches . push ( edge ) ;
916
+ } else {
917
+ for ( let key in no ) edge [ key ] = no [ key ] ;
918
+ }
919
+ } ) ;
920
+ return returnMatches ;
921
+ }
922
+
923
+
846
924
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
847
925
/*/ Update props of exact matching nodes, returns matches
848
926
Optionally resets all the NON matching nodes as well
0 commit comments