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

Make SVGRender a global instance #324

Merged
merged 1 commit into from
May 19, 2023
Merged
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
7 changes: 4 additions & 3 deletions src/components/GraphViewport.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component } from 'react';

import { Viewport } from './../graph/';
import { SVGRender, Viewport } from './../graph/';
import LoadingAnimation from './utils/LoadingAnimation';

const svgRenderer = new SVGRender();

interface GraphViewportProps {
svgRenderer: any;
typeGraph: any;
displayOptions: any;

Expand Down Expand Up @@ -83,7 +84,7 @@ export default class GraphViewport extends Component<GraphViewportProps> {
this._currentTypeGraph = typeGraph;
this._currentDisplayOptions = displayOptions;

const { svgRenderer, onSelectNode, onSelectEdge } = this.props;
const { onSelectNode, onSelectEdge } = this.props;
svgRenderer
.renderSvg(typeGraph, displayOptions)
.then((svg) => {
Expand Down
6 changes: 1 addition & 5 deletions src/components/Voyager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useState,
} from 'react';

import { getTypeGraph, SVGRender } from '../graph/';
import { getTypeGraph } from '../graph/';
import { extractTypeId, getSchema } from '../introspection';
import DocExplorer from './doc-explorer/DocExplorer';
import GraphViewport from './GraphViewport';
Expand Down Expand Up @@ -106,9 +106,6 @@ export default function Voyager(props: VoyagerProps) {
const viewportRef = useRef(null);
useEffect(() => viewportRef.current?.resize(), [hideDocs]);

// TODO: move into GraphViewport
const svgRenderer = useMemo(() => new SVGRender(), []);

return (
<ThemeProvider theme={theme}>
<div className="graphql-voyager">
Expand Down Expand Up @@ -190,7 +187,6 @@ export default function Voyager(props: VoyagerProps) {
function renderGraphViewport() {
return (
<GraphViewport
svgRenderer={svgRenderer}
typeGraph={typeGraph}
displayOptions={displayOptions}
selectedTypeID={selected.typeID}
Expand Down