Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Implement simple saving SVG schemes #147

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"classnames": "^2.2.6",
"clipboard": "^2.0.4",
"commonmark": "^0.29.0",
"file-saver": "^2.0.2",
"lodash": "^4.17.10",
"prop-types": "^15.7.2",
"svg-pan-zoom": "^3.6.0",
Expand Down
12 changes: 10 additions & 2 deletions src/components/Voyager.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
box-sizing: border-box;
position: relative;
z-index: 10;

& .contents__btn-save {
padding: 0px 15px;
margin-top: 5px;
display: flex;
flex-direction: column;
}
}

& > .viewport {
Expand All @@ -34,7 +41,8 @@
}

@media (--small-viewport) {
& > .doc-panel, & > .viewport {
& > .doc-panel,
& > .viewport {
height: 50%;
width: 100%;
max-width: none;
Expand Down Expand Up @@ -66,4 +74,4 @@
left: 10px;
}
}
}
}
28 changes: 28 additions & 0 deletions src/components/Voyager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import * as PropTypes from 'prop-types';
import { theme } from './MUITheme';
import { MuiThemeProvider } from '@material-ui/core/styles';

import Button from '@material-ui/core/Button';
import FileSaver from 'file-saver';

import GraphViewport from './GraphViewport';
import DocExplorer from './doc-explorer/DocExplorer';
import PoweredBy from './utils/PoweredBy';
import Settings from './settings/Settings';

import './Voyager.css';
import './viewport.css';
import styles from '!!postcss-loader!./viewport.css';

type IntrospectionProvider = (query: string) => Promise<any>;

Expand Down Expand Up @@ -185,6 +189,16 @@ export default class Voyager extends React.Component<VoyagerProps> {
<div className="doc-panel">
<div className="contents">
{panelHeader}
<div className="contents__btn-save">
<Button
color="primary"
style={{ color: 'white' }}
variant="contained"
onClick={this.saveToSVG}
>
Save to SVG
</Button>
</div>
<DocExplorer
typeGraph={typeGraph}
selectedTypeID={selectedTypeID}
Expand All @@ -199,6 +213,20 @@ export default class Voyager extends React.Component<VoyagerProps> {
);
}

saveToSVG = () => {
const { displayOptions, typeGraph } = this.state;

this.svgRenderer.renderSvg(typeGraph, displayOptions).then(data => {
let svgTag = document.createElement('div');
svgTag.innerHTML = data;
let styleTag = document.createElement('style');
styleTag.innerHTML = styles.toString();
svgTag.firstElementChild.insertBefore(styleTag, svgTag.firstElementChild.firstElementChild);

FileSaver.saveAs(new Blob([svgTag.innerHTML], { type: 'image/svg+xml' }), 'schema.svg');
});
};

renderSettings() {
const { schema, displayOptions } = this.state;

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,11 @@ [email protected]:
loader-utils "^1.0.2"
schema-utils "^1.0.0"

file-saver@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.2.tgz#06d6e728a9ea2df2cce2f8d9e84dfcdc338ec17a"
integrity sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw==

fill-range@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7"
Expand Down