Skip to content

Commit f907c06

Browse files
committed
include baseUrl in gradient style references
1 parent 1d0acf0 commit f907c06

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/components/drawing/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ drawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {
335335
});
336336
});
337337

338-
sel.style(prop, 'url(#' + fullID + ')')
338+
sel.style(prop, getFullUrl(fullID, gd))
339339
.style(prop + '-opacity', null);
340340
};
341341

@@ -1020,16 +1020,16 @@ function nodeHash(node) {
10201020
* - context._exportedPlot {boolean}
10211021
*/
10221022
drawing.setClipUrl = function(s, localId, gd) {
1023-
if(!localId) {
1024-
s.attr('clip-path', null);
1025-
return;
1026-
}
1023+
s.attr('clip-path', getFullUrl(localId, gd));
1024+
};
1025+
1026+
function getFullUrl(localId, gd) {
1027+
if(!localId) return null;
10271028

10281029
var context = gd._context;
10291030
var baseUrl = context._exportedPlot ? '' : (context._baseUrl || '');
1030-
1031-
s.attr('clip-path', 'url(\'' + baseUrl + '#' + localId + '\')');
1032-
};
1031+
return 'url(\'' + baseUrl + '#' + localId + '\')';
1032+
}
10331033

10341034
drawing.getTranslate = function(element) {
10351035
// Note the separator [^\d] between x and y in this regex

test/jasmine/tests/drawing_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,34 @@ describe('gradients', function() {
543543
.catch(failTest)
544544
.then(done);
545545
});
546+
547+
it('should append window URL to gradient ref if <base> is present', function(done) {
548+
var base = d3.select('body')
549+
.append('base')
550+
.attr('href', 'https://plot.ly');
551+
552+
Plotly.plot(gd, [{
553+
type: 'heatmap',
554+
x: [1, 2],
555+
y: [2, 3],
556+
z: [[1, 3], [2, 3]]
557+
}])
558+
.then(function() {
559+
var cbfills = d3.select(gd).select('.cbfills > rect');
560+
expect(cbfills.node().style.fill).toBe([
561+
'url("',
562+
window.location.href,
563+
'g',
564+
gd._fullLayout._uid,
565+
'-cb',
566+
gd._fullData[0].uid,
567+
'")'
568+
].join(''));
569+
})
570+
.catch(failTest)
571+
.then(function() {
572+
base.remove();
573+
done();
574+
});
575+
});
546576
});

0 commit comments

Comments
 (0)