From 4c6d3310ca1445961b88bd7f97195b1e7b0dfaa0 Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 10 Mar 2015 09:53:38 +0100 Subject: [PATCH] Fixed support for DataSet with custom id fields (option `fieldId`). See #701. --- HISTORY.md | 7 +++++++ lib/network/Network.js | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ffe0444e..b9f372ac 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,13 @@ http://visjs.org +## not yet released, version 3.11.1-SNAPSHOT + +### Network + +- Fixed support for DataSet with custom id fields (option `fieldId`). + + ## 2015-03-05, version 3.11.0 ### Network diff --git a/lib/network/Network.js b/lib/network/Network.js index e5eb3476..ace182e7 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -1657,9 +1657,14 @@ Network.prototype._setNodes = function(nodes) { */ Network.prototype._addNodes = function(ids) { var id; + var fieldId = this.nodesData._fieldId || null; for (var i = 0, len = ids.length; i < len; i++) { id = ids[i]; var data = this.nodesData.get(id); + if (fieldId) { + data.id = data[fieldId]; + } + var node = new Node(data, this.images, this.groups, this.constants); this.nodes[id] = node; // note: this may replace an existing node if ((node.xFixed == false || node.yFixed == false) && (node.x === null || node.y === null)) { @@ -1810,8 +1815,9 @@ Network.prototype._setEdges = function(edges) { * @private */ Network.prototype._addEdges = function (ids) { - var edges = this.edges, - edgesData = this.edgesData; + var edges = this.edges; + var edgesData = this.edgesData; + var fieldId = this.edgesData._fieldId; for (var i = 0, len = ids.length; i < len; i++) { var id = ids[i]; @@ -1822,6 +1828,9 @@ Network.prototype._addEdges = function (ids) { } var data = edgesData.get(id, {"showInternalIds" : true}); + if (fieldId) { + data.id = data[fieldId]; + } edges[id] = new Edge(data, this, this.constants); } this.moving = true;