Use new fc

This commit is contained in:
Abhas
2017-04-24 15:41:56 +05:30
parent 073a0b8a79
commit 0c21438193
2 changed files with 103 additions and 30 deletions
+102 -29
View File
@@ -15776,11 +15776,16 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
return {'name' : 'default', 'version' : 'Not Known'}; return {'name' : 'default', 'version' : 'Not Known'};
}, },
removeCrossDomainImages = function(svgStr) { removeCrossDomainImages = function(svgStr,replaceEmpty) {
// never use it i.e. remove CORS images when you can pass it on to export server.
if (replaceEmpty === undefined) {
replaceEmpty = true;
}
var imgArr; var imgArr;
imgArr = svgStr.replace(/<image [^\>]*\>/gi, function(matchStr) { imgArr = svgStr.replace(/<image [^\>]*\>/gi, function(matchStr) {
if (matchStr.match(/href=["']\s*["']/)) { if (replaceEmpty && matchStr.match(/href=["']\s*["']/)) {
return ''; return '';
} }
if(matchStr.match(/href=["']http:\/\/|href=["']https:\/\//)) { if(matchStr.match(/href=["']http:\/\/|href=["']https:\/\//)) {
@@ -15796,6 +15801,27 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
return imgArr; return imgArr;
}, },
hasCrossDomainImage = function (svgStr) {
return (svgStr != removeCrossDomainImages(svgStr, true));
},
parseUrl = function(href) {
var l = document.createElement("a");
l.href = href;
return l;
},
isSameDomainUrl = function (url1,url2) {
url1 = parseUrl(url1);
url2 = parseUrl(url2);
return (url1.host == url2.host);
},
isCrossDomainUrl = function (url1) {
return (!isSameDomainUrl(url1,win.location));
},
/* /*
* method makeClientSideDownload is used to make the file downloadable * method makeClientSideDownload is used to make the file downloadable
* for different browser * for different browser
@@ -16019,7 +16045,7 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
/* /*
* method processInternalImages is used to convert the inline images to dataurl * method processInternalImages is used to convert the inline images to dataurl
* @variable svgStr {string} the svg string whose inline images to be converted * @variable svgStr {string} the svg string whose inline images (if not CORS) to be converted
* @variable callback {string} method to be called after succesfully conversion * @variable callback {string} method to be called after succesfully conversion
*/ */
processInternalImages = function(svgStr, callback) { processInternalImages = function(svgStr, callback) {
@@ -16030,7 +16056,7 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
svgStr = svgStr.replace(/NS\d+:/gi, 'xlink:'); svgStr = svgStr.replace(/NS\d+:/gi, 'xlink:');
svgStr = removeCrossDomainImages(svgStr); // svgStr = removeCrossDomainImages(svgStr);
// if there is no images pass the svg to the callback and return. // if there is no images pass the svg to the callback and return.
if(svgStr.indexOf('<image ') === -1) { if(svgStr.indexOf('<image ') === -1) {
callback(svgStr); callback(svgStr);
@@ -16038,32 +16064,47 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
} }
noOfImages = svgStr.match(/<image [^\>]*\>/gi).length; noOfImages = svgStr.match(/<image [^\>]*\>/gi).length;
svgStr = svgStr.replace(/<image [^\>]*\>/gi, function(matchStr) { svgStr = svgStr.replace(/<image [^\>]*\>/gi, function(matchStr) {
var crossDomainImageFlag = false;
matchStr = matchStr.replace(/(:href=")([^"]*)(")/gi, function(matchSubStr, p1, p2, p3) { matchStr = matchStr.replace(/(:href=")([^"]*)(")/gi, function(matchSubStr, p1, p2, p3) {
imageName = p2; imageName = p2;
return p1+'{{{'+i+'}}}'+p3; if (isCrossDomainUrl(imageName)) {
// if CORS image, dont try to replace it, let it go
// and act as if image was successfully loaded by increasing counter
crossDomainImageFlag = true;
noOfImagesLoaded++;
return matchSubStr;
}
else {
return p1+'{{{'+i+'}}}'+p3;
}
}); });
var canvas = doc.createElement('canvas'), if (!crossDomainImageFlag) {
ctx, var canvas = doc.createElement('canvas'),
img; ctx,
ctx = canvas.getContext('2d'); img;
img = new Image(); ctx = canvas.getContext('2d');
img.src = imageName; img = new Image();
img.ind = i; img.src = imageName;
img.onload = function() { img.ind = i;
canvas.width = this.width; // currently if any of the image download fails, export fails as callback
canvas.height = this.height; // is not called ever. We should also listen to onerror of image laod
ctx.drawImage(this, 0, 0); img.onload = function() {
var imageUri = canvas.toDataURL('image/png'), canvas.width = this.width;
re; canvas.height = this.height;
new Image().src = imageUri; ctx.drawImage(this, 0, 0);
re = new RegExp('\\{\\{\\{'+img.ind+'\\}\\}\\}', 'g'); var imageUri = canvas.toDataURL('image/png'),
svgStr = svgStr.replace(re, imageUri); re;
noOfImagesLoaded++; new Image().src = imageUri;
if(noOfImages === noOfImagesLoaded) { re = new RegExp('\\{\\{\\{'+img.ind+'\\}\\}\\}', 'g');
callback(svgStr); svgStr = svgStr.replace(re, imageUri);
} noOfImagesLoaded++;
}; if(noOfImages === noOfImagesLoaded) {
callback(svgStr);
}
};
}
i++; i++;
return matchStr; return matchStr;
}); });
@@ -16086,6 +16127,12 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
}); });
}, },
getSVGRawInternalImagesProcessed = function (svg,callback) {
processInternalImages(svg, function(svgStr) {
callback(svgStr);
});
},
/*************** Image Export Function End ********************/ /*************** Image Export Function End ********************/
componentDispose = function() { componentDispose = function() {
@@ -16994,7 +17041,11 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
componentDispose : componentDispose, componentDispose : componentDispose,
componentConfigurer: componentConfigurer, componentConfigurer: componentConfigurer,
getSvgDataurl : getSvgDataurl, getSvgDataurl : getSvgDataurl,
getSVGRawInternalImagesProcessed : getSVGRawInternalImagesProcessed,
removeCrossDomainImages : removeCrossDomainImages, removeCrossDomainImages : removeCrossDomainImages,
hasCrossDomainImage : hasCrossDomainImage,
isSameDomainUrl : isSameDomainUrl,
isCrossDomainUrl : isCrossDomainUrl,
getBrowserDetails : getBrowserDetails, getBrowserDetails : getBrowserDetails,
dataurlToBlob : dataurlToBlob, dataurlToBlob : dataurlToBlob,
downloadCharts : downloadCharts, downloadCharts : downloadCharts,
@@ -39393,7 +39444,9 @@ FusionCharts.register('module', ['private', 'modules.exporter.main',
chartComponents = iapi.components, chartComponents = iapi.components,
chartInstance = iapi.chartInstance, chartInstance = iapi.chartInstance,
getSvgDataurl = lib.getSvgDataurl, getSvgDataurl = lib.getSvgDataurl,
getSVGRawInternalImagesProcessed = lib.getSVGRawInternalImagesProcessed,
removeCrossDomainImages = lib.removeCrossDomainImages, removeCrossDomainImages = lib.removeCrossDomainImages,
hasCrossDomainImage = lib.hasCrossDomainImage,
downloadCharts = lib.downloadCharts, downloadCharts = lib.downloadCharts,
options = chartConfig.exportOption, options = chartConfig.exportOption,
exportOptions_lowerKeys = isObject(exportOption) && (function (object) { // jshint ignore:line exportOptions_lowerKeys = isObject(exportOption) && (function (object) { // jshint ignore:line
@@ -39505,6 +39558,7 @@ FusionCharts.register('module', ['private', 'modules.exporter.main',
svg = paper.toSVG(exportwithimages && isCanvasSupported && exportFormat !== 'svg'); svg = paper.toSVG(exportwithimages && isCanvasSupported && exportFormat !== 'svg');
svgForClientSideExport = paper.toSVG(exportwithimages && isCanvasSupported); svgForClientSideExport = paper.toSVG(exportwithimages && isCanvasSupported);
svgForClientSideExport = removeCrossDomainImages(svgForClientSideExport);
// show the buttons layer after export // show the buttons layer after export
chartComponents.chartMenuBar && chartComponents.chartMenuBar.group.attr('visibility', 'visible'); chartComponents.chartMenuBar && chartComponents.chartMenuBar.group.attr('visibility', 'visible');
@@ -39515,7 +39569,7 @@ FusionCharts.register('module', ['private', 'modules.exporter.main',
svg = svg.replace(/NS\d+:/gi, 'xlink:'); svg = svg.replace(/NS\d+:/gi, 'xlink:');
// Remove cross domain Images // Remove cross domain Images
svg = removeCrossDomainImages(svg); // svg = removeCrossDomainImages(svg);
svgForClientSideExport = svgForClientSideExport.replace(/NS\d+:/gi, 'xlink:'); svgForClientSideExport = svgForClientSideExport.replace(/NS\d+:/gi, 'xlink:');
svgForClientSideExport = svgForClientSideExport.replace(/(\sd\s*=\s*["'])[M\s\d\.]*(["'])/ig, svgForClientSideExport = svgForClientSideExport.replace(/(\sd\s*=\s*["'])[M\s\d\.]*(["'])/ig,
@@ -39614,9 +39668,23 @@ FusionCharts.register('module', ['private', 'modules.exporter.main',
var canvas, var canvas,
sendPost, sendPost,
pdfDoc; pdfDoc;
sendPost = function (dataUri) { var crossDomainImageFlag = hasCrossDomainImage(svg);
sendPost = function (dataUri, crossDomainImageFlag) {
if (crossDomainImageFlag === undefined)
{
crossDomainImageFlag = false;
}
if (!crossDomainImageFlag)
{
postData.stream_type = 'IMAGE-DATA'; // jshint ignore:line
}
else
{
postData.stream_type = SVG; // jshint ignore:line
}
postData.stream = dataUri; postData.stream = dataUri;
postData.stream_type = 'IMAGE-DATA'; // jshint ignore:line
downloadCharts(null, null, null, postData, exportOptionObject); downloadCharts(null, null, null, postData, exportOptionObject);
}; };
// Check whether embedded images exists in the SVG String // Check whether embedded images exists in the SVG String
@@ -39628,6 +39696,11 @@ FusionCharts.register('module', ['private', 'modules.exporter.main',
getSvgDataurl(svgForClientSideExport, function (dataUri) { getSvgDataurl(svgForClientSideExport, function (dataUri) {
sendPost(dataUri); sendPost(dataUri);
}); });
} else if (crossDomainImageFlag) {
getSVGRawInternalImagesProcessed(svg,
function (svg) {
sendPost(svg,crossDomainImageFlag);
})
} else { } else {
lib.drawSvgOnCanvas(svgForClientSideExport, canvas, 0, 0, paper.width, lib.drawSvgOnCanvas(svgForClientSideExport, canvas, 0, 0, paper.width,
paper.height, function () { paper.height, function () {
+1 -1
View File
@@ -30,7 +30,7 @@
"items": [{ "items": [{
"id": "jennifer-user-icon", "id": "jennifer-user-icon",
"type": "image", "type": "image",
"url": "http://static.fusioncharts.com/sampledata/images/round-2.png", "url": "http://static.fusioncharts.com/sampledata/images/round-1.png",
"x": "$xaxis.label.0.x - 24", "x": "$xaxis.label.0.x - 24",
"y": "$xaxis.label.0.y - 48" "y": "$xaxis.label.0.y - 48"
}, { }, {