Representing a graph as backbone.js model/collection -
i looking example how represent graph , nodes , edges backbone.js model. hope can point me example how elegantly.
thanks
martin
(assuming you'd store metadata nodes - name etc)
a simple way might representing graph collection of node models.
each of these models have property containing array of edges represented id of node connect - collection.tojson()
return like:
[ { id: 1, name: 'first node', edges: [2, 4] }, { id: 2, name: 'second node', edges: [1, 3, 4] }, { id: 3, name: 'third node', edges: [2] }, { id: 1, name: 'first node', edges: [1, 2] } ]
the implement methods calculate distance between nodes or derive clusters in collection class.
now mentioned simple implementation, might woefully inefficient depending on operations on graph.
if you'd reading , find efficient way store graph information in hash-like (model) or list-like (collection) structure, google "adjacency matrix" or "adjacency list" , go there!
Comments
Post a Comment