@@ -3,7 +3,8 @@ import { getRelativeCursor, isCursorInRect, useDimensions, useTheme, Container }
3
3
import { renderAxesToCanvas , renderGridLinesToCanvas } from '@nivo/axes'
4
4
import { useTooltip } from '@nivo/tooltip'
5
5
import { renderContinuousColorLegendToCanvas } from '@nivo/legends'
6
- import { useHeatMap } from './hooks'
6
+ import { renderAnnotationsToCanvas , useComputedAnnotations } from '@nivo/annotations'
7
+ import { useHeatMap , useCellAnnotations } from './hooks'
7
8
import { renderRect , renderCircle } from './canvas'
8
9
import { canvasDefaultProps } from './defaults'
9
10
import {
@@ -39,7 +40,7 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
39
40
opacity = canvasDefaultProps . opacity ,
40
41
activeOpacity = canvasDefaultProps . activeOpacity ,
41
42
inactiveOpacity = canvasDefaultProps . inactiveOpacity ,
42
- // borderWidth = canvasDefaultProps.borderWidth,
43
+ borderWidth = canvasDefaultProps . borderWidth ,
43
44
borderColor = canvasDefaultProps . borderColor as HeatMapCommonProps < Datum > [ 'borderColor' ] ,
44
45
enableGridX = canvasDefaultProps . enableGridX ,
45
46
enableGridY = canvasDefaultProps . enableGridY ,
@@ -53,7 +54,7 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
53
54
colors = canvasDefaultProps . colors as HeatMapCommonProps < Datum > [ 'colors' ] ,
54
55
emptyColor = canvasDefaultProps . emptyColor ,
55
56
legends = canvasDefaultProps . legends ,
56
- // annotations = canvasDefaultProps.annotations as HeatMapCommonProps<Datum>['annotations'],
57
+ annotations = canvasDefaultProps . annotations as HeatMapCommonProps < Datum > [ 'annotations' ] ,
57
58
isInteractive = canvasDefaultProps . isInteractive ,
58
59
// onMouseEnter,
59
60
// onMouseMove,
@@ -98,7 +99,10 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
98
99
hoverTarget,
99
100
} )
100
101
101
- const theme = useTheme ( )
102
+ const boundAnnotations = useCellAnnotations ( cells , annotations )
103
+ const computedAnnotations = useComputedAnnotations ( {
104
+ annotations : boundAnnotations ,
105
+ } )
102
106
103
107
let renderCell : CellCanvasRenderer < Datum >
104
108
if ( typeof _renderCell === 'function' ) {
@@ -109,6 +113,8 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
109
113
renderCell = renderRect
110
114
}
111
115
116
+ const theme = useTheme ( )
117
+
112
118
useEffect ( ( ) => {
113
119
if ( canvasEl . current === null ) return
114
120
@@ -162,7 +168,7 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
162
168
ctx . textBaseline = 'middle'
163
169
164
170
cells . forEach ( cell => {
165
- renderCell ( ctx , { cell, enableLabels, theme } )
171
+ renderCell ( ctx , { cell, borderWidth , enableLabels, theme } )
166
172
} )
167
173
} else if ( layer === 'legends' && colorScale !== null ) {
168
174
legends . forEach ( legend => {
@@ -174,17 +180,23 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
174
180
theme,
175
181
} )
176
182
} )
183
+ } else if ( layer === 'annotations' ) {
184
+ renderAnnotationsToCanvas ( ctx , {
185
+ annotations : computedAnnotations ,
186
+ theme,
187
+ } )
177
188
}
178
189
} )
179
190
} , [
180
191
canvasEl ,
181
- layers ,
182
- cells ,
192
+ pixelRatio ,
183
193
outerWidth ,
184
194
outerHeight ,
185
195
innerWidth ,
186
196
innerHeight ,
187
197
margin ,
198
+ layers ,
199
+ cells ,
188
200
renderCell ,
189
201
enableGridX ,
190
202
enableGridY ,
@@ -195,10 +207,11 @@ const InnerHeatMapCanvas = <Datum extends HeatMapDatum, ExtraProps extends objec
195
207
xScale ,
196
208
yScale ,
197
209
theme ,
210
+ borderWidth ,
198
211
enableLabels ,
199
212
colorScale ,
200
213
legends ,
201
- pixelRatio ,
214
+ computedAnnotations ,
202
215
] )
203
216
204
217
const { showTooltipFromEvent, hideTooltip } = useTooltip ( )
0 commit comments