/
rect.js
60 lines (59 loc) 路 1.41 KB
/
rect.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
import React from 'react';
import cx from 'classnames';
import { Group } from '@vx/group';
import additionalProps from '../util/additionalProps';
export default function HeatmapRect({
className,
data,
binWidth,
binHeight,
x = 0,
gap = 1,
step = 0,
xScale,
yScale,
colorScale,
opacityScale = d => 1,
bin = d => d.bin,
bins = d => d.bins,
count = d => d.count,
...restProps
}) {
const width = binWidth - gap;
const height = binHeight - gap;
return (
<Group>
{data.map((d, i) => {
return (
<Group
key={`heatmap-${i}`}
className='vx-heatmap-column'
left={xScale(bin(d))}
>
{bins(d).map((b, j) => {
return (
<rect
key={`heatmap-tile-rect-${j}`}
className={cx('vx-heatmap-rect', className)}
fill={colorScale(count(b))}
width={width}
height={height}
x={x}
y={yScale(bin(b) + step) + gap}
fillOpacity={opacityScale(count(b))}
{...additionalProps(restProps, {
bin: b,
index: j,
datum: d,
datumIndex: i,
data
})}
/>
);
})}
</Group>
);
})}
</Group>
);
}