Class: Nyaplot::MapPlot
- Includes:
- Jsonizable
- Defined in:
- lib/mapnya/plot.rb
Overview
Plot Object for Map visualization
Instance Attribute Summary collapse
-
#center ⇒ Array<Numeric>
The center of the map.
-
#color ⇒ Array<String>
The array of colors which countries are fill in.
-
#map_data ⇒ Hash
The geojson map data.
-
#no_data_color ⇒ String
The color which no-data countries are fill in when specified fill_by.
-
#scale ⇒ Numeric
The scale of the map.
-
#stroke_color ⇒ String
The color which borders are fill in.
Attributes inherited from Plot
#bg_color, #grid_color, #height, #legend, #legend_options, #legend_width, #margin, #rotate_x_label, #rotate_y_label, #width, #x_label, #xrange, #y_label, #yrange, #zoom
Instance Method Summary collapse
-
#add_map(name, data = nil) ⇒ Object
Add the map of individual countries instead of world map.
- #before_to_json ⇒ Object
- #df_list ⇒ Object
-
#fill_map_with_df(df, id_column, fill_by_column) ⇒ Object
Fill countries in different colors according to some data.
-
#initialize ⇒ MapPlot
constructor
A new instance of MapPlot.
Methods included from Jsonizable
#get_property, included, #init_properties, #set_property, #to_json
Methods inherited from Plot
#add, #add_with_df, #configure, #export_html, #show, #to_iruby
Constructor Details
#initialize ⇒ MapPlot
Returns a new instance of MapPlot.
20 21 22 23 24 25 |
# File 'lib/mapnya/plot.rb', line 20 def initialize super() set_property(:axis_extra_options, {}) map_data(nil) extension('Mapnya') end |
Instance Attribute Details
#center ⇒ Array<Numeric>
Returns the center of the map.
18 |
# File 'lib/mapnya/plot.rb', line 18 define_group_properties(:axis_extra_options, [:map_data, :color, :stroke_color, :center, :scale, :no_data_color, :df_id, :cca3, :fill_by]) |
#color ⇒ Array<String>
Returns the array of colors which countries are fill in.
18 |
# File 'lib/mapnya/plot.rb', line 18 define_group_properties(:axis_extra_options, [:map_data, :color, :stroke_color, :center, :scale, :no_data_color, :df_id, :cca3, :fill_by]) |
#map_data ⇒ Hash
Returns the geojson map data.
18 |
# File 'lib/mapnya/plot.rb', line 18 define_group_properties(:axis_extra_options, [:map_data, :color, :stroke_color, :center, :scale, :no_data_color, :df_id, :cca3, :fill_by]) |
#no_data_color ⇒ String
Returns the color which no-data countries are fill in when specified fill_by.
18 |
# File 'lib/mapnya/plot.rb', line 18 define_group_properties(:axis_extra_options, [:map_data, :color, :stroke_color, :center, :scale, :no_data_color, :df_id, :cca3, :fill_by]) |
#scale ⇒ Numeric
Returns the scale of the map.
18 |
# File 'lib/mapnya/plot.rb', line 18 define_group_properties(:axis_extra_options, [:map_data, :color, :stroke_color, :center, :scale, :no_data_color, :df_id, :cca3, :fill_by]) |
#stroke_color ⇒ String
Returns the color which borders are fill in.
18 |
# File 'lib/mapnya/plot.rb', line 18 define_group_properties(:axis_extra_options, [:map_data, :color, :stroke_color, :center, :scale, :no_data_color, :df_id, :cca3, :fill_by]) |
Instance Method Details
#add_map(name, data = nil) ⇒ Object
Add the map of individual countries instead of world map
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mapnya/plot.rb', line 34 def add_map(name, data=nil) if data.nil? path = File.("../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 ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# 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.("../datasets/world.geo.json", __FILE__) map_data(JSON.parse(File.read(path))) end self.[:axis_extra_options] = end |
#df_list ⇒ Object
48 49 50 51 52 |
# 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) ⇒ Object
Fill countries in different colors according to some data
59 60 61 62 63 64 |
# 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 |