@@ -39,7 +39,6 @@ const DBG = false;
3939
4040/// LIBRARIES /////////////////////////////////////////////////////////////////
4141/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42- import FILTER from './components/filter/FilterEnums' ;
4342const SETTINGS = require ( "settings" ) ;
4443const UNISYS = require ( "unisys/client" ) ;
4544const JSCLI = require ( "system/util/jscli" ) ;
@@ -670,57 +669,20 @@ MOD.Hook("INITIALIZE", () => {
670669 m_HandleAutoCompleteSelect ( data ) ;
671670 } ) ;
672671
673- /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
674- /*/ FILTER is called by FiltersPanel when user has updated filter.
675- /*/
676- UDATA . HandleMessage ( "FILTER" , function ( data ) {
677- m_HandleFilter ( data ) ;
678- } ) ;
679-
680672} ) ; // end UNISYS_INIT
681673
674+
675+ /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
676+ /*/ INIT HANDLERS
677+ /*/
678+
682679function m_HandleAutoCompleteSelect ( data ) {
683680 if ( DBG ) console . log ( "ACL: Setting activeAutoCompleteId to" , data . id ) ;
684681 UDATA . SetAppState ( "ACTIVEAUTOCOMPLETE" , {
685682 activeAutoCompleteId : data . id
686683 } ) ;
687684}
688685
689- /**
690- *
691- * @param {object } data {action, filter}
692- *
693- */
694- function m_HandleFilter ( data ) {
695- console . log ( 'HandleFilter!' , data ) ;
696-
697- if ( data . action === undefined ) throw "m_HandleFilter called without action" ;
698-
699- switch ( data . action ) {
700- case FILTER . ACTIONS . CLEAR :
701- m_ClearFilters ( ) ;
702- break ;
703- case FILTER . ACTIONS . FILTER_EDGES :
704- break ;
705- case FILTER . ACTIONS . FILTER_NODES :
706- default :
707- m_FilterNodes ( data . filter . value ) ;
708- break ;
709- }
710- UDATA . SetAppState ( "D3DATA" , D3DATA ) ;
711- }
712-
713- function m_FilterNodes ( nodeLabelSnippet ) {
714- const marked = { isFilteredOut : true } ;
715- const normal = { isFilteredOut : false } ;
716- m_SetMatchingByNodeLabel ( nodeLabelSnippet , marked , normal ) ;
717- }
718- function m_ClearFilters ( ) {
719- const props = { isFilteredOut : false } ;
720- m_SetAllObjs ( D3DATA . nodes , props ) ;
721- m_SetAllObjs ( D3DATA . edges , props ) ;
722- }
723-
724686/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
725687/*/ lifecycle RESET handler
726688/*/
@@ -827,6 +789,7 @@ function m_SetAllObjs(obj_list, all = {}) {
827789 for ( let key in all ) obj [ key ] = all [ key ] ;
828790 } ) ;
829791}
792+ MOD . SetAllObj = m_SetAllObjs ; // Expose for filter-logic.js
830793
831794/// NODE HELPERS //////////////////////////////////////////////////////////////
832795/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -887,59 +850,7 @@ function m_SetMatchingNodesByLabel(str = "", yes = {}, no = {}) {
887850 } ) ;
888851 return returnMatches ;
889852}
890- /// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
891- /*/ Set nodes & EDGES that PARTIALLY match 'str' to 'yes' props.
892- All others nodes are set to 'no' props. Return matches.
893- Optionally resets all the NON matching nodes as well.
894-
895- Edges are matched if they link to the node.
896- /*/
897- function m_SetMatchingByNodeLabel ( str = "" , yes = { } , no = { } ) {
898- let returnMatches = [ ] ;
899- str = u_EscapeRegexChars ( str . trim ( ) ) ;
900- if ( str === "" ) return undefined ;
901- const regex = new RegExp ( /*'^'+*/ str , "i" ) ;
902- // First find the nodes
903- D3DATA . nodes . forEach ( node => {
904- if ( regex . test ( node . label ) ) {
905- for ( let key in yes ) node [ key ] = yes [ key ] ;
906- returnMatches . push ( node ) ;
907- } else {
908- for ( let key in no ) node [ key ] = no [ key ] ;
909- }
910- } ) ;
911- // Then hide all related edges
912- m_SetMatchingEdgesByNodes ( returnMatches , yes , no ) ;
913- return returnMatches ;
914- }
915853
916- /**
917- * Set edges that link to any node in nodeIDs to 'yes' props.
918- * All others nodes are set to 'no' props. Return matches.
919- *
920- * We set look for ALL nodes at once otherwise, one node can unset
921- * antoher node.
922- *
923- * This is a specialized function because edges need to be matched
924- * against both source and target.
925- *
926- * @param {Array } nodes Array of node objects
927- * @param {Object } yes e.g. marked = { isFilteredOut: true };
928- * @param {Object } no e.g. normal = { isFilteredOut: false };
929- */
930- function m_SetMatchingEdgesByNodes ( nodes , yes = { } , no = { } ) {
931- const nodeIDs = nodes . map ( node => node . id ) ;
932- let returnMatches = [ ] ;
933- D3DATA . edges . forEach ( edge => {
934- if ( nodeIDs . includes ( edge . source . id ) || nodeIDs . includes ( edge . target . id ) ) {
935- for ( let key in yes ) edge [ key ] = yes [ key ] ;
936- returnMatches . push ( edge ) ;
937- } else {
938- for ( let key in no ) edge [ key ] = no [ key ] ;
939- }
940- } ) ;
941- return returnMatches ;
942- }
943854
944855
945856/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -1025,6 +936,7 @@ const REGEX_REGEXCHARS = /[.*+?^${}()|[\]\\]/g;
1025936function u_EscapeRegexChars ( string ) {
1026937 return string . replace ( REGEX_REGEXCHARS , "\\$&" ) ; // $& means the whole matched string
1027938}
939+ MOD . EscapeRegexChars = u_EscapeRegexChars ; // Expose for filter-logic.js
1028940/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1029941/*/ Convert all IDs to integers
1030942 Node and Edge IDs should be integers.
0 commit comments