Skip to content

Commit

Permalink
consider all the series when finding a domain min and max; fixes #234
Browse files Browse the repository at this point in the history
  • Loading branch information
dchester committed Aug 5, 2013
1 parent 2277f03 commit cc3ae30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
26 changes: 16 additions & 10 deletions src/js/Rickshaw.Graph.RangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand All @@ -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;
}
}
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/js/Rickshaw.Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit cc3ae30

Please sign in to comment.