8000 Extend time period snap example GUI to include a select box to switch… · leetcode/flot-plugin-collection@051ceab · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 051ceab

Browse files
committed
Extend time period snap example GUI to include a select box to switch between period units (hour, day, week, year)
1 parent 73ef2ff commit 051ceab

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

examples/snap.html

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
<script language="javascript" type="text/javascript">
1717
$(document).ready(function() {
1818
var plot,
19-
container = $('#plot'), // plot container
20-
ui = $('#ui'), // buttons container
21-
periods = [ 'day' ], // time periods
22-
period = periods[0]; // in use time period
19+
container = $('#plot'), // plot container
20+
ui = $('#ui'), // buttons container
21+
periods = [ 'hour', 'day', 'week', 'year' ], // time periods
22+
period = periods[1]; // the default time period unit - day
2323

2424
// create the ui buttons
25-
var createUI = function(container, period, periods) {
25+
var createUI = function(container, period) {
2626
createButton('<< prev ' + period)
2727
.appendTo(container)
2828
.click(function() {
@@ -65,14 +65,33 @@
6565
plot = $.plot(container, [ data ], options);
6666

6767
// create the ui buttons
68-
createUI(ui, period, periods);
68+
createUI(ui, period);
69+
70+
$('#snapSelect').change(function() {
71+
var value = this.options[this.selectedIndex].value;
72+
ui.empty();
73+
createUI(ui, periods[periods.indexOf(value)]);
74+
plot.snapTo(value, 0);
75+
});
76+
6977
};
7078

7179
init();
7280
});
7381
</script>
7482

7583
<div id="plot" style="width:600px;height:200px;"></div>
76-
<div id="ui" style="width:600px;height:100px;"></div>
84+
85+
Snap Unit:
86+
<select id="snapSelect">
87+
<option value="hour">Hour</option>
88+
<option value="day" selected="selected">Day</option>
89+
<option value="week">Week</option>
90+
<option value="year">Year</option>
91+
</select>
92+
93+
<div id="ui" style="width:600px;height:100px;">
94+
</div>
95+
</div>
7796
</body>
7897
</html>

0 commit comments

Comments
 (0)
0