Bug 1034668 - The getMappedSelection method for all canvas graphs should clamp the selection bounds, r=pbrosset

This commit is contained in:
Victor Porof 2014-07-08 09:02:00 -04:00
parent fa40f4ef56
commit cecde6961f
2 changed files with 12 additions and 3 deletions

View File

@ -65,6 +65,14 @@ function testGraph(graph) {
"The mapped selection's min value is correct (5).");
is(graph.getMappedSelection().max, max,
"The mapped selection's max value is correct (6).");
graph.setSelection({ start: graph.width + 100, end: -100 });
min = map(0, 0, graph.width, 112, 4180);
max = map(graph.width, 0, graph.width, 112, 4180);
is(graph.getMappedSelection().min, min,
"The mapped selection's min value is correct (7).");
is(graph.getMappedSelection().max, max,
"The mapped selection's max value is correct (8).");
}
/**

View File

@ -395,7 +395,7 @@ AbstractCanvasGraph.prototype = {
*/
getMappedSelection: function(unpack = e => e.delta) {
if (!this.hasData() || !this.hasSelection()) {
return { start: null, end: null };
return { min: null, max: null };
}
let selection = this.getSelection();
let totalTicks = this._data.length;
@ -404,8 +404,9 @@ AbstractCanvasGraph.prototype = {
// The selection's start and end values are not guaranteed to be ascending.
// This can happen, for example, when click & dragging from right to left.
let min = Math.min(selection.start, selection.end);
let max = Math.max(selection.start, selection.end);
// Also make sure that the selection bounds fit inside the canvas bounds.
let min = Math.max(Math.min(selection.start, selection.end), 0);
let max = Math.min(Math.max(selection.start, selection.end), this._width);
min = map(min, 0, this._width, firstTick, lastTick);
max = map(max, 0, this._width, firstTick, lastTick);