Debian Codegraph @

examples/selection/index.html

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title>Flot Examples: Selection</title>
6 <link href="../examples.css" rel="stylesheet" type="text/css">
7 <script language="javascript" type="text/javascript" src="../../source/jquery.js"></script>
8 <script language="javascript" type="text/javascript" src="../../lib/jquery.event.drag.js"></script>
9 <script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
10 <script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
11 <script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
12 <script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
13 <script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
14 <script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
15 <script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
16 <script language="javascript" type="text/javascript" src="../../source/jquery.flot.selection.js"></script>
17 <script type="text/javascript">
18
19 $(function() {
20
21 // Shim allowing us to get the state of the check-box on jQuery versions
22 // prior to 1.6, when prop was added. The reason we don't just use attr
23 // is because it doesn't work in jQuery versions 1.9.x and later.
24
25 // TODO: Remove this once Flot's minimum supported jQuery reaches 1.6.
26 if (typeof $.fn.prop != 'function') {
27 $.fn.prop = $.fn.attr;
28 }
29
30 var data = [{
31 label: "United States",
32 data: [[1990, 18.9], [1991, 18.7], [1992, 18.4], [1993, 19.3], [1994, 19.5], [1995, 19.3], [1996, 19.4], [1997, 20.2], [1998, 19.8], [1999, 19.9], [2000, 20.4], [2001, 20.1], [2002, 20.0], [2003, 19.8], [2004, 20.4]]
33 }, {
34 label: "Russia",
35 data: [[1992, 13.4], [1993, 12.2], [1994, 10.6], [1995, 10.2], [1996, 10.1], [1997, 9.7], [1998, 9.5], [1999, 9.7], [2000, 9.9], [2001, 9.9], [2002, 9.9], [2003, 10.3], [2004, 10.5]]
36 }, {
37 label: "United Kingdom",
38 data: [[1990, 10.0], [1991, 11.3], [1992, 9.9], [1993, 9.6], [1994, 9.5], [1995, 9.5], [1996, 9.9], [1997, 9.3], [1998, 9.2], [1999, 9.2], [2000, 9.5], [2001, 9.6], [2002, 9.3], [2003, 9.4], [2004, 9.79]]
39 }, {
40 label: "Germany",
41 data: [[1990, 12.4], [1991, 11.2], [1992, 10.8], [1993, 10.5], [1994, 10.4], [1995, 10.2], [1996, 10.5], [1997, 10.2], [1998, 10.1], [1999, 9.6], [2000, 9.7], [2001, 10.0], [2002, 9.7], [2003, 9.8], [2004, 9.79]]
42 }, {
43 label: "Denmark",
44 data: [[1990, 9.7], [1991, 12.1], [1992, 10.3], [1993, 11.3], [1994, 11.7], [1995, 10.6], [1996, 12.8], [1997, 10.8], [1998, 10.3], [1999, 9.4], [2000, 8.7], [2001, 9.0], [2002, 8.9], [2003, 10.1], [2004, 9.80]]
45 }, {
46 label: "Sweden",
47 data: [[1990, 5.8], [1991, 6.0], [1992, 5.9], [1993, 5.5], [1994, 5.7], [1995, 5.3], [1996, 6.1], [1997, 5.4], [1998, 5.4], [1999, 5.1], [2000, 5.2], [2001, 5.4], [2002, 6.2], [2003, 5.9], [2004, 5.89]]
48 }, {
49 label: "Norway",
50 data: [[1990, 8.3], [1991, 8.3], [1992, 7.8], [1993, 8.3], [1994, 8.4], [1995, 5.9], [1996, 6.4], [1997, 6.7], [1998, 6.9], [1999, 7.6], [2000, 7.4], [2001, 8.1], [2002, 12.5], [2003, 9.9], [2004, 19.0]]
51 }];
52
53 var options = {
54 series: {
55 lines: {
56 show: true
57 },
58 points: {
59 show: true
60 }
61 },
62 legend: {
63 noColumns: 2
64 },
65 xaxis: {
66 autoScale: "exact",
67 tickDecimals: 0
68 },
69 yaxis: {
70 autoScale: "loose",
71 autoScaleMargin: 0.2,
72 min: 0
73 },
74 selection: {
75 mode: "x"
76 }
77 };
78
79 var placeholder = $("#placeholder");
80
81 placeholder.bind("plotselected", function (event, ranges) {
82
83 $("#selection").text(ranges.xaxis.from.toFixed(1) + " to " + ranges.xaxis.to.toFixed(1));
84
85 var zoom = $("#zoom").prop("checked");
86
87 if (zoom) {
88 $.each(plot.getXAxes(), function(_, axis) {
89 var opts = axis.options;
90 opts.min = ranges.xaxis.from;
91 opts.max = ranges.xaxis.to;
92 });
93 plot.setupGrid();
94 plot.draw();
95 plot.clearSelection();
96 }
97 });
98
99 placeholder.bind("plotunselected", function (event) {
100 $("#selection").text("");
101 });
102
103 var plot = $.plot(placeholder, data, options);
104
105 $("#clearSelection").click(function () {
106 plot.clearSelection();
107 });
108
109 $("#setSelection").click(function () {
110 plot.setSelection({
111 xaxis: {
112 from: 1994,
113 to: 1995
114 }
115 });
116 });
117
118 // Add the Flot version string to the footer
119
120 $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
121 });
122
123 </script>
124 </head>
125 <body>
126
127 <div id="header">
128 <h2>Selection</h2>
129 </div>
130
131 <div id="content">
132
133 <div class="demo-container">
134 <div id="placeholder" class="demo-placeholder"></div>
135 </div>
136
137 <p>1000 kg. CO<sub>2</sub> emissions per year per capita for various countries (source: <a href="http://en.wikipedia.org/wiki/List_of_countries_by_carbon_dioxide_emissions_per_capita">Wikipedia</a>).</p>
138
139 <p>Flot supports selections through the selection plugin. You can enable rectangular selection or one-dimensional selection if the user should only be able to select on one axis. Try left-click and drag on the plot above where selection on the x axis is enabled.</p>
140
141 <p>You selected: <span id="selection"></span></p>
142
143 <p>The plot command returns a plot object you can use to control the selection. Click the buttons below.</p>
144
145 <p>
146 <button id="clearSelection">Clear selection</button>
147 <button id="setSelection">Select year 1994</button>
148 </p>
149
150 <p>Selections are really useful for zooming. Just replot the chart with min and max values for the axes set to the values in the "plotselected" event triggered. Enable the checkbox below and select a region again.</p>
151
152 <p><label><input id="zoom" type="checkbox"></input>Zoom to selection.</label></p>
153
154 </div>
155
156 <div id="footer">
157 Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
158 </div>
159
160 </body>
161 </html>