forked from bradvatne/reaviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHiveNode.tsx
executable file
·55 lines (51 loc) · 1.32 KB
/
HiveNode.tsx
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
import React from 'react';
import classNames from 'classnames';
import { Node, degrees } from '../utils';
import * as css from './HiveNode.module.scss';
interface HiveNodeProps {
angle: (...args: any[]) => any;
radius: (...args: any[]) => any;
color: (...args: any[]) => any;
node: Node;
active?: boolean;
disabled?: boolean;
onClick: (...args: any[]) => any;
onMouseOver: (...args: any[]) => any;
onMouseOut: (...args: any[]) => any;
}
export class HiveNode extends React.Component<HiveNodeProps, {}> {
render() {
const {
angle,
radius,
node,
color,
onClick,
onMouseOver,
onMouseOut,
active,
disabled
} = this.props;
// If the size exists on the node, use it to specify the node size.
// Otherwise, calculate a relative size using the node count.
let size = node.size;
if (size === undefined) {
size = node.count || 0;
}
return (
<circle
className={classNames(css.node, {
[css.inactive]: !active
})}
transform={`rotate(${degrees(angle(node.x))})`}
cx={radius(node.y)}
r={size}
style={{ cursor: disabled ? 'initial' : 'cursor' }}
fill={color(node.x)}
onClick={onClick}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
/>
);
}
}