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 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(); } }, { 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(); }