mirror of
https://github.com/morrisjs/morris.js.git
synced 2024-11-10 21:36:34 +01:00
Decade intervals for time-axis labels.
This commit is contained in:
parent
2a2a849ebd
commit
25698d6664
@ -329,6 +329,11 @@ secondsSpecHelper = (interval) ->
|
|||||||
incr: (d) -> d.setSeconds(d.getSeconds() + interval)
|
incr: (d) -> d.setSeconds(d.getSeconds() + interval)
|
||||||
|
|
||||||
Morris.LABEL_SPECS =
|
Morris.LABEL_SPECS =
|
||||||
|
"decade":
|
||||||
|
span: 172800000000 # 10 * 365 * 24 * 60 * 60 * 1000
|
||||||
|
start: (d) -> new Date(d.getFullYear() - d.getFullYear() % 10, 0, 1)
|
||||||
|
fmt: (d) -> "#{d.getFullYear()}"
|
||||||
|
incr: (d) -> d.setFullYear(d.getFullYear() + 10)
|
||||||
"year":
|
"year":
|
||||||
span: 17280000000 # 365 * 24 * 60 * 60 * 1000
|
span: 17280000000 # 365 * 24 * 60 * 60 * 1000
|
||||||
start: (d) -> new Date(d.getFullYear(), 0, 1)
|
start: (d) -> new Date(d.getFullYear(), 0, 1)
|
||||||
@ -357,7 +362,7 @@ Morris.LABEL_SPECS =
|
|||||||
"second": secondsSpecHelper(1)
|
"second": secondsSpecHelper(1)
|
||||||
|
|
||||||
Morris.AUTO_LABEL_ORDER = [
|
Morris.AUTO_LABEL_ORDER = [
|
||||||
"year", "month", "day", "hour",
|
"decade", "year", "month", "day", "hour",
|
||||||
"30min", "15min", "10min", "5min", "minute",
|
"30min", "15min", "10min", "5min", "minute",
|
||||||
"30sec", "15sec", "10sec", "5sec", "second"
|
"30sec", "15sec", "10sec", "5sec", "second"
|
||||||
]
|
]
|
||||||
|
14
morris.js
14
morris.js
@ -892,6 +892,18 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Morris.LABEL_SPECS = {
|
Morris.LABEL_SPECS = {
|
||||||
|
"decade": {
|
||||||
|
span: 172800000000,
|
||||||
|
start: function(d) {
|
||||||
|
return new Date(d.getFullYear() - d.getFullYear() % 10, 0, 1);
|
||||||
|
},
|
||||||
|
fmt: function(d) {
|
||||||
|
return "" + (d.getFullYear());
|
||||||
|
},
|
||||||
|
incr: function(d) {
|
||||||
|
return d.setFullYear(d.getFullYear() + 10);
|
||||||
|
}
|
||||||
|
},
|
||||||
"year": {
|
"year": {
|
||||||
span: 17280000000,
|
span: 17280000000,
|
||||||
start: function(d) {
|
start: function(d) {
|
||||||
@ -941,7 +953,7 @@
|
|||||||
"second": secondsSpecHelper(1)
|
"second": secondsSpecHelper(1)
|
||||||
};
|
};
|
||||||
|
|
||||||
Morris.AUTO_LABEL_ORDER = ["year", "month", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"];
|
Morris.AUTO_LABEL_ORDER = ["decade", "year", "month", "day", "hour", "30min", "15min", "10min", "5min", "minute", "30sec", "15sec", "10sec", "5sec", "second"];
|
||||||
|
|
||||||
Morris.Area = (function(_super) {
|
Morris.Area = (function(_super) {
|
||||||
|
|
||||||
|
2
morris.min.js
vendored
2
morris.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,5 +1,31 @@
|
|||||||
describe '#labelSeries', ->
|
describe '#labelSeries', ->
|
||||||
|
|
||||||
|
it 'should generate decade intervals', ->
|
||||||
|
Morris.labelSeries(
|
||||||
|
new Date(1952, 0, 1).getTime(),
|
||||||
|
new Date(2012, 0, 1).getTime(),
|
||||||
|
1000
|
||||||
|
).should.deep.equal([
|
||||||
|
["1960", new Date(1960, 0, 1).getTime()],
|
||||||
|
["1970", new Date(1970, 0, 1).getTime()],
|
||||||
|
["1980", new Date(1980, 0, 1).getTime()],
|
||||||
|
["1990", new Date(1990, 0, 1).getTime()],
|
||||||
|
["2000", new Date(2000, 0, 1).getTime()],
|
||||||
|
["2010", new Date(2010, 0, 1).getTime()]
|
||||||
|
])
|
||||||
|
Morris.labelSeries(
|
||||||
|
new Date(1952, 3, 1).getTime(),
|
||||||
|
new Date(2012, 3, 1).getTime(),
|
||||||
|
1000
|
||||||
|
).should.deep.equal([
|
||||||
|
["1960", new Date(1960, 0, 1).getTime()],
|
||||||
|
["1970", new Date(1970, 0, 1).getTime()],
|
||||||
|
["1980", new Date(1980, 0, 1).getTime()],
|
||||||
|
["1990", new Date(1990, 0, 1).getTime()],
|
||||||
|
["2000", new Date(2000, 0, 1).getTime()],
|
||||||
|
["2010", new Date(2010, 0, 1).getTime()]
|
||||||
|
])
|
||||||
|
|
||||||
it 'should generate year intervals', ->
|
it 'should generate year intervals', ->
|
||||||
Morris.labelSeries(
|
Morris.labelSeries(
|
||||||
new Date(2007, 0, 1).getTime(),
|
new Date(2007, 0, 1).getTime(),
|
||||||
|
Loading…
Reference in New Issue
Block a user