%include header

<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Flot Examples</title>
    <link href="/static/style.css" rel="stylesheet" type="text/css"></link>
    <!--[if IE]><script language="javascript" type="text/javascript" src="/flot/excanvas.min.js"></script><![endif]-->
    <script language="javascript" type="text/javascript" src="/flot/jquery.js"></script>
    <script language="javascript" type="text/javascript" src="/flot/jquery.flot.js"></script>
 </head>
    <body>
        <h2>{{app_name}}</h2>

        <h4>Response Times</h4>
    <div id="response" style="width:800px;height:300px"></div>

    <h4>Requests per Second</h4>
    <div id="requests" style="width:800px;height:300px"></div>


<script id="source" language="javascript" type="text/javascript">
$(function () {
    var request = {{time_response}};
    var plot = $.plot($("#response"),
        [ { data: request, label: "Response Times"}], 
        { xaxis: { mode: "time" },
          series: {lines: { show: true },points: { show: true }},
          grid: { hoverable: true, clickable: true }
             });

    var request = {{requests_second}};
    var plot = $.plot($("#requests"),
        [ { data: request, label: "Requests Per Second"}], 
        { xaxis: { mode: "time" },
          series: {lines: { show: true },points: { show: true }},
          grid: { hoverable: true, clickable: true }
          });

    function showTooltip(x, y, contents) {
        $('<div id="tooltip">' + contents + '</div>').css( {
            position: 'absolute',
            display: 'none',
            top: y + 5,
            left: x + 5,
            border: '1px solid #fdd',
            padding: '2px',
            'background-color': '#fee',
            opacity: 0.80
        }).appendTo("body").fadeIn();
    }

    var previousPoint = null;
    $("#requests").bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

            if (item) {
                if (previousPoint != item.datapoint) {
                    previousPoint = item.datapoint;
                    
                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    
                    showTooltip(item.pageX, item.pageY,
                                "Requests per second  = " + y);
                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
    });

    $("#response").bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

            if (item) {
                if (previousPoint != item.datapoint) {
                    previousPoint = item.datapoint;
                    
                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    
                    showTooltip(item.pageX, item.pageY,
                                "Response time  = " + y);
                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
    });
    $("#requests").bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

            if (item) {
                if (previousPoint != item.datapoint) {
                    previousPoint = item.datapoint;
                    
                    $("#tooltip").remove();
                    var x = item.datapoint[0].toFixed(2),
                        y = item.datapoint[1].toFixed(2);
                    
                    showTooltip(item.pageX, item.pageY,
                                "Requests per second  = " + y);
                }
            }
            else {
                $("#tooltip").remove();
                previousPoint = null;            
            }
    });
    $("#response").bind("plotclick", function (event, pos, item) {
        if (item) {
            $("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
            plot.highlight(item.series, item.datapoint);
        }
    });
});
</script>

 </body>
</html>
