Method: Jekyll::Graph::Generator#set_neighbors

Defined in:
lib/jekyll-graph.rb

#set_neighbors(json_nodes, json_links) ⇒ Object

json population helpers

set ids here, full javascript objects are populated in client-side javascript.


144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/jekyll-graph.rb', line 144

def set_neighbors(json_nodes, json_links)
  json_links.each do |json_link|
    source_node = json_nodes.detect { |n| n[:id] == json_link[:source] }
    target_node = json_nodes.detect { |n| n[:id] == json_link[:target] }

    source_node[:neighbors][:nodes] << target_node[:id]
    target_node[:neighbors][:nodes] << source_node[:id]

    source_node[:neighbors][:links] << json_link
    target_node[:neighbors][:links] << json_link
  end
end