@@ -285,17 +285,21 @@ export default {
285285 */
286286 const canvasNode = canvas .node ();
287287
288+ const getDataFromMouse = (mouseX , mouseY ) => {
289+ // Get the corresponding pixel color on the hidden canvas
290+ const col = contextHidden .getImageData (mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data ;
291+ const colString = " rgb(" + col[0 ] + " ," + col[1 ] + " ," + col[2 ] + " )" ;
292+ // Look up the node in our map
293+ return colToNode[colString];
294+ };
295+
288296 const debouncedTooltipDestroy = debounce (vm .tooltipDestroy , TOOLTIP_DEBOUNCE );
289297 canvas .on (" mousemove" , () => {
290298 const mouse = d3_mouse (canvasNode);
291299 const mouseX = mouse[0 ];
292300 const mouseY = mouse[1 ];
293301
294- // Get the corresponding pixel color on the hidden canvas
295- const col = contextHidden .getImageData (mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data ;
296- const colString = " rgb(" + col[0 ] + " ," + col[1 ] + " ," + col[2 ] + " )" ;
297- // Look up the node in our map
298- const node = colToNode[colString];
302+ const node = getDataFromMouse (mouseX, mouseY);
299303
300304 if (node) {
301305 vm .tooltip (mouseX, mouseY, node[" x" ], node[" y" ], node[" c" ]);
@@ -311,11 +315,7 @@ export default {
311315 const mouseX = mouse[0 ];
312316 const mouseY = mouse[1 ];
313317
314- // Get the corresponding pixel color on the hidden canvas
315- const col = contextHidden .getImageData (mouseX * ratio, mouseY * ratio, scaledWidth, scaledHeight).data ;
316- const colString = " rgb(" + col[0 ] + " ," + col[1 ] + " ," + col[2 ] + " )" ;
317- // Look up the node in our map
318- const node = colToNode[colString];
318+ const node = getDataFromMouse (mouseX, mouseY);
319319
320320 if (node) {
321321 vm .clickHandler (node[" x" ], node[" y" ], node[" c" ]);
0 commit comments