rateScales saving at config
This commit is contained in:
1 parent
3336961af0
commit
44d0944a56
2 files changed
+57
-18
No files matched your search
+48
-10
@@ -6,7 +6,7 @@ function newRateScale () {
|
||||
rate: undefined,
|
||||
fitFunction: undefined,
|
||||
payload: undefined,
|
||||
heightPercentage: 150,
|
||||
heightPercentage: undefined,
|
||||
onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer,
|
||||
physics: physics,
|
||||
draw: draw,
|
||||
@@ -16,9 +16,10 @@ function newRateScale () {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const HEIGHT_PERCENTAGE_DEFAULT_VALUE = 50
|
||||
const DEFAULT_VALUE = 50
|
||||
const STEP_SIZE = 2
|
||||
const MIN_WIDTH = 50
|
||||
const MAX_VALUE = 150
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
@@ -72,12 +73,8 @@ function newRateScale () {
|
||||
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
|
||||
|
||||
thisObject.heightPercentage = window.localStorage.getItem(MODULE_NAME)
|
||||
if (!thisObject.heightPercentage) {
|
||||
thisObject.heightPercentage = HEIGHT_PERCENTAGE_DEFAULT_VALUE
|
||||
} else {
|
||||
thisObject.heightPercentage = JSON.parse(thisObject.heightPercentage)
|
||||
}
|
||||
thisObject.heightPercentage = DEFAULT_VALUE
|
||||
readObjectState()
|
||||
|
||||
let event = {}
|
||||
event.heightPercentage = thisObject.heightPercentage
|
||||
@@ -124,12 +121,12 @@ function newRateScale () {
|
||||
if (thisObject.heightPercentage < STEP_SIZE * 3) { thisObject.heightPercentage = STEP_SIZE }
|
||||
} else {
|
||||
thisObject.heightPercentage = thisObject.heightPercentage + STEP_SIZE * morePower
|
||||
if (thisObject.heightPercentage > 150) { thisObject.heightPercentage = 200 }
|
||||
if (thisObject.heightPercentage > MAX_VALUE) { thisObject.heightPercentage = MAX_VALUE }
|
||||
}
|
||||
event.heightPercentage = thisObject.heightPercentage
|
||||
thisObject.container.eventHandler.raiseEvent('Height Percentage Changed', event)
|
||||
|
||||
window.localStorage.setItem(MODULE_NAME, thisObject.heightPercentage)
|
||||
saveObjectState()
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
@@ -138,7 +135,48 @@ function newRateScale () {
|
||||
}
|
||||
}
|
||||
|
||||
function saveObjectState () {
|
||||
try {
|
||||
let code = JSON.parse(thisObject.payload.node.code)
|
||||
code.value = thisObject.heightPercentage / MAX_VALUE * 100
|
||||
code.value = code.value.toFixed(2)
|
||||
thisObject.payload.node.code = JSON.stringify(code)
|
||||
} catch (err) {
|
||||
// we ignore errors here since most likely they will be parsing errors.
|
||||
}
|
||||
}
|
||||
|
||||
function readObjectState () {
|
||||
try {
|
||||
let code = JSON.parse(thisObject.payload.node.code)
|
||||
|
||||
if (isNaN(code.value) || code.value === null || code.value === undefined) {
|
||||
saveObjectState()
|
||||
return
|
||||
}
|
||||
code.value = code.value / 100 * MAX_VALUE
|
||||
if (code.value < STEP_SIZE) { code.value = STEP_SIZE }
|
||||
if (code.value > MAX_VALUE) { code.value = MAX_VALUE }
|
||||
|
||||
if (code.value !== thisObject.heightPercentage) {
|
||||
thisObject.heightPercentage = code.value
|
||||
let event = {}
|
||||
event.heightPercentage = thisObject.heightPercentage
|
||||
thisObject.container.eventHandler.raiseEvent('Height Percentage Changed', event)
|
||||
} else {
|
||||
saveObjectState()
|
||||
}
|
||||
} catch (err) {
|
||||
// we ignore errors here since most likely they will be parsing errors.
|
||||
}
|
||||
}
|
||||
|
||||
function physics () {
|
||||
readObjectState()
|
||||
positioningphysics()
|
||||
}
|
||||
|
||||
function positioningphysics () {
|
||||
/* Container Limits */
|
||||
|
||||
let upCorner = {
|
||||
|
||||
+9
-8
@@ -16,9 +16,9 @@ function newTimeScale () {
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
const LENGHT_PERCENTAGE_DEFAULT_VALUE = 5
|
||||
const DEFAULT_VALUE = 5
|
||||
const STEP_SIZE = 2.5
|
||||
const LENGHT_PERCENTAGE_MAX_VALUE = 400
|
||||
const MAX_VALUE = 400
|
||||
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
@@ -72,7 +72,7 @@ function newTimeScale () {
|
||||
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
|
||||
|
||||
thisObject.lenghtPercentage = LENGHT_PERCENTAGE_DEFAULT_VALUE
|
||||
thisObject.lenghtPercentage = DEFAULT_VALUE
|
||||
readObjectState()
|
||||
|
||||
let event = {}
|
||||
@@ -120,7 +120,7 @@ function newTimeScale () {
|
||||
if (thisObject.lenghtPercentage < STEP_SIZE) { thisObject.lenghtPercentage = STEP_SIZE }
|
||||
} else {
|
||||
thisObject.lenghtPercentage = thisObject.lenghtPercentage + STEP_SIZE * morePower
|
||||
if (thisObject.lenghtPercentage > LENGHT_PERCENTAGE_MAX_VALUE) { thisObject.lenghtPercentage = LENGHT_PERCENTAGE_MAX_VALUE }
|
||||
if (thisObject.lenghtPercentage > MAX_VALUE) { thisObject.lenghtPercentage = MAX_VALUE }
|
||||
}
|
||||
|
||||
event.lenghtPercentage = thisObject.lenghtPercentage
|
||||
@@ -138,7 +138,8 @@ function newTimeScale () {
|
||||
function saveObjectState () {
|
||||
try {
|
||||
let code = JSON.parse(thisObject.payload.node.code)
|
||||
code.value = thisObject.lenghtPercentage / LENGHT_PERCENTAGE_MAX_VALUE * 100
|
||||
code.value = thisObject.lenghtPercentage / MAX_VALUE * 100
|
||||
code.value = code.value.toFixed(2)
|
||||
thisObject.payload.node.code = JSON.stringify(code)
|
||||
} catch (err) {
|
||||
// we ignore errors here since most likely they will be parsing errors.
|
||||
@@ -153,9 +154,9 @@ function newTimeScale () {
|
||||
saveObjectState()
|
||||
return
|
||||
}
|
||||
code.value = code.value / 100 * LENGHT_PERCENTAGE_MAX_VALUE
|
||||
code.value = code.value / 100 * MAX_VALUE
|
||||
if (code.value < STEP_SIZE) { code.value = STEP_SIZE }
|
||||
if (code.value > LENGHT_PERCENTAGE_MAX_VALUE) { code.value = LENGHT_PERCENTAGE_MAX_VALUE }
|
||||
if (code.value > MAX_VALUE) { code.value = MAX_VALUE }
|
||||
|
||||
if (code.value !== thisObject.lenghtPercentage) {
|
||||
thisObject.lenghtPercentage = code.value
|
||||
@@ -266,7 +267,7 @@ function newTimeScale () {
|
||||
const DISTANCE_BETWEEN_ARROWS = 10
|
||||
const MIN_DISTANCE_FROM_CENTER = 110
|
||||
const CURRENT_VALUE_DISTANCE = MIN_DISTANCE_FROM_CENTER + thisObject.lenghtPercentage
|
||||
const MAX_DISTANCE_FROM_CENTER = MIN_DISTANCE_FROM_CENTER + LENGHT_PERCENTAGE_MAX_VALUE + DISTANCE_BETWEEN_ARROWS
|
||||
const MAX_DISTANCE_FROM_CENTER = MIN_DISTANCE_FROM_CENTER + MAX_VALUE + DISTANCE_BETWEEN_ARROWS
|
||||
|
||||
let ARROW_DIRECTION = 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user