Merge branch 'master' of gitea.iwm-tuebingen.de:IWMBrowser/iwmlib

This commit is contained in:
2019-08-12 15:57:14 +02:00
137 changed files with 6467 additions and 6486 deletions
+19 -91
View File
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-console */
/* globals TweenLite debugCanvas */
/* globals debugCanvas */
import Interface from './interface.js'
import { Points, Polygon, Angle, Elements, LowPassFilter } from './utils.js'
import Events from './events.js'
@@ -45,14 +45,7 @@ const END = 'onEnd'
export class ScatterEvent extends BaseEvent {
constructor(
target,
{
translate = { x: 0, y: 0 },
scale = null,
rotate = 0,
about = null,
fast = false,
type = null
} = {}
{ translate = { x: 0, y: 0 }, scale = null, rotate = 0, about = null, fast = false, type = null } = {}
) {
super('scatterTransformed', { target: target })
this.translate = translate
@@ -65,13 +58,7 @@ export class ScatterEvent extends BaseEvent {
toString() {
return (
"Event('scatterTransformed', scale: " +
this.scale +
' about: ' +
this.about.x +
', ' +
this.about.y +
')'
"Event('scatterTransformed', scale: " + this.scale + ' about: ' + this.about.x + ', ' + this.about.y + ')'
)
}
}
@@ -91,13 +78,7 @@ export class ResizeEvent extends BaseEvent {
}
toString() {
return (
'Event(scatterResized width: ' +
this.width +
'height: ' +
this.height +
')'
)
return 'Event(scatterResized width: ' + this.width + 'height: ' + this.height + ')'
}
}
@@ -386,9 +367,7 @@ export class AbstractScatter extends Throwable {
}
_removeSelfFromScatterContainer() {
/**
Removes self from container when it's closed.
*/
// Removes self from container when it's closed.
if (this.container) {
this.container.remove(this)
}
@@ -524,10 +503,7 @@ export class AbstractScatter extends Throwable {
_checkAutoClose() {
if (this.scaleAutoClose)
if (
this.scale <
this.minScale + this.scaleCloseThreshold - this.scaleCloseBuffer
) {
if (this.scale < this.minScale + this.scaleCloseThreshold - this.scaleCloseBuffer) {
this.zoom(this.minScale, {
animate: 0.2,
onComplete: this.close.bind(this)
@@ -582,17 +558,7 @@ export class AbstractScatter extends Throwable {
this.move(delta, { animate: animate })
}
zoom(
scale,
{
animate = 0,
about = null,
delay = 0,
x = null,
y = null,
onComplete = null
} = {}
) {
zoom(scale, { animate = 0, about = null, delay = 0, x = null, y = null, onComplete = null } = {}) {
let anchor = about || this.center
if (scale != this.scale) {
if (animate > 0) {
@@ -643,15 +609,9 @@ export class AbstractScatter extends Throwable {
let origin = this.rotationOrigin
let beta = Points.angle(origin, anchor)
let distance = Points.distance(origin, anchor)
let { scale: newScale, zoom: thresholdedZoom } = this.calculateScale(
zoom
)
let { scale: newScale, zoom: thresholdedZoom } = this.calculateScale(zoom)
let newOrigin = Points.arc(
anchor,
beta + rotate,
distance * thresholdedZoom
)
let newOrigin = Points.arc(anchor, beta + rotate, distance * thresholdedZoom)
let extra = Points.subtract(newOrigin, origin)
let offset = Points.subtract(anchor, origin)
this._move(offset)
@@ -714,10 +674,8 @@ export class AbstractScatter extends Throwable {
}
calculateScaleTransparency() {
let transparency =
(this.scale - this.minScale) / this.scaleCloseThreshold
transparency =
transparency > 1 ? 1 : transparency < 0 ? 0 : transparency
let transparency = (this.scale - this.minScale) / this.scaleCloseThreshold
transparency = transparency > 1 ? 1 : transparency < 0 ? 0 : transparency
return transparency
}
@@ -775,8 +733,7 @@ export class AbstractScatter extends Throwable {
if (this.scaleAutoClose) {
if (this.scale <= this.minScale + this.scaleCloseThreshold) {
if (this.scaleAutoCloseTimeout)
clearTimeout(this.scaleAutoCloseTimeout)
if (this.scaleAutoCloseTimeout) clearTimeout(this.scaleAutoCloseTimeout)
this.scaleAutoCloseTimeout = setTimeout(() => {
this._checkAutoClose()
}, 600)
@@ -939,13 +896,7 @@ export class DOMScatterContainer {
*/
constructor(
element,
{
stopEvents = 'auto',
claimEvents = true,
useCapture = true,
touchAction = 'none',
debugCanvas = null
} = {}
{ stopEvents = 'auto', claimEvents = true, useCapture = true, touchAction = 'none', debugCanvas = null } = {}
) {
this.onCapture = null
this.element = element
@@ -956,11 +907,7 @@ export class DOMScatterContainer {
movement of scatter objects, the touchmove event has to be bound again.
*/
if (Capabilities.isSafari) {
document.addEventListener(
'touchmove',
event => this.preventPinch(event),
false
)
document.addEventListener('touchmove', event => this.preventPinch(event), false)
stopEvents = false
} else {
stopEvents = true
@@ -996,14 +943,7 @@ export class DOMScatterContainer {
for (let [key, point] of current.entries()) {
let local = point
context.beginPath()
context.arc(
local.x * resolution,
local.y * resolution,
radius,
0,
2 * Math.PI,
false
)
context.arc(local.x * resolution, local.y * resolution, radius, 0, 2 * Math.PI, false)
context.fill()
context.stroke()
}
@@ -1026,14 +966,7 @@ export class DOMScatterContainer {
* @memberof DOMScatterContainer
*/
remove(scatter) {
const element = scatter.element
if (!this.scatter.has(element))
console.warn(
`Try removing element that is not in the scatter.`,
element
)
this.scatter.delete(element)
this.scatter.delete(scatter.element)
}
/**
@@ -1082,10 +1015,7 @@ export class DOMScatterContainer {
***/
let found = document.elementFromPoint(global.x, global.y)
for (let target of this.scatter.values()) {
if (
target.interactive &&
this.isDescendant(target.element, found)
) {
if (target.interactive && this.isDescendant(target.element, found)) {
if (this.stopEvents) Events.stop(event)
if (this.claimEvents) event.claimedByScatter = target
return target
@@ -1516,10 +1446,8 @@ export class DOMScatter extends AbstractScatter {
let resizeH = -r * Math.sin(Angle.degree2radian(phiCorrected))
if (
(this.element.offsetWidth + resizeW) / this.scale >
(this.width * 0.5) / this.scale &&
(this.element.offsetHeight + resizeH) / this.scale >
(this.height * 0.3) / this.scale
(this.element.offsetWidth + resizeW) / this.scale > (this.width * 0.5) / this.scale &&
(this.element.offsetHeight + resizeH) / this.scale > (this.height * 0.3) / this.scale
)
TweenLite.to(this.element, 0, {
width: this.element.offsetWidth + resizeW / this.scale,