From 764b22690c1aad0090234e26062bf36ab193fa22 Mon Sep 17 00:00:00 2001 From: Nikhil S Date: Fri, 18 Mar 2016 14:58:27 -0400 Subject: [PATCH] remove font reset in index; set save-svg-as-png to fork; remove local svg code --- package.json | 2 +- src/js/components/ChartExport.jsx | 54 +++++++++---------------------- src/js/index.js | 5 --- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 95e01aa5..e0bd808f 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "react-addons-shallow-compare": "^0.14.7", "react-addons-update": "^0.14.7", "react-dom": "^0.14.7", - "save-svg-as-png": "^1.0.2", + "save-svg-as-png": "git://github.com/nsonnad/saveSvgAsPng.git#clean-svg-fonts", "sizeof": "^1.0.0", "sugar-date": "^1.5.1" }, diff --git a/src/js/components/ChartExport.jsx b/src/js/components/ChartExport.jsx index 89efb7c3..56ebdb88 100644 --- a/src/js/components/ChartExport.jsx +++ b/src/js/components/ChartExport.jsx @@ -35,18 +35,6 @@ var ChartExport = React.createClass({ }; }, - embedCSS: function(type) { - if (type == "add") { - d3.selectAll("." + this.props.svgWrapperClassName) - .append("style") - .attr("type","text/css") - .html("\n\n"); - } - else { - d3.selectAll("." + this.props.svgWrapperClassName + " style").remove(); - } - }, - componentDidMount: function() { var enableSvgExport; var chartNode = null; @@ -92,16 +80,6 @@ var ChartExport = React.createClass({ return chart[0][0]; }, - _cleanRuleOfExtraFonts: function(pd) { - // Adobe Illustrator freaks out with fallback fonts, remove fallback fonts - if(pd.prop == "font-family") { - pd.dec = pd.dec.split(",")[0]; - } - - return {"prop":pd.prop,"dec":pd.dec}; - }, - - _makeFilename: function(extension) { var filename = this.props.data.reduce(function(a, b, i) { if (a.length === 0) { @@ -121,21 +99,26 @@ var ChartExport = React.createClass({ saveSvgAsPng.saveSvgAsPng(this.state.chartNode, filename, { scale: 2.0 }); }, + _autoClickDownload: function(filename, href) { + var a = document.createElement('a'); + a.download = filename; + a.href = href; + document.body.appendChild(a); + a.addEventListener("click", function(e) { + a.parentNode.removeChild(a); + }); + a.click(); + }, + downloadSVG: function() { var filename = this._makeFilename("svg"); var chart = this._addIDsForIllustrator(this.state.chartNode); + var autoClickDownload = this._autoClickDownload; saveSvgAsPng.svgAsDataUri(chart, { cleanFontDefs: true, fontFamilyRemap: { "Khula-Light": "Khula Light"} }, function(uri) { - var a = document.createElement('a'); - a.download = filename; - a.href = uri; - document.body.appendChild(a); - a.addEventListener("click", function(e) { - a.parentNode.removeChild(a); - }); - a.click(); + autoClickDownload(filename, uri); }); }, @@ -146,14 +129,9 @@ var ChartExport = React.createClass({ metadata: this.props.model.metadata }, null, "\t") - var a = document.createElement('a'); - a.download = this._makeFilename(".json") - a.href = "data:text/json;charset=utf-8," + encodeURIComponent(json_string); - document.body.appendChild(a); - a.addEventListener("click", function(e) { - a.parentNode.removeChild(a); - }); - a.click(); + var filename = this._makeFilename("json"); + var href = "data:text/json;charset=utf-8," + encodeURIComponent(json_string); + this._autoClickDownload(filename, href); }, setAdvancedOptionState: function() { diff --git a/src/js/index.js b/src/js/index.js index f669f95e..51a1e2f7 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -21,9 +21,4 @@ document.addEventListener("DOMContentLoaded", function() { />, container ); - //append the current timestamp to the end of the stylesheets on load so that the fonts will load - Array.prototype.slice.call(document.querySelectorAll('link[rel="stylesheet"]')) - .forEach(function(el){ - el.setAttribute("href",el.getAttribute("href").split("?")[0] + "?t=" + (new Date().getTime())); - }); });