Commit af65a81d by ubhatnagar

Added relative time in tooltip

parent 03e2f25a
...@@ -31,8 +31,13 @@ function ($) { ...@@ -31,8 +31,13 @@ function ($) {
return j - 1; return j - 1;
}; };
this.showTooltip = function(title, innerHtml, pos) { this.showTooltip = function(absoluteTime, relativeTime, innerHtml, pos) {
var body = '<div class="graph-tooltip small"><div class="graph-tooltip-time">'+ title + '</div> ' ; var body;
if(typeof relativeTime === 'undefined') {
body = '<div class="graph-tooltip small"><div class="graph-tooltip-time">'+ absoluteTime + '</div> ' ;
} else {
body = '<div class="graph-tooltip small"><div class="graph-tooltip-time">'+ absoluteTime + '<br>(' + relativeTime + ')</div> ' ;
}
body += innerHtml + '</div>'; body += innerHtml + '</div>';
$tooltip.html(body).place_tt(pos.pageX + 20, pos.pageY); $tooltip.html(body).place_tt(pos.pageX + 20, pos.pageY);
}; };
...@@ -101,7 +106,7 @@ function ($) { ...@@ -101,7 +106,7 @@ function ($) {
var plot = elem.data().plot; var plot = elem.data().plot;
var plotData = plot.getData(); var plotData = plot.getData();
var seriesList = getSeriesFn(); var seriesList = getSeriesFn();
var group, value, timestamp, hoverInfo, i, series, seriesHtml; var group, value, absoluteTime, relativeTime, hoverInfo, i, series, seriesHtml;
if(dashboard.sharedCrosshair){ if(dashboard.sharedCrosshair){
scope.appEvent('setCrosshair', { pos: pos, scope: scope }); scope.appEvent('setCrosshair', { pos: pos, scope: scope });
...@@ -117,12 +122,13 @@ function ($) { ...@@ -117,12 +122,13 @@ function ($) {
var seriesHoverInfo = self.getMultiSeriesPlotHoverInfo(plotData, pos); var seriesHoverInfo = self.getMultiSeriesPlotHoverInfo(plotData, pos);
seriesHtml = ''; seriesHtml = '';
if(scope.panel.tooltip.relativeTimestamp) { if(scope.panel.tooltip.relativeTimestamp) {
timestamp = dashboard.formatRelativeDate(seriesHoverInfo.time); relativeTime = dashboard.formatRelativeDate(seriesHoverInfo.time);
} else {
timestamp = dashboard.formatDate(seriesHoverInfo.time);
} }
absoluteTime = dashboard.formatDate(seriesHoverInfo.time);
for (i = 0; i < seriesHoverInfo.length; i++) { for (i = 0; i < seriesHoverInfo.length; i++) {
hoverInfo = seriesHoverInfo[i]; hoverInfo = seriesHoverInfo[i];
...@@ -140,7 +146,7 @@ function ($) { ...@@ -140,7 +146,7 @@ function ($) {
plot.highlight(i, hoverInfo.hoverIndex); plot.highlight(i, hoverInfo.hoverIndex);
} }
self.showTooltip(timestamp, seriesHtml, pos); self.showTooltip(absoluteTime, relativeTime, seriesHtml, pos);
} }
// single series tooltip // single series tooltip
else if (item) { else if (item) {
...@@ -158,14 +164,14 @@ function ($) { ...@@ -158,14 +164,14 @@ function ($) {
value = series.formatValue(value); value = series.formatValue(value);
if(scope.panel.tooltip.relativeTimestamp) { if(scope.panel.tooltip.relativeTimestamp) {
timestamp = dashboard.formatRelativeDate(item.datapoint[0]); relativeTime = dashboard.formatRelativeDate(item.datapoint[0]);
} else {
timestamp = dashboard.formatDate(item.datapoint[0]);
} }
absoluteTime = dashboard.formatDate(item.datapoint[0]);
group += '<div class="graph-tooltip-value">' + value + '</div>'; group += '<div class="graph-tooltip-value">' + value + '</div>';
self.showTooltip(timestamp, group, pos); self.showTooltipOther(absoluteTime, relativeTime, group, pos);
} }
// no hit // no hit
else { else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment