Skip to content

Commit 95817e8

Browse files
committed
add range slider data-update test cases
1 parent cebc31c commit 95817e8

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

test/jasmine/tests/range_slider_test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,24 @@ describe('the range slider', function() {
516516

517517
describe('in general', function() {
518518

519+
beforeAll(function() {
520+
jasmine.addMatchers(customMatchers);
521+
});
522+
519523
beforeEach(function() {
520524
gd = createGraphDiv();
521525
});
522526

523527
afterEach(destroyGraphDiv);
524528

529+
function assertRange(axRange, rsRange) {
530+
// lower toBeCloseToArray precision for FF38 on CI
531+
var precision = 1e-2;
532+
533+
expect(gd.layout.xaxis.range).toBeCloseToArray(axRange, precision);
534+
expect(gd.layout.xaxis.rangeslider.range).toBeCloseToArray(rsRange, precision);
535+
}
536+
525537
it('should plot when only x data is provided', function(done) {
526538
Plotly.plot(gd, [{ x: [1, 2, 3] }], { xaxis: { rangeslider: {} }})
527539
.then(function() {
@@ -541,6 +553,80 @@ describe('the range slider', function() {
541553
})
542554
.then(done);
543555
});
556+
557+
it('should expand its range in accordance with new data arrays', function(done) {
558+
Plotly.plot(gd, [{
559+
y: [2, 1, 2]
560+
}], {
561+
xaxis: { rangeslider: {} }
562+
})
563+
.then(function() {
564+
assertRange([-0.13, 2.13], [-0.13, 2.13]);
565+
566+
return Plotly.restyle(gd, 'y', [[2, 1, 2, 1]]);
567+
})
568+
.then(function() {
569+
assertRange([-0.19, 3.19], [-0.19, 3.19]);
570+
571+
return Plotly.extendTraces(gd, { y: [[2, 1]] }, [0]);
572+
})
573+
.then(function() {
574+
assertRange([-0.32, 5.32], [-0.32, 5.32]);
575+
576+
return Plotly.addTraces(gd, { x: [0, 10], y: [2, 1] });
577+
})
578+
.then(function() {
579+
assertRange([-0.68, 10.68], [-0.68, 10.68]);
580+
581+
return Plotly.deleteTraces(gd, [1]);
582+
})
583+
.then(function() {
584+
assertRange([-0.31, 5.31], [-0.31, 5.31]);
585+
})
586+
.then(done);
587+
});
588+
589+
it('should not expand its range when range slider range is set', function(done) {
590+
Plotly.plot(gd, [{
591+
y: [2, 1, 2]
592+
}], {
593+
xaxis: { rangeslider: { range: [-1, 11] } }
594+
})
595+
.then(function() {
596+
assertRange([-0.13, 2.13], [-1, 11]);
597+
598+
return Plotly.restyle(gd, 'y', [[2, 1, 2, 1]]);
599+
})
600+
.then(function() {
601+
assertRange([-0.19, 3.19], [-1, 11]);
602+
603+
return Plotly.extendTraces(gd, { y: [[2, 1]] }, [0]);
604+
})
605+
.then(function() {
606+
assertRange([-0.32, 5.32], [-1, 11]);
607+
608+
return Plotly.addTraces(gd, { x: [0, 10], y: [2, 1] });
609+
})
610+
.then(function() {
611+
assertRange([-0.68, 10.68], [-1, 11]);
612+
613+
return Plotly.deleteTraces(gd, [1]);
614+
})
615+
.then(function() {
616+
assertRange([-0.31, 5.31], [-1, 11]);
617+
618+
return Plotly.update(gd, {
619+
y: [[2, 1, 2, 1, 2]]
620+
}, {
621+
'xaxis.rangeslider.autorange': true
622+
});
623+
})
624+
.then(function() {
625+
assertRange([-0.26, 4.26], [-0.26, 4.26]);
626+
627+
})
628+
.then(done);
629+
});
544630
});
545631
});
546632

0 commit comments

Comments
 (0)