Skip to content

Commit 4cfa338

Browse files
committed
Add weights to serialization
Serialized graphs should retain weights
1 parent 2f1fbf4 commit 4cfa338

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ module.exports = function Graph(serialized){
311311
adjacent(source).forEach(function (target){
312312
serialized.links.push({
313313
source: source,
314-
target: target
314+
target: target,
315+
weight: getEdgeWeight(source, target)
315316
});
316317
});
317318
});
@@ -322,7 +323,7 @@ module.exports = function Graph(serialized){
322323
// Deserializes the given serialized graph.
323324
function deserialize(serialized){
324325
serialized.nodes.forEach(function (node){ addNode(node.id); });
325-
serialized.links.forEach(function (link){ addEdge(link.source, link.target); });
326+
serialized.links.forEach(function (link){ addEdge(link.source, link.target, link.weight); });
326327
return graph;
327328
}
328329

0 commit comments

Comments
 (0)