Skip to content

Commit

Permalink
Merge pull request #377 from plotly/rangeslider-gl-safety
Browse files Browse the repository at this point in the history
Rangeslider gl safety check
  • Loading branch information
mdtusz committed Mar 31, 2016
2 parents 046915c + 839db41 commit 3fead90
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/components/rangeslider/create_slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ module.exports = function createSlider(gd, minStart, maxStart) {
]);

sliderContainer.data([0])
.enter().append(function() {
options.setRange = setRange;
return slider;
});
.enter().append(function() {
options.setRange = setRange;
return slider;
});
};
8 changes: 6 additions & 2 deletions src/components/rangeslider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ function draw(gd, minStart, maxStart) {
var height = (fullLayout.height - fullLayout.margin.b - fullLayout.margin.t) * options.thickness,
offsetShift = Math.floor(options.borderwidth / 2);

if(sliderContainer[0].length === 0) createSlider(gd, minStart, maxStart);
if(sliderContainer[0].length === 0 && !fullLayout._hasGL2D) createSlider(gd, minStart, maxStart);

// Need to default to 0 for when making gl plots
var bb = fullLayout.xaxis._boundingBox ?
fullLayout.xaxis._boundingBox.height : 0;

Plots.autoMargin(gd, 'range-slider', {
x: 0, y: 0, l: 0, r: 0, t: 0,
b: height + fullLayout.margin.b + fullLayout.xaxis._boundingBox.height,
b: height + fullLayout.margin.b + bb,
pad: 15 + offsetShift * 2
});
}
35 changes: 35 additions & 0 deletions test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,38 @@ describe('Test gl plot interactions', function() {
});
});
});

describe('Test gl plot side effects', function() {
describe('when present with rangeslider', function() {

var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

it('should not draw the rangeslider', function(done) {
var data = [{
x: [1,2,3],
y: [2,3,4],
type: 'scattergl'
}, {
x: [1,2,3],
y: [2,3,4],
type: 'scatter'
}];

var layout = {
xaxis: { rangeslider: { visible: true } }
};

Plotly.plot(gd, data, layout).then(function() {
var rangeSlider = document.getElementsByClassName('range-slider')[0];
expect(rangeSlider).not.toBeDefined();
done();
});
});
});
});

0 comments on commit 3fead90

Please sign in to comment.