Tested new way to compute interaction delta.

This commit is contained in:
Uwe Oestermeier 2019-07-24 08:54:09 +02:00
parent ef4267e926
commit cc6ef8de46
3 changed files with 243 additions and 2 deletions

97
dist/iwmlib.js vendored
View File

@ -1929,6 +1929,78 @@
* @memberof InteractionPoints * @memberof InteractionPoints
*/ */
delta() { delta() {
let prev = [];
let curr = [];
let cm = { x: 0, y: 0};
let pm = { x: 0, y: 0};
let count = 0;
for(let key of this.current.keys()) {
if (this.previous.has(key)) {
let p = this.previous.get(key);
let c = this.current.get(key);
pm = Points$1.add(pm, p);
cm = Points$1.add(cm, c);
prev.push(p);
curr.push(c);
count += 1;
}
}
if (count > 0) {
pm = Points$1.multiplyScalar(pm, 1 / count);
cm = Points$1.multiplyScalar(cm, 1 / count);
let delta = Points$1.subtract(cm, pm);
let scale = 0;
let scaled = 0;
let alpha = 0;
let zoom = 1;
for(let i=0; i<count; i++) {
let p = prev[i];
let c = curr[i];
let previousAngle = Points$1.angle(p, pm);
let currentAngle = Points$1.angle(c, cm);
let diff = this.diffAngle(currentAngle, previousAngle);
alpha += diff;
let distance1 = Points$1.distance(p, pm);
let distance2 = Points$1.distance(c, cm);
if (distance1 != 0 && distance2 != 0) {
scale += distance2 / distance1;
scaled += 1;
}
}
if (scaled > 0) {
zoom = scale / scaled;
}
alpha /= count;
let current = this.current.farthests();
let c1 = current[0];
let c2 = current[1];
let distance2 = Points$1.distance(c1, c2);
return new InteractionDelta(
delta.x,
delta.y,
zoom,
alpha,
cm,
count,
distance2
)
}
else {
return null
}
}
/**
* Computes the delta between interaction points at t and t+1.
*
* @returns InteractionDelta
* @memberof InteractionPoints
*/
deltaByTwoFarthestsPoints() {
let csize = this.current.size; let csize = this.current.size;
let psize = this.previous.size; let psize = this.previous.size;
if (csize >= 2 && csize == psize) { if (csize >= 2 && csize == psize) {
@ -3481,7 +3553,9 @@
if (delta.distance < this.minInteractionDistance) { if (delta.distance < this.minInteractionDistance) {
let ratio = delta.distance / this.minInteractionDistance; let ratio = delta.distance / this.minInteractionDistance;
rotate *= ratio; rotate *= ratio;
zoom *= ratio; let zoomDelta = zoom - 1;
zoomDelta *= ratio;
zoom = 1 + zoomDelta;
} }
this.transform(delta, zoom, rotate, delta.about); this.transform(delta, zoom, rotate, delta.about);
@ -9907,8 +9981,22 @@
); );
} }
isClickPrevented(node) {
if (node == null) {
return false
}
if (node.style && node.style.pointerEvents == 'none') {
return true
}
return this.isClickPrevented(node.parentNode)
}
isClickable(node) { isClickable(node) {
if (node == null) return false if (node == null) return false
// console.log("isClickable", node, this.isClickPrevented(node))
if (this.isClickPrevented(node)) {
return false
}
if (node.tagName == 'A' && node.hasAttribute('href')) return true if (node.tagName == 'A' && node.hasAttribute('href')) return true
if (node.hasAttribute('onclick')) return true if (node.hasAttribute('onclick')) return true
return false return false
@ -10002,6 +10090,7 @@
} }
nodeTapped(node, event) { nodeTapped(node, event) {
console.log("nodeTapped", node, this.isClickable(node));
if (this.isClickable(node)) { if (this.isClickable(node)) {
this.simulateClick(node, event); this.simulateClick(node, event);
return true return true
@ -10012,6 +10101,7 @@
return true return true
} }
for (let [selector, handler] of this.tapHandler.entries()) { for (let [selector, handler] of this.tapHandler.entries()) {
console.log("nodeTapped", selector);
for (let obj of this.domNode.querySelectorAll(selector)) { for (let obj of this.domNode.querySelectorAll(selector)) {
if (node == obj) { if (node == obj) {
handler(event); handler(event);
@ -10023,8 +10113,10 @@
} }
tap(event, calledBy = 'unknown') { tap(event, calledBy = 'unknown') {
if (event.isTrusted) { if (event.isTrusted) {
let node = this.nearestActive(event); let node = this.nearestActive(event);
console.log("tap", node);
this.nodeTapped(node, event); this.nodeTapped(node, event);
/* let node = document.elementFromPoint(event.clientX, event.clientY) /* let node = document.elementFromPoint(event.clientX, event.clientY)
@ -10261,6 +10353,9 @@
this._bringToFront(target); this._bringToFront(target);
let svgRoot = target.closest('svg'); let svgRoot = target.closest('svg');
if (svgRoot == null) {
return
}
let image = svgRoot.querySelector('image'); let image = svgRoot.querySelector('image');
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars

76
dist/iwmlib.pixi.js vendored
View File

@ -5350,6 +5350,78 @@
* @memberof InteractionPoints * @memberof InteractionPoints
*/ */
delta() { delta() {
let prev = [];
let curr = [];
let cm = { x: 0, y: 0};
let pm = { x: 0, y: 0};
let count = 0;
for(let key of this.current.keys()) {
if (this.previous.has(key)) {
let p = this.previous.get(key);
let c = this.current.get(key);
pm = Points.add(pm, p);
cm = Points.add(cm, c);
prev.push(p);
curr.push(c);
count += 1;
}
}
if (count > 0) {
pm = Points.multiplyScalar(pm, 1 / count);
cm = Points.multiplyScalar(cm, 1 / count);
let delta = Points.subtract(cm, pm);
let scale = 0;
let scaled = 0;
let alpha = 0;
let zoom = 1;
for(let i=0; i<count; i++) {
let p = prev[i];
let c = curr[i];
let previousAngle = Points.angle(p, pm);
let currentAngle = Points.angle(c, cm);
let diff = this.diffAngle(currentAngle, previousAngle);
alpha += diff;
let distance1 = Points.distance(p, pm);
let distance2 = Points.distance(c, cm);
if (distance1 != 0 && distance2 != 0) {
scale += distance2 / distance1;
scaled += 1;
}
}
if (scaled > 0) {
zoom = scale / scaled;
}
alpha /= count;
let current = this.current.farthests();
let c1 = current[0];
let c2 = current[1];
let distance2 = Points.distance(c1, c2);
return new InteractionDelta(
delta.x,
delta.y,
zoom,
alpha,
cm,
count,
distance2
)
}
else {
return null
}
}
/**
* Computes the delta between interaction points at t and t+1.
*
* @returns InteractionDelta
* @memberof InteractionPoints
*/
deltaByTwoFarthestsPoints() {
let csize = this.current.size; let csize = this.current.size;
let psize = this.previous.size; let psize = this.previous.size;
if (csize >= 2 && csize == psize) { if (csize >= 2 && csize == psize) {
@ -6893,7 +6965,9 @@
if (delta.distance < this.minInteractionDistance) { if (delta.distance < this.minInteractionDistance) {
let ratio = delta.distance / this.minInteractionDistance; let ratio = delta.distance / this.minInteractionDistance;
rotate *= ratio; rotate *= ratio;
zoom *= ratio; let zoomDelta = zoom - 1;
zoomDelta *= ratio;
zoom = 1 + zoomDelta;
} }
this.transform(delta, zoom, rotate, delta.about); this.transform(delta, zoom, rotate, delta.about);

View File

@ -203,6 +203,78 @@ export class InteractionPoints {
* @memberof InteractionPoints * @memberof InteractionPoints
*/ */
delta() { delta() {
let prev = []
let curr = []
let cm = { x: 0, y: 0}
let pm = { x: 0, y: 0}
let count = 0
for(let key of this.current.keys()) {
if (this.previous.has(key)) {
let p = this.previous.get(key)
let c = this.current.get(key)
pm = Points.add(pm, p)
cm = Points.add(cm, c)
prev.push(p)
curr.push(c)
count += 1
}
}
if (count > 0) {
pm = Points.multiplyScalar(pm, 1 / count)
cm = Points.multiplyScalar(cm, 1 / count)
let delta = Points.subtract(cm, pm)
let scale = 0
let scaled = 0
let alpha = 0
let zoom = 1
for(let i=0; i<count; i++) {
let p = prev[i]
let c = curr[i]
let previousAngle = Points.angle(p, pm)
let currentAngle = Points.angle(c, cm)
let diff = this.diffAngle(currentAngle, previousAngle)
alpha += diff
let distance1 = Points.distance(p, pm)
let distance2 = Points.distance(c, cm)
if (distance1 != 0 && distance2 != 0) {
scale += distance2 / distance1
scaled += 1
}
}
if (scaled > 0) {
zoom = scale / scaled
}
alpha /= count
let current = this.current.farthests()
let c1 = current[0]
let c2 = current[1]
let distance2 = Points.distance(c1, c2)
return new InteractionDelta(
delta.x,
delta.y,
zoom,
alpha,
cm,
count,
distance2
)
}
else {
return null
}
}
/**
* Computes the delta between interaction points at t and t+1.
*
* @returns InteractionDelta
* @memberof InteractionPoints
*/
deltaByTwoFarthestsPoints() {
let csize = this.current.size let csize = this.current.size
let psize = this.previous.size let psize = this.previous.size
if (csize >= 2 && csize == psize) { if (csize >= 2 && csize == psize) {