@@ -1000,32 +1000,28 @@ function nodeHash(node) {
10001000 node . getAttribute ( 'style' ) ;
10011001}
10021002
1003- /*
1004- * make a robust clipPath url from a local id
1005- * note! We'd better not be exporting from a page
1006- * with a <base> or the svg will not be portable!
1003+ /**
1004+ * Set clipPath URL in a way that work for all situations.
1005+ *
1006+ * In details, graphs on pages with <base> HTML tags need to prepend
1007+ * the clip path ids with the page's base url EXCEPT during toImage exports.
1008+ *
1009+ * @param {d3 selection } s : node to add clip-path attribute
1010+ * @param {string } localId : local clip-path (w/o base url) id
1011+ * @param {DOM element || object } gd
1012+ * - context._baseUrl {string}
1013+ * - context._exportedPlot {boolean}
10071014 */
1008- drawing . setClipUrl = function ( s , localId ) {
1015+ drawing . setClipUrl = function ( s , localId , gd ) {
10091016 if ( ! localId ) {
10101017 s . attr ( 'clip-path' , null ) ;
10111018 return ;
10121019 }
10131020
1014- if ( drawing . baseUrl === undefined ) {
1015- var base = d3 . select ( 'base' ) ;
1016-
1017- // Stash base url once and for all!
1018- // We may have to stash this elsewhere when
1019- // we'll try to support for child windows
1020- // more info -> https://github.com/plotly/plotly.js/issues/702
1021- if ( base . size ( ) && base . attr ( 'href' ) ) {
1022- drawing . baseUrl = window . location . href . split ( '#' ) [ 0 ] ;
1023- } else {
1024- drawing . baseUrl = '' ;
1025- }
1026- }
1021+ var context = gd . _context ;
1022+ var baseUrl = context . _exportedPlot ? '' : ( context . _baseUrl || '' ) ;
10271023
1028- s . attr ( 'clip-path' , 'url(' + drawing . baseUrl + '#' + localId + ')' ) ;
1024+ s . attr ( 'clip-path' , 'url(' + baseUrl + '#' + localId + ')' ) ;
10291025} ;
10301026
10311027drawing . getTranslate = function ( element ) {
0 commit comments