Skip to content

Commit

Permalink
Merge pull request #1382 from adamabeshouse/empty-bg-svg
Browse files Browse the repository at this point in the history
Switch svg saving libraries to allow saving png with background
  • Loading branch information
adamabeshouse authored Aug 15, 2018
2 parents 64b4582 + 92effb5 commit a7b479b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 44 deletions.
35 changes: 13 additions & 22 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@
"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",
"source-map-loader": "^0.1.6",
"style-loader": "^0.13.1",
"superagent": "^3.4.0",
"svgsaver": "0.9.0",
"swagger-client": "^2.1.32",
"ts-loader": "^2.0.0",
"typescript": "^2.7.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Slider from 'react-rangeslider';
import {FormGroup, ControlLabel, FormControl} from 'react-bootstrap';
import {If, Then, Else} from 'react-if';
import classnames from 'classnames';
import SvgSaver from 'svgsaver';

import 'react-select/dist/react-select.css';
import 'react-rangeslider/lib/index.css';
Expand Down
1 change: 0 additions & 1 deletion src/pages/resultsView/coExpression/CoExpressionPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {action, computed, observable} from "mobx";
import {observer, Observer} from "mobx-react";
import {MolecularProfile} from "../../../shared/api/generated/CBioPortalAPI";
import {AlterationTypeConstants} from "../ResultsViewPageStore";
import SvgSaver from "svgsaver";
import svgToPdfDownload from "shared/lib/svgToPdfDownload";
import {getSampleViewUrl} from "../../../shared/api/urls";
import "./styles.scss";
Expand Down
2 changes: 0 additions & 2 deletions src/pages/resultsView/survival/SurvivalChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
VictoryChart, VictoryContainer, VictoryLine, VictoryTooltip,
VictoryAxis, VictoryLegend, VictoryLabel, VictoryScatter, VictoryTheme, VictoryZoomContainer
} from 'victory';
import SvgSaver from 'svgsaver';
import {
getEstimates, getMedian, getLineData, getScatterData, getScatterDataWithOpacity, getStats, calculateLogRank,
getDownloadContent, convertScatterDataToDownloadData, downSampling, GroupedScatterData, filteringScatterData
Expand Down Expand Up @@ -59,7 +58,6 @@ export default class SurvivalChart extends React.Component<ISurvivalChartProps,
private alteredLegendText = 'Cases with Alteration(s) in Query Gene(s)';
private unalteredLegendText = 'Cases without Alteration(s) in Query Gene(s)';
private svgContainer: any;
private svgsaver = new SvgSaver();
private styleOptsDefaultProps:any = {
width: 900,
height: 500,
Expand Down
13 changes: 0 additions & 13 deletions src/shared/components/ChartContainer/ChartContainer.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 autobind from "autobind-decorator";
import DownloadControls from "../downloadControls/DownloadControls";

Expand All @@ -10,18 +9,6 @@ interface IChartContainer {

export default class ChartContainer extends React.Component<IChartContainer, {}> {

@autobind
private downloadSvg() {
this.svgsaver.asSvg(this.props.getSVGElement!(), this.props.exportFileName + '.svg');
}

@autobind
private downloadPng() {
this.svgsaver.asPng(this.props.getSVGElement!(), this.props.exportFileName + '.png');
}

private svgsaver = new SvgSaver();

render(){

return (
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 a7b479b

Please sign in to comment.