aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/graph/GraphArea.tsx
blob: 2bf40d1ad4d05cd274e181a2a6dcc8d18e5d2782 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */

import Box from '@mui/material/Box';
import { useTheme } from '@mui/material/styles';
import { observer } from 'mobx-react-lite';
import { useState } from 'react';
import { useResizeDetector } from 'react-resize-detector';

import DotGraphVisualizer from './DotGraphVisualizer';
import ExportButton from './ExportButton';
import type GraphStore from './GraphStore';
import VisibilityPanel from './VisibilityPanel';
import ZoomCanvas from './ZoomCanvas';

function GraphArea({ graph }: { graph: GraphStore }): JSX.Element {
  const { breakpoints } = useTheme();
  const { ref, width, height } = useResizeDetector({
    refreshMode: 'debounce',
  });
  const [svgContainer, setSvgContainer] = useState<HTMLElement | undefined>();

  const breakpoint = breakpoints.values.sm;
  const dialog =
    width === undefined ||
    height === undefined ||
    width < breakpoint ||
    height < breakpoint;

  return (
    <Box
      width="100%"
      height="100%"
      overflow="hidden"
      position="relative"
      ref={ref}
    >
      <ZoomCanvas>
        {(fitZoom) => (
          <DotGraphVisualizer
            graph={graph}
            fitZoom={fitZoom}
            setSvgContainer={setSvgContainer}
          />
        )}
      </ZoomCanvas>
      <VisibilityPanel graph={graph} dialog={dialog} />
      <ExportButton svgContainer={svgContainer} />
    </Box>
  );
}

export default observer(GraphArea);