-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Add time navigation buttons #8546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import moment from 'moment'; | |
| import UiModules from 'ui/modules'; | ||
| import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls'; | ||
|
||
| import { once, clone } from 'lodash'; | ||
| import dateMath from '@elastic/datemath'; | ||
|
|
||
| import toggleHtml from './kbn_global_timepicker.html'; | ||
|
|
||
|
|
@@ -25,6 +26,71 @@ UiModules | |
| $rootScope.toggleRefresh = () => { | ||
| timefilter.refreshInterval.pause = !timefilter.refreshInterval.pause; | ||
| }; | ||
|
|
||
| // travel forward in time based on the interval between from and to | ||
| $scope.forward = function () { | ||
| const time = getFromTo(); | ||
| const diff = time.to.diff(time.from); | ||
| const origTo = time.to.toISOString(); | ||
|
|
||
| time.to.add(diff, 'milliseconds'); | ||
| timefilter.time.from = origTo; | ||
| timefilter.time.to = time.to.toISOString(); | ||
| }; | ||
|
|
||
| // travel backwards in time based on the interval between from and to | ||
| $scope.back = function () { | ||
| const time = getFromTo(); | ||
| const diff = time.to.diff(time.from); | ||
| const origFrom = time.from.toISOString(); | ||
|
|
||
| time.from.subtract(diff, 'milliseconds'); | ||
| timefilter.time.from = time.from.toISOString(); | ||
| timefilter.time.to = origFrom; | ||
| }; | ||
|
|
||
| // zoom out, doubling the difference between start and end, keeping the same time range center | ||
| $scope.zoomOut = function () { | ||
| const time = getFromTo(); | ||
| const from = time.from.unix() * 1000; | ||
| const to = time.to.unix() * 1000; | ||
|
|
||
| const diff = Math.floor((to - from) / 2); | ||
|
|
||
| timefilter.time.from = moment(from - diff).toISOString(); | ||
| timefilter.time.to = moment(to + diff).toISOString(); | ||
| }; | ||
|
|
||
| // zoom in, halving the difference between start and end, keeping the same time range center | ||
| $scope.zoomIn = function () { | ||
| const time = getFromTo(); | ||
| const from = time.from.unix() * 1000; | ||
| const to = time.to.unix() * 1000; | ||
|
|
||
| const diff = Math.floor((to - from) / 4); | ||
|
|
||
| timefilter.time.from = moment(from + diff).toISOString(); | ||
| timefilter.time.to = moment(to - diff).toISOString(); | ||
| }; | ||
|
|
||
| // find the from and to values from the timefilter | ||
| // if a quick or relative mode has been selected, work out the | ||
| // absolute times and then change the mode to absolute | ||
| function getFromTo() { | ||
| if (timefilter.time.mode === 'absolute') { | ||
| return { | ||
| to: moment(timefilter.time.to), | ||
| from: moment(timefilter.time.from) | ||
| }; | ||
| } else { | ||
| timefilter.time.mode = 'absolute'; | ||
|
||
| return { | ||
| to: dateMath.parse(timefilter.time.to, true), | ||
| from: dateMath.parse(timefilter.time.from) | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| }, | ||
| }; | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for me, I think it looks good.