Skip to content

Commit

Permalink
Switch svg saving libraries to allow saving png with background
Browse files Browse the repository at this point in the history
Signed-off-by: Abeshouse, Adam A./Sloan Kettering Institute <[email protected]>
  • Loading branch information
Abeshouse, Adam A./Sloan Kettering Institute committed Aug 14, 2018
1 parent a24962e commit a5f31b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
21 changes: 13 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
"route-parser": "0.0.5",
"sass-loader": "^4.1.1",
"sass-resources-loader": "^1.3.1",
"save-svg-as-png": "^1.4.6",
"script-loader": "^0.7.0",
"seamless-immutable": "^7.0.1",
"seedrandom": "^2.4.3",
Expand Down
7 changes: 3 additions & 4 deletions src/shared/components/downloadControls/DownloadControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from "react";
import SvgSaver from 'svgsaver';
import svgToPdfDownload from "shared/lib/svgToPdfDownload";
import FadeInteraction from "../fadeInteraction/FadeInteraction";
import {observer} from "mobx-react";
Expand All @@ -9,6 +8,7 @@ import fileDownload from 'react-file-download';
import DefaultTooltip from "../defaultTooltip/DefaultTooltip";
import classnames from "classnames";
import styles from "./DownloadControls.module.scss";
import {saveSvg, saveSvgAsPng} from "save-svg-as-png";

type ButtonSpec = { key:string, content:JSX.Element, onClick:()=>void, disabled?: boolean };

Expand Down Expand Up @@ -53,15 +53,14 @@ function makeMenuItem(spec:ButtonSpec) {

@observer
export default class DownloadControls extends React.Component<IDownloadControlsProps, {}> {
private svgsaver = new SvgSaver();
@observable private collapsed = true;

@autobind
private downloadSvg() {
if (this.props.getSvg) {
const svg = this.props.getSvg();
if (svg) {
this.svgsaver.asSvg(svg, `${this.props.filename}.svg`);
saveSvg(svg, `${this.props.filename}.svg`);
}
}
}
Expand All @@ -71,7 +70,7 @@ export default class DownloadControls extends React.Component<IDownloadControlsP
if (this.props.getSvg) {
const svg = this.props.getSvg();
if (svg) {
this.svgsaver.asPng(svg, `${this.props.filename}.png`);
saveSvgAsPng(svg, `${this.props.filename}.png`, {backgroundColor:"#ffffff"});
}
}
}
Expand Down
1 change: 1 addition & 0 deletions typings/missing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare module '*.scss';
declare module '*.json';

// these packages are missing typings
declare module 'save-svg-as-png'
declare module 'react-file-download';
declare module 'react-select-checked';
declare module 'react-zeroclipboard';
Expand Down

0 comments on commit a5f31b4

Please sign in to comment.