@qctrl/visualizer
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -357,7 +357,16 @@ "use strict"; | ||
// set mouse coordinates based on current Bloch Sphere div | ||
_this3.setMouseCoords(e); | ||
var clientX = e.clientX, | ||
clientY = e.clientY; | ||
clientY = e.clientY, | ||
currentTarget = e.currentTarget; | ||
var _currentTarget$getBou = currentTarget.getBoundingClientRect(), | ||
left = _currentTarget$getBou.left, | ||
right = _currentTarget$getBou.right, | ||
top = _currentTarget$getBou.top, | ||
bottom = _currentTarget$getBou.bottom, | ||
width = _currentTarget$getBou.width, | ||
height = _currentTarget$getBou.height; | ||
_this3.setMouseCoords(clientX, clientY, currentTarget, left, right, top, bottom); | ||
var element = _this3.sceneManager.elements.find(function (element) { | ||
@@ -377,2 +386,7 @@ return element.div.id === _this3.mouse.targetId; | ||
var name = label.object.name; | ||
var _this3$getScreenPosit = _this3.getScreenPositionOfObject(label.object, element.camera, width, height), | ||
x = _this3$getScreenPosit.x, | ||
y = _this3$getScreenPosit.y; | ||
lastLabelName = name; | ||
@@ -383,4 +397,4 @@ var tooltipText = tooltips ? tooltips[name] : undefined; | ||
tooltipPosition: { | ||
top: clientY - 10, | ||
left: clientX - 10 | ||
top: y, | ||
left: x | ||
}, | ||
@@ -606,16 +620,22 @@ tooltipText: tooltipText | ||
key: "setMouseCoords", | ||
value: function setMouseCoords(e) { | ||
var target = e.target, | ||
clientX = e.clientX, | ||
clientY = e.clientY; | ||
var _target$getBoundingCl = target.getBoundingClientRect(), | ||
left = _target$getBoundingCl.left, | ||
right = _target$getBoundingCl.right, | ||
top = _target$getBoundingCl.top, | ||
bottom = _target$getBoundingCl.bottom; | ||
value: function setMouseCoords(clientX, clientY, target, left, right, top, bottom) { | ||
this.mouse.x = (clientX - left) / (right - left) * 2 - 1; | ||
this.mouse.y = -(clientY - top) / (bottom - top) * 2 + 1; | ||
this.mouse.targetId = target.id; | ||
} | ||
}, { | ||
key: "getScreenPositionOfObject", | ||
value: function getScreenPositionOfObject(obj, camera, width, height) { | ||
var vector = new _three.Vector3(); | ||
var widthHalf = 0.5 * width; | ||
var heightHalf = 0.5 * height; | ||
obj.updateMatrixWorld(); | ||
vector.setFromMatrixPosition(obj.matrixWorld); | ||
vector.project(camera); | ||
vector.x = vector.x * widthHalf + widthHalf; | ||
vector.y = -(vector.y * heightHalf) + heightHalf; | ||
return { | ||
x: vector.x, | ||
y: vector.y | ||
}; | ||
} // animation loop | ||
@@ -622,0 +642,0 @@ |
{ | ||
"name": "@qctrl/visualizer", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "An animated and interactive quantum state visualisation built with THREE.js and implemented as a React component", | ||
@@ -5,0 +5,0 @@ "repository": { |
294317
3346