src/components/Graph.tsx   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 62
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 50
mnd 1
bc 1
fnc 0
dl 0
loc 62
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import * as React from 'react';
2
import { useEffect, useRef } from 'react';
3
import { css, cx } from 'emotion';
4
import { draw } from '../utils/Draw';
5
import { Network } from './types';
6
import { ElementIds } from '../utils/AppConsts';
7
import { selectById } from '../utils/helpers/Selectors';
8
9
export interface GraphProps {
10
    network: Network;
11
}
12
13
export const Graph = React.memo<GraphProps>(({ network: { nodes, links, detailsNodes } }) => {
14
    const dependencyGraphDiv = useRef<HTMLDivElement>(null);
15
16
    useEffect(() => {
17
        selectById(ElementIds.OVERVIEW_CONTAINER_DIV)
18
            .selectAll('*')
19
            .remove();
20
        selectById(ElementIds.DETAILS_CONTAINER_DIV)
21
            .selectAll('*')
22
            .remove();
23
        if (dependencyGraphDiv.current !== null && nodes.length > 0) {
24
            draw({ nodes, links, detailsNodes }, dependencyGraphDiv.current);
25
        }
26
    }, [nodes, links, detailsNodes]);
27
28
    return (
29
        <div ref={dependencyGraphDiv} className={graphContainerCls}>
30
            <div id={ElementIds.OVERVIEW_CONTAINER_DIV} className={graphOverviewCls} />
31
            <div id={ElementIds.DETAILS_CONTAINER_DIV} className={cx(graphOverviewCls, graphDetailsCls)} />
32
        </div>
33
    );
34
});
35
36
const graphContainerCls = css({
37
    label: 'graph-container',
38
    position: 'relative',
39
    display: 'flex',
40
    flexDirection: 'column',
41
    overflow: 'hidden',
42
    height: '100vh',
43
    '& > svg': {
44
        flex: 1,
45
        overflow: 'hidden',
46
    },
47
});
48
49
const graphOverviewCls = css({
50
    label: 'graph-overview-container',
51
    position: 'absolute',
52
    top: 0,
53
    left: 0,
54
    right: 0,
55
    bottom: 0,
56
});
57
58
const graphDetailsCls = css({
59
    label: 'graph-details-container',
60
    zIndex: 6,
61
});
62