Last active
August 29, 2015 13:57
-
-
Save domitry/9656290 to your computer and use it in GitHub Desktop.
Sample of the new Plotrb, GSoC2014
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
... | |
<script> | |
function hover_province(var state_num){ | |
// when hovering a state on the right map, show the chart relating to it. | |
$("#income_graph").load("graph/"+state_num); | |
} | |
</script> | |
... | |
<div id="income_graph"> | |
</div> | |
<div id="map"> | |
<%= @snippet %> | |
</div> | |
... | |
</html> |
This file contains hidden or 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
class PlotController<ApplicationController | |
def index | |
@snippet= plot_map | |
end | |
def graph | |
plot_income_graph(params[:id]) | |
end | |
end | |
This file contains hidden or 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
module PlotHelper | |
def plot_map | |
alaska_topo = "alaska.topo.json" | |
geo_data = [{name:"countries", url: alaska_topo, feature:"alaska_state.geo"}] | |
map = Map.new(geo_data) do | |
# additional callback method | |
params=["state_num"] | |
hover.callback(name:"hover_map", param:params) | |
end | |
map.to_html | |
end | |
def plot_income_graph(state_num) | |
state_date =[] | |
# get some data about the hoverd state, using state_num. | |
bar =Bar.new(state_data)do | |
# add some code here to change some features like axis, color..etc. | |
enable :interactive | |
end | |
bar.to_html | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment