Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create_protovis_data_from tweeps, tweep_edges
- counter = 0
- tweep_index_lookup = {}
- File.open('strangeloop_words.js', 'w'){|file|
- file.puts 'var miserables = {'
- file.puts 'nodes:['
- tweeps.each{|tweep|
- tweep_index_lookup[tweep] = counter
- file.puts "{nodeName:\"#{tweep}\", group:1}, //#{tweep_index_lookup[tweep]}"
- counter += 1
- }
- file.puts '],'
- file.puts 'links:['
- tweep_edges.each{ |edge, strength|
- from_tweep = edge[:from]
- to_tweep = edge[:to]
- raise "bad to tweep!!" if not tweep_index_lookup.include? to_tweep
- raise "bad to tweep!!" if not tweep_index_lookup.include? from_tweep
- from_index = tweep_index_lookup[from_tweep]
- to_index = tweep_index_lookup[to_tweep]
- file.puts "{source:#{from_index}, target:#{to_index}, value: #{(2)**strength}},"
- }
- file.puts ']};'
- }
- end
Add Comment
Please, Sign In to add comment