From b21258534e2782418e2b3c09ab91779223fdab23 Mon Sep 17 00:00:00 2001 From: Lukas Nasarek Date: Tue, 27 Apr 2021 15:11:05 +0200 Subject: [PATCH 1/3] Update index.js Allow the component to use user supplied data sets for nodes and edges instead of only arrays. --- lib/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 78577747..8dd18be9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -94,10 +94,18 @@ var Graph = function (_Component) { _createClass(Graph, [{ key: "componentDidMount", value: function componentDidMount() { - this.edges = new _visData.DataSet(); - this.edges.add(this.props.graph.edges); - this.nodes = new _visData.DataSet(); - this.nodes.add(this.props.graph.nodes); + if (this.props.graph.edges instanceof _visData.DataSet) { + this.edges = this.props.graph.edges; + } else { + this.edges = new _visData.DataSet(); + this.edges.add(this.props.graph.edges); + } + if (this.props.graph.edges instanceof _visData.DataSet) { + this.nodes = this.props.graph.nodes; + } else { + this.edges = new _visData.DataSet(); + this.nodes.add(this.props.graph.nodes); + } this.updateGraph(); } }, { From 338fb34dfc443ab116516dca91c17d1a09b282b8 Mon Sep 17 00:00:00 2001 From: Lukas Nasarek Date: Tue, 27 Apr 2021 15:11:19 +0200 Subject: [PATCH 2/3] Update build. --- src/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 101a0075..3c5c2691 100644 --- a/src/index.js +++ b/src/index.js @@ -48,10 +48,18 @@ class Graph extends Component { } componentDidMount() { - this.edges = new DataSet(); - this.edges.add(this.props.graph.edges); - this.nodes = new DataSet(); - this.nodes.add(this.props.graph.nodes); + if (this.props.graph.edges instanceof DataSet) { + this.edges = this.props.graph.edges + } else { + this.edges = new DataSet(); + this.edges.add(this.props.graph.edges); + } + if (this.props.graph.edges instanceof DataSet) { + this.nodes = this.props.graph.nodes + } else { + this.edges = new DataSet(); + this.nodes.add(this.props.graph.nodes); + } this.updateGraph(); } From 8f80cadf90c00ece85dbaa21cdebaed3ea7bb4de Mon Sep 17 00:00:00 2001 From: Lukas Nasarek Date: Tue, 27 Apr 2021 15:21:14 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2516a41c..b76013a5 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Due to the imperative nature of vis.js, updating graph properties causes complet This component takes three vis.js configuration objects as properties: -- graph: contains two arrays { edges, nodes } +- graph: contains two arrays or `DataSets`{ edges, nodes } - options: normal vis.js options as described [here](http://visjs.org/docs/network/#options) - events: an object that has [event name](http://visjs.org/docs/network/#Events) as keys and their callback as values