Skip to content
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

Add time navigation buttons #8546

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ui/public/styles/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ a {
}

.navbar-timepicker {
border-left: 1px solid @kibanaGray4;

Copy link
Contributor

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.

> li > a {
padding-left: 7px !important;
padding-right: 7px !important;
Expand All @@ -232,6 +234,11 @@ a {
background-color: transparent;
border-radius: 0;
}

.time-nav-btn {
padding-left: 10px;
padding-right: 10px;
}
}

.navbar-timepicker-time-desc > .fa-clock-o {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/timepicker/kbn_global_timepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</li>

<li>
<i ng-click="zoomIn()" class="time-nav-btn fa fa-search-plus ng-scope" tooltip="Zoom in"></i>
<i ng-click="zoomOut()" class="time-nav-btn fa fa-search-minus ng-scope" tooltip="Zoom out"></i>
<i ng-click="back()" class="time-nav-btn fa fa-arrow-left ng-scope" tooltip="Move backwards in time"></i>
<button ng-class="{active: kbnTopNav.isCurrent('filter')}"
ng-click="kbnTopNav.toggle('filter')"
aria-haspopup="true"
Expand All @@ -28,5 +31,6 @@
<i aria-hidden="true" class="fa fa-clock-o"></i>
<pretty-duration from="timefilter.time.from" to="timefilter.time.to"></pretty-duration>
</button>
<i ng-click="forward()" class="time-nav-btn fa fa-arrow-right ng-scope" tooltip="Move forwards in time"></i>
</li>
</ul>
66 changes: 66 additions & 0 deletions src/ui/public/timepicker/kbn_global_timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import moment from 'moment';
import UiModules from 'ui/modules';
import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls';
Copy link
Contributor

@thomasneirynck thomasneirynck Oct 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this import is obsolete. linter was also complaining about unused function arguments in this file as well: config, newval, oldVal, $el, attrs

While we're at it, we may as well remove them ;)

import { once, clone } from 'lodash';
import dateMath from '@elastic/datemath';

import toggleHtml from './kbn_global_timepicker.html';

Expand All @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: consider not doing the side-effect in this getter/setter. If you prefer to avoid two function-calls, perhaps rename this function to something like setToTimeToAbsoluteAndGetToFrom (yeah, i know :$). But now, this state change is a little buried.

return {
to: dateMath.parse(timefilter.time.to, true),
from: dateMath.parse(timefilter.time.from)
};
}
}

},
};
});