Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3284 vikas 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
<html>
3
 <head>
4
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
    <title>Flot Examples</title>
6
    <link href="layout.css" rel="stylesheet" type="text/css">
7
    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
8
    <script language="javascript" type="text/javascript" src="../jquery.js"></script>
9
    <script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>
10
 </head>
11
    <body>
12
    <h1>Flot Examples</h1>
13
 
14
    <div id="placeholder" style="width:600px;height:300px;"></div>
15
 
16
    <p>With multiple axes, you sometimes need to interact with them. A
17
    simple way to do this is to draw the plot, deduce the axis
18
    placements and insert a couple of divs on top to catch events.
19
    Try clicking an axis.</p>
20
 
21
    <p id="click"></p>
22
 
23
<script type="text/javascript">
24
$(function () {
25
    function generate(start, end, fn) {
26
        var res = [];
27
        for (var i = 0; i <= 100; ++i) {
28
            var x = start + i / 100 * (end - start);
29
            res.push([x, fn(x)]);
30
        }
31
        return res;
32
    }
33
 
34
    var data = [
35
        { data: generate(0, 10, function (x) { return Math.sqrt(x)}), xaxis: 1, yaxis:1 },
36
        { data: generate(0, 10, function (x) { return Math.sin(x)}), xaxis: 1, yaxis:2 },
37
        { data: generate(0, 10, function (x) { return Math.cos(x)}), xaxis: 1, yaxis:3 },
38
        { data: generate(2, 10, function (x) { return Math.tan(x)}), xaxis: 2, yaxis: 4 }
39
    ];
40
 
41
    var plot = $.plot($("#placeholder"),
42
                      data,
43
                      {
44
                          xaxes: [
45
                              { position: 'bottom' },
46
                              { position: 'top'}
47
                          ],
48
                          yaxes: [
49
                              { position: 'left' },
50
                              { position: 'left' },
51
                              { position: 'right' },
52
                              { position: 'left' }
53
                          ]
54
                      });
55
 
56
    // now for each axis, create a div
57
 
58
    function getBoundingBoxForAxis(plot, axis) {
59
        var left = axis.box.left, top = axis.box.top,
60
            right = left + axis.box.width, bottom = top + axis.box.height;
61
 
62
        // some ticks may stick out, enlarge the box to encompass all ticks
63
        var cls = axis.direction + axis.n + 'Axis';
64
        plot.getPlaceholder().find('.' + cls + ' .tickLabel').each(function () {
65
            var pos = $(this).position();
66
            left = Math.min(pos.left, left);
67
            top = Math.min(pos.top, top);
68
            right = Math.max(Math.round(pos.left) + $(this).outerWidth(), right);
69
            bottom = Math.max(Math.round(pos.top) + $(this).outerHeight(), bottom);
70
        });
71
 
72
        return { left: left, top: top, width: right - left, height: bottom - top };
73
    }
74
 
75
    $.each(plot.getAxes(), function (i, axis) {
76
        if (!axis.show)
77
            return;
78
 
79
        var box = getBoundingBoxForAxis(plot, axis);
80
 
81
        $('<div class="axisTarget" style="position:absolute;left:' + box.left + 'px;top:' + box.top + 'px;width:' + box.width +  'px;height:' + box.height + 'px"></div>')
82
            .data('axis.direction', axis.direction)
83
            .data('axis.n', axis.n)
84
            .css({ backgroundColor: "#f00", opacity: 0, cursor: "pointer" })
85
            .appendTo(plot.getPlaceholder())
86
            .hover(
87
                function () { $(this).css({ opacity: 0.10 }) },
88
                function () { $(this).css({ opacity: 0 }) }
89
            )
90
            .click(function () {
91
                $("#click").text("You clicked the " + axis.direction + axis.n + "axis!")
92
            });
93
    });
94
});
95
</script>
96
 </body>
97
</html>