|
@ -2,34 +2,48 @@ import React, {useEffect} from "react"; |
|
|
import h337 from "heatmap.js"; |
|
|
import h337 from "heatmap.js"; |
|
|
import { MOUSE_MODE, HEATMAP_MAX } from "../../core/Constants"; |
|
|
import { MOUSE_MODE, HEATMAP_MAX } from "../../core/Constants"; |
|
|
|
|
|
|
|
|
|
|
|
var stopInput = false; |
|
|
|
|
|
|
|
|
var heatmapInstance = h337.create({ |
|
|
var heatmapInstance = h337.create({ |
|
|
container: document.body, |
|
|
container: document.body, |
|
|
radius: 20 |
|
|
radius: 20 |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const visualiseMouseData = ((mouseData) => { |
|
|
|
|
|
mouseData.max = mouseData.data.length + 1; |
|
|
|
|
|
heatmapInstance.setData(mouseData); |
|
|
|
|
|
document.getElementsByTagName("canvas")[0].style.opacity = 1; |
|
|
|
|
|
stopInput = true; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
export function StudySite(props) { |
|
|
export function StudySite(props) { |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
|
|
|
window.visualiseMouseData = visualiseMouseData; |
|
|
heatmapInstance.setDataMax(HEATMAP_MAX); |
|
|
heatmapInstance.setDataMax(HEATMAP_MAX); |
|
|
var addData; |
|
|
var addData; |
|
|
|
|
|
|
|
|
if(MOUSE_MODE) { |
|
|
if(MOUSE_MODE) { |
|
|
const mouseDataFunc = function(ev) { |
|
|
const mouseDataFunc = function(ev) { |
|
|
|
|
|
if(!stopInput) { |
|
|
heatmapInstance.addData({ |
|
|
heatmapInstance.addData({ |
|
|
x: ev.layerX, |
|
|
x: ev.layerX, |
|
|
y: ev.layerY, |
|
|
y: ev.layerY, |
|
|
value: 1, |
|
|
value: 1, |
|
|
}); |
|
|
}); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
addData = mouseDataFunc; |
|
|
addData = mouseDataFunc; |
|
|
} else { |
|
|
} else { |
|
|
const touchDataFunc = function(ev) { |
|
|
const touchDataFunc = function(ev) { |
|
|
|
|
|
if(!stopInput) { |
|
|
heatmapInstance.addData({ |
|
|
heatmapInstance.addData({ |
|
|
x: ev.layerX, |
|
|
x: ev.layerX, |
|
|
y: ev.layerY, |
|
|
y: ev.layerY, |
|
|
value: 1 |
|
|
value: 1 |
|
|
}); |
|
|
}); |
|
|
|
|
|
} |
|
|
}; |
|
|
}; |
|
|
addData = touchDataFunc; |
|
|
addData = touchDataFunc; |
|
|
} |
|
|
} |
|
@ -41,6 +55,10 @@ export function StudySite(props) { |
|
|
document.body.addEventListener("touchstart", addData, false); |
|
|
document.body.addEventListener("touchstart", addData, false); |
|
|
document.body.addEventListener("touchend", addData, false); |
|
|
document.body.addEventListener("touchend", addData, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return () => { |
|
|
|
|
|
delete window.visualiseMouseData; |
|
|
|
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return (<>{props.children}</>); |
|
|
return (<>{props.children}</>); |
|
|