Commit 485980ee by Torkel Ödegaard

Merge branch 'issue-2912' of https://github.com/benrubson/grafana into benrubson-issue-2912

parents 33664b0a 807bc5eb
...@@ -279,8 +279,14 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) { ...@@ -279,8 +279,14 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
break; break;
} }
default: { default: {
if (data.length && data[0].stats.timeStep) { var width;
options.series.bars.barWidth = data[0].stats.timeStep / 1.5; for (let i = 0; i < data.length; i++) {
if (data[i].stats.timeStep && (width == null || (data[i].stats.timeStep / 1.5) < width)) {
width = data[i].stats.timeStep / 1.5;
}
}
if (width) {
options.series.bars.barWidth = width;
} }
addTimeAxis(options); addTimeAxis(options);
break; break;
......
...@@ -2,7 +2,7 @@ define([ ...@@ -2,7 +2,7 @@ define([
'jquery', 'jquery',
'lodash' 'lodash'
], ],
function ($, _) { function ($) {
'use strict'; 'use strict';
function GraphTooltip(elem, dashboard, scope, getSeriesFn) { function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
...@@ -21,7 +21,8 @@ function ($, _) { ...@@ -21,7 +21,8 @@ function ($, _) {
var initial = last*ps; var initial = last*ps;
var len = series.datapoints.points.length; var len = series.datapoints.points.length;
for (var j = initial; j < len; j += ps) { for (var j = initial; j < len; j += ps) {
if (series.datapoints.points[j] > posX) { if ((series.datapoints.points[initial] != null && series.datapoints.points[j] == null && ! series.lines.steps)
|| series.datapoints.points[j] > posX) {
return Math.max(j - ps, 0)/ps; return Math.max(j - ps, 0)/ps;
} }
} }
...@@ -51,6 +52,8 @@ function ($, _) { ...@@ -51,6 +52,8 @@ function ($, _) {
//now we know the current X (j) position for X and Y values //now we know the current X (j) position for X and Y values
var last_value = 0; //needed for stacked values var last_value = 0; //needed for stacked values
var minDistance, minTime;
for (i = 0; i < seriesList.length; i++) { for (i = 0; i < seriesList.length; i++) {
series = seriesList[i]; series = seriesList[i];
...@@ -65,9 +68,16 @@ function ($, _) { ...@@ -65,9 +68,16 @@ function ($, _) {
} }
hoverIndex = this.findHoverIndexFromData(pos.x, series); hoverIndex = this.findHoverIndexFromData(pos.x, series);
hoverDistance = Math.abs(pos.x - series.data[hoverIndex][0]); hoverDistance = pos.x - series.data[hoverIndex][0];
pointTime = series.data[hoverIndex][0]; pointTime = series.data[hoverIndex][0];
if (! minDistance
|| (hoverDistance >=0 && (hoverDistance < minDistance || minDistance < 0))
|| (hoverDistance < 0 && hoverDistance > minDistance)) {
minDistance = hoverDistance;
minTime = pointTime;
}
if (series.stack) { if (series.stack) {
if (panel.tooltip.value_type === 'individual') { if (panel.tooltip.value_type === 'individual') {
value = series.data[hoverIndex][1]; value = series.data[hoverIndex][1];
...@@ -107,7 +117,7 @@ function ($, _) { ...@@ -107,7 +117,7 @@ function ($, _) {
} }
// Find point which closer to pointer // Find point which closer to pointer
results.time = _.min(results, 'distance').time; results.time = minTime;
return results; return results;
}; };
...@@ -153,6 +163,8 @@ function ($, _) { ...@@ -153,6 +163,8 @@ function ($, _) {
seriesHtml = ''; seriesHtml = '';
absoluteTime = dashboard.formatDate(seriesHoverInfo.time, tooltipFormat);
// Dynamically reorder the hovercard for the current time point if the // Dynamically reorder the hovercard for the current time point if the
// option is enabled, sort by yaxis by default. // option is enabled, sort by yaxis by default.
if (panel.tooltip.sort === 2) { if (panel.tooltip.sort === 2) {
...@@ -169,8 +181,6 @@ function ($, _) { ...@@ -169,8 +181,6 @@ function ($, _) {
}); });
} }
var distance, time;
for (i = 0; i < seriesHoverInfo.length; i++) { for (i = 0; i < seriesHoverInfo.length; i++) {
hoverInfo = seriesHoverInfo[i]; hoverInfo = seriesHoverInfo[i];
...@@ -178,11 +188,6 @@ function ($, _) { ...@@ -178,11 +188,6 @@ function ($, _) {
continue; continue;
} }
if (! distance || hoverInfo.distance < distance) {
distance = hoverInfo.distance;
time = hoverInfo.time;
}
var highlightClass = ''; var highlightClass = '';
if (item && i === item.seriesIndex) { if (item && i === item.seriesIndex) {
highlightClass = 'graph-tooltip-list-item--highlight'; highlightClass = 'graph-tooltip-list-item--highlight';
...@@ -198,7 +203,6 @@ function ($, _) { ...@@ -198,7 +203,6 @@ function ($, _) {
plot.highlight(hoverInfo.index, hoverInfo.hoverIndex); plot.highlight(hoverInfo.index, hoverInfo.hoverIndex);
} }
absoluteTime = dashboard.formatDate(time, tooltipFormat);
self.showTooltip(absoluteTime, seriesHtml, pos); self.showTooltip(absoluteTime, seriesHtml, pos);
} }
// single series tooltip // single series tooltip
......
...@@ -135,7 +135,7 @@ describe('grafanaGraph', function() { ...@@ -135,7 +135,7 @@ describe('grafanaGraph', function() {
}); });
it('should set barWidth', function() { it('should set barWidth', function() {
expect(ctx.plotOptions.series.bars.barWidth).to.be(10/1.5); expect(ctx.plotOptions.series.bars.barWidth).to.be(1/1.5);
}); });
}); });
......
...@@ -1201,27 +1201,24 @@ Licensed under the MIT license. ...@@ -1201,27 +1201,24 @@ Licensed under the MIT license.
points[k + m] = null; points[k + m] = null;
} }
} }
else {
// a little bit of line specific stuff that if (insertSteps && k > 0 && (!nullify || points[k - ps] != null)) {
// perhaps shouldn't be here, but lacking
// better means...
if (insertSteps && k > 0
&& points[k - ps] != null
&& points[k - ps] != points[k]
&& points[k - ps + 1] != points[k + 1]) {
// copy the point to make room for a middle point // copy the point to make room for a middle point
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m)
points[k + ps + m] = points[k + m]; points[k + ps + m] = points[k + m];
// middle point has same y // middle point has same y
points[k + 1] = points[k - ps + 1]; points[k + 1] = points[k - ps + 1] || 0;
// if series has null values, let's give the last correct value a nice step
if(nullify)
points[k] = p[0];
// we've added a point, better reflect that // we've added a point, better reflect that
k += ps; k += ps;
} }
} }
} }
}
// give the hooks a chance to run // give the hooks a chance to run
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
......
...@@ -78,41 +78,41 @@ charts or filled areas). ...@@ -78,41 +78,41 @@ charts or filled areas).
i = 0, j = 0, l, m; i = 0, j = 0, l, m;
while (true) { while (true) {
if (i >= points.length) if (i >= points.length && j >= otherpoints.length)
break; break;
l = newpoints.length; l = newpoints.length;
px = points[i + keyOffset];
py = points[i + accumulateOffset];
qx = otherpoints[j + keyOffset];
qy = otherpoints[j + accumulateOffset];
bottom = 0;
if (points[i] == null) { if (i < points.length && px == null) {
// copy gaps // ignore point
for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]);
i += ps; i += ps;
} }
else if (j < otherpoints.length && qx == null) {
// ignore point
j += otherps;
}
else if (i >= points.length) {
// take the remaining points from the previous series
for (m = 0; m < ps; ++m)
newpoints.push(otherpoints[j + m]);
bottom = qy;
j += otherps;
}
else if (j >= otherpoints.length) { else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points // take the remaining points from the current series
if (!withlines) {
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
}
i += ps; i += ps;
} }
else if (otherpoints[j] == null) {
// oops, got a gap
for (m = 0; m < ps; ++m)
newpoints.push(null);
fromgap = true;
j += otherps;
}
else { else {
// cases where we actually got two points // cases where we actually got two points
px = points[i + keyOffset];
py = points[i + accumulateOffset];
qx = otherpoints[j + keyOffset];
qy = otherpoints[j + accumulateOffset];
bottom = 0;
if (px == qx) { if (px == qx) {
// take the point from the current series and skip the previous' one
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
...@@ -123,54 +123,36 @@ charts or filled areas). ...@@ -123,54 +123,36 @@ charts or filled areas).
j += otherps; j += otherps;
} }
else if (px > qx) { else if (px > qx) {
// we got past point below, might need to // take the point from the previous series so that the next series can stack over it
// insert interpolated extra point for (m = 0; m < ps; ++m)
if (withlines && i > 0 && points[i - ps] != null) { newpoints.push(otherpoints[j + m]);
intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(qx); // we might be able to interpolate
newpoints.push(intery + qy); if (i > 0 && points[i - ps] != null)
for (m = 2; m < ps; ++m) newpoints[l + accumulateOffset] += py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(points[i + m]);
bottom = qy; bottom = qy;
}
j += otherps; j += otherps;
} }
else { // px < qx else { // px < qx
if (fromgap && withlines) { // take the point from the current series
// if we come from a gap, we just skip this point
i += ps;
continue;
}
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m)
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
// we might be able to interpolate a point below, // we might be able to interpolate a point below,
// this can give us a better y // this can give us a better y
if (withlines && j > 0 && otherpoints[j - otherps] != null) if (j > 0 && otherpoints[j - otherps] != null)
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx); bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
newpoints[l + accumulateOffset] += bottom; newpoints[l + accumulateOffset] += bottom;
i += ps; i += ps;
} }
fromgap = false;
if (l != newpoints.length && withbottom)
newpoints[l + 2] += bottom;
} }
// maintain the line steps invariant if (l != newpoints.length && withbottom)
if (withsteps && l != newpoints.length && l > 0 newpoints[l + 2] = bottom;
&& newpoints[l] != null
&& newpoints[l] != newpoints[l - ps]
&& newpoints[l + 1] != newpoints[l - ps + 1]) {
for (m = 0; m < ps; ++m)
newpoints[l + ps + m] = newpoints[l + m];
newpoints[l + 1] = newpoints[l - ps + 1];
}
} }
datapoints.points = newpoints; datapoints.points = newpoints;
......
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