class Nyaplot::MapPlot

Plot Object for Map visualization

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/mapnya/plot.rb, line 20
def initialize
  super()
  set_property(:axis_extra_options, {})
  map_data(nil)
  extension('Mapnya')
end

Public Instance Methods

add_map(name, data=nil) click to toggle source

Add the map of individual countries instead of world map @param [String] name the name of country to add @param [Hash] data your own geojson data @example

plot = Nyaplot::MapPlot.new
plot.add_map(JPN) #-> add the map of Japan to the plot

@see nbviewer.ipython.org/github/domitry/nyaplot/blob/master/examples/notebook/Mapnya3.ipynb

# File lib/mapnya/plot.rb, line 34
def add_map(name, data=nil)
  if data.nil?
    path = File.expand_path("../datasets/countries/data/" + name.downcase + ".geo.json", __FILE__)
    map_data = JSON.parse(File.read(path))
    # pre-processing
    map_data["features"].push(map_data["features"][0]) if map_data["features"].length == 1
    country_data = Countries.df.filter{|row| row[:cca3] == name.upcase}.row(0)
    center([country_data[:lng], country_data[:lat]])
    map_data(map_data)
  else
    map_data(data)
  end
end
before_to_json() click to toggle source
# File lib/mapnya/plot.rb, line 66
def before_to_json
  zoom(true)
  width(800) if width.nil?
  height(800) if height.nil?

  if map_data.nil?
    path = File.expand_path("../datasets/geo-boundaries-world-110m/countries.geojson", __FILE__)
    map_data(JSON.parse(File.read(path)))
  end

  self.options[:axis_extra_options] = axis_extra_options
end
df_list() click to toggle source
Calls superclass method
# File lib/mapnya/plot.rb, line 48
def df_list
  arr = super()
  return arr if df_id.nil?
  return arr.push(df_id)
end
fill_map_with_df(df, id_column, fill_by_column) click to toggle source

Fill countries in different colors according to some data @param [DataFrame] df @param [Symbol] id_column the column that includes cca3 @param [Symbol] fill_by_column the column that includes some values @see nbviewer.ipython.org/github/domitry/Nyaplot/blob/master/examples/notebook/Mapnya.ipynb#Case2-:Fill-countries-in-different-colors

# File lib/mapnya/plot.rb, line 59
def fill_map_with_df(df, id_column, fill_by_column)
  cca3(id_column)
  fill_by(fill_by_column)
  df_id(df.name)
  DataBase.instance.add(df)
end