diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 6584f7f6e..a046f350c 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -601,12 +601,12 @@ function newTimeMachine () { x: MAX_PLOTABLE_DATE.valueOf(), y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 } -/* + if (thisObject.timeScale !== undefined) { - minValue.y = thisObject.rateScale.minValue - maxValue.y = thisObject.rateScale.maxValue + minValue.x = thisObject.timeScale.fromDate + maxValue.x = thisObject.timeScale.toDate } - */ + if (thisObject.rateScale !== undefined) { minValue.y = thisObject.rateScale.minValue maxValue.y = thisObject.rateScale.maxValue diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 9d367f1ca..232c4c309 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -218,7 +218,7 @@ function newRateScale () { code.offset = thisObject.offset code.minValue = thisObject.minValue code.maxValue = thisObject.maxValue - thisObject.payload.node.code = JSON.stringify(code) + thisObject.payload.node.code = JSON.stringify(code, null, 4) } catch (err) { // we ignore errors here since most likely they will be parsing errors. } @@ -279,8 +279,8 @@ function newRateScale () { } else { thisObject.minValue = code.minValue thisObject.maxValue = code.maxValue - coordinateSystem.min.y = code.minValue - coordinateSystem.max.y = code.maxValue + coordinateSystem.min.y = thisObject.minValue + coordinateSystem.max.y = thisObject.maxValue coordinateSystem.recalculateScale() } saveObjectState() // this overrides any invalid value at the config. diff --git a/Scales/TimeScale.js b/Scales/TimeScale.js index b39ceb13d..ccbe3cbc2 100644 --- a/Scales/TimeScale.js +++ b/Scales/TimeScale.js @@ -8,6 +8,8 @@ function newTimeScale () { fitFunction: undefined, payload: undefined, isVisible: true, + fromDate: undefined, + toDate: undefined, onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer, physics: physics, draw: draw, @@ -72,6 +74,9 @@ function newTimeScale () { coordinateSystem = pCoordinateSystem limitingContainer = pLimitingContainer + thisObject.fromDate = coordinateSystem.min.x + thisObject.toDate = coordinateSystem.max.x + onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver) @@ -155,7 +160,9 @@ function newTimeScale () { let code = JSON.parse(thisObject.payload.node.code) code.scale = thisObject.scale / MAX_SCALE * 100 code.scale = code.scale.toFixed(0) - thisObject.payload.node.code = JSON.stringify(code) + code.fromDate = (new Date(thisObject.fromDate)).toISOString() + code.toDate = (new Date(thisObject.toDate)).toISOString() + thisObject.payload.node.code = JSON.stringify(code, null, 4) } catch (err) { // we ignore errors here since most likely they will be parsing errors. } @@ -166,28 +173,40 @@ function newTimeScale () { let code = JSON.parse(thisObject.payload.node.code) if (isNaN(code.scale) || code.scale === null || code.scale === undefined) { - saveObjectState() - return - } - 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('Time Scale Value Changed', event) + // not using this value } else { - saveObjectState() + 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('Time Scale Value Changed', event) + } } + + if ( + (isNaN(Date.parse(code.fromDate)) || code.fromDate === null || code.fromDate === undefined) || + (isNaN(Date.parse(code.toDate)) || code.toDate === null || code.toDate === undefined) + ) { + // not using this value + } else { + thisObject.fromDate = Date.parse(code.fromDate) + thisObject.toDate = Date.parse(code.toDate) + coordinateSystem.min.x = thisObject.fromDate + coordinateSystem.max.x = thisObject.toDate + coordinateSystem.recalculateScale() + } + saveObjectState() // this overrides any invalid value at the config. } catch (err) { // we ignore errors here since most likely they will be parsing errors. }