in kitsune/sumo/static/sumo/js/rickshaw_utils.js [1160:1226]
update: function (e) {
e = e || this.lastEvent;
if (!e) { return; }
this.lastEvent = e;
if (!e.target.nodeName.match(/^(path|svg|rect)$/)) { return; }
var i;
var graph = this.graph;
var eventX = e.offsetX || e.layerX;
var eventY = e.offsetY || e.layerY;
var points = [];
var data = this.graph.stackedData[0];
// The x value in the units of the graph that corresponds to the pointer.
var domainX = graph.x.invert(eventX);
var xMin = graph.window.xMin || data[0].x;
var xMax = graph.window.xMax || data.slice(-1)[0].x;
var domainIndexScale = d3.scale.linear()
.domain([xMin, xMax])
.range([0, data.length - 1]);
var dataIndex = Math.round(domainIndexScale(domainX)) || 0;
// clamp dataIndex between 0 and length;
dataIndex = Math.max(0, Math.min(dataIndex, data.length - 1));
// Sometimes the data has holes in it. In that case, the dataIndex
// will be wrong. Walk around the graph until we are at about the
// right point.
while (dataIndex >= 0 && dataIndex < data.length - 1) {
if (data[dataIndex].x <= domainX && domainX <= data[dataIndex + 1].x) {
// the right one.
break;
}
// Move to the left or right, as appropratiate.
if (data[dataIndex].x > domainX) { dataIndex -= 1; } else { dataIndex += 1; }
}
// Choose the closer of the two points.
if (data[dataIndex + 1] &&
data[dataIndex + 1].x - domainX < domainX - data[dataIndex].x) {
dataIndex += 1;
}
var activeSeries = graph.series.active();
for (i = 0; i < graph.stackedData.length; i += 1) {
points.push({
x: graph.stackedData[i][dataIndex].x,
y: graph.stackedData[i][dataIndex].y,
series: activeSeries[i]
});
}
if (this.visible) {
this.render({
eventX: eventX,
eventY: eventY,
x: points[0].x,
points: points
});
}
},