Skip to content

Commit 7f6650b

Browse files
authored
Merge pull request #5210 from miqh/fix/5177
Fix staticPlot behaviour for range slider and legend
2 parents 39fe198 + 256f4de commit 7f6650b

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

Diff for: src/components/legend/draw.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,14 @@ function setupTraceToggle(g, gd) {
465465
var numClicks = 1;
466466

467467
var traceToggle = Lib.ensureSingle(g, 'rect', 'legendtoggle', function(s) {
468-
s.style('cursor', 'pointer')
469-
.attr('pointer-events', 'all')
470-
.call(Color.fill, 'rgba(0,0,0,0)');
468+
if(!gd._context.staticPlot) {
469+
s.style('cursor', 'pointer').attr('pointer-events', 'all');
470+
}
471+
s.call(Color.fill, 'rgba(0,0,0,0)');
471472
});
472473

474+
if(gd._context.staticPlot) return;
475+
473476
traceToggle.on('mousedown', function() {
474477
newMouseDownTime = (new Date()).getTime();
475478
if(newMouseDownTime - gd._legendMouseDownTime < doubleClickDelay) {

Diff for: src/components/rangeslider/draw.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ module.exports = function(gd) {
232232
};
233233

234234
function setupDragElement(rangeSlider, gd, axisOpts, opts) {
235+
if(gd._context.staticPlot) return;
236+
235237
var slideBox = rangeSlider.select('rect.' + constants.slideBoxClassName).node();
236238
var grabAreaMin = rangeSlider.select('rect.' + constants.grabAreaMinClassName).node();
237239
var grabAreaMax = rangeSlider.select('rect.' + constants.grabAreaMaxClassName).node();
@@ -619,14 +621,12 @@ function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
619621
handleMax.attr(handleDynamicAttrs);
620622

621623
// <g grabarea />
622-
if(gd._context.staticPlot) return;
623-
624624
var grabAreaFixAttrs = {
625625
width: constants.grabAreaWidth,
626626
x: 0,
627627
y: 0,
628628
fill: constants.grabAreaFill,
629-
cursor: constants.grabAreaCursor
629+
cursor: !gd._context.staticPlot ? constants.grabAreaCursor : undefined,
630630
};
631631

632632
var grabAreaMin = Lib.ensureSingle(grabberMin, 'rect', constants.grabAreaMinClassName, function(s) {

Diff for: test/jasmine/tests/legend_test.js

+41
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,47 @@ describe('legend interaction', function() {
12891289
});
12901290
});
12911291

1292+
describe('staticPlot', function() {
1293+
var gd;
1294+
1295+
beforeEach(function() {
1296+
gd = createGraphDiv();
1297+
});
1298+
1299+
afterEach(destroyGraphDiv);
1300+
1301+
function toggleTrace() {
1302+
var toggle = d3.select('.legendtoggle').node();
1303+
expect(toggle).not.toEqual(null);
1304+
1305+
toggle.dispatchEvent(new MouseEvent('mousedown'));
1306+
toggle.dispatchEvent(new MouseEvent('mouseup'));
1307+
1308+
// Delay needs to be long enough for Plotly to react
1309+
return delay(300)();
1310+
}
1311+
1312+
function assertToggled(toggled) {
1313+
return function() {
1314+
var container = d3.select('g.traces').node();
1315+
expect(container).not.toEqual(null);
1316+
expect(container.style.opacity).toBe(toggled ? '0.5' : '1');
1317+
};
1318+
}
1319+
1320+
it('should prevent toggling if set', function(done) {
1321+
var data = [{ x: [0, 1], y: [0, 1], type: 'scatter' }];
1322+
var layout = { showlegend: true };
1323+
var config = { staticPlot: true };
1324+
1325+
Plotly.newPlot(gd, data, layout, config)
1326+
.then(toggleTrace)
1327+
.then(assertToggled(false))
1328+
.catch(failTest)
1329+
.then(done);
1330+
});
1331+
});
1332+
12921333
describe('visible toggle', function() {
12931334
var gd;
12941335

Diff for: test/jasmine/tests/range_slider_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,40 @@ describe('Visible rangesliders', function() {
201201
.then(done);
202202
});
203203

204+
it('should not react to any interactions when staticPlot is set', function(done) {
205+
var mockCopy = Lib.extendDeep({}, mock);
206+
var moveDelta = 50;
207+
Plotly.newPlot(gd, mockCopy.data, mockCopy.layout, { staticPlot: true })
208+
.then(function() {
209+
// Try move minimum handle
210+
var minHandle = d3.select('.' + constants.grabberMinClassName).node();
211+
expect(minHandle).not.toEqual(null);
212+
var minHandleRect = minHandle.getBoundingClientRect();
213+
var x = minHandleRect.x + minHandleRect.width / 2;
214+
var y = minHandleRect.y + minHandleRect.height / 2;
215+
return slide(x, y, x + moveDelta, y);
216+
})
217+
.then(function() {
218+
// Try move maximum handle
219+
var maxHandle = d3.select('.' + constants.grabberMaxClassName).node();
220+
expect(maxHandle).not.toEqual(null);
221+
var maxHandleRect = maxHandle.getBoundingClientRect();
222+
var x = maxHandleRect.x + maxHandleRect.width / 2;
223+
var y = maxHandleRect.y + maxHandleRect.height / 2;
224+
return slide(x, y, x - moveDelta, y);
225+
})
226+
.then(function() {
227+
// Slidebox should not exist
228+
var slidebox = d3.select('.' + constants.slideBoxClassName).node();
229+
expect(slidebox).toEqual(null);
230+
})
231+
.then(function() {
232+
expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49]);
233+
})
234+
.catch(failTest)
235+
.then(done);
236+
});
237+
204238
it('should update correctly when moving slider on an axis with rangebreaks', function(done) {
205239
var start = 250;
206240
var end = 300;

0 commit comments

Comments
 (0)