@@ -11,6 +11,7 @@ import deepmerge from 'deepmerge';
11
11
import type * as VisNetwork from 'vis-network' ;
12
12
import {
13
13
Cypher ,
14
+ DataFunctionType ,
14
15
Edge ,
15
16
LabelConfig ,
16
17
Neo4jConfig ,
@@ -560,19 +561,19 @@ export class NeoVis {
560
561
/**
561
562
* Renders the network
562
563
*/
563
- render ( query ?: Cypher , parameters ?: unknown ) : void {
564
- if ( this . #config. dataFunction ) {
565
- this . #runFunctionDataGetter( parameters ) ;
564
+ render ( query_or_function ?: Cypher | DataFunctionType , parameters ?: unknown ) : void {
565
+ if ( this . #config. dataFunction || typeof query_or_function === 'function' ) {
566
+ this . #runFunctionDataGetter( typeof query_or_function === 'function' ? query_or_function : this . #config . dataFunction , parameters ) ;
566
567
} else {
567
- this . #runNeo4jDataGetter( query , parameters ) ;
568
+ this . #runNeo4jDataGetter( query_or_function as Cypher , parameters ) ;
568
569
}
569
570
}
570
571
571
- async #runFunctionDataGetter( parameters ? : unknown ) {
572
+ async #runFunctionDataGetter( func : DataFunctionType , parameters : unknown ) {
572
573
let recordCount = 0 ;
573
574
try {
574
575
const dataBuildPromises : Promise < unknown > [ ] = [ ] ;
575
- for await ( const record of await this . #config . dataFunction ( parameters ) ) {
576
+ for await ( const record of await func ( parameters ) ) {
576
577
dataBuildPromises . push ( this . #createSingleRecord( record ) ) ;
577
578
recordCount ++ ;
578
579
}
@@ -733,17 +734,17 @@ export class NeoVis {
733
734
* Reset the config object and reload data
734
735
* @param config
735
736
*/
736
- reinit ( config : NeovisConfig | NonFlatNeovisConfig ) : void {
737
+ reinit ( config : NeovisConfig | NonFlatNeovisConfig , parameter ?: unknown ) : void {
737
738
this . #init( config ) ;
738
- this . render ( ) ;
739
+ this . render ( undefined , parameter ) ;
739
740
}
740
741
741
742
/**
742
743
* Clear the network and fetch live data form the server and reload the visualization
743
744
*/
744
- reload ( ) : void {
745
+ reload ( parameter ?: unknown ) : void {
745
746
this . clearNetwork ( ) ;
746
- this . render ( ) ;
747
+ this . render ( undefined , parameter ) ;
747
748
}
748
749
749
750
/**
@@ -757,21 +758,42 @@ export class NeoVis {
757
758
/**
758
759
* Execute an arbitrary Cypher query and re-render the visualization
759
760
* @param query
761
+ * @param parameters - parameters to send to the cypher
760
762
*/
761
- renderWithCypher ( query : Cypher ) : void {
763
+ renderWithCypher ( query : Cypher , parameters ?: unknown ) : void {
762
764
// this._config.initialCypher = query;
763
765
this . clearNetwork ( ) ;
764
766
this . #query = query ;
765
- this . render ( ) ;
767
+ this . render ( undefined , parameters ) ;
768
+ }
769
+
770
+ /**
771
+ * Execute an arbitrary function and re-render the visualization
772
+ * @param func
773
+ * @param parameters - parameters to send to the function
774
+ */
775
+ renderWithFunction ( func : DataFunctionType , parameters ?: unknown ) : void {
776
+ this . clearNetwork ( ) ;
777
+ this . render ( func , parameters ) ;
766
778
}
767
779
768
780
/**
769
781
* Execute an arbitrary Cypher query and update the current visualization, retaning current nodes
770
- * This function will not change the original query given by renderWithCypher or the inital cypher.
771
- * @param query
782
+ * This function will not change the original query given by renderWithCypher or the inital cypher.
783
+ * @param parameters - parameters to send to the cypher
784
+ *
785
+ */
786
+ updateWithCypher ( query : Cypher , parameters ?: unknown ) : void {
787
+ this . render ( query , parameters ) ;
788
+ }
789
+
790
+ /**
791
+ * Execute an arbitrary function and update the visualization
792
+ * @param func
793
+ * @param parameters - parameters to send to the function
772
794
*/
773
- updateWithCypher ( query : Cypher ) : void {
774
- this . render ( query ) ;
795
+ updateWithFunction ( func : DataFunctionType , parameters ?: unknown ) : void {
796
+ this . render ( func , parameters ) ;
775
797
}
776
798
}
777
799
0 commit comments