/base/000_base/bower_components/highcharts/js/modules/exporting.src.js |
@@ -1,5 +1,5 @@ |
/** |
* @license Highcharts JS v5.0.10 (2017-03-31) |
* @license Highcharts JS v5.0.12 (2017-05-24) |
* Exporting module |
* |
* (c) 2010-2017 Torstein Honsi |
@@ -38,13 +38,16 @@ |
merge = H.merge, |
pick = H.pick, |
each = H.each, |
objectEach = H.objectEach, |
extend = H.extend, |
isTouchDevice = H.isTouchDevice, |
win = H.win, |
SVGRenderer = H.SVGRenderer; |
userAgent = win.navigator.userAgent, |
SVGRenderer = H.SVGRenderer, |
symbols = H.Renderer.prototype.symbols, |
isMSBrowser = /Edge\/|Trident\/|MSIE /.test(userAgent), |
isFirefoxBrowser = /firefox/i.test(userAgent); |
|
var symbols = H.Renderer.prototype.symbols; |
|
// Add language |
extend(defaultOptions.lang, { |
printChart: 'Print chart', |
@@ -92,64 +95,39 @@ |
symbol: 'menu', |
_titleKey: 'contextButtonTitle', |
menuItems: [{ |
textKey: 'printChart', |
onclick: function() { |
this.print(); |
} |
}, { |
separator: true |
}, { |
textKey: 'downloadPNG', |
onclick: function() { |
this.exportChart(); |
} |
}, { |
textKey: 'downloadJPEG', |
onclick: function() { |
this.exportChart({ |
type: 'image/jpeg' |
}); |
} |
}, { |
textKey: 'downloadPDF', |
onclick: function() { |
this.exportChart({ |
type: 'application/pdf' |
}); |
} |
}, { |
textKey: 'downloadSVG', |
onclick: function() { |
this.exportChart({ |
type: 'image/svg+xml' |
}); |
} |
textKey: 'printChart', |
onclick: function() { |
this.print(); |
} |
// Enable this block to add "View SVG" to the dropdown menu |
/* |
,{ |
|
text: 'View SVG Image', |
onclick: function () { |
var div = doc.createElement('div'); |
div.innerHTML = this.getSVGForExport(); |
|
this.renderTo.parentNode.appendChild(div); |
} |
}, { |
|
text: 'View SVG Source', |
onclick: function () { |
var pre = doc.createElement('pre'); |
pre.innerHTML = this.getSVGForExport() |
.replace(/</g, '\n<') |
.replace(/>/g, '>'); |
|
this.renderTo.parentNode.appendChild(pre); |
} |
}, { |
separator: true |
}, { |
textKey: 'downloadPNG', |
onclick: function() { |
this.exportChart(); |
} |
// */ |
] |
}, { |
textKey: 'downloadJPEG', |
onclick: function() { |
this.exportChart({ |
type: 'image/jpeg' |
}); |
} |
}, { |
textKey: 'downloadPDF', |
onclick: function() { |
this.exportChart({ |
type: 'application/pdf' |
}); |
} |
}, { |
textKey: 'downloadSVG', |
onclick: function() { |
this.exportChart({ |
type: 'image/svg+xml' |
}); |
} |
}] |
} |
} |
}; |
@@ -156,11 +134,8 @@ |
|
// Add the H.post utility |
H.post = function(url, data, formAttributes) { |
var name, |
form; |
|
// create the form |
form = createElement('form', merge({ |
var form = createElement('form', merge({ |
method: 'post', |
action: url, |
enctype: 'multipart/form-data' |
@@ -169,13 +144,13 @@ |
}, doc.body); |
|
// add the data |
for (name in data) { |
objectEach(data, function(val, name) { |
createElement('input', { |
type: 'hidden', |
name: name, |
value: data[name] |
value: val |
}, null, form); |
} |
}); |
|
// submit |
form.submit(); |
@@ -184,7 +159,7 @@ |
discardElement(form); |
}; |
|
extend(Chart.prototype, { |
extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ { |
|
/** |
* A collection of fixes on the produced SVG to account for expando properties, |
@@ -247,13 +222,17 @@ |
/** |
* Return an SVG representation of the chart. |
* |
* @param additionalOptions {Object} Additional chart options for the |
* generated SVG representation. For collections like `xAxis`, `yAxis` or |
* `series`, the additional options is either merged in to the orininal |
* item of the same `id`, or to the first item if a commin id is not |
* found. |
* @param chartOptions {Options} |
* Additional chart options for the generated SVG representation. |
* For collections like `xAxis`, `yAxis` or `series`, the additional |
* options is either merged in to the orininal item of the same |
* `id`, or to the first item if a common id is not found. |
* @return {String} |
* The SVG representation of the rendered chart. |
* @sample highcharts/members/chart-getsvg/ |
* View the SVG from a button |
*/ |
getSVG: function(additionalOptions) { |
getSVG: function(chartOptions) { |
var chart = this, |
chartCopy, |
sandbox, |
@@ -263,7 +242,7 @@ |
sourceHeight, |
cssWidth, |
cssHeight, |
options = merge(chart.options, additionalOptions); // copy the options and add extra options |
options = merge(chart.options, chartOptions); // copy the options and add extra options |
|
|
// IE compatibility hack for generating SVG content that it doesn't really understand |
@@ -331,11 +310,11 @@ |
chartCopy = new H.Chart(options, chart.callback); |
|
// Axis options and series options (#2022, #3900, #5982) |
if (additionalOptions) { |
if (chartOptions) { |
each(['xAxis', 'yAxis', 'series'], function(coll) { |
var collOptions = {}; |
if (additionalOptions[coll]) { |
collOptions[coll] = additionalOptions[coll]; |
if (chartOptions[coll]) { |
collOptions[coll] = chartOptions[coll]; |
chartCopy.update(collOptions); |
} |
}); |
@@ -388,30 +367,63 @@ |
}, |
|
/** |
* Submit the SVG representation of the chart to the server |
* @param {Object} options Exporting options. Possible members are url, type, width and formAttributes. |
* @param {Object} chartOptions Additional chart options for the SVG representation of the chart |
* Exporting module required. Submit an SVG version of the chart to a server |
* along with some parameters for conversion. |
* @param {Object} exportingOptions |
* Exporting options in addition to those defined in {@link |
* https://api.highcharts.com/highcharts/exporting|exporting}. |
* @param {String} exportingOptions.filename |
* The file name for the export without extension. |
* @param {String} exportingOptions.url |
* The URL for the server module to do the conversion. |
* @param {Number} exportingOptions.width |
* The width of the PNG or JPG image generated on the server. |
* @param {String} exportingOptions.type |
* The MIME type of the converted image. |
* @param {Number} exportingOptions.sourceWidth |
* The pixel width of the source (in-page) chart. |
* @param {Number} exportingOptions.sourceHeight |
* The pixel height of the source (in-page) chart. |
* @param {Options} chartOptions |
* Additional chart options for the exported chart. For example a |
* different background color can be added here, or `dataLabels` |
* for export only. |
* |
* @sample highcharts/members/chart-exportchart/ |
* Export with no options |
* @sample highcharts/members/chart-exportchart-filename/ |
* PDF type and custom filename |
* @sample highcharts/members/chart-exportchart-custom-background/ |
* Different chart background in export |
* @sample stock/members/chart-exportchart/ |
* Export with Highstock |
*/ |
exportChart: function(options, chartOptions) { |
exportChart: function(exportingOptions, chartOptions) { |
|
var svg = this.getSVGForExport(options, chartOptions); |
var svg = this.getSVGForExport(exportingOptions, chartOptions); |
|
// merge the options |
options = merge(this.options.exporting, options); |
exportingOptions = merge(this.options.exporting, exportingOptions); |
|
// do the post |
H.post(options.url, { |
filename: options.filename || 'chart', |
type: options.type, |
width: options.width || 0, // IE8 fails to post undefined correctly, so use 0 |
scale: options.scale, |
H.post(exportingOptions.url, { |
filename: exportingOptions.filename || 'chart', |
type: exportingOptions.type, |
width: exportingOptions.width || 0, // IE8 fails to post undefined correctly, so use 0 |
scale: exportingOptions.scale, |
svg: svg |
}, options.formAttributes); |
}, exportingOptions.formAttributes); |
|
}, |
|
/** |
* Print the chart |
* Exporting module required. Clears away other elements in the page and |
* prints the chart as it is displayed. By default, when the exporting |
* module is enabled, a context button with a drop down menu in the upper |
* right corner accesses this function. |
* |
* @sample highcharts/members/chart-print/ |
* Print from a HTML button |
*/ |
print: function() { |
|
@@ -809,6 +821,7 @@ |
var renderer = this.renderer, |
inlineToAttributes = renderer.inlineToAttributes, |
blacklist = renderer.inlineBlacklist, |
whitelist = renderer.inlineWhitelist, // For IE |
unstyledElements = renderer.unstyledElements, |
defaultStyles = {}, |
dummySVG; |
@@ -829,15 +842,55 @@ |
* Call this on all elements and recurse to children |
*/ |
function recurse(node) { |
var prop, |
styles, |
var styles, |
parentStyles, |
cssText = '', |
dummy, |
styleAttr, |
blacklisted, |
whitelisted, |
i; |
|
// Check computed styles and whether they are in the white/blacklist for |
// styles or atttributes |
function filterStyles(val, prop) { |
|
// Check against whitelist & blacklist |
blacklisted = whitelisted = false; |
if (whitelist) { |
// Styled mode in IE has a whitelist instead. |
// Exclude all props not in this list. |
i = whitelist.length; |
while (i-- && !whitelisted) { |
whitelisted = whitelist[i].test(prop); |
} |
blacklisted = !whitelisted; |
} |
|
// Explicitly remove empty transforms |
if (prop === 'transform' && val === 'none') { |
blacklisted = true; |
} |
|
i = blacklist.length; |
while (i-- && !blacklisted) { |
blacklisted = blacklist[i].test(prop) || typeof val === 'function'; |
} |
|
if (!blacklisted) { |
// If parent node has the same style, it gets inherited, no need to inline it |
if (parentStyles[prop] !== val && defaultStyles[node.nodeName][prop] !== val) { |
// Attributes |
if (inlineToAttributes.indexOf(prop) !== -1) { |
node.setAttribute(hyphenate(prop), val); |
// Styles |
} else { |
cssText += hyphenate(prop) + ':' + val + ';'; |
} |
} |
} |
} |
|
if (node.nodeType === 1 && unstyledElements.indexOf(node.nodeName) === -1) { |
styles = win.getComputedStyle(node, null); |
parentStyles = node.nodeName === 'svg' ? {} : win.getComputedStyle(node.parentNode, null); |
@@ -855,32 +908,14 @@ |
dummySVG.removeChild(dummy); |
} |
|
// Loop over all the computed styles and check whether they are in the |
// white list for styles or atttributes. |
for (prop in styles) { |
|
// Check against blacklist |
blacklisted = false; |
i = blacklist.length; |
while (i-- && !blacklisted) { |
blacklisted = blacklist[i].test(prop) || typeof styles[prop] === 'function'; |
// Loop through all styles and add them inline if they are ok |
if (isFirefoxBrowser || isMSBrowser) { |
// Some browsers put lots of styles on the prototype |
for (var p in styles) { |
filterStyles(styles[p], p); |
} |
|
if (!blacklisted) { |
|
// If parent node has the same style, it gets inherited, no need to inline it |
if (parentStyles[prop] !== styles[prop] && defaultStyles[node.nodeName][prop] !== styles[prop]) { |
|
// Attributes |
if (inlineToAttributes.indexOf(prop) !== -1) { |
node.setAttribute(hyphenate(prop), styles[prop]); |
|
// Styles |
} else { |
cssText += hyphenate(prop) + ':' + styles[prop] + ';'; |
} |
} |
} |
} else { |
objectEach(styles, filterStyles); |
} |
|
// Apply styles |
@@ -889,6 +924,11 @@ |
node.setAttribute('style', (styleAttr ? styleAttr + ';' : '') + cssText); |
} |
|
// Set default stroke width (needed at least for IE) |
if (node.nodeName === 'svg') { |
node.setAttribute('stroke-width', '1px'); |
} |
|
if (node.nodeName === 'text') { |
return; |
} |
@@ -926,28 +966,28 @@ |
|
// Add the buttons on chart load |
Chart.prototype.renderExporting = function() { |
var n, |
exportingOptions = this.options.exporting, |
var chart = this, |
exportingOptions = chart.options.exporting, |
buttons = exportingOptions.buttons, |
isDirty = this.isDirtyExporting || !this.exportSVGElements; |
isDirty = chart.isDirtyExporting || !chart.exportSVGElements; |
|
this.buttonOffset = 0; |
if (this.isDirtyExporting) { |
this.destroyExport(); |
chart.buttonOffset = 0; |
if (chart.isDirtyExporting) { |
chart.destroyExport(); |
} |
|
if (isDirty && exportingOptions.enabled !== false) { |
this.exportEvents = []; |
chart.exportEvents = []; |
|
for (n in buttons) { |
this.addButton(buttons[n]); |
} |
objectEach(buttons, function(button) { |
chart.addButton(button); |
}); |
|
this.isDirtyExporting = false; |
chart.isDirtyExporting = false; |
} |
|
// Destroy the export elements at chart destroy |
addEvent(this, 'destroy', this.destroyExport); |
addEvent(chart, 'destroy', chart.destroyExport); |
}; |
|
Chart.prototype.callbacks.push(function(chart) { |
@@ -979,8 +1019,11 @@ |
// testing of export |
/* |
if (!chart.renderer.forExport) { |
var button = doc.createElement('button'); |
button.innerHTML = 'View exported SVG'; |
var button; |
|
// View SVG Image |
button = doc.createElement('button'); |
button.innerHTML = 'View SVG Image'; |
chart.renderTo.parentNode.appendChild(button); |
button.onclick = function () { |
var div = doc.createElement('div'); |
@@ -987,6 +1030,18 @@ |
div.innerHTML = chart.getSVGForExport(); |
chart.renderTo.parentNode.appendChild(div); |
}; |
|
// View SVG Source |
button = doc.createElement('button'); |
button.innerHTML = 'View SVG Source'; |
chart.renderTo.parentNode.appendChild(button); |
button.onclick = function () { |
var pre = doc.createElement('pre'); |
pre.innerHTML = chart.getSVGForExport() |
.replace(/</g, '\n<') |
.replace(/>/g, '>'); |
chart.renderTo.parentNode.appendChild(pre); |
}; |
} |
// */ |
}); |