php-mpos/public/templates/test/dashboard/graph.tpl
Sebastian Grewe 728ee2dd11 Feature update and Improvement to Dashboard
* [FEATURE] Dasboard honors Ajax interval for hashrate graph
* [IMPROVEMENT] Load graph plugins on graph template not on master template
2013-09-14 23:01:31 +02:00

58 lines
2.4 KiB
Smarty

<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.json2.min.js"></script>
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.dateAxisRenderer.js"></script>
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.highlighter.js"></script>
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.canvasTextRenderer.min.js"></script>
<script type="text/javascript" src="{$PATH}/js/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
<article class="module width_full">
<header><h3>Graphs</h3></header>
<div class="module_content">
<div id="hashrategraph" style="height:200px; width: 95%;"></div>
</div>
<footer>
<p style="margin-left: 25px">Refresh interval: {$GLOBAL.config.statistics_ajax_refresh_interval|default:"10"} seconds. Hashrate based on shares submitted in the past {$INTERVAL|default:"5"} minutes.</p>
</footer>
</article>
<script>{literal}
$(document).ready(function(){
var url = "{/literal}{$smarty.server.PHP_SELF}?page=api&action=getuserhashrate&api_key={$GLOBAL.userdata.api_key}&id={$GLOBAL.userdata.id}{literal}";
var storedData = Array();
var options = {
highlighter: { tooltipAxes: 'both', show: true },
title: 'Hashrate',
axes: {
yaxis:{ min:0, padMin: 0, padMax: 1.5, label: '{/literal}{$GLOBAL.hashunits.personal}{literal}', labelRenderer: $.jqplot.CanvasAxisLabelRenderer},
xaxis:{ min:0, max: 60, tickInterval: 10, padMax: 0, label: 'Minutes', labelRenderer: $.jqplot.CanvasAxisLabelRenderer}
},
};
// Init empty graph with 0 data
for (var i = 0; i < 60; i++) { storedData[i] = [i, 0] }
$.jqplot('hashrategraph', [storedData], options);
// Fetch current datapoint as initial data
var d = new Date();
$.ajax({
url: url,
dataType: "json",
success: function(data) {
storedData[d.getMinutes()] = [d.getMinutes(), data.getuserhashrate.hashrate];
$.jqplot('hashrategraph', [storedData], options).replot();
}
});
// Update graph
setInterval(function() {
var d = new Date();
$.ajax({
url: url,
dataType: "json",
success: function(data) {
storedData[d.getMinutes()] = [d.getMinutes(), data.getuserhashrate.hashrate];
$.jqplot('hashrategraph', [storedData], options).replot();
}
});
}, {/literal}{($GLOBAL.config.statistics_ajax_refresh_interval * 1000)|default:"10000"}{literal});
});
{/literal}</script>