File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -166,6 +166,7 @@ Serializes the graph. Returns an object with the following properties.
166166 * ` links ` An array of objects representing edges, each with the following properties.
167167 * ` source ` The node identifier string of the source node (** u** ).
168168 * ` target ` The node identifier string of the target node (** v** ).
169+ * ` weight ` The weight of the edge between the source and target nodes.
169170
170171Here's example code for serializing a graph.
171172
@@ -186,8 +187,8 @@ The following will be the value of `serialized`.
186187 { "id" : " c" }
187188 ],
188189 "links" : [
189- { "source" : " a" , "target" : " b" },
190- { "source" : " b" , "target" : " c" }
190+ { "source" : " a" , "target" : " b" , "weight" : 1 },
191+ { "source" : " b" , "target" : " c" , "weight" : 1 }
191192 ]
192193}
193194```
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments