Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created July 29, 2009 10:38
Show Gist options
  • Save jakearchibald/157973 to your computer and use it in GitHub Desktop.
Save jakearchibald/157973 to your computer and use it in GitHub Desktop.
// here are the month names how we want to display them...
var fullMonthNames = [
"Janurary",
"Feburary",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
var shortMonthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
];
// add a scale to the top for each month with values like "March 2009"
myTimetable.addScale("month", "top", 100, {
// here's where we create the output for each segment of the scale
template: function(seg) {
// seg.start is a JavaScript date object
return
fullMonthNames[ seg.start.getMonth() ] +
" " +
seg.start.getFullYear();
}
});
// add a scale to the bottom for every saturday with values like "9 Aug"
myTimetable.addScale("week", "bottom", 100, {
// weekly intervals start on a Sunday by default, so we override this here
start: new Date("2009/01/03"),
// here's where we create the output for each segment of the scale
template: function(seg) {
// seg.start is a JavaScript date object
return
seg.start.getDate() +
" " +
shortMonthNames[ seg.start.getMonth() ];
}
});
// add a scrollbar to the bottom to display every quarter with values like "Jun 09"
// There isn't a shortcut for a quarterly interval, so we make a simple function for it
function quarterly(previousDate) {
var nextDate = new Date( previousDate.valueOf() );
if (nextDate.getMonth() > 8) {
// move to the next year
nextDate.setFullYear( nextDate.getFullYear() + 1 );
// advance 3 months (-12 + 3)
nextDate.setMonth( nextDate.getMonth() - 9 );
} else {
// advance 3 months
nextDate.setMonth( nextDate.getMonth() + 3 );
}
return nextDate;
}
myTimetable.addScrollbar(quarterly, "bottom", 50, {
// we want the intervals to start at the start of the year
start: new Date("2009/01/01"),
// here's where we create the output for each segment of the scale
template: function(seg) {
// seg.start is a JavaScript date object
return
shortMonthNames[ seg.start.getMonth() ] +
" " +
// this will get "2009" as a string then remove the first 2 chars
seg.start.getFullYear().toString().slice(2);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment