Skip to content

Commit c164e35

Browse files
authoredApr 12, 2019
Merge pull request #3765 from plotly/handle-base-href-in-gradient-url
Include baseUrl in gradient style references
2 parents 74e8bb9 + f907c06 commit c164e35

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed
 

‎src/components/drawing/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ drawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {
332332
});
333333
});
334334

335-
sel.style(prop, 'url(#' + fullID + ')')
335+
sel.style(prop, getFullUrl(fullID, gd))
336336
.style(prop + '-opacity', null);
337337
};
338338

@@ -1015,16 +1015,16 @@ function nodeHash(node) {
10151015
* - context._exportedPlot {boolean}
10161016
*/
10171017
drawing.setClipUrl = function(s, localId, gd) {
1018-
if(!localId) {
1019-
s.attr('clip-path', null);
1020-
return;
1021-
}
1018+
s.attr('clip-path', getFullUrl(localId, gd));
1019+
};
1020+
1021+
function getFullUrl(localId, gd) {
1022+
if(!localId) return null;
10221023

10231024
var context = gd._context;
10241025
var baseUrl = context._exportedPlot ? '' : (context._baseUrl || '');
1025-
1026-
s.attr('clip-path', 'url(\'' + baseUrl + '#' + localId + '\')');
1027-
};
1026+
return 'url(\'' + baseUrl + '#' + localId + '\')';
1027+
}
10281028

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

‎test/jasmine/tests/drawing_test.js

+30
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)
Please sign in to comment.