Added LowPassFilter and support for smooth scatter rotation and zoom.

This commit is contained in:
2019-07-11 15:41:03 +02:00
parent 2a11f02bd2
commit cd76ae22a4
6 changed files with 1602 additions and 1276 deletions
+25 -9
View File
@@ -1,11 +1,11 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-console */
/* globals TweenLite debugCanvas */
import { Points, Polygon, Angle, Elements } from './utils.js'
import { Points, Polygon, Angle, Elements, LowPassFilter } from './utils.js'
import Events from './events.js'
import { InteractionMapper } from './interaction.js'
import { Capabilities } from './capabilities.js'
import PopupMenu from './popupmenu.js'
/**
* A base class for scatter specific events.
*
@@ -270,7 +270,8 @@ export class AbstractScatter extends Throwable {
scaleAutoClose = false,
scaleCloseThreshold = 0.10,
scaleCloseBuffer = 0.05,
maxRotation = Angle.degree2radian(5)
maxRotation = Angle.degree2radian(5),
useLowPassFilter = true
} = {}) {
if (rotationDegrees != null && rotation != null) {
throw new Error('Use rotationDegrees or rotation but not both')
@@ -314,7 +315,12 @@ export class AbstractScatter extends Throwable {
this.resizable = resizable
this.mouseZoomFactor = mouseZoomFactor
this.autoBringToFront = autoBringToFront
this.useLowPassFilter = useLowPassFilter
if (useLowPassFilter) {
this.rotateLPF = new LowPassFilter()
this.zoomLPF = new LowPassFilter()
this.zoomLPF.setup([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
}
this.dragging = false
this.onTransform = onTransform != null ? [onTransform] : null
this.onClose = onClose != null ? [onClose] : null
@@ -338,6 +344,11 @@ export class AbstractScatter extends Throwable {
this.bringToFront()
this.killAnimation()
this.observeVelocity()
if (this.useLowPassFilter) {
this.rotateLPF.clear()
this.zoomLPF.clear()
this.zoomLPF.setup([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
}
return true
}
@@ -351,14 +362,19 @@ export class AbstractScatter extends Throwable {
let delta = interaction.delta()
if (delta != null) {
this.addVelocity(delta)
let alpha = delta.rotate
let rotate = delta.rotate
let zoom = delta.zoom
if (this.maxRotation != null) {
if (Math.abs(alpha) > this.maxRotation) {
alpha = 0
if (Math.abs(rotate) > this.maxRotation) {
rotate = 0
}
}
this.transform(delta, delta.zoom, alpha, delta.about)
if (delta.zoom != 1) this.interactionAnchor = delta.about
if (this.useLowPassFilter) {
rotate = this.rotateLPF.next(rotate)
zoom = this.zoomLPF.next(zoom)
}
this.transform(delta, zoom, rotate, delta.about)
if (zoom != 1) this.interactionAnchor = delta.about
}
}