Add week in label_specs

This commit is contained in:
dhoko 2013-06-04 21:38:35 +02:00
parent b98ae8ab1d
commit b192a00d68
4 changed files with 34 additions and 3 deletions

View File

@ -359,6 +359,11 @@ Morris.LABEL_SPECS =
start: (d) -> new Date(d.getFullYear(), d.getMonth(), 1)
fmt: (d) -> "#{d.getFullYear()}-#{Morris.pad2(d.getMonth() + 1)}"
incr: (d) -> d.setMonth(d.getMonth() + 1)
"week":
span: 604800000 # 7 * 24 * 60 * 60 * 1000
start: (d) -> new Date(d.getFullYear(), d.getMonth(), d.getDate())
fmt: (d) -> "#{d.getFullYear()}-#{Morris.pad2(d.getMonth() + 1)}-#{Morris.pad2(d.getDate())}"
incr: (d) -> d.setDate(d.getDate() + 7)
"day":
span: 86400000 # 24 * 60 * 60 * 1000
start: (d) -> new Date(d.getFullYear(), d.getMonth(), d.getDate())
@ -377,7 +382,7 @@ Morris.LABEL_SPECS =
"second": secondsSpecHelper(1)
Morris.AUTO_LABEL_ORDER = [
"decade", "year", "month", "day", "hour",
"decade", "year", "month", "week", "day", "hour",
"30min", "15min", "10min", "5min", "minute",
"30sec", "15sec", "10sec", "5sec", "second"
]

View File

@ -1151,6 +1151,18 @@
return d.setMonth(d.getMonth() + 1);
}
},
"week": {
span: 604800000,
start: function(d) {
return new Date(d.getFullYear(), d.getMonth(), d.getDate());
},
fmt: function(d) {
return "" + (d.getFullYear()) + "-" + (Morris.pad2(d.getMonth() + 1)) + "-" + (Morris.pad2(d.getDate()));
},
incr: function(d) {
return d.setDate(d.getDate() + 7);
}
},
"day": {
span: 86400000,
start: function(d) {
@ -1176,7 +1188,7 @@
"second": secondsSpecHelper(1)
};
Morris.AUTO_LABEL_ORDER = ["decade", "year", "month", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"];
Morris.AUTO_LABEL_ORDER = ["decade", "year", "month", "week", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"];
Morris.Area = (function(_super) {
var areaDefaults;

2
morris.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -65,6 +65,20 @@ describe '#labelSeries', ->
["2012-06", new Date(2012, 5, 1).getTime()]
])
it 'should generate week intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1).getTime(),
new Date(2012, 1, 10).getTime(),
1000
).should.deep.equal([
["2012-01-01", new Date(2012, 0, 1).getTime()],
["2012-01-08", new Date(2012, 0, 8).getTime()],
["2012-01-15", new Date(2012, 0, 15).getTime()],
["2012-01-22", new Date(2012, 0, 22).getTime()],
["2012-01-29", new Date(2012, 0, 29).getTime()],
["2012-02-05", new Date(2012, 1, 5).getTime()]
])
it 'should generate day intervals', ->
Morris.labelSeries(
new Date(2012, 0, 1).getTime(),