Вход Регистрация
Файл: admin/skins/lib/flot/examples/interacting-axes.html
Строк: 96
<?php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html>
 <
head>
    <
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
title>Flot Examples</title>
    <
link href="layout.css" rel="stylesheet" type="text/css">
    <!--[if 
lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
    <
script language="javascript" type="text/javascript" src="../jquery.js"></script>
    <
script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
 </
head>
    <
body>
    <
h1>Flot Examples</h1>

    <
div id="placeholder" style="width:600px;height:300px;"></div>

    <
p>With multiple axesyou sometimes need to interact with themA
    simple way to 
do this is to draw the plotdeduce the axis
    placements 
and insert a couple of divs on top to catch events.
    Try 
clicking an axis.</p>

    <
p id="click"></p>

<
script type="text/javascript">
$(function () {
    function 
generate(startendfn) {
        var 
res = [];
        for (var 
0<= 100; ++i) {
            var 
start 100 * (end start);
            
res.push([xfn(x)]);
        }
        return 
res;
    }

    var 
data = [
        { 
datagenerate(010, function (x) { return Math.sqrt(x)}), xaxis1yaxis:},
        { 
datagenerate(010, function (x) { return Math.sin(x)}), xaxis1yaxis:},
        { 
datagenerate(010, function (x) { return Math.cos(x)}), xaxis1yaxis:},
        { 
datagenerate(210, function (x) { return Math.tan(x)}), xaxis2yaxis}
    ];

    var 
plot = $.plot($("#placeholder"),
                      
data,
                      {
                          
xaxes: [
                              { 
position'bottom' },
                              { 
position'top'}
                          ],
                          
yaxes: [
                              { 
position'left' },
                              { 
position'left' },
                              { 
position'right' },
                              { 
position'left' }
                          ]
                      });

    
// now for each axis, create a div

    
function getBoundingBoxForAxis(plotaxis) {
        var 
left axis.box.lefttop axis.box.top,
            
right left axis.box.widthbottom top axis.box.height;

        
// some ticks may stick out, enlarge the box to encompass all ticks
        
var cls axis.direction axis.'Axis';
        
plot.getPlaceholder().find('.' cls ' .tickLabel').each(function () {
            var 
pos = $(this).position();
            
left Math.min(pos.leftleft);
            
top Math.min(pos.toptop);
            
right Math.max(Math.round(pos.left) + $(this).outerWidth(), right);
            
bottom Math.max(Math.round(pos.top) + $(this).outerHeight(), bottom);
        });
        
        return { 
leftlefttoptopwidthright leftheightbottom top };
    }
    
    $.
each(plot.getAxes(), function (iaxis) {
        if (!
axis.show)
            return;
        
        var 
box getBoundingBoxForAxis(plotaxis);
        
        $(
'<div class="axisTarget" style="position:absolute;left:' box.left 'px;top:' box.top 'px;width:' box.width +  'px;height:' box.height 'px"></div>')
            .
data('axis.direction'axis.direction)
            .
data('axis.n'axis.n)
            .
css({ backgroundColor"#f00"opacity0cursor"pointer" })
            .
appendTo(plot.getPlaceholder())
            .
hover(
                function () { $(
this).css({ opacity0.10 }) },
                function () { $(
this).css({ opacity}) }
            )
            .
click(function () {
                $(
"#click").text("You clicked the " axis.direction axis."axis!")
            });
    });
});
</
script>
 </
body>
</
html>
?>
Онлайн: 1
Реклама