Skip to content

Commit

Permalink
remove font reset in index; set save-svg-as-png to fork; remove local…
Browse files Browse the repository at this point in the history
… svg code
  • Loading branch information
nsonnad committed Mar 18, 2016
1 parent a55ae24 commit 764b226
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
54 changes: 16 additions & 38 deletions src/js/components/ChartExport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<![CDATA["+this.styleStringify(document.styleSheets)+"]]>\n");
}
else {
d3.selectAll("." + this.props.svgWrapperClassName + " style").remove();
}
},

componentDidMount: function() {
var enableSvgExport;
var chartNode = null;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
});
},

Expand All @@ -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() {
Expand Down
5 changes: 0 additions & 5 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
});
});

0 comments on commit 764b226

Please sign in to comment.