Skip to content

Commit beccece

Browse files
committed
Add zoomlayer
Fixes #359
1 parent d117e92 commit beccece

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/plot_api/plot_api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,7 @@ function makePlotFramework(gd) {
26542654
// these are in a different svg element normally, but get collapsed into a single
26552655
// svg when exporting (after inserting 3D)
26562656
fullLayout._infolayer = fullLayout._toppaper.append('g').classed('infolayer', true);
2657+
fullLayout._zoomlayer = fullLayout._toppaper.append('g').classed('zoomlayer', true);
26572658
fullLayout._hoverlayer = fullLayout._toppaper.append('g').classed('hoverlayer', true);
26582659

26592660
gd.emit('plotly_framework');

src/plots/cartesian/dragbox.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
139139

140140
dragElement.init(dragOptions);
141141

142-
var x0,
142+
var zoomlayer = gd._fullLayout._zoomlayer,
143+
xs = plotinfo.x()._offset,
144+
ys = plotinfo.y()._offset,
145+
x0,
143146
y0,
144147
box,
145148
lum,
@@ -161,22 +164,24 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
161164
dimmed = false;
162165
zoomMode = 'xy';
163166

164-
zb = plotinfo.plot.append('path')
167+
zb = zoomlayer.append('path')
165168
.attr('class', 'zoombox')
166169
.style({
167170
'fill': lum>0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)',
168171
'stroke-width': 0
169172
})
173+
.attr('transform','translate(' + xs + ' ' + ys + ')')
170174
.attr('d', path0 + 'Z');
171175

172-
corners = plotinfo.plot.append('path')
176+
corners = zoomlayer.append('path')
173177
.attr('class', 'zoombox-corners')
174178
.style({
175179
fill: Color.background,
176180
stroke: Color.defaultLine,
177181
'stroke-width': 1,
178182
opacity: 0
179183
})
184+
.attr('transform','translate(' + xs + ' ' + ys + ')')
180185
.attr('d','M0,0Z');
181186

182187
clearSelect();
@@ -187,7 +192,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
187192
// until we get around to persistent selections, remove the outline
188193
// here. The selection itself will be removed when the plot redraws
189194
// at the end.
190-
plotinfo.plot.selectAll('.select-outline').remove();
195+
zoomlayer.selectAll('.select-outline').remove();
191196
}
192197

193198
function zoomMove(dx0, dy0) {

src/plots/cartesian/select.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ var MINSELECT = constants.MINSELECT;
2222
function getAxId(ax) { return ax._id; }
2323

2424
module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
25-
var plot = dragOptions.plotinfo.plot,
25+
var plot = dragOptions.gd._fullLayout._zoomlayer,
2626
dragBBox = dragOptions.element.getBoundingClientRect(),
27+
xs = dragOptions.plotinfo.x()._offset,
28+
ys = dragOptions.plotinfo.y()._offset,
2729
x0 = startX - dragBBox.left,
2830
y0 = startY - dragBBox.top,
2931
x1 = x0,
@@ -45,6 +47,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
4547
outlines.enter()
4648
.append('path')
4749
.attr('class', function(d) { return 'select-outline select-outline-' + d; })
50+
.attr('transform','translate(' + xs + ' ' + ys + ')')
4851
.attr('d', path0 + 'Z');
4952

5053
var corners = plot.append('path')
@@ -54,6 +57,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
5457
stroke: color.defaultLine,
5558
'stroke-width': 1
5659
})
60+
.attr('transform','translate(' + xs + ' ' + ys + ')')
5761
.attr('d','M0,0Z');
5862

5963

0 commit comments

Comments
 (0)