Reimplementation of auto scales with mouse wheel

This commit is contained in:
Luis Fernando Molina committed 2020-02-14 20:22:43 +01:00
1 parent 48ab3c0b20
commit 3b2c3d3d61
3 files changed
+66 -41

No files matched your search

+52 -22
View File
@@ -5,6 +5,7 @@ function newAutoScaleButton () {
parentContainer: undefined,
autoMinScale: undefined,
autoMaxScale: undefined,
setStatus: setStatus,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize,
@@ -19,13 +20,14 @@ function newAutoScaleButton () {
thisObject.container.isDraggeable = false
thisObject.container.frame.containerName = 'Auto Scale Button'
let onMouseClickEventSuscriptionId
let onMouseWheelEventSubscriptionId
let coordinateSystem
let axis
let currentStatus
return thisObject
function finalize () {
thisObject.container.eventHandler.stopListening(onMouseClickEventSuscriptionId)
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
@@ -68,35 +70,63 @@ function newAutoScaleButton () {
break
}
}
/* Lets listen to our own events to react when we have a Mouse Click */
onMouseClickEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
}
function onMouseClick (event) {
function setStatus (autoMinScale, autoMaxScale) {
thisObject.autoMinScale = autoMinScale
thisObject.autoMaxScale = autoMaxScale
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === false) {
thisObject.autoMinScale = true
thisObject.autoMaxScale = false
update()
return
currentStatus = 1
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === false) {
thisObject.autoMinScale = false
thisObject.autoMaxScale = true
update()
return
currentStatus = 2
}
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) {
thisObject.autoMinScale = true
thisObject.autoMaxScale = true
update()
return
currentStatus = 3
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
currentStatus = 4
}
}
function onMouseWheel (event) {
let factor
let delta = event.wheelDelta
if (delta < 0) {
delta = -1
} else {
delta = 1
}
currentStatus = currentStatus + delta
if (currentStatus === 5) { currentStatus = 1 }
if (currentStatus === 0) { currentStatus = 4 }
switch (currentStatus) {
case 1: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 2: {
thisObject.autoMinScale = true
thisObject.autoMaxScale = false
update()
return
}
case 3: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = true
update()
return
}
case 4: {
thisObject.autoMinScale = true
thisObject.autoMaxScale = true
update()
return
}
}
function update () {
+8 -10
View File
@@ -134,6 +134,11 @@ function newRateScale () {
}
function onMouseWheel (event) {
if (event.shiftKey === true) {
autoScaleButton.container.eventHandler.raiseEvent('onMouseWheel', event)
return
}
let factor
let morePower = 10
if (event.buttons === 4) { morePower = 1 } // Mouse wheel pressed.
@@ -151,11 +156,6 @@ function newRateScale () {
function getContainer (point, purpose) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
let container = autoScaleButton.getContainer(point, purpose)
if (container !== undefined) {
return container
}
if (purpose === GET_CONTAINER_PURPOSE.DRAGGING) {
return draggeableContainer
}
@@ -198,14 +198,12 @@ function newRateScale () {
coordinateSystem.min.y = thisObject.minValue
coordinateSystem.max.y = thisObject.maxValue
if (code.autoMinScale !== undefined && (code.autoMinScale === true || code.autoMinScale === false)) {
if (code.autoMinScale !== undefined && (code.autoMinScale === true || code.autoMinScale === false) && code.autoMaxScale !== undefined && (code.autoMaxScale === true || code.autoMaxScale === false)) {
coordinateSystem.autoMinYScale = code.autoMinScale
autoScaleButton.autoMinScale = code.autoMinScale
}
if (code.autoMaxScale !== undefined && (code.autoMaxScale === true || code.autoMaxScale === false)) {
coordinateSystem.autoMaxYScale = code.autoMaxScale
autoScaleButton.autoMaxScale = code.autoMaxScale
autoScaleButton.setStatus(code.autoMinScale, code.autoMaxScale)
}
coordinateSystem.recalculateScale()
}
}
+6 -9
View File
@@ -116,6 +116,10 @@ function newTimeScale () {
}
function onMouseWheel (event) {
if (event.shiftKey === true) {
autoScaleButton.container.eventHandler.raiseEvent('onMouseWheel', event)
return
}
let factor
let morePower = 10
if (event.buttons === 4) { morePower = 1 } // Mouse wheel pressed.
@@ -136,10 +140,6 @@ function newTimeScale () {
function getContainer (point, purpose) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
let container = autoScaleButton.getContainer(point, purpose)
if (container !== undefined) {
return container
}
return thisObject.container
}
}
@@ -173,13 +173,10 @@ function newTimeScale () {
coordinateSystem.min.x = thisObject.fromDate
coordinateSystem.max.x = thisObject.toDate
if (code.autoMinScale !== undefined && (code.autoMinScale === true || code.autoMinScale === false)) {
if (code.autoMinScale !== undefined && (code.autoMinScale === true || code.autoMinScale === false) && code.autoMaxScale !== undefined && (code.autoMaxScale === true || code.autoMaxScale === false)) {
coordinateSystem.autoMinXScale = code.autoMinScale
autoScaleButton.autoMinScale = code.autoMinScale
}
if (code.autoMaxScale !== undefined && (code.autoMaxScale === true || code.autoMaxScale === false)) {
coordinateSystem.autoMaxXScale = code.autoMaxScale
autoScaleButton.autoMaxScale = code.autoMaxScale
autoScaleButton.setStatus(code.autoMinScale, code.autoMaxScale)
}
coordinateSystem.recalculateScale()
}