app/assets/javascripts/highcharts/modules/exporting.js in highcharts-rails-4.1.1 vs app/assets/javascripts/highcharts/modules/exporting.js in highcharts-rails-4.1.2

- old
+ new

@@ -1,7 +1,7 @@ /** - * @license Highcharts JS v4.1.1 (2015-02-17) + * @license Highcharts JS v4.1.2 (2015-02-27) * Exporting module * * (c) 2010-2014 Torstein Honsi * * License: www.highcharts.com/license @@ -21,10 +21,11 @@ discardElement = Highcharts.discardElement, css = Highcharts.css, merge = Highcharts.merge, each = Highcharts.each, extend = Highcharts.extend, + splat = Highcharts.splat, math = Math, mathMax = math.max, doc = document, win = window, isTouchDevice = Highcharts.isTouchDevice, @@ -189,10 +190,67 @@ }; extend(Chart.prototype, { /** + * A collection of regex fixes on the produces SVG to account for expando properties, + * browser bugs, VML problems and other. Returns a cleaned SVG. + */ + sanitizeSVG: function (svg) { + return svg + .replace(/zIndex="[^"]+"/g, '') + .replace(/isShadow="[^"]+"/g, '') + .replace(/symbolName="[^"]+"/g, '') + .replace(/jQuery[0-9]+="[^"]+"/g, '') + .replace(/url\([^#]+#/g, 'url(#') + .replace(/<svg /, '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ') + .replace(/ (NS[0-9]+\:)?href=/g, ' xlink:href=') // #3567 + .replace(/\n/, ' ') + // Any HTML added to the container after the SVG (#894) + .replace(/<\/svg>.*?$/, '</svg>') + // Batik doesn't support rgba fills and strokes (#3095) + .replace(/(fill|stroke)="rgba\(([ 0-9]+,[ 0-9]+,[ 0-9]+),([ 0-9\.]+)\)"/g, '$1="rgb($2)" $1-opacity="$3"') + + // An issue with PhantomJS as of 2015-01-11. Revisit with newer versions. (#3649) + .replace(/(text-shadow:)([^;"]+)([;"])/g, function (s, $1, $2, $3) { + // Escape commas within rgb and rgba definitions + $2 = $2.replace(/\([^\)]+\)/g, function (s) { + return s.replace(/,/g, '|'); + }); + // Keep the first definition + $2 = $2.split(',')[0]; + // Re-inert commas + $2 = $2.replace(/\([^\)]+\)/g, function (s) { + return s.replace(/\|/g, ','); + }); + s = $1 + $2 + $3; + return s; + }) + /* This fails in IE < 8 + .replace(/([0-9]+)\.([0-9]+)/g, function(s1, s2, s3) { // round off to save weight + return s2 +'.'+ s3[0]; + })*/ + + // Replace HTML entities, issue #347 + .replace(/&nbsp;/g, '\u00A0') // no-break space + .replace(/&shy;/g, '\u00AD') // soft hyphen + + // IE specific + .replace(/<IMG /g, '<image ') + .replace(/height=([^" ]+)/g, 'height="$1"') + .replace(/width=([^" ]+)/g, 'width="$1"') + .replace(/hc-svg-href="([^"]+)">/g, 'xlink:href="$1"/>') + .replace(/id=([^" >]+)/g, 'id="$1"') + .replace(/class=([^" >]+)/g, 'class="$1"') + .replace(/ transform /g, ' ') + .replace(/:(path|rect)/g, '$1') + .replace(/style="([^"]+)"/g, function (s) { + return s.toLowerCase(); + }); + }, + + /** * Return an SVG representation of the chart * * @param additionalOptions {Object} Additional chart options for the generated SVG representation */ getSVG: function (additionalOptions) { @@ -260,10 +318,19 @@ if (!seriesOptions.isInternal) { // used for the navigator series that has its own option set options.series.push(seriesOptions); } }); + // Axis options must be merged in one by one, since it may be an array or an object (#2022) + if (additionalOptions) { + each(['xAxis', 'yAxis'], function (axisType, i) { + each(splat(additionalOptions[axisType]), function (axisOptions) { + options[axisType][i] = merge(options[axisType][i], axisOptions); + }); + }); + } + // generate the chart copy chartCopy = new Highcharts.Chart(options, chart.callback); // reflect axis extremes in the export each(['xAxis', 'yAxis'], function (axisType) { @@ -286,45 +353,10 @@ options = null; chartCopy.destroy(); discardElement(sandbox); // sanitize - svg = svg - .replace(/zIndex="[^"]+"/g, '') - .replace(/isShadow="[^"]+"/g, '') - .replace(/symbolName="[^"]+"/g, '') - .replace(/jQuery[0-9]+="[^"]+"/g, '') - .replace(/url\([^#]+#/g, 'url(#') - .replace(/<svg /, '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ') - .replace(/ href=/g, ' xlink:href=') - .replace(/\n/, ' ') - // Any HTML added to the container after the SVG (#894) - .replace(/<\/svg>.*?$/, '</svg>') - // Batik doesn't support rgba fills and strokes (#3095) - .replace(/(fill|stroke)="rgba\(([ 0-9]+,[ 0-9]+,[ 0-9]+),([ 0-9\.]+)\)"/g, '$1="rgb($2)" $1-opacity="$3"') - // An issue with PhantomJS as of 2015-01-11. Revisit with newer versions. (#3649) - .replace(/(text-shadow:[ 0-9a-z]+),[^"]+([;"])/g, '$1$2') - /* This fails in IE < 8 - .replace(/([0-9]+)\.([0-9]+)/g, function(s1, s2, s3) { // round off to save weight - return s2 +'.'+ s3[0]; - })*/ - - // Replace HTML entities, issue #347 - .replace(/&nbsp;/g, '\u00A0') // no-break space - .replace(/&shy;/g, '\u00AD') // soft hyphen - - // IE specific - .replace(/<IMG /g, '<image ') - .replace(/height=([^" ]+)/g, 'height="$1"') - .replace(/width=([^" ]+)/g, 'width="$1"') - .replace(/hc-svg-href="([^"]+)">/g, 'xlink:href="$1"/>') - .replace(/id=([^" >]+)/g, 'id="$1"') - .replace(/class=([^" >]+)/g, 'class="$1"') - .replace(/ transform /g, ' ') - .replace(/:(path|rect)/g, '$1') - .replace(/style="([^"]+)"/g, function (s) { - return s.toLowerCase(); - }); + svg = this.sanitizeSVG(svg); // IE9 beta bugs with innerHTML. Test again with final IE9. svg = svg.replace(/(url\(#highcharts-[0-9]+)&quot;/g, '$1') .replace(/&quot;/g, "'");