|
@ -0,0 +1,51 @@ |
|
|
|
|
|
import React, {useEffect} from "react"; |
|
|
|
|
|
import h337 from "heatmap.js"; |
|
|
|
|
|
import { MOUSE_MODE, HEATMAP_MAX } from "../../core/Constants"; |
|
|
|
|
|
|
|
|
|
|
|
var heatmapInstance = h337.create({ |
|
|
|
|
|
container: document.body, |
|
|
|
|
|
radius: 20 |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export function StudySite(props) { |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
heatmapInstance.setDataMax(HEATMAP_MAX); |
|
|
|
|
|
var addData; |
|
|
|
|
|
|
|
|
|
|
|
if(MOUSE_MODE) { |
|
|
|
|
|
const mouseDataFunc = function(ev) { |
|
|
|
|
|
heatmapInstance.addData({ |
|
|
|
|
|
x: ev.layerX, |
|
|
|
|
|
y: ev.layerY, |
|
|
|
|
|
value: 1 |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
addData = mouseDataFunc; |
|
|
|
|
|
} else { |
|
|
|
|
|
const touchDataFunc = function(ev) { |
|
|
|
|
|
heatmapInstance.addData({ |
|
|
|
|
|
x: ev.layerX, |
|
|
|
|
|
y: ev.layerY, |
|
|
|
|
|
value: 1 |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
addData = touchDataFunc; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(MOUSE_MODE) { |
|
|
|
|
|
document.body.addEventListener("mousemove", addData, false); |
|
|
|
|
|
} else { |
|
|
|
|
|
document.body.addEventListener("touchmove", addData, false); |
|
|
|
|
|
document.body.addEventListener("touchstart", addData, false); |
|
|
|
|
|
document.body.addEventListener("touchend", addData, false); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return (<>{props.children}</>); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function getHeatmapData() { |
|
|
|
|
|
return heatmapInstance.getData(); |
|
|
|
|
|
} |