-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add time navigation buttons * changing vars to const * Address some review points * fixing typo in function name * Remove unused variables * [timepicker] Simplify zoom in/out and forward/back and remove getter that had side effects * [timepicker] Move time navigation calculations to own class and write test * [timepicker] Remove unused styling and classes * [timepicker] Change from i to span, add more explanatory comments * [timepicker] Remove unused variable * Remove zoom in/out buttons from timepicker nav * Change step forward/back timepicker nav button icons
- Loading branch information
1 parent
a4e201f
commit 33d23d0
Showing
5 changed files
with
101 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import expect from 'expect.js'; | ||
import moment from 'moment'; | ||
import timeNavigation from '../time_navigation'; | ||
|
||
describe('timeNavigation', () => { | ||
let bounds; | ||
|
||
beforeEach(() => { | ||
bounds = { | ||
min: moment('2016-01-01T00:00:00.000Z'), | ||
max: moment('2016-01-01T00:15:00.000Z') | ||
}; | ||
}); | ||
|
||
it('should step forward by the amount of the duration', () => { | ||
const {from, to} = timeNavigation.stepForward(bounds); | ||
expect(from).to.be('2016-01-01T00:15:00.000Z'); | ||
expect(to).to.be('2016-01-01T00:30:00.000Z'); | ||
}); | ||
|
||
it('should step backward by the amount of the duration', () => { | ||
const {from, to} = timeNavigation.stepBackward(bounds); | ||
expect(from).to.be('2015-12-31T23:45:00.000Z'); | ||
expect(to).to.be('2016-01-01T00:00:00.000Z'); | ||
}); | ||
|
||
it('should zoom out to be double the original duration', () => { | ||
const {from, to} = timeNavigation.zoomOut(bounds); | ||
expect(from).to.be('2015-12-31T23:52:30.000Z'); | ||
expect(to).to.be('2016-01-01T00:22:30.000Z'); | ||
}); | ||
|
||
it('should zoom in to be half the original duration', () => { | ||
const {from, to} = timeNavigation.zoomIn(bounds); | ||
expect(from).to.be('2016-01-01T00:03:45.000Z'); | ||
expect(to).to.be('2016-01-01T00:11:15.000Z'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import moment from 'moment'; | ||
|
||
export default { | ||
// travel forward in time based on the interval between from and to | ||
stepForward({min, max}) { | ||
const diff = max.diff(min); | ||
return { | ||
from: max.toISOString(), | ||
to: moment(max).add(diff).toISOString() | ||
}; | ||
}, | ||
|
||
// travel backwards in time based on the interval between from and to | ||
stepBackward({min, max}) { | ||
const diff = max.diff(min); | ||
return { | ||
from: moment(min).subtract(diff).toISOString(), | ||
to: min.toISOString() | ||
}; | ||
}, | ||
|
||
// zoom out, doubling the difference between start and end, keeping the same time range center | ||
zoomOut({min, max}) { | ||
const diff = max.diff(min); | ||
return { | ||
from: moment(min).subtract(diff / 2).toISOString(), | ||
to: moment(max).add(diff / 2).toISOString() | ||
}; | ||
}, | ||
|
||
// zoom in, halving the difference between start and end, keeping the same time range center | ||
zoomIn({min, max}) { | ||
const diff = max.diff(min); | ||
return { | ||
from: moment(min).add(diff / 4).toISOString(), | ||
to: moment(max).subtract(diff / 4).toISOString() | ||
}; | ||
} | ||
}; |