Skip to content

Commit

Permalink
feat(data): allow custom DataSet/View implementations (#1108)
Browse files Browse the repository at this point in the history
This tests that the methods and properties are implemented instead of
checking the prototype. Thanks to this it is now possible to use a
different DataSet or DataView without extending the Vis one. This also
removes some interoperability issues of the standalone build when used
toghether with other Vis family libraries.
  • Loading branch information
Thomaash authored Oct 14, 2020
1 parent c130c57 commit 6c5a958
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/network/modules/EdgesHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deepExtend, forEach } from "vis-util/esnext";
import { DataSet, DataView } from "vis-data/esnext";
import { DataSet, isDataViewLike } from "vis-data/esnext";
import Edge from "./components/Edge";

/**
Expand Down Expand Up @@ -248,13 +248,13 @@ class EdgesHandler {
* Load edges by reading the data table
*
* @param {Array | DataSet | DataView} edges The data containing the edges.
* @param {boolean} [doNotEmit=false]
* @param {boolean} [doNotEmit=false] - Suppress data changed event.
* @private
*/
setData(edges, doNotEmit = false) {
const oldEdgesData = this.body.data.edges;

if (edges instanceof DataSet || edges instanceof DataView) {
if (isDataViewLike("id", edges)) {
this.body.data.edges = edges;
} else if (Array.isArray(edges)) {
this.body.data.edges = new DataSet();
Expand Down
6 changes: 3 additions & 3 deletions lib/network/modules/NodesHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bridgeObject, forEach } from "vis-util/esnext";
import { DataSet, DataView } from "vis-data/esnext";
import { DataSet, isDataViewLike } from "vis-data/esnext";
import Node from "./components/Node";

/**
Expand Down Expand Up @@ -245,13 +245,13 @@ class NodesHandler {
* Set a data set with nodes for the network
*
* @param {Array | DataSet | DataView} nodes The data containing the nodes.
* @param {boolean} [doNotEmit=false]
* @param {boolean} [doNotEmit=false] - Suppress data changed event.
* @private
*/
setData(nodes, doNotEmit = false) {
const oldNodesData = this.body.data.nodes;

if (nodes instanceof DataSet || nodes instanceof DataView) {
if (isDataViewLike("id", nodes)) {
this.body.data.nodes = nodes;
} else if (Array.isArray(nodes)) {
this.body.data.nodes = new DataSet();
Expand Down

0 comments on commit 6c5a958

Please sign in to comment.