diff --git a/browser/devtools/shared/test/browser_graphs-06.js b/browser/devtools/shared/test/browser_graphs-06.js index eb9bc53776c..5d28bcda033 100644 --- a/browser/devtools/shared/test/browser_graphs-06.js +++ b/browser/devtools/shared/test/browser_graphs-06.js @@ -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)."); } /** diff --git a/browser/devtools/shared/widgets/Graphs.jsm b/browser/devtools/shared/widgets/Graphs.jsm index 53ecef8d34f..80a7ae7e689 100644 --- a/browser/devtools/shared/widgets/Graphs.jsm +++ b/browser/devtools/shared/widgets/Graphs.jsm @@ -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);