/
TreeMap.js
112 lines (105 loc) · 2.63 KB
/
TreeMap.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import React from 'react'
import { SvgWrapper, withContainer, useDimensions, bindDefs } from '@nivo/core'
import { TreeMapDefaultProps, TreeMapPropTypes } from './props'
import { useTreeMap } from './hooks'
import TreeMapNodes from './TreeMapNodes'
const TreeMap = ({
data,
identity,
value,
tile,
nodeComponent,
valueFormat,
innerPadding,
outerPadding,
leavesOnly,
width,
height,
margin: partialMargin,
colors,
colorBy,
nodeOpacity,
borderWidth,
borderColor,
defs,
fill,
enableLabel,
label,
labelTextColor,
orientLabel,
labelSkipSize,
enableParentLabel,
parentLabel,
parentLabelSize,
parentLabelPosition,
parentLabelPadding,
parentLabelTextColor,
isInteractive,
onMouseEnter,
onMouseMove,
onMouseLeave,
onClick,
tooltip,
}) => {
const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions(
width,
height,
partialMargin
)
const { nodes } = useTreeMap({
data,
identity,
value,
valueFormat,
leavesOnly,
width: innerWidth,
height: innerHeight,
tile,
innerPadding,
outerPadding,
colors,
colorBy,
nodeOpacity,
borderColor,
label,
labelTextColor,
orientLabel,
enableParentLabel,
parentLabel,
parentLabelSize,
parentLabelPosition,
parentLabelPadding,
parentLabelTextColor,
})
const boundDefs = bindDefs(defs, nodes, fill)
return (
<SvgWrapper width={outerWidth} height={outerHeight} margin={margin} defs={boundDefs}>
<TreeMapNodes
nodes={nodes}
nodeComponent={nodeComponent}
borderWidth={borderWidth}
enableLabel={enableLabel}
labelSkipSize={labelSkipSize}
enableParentLabel={enableParentLabel}
isInteractive={isInteractive}
onMouseEnter={onMouseEnter}
onMouseMove={onMouseMove}
onMouseLeave={onMouseLeave}
onClick={onClick}
tooltip={tooltip}
/>
</SvgWrapper>
)
}
TreeMap.propTypes = TreeMapPropTypes
const WrappedTreeMap = withContainer(TreeMap)
WrappedTreeMap.defaultProps = TreeMapDefaultProps
export default WrappedTreeMap