diff --git a/src/js/Rickshaw.Graph.RangeSlider.js b/src/js/Rickshaw.Graph.RangeSlider.js index 517e1caf..1bb7aa3d 100644 --- a/src/js/Rickshaw.Graph.RangeSlider.js +++ b/src/js/Rickshaw.Graph.RangeSlider.js @@ -17,14 +17,16 @@ Rickshaw.Graph.RangeSlider = Rickshaw.Class.create({ var element = this.element; var graph = this.graph; + var domain = graph.dataDomain(); + $( function() { $(element).slider( { range: true, - min: graph.dataDomain()[0], - max: graph.dataDomain()[1], + min: domain[0], + max: domain[1], values: [ - graph.dataDomain()[0], - graph.dataDomain()[1] + domain[0], + domain[1] ], slide: function( event, ui ) { @@ -34,11 +36,13 @@ Rickshaw.Graph.RangeSlider = Rickshaw.Class.create({ graph.window.xMax = ui.values[1]; graph.update(); + var domain = graph.dataDomain(); + // if we're at an extreme, stick there - if (graph.dataDomain()[0] == ui.values[0]) { + if (domain[0] == ui.values[0]) { graph.window.xMin = undefined; } - if (graph.dataDomain()[1] == ui.values[1]) { + if (domain[1] == ui.values[1]) { graph.window.xMax = undefined; } } @@ -55,14 +59,16 @@ Rickshaw.Graph.RangeSlider = Rickshaw.Class.create({ var values = $(element).slider('option', 'values'); - $(element).slider('option', 'min', graph.dataDomain()[0]); - $(element).slider('option', 'max', graph.dataDomain()[1]); + var domain = graph.dataDomain(); + + $(element).slider('option', 'min', domain[0]); + $(element).slider('option', 'max', domain[1]); if (graph.window.xMin == null) { - values[0] = graph.dataDomain()[0]; + values[0] = domain[0]; } if (graph.window.xMax == null) { - values[1] = graph.dataDomain()[1]; + values[1] = domain[1]; } $(element).slider('option', 'values', values); diff --git a/src/js/Rickshaw.Graph.js b/src/js/Rickshaw.Graph.js index b2eb433e..1059d038 100644 --- a/src/js/Rickshaw.Graph.js +++ b/src/js/Rickshaw.Graph.js @@ -91,11 +91,12 @@ Rickshaw.Graph = function(args) { this.dataDomain = function() { - // take from the first series - var data = this.series[0].data; + var data = graph.series.map( function(s) { return s.data } ); - return [ data[0].x, data.slice(-1).shift().x ]; + var min = d3.min( data.map( function(d) { return d[0].x } ) ); + var max = d3.max( data.map( function(d) { return d[d.length - 1].x } ) ); + return [min, max]; }; this.discoverRange = function() {