Skip to content

Commit 75bb57f

Browse files
committed
remove duplicative test, add relayout test
1 parent c31eb68 commit 75bb57f

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

test/jasmine/tests/legend_test.js

+7-56
Original file line numberDiff line numberDiff line change
@@ -546,69 +546,20 @@ describe('legend orientation change:', function() {
546546

547547
afterEach(destroyGraphDiv);
548548

549-
it('should update legend orientation', function(done) {
549+
it('should update plot background', function(done) {
550550
var mock = require('@mocks/legend_horizontal_autowrap.json'),
551551
gd = createGraphDiv(),
552-
initialLegendY = mock.layout.legend.y;
552+
initialLegendBGColor;
553553

554554
Plotly.plot(gd, mock.data, mock.layout).then(function() {
555-
var node = d3.select('g.legend').select('rect'),
556-
nw = node.property('width').baseVal.value,
557-
gw = mock.layout.width,
558-
maxTraceHeight = 0,
559-
maxTraceWidth = 0,
560-
maxOffsetX = 0,
561-
maxOffsetY = 0,
562-
traceGap = gd._fullLayout.legend.tracegroupgap || 5;
563-
564-
d3.selectAll('g.legend g.traces').each(function() {
565-
var b = d3.select(this).select('text').node().getBBox(),
566-
w = b.width + traceGap + 40,
567-
h = d3.select(this).node().getBBox().height,
568-
t = d3.transform(d3.select(this).attr('transform'));
569-
//console.log(t.translate[0], t.translate[1], w, h);
570-
maxOffsetX = Math.max(maxOffsetX, t.translate[0]);
571-
maxOffsetY = Math.max(maxOffsetY, t.translate[1]);
572-
maxTraceWidth = Math.max(maxTraceWidth, w);
573-
maxTraceHeight = Math.max(maxTraceHeight, h);
574-
});
575-
576-
//legend rect less than width of plot
577-
expect(nw).toBeLessThan(gw);
578-
expect(maxTraceHeight).toBeGreaterThan(0);
579-
expect(maxTraceWidth).toBeGreaterThan(0);
580-
expect(maxOffsetX).toBeGreaterThan(0);
581-
expect(maxOffsetY).toBeGreaterThan(0);
582-
583-
//none of the traces are pushed off the graph
584-
expect(maxOffsetX).toBeLessThan(mock.layout.width);
585-
expect(maxOffsetY).toBeLessThan(mock.layout.height);
586-
587-
//update mock
588-
mock.layout.legend.orientation = 'v';
589-
mock.layout.legend.y = 1;
590-
//re-graph
591-
destroyGraphDiv(gd);
592-
gd = createGraphDiv();
593-
return Plotly.plot(gd, mock.data, mock.layout);
555+
initialLegendBGColor = gd._fullLayout.legend.bgcolor;
556+
return Plotly.relayout(gd, 'legend.bgcolor', '#000000');
594557
}).then(function() {
595-
expect(gd._fullLayout.legend.orientation).toBe('v');
596-
//scrollbar has width and height now
597-
var bbox = d3.select('rect.scrollbar').node().getBBox();
598-
expect(bbox.width).toBeGreaterThan(0);
599-
expect(bbox.height).toBeGreaterThan(0);
600-
//update mock and re-graph
601-
mock.layout.legend.orientation = 'h';
602-
mock.layout.legend.y = initialLegendY;
603-
destroyGraphDiv(gd);
604-
gd = createGraphDiv();
605-
return Plotly.plot(gd, mock.data, mock.layout);
558+
expect(gd._fullLayout.legend.bgcolor).toBe('#000000');
559+
return Plotly.relayout(gd, 'legend.bgcolor', initialLegendBGColor);
606560
}).then(function() {
607-
//back to base case
608-
expect(gd._fullLayout.legend.orientation).toBe('h');
609-
expect(gd._fullLayout.legend.y).toBe(initialLegendY);
561+
expect(gd._fullLayout.legend.bgcolor).toBe(initialLegendBGColor);
610562
done();
611563
});
612564
});
613-
614565
});

0 commit comments

Comments
 (0)