Skip to content

Commit 8477dc9

Browse files
committed
nest modebar into a responsive container, fix bgcolor
1 parent 4808f3f commit 8477dc9

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

build/plotcss.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ var rules = {
3535
"X .ease-bg": "-webkit-transition:background-color 0.3s ease 0s;-moz-transition:background-color 0.3s ease 0s;-ms-transition:background-color 0.3s ease 0s;-o-transition:background-color 0.3s ease 0s;transition:background-color 0.3s ease 0s;",
3636
"X .modebar--hover>:not(.watermark)": "opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;",
3737
"X:hover .modebar--hover .modebar-group": "opacity:1;",
38-
"X .modebar-group": "float:left;display:inline-block;box-sizing:border-box;margin-left:8px;position:relative;vertical-align:middle;white-space:nowrap;",
38+
"X .modebar-group": "float:left;display:inline-block;box-sizing:border-box;padding-left:8px;position:relative;vertical-align:middle;white-space:nowrap;",
3939
"X .modebar-btn": "position:relative;font-size:16px;padding:3px 4px;height:22px;cursor:pointer;line-height:normal;box-sizing:border-box;",
4040
"X .modebar-btn svg": "position:relative;top:2px;",
4141
"X .modebar.vertical": "display:flex;flex-direction:column;flex-wrap:wrap;align-content:flex-end;max-height:100%;",
4242
"X .modebar.vertical svg": "top:-1px;",
43-
"X .modebar.vertical .modebar-group": "display:block;float:none;margin-left:0px;margin-bottom:8px;",
43+
"X .modebar.vertical .modebar-group": "display:block;float:none;padding-left:0px;padding-bottom:8px;",
4444
"X .modebar.vertical .modebar-group .modebar-btn": "display:block;text-align:center;",
4545
"X [data-title]:before,X [data-title]:after": "position:absolute;-webkit-transform:translate3d(0, 0, 0);-moz-transform:translate3d(0, 0, 0);-ms-transform:translate3d(0, 0, 0);-o-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:none;opacity:0;z-index:1001;pointer-events:none;top:110%;right:50%;",
4646
"X [data-title]:hover:before,X [data-title]:hover:after": "display:block;opacity:1;",

src/components/modebar/modebar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ proto.update = function(graphInfo, buttons) {
6464
var bgSelector = context.displayModeBar === 'hover' ? '.js-plotly-plot .plotly:hover ' : '';
6565

6666
Lib.deleteRelatedStyleRule(modeBarId);
67-
Lib.addRelatedStyleRule(modeBarId, bgSelector + '#' + modeBarId, 'background-color: ' + style.bgcolor);
67+
Lib.addRelatedStyleRule(modeBarId, bgSelector + '#' + modeBarId + ' .modebar-group', 'background-color: ' + style.bgcolor);
6868
Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn .icon path', 'fill: ' + style.color);
6969
Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn:hover .icon path', 'fill: ' + style.activecolor);
7070
Lib.addRelatedStyleRule(modeBarId, '#' + modeBarId + ' .modebar-btn.active .icon path', 'fill: ' + style.activecolor);
@@ -333,7 +333,7 @@ function createModeBar(gd, buttons) {
333333

334334
var modeBar = new ModeBar({
335335
graphInfo: gd,
336-
container: fullLayout._paperdiv.node(),
336+
container: fullLayout._modebardiv.node(),
337337
buttons: buttons
338338
});
339339

src/css/_modebar.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
float: left;
2323
display: inline-block;
2424
box-sizing: border-box;
25-
margin-left: 8px;
25+
padding-left: 8px;
2626
position: relative;
2727
vertical-align: middle;
2828
white-space: nowrap;
@@ -60,8 +60,8 @@
6060
.modebar-group {
6161
display: block;
6262
float: none;
63-
margin-left: 0px;
64-
margin-bottom: 8px;
63+
padding-left: 0px;
64+
padding-bottom: 8px;
6565

6666
.modebar-btn {
6767
display: block;

src/plot_api/plot_api.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ exports.plot = function(gd, data, layout, config) {
277277
}
278278
}
279279

280+
if(fullLayout.modebar.orientation === 'h') {
281+
fullLayout._modebardiv
282+
.style('height', null)
283+
.style('width', '100%');
284+
} else {
285+
fullLayout._modebardiv
286+
.style('width', null)
287+
.style('height', fullLayout.height + 'px');
288+
}
289+
280290
return Plots.previousPromises(gd);
281291
}
282292

@@ -3843,5 +3853,13 @@ function makePlotFramework(gd) {
38433853
fullLayout._zoomlayer = fullLayout._toppaper.append('g').classed('zoomlayer', true);
38443854
fullLayout._hoverlayer = fullLayout._toppaper.append('g').classed('hoverlayer', true);
38453855

3856+
// Make the modebar container
3857+
fullLayout._modebardiv = fullLayout._paperdiv.selectAll('.modebar-container').data([0]);
3858+
fullLayout._modebardiv.enter().append('div')
3859+
.classed('modebar-container', true)
3860+
.style('position', 'absolute')
3861+
.style('top', '0px')
3862+
.style('right', '0px');
3863+
38463864
gd.emit('plotly_framework');
38473865
}

test/jasmine/tests/modebar_test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ describe('ModeBar', function() {
2727
return parent;
2828
}
2929

30+
function getMockModeBarTree() {
31+
var el = document.createElement('div');
32+
el.className = 'modebar-container';
33+
return el;
34+
}
35+
3036
function getMockGraphInfo(xaxes, yaxes) {
3137
return {
3238
_fullLayout: {
3339
_uid: '6ea6a7',
3440
dragmode: 'zoom',
3541
_paperdiv: d3.select(getMockContainerTree()),
42+
_modebardiv: d3.select(getMockModeBarTree()),
3643
_has: Plots._hasPlotType,
3744
_subplots: {xaxis: xaxes || [], yaxis: yaxes || []},
3845
modebar: {
@@ -1349,13 +1356,13 @@ describe('ModeBar', function() {
13491356
it('changes background color (displayModeBar: hover)', function(done) {
13501357
Plotly.plot(gd, [], {modebar: { bgcolor: colors[0]}})
13511358
.then(function() {
1352-
style = window.getComputedStyle(gd._fullLayout._modeBar.element);
1359+
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
13531360
expect(style.backgroundColor).toBe('rgba(0, 0, 0, 0)');
13541361
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[0]);
13551362
})
13561363
.then(function() { return Plotly.relayout(gd, 'modebar.bgcolor', colors[1]); })
13571364
.then(function() {
1358-
style = window.getComputedStyle(gd._fullLayout._modeBar.element);
1365+
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
13591366
expect(style.backgroundColor).toBe('rgba(0, 0, 0, 0)');
13601367
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[1]);
13611368
})
@@ -1366,13 +1373,13 @@ describe('ModeBar', function() {
13661373
it('changes background color (displayModeBar: true)', function(done) {
13671374
Plotly.plot(gd, [], {modebar: {bgcolor: colors[0]}}, {displayModeBar: true})
13681375
.then(function() {
1369-
style = window.getComputedStyle(gd._fullLayout._modeBar.element);
1376+
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
13701377
expect(style.backgroundColor).toBe(colors[0]);
13711378
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[0]);
13721379
})
13731380
.then(function() { return Plotly.relayout(gd, 'modebar.bgcolor', colors[1]); })
13741381
.then(function() {
1375-
style = window.getComputedStyle(gd._fullLayout._modeBar.element);
1382+
style = window.getComputedStyle(gd._fullLayout._modeBar.element.querySelector('.modebar-group'));
13761383
expect(style.backgroundColor).toBe(colors[1]);
13771384
expect(getStyleRule().rules[3].style.backgroundColor).toBe(colors[1]);
13781385
})

0 commit comments

Comments
 (0)