root / hci / trunk / eneraptor-web-app / web-app / js / flot / examples / navigate.html @ 69
History | View | Annotate | Download (3.98 KB)
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"></link> |
7 |
<!--[if IE]><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 |
<script language="javascript" type="text/javascript" src="../jquery.flot.navigate.js"></script> |
11 |
<style>
|
12 |
#placeholder .button {
|
13 |
position: absolute;
|
14 |
cursor: pointer;
|
15 |
}
|
16 |
#placeholder div.button {
|
17 |
font-size: smaller;
|
18 |
color: #999;
|
19 |
background-color: #eee;
|
20 |
padding: 2px;
|
21 |
}
|
22 |
.message {
|
23 |
padding-left: 50px;
|
24 |
font-size: smaller;
|
25 |
}
|
26 |
</style>
|
27 |
</head>
|
28 |
<body>
|
29 |
<h1>Flot Examples</h1> |
30 |
|
31 |
<div id="placeholder" style="width:600px;height:300px;"></div> |
32 |
|
33 |
<p class="message"></p> |
34 |
|
35 |
<p>With the navigate plugin it is easy to add panning and zooming.
|
36 |
Drag to pan, double click to zoom (or use the mouse scrollwheel).</p>
|
37 |
|
38 |
<p>The plugin fires events (useful for synchronizing several
|
39 |
plots) and adds a couple of public methods so you can easily build |
40 |
a little user interface around it, like the little buttons at the |
41 |
top right in the plot.</p>
|
42 |
|
43 |
|
44 |
<script id="source" language="javascript" type="text/javascript"> |
45 |
$(function () {
|
46 |
// generate data set from a parametric function with a fractal
|
47 |
// look
|
48 |
function sumf(f, t, m) {
|
49 |
var res = 0;
|
50 |
for (var i = 1; i < m; ++i)
|
51 |
res += f(i * i * t) / (i * i);
|
52 |
return res;
|
53 |
}
|
54 |
|
55 |
var d1 = [];
|
56 |
for (var t = 0; t <= 2 * Math.PI; t += 0.01)
|
57 |
d1.push([sumf(Math.cos, t, 10), sumf(Math.sin, t, 10)]);
|
58 |
var data = [ d1 ];
|
59 |
|
60 |
|
61 |
var placeholder = $("#placeholder");
|
62 |
var options = {
|
63 |
series: { lines: { show: true }, shadowSize: 0 },
|
64 |
xaxis: { zoomRange: [0.1, 10], panRange: [-10, 10] },
|
65 |
yaxis: { zoomRange: [0.1, 10], panRange: [-10, 10] },
|
66 |
zoom: {
|
67 |
interactive: true
|
68 |
},
|
69 |
pan: {
|
70 |
interactive: true
|
71 |
}
|
72 |
};
|
73 |
|
74 |
var plot = $.plot(placeholder, data, options);
|
75 |
|
76 |
// show pan/zoom messages to illustrate events
|
77 |
placeholder.bind('plotpan', function (event, plot) {
|
78 |
var axes = plot.getAxes();
|
79 |
$(".message").html("Panning to x: " + axes.xaxis.min.toFixed(2)
|
80 |
+ " – " + axes.xaxis.max.toFixed(2)
|
81 |
+ " and y: " + axes.yaxis.min.toFixed(2)
|
82 |
+ " – " + axes.yaxis.max.toFixed(2));
|
83 |
});
|
84 |
|
85 |
placeholder.bind('plotzoom', function (event, plot) {
|
86 |
var axes = plot.getAxes();
|
87 |
$(".message").html("Zooming to x: " + axes.xaxis.min.toFixed(2)
|
88 |
+ " – " + axes.xaxis.max.toFixed(2)
|
89 |
+ " and y: " + axes.yaxis.min.toFixed(2)
|
90 |
+ " – " + axes.yaxis.max.toFixed(2));
|
91 |
});
|
92 |
|
93 |
// add zoom out button
|
94 |
$('<div class="button" style="right:20px;top:20px">zoom out</div>').appendTo(placeholder).click(function (e) {
|
95 |
e.preventDefault();
|
96 |
plot.zoomOut();
|
97 |
});
|
98 |
|
99 |
// and add panning buttons
|
100 |
|
101 |
// little helper for taking the repetitive work out of placing
|
102 |
// panning arrows
|
103 |
function addArrow(dir, right, top, offset) {
|
104 |
$('<img class="button" src="arrow-' + dir + '.gif" style="right:' + right + 'px;top:' + top + 'px">').appendTo(placeholder).click(function (e) {
|
105 |
e.preventDefault();
|
106 |
plot.pan(offset);
|
107 |
});
|
108 |
}
|
109 |
|
110 |
addArrow('left', 55, 60, { left: -100 });
|
111 |
addArrow('right', 25, 60, { left: 100 });
|
112 |
addArrow('up', 40, 45, { top: -100 });
|
113 |
addArrow('down', 40, 75, { top: 100 });
|
114 |
});
|
115 |
</script>
|
116 |
|
117 |
</body>
|
118 |
</html>
|