#!/bin/bash cat << EOF >> ./lines.csv 2>&1 name, colors "銀座線", "#f39700" "丸ノ内線", "#e60012" "日比谷線", "#9caeb7" "東西線", "#00a7db" "千代田線", "#009944" "有楽町線", "#d7c447" "半蔵門線", "#9b7cb6" "南北線", "#00ada9" "副都心線", "#bb641d" "浅草線", "#e85298" "三田線", "#0079c2" "新宿線", "#6cbb5a" "大江戸線", "#b6007a" "荒川線", "#7aaa16" "舎人ライナー", "#999999" EOF end # encoding: UTF-8 require "gviz" require "csv" colors = [["銀座線", "#f39700" "丸ノ内線", "#e60012"], ["日比谷線", "#9caeb7"], ["東西線", "#00a7db"], ["千代田線", "#009944"], ["有楽町線", "#d7c447"], ["半蔵門線", "#9b7cb6"], ["南北線", "#00ada9"], ["副都心線", "#bb641d"], ["浅草線", "#e85298"], ["三田線", "#0079c2"], ["新宿線", "#6cbb5a"], ["大江戸線", "#b6007a"], ["荒川線", "#7aaa16"], ["舎人ライナー", "#999999"]] header, *data = CSV.read('m_station.csv') metrodata = data.select { |d| d[7].match(/東京メトロ|東京都交通局/) } .group_by { |d| d[8] } flatdata = metrodata.values.flatten(1) lon_minmax = flatdata.map { |d| d[11].to_f }.minmax lat_minmax = flatdata.map { |d| d[12].to_f }.minmax lon_range = Range.new(*lon_minmax) # => 139.612434..139.958972 lat_range = Range.new(*lat_minmax) # => 35.586859..35.814544 Graph(:Metro) do global label:'Metro of Tokyo', size:16, layout:'neato' edges arrowhead:'none', penwidth:10 nodes style:'bold' metrodata.each do |line, stations| stlength = stations.length stations.each.with_index(1) do |st, i| st_id, st_name, st_seq = st.values_at(2, 9, 4) st_id = st_id.intern next_id = "#{st_seq.to_i+1}".intern color = (c = colors.detect { |ln, c| line.match /#{ln}/ }) ? c[1] : "#999999" pos_x = st[11].to_f.norm(lon_range, 10..60).round # 10..60 for svg pos_y = st[12].to_f.norm(lat_range, 10..60).round # 10..60 for svg # node st_id, label:st_name, color:color, pos:"#{pos_x},#{pos_y}!" node st_id, pos:"#{pos_x},#{pos_y}!" node st_id, label:st_name, color:color case st_id when :'2800220' # 中野坂上 edge [st_id, :'2800226'].join('_'), color:color # 中野坂上 => 中野新橋 when :'2800225' # 荻窪 next end edge [st_id, next_id].join('_'), color:color if i < stlength end end save(:metro, :svg) end