Skip to content

Commit 3e96a40

Browse files
committed
fix issue 4806 and 4808 - use and ensure stroke event only to activate editable shapes
1 parent 245eeec commit 3e96a40

File tree

3 files changed

+139
-19
lines changed

3 files changed

+139
-19
lines changed

src/components/shapes/draw.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ function drawOne(gd, index) {
119119
var lineColor = options.line.width ? options.line.color : 'rgba(0,0,0,0)';
120120
var lineWidth = options.line.width;
121121
var lineDash = options.line.dash;
122+
if(!lineWidth && options.editable === true) {
123+
// ensure invisible border to active the shape
124+
lineWidth = 5;
125+
lineDash = 'solid';
126+
}
122127

123128
var isOpen = d[d.length - 1] !== 'Z';
124129

@@ -163,15 +168,11 @@ function drawOne(gd, index) {
163168
} else {
164169
if(gd._context.edits.shapePosition) {
165170
setupDragElement(gd, path, options, index, shapeLayer, editHelpers);
171+
} else {
172+
if(options.editable === true) {
173+
path.style('pointer-events', 'stroke');
174+
}
166175
}
167-
168-
path.style('pointer-events',
169-
!couldHaveActiveShape(gd) || (
170-
lineWidth < 2 || ( // not has a remarkable border
171-
!isOpen && Color.opacity(fillColor) * opacity > 0.5 // not too transparent
172-
)
173-
) ? 'all' : 'stroke'
174-
);
175176
}
176177

177178
path.node().addEventListener('click', function() { return activateShape(gd, path); });

src/components/shapes/draw_newshape/attributes.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ module.exports = {
4444
dflt: 'rgba(0,0,0,0)',
4545
role: 'info',
4646
editType: 'none',
47-
description: [
48-
'Sets the color filling new shapes\' interior.',
49-
'Please note that if using a fillcolor with alpha greater than half,',
50-
'drag inside the active shape starts moving the shape underneath,',
51-
'otherwise a new shape could be started over.'
52-
].join(' ')
47+
description: 'Sets the color filling new shapes\' interior.'
5348
},
5449
fillrule: {
5550
valType: 'enumerated',
@@ -99,6 +94,10 @@ module.exports = {
9994
},
10095

10196
activeshape: {
97+
description: [
98+
'An \'editable`\' shape can be \'activated\' by clicking on its border line.'
99+
].join(' '),
100+
102101
fillcolor: {
103102
valType: 'color',
104103
dflt: 'rgb(255,0,255)',

test/jasmine/tests/draw_newshape_test.js

+125-5
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ describe('Activate and edit editable shapes', function() {
10891089
afterEach(destroyGraphDiv);
10901090

10911091
['mouse'].forEach(function(device) {
1092-
it('@flaky reactangle using' + device, function(done) {
1092+
it('@flaky reactangle using ' + device, function(done) {
10931093
var i = 0; // shape index
10941094

10951095
Plotly.newPlot(gd, {
@@ -1224,7 +1224,7 @@ describe('Activate and edit editable shapes', function() {
12241224
.then(done);
12251225
});
12261226

1227-
it('@flaky circle using' + device, function(done) {
1227+
it('@flaky circle using ' + device, function(done) {
12281228
var i = 1; // shape index
12291229

12301230
Plotly.newPlot(gd, {
@@ -1281,7 +1281,7 @@ describe('Activate and edit editable shapes', function() {
12811281
.then(done);
12821282
});
12831283

1284-
it('@flaky closed-path using' + device, function(done) {
1284+
it('@flaky closed-path using ' + device, function(done) {
12851285
var i = 2; // shape index
12861286

12871287
Plotly.newPlot(gd, {
@@ -1326,7 +1326,7 @@ describe('Activate and edit editable shapes', function() {
13261326
.then(done);
13271327
});
13281328

1329-
it('@flaky bezier curves using' + device, function(done) {
1329+
it('@flaky bezier curves using ' + device, function(done) {
13301330
var i = 5; // shape index
13311331

13321332
Plotly.newPlot(gd, {
@@ -1371,7 +1371,7 @@ describe('Activate and edit editable shapes', function() {
13711371
.then(done);
13721372
});
13731373

1374-
it('@flaky multi-cell path using' + device, function(done) {
1374+
it('@flaky multi-cell path using ' + device, function(done) {
13751375
var i = 6; // shape index
13761376

13771377
Plotly.newPlot(gd, {
@@ -1426,3 +1426,123 @@ describe('Activate and edit editable shapes', function() {
14261426
});
14271427
});
14281428
});
1429+
1430+
1431+
describe('Activate and edit editable shapes', function() {
1432+
var gd;
1433+
1434+
beforeEach(function() {
1435+
gd = createGraphDiv();
1436+
});
1437+
1438+
afterEach(destroyGraphDiv);
1439+
1440+
it('should not set pointer-events for non-editable shapes i.e. to allow pan/zoom/hover work inside shapes', function(done) {
1441+
Plotly.newPlot(gd, {
1442+
data: [{
1443+
mode: 'markers',
1444+
x: [1, 3, 3],
1445+
y: [2, 1, 3]
1446+
}],
1447+
layout: {
1448+
shapes: [
1449+
{
1450+
x0: 1.5,
1451+
x1: 2.5,
1452+
y0: 1.5,
1453+
y1: 2.5,
1454+
fillcolor: 'blue'
1455+
}
1456+
]
1457+
}
1458+
})
1459+
1460+
.then(function() {
1461+
var el = Plotly.d3.selectAll('.shapelayer path')[0][0];
1462+
var pointerEvents = el.style['pointer-events'];
1463+
expect(pointerEvents).not.toBe('all');
1464+
expect(pointerEvents).not.toBe('stroke');
1465+
expect(pointerEvents).toBe('');
1466+
})
1467+
1468+
.catch(failTest)
1469+
.then(done);
1470+
});
1471+
1472+
it('should provide invisible border & set pointer-events to "stroke" for editable shapes i.e. to allow shape activation', function(done) {
1473+
Plotly.newPlot(gd, {
1474+
data: [{
1475+
mode: 'markers',
1476+
x: [1, 3, 3],
1477+
y: [2, 1, 3]
1478+
}],
1479+
layout: {
1480+
shapes: [
1481+
{
1482+
editable: true,
1483+
x0: 1.5,
1484+
x1: 2.5,
1485+
y0: 1.5,
1486+
y1: 2.5,
1487+
fillcolor: 'blue',
1488+
line: {
1489+
width: 0,
1490+
dash: 'dash',
1491+
color: 'black'
1492+
}
1493+
}
1494+
]
1495+
}
1496+
})
1497+
1498+
.then(function() {
1499+
var el = Plotly.d3.selectAll('.shapelayer path')[0][0];
1500+
expect(el.style['pointer-events']).toBe('stroke');
1501+
expect(el.style.stroke).toBe('rgb(0, 0, 0)'); // no color
1502+
expect(el.style['stroke-opacity']).toBe('0'); // invisible
1503+
expect(el.style['stroke-width']).toBe('5px'); // some pixels to activate shape
1504+
})
1505+
1506+
.catch(failTest)
1507+
.then(done);
1508+
});
1509+
1510+
it('should not provide invisible border & set pointer-events to "stroke" for shapes made editable via config', function(done) {
1511+
Plotly.newPlot(gd, {
1512+
data: [{
1513+
mode: 'markers',
1514+
x: [1, 3, 3],
1515+
y: [2, 1, 3]
1516+
}],
1517+
layout: {
1518+
shapes: [
1519+
{
1520+
x0: 1.5,
1521+
x1: 2.5,
1522+
y0: 1.5,
1523+
y1: 2.5,
1524+
fillcolor: 'blue',
1525+
line: {
1526+
width: 0,
1527+
dash: 'dash',
1528+
color: 'black'
1529+
}
1530+
}
1531+
]
1532+
}, onfig: {
1533+
editable: true
1534+
}
1535+
})
1536+
1537+
.then(function() {
1538+
var el = Plotly.d3.selectAll('.shapelayer path')[0][0];
1539+
expect(el.style['pointer-events']).toBe('');
1540+
expect(el.style.stroke).toBe('rgb(0, 0, 0)'); // no color
1541+
expect(el.style['stroke-opacity']).toBe('0'); // invisible
1542+
expect(el.style['stroke-width']).toBe('0px'); // no extra pixels
1543+
})
1544+
1545+
.catch(failTest)
1546+
.then(done);
1547+
});
1548+
});

0 commit comments

Comments
 (0)