Skip to content

Commit aa67de2

Browse files
authoredOct 27, 2017
Merge pull request #2121 from plotly/layer-fix
Layer fix
2 parents fd3a5b8 + e0a10af commit aa67de2

File tree

8 files changed

+72
-36
lines changed

8 files changed

+72
-36
lines changed
 

‎src/components/shapes/draw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function draw(gd) {
5757
function drawOne(gd, index) {
5858
// remove the existing shape if there is one.
5959
// because indices can change, we need to look in all shape layers
60-
gd._fullLayout._paper
60+
gd._fullLayout._paperdiv
6161
.selectAll('.shapelayer [data-index="' + index + '"]')
6262
.remove();
6363

‎src/components/updatemenus/draw.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function draw(gd) {
5454
*/
5555

5656
// draw update menu container
57-
var menus = fullLayout._infolayer
57+
var menus = fullLayout._menulayer
5858
.selectAll('g.' + constants.containerClassName)
5959
.data(menuData.length > 0 ? [0] : []);
6060

@@ -97,6 +97,9 @@ module.exports = function draw(gd) {
9797

9898
// remove exiting header, remove dropped buttons and reset margins
9999
if(headerGroups.enter().size()) {
100+
// make sure gButton is on top of all headers
101+
gButton.node().parentNode.appendChild(gButton.node());
102+
100103
gButton
101104
.call(removeAllButtons)
102105
.attr(constants.menuIndexAttrName, '-1');
@@ -135,13 +138,12 @@ module.exports = function draw(gd) {
135138
});
136139
};
137140

141+
/**
142+
* get only visible menus for display
143+
*/
138144
function makeMenuData(fullLayout) {
139-
var contOpts = fullLayout[constants.name],
140-
menuData = [];
141-
142-
// Filter visible dropdowns and attach '_index' to each
143-
// fullLayout options object to be used for 'object constancy'
144-
// in the data join key function.
145+
var contOpts = fullLayout[constants.name];
146+
var menuData = [];
145147

146148
for(var i = 0; i < contOpts.length; i++) {
147149
var item = contOpts[i];
@@ -154,7 +156,7 @@ function makeMenuData(fullLayout) {
154156

155157
// Note that '_index' is set at the default step,
156158
// it corresponds to the menu index in the user layout update menu container.
157-
// Because a menu can b set invisible,
159+
// Because a menu can be set invisible,
158160
// this is a more 'consistent' field than the index in the menuData.
159161
function keyFunction(menuOpts) {
160162
return menuOpts._index;

‎src/plot_api/plot_api.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2830,25 +2830,25 @@ function makePlotFramework(gd) {
28302830
// single geo layer for the whole plot
28312831
fullLayout._geolayer = fullLayout._paper.append('g').classed('geolayer', true);
28322832

2833-
// upper shape layer
2834-
// (only for shapes to be drawn above the whole plot, including subplots)
2835-
var layerAbove = fullLayout._paper.append('g')
2836-
.classed('layer-above', true);
2837-
fullLayout._imageUpperLayer = layerAbove.append('g')
2838-
.classed('imagelayer', true);
2839-
fullLayout._shapeUpperLayer = layerAbove.append('g')
2840-
.classed('shapelayer', true);
2841-
28422833
// single pie layer for the whole plot
28432834
fullLayout._pielayer = fullLayout._paper.append('g').classed('pielayer', true);
28442835

28452836
// fill in image server scrape-svg
28462837
fullLayout._glimages = fullLayout._paper.append('g').classed('glimages', true);
28472838

2848-
// lastly info (legend, annotations) and hover layers go on top
2839+
// lastly upper shapes, info (legend, annotations) and hover layers go on top
28492840
// these are in a different svg element normally, but get collapsed into a single
28502841
// svg when exporting (after inserting 3D)
2842+
// upper shapes/images are only those drawn above the whole plot, including subplots
2843+
var layerAbove = fullLayout._toppaper.append('g')
2844+
.classed('layer-above', true);
2845+
fullLayout._imageUpperLayer = layerAbove.append('g')
2846+
.classed('imagelayer', true);
2847+
fullLayout._shapeUpperLayer = layerAbove.append('g')
2848+
.classed('shapelayer', true);
2849+
28512850
fullLayout._infolayer = fullLayout._toppaper.append('g').classed('infolayer', true);
2851+
fullLayout._menulayer = fullLayout._toppaper.append('g').classed('menulayer', true);
28522852
fullLayout._zoomlayer = fullLayout._toppaper.append('g').classed('zoomlayer', true);
28532853
fullLayout._hoverlayer = fullLayout._toppaper.append('g').classed('hoverlayer', true);
28542854

‎test/image/baselines/pie_style.png

1.24 KB
Loading

‎test/image/baselines/updatemenus.png

5.15 KB
Loading

‎test/image/mocks/pie_style.json

+24-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@
3030
"height": 400,
3131
"width": 500,
3232
"paper_bgcolor": "#ddd",
33-
"showlegend": false
33+
"showlegend": false,
34+
"shapes": [{
35+
"type": "rect",
36+
"xref": "paper",
37+
"yref": "paper",
38+
"x0": 0,
39+
"y0": 0.4,
40+
"x1": 1,
41+
"y1": 0.6,
42+
"fillcolor": "rgba(128, 0, 0, 0.5)",
43+
"line": {"width": 0},
44+
"layer": "below"
45+
}, {
46+
"type": "rect",
47+
"xref": "paper",
48+
"yref": "paper",
49+
"x0": 0.4,
50+
"y0": 0,
51+
"x1": 0.6,
52+
"y1": 1,
53+
"fillcolor": "rgba(0, 0, 128, 0.5)",
54+
"line": {"width": 0},
55+
"layer": "above"
56+
}]
3457
}
3558
}

‎test/image/mocks/updatemenus.json

+17-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979
},
8080
"visible": false,
8181
"name": "Data set 3"
82+
},
83+
{
84+
"x": [2, 3, 4],
85+
"y": [0.4, 0.6, 0.8],
86+
"z": [[1, 2], [3, 4]],
87+
"type": "heatmap",
88+
"colorbar": {
89+
"x": -0.2,
90+
"y": 0.6
91+
}
8292
}
8393
],
8494
"layout": {
@@ -123,7 +133,8 @@
123133
true,
124134
false,
125135
false,
126-
false
136+
false,
137+
true
127138
]
128139
],
129140
"label": "Data set 0"
@@ -136,7 +147,8 @@
136147
false,
137148
true,
138149
false,
139-
false
150+
false,
151+
true
140152
]
141153
],
142154
"label": "Data set 1"
@@ -149,7 +161,8 @@
149161
false,
150162
false,
151163
true,
152-
false
164+
false,
165+
true
153166
]
154167
],
155168
"label": "Data set 2"
@@ -162,6 +175,7 @@
162175
false,
163176
false,
164177
false,
178+
true,
165179
true
166180
]
167181
],

‎test/jasmine/tests/updatemenus_test.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,10 @@ describe('update menus interactions', function() {
671671
// fold up buttons whenever new menus are added
672672
assertMenus([0, 0]);
673673

674+
// dropdown buttons container should still be on top of headers (and non-dropdown buttons)
675+
var gButton = d3.select('.updatemenu-dropdown-button-group');
676+
expect(gButton.node().nextSibling).toBe(null);
677+
674678
return Plotly.relayout(gd, {
675679
'updatemenus[0].bgcolor': null,
676680
'paper_bgcolor': 'black'
@@ -826,7 +830,7 @@ describe('update menus interaction with other components:', function() {
826830

827831
afterEach(destroyGraphDiv);
828832

829-
it('buttons show be drawn above sliders', function(done) {
833+
it('draws buttons above sliders', function(done) {
830834

831835
Plotly.plot(createGraphDiv(), [{
832836
x: [1, 2, 3],
@@ -869,19 +873,12 @@ describe('update menus interaction with other components:', function() {
869873
})
870874
.then(function() {
871875
var infoLayer = d3.select('g.infolayer');
872-
var containerClassNames = ['slider-container', 'updatemenu-container'];
873-
var list = [];
874-
875-
infoLayer.selectAll('*').each(function() {
876-
var className = d3.select(this).attr('class');
877-
878-
if(containerClassNames.indexOf(className) !== -1) {
879-
list.push(className);
880-
}
881-
});
882-
883-
expect(list).toEqual(containerClassNames);
876+
var menuLayer = d3.select('g.menulayer');
877+
expect(infoLayer.selectAll('.slider-container').size()).toBe(1);
878+
expect(menuLayer.selectAll('.updatemenu-container').size()).toBe(1);
879+
expect(infoLayer.node().nextSibling).toBe(menuLayer.node());
884880
})
881+
.catch(fail)
885882
.then(done);
886883
});
887884
});

0 commit comments

Comments
 (0)
Please sign in to comment.