Scales in Time Machines Workingn well

This commit is contained in:
Luis Fernando Molina committed 2020-02-12 15:53:17 +01:00
1 parent 3a58288bab
commit b4d5c763cb
5 files changed
+15 -130

No files matched your search

+4 -4
View File
@@ -169,7 +169,7 @@ function newEdgeEditor () {
break
}
case 'top' : {
if (thisObject.container.parentContainer.frame.height - dragVector.y < MIN_HEIGHT) {
if (thisObject.container.parentContainer.frame.height - dragVector.y < MIN_HEIGHT && dragVector.y > 0) {
return
}
@@ -199,7 +199,7 @@ function newEdgeEditor () {
break
}
case 'bottom' : {
if (thisObject.container.parentContainer.frame.height + dragVector.y < MIN_HEIGHT) {
if (thisObject.container.parentContainer.frame.height + dragVector.y < MIN_HEIGHT && dragVector.y < 0) {
return
}
@@ -228,7 +228,7 @@ function newEdgeEditor () {
break
}
case 'left' : {
if (thisObject.container.parentContainer.frame.width - dragVector.x < MIN_WIDTH) {
if (thisObject.container.parentContainer.frame.width - dragVector.x < MIN_WIDTH && dragVector.x > 0) {
return
}
let point = {
@@ -257,7 +257,7 @@ function newEdgeEditor () {
break
}
case 'right' : {
if (thisObject.container.parentContainer.frame.width + dragVector.x < MIN_WIDTH) {
if (thisObject.container.parentContainer.frame.width + dragVector.x < MIN_WIDTH && dragVector.x < 0) {
return
}
-18
View File
@@ -51,7 +51,6 @@ function newTimeMachine () {
let onMouseOverEventSuscriptionId
let onMouseNotOverEventSuscriptionId
let timeScaleMouseOverEventSuscriptionId
let rateScaleValueEventSuscriptionId
let rateScaleMouseOverEventSuscriptionId
let timeFrameScaleEventSuscriptionId
let timeFrameScaleMouseOverEventSuscriptionId
@@ -121,7 +120,6 @@ function newTimeMachine () {
function finalizeRateScale () {
if (thisObject.rateScale === undefined) { return }
thisObject.rateScale.container.eventHandler.stopListening(rateScaleValueEventSuscriptionId)
thisObject.rateScale.container.eventHandler.stopListening(rateScaleMouseOverEventSuscriptionId)
thisObject.rateScale.finalize()
thisObject.rateScale = undefined
@@ -208,25 +206,9 @@ function newTimeMachine () {
thisObject.rateScale.fitFunction = thisObject.fitFunction
thisObject.rateScale.payload = thisObject.payload.node.rateScale.payload
rateScaleValueEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('Rate Scale Value Changed', rateScaleValueChanged)
rateScaleMouseOverEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('onMouseOverScale', rateScaleMouseOver)
thisObject.rateScale.initialize(timeMachineCoordinateSystem, thisObject.container, thisObject.container)
function rateScaleValueChanged (event) {
if (event.isUserAction === true) {
let currentDate = getDateFromPointAtBrowserCanvas(event.mousePosition, thisObject.container, timeMachineCoordinateSystem)
let currentRate = getRateFromPointAtBrowserCanvas(event.mousePosition, thisObject.container, timeMachineCoordinateSystem)
// thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale
recalculateCoordinateSystem()
moveToUserPosition(thisObject.container, currentDate, currentRate, timeMachineCoordinateSystem, true, false, event.mousePosition)
} else {
// thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale
recalculateCoordinateSystem()
}
thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event)
thisObject.container.eventHandler.raiseEvent('Upstream Rate Scale Value Changed', event)
}
function rateScaleMouseOver (event) {
thisObject.container.eventHandler.raiseEvent('onMouseOver', event)
}
-23
View File
@@ -38,11 +38,9 @@ function newTimelineChart () {
let onMouseOverEventSuscriptionId
let onMouseNotOverEventSuscriptionId
let rateScaleValueEventSuscriptionId
let rateScaleUpstreamEventSuscriptionId
let rateScaleMouseOverEventSuscriptionId
let rateScaleOffsetEventSuscriptionId
let rateScaleUpstreamDimensionsEventSuscriptionId
let timeFrameScaleEventSuscriptionId
let timeFrameScaleMouseOverEventSuscriptionId
let scaleChangedEventSubscriptionId
@@ -125,10 +123,8 @@ function newTimelineChart () {
if (thisObject.rateScale === undefined) { return }
thisObject.rateScale.container.eventHandler.stopListening(rateScaleOffsetEventSuscriptionId)
thisObject.rateScale.container.eventHandler.stopListening(rateScaleValueEventSuscriptionId)
thisObject.rateScale.container.eventHandler.stopListening(rateScaleMouseOverEventSuscriptionId)
thisObject.container.parentContainer.eventHandler.stopListening(rateScaleUpstreamEventSuscriptionId)
thisObject.container.parentContainer.eventHandler.stopListening(rateScaleUpstreamDimensionsEventSuscriptionId)
thisObject.rateScale.finalize()
thisObject.rateScale = undefined
@@ -182,22 +178,9 @@ function newTimelineChart () {
thisObject.rateScale.payload = thisObject.payload.node.rateScale.payload
rateScaleOffsetEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('Rate Scale Offset Changed', rateScaleOffsetChanged)
rateScaleValueEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('Rate Scale Value Changed', rateScaleValueChanged)
rateScaleMouseOverEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('onMouseOverScale', rateScaleMouseOver)
rateScaleUpstreamEventSuscriptionId = thisObject.container.parentContainer.eventHandler.listenToEvent('Upstream Rate Scale Value Changed', rateScaleUpstreamChanged)
rateScaleUpstreamDimensionsEventSuscriptionId = thisObject.container.parentContainer.eventHandler.listenToEvent('Dimmensions Changed', rateScaleUpstreamDimensioinsChanged)
thisObject.rateScale.initialize(timelineChartCoordinateSystem, thisObject.container.parentContainer, thisObject.container)
function rateScaleUpstreamDimensioinsChanged () {
thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * thisObject.rateScale.scale
recalculateCoordinateSystem()
thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event)
}
function rateScaleUpstreamChanged (event) {
// thisObject.rateScale.setScale(event.scale)
}
function rateScaleOffsetChanged (event) {
if (thisObject.container.frame.offset.y !== event.offset) {
thisObject.container.frame.offset.y = event.offset
@@ -205,12 +188,6 @@ function newTimelineChart () {
}
}
function rateScaleValueChanged (event) {
thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale
recalculateCoordinateSystem()
thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event)
}
function rateScaleMouseOver (event) {
thisObject.container.eventHandler.raiseEvent('onChildrenMouseOver', event)
}
+10 -84
View File
@@ -6,13 +6,11 @@ function newRateScale () {
rate: undefined,
fitFunction: undefined,
payload: undefined,
scale: undefined,
offset: undefined,
minValue: undefined,
maxValue: undefined,
isVisible: true,
layersOn: undefined,
setScale: setScale,
onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer,
physics: physics,
draw: draw,
@@ -22,12 +20,6 @@ function newRateScale () {
finalize: finalize
}
const DEFAULT_SCALE = 50
const STEP_SCALE = 1
const MIN_SCALE = 0
const MAX_SCALE = 100
const SNAP_THRESHOLD_SCALE = 1
const DEFAULT_OFFSET = 0
const STEP_OFFSET = 1
const MIN_OFFSET = -1000
@@ -53,6 +45,7 @@ function newRateScale () {
let onMouseWheelEventSubscriptionId
let onMouseOverEventSubscriptionId
let onMouseNotOverEventSubscriptionId
let onScaleChangedEventSubscriptionId
let coordinateSystem
let limitingContainer
@@ -66,13 +59,13 @@ function newRateScale () {
}
let offsetTimer = 0
let scaleTimer = 0
return thisObject
function finalize () {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId)
coordinateSystem.eventHandler.stopListening(onScaleChangedEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
@@ -96,13 +89,9 @@ function newRateScale () {
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
onScaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged)
thisObject.scale = DEFAULT_SCALE
readObjectState()
let event = {}
event.scale = thisObject.scale
thisObject.container.eventHandler.raiseEvent('Rate Scale Value Changed', event)
}
function onMouseOverSomeTimeMachineContainer (event) {
@@ -125,6 +114,10 @@ function newRateScale () {
}
}
function onScaleChanged () {
saveObjectState()
}
function onMouseOver (event) {
isMouseOver = true
event.containerId = thisObject.container.id
@@ -134,7 +127,6 @@ function newRateScale () {
function onMouseNotOver () {
isMouseOver = false
offsetTimer = 0
scaleTimer = 0
}
function onMouseWheel (event) {
@@ -164,7 +156,6 @@ function newRateScale () {
saveObjectState()
offsetTimer = 100
scaleTimer = 0
} else {
let factor
let morePower = 10
@@ -178,45 +169,9 @@ function newRateScale () {
}
coordinateSystem.zoomY(factor, event, limitingContainer)
return
if (event.buttons === 4) { morePower = 5 } // Mouse wheel pressed.
delta = event.wheelDelta
if (delta < 0) {
thisObject.scale = thisObject.scale - STEP_SCALE * morePower
if (thisObject.scale < MIN_SCALE) { thisObject.scale = MIN_SCALE }
} else {
thisObject.scale = thisObject.scale + STEP_SCALE * morePower
if (thisObject.scale > MAX_SCALE) { thisObject.scale = MAX_SCALE }
}
finishScaleChange(event)
}
}
function setScale (scale) {
thisObject.scale = scale
let event = {}
finishScaleChange(event)
}
function finishScaleChange (event) {
if (
thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE &&
thisObject.scale >= DEFAULT_SCALE - SNAP_THRESHOLD_SCALE
) {
event.scale = DEFAULT_SCALE
} else {
event.scale = thisObject.scale
}
event.isUserAction = true
thisObject.container.eventHandler.raiseEvent('Rate Scale Value Changed', event)
saveObjectState()
offsetTimer = 0
scaleTimer = 100
}
function getContainer (point) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
@@ -226,11 +181,10 @@ function newRateScale () {
function saveObjectState () {
try {
let code = JSON.parse(thisObject.payload.node.code)
code.scale = thisObject.scale / MAX_SCALE * 100
code.scale = code.scale.toFixed(0)
code.scale = undefined
code.offset = thisObject.offset
code.minValue = thisObject.minValue
code.maxValue = thisObject.maxValue
code.minValue = coordinateSystem.min.y
code.maxValue = coordinateSystem.max.y
thisObject.payload.node.code = JSON.stringify(code, null, 4)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
@@ -241,28 +195,6 @@ function newRateScale () {
try {
let code = JSON.parse(thisObject.payload.node.code)
if (isNaN(code.scale) || code.scale === null || code.scale === undefined) {
// not using this value
} else {
code.scale = code.scale / 100 * MAX_SCALE
if (code.scale < MIN_SCALE) { code.scale = MIN_SCALE }
if (code.scale > MAX_SCALE) { code.scale = MAX_SCALE }
if (code.scale !== thisObject.scale) {
thisObject.scale = code.scale
let event = {}
if (
thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE &&
thisObject.scale >= DEFAULT_SCALE - SNAP_THRESHOLD_SCALE
) {
event.scale = DEFAULT_SCALE
} else {
event.scale = thisObject.scale
}
thisObject.container.eventHandler.raiseEvent('Rate Scale Value Changed', event)
}
}
if (isNaN(code.offset) || code.offset === null || code.offset === undefined) {
// not using this value
} else {
@@ -306,7 +238,6 @@ function newRateScale () {
function physics () {
offsetTimer--
scaleTimer--
readObjectState()
positioningPhysics()
}
@@ -438,11 +369,6 @@ function newRateScale () {
label3 = 'OFFSET'
}
if (scaleTimer > 0) {
label2 = (thisObject.scale / MAX_SCALE * 100).toFixed(0)
label3 = 'SCALE'
}
drawScaleDisplay(label1, label2, label3, 0, 0, 0, icon1, icon2, thisObject.container, backgroundColor)
}
}
+1 -1
View File
@@ -135,6 +135,7 @@ function newTimeScale () {
function saveObjectState () {
try {
let code = JSON.parse(thisObject.payload.node.code)
code.scale = undefined
code.fromDate = (new Date(coordinateSystem.min.x)).toISOString()
code.toDate = (new Date(coordinateSystem.max.x)).toISOString()
thisObject.payload.node.code = JSON.stringify(code, null, 4)
@@ -144,7 +145,6 @@ function newTimeScale () {
}
function readObjectState () {
return
try {
let code = JSON.parse(thisObject.payload.node.code)