mirror of
https://github.com/bendtherules/line_chart_demo.git
synced 2026-08-18 13:52:30 +00:00
Use new fc
This commit is contained in:
+80
-7
@@ -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,11 +16064,23 @@ 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;
|
||||||
|
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;
|
return p1+'{{{'+i+'}}}'+p3;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if (!crossDomainImageFlag) {
|
||||||
var canvas = doc.createElement('canvas'),
|
var canvas = doc.createElement('canvas'),
|
||||||
ctx,
|
ctx,
|
||||||
img;
|
img;
|
||||||
@@ -16050,6 +16088,8 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
|
|||||||
img = new Image();
|
img = new Image();
|
||||||
img.src = imageName;
|
img.src = imageName;
|
||||||
img.ind = i;
|
img.ind = i;
|
||||||
|
// currently if any of the image download fails, export fails as callback
|
||||||
|
// is not called ever. We should also listen to onerror of image laod
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
canvas.width = this.width;
|
canvas.width = this.width;
|
||||||
canvas.height = this.height;
|
canvas.height = this.height;
|
||||||
@@ -16064,6 +16104,7 @@ FusionCharts.register('module', ['private', 'modules.renderer.js-lib', function
|
|||||||
callback(svgStr);
|
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);
|
||||||
postData.stream = dataUri;
|
sendPost = function (dataUri, crossDomainImageFlag) {
|
||||||
|
if (crossDomainImageFlag === undefined)
|
||||||
|
{
|
||||||
|
crossDomainImageFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!crossDomainImageFlag)
|
||||||
|
{
|
||||||
postData.stream_type = 'IMAGE-DATA'; // jshint ignore:line
|
postData.stream_type = 'IMAGE-DATA'; // jshint ignore:line
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
postData.stream_type = SVG; // jshint ignore:line
|
||||||
|
}
|
||||||
|
|
||||||
|
postData.stream = dataUri;
|
||||||
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
@@ -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"
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user