Skip to content

Commit 95f9b33

Browse files
committed
test legend, rangeselector, rangeslider automargin updates
1 parent fa86147 commit 95f9b33

File tree

3 files changed

+102
-8
lines changed

3 files changed

+102
-8
lines changed

test/jasmine/tests/legend_test.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -524,18 +524,36 @@ describe('legend relayout update', function() {
524524
afterEach(destroyGraphDiv);
525525

526526
it('should hide and show the legend', function(done) {
527-
var mockCopy = Lib.extendDeep({}, mock);
527+
var mockCopy = Lib.extendDeep({}, mock, {layout: {
528+
legend: {x: 1.1, xanchor: 'left'},
529+
margin: {l: 50, r: 50},
530+
width: 500
531+
}});
532+
533+
function plotWidth() {
534+
return d3.select('.ygrid').node().getBoundingClientRect().width;
535+
}
536+
528537
Plotly.newPlot(gd, mockCopy.data, mockCopy.layout)
529538
.then(function() {
530539
expect(d3.selectAll('g.legend').size()).toBe(1);
540+
// check that the margins changed
541+
expect(plotWidth()).toBeLessThan(400);
531542
return Plotly.relayout(gd, {showlegend: false});
532543
})
533544
.then(function() {
534545
expect(d3.selectAll('g.legend').size()).toBe(0);
546+
expect(plotWidth()).toBe(400);
535547
return Plotly.relayout(gd, {showlegend: true});
536548
})
537549
.then(function() {
538550
expect(d3.selectAll('g.legend').size()).toBe(1);
551+
expect(plotWidth()).toBeLessThan(400);
552+
return Plotly.relayout(gd, {'legend.x': 0.7});
553+
})
554+
.then(function() {
555+
expect(d3.selectAll('g.legend').size()).toBe(1);
556+
expect(plotWidth()).toBe(400);
539557
})
540558
.catch(failTest)
541559
.then(done);

test/jasmine/tests/range_selector_test.js

+60
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,63 @@ describe('range selector interactions:', function() {
597597
.then(done);
598598
});
599599
});
600+
601+
describe('range selector automargin', function() {
602+
'use strict';
603+
604+
var mock = require('@mocks/range_selector.json');
605+
606+
var gd, mockCopy;
607+
608+
beforeEach(function(done) {
609+
gd = createGraphDiv();
610+
mockCopy = Lib.extendDeep({}, mock, {layout: {
611+
width: 500,
612+
height: 500,
613+
margin: {l: 50, r: 50, t: 100, b: 100}
614+
}});
615+
616+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
617+
.catch(failTest)
618+
.then(done);
619+
});
620+
621+
afterEach(destroyGraphDiv);
622+
623+
function plotWidth() {
624+
return d3.selectAll('.ygrid').node().getBoundingClientRect().width;
625+
}
626+
627+
function plotHeight() {
628+
return d3.selectAll('.xgrid').node().getBoundingClientRect().height;
629+
}
630+
631+
it('updates automargin when hiding, showing, or moving', function(done) {
632+
expect(plotWidth()).toBe(400);
633+
expect(plotHeight()).toBe(300);
634+
635+
Plotly.relayout(gd, {
636+
'xaxis.rangeselector.y': 1.3,
637+
'xaxis.rangeselector.xanchor': 'center'
638+
})
639+
.then(function() {
640+
expect(plotWidth()).toBeLessThan(400);
641+
expect(plotHeight()).toBeLessThan(300);
642+
643+
return Plotly.relayout(gd, {'xaxis.rangeselector.visible': false});
644+
})
645+
.then(function() {
646+
expect(plotWidth()).toBe(400);
647+
expect(plotHeight()).toBe(300);
648+
649+
return Plotly.relayout(gd, {'xaxis.rangeselector.visible': true});
650+
})
651+
.then(function() {
652+
expect(plotWidth()).toBeLessThan(400);
653+
expect(plotHeight()).toBeLessThan(300);
654+
})
655+
.catch(failTest)
656+
.then(done);
657+
});
658+
659+
});

test/jasmine/tests/range_slider_test.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -363,38 +363,53 @@ describe('Rangeslider visibility property', function() {
363363

364364
afterEach(destroyGraphDiv);
365365

366+
function plotHeight() {
367+
return d3.select('.xgrid').node().getBoundingClientRect().height;
368+
}
369+
370+
function defaultLayout(opts) {
371+
return Lib.extendDeep({
372+
width: 500,
373+
height: 600,
374+
margin: {l: 50, r: 50, t: 100, b: 100}
375+
}, opts || {});
376+
}
377+
366378
it('should not add the slider to the DOM by default', function(done) {
367-
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {})
379+
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], defaultLayout())
368380
.then(function() {
369381
var rangeSlider = getRangeSlider();
370382
expect(rangeSlider).not.toBeDefined();
383+
expect(plotHeight()).toBe(400);
371384
})
372385
.catch(failTest)
373386
.then(done);
374387
});
375388

376389
it('should add the slider if rangeslider is set to anything', function(done) {
377-
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {})
390+
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], defaultLayout())
378391
.then(function() {
379392
return Plotly.relayout(gd, 'xaxis.rangeslider', 'exists');
380393
})
381394
.then(function() {
382395
var rangeSlider = getRangeSlider();
383396
expect(rangeSlider).toBeDefined();
397+
expect(plotHeight()).toBeLessThan(400);
384398
})
385399
.catch(failTest)
386400
.then(done);
387401
});
388402

389403
it('should add the slider if visible changed to `true`', function(done) {
390-
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], {})
404+
Plotly.plot(gd, [{ x: [1, 2, 3], y: [2, 3, 4] }], defaultLayout())
391405
.then(function() {
392406
return Plotly.relayout(gd, 'xaxis.rangeslider.visible', true);
393407
})
394408
.then(function() {
395409
var rangeSlider = getRangeSlider();
396410
expect(rangeSlider).toBeDefined();
397411
expect(countRangeSliderClipPaths()).toEqual(1);
412+
expect(plotHeight()).toBeLessThan(400);
398413
})
399414
.catch(failTest)
400415
.then(done);
@@ -404,18 +419,19 @@ describe('Rangeslider visibility property', function() {
404419
Plotly.plot(gd, [{
405420
x: [1, 2, 3],
406421
y: [2, 3, 4]
407-
}], {
422+
}], defaultLayout({
408423
xaxis: {
409424
rangeslider: { visible: true }
410425
}
411-
})
426+
}))
412427
.then(function() {
413428
return Plotly.relayout(gd, 'xaxis.rangeslider.visible', false);
414429
})
415430
.then(function() {
416431
var rangeSlider = getRangeSlider();
417432
expect(rangeSlider).not.toBeDefined();
418433
expect(countRangeSliderClipPaths()).toEqual(0);
434+
expect(plotHeight()).toBe(400);
419435
})
420436
.catch(failTest)
421437
.then(done);
@@ -434,11 +450,11 @@ describe('Rangeslider visibility property', function() {
434450
type: 'bar',
435451
x: [1, 2, 3],
436452
y: [2, 5, 2]
437-
}], {
453+
}], defaultLayout({
438454
xaxis: {
439455
rangeslider: { visible: true }
440456
}
441-
})
457+
}))
442458
.then(function() {
443459
expect(count('g.scatterlayer > g.trace')).toEqual(1);
444460
expect(count('g.barlayer > g.trace')).toEqual(1);

0 commit comments

Comments
 (0)