Skip to content

Instantly share code, notes, and snippets.

@domitry
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domitry/9656290 to your computer and use it in GitHub Desktop.
Save domitry/9656290 to your computer and use it in GitHub Desktop.
Sample of the new Plotrb, GSoC2014
<!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>
class PlotController<ApplicationController
def index
@snippet= plot_map
end
def graph
plot_income_graph(params[:id])
end
end
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