more work on stats view

This commit is contained in:
Kyle Drake 2015-06-04 03:08:39 -07:00
parent 64ebf70b31
commit 453e762f8c
2 changed files with 169 additions and 134 deletions

View file

@ -7,7 +7,6 @@
<a href="/" <% if params[:activity].nil? %>class="selected"<% end %>>All</a> <a href="/" <% if params[:activity].nil? %>class="selected"<% end %>>All</a>
<a href="/?activity=mine" <% if params[:activity] == 'mine' %>class="selected"<% end %>>Profile Activity</a> <a href="/?activity=mine" <% if params[:activity] == 'mine' %>class="selected"<% end %>>Profile Activity</a>
<% end %> <% end %>
<a href="/activity">Global Activity</a>
</div> </div>
</div> </div>
<div class="col col-32"> <div class="col col-32">
@ -23,10 +22,11 @@
<div class="col col-66"> <div class="col col-66">
<div class="row"> <div class="row">
<div class="col col-50 globe"> <div class="col col-100 globe">
<h2>Latest Visitors</h2> <h2>Most popular locations (this week)</h2>
<div id="earth_div"></div> <div id="earth_div"></div>
</div> </div>
<!--
<div class="col col-50" style="padding-right: 0;"> <div class="col col-50" style="padding-right: 0;">
<table class="table table-striped" id="latest-visitors"> <table class="table table-striped" id="latest-visitors">
<tbody> <tbody>
@ -133,16 +133,24 @@
</tbody> </tbody>
</table> </table>
</div> </div>
-->
</div> </div>
<h2>Last 7 Days</h2> <h2>Total Visitors (last 7 days)</h2>
<p>(<a href="/plan">Upgrade</a> to see up to see stats for all time)</p>
<% if current_site && current_site.id == @site.id %>
<% if current_site.supporter? %>
<ul class="nav h-Nav"> <ul class="nav h-Nav">
<li><a href="">Month</a></li> <li><a href="">1 month</a></li>
<li><a href="">3 months</a></li> <li><a href="">3 months</a></li>
<li><a href="">1 Year</a></li> <li><a href="">1 year</a></li>
<li><a href="">All time</a></li> <li><a href="">All time</a></li>
</ul> </ul>
<% else %>
<p>(<a href="/plan">Upgrade</a> to see up to see stats for all time)</p>
<% end %>
<% end %>
<canvas id="myChart" style="width:100%;height:300px;display:block"></canvas> <canvas id="myChart" style="width:100%;height:300px;display:block"></canvas>
@ -165,7 +173,8 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
</div>
<div class="col col-50">
<h2>Top Locations</h2> <h2>Top Locations</h2>
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
@ -186,9 +195,12 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<div class="col col-50"> <% if current_site && current_site.id == @site.id %>
<div class="row">
<div class="col col-100">
<h2>Top Referrers</h2> <h2>Top Referrers</h2>
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
@ -208,6 +220,8 @@
</table> </table>
</div> </div>
</div> </div>
<% end %>
</div> </div>
<div class="col col-33"> <div class="col col-33">
@ -244,11 +258,32 @@
<script> <script>
//OpenGL globe //OpenGL globe
$(document).ready(function() { $(document).ready(function() {
var earth = new WE.map('earth_div'); var options = {
earth.setView([20, -100], 2.07); sky: true,
atmosphere: false,
dragging: true,
tilting: true,
center: [46.8011, 8.2266],
zoom: 2
}
var earth = new WE.map('earth_div', options)
earth.setView([20, -100], 2.07)
/*
WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{ WE.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
attribution: '© OpenStreetMap' attribution: '© OpenStreetMap'
}).addTo(earth); }).addTo(earth);
*/
WE.tileLayer('http://data.webglearth.com/natural-earth-color/{z}/{x}/{y}.jpg', {
tileSize: 256,
bounds: [[-85, -180], [85, 180]],
minZoom: 0,
maxZoom: 16,
attribution: 'WebGL Earth Tiles',
tms: true
}).addTo(earth)
<% @stats[:locations].each do |location| %> <% @stats[:locations].each do |location| %>
var marker = WE.marker([<%= location[:latitude] %>, <%= location[:longitude] %>]).addTo(earth); var marker = WE.marker([<%= location[:latitude] %>, <%= location[:longitude] %>]).addTo(earth);
@ -258,13 +293,13 @@
// Start a simple rotation animation // Start a simple rotation animation
var before = null; var before = null
requestAnimationFrame(function animate(now) { requestAnimationFrame(function animate(now) {
var c = earth.getPosition(); var c = earth.getPosition()
var elapsed = before? now - before: 0; var elapsed = before? now - before: 0
before = now; before = now
earth.setCenter([c[0], c[1] + 0.1*(elapsed/30)]); earth.setCenter([c[0], c[1] + 0.1*(elapsed/30)])
requestAnimationFrame(animate); requestAnimationFrame(animate)
}); });
//chart.js //chart.js
@ -292,14 +327,14 @@
data: <%== @stats[:stat_days].collect {|s| s.views}.to_json %> data: <%== @stats[:stat_days].collect {|s| s.views}.to_json %>
} }
] ]
}; }
// Get context with jQuery - using jQuery's .get() method. // Get context with jQuery - using jQuery's .get() method.
var ctx = $("#myChart").get(0).getContext("2d"); var ctx = $("#myChart").get(0).getContext("2d")
// This will get the first returned node in the jQuery collection. // This will get the first returned node in the jQuery collection.
//var myNewChart = new Chart(ctx); //var myNewChart = new Chart(ctx);
var myLineChart = new Chart(ctx).Line(data, { var myLineChart = new Chart(ctx).Line(data, {
bezierCurve: false, bezierCurve: false,
multiTooltipTemplate: "<%== @multi_tooltip_template %>" multiTooltipTemplate: "<%== @multi_tooltip_template %>"
}); })
}) })
</script> </script>