# All files / src/components Link.jsx

100% Statements 7/7
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80

    3x

    3x

    3x

    3x

    7x

    3x
    3x

     import { css, StyleSheet } from 'aphrodite';
    import { Bar } from '@vx/shape';
    import React from 'react';
    import PropTypes from 'prop-types';

    import { nodeShape } from '../propShapes';

    const DEFAULT_LINK_COLOR = '#ddd';

    const styles = StyleSheet.create({
      group: {
        ':hover': {
          opacity: 0.4,
        },
      },
    });

    const propTypes = {
      source: nodeShape.isRequired,
      target: nodeShape.isRequired,
      x: PropTypes.number.isRequired,
      y: PropTypes.number.isRequired,
      width: PropTypes.number.isRequired,
      height: PropTypes.number.isRequired,
      fill: PropTypes.string,
      onMouseOver: PropTypes.func,
      onMouseOut: PropTypes.func,
      onClick: PropTypes.func,
    };

    const defaultProps = {
      fill: DEFAULT_LINK_COLOR,
      onMouseOver: null,
      onMouseOut: null,
      onClick: null,
    };

    function Link({
      source,
      target,
      x,
      y,
      width,
      height,
      fill,
      onClick,
      onMouseOver,
      onMouseOut,
    }) {
      return (
        <g
          className={css(styles.group)}
          onClick={onClick}
          onMouseOver={onMouseOver}
          onMouseOut={onMouseOut}
          data-source={source.id}
          data-target={target.id}
        >
          <Bar
            x={x}
            y={y}
            width={Math.max(1, width)}
            height={Math.max(1, height)}
            fill={fill}
            fillOpacity={0.9}
            rx={2}
            ry={2}
            stroke="#fff"
            strokeWidth={2}
            vectorEffect="non-scaling-stroke"
          />
        </g>
      );
    }

    Link.propTypes = propTypes;
    Link.defaultProps = defaultProps;

    export default Link;