Skip to content

Commit 519f2ce

Browse files
authored
Merge pull request #3725 from blubiszirp/fix3724-parenthesis-in-url-draws-data-outside-plot-area
Fix3724 parenthesis in url draws data outside plot area
2 parents 5d69e77 + aefd2ab commit 519f2ce

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

src/components/drawing/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ drawing.setClipUrl = function(s, localId, gd) {
10281028
var context = gd._context;
10291029
var baseUrl = context._exportedPlot ? '' : (context._baseUrl || '');
10301030

1031-
s.attr('clip-path', 'url(' + baseUrl + '#' + localId + ')');
1031+
s.attr('clip-path', 'url(\'' + baseUrl + '#' + localId + '\')');
10321032
};
10331033

10341034
drawing.getTranslate = function(element) {

test/jasmine/assets/custom_assertions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ exports.assertClip = function(sel, isClipped, size, msg) {
226226
var clipPath = d3.select(this).attr('clip-path');
227227

228228
if(isClipped) {
229-
expect(String(clipPath).substr(0, 4))
230-
.toBe('url(', msg + ' clip path ' + '(item ' + i + ')');
229+
expect(String(clipPath).substr(0, 5))
230+
.toBe('url(\'', msg + ' clip path ' + '(item ' + i + ')');
231231
} else {
232232
expect(clipPath)
233233
.toBe(null, msg + ' clip path ' + '(item ' + i + ')');

test/jasmine/assets/get_bbox.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function getBBox(element) {
1515
if(!clipPathAttr) return elementBBox;
1616

1717
// only supports 'url(#<id>)' at the moment
18-
var clipPathId = clipPathAttr.substring(5, clipPathAttr.length - 1);
18+
var clipPathId = clipPathAttr.substring(6, clipPathAttr.length - 2);
1919
var clipBBox = getClipBBox(clipPathId);
2020

2121
return minBBox(elementBBox, clipBBox);
@@ -28,8 +28,7 @@ function getClipBBox(clipPathId) {
2828
try {
2929
// this line throws an error in FF (38 and 45 at least)
3030
clipBBox = clipPath.node().getBBox();
31-
}
32-
catch(e) {
31+
} catch(e) {
3332
// use DOM attributes as fallback
3433
var path = d3.select(clipPath.node().firstChild);
3534

test/jasmine/tests/drawing_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ describe('Drawing', function() {
2525

2626
Drawing.setClipUrl(this.g, 'id1', {_context: {}});
2727

28-
expect(this.g.attr('clip-path')).toEqual('url(#id1)');
28+
expect(this.g.attr('clip-path')).toEqual('url(\'#id1\')');
2929
});
3030

3131
it('should unset the clip-path if arg is falsy', function() {
32-
this.g.attr('clip-path', 'url(#id2)');
32+
this.g.attr('clip-path', 'url(\'#id2\')');
3333

3434
Drawing.setClipUrl(this.g, false);
3535

@@ -48,7 +48,7 @@ describe('Drawing', function() {
4848
Drawing.setClipUrl(this.g, 'id3', {_context: {_baseUrl: href}});
4949

5050
expect(this.g.attr('clip-path'))
51-
.toEqual('url(' + href + '#id3)');
51+
.toEqual('url(\'' + href + '#id3\')');
5252

5353
base.remove();
5454
});
@@ -64,7 +64,7 @@ describe('Drawing', function() {
6464

6565
Drawing.setClipUrl(this.g, 'id4', {_context: {_baseUrl: href2}});
6666

67-
var expected = 'url(' + href2 + '#id4)';
67+
var expected = 'url(\'' + href2 + '#id4\')';
6868

6969
expect(this.g.attr('clip-path')).toEqual(expected);
7070

test/jasmine/tests/layout_images_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -448,22 +448,22 @@ describe('images log/linear axis changes', function() {
448448
// automatically when you change xref / yref, we leave it to the caller.
449449

450450
// initial clip path should end in 'xy' to match xref/yref
451-
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy\)$/);
451+
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy\'\)$/);
452452

453453
// linear to log
454454
Plotly.relayout(gd, {'images[0].yref': 'y2'})
455455
.then(function() {
456456
expect(gd.layout.images[0].y).toBe(1);
457457

458-
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy2\)$/);
458+
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy2\'\)$/);
459459

460460
// log to paper
461461
return Plotly.relayout(gd, {'images[0].yref': 'paper'});
462462
})
463463
.then(function() {
464464
expect(gd.layout.images[0].y).toBe(1);
465465

466-
expect(d3.select('image').attr('clip-path') || '').toMatch(/x\)$/);
466+
expect(d3.select('image').attr('clip-path') || '').toMatch(/x\'\)$/);
467467

468468
// change to full paper-referenced, to make sure the clip path disappears
469469
return Plotly.relayout(gd, {'images[0].xref': 'paper'});
@@ -477,7 +477,7 @@ describe('images log/linear axis changes', function() {
477477
.then(function() {
478478
expect(gd.layout.images[0].y).toBe(1);
479479

480-
expect(d3.select('image').attr('clip-path') || '').toMatch(/^[^x]+y2\)$/);
480+
expect(d3.select('image').attr('clip-path') || '').toMatch(/^[^x]+y2\'\)$/);
481481

482482
// log to linear
483483
return Plotly.relayout(gd, {'images[0].yref': 'y'});

test/jasmine/tests/plot_interact_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ describe('plot svg clip paths', function() {
545545
d3.selectAll('[clip-path]').each(function() {
546546
var cp = d3.select(this).attr('clip-path');
547547

548-
expect(cp.substring(0, 5)).toEqual('url(#');
549-
expect(cp.substring(cp.length - 1)).toEqual(')');
548+
expect(cp.substring(0, 6)).toEqual('url(\'#');
549+
expect(cp.substring(cp.length - 2)).toEqual('\')');
550550
});
551551
})
552552
.catch(failTest)
@@ -569,8 +569,8 @@ describe('plot svg clip paths', function() {
569569
d3.selectAll('[clip-path]').each(function() {
570570
var cp = d3.select(this).attr('clip-path');
571571

572-
expect(cp.substring(0, 5 + href.length)).toEqual('url(' + href + '#');
573-
expect(cp.substring(cp.length - 1)).toEqual(')');
572+
expect(cp.substring(0, 6 + href.length)).toEqual('url(\'' + href + '#');
573+
expect(cp.substring(cp.length - 2)).toEqual('\')');
574574
});
575575

576576
base.remove();

test/jasmine/tests/shapes_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ describe('shapes axis reference changes', function() {
458458
}
459459

460460
it('draws the right number of objects and updates clip-path correctly', function(done) {
461-
expect(getShape(0).attr('clip-path') || '').toMatch(/x\)$/);
461+
expect(getShape(0).attr('clip-path') || '').toMatch(/x\'\)$/);
462462

463463
Plotly.relayout(gd, {
464464
'shapes[0].xref': 'paper',
@@ -475,7 +475,7 @@ describe('shapes axis reference changes', function() {
475475
});
476476
})
477477
.then(function() {
478-
expect(getShape(0).attr('clip-path') || '').toMatch(/^[^x]+y2\)$/);
478+
expect(getShape(0).attr('clip-path') || '').toMatch(/^[^x]+y2\'\)$/);
479479

480480
return Plotly.relayout(gd, {
481481
'shapes[0].xref': 'x',
@@ -484,7 +484,7 @@ describe('shapes axis reference changes', function() {
484484
});
485485
})
486486
.then(function() {
487-
expect(getShape(0).attr('clip-path') || '').toMatch(/xy2\)$/);
487+
expect(getShape(0).attr('clip-path') || '').toMatch(/xy2\'\)$/);
488488
})
489489
.catch(failTest)
490490
.then(done);

test/jasmine/tests/toimage_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ describe('Plotly.toImage', function() {
229229
var clipPath = gSubplot.getAttribute('clip-path');
230230
var len = clipPath.length;
231231

232-
var head = clipPath.substr(0, 4);
233-
var tail = clipPath.substr(len - 7, len);
234-
expect(head).toBe('url(', 'subplot clipPath head');
235-
expect(tail).toBe('xyplot)', 'subplot clipPath tail');
232+
var head = clipPath.substr(0, 5);
233+
var tail = clipPath.substr(len - 8, len);
234+
expect(head).toBe('url(\'', 'subplot clipPath head');
235+
expect(tail).toBe('xyplot\')', 'subplot clipPath tail');
236236

237237
var middle = clipPath.substr(4, 10);
238238
expect(middle.length).toBe(10, 'subplot clipPath uid length');

0 commit comments

Comments
 (0)