Created
December 8, 2014 11:26
-
-
Save tobypinder/183f7c3cab749c08a5ca to your computer and use it in GitHub Desktop.
Plot EVE's Regions using Ruby-graphviz
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
# Include ruby-graphviz in the gemfile | |
# Doesn't have to be a rake task, obviously. | |
task draw_regions: :environment do | |
require 'graphviz' | |
# Model initialization left as an exercise to the reader. The models I use are | |
# just tables from EVE's static data export. | |
regions = StaticData::Region.all.to_a.reject { |r| r.jumps_from.size.zero? }.map { |r| [r.regionID, r] }.to_h | |
jumps = StaticData::RegionJump.all.to_a.map { |j| [j.fromRegionID, j.toRegionID] } | |
regionNodes = {} | |
opts_graph = { mode: :graph, layout: :neato, splines: :polyline, overlap: :scalexy, pack: true, smoothing: :spring, compound: true } | |
opts_node = { color: :grey, fillcolor: :yellow, shape: :rect } | |
opts_edge = { arrowhead: :none } | |
graph = GraphViz::new(:G, opts_graph) do |graph| | |
regions.each do |k, r| | |
regionNodes[k] = graph.add_node(r.to_s, opts_node.merge(label: r.to_s)) | |
end | |
jumps.each do |j| | |
if j[0].to_i > j[1].to_i | |
graph.add_edges(regionNodes[j[0]], regionNodes[j[1]], opts_edge) | |
end | |
end | |
end | |
# graph.output(svg: 'output/regions.svg') | |
graph.output(png: 'output/regions.png') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment