Skip to content

Commit

Permalink
Make SVGRender a global instance (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored May 19, 2023
1 parent 2f7f5be commit 3cd5508
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
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

0 comments on commit 3cd5508

Please sign in to comment.