Created
September 6, 2012 22:05
-
-
Save ddd1600/3660718 to your computer and use it in GitHub Desktop.
a sample of the code for a problem I'm trying to get solved
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
#controller method example | |
def us_map | |
@locations = LocationNode.where(:in_the_us => true).where('d_s > ?', 10) | |
end | |
#example of view | |
<h1>US Map of Startup Density</h1> | |
<% i = 0 %> | |
<script type='text/javascript'> | |
google.load('visualization', '1', {'packages': ['geochart']}); | |
google.setOnLoadCallback(drawMarkersMap); | |
function drawMarkersMap() { | |
var data = google.visualization.arrayToDataTable([ | |
['Location', 'Startups'], | |
# these (above) are the headers and can be set manually | |
# the below is where I'm using ruby inside of the javascript | |
# this was a mistake and rails cannot handle the below erb in | |
# production mode | |
<% @locations.count.times do %> | |
[<%= "'#{@locations[i].name}', #{@locations[i].d_s}" %>], | |
<% i += 1 ;end %> | |
]); | |
var options = { | |
region: 'US', | |
resolution: 'provinces', | |
displayMode: 'markers', | |
magnifyingGlass: {enable: true, zoomFactor: 9.0}, | |
colorAxis: {colors: ['green', 'blue']} | |
}; | |
var chart = new google.visualization.GeoChart(document.getElementById('chart_div')); | |
chart.draw(data, options); | |
}; | |
</script> | |
</head> | |
<body> | |
<h4>All cities with less than 10 startups have been exempted from this graph.</h4> | |
<div id="chart_div" style="width: 900px; height: 500px;"></div> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment