Skip to content

Commit

Permalink
fix(data-set): do not use private props (#232)
Browse files Browse the repository at this point in the history
Formerly ._data was accessed directly. No idea how that could ever work
at all. Now the proper methods from the API are used so there should be
no further issues.

Closes #228.
  • Loading branch information
Thomaash committed Nov 19, 2019
1 parent ff3956e commit c47be95
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/network/modules/EdgesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class EdgesHandler {
for (let edgeId in this.body.edges) {
if (this.body.edges.hasOwnProperty(edgeId)) {
let edge = this.body.edges[edgeId];
let edgeData = this.body.data.edges._data[edgeId];
const edgeData = this.body.data.edges.get(edgeId);

// only forcibly remove the smooth curve if the data has been set of the edge has the smooth curves defined.
// this is because a change in the global would not affect these curves.
Expand Down Expand Up @@ -370,7 +370,7 @@ class EdgesHandler {
*/
refresh() {
util.forEach(this.body.edges, (edge, edgeId) => {
let data = this.body.data.edges._data[edgeId];
const data = this.body.data.edges.get(edgeId);
if (data !== undefined) {
edge.setOptions(data);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/network/modules/ManipulationSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,12 @@ class ManipulationSystem {
* @private
*/
_performEditEdge(sourceNodeId, targetNodeId) {
let defaultData = {id: this.edgeBeingEditedId, from: sourceNodeId, to: targetNodeId, label: this.body.data.edges._data[this.edgeBeingEditedId].label };
const defaultData = {
id: this.edgeBeingEditedId,
from: sourceNodeId,
to: targetNodeId,
label: this.body.data.edges.get(this.edgeBeingEditedId).label
};
let eeFunct = this.options.editEdge;
if (typeof eeFunct === 'object') {
eeFunct = eeFunct.editWithoutDrag;
Expand Down
21 changes: 12 additions & 9 deletions lib/network/modules/NodesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,20 @@ class NodesHandler {
*/
storePositions() {
// todo: add support for clusters and hierarchical.
let dataArray = [];
var dataset = this.body.data.nodes.getDataSet();

for (let nodeId in dataset._data) {
if (dataset._data.hasOwnProperty(nodeId)) {
let node = this.body.nodes[nodeId];
if (dataset._data[nodeId].x != Math.round(node.x) || dataset._data[nodeId].y != Math.round(node.y)) {
dataArray.push({ id: node.id, x: Math.round(node.x), y: Math.round(node.y) });
}
const dataArray = [];
const dataset = this.body.data.nodes.getDataSet();

for (const dsNode of dataset.get()) {
const id = dsNode.id;
const bodyNode = this.body.nodes[id];
const x = Math.round(bodyNode.x);
const y = Math.round(bodyNode.y);

if (dsNode.x !== x || dsNode.y !== y) {
dataArray.push({ id, x, y });
}
}

dataset.update(dataArray);
}

Expand Down

0 comments on commit c47be95

Please sign in to comment.