Skip to content

Commit 2443326

Browse files
Ben RUBSONtorkelo
authored andcommitted
Add some comments about some previous modifications (grafana#6533)
1 parent ef08a24 commit 2443326

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

public/app/plugins/panel/graph/graph.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
183183
}
184184
}
185185

186+
// Series could have different timeSteps,
187+
// let's find the smallest one so that bars are correctly rendered.
186188
function getMinTimeStepOfSeries(data) {
187189
var min = 100000000000;
188190

public/app/plugins/panel/graph/graph_tooltip.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ function ($) {
2121
var initial = last*ps;
2222
var len = series.datapoints.points.length;
2323
for (var j = initial; j < len; j += ps) {
24+
// Special case of a non stepped line, highlight the very last point just before a null point
2425
if ((series.datapoints.points[initial] != null && series.datapoints.points[j] == null && ! series.lines.steps)
26+
//normal case
2527
|| series.datapoints.points[j] > posX) {
2628
return Math.max(j - ps, 0)/ps;
2729
}
@@ -58,11 +60,13 @@ function ($) {
5860
series = seriesList[i];
5961

6062
if (!series.data.length || (panel.legend.hideEmpty && series.allIsNull)) {
63+
// Init value & yaxis so that it does not brake series sorting
6164
results.push({ hidden: true, value: 0, yaxis: 0 });
6265
continue;
6366
}
6467

6568
if (!series.data.length || (panel.legend.hideZero && series.allIsZero)) {
69+
// Init value & yaxis so that it does not brake series sorting
6670
results.push({ hidden: true, value: 0, yaxis: 0 });
6771
continue;
6872
}
@@ -71,6 +75,7 @@ function ($) {
7175
hoverDistance = pos.x - series.data[hoverIndex][0];
7276
pointTime = series.data[hoverIndex][0];
7377

78+
// Take the closest point before the cursor, or if it does not exist, the closest after
7479
if (! minDistance
7580
|| (hoverDistance >=0 && (hoverDistance < minDistance || minDistance < 0))
7681
|| (hoverDistance < 0 && hoverDistance > minDistance)) {
@@ -99,6 +104,7 @@ function ($) {
99104
hoverIndex = this.findHoverIndexFromDataPoints(pos.x, series, hoverIndex);
100105
}
101106

107+
// Be sure we have a yaxis so that it does not brake series sorting
102108
yaxis = 0;
103109
if (series.yaxis) {
104110
yaxis = series.yaxis.n;
@@ -116,7 +122,7 @@ function ($) {
116122
});
117123
}
118124

119-
// Find point which closer to pointer
125+
// Time of the point closer to pointer
120126
results.time = minTime;
121127

122128
return results;

public/vendor/flot/jquery.flot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ Licensed under the MIT license.
12101210
// middle point has same y
12111211
points[k + 1] = points[k - ps + 1] || 0;
12121212

1213-
// if series has null values, let's give the last correct value a nice step
1213+
// if series has null values, let's give the last !null value a nice step
12141214
if(nullify)
12151215
points[k] = p[0];
12161216

public/vendor/flot/jquery.flot.stack.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ charts or filled areas).
7878
i = 0, j = 0, l, m;
7979

8080
while (true) {
81+
// browse all points from the current series and from the previous series
8182
if (i >= points.length && j >= otherpoints.length)
8283
break;
8384

85+
// newpoints will replace current series with
86+
// as many points as different timestamps we have in the 2 (current & previous) series
8487
l = newpoints.length;
8588
px = points[i + keyOffset];
8689
py = points[i + accumulateOffset];
@@ -89,30 +92,32 @@ charts or filled areas).
8992
bottom = 0;
9093

9194
if (i < points.length && px == null) {
92-
// ignore point
95+
// let's ignore null points from current series, nothing to do with them
9396
i += ps;
9497
}
9598
else if (j < otherpoints.length && qx == null) {
96-
// ignore point
99+
// let's ignore null points from previous series, nothing to do with them
97100
j += otherps;
98101
}
99102
else if (i >= points.length) {
100-
// take the remaining points from the previous series
103+
// no more points in the current series, simply take the remaining points
104+
// from the previous series so that next series will correctly stack
101105
for (m = 0; m < ps; ++m)
102106
newpoints.push(otherpoints[j + m]);
103107
bottom = qy;
104108
j += otherps;
105109
}
106110
else if (j >= otherpoints.length) {
107-
// take the remaining points from the current series
111+
// no more points in the previous series, of course let's take
112+
// the remaining points from the current series
108113
for (m = 0; m < ps; ++m)
109114
newpoints.push(points[i + m]);
110115
i += ps;
111116
}
112117
else {
113-
// cases where we actually got two points
118+
// next available points from current and previous series have the same timestamp
114119
if (px == qx) {
115-
// take the point from the current series and skip the previous' one
120+
// so take the point from the current series and skip the previous' one
116121
for (m = 0; m < ps; ++m)
117122
newpoints.push(points[i + m]);
118123

@@ -122,8 +127,9 @@ charts or filled areas).
122127
i += ps;
123128
j += otherps;
124129
}
130+
// next available point with the smallest timestamp is from the previous series
125131
else if (px > qx) {
126-
// take the point from the previous series so that the next series can stack over it
132+
// so take the point from the previous series so that next series will correctly stack
127133
for (m = 0; m < ps; ++m)
128134
newpoints.push(otherpoints[j + m]);
129135

@@ -135,8 +141,9 @@ charts or filled areas).
135141

136142
j += otherps;
137143
}
138-
else { // px < qx
139-
// take the point from the current series
144+
// (px < qx) next available point with the smallest timestamp is from the current series
145+
else {
146+
// so of course let's take the point from the current series
140147
for (m = 0; m < ps; ++m)
141148
newpoints.push(points[i + m]);
142149

0 commit comments

Comments
 (0)