Last active
February 19, 2018 17:37
-
-
Save keithwhor/15b31f101ff5a2721dfa to your computer and use it in GitHub Desktop.
UnitGraph example, loading graph and finding closest nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ug = require('ug'); | |
let graph = new ug.Graph(); | |
// load graph from flatfile into RAM | |
graph.load('/path_to_saved_graph.ugd', function() { | |
// get the closest 100 'listings' nodes, at a minimum depth (distance) of 3 | |
let results = graph.closest(node, { | |
compare: function(node) { return node.entity === 'listing'; }, | |
minDepth: 3, | |
count: 100 | |
}); | |
// results is now an array of Paths, which are each traces from your starting node to your result node... | |
let resultNodes = result.map(function(path) { | |
return path.end(); | |
})); | |
doSomething(resultNodes); // render, whatever you'd like | |
}); |
// load graph from flatfile into RAM
graph.load('/path_to_saved_graph.ugd', function()
What is a ugd ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't line #16 read:
let resultNodes = results.map(function(path) {
?